Index Scan using ni_child_parent_uuid on child c (cost=0.43..1286.53 rows=636 width=16)(actual time=0.037..0.479 rows=206 loops=1)
Index Cond: (parent_uuid = '752726e3-af63-49a8-93e7-cfda65be27af'::uuid)
Parallel Seq Scan on child c (cost=0.00..831237.98 rows=91 width=16)(actual time=8232.835..11644.969 rows=206 loops=1)
Filter: (parent_uuid = '752726e3-af63-49a8-93e7-cfda65be27af'::uuid)
为什么预期记录数不同?条件相同,数据库相同,一切都相同,只是一个使用 seq 扫描,另一个使用 pg_hint_plan 进行索引扫描IndexScan(c)。
由于6倍的差异,在带有连接的复杂查询中,优化器更喜欢使用seq扫描,因为6倍的减少极大地影响了连接的成本。
因为这是一个预定进程的行数。
在这种情况下,计划有 7 名工人
636/7=91。PS:请求的问题与统计数据不足有关,我增加了它 - 它有帮助: