PostgreSQL 并行表扫描分析 Gather Parallel Seq Scan

PostgreSQL 在很多场景下会启用并行执行计划,创建多个并行工作子进程,提升查询效率。


一个常用的并行表扫描的例子:

从下面的执行计划可以看出,Parallel Seq Scan 并行表扫描,并发工作进程数为 2,最上层的执行计划节点名称为 Gather。

postgres=# explain select * from tt where product_item_id=12836242; QUERY PLAN ---------------------------------------------------------------------- Gather (cost=1000.00..46068.10 rows=1 width=41) Workers Planned: 2 -> Parallel Seq Scan on tt (cost=0.00..45068.00 rows=1 width=41) Filter: (product_item_id = 12836242)