zoukankan      html  css  js  c++  java
  • PostgreSQL在何处处理 sql查询之二十五

    再次梳理  build_simple_rel 的执行内容:

    /*
     * build_simple_rel
     *      Construct a new RelOptInfo for a base relation or 'other' relation.
     */
    RelOptInfo *
    build_simple_rel(PlannerInfo *root, int relid, RelOptKind reloptkind)
    {
        RelOptInfo *rel;
        RangeTblEntry *rte;
    
        /* Rel should not exist already */
        Assert(relid > 0 && relid < root->simple_rel_array_size);
        if (root->simple_rel_array[relid] != NULL)
            elog(ERROR, "rel %d already exists", relid);
    
        /* Fetch RTE for relation */
        rte = root->simple_rte_array[relid];
        Assert(rte != NULL);
    
        rel = makeNode(RelOptInfo);
        rel->reloptkind = reloptkind;
        rel->relids = bms_make_singleton(relid);
        rel->rows = 0;
        ...
        rel->has_eclass_joins = false;
    
        /* Check type of rtable entry */
        switch (rte->rtekind)
        {
            case RTE_RELATION:
                /* Table --- retrieve statistics from the system catalogs */
                get_relation_info(root, rte->relid, rte->inh, rel);
                break;
            case RTE_SUBQUERY:
            case RTE_FUNCTION:
            case RTE_VALUES:
            case RTE_CTE:
    
                /*
                 * Subquery, function, or values list --- set up attr range and
                 * arrays
                 *
                 * Note: 0 is included in range to support whole-row Vars
                 */
                rel->min_attr = 0;
                rel->max_attr = list_length(rte->eref->colnames);
                rel->attr_needed = (Relids *)
                    palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(Relids));
                rel->attr_widths = (int32 *)
                    palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(int32));
                break;
            default:
                elog(ERROR, "unrecognized RTE kind: %d",
                     (int) rte->rtekind);
                break;
        }
    
        /* Save the finished struct in the query's simple_rel_array */
        root->simple_rel_array[relid] = rel;
    
        ...
        return rel;
    }

    可以看出,这是准备了 表信息的结构--RelOptInfo,然后再把它挂在计划树上:

        root->simple_rel_array[relid] = rel;

     需要注意的是,这里 relid 是 simple_rel_array数组的下标,而非oid。

  • 相关阅读:
    转 ShowSlow+Yslow页面前端性能测试环境搭建
    ORA-01843 无效的月份
    微信回复图片
    springmvc 监听器getWriter() has already been called for this response问题
    执子之手 与子偕老
    美字
    睡至三更时凡功名都成幻境 想到百年后无少长俱是古人
    oracle regexp_like介绍和例子
    Oracle中如何判断字符串是否全为数字
    ruby for in 循环中改变i的值无效
  • 原文地址:https://www.cnblogs.com/gaojian/p/3103866.html
Copyright © 2011-2022 走看看