Greenplum列存压缩表索引机制

本文介绍列存压缩表(AOCS表)的数据生成方法,并详细解析了通过索引进行数据查找的过程。利用BitmapIndexScan进行索引扫描,通过索引页中的tid定位到具体的数据块及值。此外,还介绍了如何通过rownum快速定位到block的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

点击查看全文


列存压缩表,简称AOCS表

数据生成

create table testao(date text, time text, open float, high float,                                                                                                                           low float, volume int) with(APPENDONLY=true,ORIENTATION=column);

create index testao_idx on testao using btree (volume);

insert into testao select t, t, t, t, t, t from generate_series(1, 1000000) as t;

现象

执行计划如下:

postgres=> explain select * from testao where volume = 100 limit 1;
                                                 QUERY PLAN
------------------------------------------------------------------------------------------------------------
 Limit  (cost=100.95..200.98 rows=1 width=40)
   ->  Gather Motion 4:1  (slice1; segments: 4)  (cost=100.95..200.98 rows=1 width=40)
         ->  Limit  (cost=100.95..200.96 rows=1 width=40)
               ->  Bitmap Append-Only Column-Oriented Scan on testao  (cost=100.95..200.96 rows=1 width=40)
                     Recheck Cond: volume = 100
                     ->  Bitmap Index Scan on testao_idx  (cost=0.00..100.95 rows=1 width=0)
                           Index Cond: volume = 100
 Settings:  effective_cache_size=8GB; gp_statistics_use_fkeys=on
 Optimizer status: legacy query optimizer
(9 rows)

我们看到使用Bitmap Index Scan索引扫描

如何通过索引找到数据

索引页包含记录的tid,而tid包含segfileno和rownum信息,通过segfileno可以定位到文件,通过rownum可以定位到block及具体值。

如何通过rownum快速定位到block

对于索引,GP将会创建一个pg_aoblkdi_oid辅助表(block directory),里面包含每个block在文件的偏移位置fileOffset、segfileno、firstRowNum,并在firstRowNum列上创建索引,只要给出一个rownum,通过索引在pg_aoblkdi_oid辅助表中可以快速得到block在文件的偏移位置fileOffset,然后取出数据。




点击查看全文


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值