德州企业网站建设要素,有产品怎么找销售渠道,wordpress网络验证码,如何做自己的网站链接一. 前言 本文主要通过走读OpenGuass的代码#xff0c;来了解查询的时候OpenGuass是如何查找表的索引信息以及根据谓词条件过滤掉无用的索引信息的。 二. 索引路径匹配流程 1. 首先OpenGuass在build_simple_rel的时候#xff0c;首先将一个表以及与他相关的索引都加到rel-来了解查询的时候OpenGuass是如何查找表的索引信息以及根据谓词条件过滤掉无用的索引信息的。 二. 索引路径匹配流程 1. 首先OpenGuass在build_simple_rel的时候首先将一个表以及与他相关的索引都加到rel-indexlist中后续再筛选。主要代码如下所示
build_simple_rel
switch (rte-rtekind) {
case RTE_RELATION:
get_relation_info
List* indexoidlist RelationGetIndexList(relation) // 到pg_index系统表中查找与relation相关的索引
while (HeapTupleIsValid(htup systable_getnext(indscan))) {
result insert_ordered_oid(result, index-indexrelid) // result保存着索引的oid
}
indexinfos lcons(info, indexinfos) // 无条件保留与一个表有关的所有索引
rel-indexlist indexinfos} 2. 再在create_index_paths中根据列的过滤条件对用不上的索引进行剔除主要代码如下
create_index_paths
foreach (lc, rel-indexlist) {
match_restriction_clauses_to_index(rclauseset);// 如果此索引跟谓词条件无关则剔除此索引
bitindexpaths list_concat(bitindexpaths, indexpaths);
add_path(root, rel, (Path*)bpath); // 为索引建立起路径建立的索引路径也会和其他路径进行代价对比取舍
} 3. 保留下来的索引将计算代码和顺序扫描等其他路径进行代码比较再决定是否使用。 三. BitmapOrPath 当查询条件带有or条件的时候OpenGuass会生成一个BitmapOrPath将各个索引及其过滤条件连接起来如对于select * from t1 where id 1 or id 2语句会通过BitmapOr将多个条件应用到索引再通过BitmapOrPath连接起来如下所示 其实现过程主要如下所示
generate_bitmap_or_paths
foreach (j, ((BoolExpr*)rinfo-orclause)-args) { // 逐个遍历or的所有条件
orargs list_make1(orarg);
indlist build_paths_for_OR
indexpaths build_index_paths // 用or其中一个条件构建一个index path
pathlist lappend(pathlist, bitmapqual) // 将当前or的其中一个条件保存到pathlist中
}
bitmapqual create_bitmap_or_path(pathlist) // 将pathlist组装成BitmapOrPath路径