Missing query plans in Data Explorer

AI-generated summary

A user, Moin, encountered an issue with the Data Explorer where query plans were not visible in the frontend UI, despite enabling the “Include query plan” option. After debugging with the help of ChatGPT, it was discovered that the explain key was not being forwarded to the ResultFormatConverter. The root cause was that the to_json method only included the explain key if opts[:explain] == true, but this option was not included in the convert call.

Moin found that adding explain: opts[:explain] to the call to ResultFormatConverter.convert fixed the issue. Arkshine suggested that this might be a regression from a previous commit. The issue was later confirmed fixed by kris.kotlarek in a PR.

While using the data explorer, I recently wondered what ‘Include query plan’ was for. So I enabled it to find out - but I didn’t notice any change.

So I asked someone I’ve learned a lot from over the years and he shared a screenshot of how it’s supposed to look. I was curious why it wasn’t working, so I checked and noticed that explain: true is included in the request send[1], but not included in the response[2]. So I tried to understand where it got lost. At some point I asked ChatGPT because I wasn’t sure where to look next. It was very helpful and navigated me though the whole debugging. I tried the fix, after adding explain: opts[:explain] the query plan appeared. Though I have to admit that I only have a faint idea of what I was doing. That’s why I asked ChatGPT to write a summary of our findings for the bug report[3]:

Bug Summary – Missing `explain` in Query Results (Discourse Data Explorer) AI

Issue:
The explain field was not being included in the JSON response of the Data Explorer /run endpoint, even when explain=true was passed in the request. As a result, query plans were not visible in the frontend UI, even though Postgres returned them correctly.

Root Cause:
While the backend correctly passed opts[:explain] = true into the query execution logic and the result[:explain] value was present, this value was not forwarded to the ResultFormatConverter. The to_json method in ResultFormatConverter only includes the explain key if opts[:explain] == true. However, this option was not included in the convert call.

Fix:
Add explain: opts[:explain] to the call to ResultFormatConverter.convert, like so:

render json: 
         ResultFormatConverter.convert(
           :json,
           result,
           query_params: query_params,
           download: params[:download],
+          explain: opts[:explain]
         )

Result:
Once passed correctly, the explain field is included in the JSON response and rendered properly in the frontend UI.




  1. ↩︎



  2. ↩︎

  3. I added the GitHub link and formatted the code snippet ↩︎

3 Likes

Nice job figuring out the issue!
I think it’s a regression from FEATURE: Allows CSV file result to be attached in automated PMs (#318) · discourse/discourse-data-explorer@cbae98f · GitHub.
The code has been refactored, but the explain param is omitted.

2 Likes

Thank you for reporting this issue. It was fixed in this PR:

https://github.com/discourse/discourse-data-explorer/pull/371

6 Likes