# Data Explorer 中缺失查询计划

**URL:** https://meta.discourse.org/t/missing-query-plans-in-data-explorer/363061
**Category:** Bug
**Tags:** data-explorer
**Created:** [2025年四月22日 21:16 UTC](https://meta.discourse.org/t/missing-query-plans-in-data-explorer/363061 "2025-04-22T21:16:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [2025年四月22日 21:16 UTC](https://meta.discourse.org/t/missing-query-plans-in-data-explorer/363061/1 "2025-04-22T21:16:31Z")

</div>

在使用数据浏览器时，我最近想知道“包含查询计划”是做什么用的。所以我启用它来找出答案——但我没有注意到任何变化。

 ![Screenshot_20250422_222115_Firefox](https://global.discourse-cdn.com/meta/original/4X/1/3/d/13d60d49c7a71034ebe051c0674ac9febad6fc69.jpeg)

所以我问了一个我多年来学到很多的人，他分享了一个截图，展示了它应该是什么样子。我很好奇为什么它不起作用，所以我检查了一下，注意到请求发送中包含了 `explain: true`\[1\]，但响应中没有包含\[2\]。所以我试图弄清楚它在哪里丢失了。有一次我问了 ChatGPT，因为我不确定接下来该看哪里。它非常有帮助，引导我完成了整个调试过程。我尝试了修复，在添加 `explain: opts[:explain]` 后，查询计划出现了。尽管我不得不承认，我只对我在做什么有一个模糊的了解。这就是为什么我让 ChatGPT 为 bug 报告写一份我们发现的摘要\[3\]：

> **Bug Summary – Missing \`explain\` in Query Results (Discourse Data Explorer)
AI**
>
> **Issue:**  
> 即使在请求中传递了 `explain=true`，`explain` 字段也没有包含在数据浏览器 `/run` 端点的 JSON 响应中。因此，查询计划在前台 UI 中不可见，尽管 Postgres 正确返回了它们。
> 
> **Root Cause:**  
> 虽然后端正确地将 `opts[:explain] = true` 传递给了查询执行逻辑，并且 `result[:explain]` 值存在，但该值 **未转发** 给 `ResultFormatConverter`。`ResultFormatConverter` 中的 `to_json` 方法仅在 `opts[:explain] == true` 时才包含 `explain` 键。但是，此选项未包含在 `convert` 调用中。
> 
> **Fix:**  
> 将 `explain: opts[:explain]` 添加到 `ResultFormatConverter.convert` 的调用中，如下所示：
> 
> > <https://github.com/discourse/discourse-data-explorer/blob/7922daf500c8a976a8fc046aac61133f9c327745/app/controllers/discourse_data_explorer/query_controller.rb#L191-L197>
> 
> ```diff
> render json:
> ResultFormatConverter.convert(
> :json,
> result,
> query_params: query_params,
> download: params[:download],
> + explain: opts[:explain]
> )
> 
> ```
> 
> **Result:**  
> 正确传递后，`explain` 字段将包含在 JSON 响应中，并在前台 UI 中正确呈现。

* * *

1.   

2.   

3. 我添加了 GitHub 链接并格式化了代码片段

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [2025年四月22日 23:19 UTC](https://meta.discourse.org/t/missing-query-plans-in-data-explorer/363061/2 "2025-04-22T23:19:24Z")

</div>

干得好，解决了问题！  
我认为这是 [FEATURE: Allows CSV file result to be attached in automated PMs (#318) · discourse/discourse-data-explorer@cbae98f · GitHub](https://github.com/discourse/discourse-data-explorer/commit/cbae98f6eda078906b65a18b4bd3e32850372dea) 的回归。  
代码已被重构，但省略了 `explain` 参数。

---

<div class="post-metadata">

### Author: ![kris.kotlarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kris.kotlarek/32/176919_2.png) [@kris.kotlarek](https://meta.discourse.org/u/kris.kotlarek)
#### Post date: [2025年四月23日 06:02 UTC](https://meta.discourse.org/t/missing-query-plans-in-data-explorer/363061/8 "2025-04-23T06:02:57Z")

</div>

感谢您报告此问题。此问题已在此 PR 中修复：

> <https://github.com/discourse/discourse-data-explorer/pull/371>
>
> Bug introduced during refactoring in this PR: https://github.com/discourse/disco…urse-data-explorer/pull/318
> 
> Explain parameter must be passed to \`ResultFormatConverter\`.
> 
> !\[Screenshot 2025-04-23 at 1 39 54 pm\](https://github.com/user-attachments/assets/451591aa-0975-48f4-848c-50affa414885)

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2025年五月22日 01:07 UTC](https://meta.discourse.org/t/missing-query-plans-in-data-explorer/363061/10 "2025-05-22T01:07:23Z")

</div>


