理解Postgres解释计划



我正试图通过这个网站了解Postgres的解释计划(http://explain.depesz.com)。

这是我的计划:

Unique  (cost=795.43..800.89 rows=546 width=23) (actual time=0.599..0.755 rows=620 loops=1)
->  Sort  (cost=795.43..796.79 rows=546 width=23) (actual time=0.598..0.626 rows=620 loops=1)
Sort Key: m.member_id, c.total_charged_amt DESC, c.claim_status
Sort Method: quicksort  Memory: 73kB
->  Nested Loop  (cost=9.64..770.60 rows=546 width=23) (actual time=0.023..0.342 rows=620 loops=1)
->  Bitmap Heap Scan on member m  (cost=9.22..222.50 rows=63 width=8) (actual time=0.016..0.024 rows=62 loops=1)
Recheck Cond: (((member_id >= 1584161838) AND (member_id <= 1584161898)) OR (member_birth_dt = '1978-03-13'::date))
Heap Blocks: exact=3
->  BitmapOr  (cost=9.22..9.22 rows=63 width=0) (actual time=0.013..0.013 rows=0 loops=1)
->  Bitmap Index Scan on member_pkey  (cost=0.00..4.31 rows=2 width=0) (actual time=0.007..0.007 rows=61 loops=1)
Index Cond: ((member_id >= 1584161838) AND (member_id <= 1584161898))
->  Bitmap Index Scan on idx_dob  (cost=0.00..4.88 rows=61 width=0) (actual time=0.006..0.006 rows=1 loops=1)
Index Cond: (member_birth_dt = '1978-03-13'::date)
->  Index Scan using idx_memberid on claim c  (cost=0.42..8.60 rows=10 width=23) (actual time=0.001..0.003 rows=10 loops=62)
Index Cond: (member_id = m.member_id)
Planning Time: 0.218 ms
Execution Time: 0.812 ms

该计划也可在以下链接中获得:https://explain.depesz.com/s/Qzau.

我有以下问题:

  1. Bitmap Index Scans分别以0.007s和0.006s运行,由于压痕而平行运行。

    那么为什么Bitmapor的起始时间是0.013秒呢?为什么要增加两个孩子的时间?Bitmapor的开始时间应为其2个子项中的最大值。因此,理想情况下,Bitmapor独占时间应为0.006(0.013-0.007(,但为0(0.013-0.0007-0.006(

  2. Bitmap Heap Scanindex scanNested Loop的子代,运行时间分别为0.024s和0.186s。

    由于缩进,我假设这两个孩子是平行运行的。因此,父独占时间应为0.156(0.342-0.186(,但实际为0.132(0.342-0186-0.24(

我的理解是,我们应该减去子时序的最大值(因为它们是并行运行的(,以获得在节点中花费的独占时间。但相反,它是将子时间相加,然后从父时间的结束时间中减去总和,得到独占时间。我对解释计划的理解有误吗?

任何帮助我都非常感激,因为我完全无法理解它们。

正如马所说,不涉及并行处理。如果涉及并行查询,您将看到一个Gather节点来收集结果。

缩进使查询执行计划的图形可视化:

Unique
|
Sort
|
Nested Loop
/      
Bitmap Heap Scan    Index Scan
|
Bitmap Or
/     
Bitmap Index Scan   Bitmap Index Scan

这就解释了explain.depesz.com计算独占时间的方式。请注意,这只是尽最大努力,而不是绝对的事实,因为(例如("位图或"不需要零时间。但是explain.depesz.com只能根据它从EXPLAIN得到的数字。

最新更新