对get_baserel_parampathinfo函数的学习
2013-06-19 14:49
387 查看
/* * get_baserel_parampathinfo * Get the ParamPathInfo for a parameterized path for a base relation, * constructing one if we don't have one already. * * This centralizes estimating the rowcounts for parameterized paths. * We need to cache those to be sure we use the same rowcount for all paths * of the same parameterization for a given rel. This is also a convenient * place to determine which movable join clauses the parameterized path will * be responsible for evaluating. */ ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer) { ParamPathInfo *ppi; Relids joinrelids; List *pclauses; double rows; ListCell *lc; /* Unparameterized paths have no ParamPathInfo */ if (bms_is_empty(required_outer)) return NULL; Assert(!bms_overlap(baserel->relids, required_outer)); /* If we already have a PPI for this parameterization, just return it */ foreach(lc, baserel->ppilist) { ppi = (ParamPathInfo *) lfirst(lc); if (bms_equal(ppi->ppi_req_outer, required_outer)) return ppi; } /* * Identify all joinclauses that are movable to this base rel given this * parameterization. */ joinrelids = bms_union(baserel->relids, required_outer); pclauses = NIL; foreach(lc, baserel->joininfo) { RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc); if (join_clause_is_movable_into(rinfo, baserel->relids, joinrelids)) pclauses = lappend(pclauses, rinfo); } /* * Add in joinclauses generated by EquivalenceClasses, too. (These * necessarily satisfy join_clause_is_movable_into.) */ pclauses = list_concat(pclauses, generate_join_implied_equalities(root, joinrelids, required_outer, baserel)); /* Estimate the number of rows returned by the parameterized scan */ rows = get_parameterized_baserel_size(root, baserel, pclauses); /* And now we can build the ParamPathInfo */ ppi = makeNode(ParamPathInfo); ppi->ppi_req_outer = required_outer; ppi->ppi_rows = rows; ppi->ppi_clauses = pclauses; baserel->ppilist = lappend(baserel->ppilist, ppi); return ppi; }
上溯来看:
/* * set_plain_rel_pathlist * Build access paths for a plain relation (no subquery, no inheritance) */ static void set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) { /* Consider sequential scan */ add_path(rel, create_seqscan_path(root, rel, NULL)); /* Consider index scans */ create_index_paths(root, rel); /* Consider TID scans */ create_tidscan_paths(root, rel); /* Now find the cheapest of the paths for this rel */ set_cheapest(rel); }
只要进入了 set_plain_rel_pathlist 函数,进行
add_path(rel, create_seqscan_path(root, rel, NULL))调用是,给予 create_seqscan_path 的第三个参数是NULL
再看 create_seqscan_path:
/* * create_seqscan_path * Creates a path corresponding to a sequential scan, returning the * pathnode. */ Path * create_seqscan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer) { Path *pathnode = makeNode(Path); pathnode->pathtype = T_SeqScan; pathnode->parent = rel; pathnode->param_info = get_baserel_parampathinfo(root, rel, required_outer); pathnode->pathkeys = NIL; /* seqscan has unordered result */ cost_seqscan(pathnode, root, rel, pathnode->param_info); return pathnode; }
看这句话:pathnode->param_info = get_baserel_parampathinfo(root, rel, required_outer);
由于传递的required_outer是NULL,所以就是 get_baserel_parampathinfo(root, rel, NULL);
那么:
/* * get_baserel_parampathinfo * Get the ParamPathInfo for a parameterized path for a base relation, * constructing one if we don't have one already. * * This centralizes estimating the rowcounts for parameterized paths. * We need to cache those to be sure we use the same rowcount for all paths * of the same parameterization for a given rel. This is also a convenient * place to determine which movable join clauses the parameterized path will * be responsible for evaluating. */ ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer) { ParamPathInfo *ppi; Relids joinrelids; List *pclauses; double rows; ListCell *lc; /* Unparameterized paths have no ParamPathInfo */ if (bms_is_empty(required_outer)) return NULL; Assert(!bms_overlap(baserel->relids, required_outer)); /* If we already have a PPI for this parameterization, just return it */ foreach(lc, baserel->ppilist) { ppi = (ParamPathInfo *) lfirst(lc); if (bms_equal(ppi->ppi_req_outer, required_outer)) return ppi; } /* * Identify all joinclauses that are movable to this base rel given this * parameterization. */ joinrelids = bms_union(baserel->relids, required_outer); pclauses = NIL; foreach(lc, baserel->joininfo) { RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc); if (join_clause_is_movable_into(rinfo, baserel->relids, joinrelids)) pclauses = lappend(pclauses, rinfo); } /* * Add in joinclauses generated by EquivalenceClasses, too. (These * necessarily satisfy join_clause_is_movable_into.) */ pclauses = list_concat(pclauses, generate_join_implied_equalities(root, joinrelids, required_outer, baserel)); /* Estimate the number of rows returned by the parameterized scan */ rows = get_parameterized_baserel_size(root, baserel, pclauses); /* And now we can build the ParamPathInfo */ ppi = makeNode(ParamPathInfo); ppi->ppi_req_outer = required_outer; ppi->ppi_rows = rows; ppi->ppi_clauses = pclauses; baserel->ppilist = lappend(baserel->ppilist, ppi); return ppi; }
看这一小段:
/* Unparameterized paths have no ParamPathInfo */ if (bms_is_empty(required_outer)) return NULL;
看看 bms_is_empty:
/* * bms_is_empty - is a set empty? * * This is even faster than bms_membership(). */ bool bms_is_empty(const Bitmapset *a) { int nwords; int wordnum; if (a == NULL) return true; nwords = a->nwords; for (wordnum = 0; wordnum < nwords; wordnum++) { bitmapword w = a->words[wordnum]; if (w != 0) return false; } return true; }
相关文章推荐
- 学习thinkPHP 笔记(1)————————数据库操作 自写函数getbaseWhere() 和 where等操作
- WindowsAPI之GetFileVersionInfo函数和VerQueryValue函数
- C++ 学习笔记(19)new/delete表达式、定位new、typeid、dynamic_cast、type_info、枚举类型、成员函数指针、union、位域、volatile限定符、链接指示
- JNI学习1——Android jni GetFieldID 和 GetMethodID 函数的说明
- UNICODE和ANSI字符串的转换(解释了MultiByteToWideChar,WideCharToMultiByte,GetTextCharsetInfo,GetTextCharset,IsDBCSLeadByte,IsDBCSLeadByteEx,IsTextUnicode一共7个函数)
- MFC特定函数的应用20160720(SystemParametersInfo,GetWindowRect,WriteProfileString,GetSystemMetrics)
- ffmpeg学习七:avformat_find_stream_info函数源码分析
- C++程序学习--cin.get()函数读取空行时的细节
- thinkphp函数学习(2)——microtime, memory_get_usage, dirname, strtolower, is_file
- SODBASE CEP学习(十七):自定义函数开发
- VS6.0下使用 IP Help API(Iphlpapi.dll)系列函数之GetAdaptersAddresses(GetAdaptersInfo) 获取网卡信息简述
- Hyperion Essbase BusinessRule 函数学习--2
- Hyperion Essbase BusinessRule 函数学习--2
- InternetGetLastResponseInfo函数
- Java反射学习 getClass()函数应用
- getBasePath 函数第二版
- wordpress get_header 函数学习
- C和Java JNA获取系统空闲时间 --GetLastInputInfo 函数
- Android 学习笔记之AndBase框架学习(四) 使用封装好的函数实现单,多线程任务
- WinSock网络编程学习笔记(六):服务查询程序(getserverbyname和getserverbyport函数)