# 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:** 1\
**Showing post:** 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 链接并格式化了代码片段

---

_[View the full topic](https://meta.discourse.org/t/missing-query-plans-in-data-explorer/363061)._
