文章目录
- 扫描节点
- 案例
- 注意
扫描节点
- Seq Scan:顺序扫描(全表扫描)
- Index Scan:索引扫描(不只是返回索引列的值)
- IndexOnly Scan:索引扫描(只返回索引列的值)
- BitmapIndex Scan:利用Bitmap 结构扫描
- BitmapHeap Scan:把BitmapIndex Scan 返回的Bitmap 结构转换为元组结构
Bitmap 结构扫描:处理多索引列的组合查询
案例
下面这是一段执行explain ANALYZE
打印输出的结果
Append (cost=4.32..18016.95 rows=4507 width=54) (actual time=0.037..20.751 rows=6046 loops=1)
-> Bitmap Heap Scan on dwa_d_dg_staff_directsale_dev_report_p20231114 a (cost=4.32..19.11 rows=4 width=49) (actual time=0.036..0.045 rows=4 loops=1)
Recheck Cond: ((branch_id)::text = '837010040280000'::text)
Heap Blocks: exact=4
-> Bitmap Index Scan on dwa_d_dg_staff_directsale_dev_report_p20231114_branch_id_idx (cost=0.00..4.32 rows=4 width=0) (actual time=0.025..0.025 rows=4 loops=1)
Index Cond: ((branch_id)::text = '837010040280000'::text)
-> Bitmap Heap Scan on dwa_d_dg_staff_directsale_dev_report_p20231115 a_1 (cost=4.32..19.11 rows=4 width=49) (actual time=0.019..0.026 rows=4 loops=1)
Recheck Cond: ((branch_id)::text = '837010040280000'::text)
Heap Blocks: exact=4
-> Bitmap Index Scan on dwa_d_dg_staff_directsale_dev_report_p20231115_branch_id_idx (cost=0.00..4.32 rows=4 width=0) (actual time=0.013..0.013 rows=4 loops=1)
Index Cond: ((branch_id)::text = '837010040280000'::text)
-> Bitmap Heap Scan on dwa_d_dg_staff_directsale_dev_report_p20231116 a_2 (cost=4.54..64.13 rows=16 width=54) (actual time=0.023..0.073 rows=18 loops=1)
Recheck Cond: ((branch_id)::text = '837010040280000'::text)
Heap Blocks: exact=18
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
从上面打印的结果 我们由此可以分析出branch_id是where里面的其中一个条件,在执行这个where条件时,branch_id进行了索引扫描,具体应该怎么看呢,下面来详细的分析一下:
- Bitmap Heap Scan on dwa_d_dg_staff_directsale_dev_report_p20231114:表示对dwa_d_dg_staff_directsale_dev_report表进行Bitmap Heap 扫描
- Recheck Cond: ((branch_id)::text = ‘837010040280000’::text)表明Bitmap Heap Scan 的Recheck操作 的条件是branch_id = ‘837010040280000’
- Heap Blocks: exact=4表明准确扫描到数据块的个数是4
- Bitmap Index Scan on dwa_d_dg_staff_directsale_dev_report_p20231114_branch_id_idx:表示使用dwa_d_dg_staff_directsale_dev_report_p20231114_branch_id_idx 索引进行位图索引扫描
- actual time:执行时间,格式为xxx…xxx,在… 之前的是该节点实际的启动时间,即找到符合该节点条件的第一个结果实际需要的时间,在…之后的是该节点实际的执行时间
- Filter:条件过滤
- rows:指的是该节点实际的返回行数
- loops:指的是该节点实际的重启次数。如果一个计划节点在运行过程中,它的相关参数值(如绑定变量)发生了变化,就需要重新运行这个计划节点。
- width:每行平均宽度为74字节
- cost:第一个数字表示启动的成本,也就是返回第一行需要多少 cost 值;第二个数字表示返回所有的数据的成本
注意
如果获取的结果集的占比比较小,但是元组数很多时,可能Bitmap Index Scan 的性能要比Index Scan 好