【问题标题】:Explain analyze: Total time spent executing a task. Documentation error or my error?解释分析:执行任务所花费的总时间。文档错误还是我的错误?
【发布时间】:2019-08-15 04:34:04
【问题描述】:

我认为在有关解释计划的 postgres 文档中发现了一个错误,并可能进行更正。

发件人:https://www.postgresql.org/docs/current/using-explain.html

Index Scan using tenk2_unique2 on tenk2 t2  (cost=0.29..7.91 rows=1 width=244) (actual time=0.021..0.022 rows=1 loops=10)

“在上面的例子中,我们总共花费了 0.220 毫秒在 tenk2 上执行索引扫描。”

文档似乎表明 Actual Total Time * Actual Loops = 花费在操作上的总时间。

但是,根据我制作的 JSON 计划:

 "Plans": [
        {
          "Node Type": "Hash Join",
          "Parent Relationship": "Outer",
          "Parallel Aware": false,
          "Join Type": "Inner",
          "Startup Cost": 66575.34,
          "Total Cost": 76861.82,
          "Plan Rows": 407,
          "Plan Width": 290,
          "Actual Startup Time": 49962.789,
          "Actual Total Time": 51206.643,
          "Actual Rows": 127117,
          "Actual Loops": 3,
          "Output": [ ... ],
...
"Execution Time": 52677.398

(完整的计划是here。)

Actual Total Time * Actual Loops = 51 秒 * 3 = 2 分 33 秒明显超过了 Execution Time 的 52.7 秒。

我对文档的理解正确吗?

如果是这样,不应该说,“我们总共花了 0.01 毫秒在 tenk2 上执行索引扫描”吗?

【问题讨论】:

  • 在这种情况下文档是正确的。您的EXPLAIN 输出不完整,因此很难判断它是否与文档相矛盾。
  • 如果Actual Total Time * Actual Loops 超过Execution Time,文档如何正确?
  • 我不确定。这就是为什么我想看看整个计划。如果不是太多要求,以文本格式。
  • 这里是:tatiyants.com/pev/#/plans/plan_1553519907593。我帖子中的操作是使用s._fixation_key = f._fixation_key的哈希连接。
  • 该链接指向我的空白页面。您可以将其添加到问题中吗?

标签: postgresql sql-execution-plan explain


【解决方案1】:

您的Hash Join 位于Gather 节点下:

Gather (cost=67,575.34..77,959.52 rows=977 width=290) (actual time=51,264.085..52,595.474 rows=381,352 loops=1)
Buffers: shared hit=611279 read=99386
  -> Hash Join (cost=66,575.34..76,861.82 rows=407 width=290) (actual time=49,962.789..51,206.643 rows=127,117 loops=3)
     Buffers: shared hit=611279 read=99386

这意味着查询启动了两个与主后端并行运行的后台工作程序以完成哈希连接(参见执行计划中的"Workers Launched": 2)。

现在很明显,如果三个进程在一个任务上工作,总执行时间不会是各个执行时间的总和。

换句话说,执行时间与循环数相乘的规则适用于嵌套循环连接(单线程),但不适用于并行执行查询。

【讨论】:

  • 您的回答让我更仔细地阅读了解释和并行查询文档。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-26
  • 1970-01-01
  • 1970-01-01
  • 2015-12-11
  • 2020-06-30
相关资源
最近更新 更多