理解 Postgres 解释计划

Understanding Postgres explain plan

我正在尝试使用此网站 (http://explain.depesz.com) 了解 Postgres 解释计划。

这是我的计划:

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

以下 link:https://explain.depesz.com/s/Qzau 也提供该计划。

我有以下问题:

  1. Bitmap Index Scans 其中 运行s 分别在 0.007s 和 0.006s 中 运行s 由于缩进而并行。

    那么为什么 Bitmapor 从 0.013 秒开始?为什么要增加其 children 的时间? Bitmapor的开始时间应该是其2children中的最大值。所以理想情况下Bitmapor独占时间应该是0.006(0.013-0.007),但它是0(0.013-0.007-0.006)

  2. Bitmap Heap Scanindex scan分别是Nested Loop和运行的children,分别用0.024s和0.186s。

    由于缩进,我假设这 2 children 运行 是并行的。所以parent独占时间应该是0.156(0.342-0.186),反而是0.132(0.342-0.186-0.24).

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

非常感谢任何帮助,因为我对解释它们完全感到困惑。

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

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

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

这就解释了为什么 explain.depesz.com 以这种方式计算独占时间。请注意,这只是尽力而为,而不是绝对事实,因为(例如)"bitmap or" 不会花费零时间。但是 explain.depesz.com 只能根据从 EXPLAIN.

获得的数字