OpenGauss 之索引查找和匹配

一. 前言

       本文主要通过走读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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值