一. 前言
本文主要通过走读OpenGuass的代码,来了解查询的时候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
f