Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support explain diagnostic command #909

Merged
merged 68 commits into from
Jul 26, 2022
Merged

Support explain diagnostic command #909

merged 68 commits into from
Jul 26, 2022

Conversation

seeforschauer
Copy link
Contributor

@seeforschauer seeforschauer commented Jul 18, 2022

Description

This PR closes #167.

PR checklist

  • convert returned JSON document into types.Document of the same form;
  • implement explain command:
    • verbosity parameter should be ingored;
    • explainVersion, command, serverInfo fields should be returned as in MongoDB;
    • queryPlanner should contain converted EXPLAIN (FORMAT JSON) results;
    • executionStats and serverParameters should be absent;
  • change fetch method to run EXPLAIN (VERBOSE true, FORMAT JSON) <query> instead of the query itself if parameter is given;
  • write integration test;
  • refactor fetch method (split it into two?) if it seems to be needed on review.

Example output

ferretdb=#
ferretdb=# EXPLAIN (FORMAT JSON) SELECT _jsonb FROM "testcommandsdiagnosticexplain"."testcommandsdiagnosticexplain_1dd9d237"
ferretdb-# ;
                            QUERY PLAN
------------------------------------------------------------------
 [                                                               +
   {                                                             +
     "Plan": {                                                   +
       "Node Type": "Seq Scan",                                  +
       "Parallel Aware": false,                                  +
       "Async Capable": false,                                   +
       "Relation Name": "testcommandsdiagnosticexplain_1dd9d237",+
       "Alias": "testcommandsdiagnosticexplain_1dd9d237",        +
       "Startup Cost": 0.00,                                     +
       "Total Cost": 23.60,                                      +
       "Plan Rows": 1360,                                        +
       "Plan Width": 32                                          +
     }                                                           +
   }                                                             +
 ]
(1 row)

Or

--------------------------------------[ RECORD 1 ]--------
QUERY PLAN 
| [                                        +
|   {                                      +
|     "Plan": {                            +
|       "Node Type": "Seq Scan",           +
|       "Parallel Aware": false,           +
|       "Async Capable": false,            +
|       "Relation Name": "values_34474c3b",+
|       "Schema": "test",                  +
|       "Alias": "values_34474c3b",        +
|       "Startup Cost": 0.00,              +
|       "Total Cost": 23.60,               +
|       "Plan Rows": 1360,                 +
|       "Plan Width": 32,                  +
|       "Output": ["_jsonb"]               +
|     }                                    +
|   }                                      +
| ]

Readiness checklist

  • I added tests for new functionality or bugfixes.
  • I ran task all, and it passed.
  • I added/updated comments for both exported and unexported top-level declarations (functions, types, etc).
  • I checked comments rendering with task godocs.
  • (for maintainers only) I set Reviewers, Assignee, Labels, Project and project's Sprint fields.
  • I marked all done items in this checklist.

@seeforschauer seeforschauer self-assigned this Jul 18, 2022
@seeforschauer seeforschauer added the code/feature Some user-visible feature is not implemented yet label Jul 18, 2022
@codecov
Copy link

codecov bot commented Jul 18, 2022

Codecov Report

Merging #909 (ba43932) into main (8bcfbd9) will decrease coverage by 0.71%.
The diff coverage is 20.60%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #909      +/-   ##
==========================================
- Coverage   62.66%   61.94%   -0.72%     
==========================================
  Files         225      228       +3     
  Lines       10463    10591     +128     
==========================================
+ Hits         6557     6561       +4     
- Misses       3135     3254     +119     
- Partials      771      776       +5     
Impacted Files Coverage Δ
internal/handlers/common/error.go 82.65% <ø> (ø)
internal/handlers/common/errorcode_string.go 80.00% <ø> (ø)
internal/handlers/common/msg_listcommands.go 85.71% <ø> (ø)
internal/handlers/dummy/msg_explain.go 0.00% <0.00%> (ø)
internal/handlers/pg/msg_explain.go 0.00% <0.00%> (ø)
internal/handlers/tigris/msg_explain.go 0.00% <0.00%> (ø)
internal/handlers/pg/pgdb/query_documents.go 36.55% <25.55%> (-24.37%) ⬇️
internal/types/document.go 85.63% <100.00%> (+0.51%) ⬆️
internal/clientconn/conninfo/conn_info.go 66.66% <0.00%> (-16.67%) ⬇️
internal/handlers/pg/msg_dbstats.go 65.11% <0.00%> (-6.98%) ⬇️
... and 3 more
Flag Coverage Δ
integration 56.64% <20.60%> (-0.70%) ⬇️
mongodb 18.65% <6.74%> (-0.21%) ⬇️
pg 61.58% <20.85%> (-0.87%) ⬇️
tigris 18.17% <6.66%> (-0.20%) ⬇️
unit 24.77% <16.36%> (-0.26%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@seeforschauer
Copy link
Contributor Author

seeforschauer commented Jul 21, 2022

It's not ready yet but let's discuss some:

  • I've added explain parameter to iterateFetch. iterateFetch(ctx context.Context, fetched chan FetchedDocs, rows pgx.Rows, explain bool) error. Do you have any thoughts on how can it be more beautiful?
  • the Convert func in internal/util/convert/convert.go. Should it be in that package or in another place?
  • the test doesn't check any values. I'm about to add some, for example, from the example structures (see header)

@seeforschauer seeforschauer marked this pull request as ready for review July 21, 2022 14:22
w84thesun
w84thesun previously approved these changes Jul 25, 2022
@AlekSi AlekSi added this to the v0.5.1 milestone Jul 25, 2022
@ferretdb-bot
Copy link
Member

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ AlekSi
❌ Ekaterina Blech


Ekaterina Blech seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@AlekSi AlekSi assigned AlekSi and unassigned seeforschauer Jul 26, 2022
@AlekSi AlekSi added the no ci label Jul 26, 2022
@AlekSi AlekSi removed the no ci label Jul 26, 2022
@AlekSi AlekSi disabled auto-merge July 26, 2022 18:36
@AlekSi AlekSi merged commit 6ee4f97 into FerretDB:main Jul 26, 2022
@seeforschauer seeforschauer deleted the explain branch July 27, 2022 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code/feature Some user-visible feature is not implemented yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support explain diagnostic command
5 participants