feat: add verbose mode to explain_query for scan-level metrics#42
Merged
Conversation
explain_query could only emit EXPLAIN [ANALYZE], never EXPLAIN ANALYZE VERBOSE. The index-pruning counters (rg_bloom_filtered, rg_inverted_filtered, rg_minmax_filtered, rows_bloom_filtered, rows_inverted_filtered) only render under VERBOSE in mito2's per-partition ScanMetricsSet. Without them the tool only exposed the coarse partition_count, which says nothing about row-group-level pruning. Add a `verbose: bool = False` param, orthogonal to `analyze`, applied to both SQL (EXPLAIN [ANALYZE] [VERBOSE]) and TQL (TQL ANALYZE/EXPLAIN [VERBOSE]) paths. Update the performance-tuning prompt to call explain_query(analyze=true, verbose=true) instead of falling back to execute_sql.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a verbose option to the explain_query MCP tool so users can request EXPLAIN ... VERBOSE (and EXPLAIN ANALYZE VERBOSE) output, enabling visibility into scan-level/per-partition metrics that aren’t shown in non-verbose explains. Updates prompt templates/docs to use the new capability and bumps the package/registry version.
Changes:
- Extend
explain_querywithverbose: bool = Falseand assembleEXPLAIN [ANALYZE] [VERBOSE] <query>(plusTQL ANALYZE|EXPLAIN [VERBOSE] ...rewriting). - Add tests that spy on executed SQL to validate keyword assembly for SQL and TQL paths.
- Update prompts/docs/README references and bump version from
0.5.0to0.5.1.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/greptimedb_mcp_server/server.py |
Adds verbose parameter and keyword composition for SQL/TQL explain execution. |
tests/test_server.py |
Adds 3 tests verifying correct EXPLAIN/TQL ... VERBOSE generation via a cursor spy. |
src/greptimedb_mcp_server/templates/query_performance_tuning/template.md |
Switches guidance from execute_sql workaround to explain_query(..., analyze=true, verbose=true). |
src/greptimedb_mcp_server/templates/table_operation/template.md |
Updates tool description to mention verbose mode. |
README.md |
Updates explain_query tool description to mention verbose=true. |
docs/llm-instructions.md |
Updates tool description to mention verbose=true. |
pyproject.toml |
Bumps project version to 0.5.1. |
server.json |
Bumps MCP registry metadata version to 0.5.1. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
sunng87
approved these changes
Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
explain_queryonly ever issuedEXPLAINorEXPLAIN ANALYZE, neverEXPLAIN ANALYZE VERBOSE. The index-pruning counters that matter for diagnosing query performance —rg_bloom_filtered,rg_inverted_filtered,rg_minmax_filtered,rows_bloom_filtered,rows_inverted_filtered— live in mito2's per-partitionScanMetricsSetand only render underVERBOSE(and only when> 0). Non-verbose output just shows the coarsepartition_count(files / file_ranges), which says nothing about row-group-level pruning.The
query_performance_tuningprompt even acknowledged the gap: it told users to fall back toexecute_sqlwithEXPLAIN ANALYZE VERBOSE <query>because the tool couldn't produce it.Change
verbose: bool = Falseparameter toexplain_query, orthogonal toanalyze.EXPLAIN [ANALYZE] [VERBOSE] <query>TQL ANALYZE|EXPLAIN [VERBOSE] ...(TQL supports VERBOSE too, verified against a live instance)query_performance_tuningprompt to useexplain_query(analyze=true, verbose=true)instead of theexecute_sqlworkaround.docs/llm-instructions.md, and thetable_operationprompt.Scan-level index-pruning counters require
analyze=true, verbose=true(the counters are only produced during actual execution).Tests
Added 3 tests that spy on the executed SQL and assert correct keyword assembly:
EXPLAIN ANALYZE VERBOSE(analyze + verbose)EXPLAIN VERBOSE(verbose without analyze — confirms orthogonality)TQL ANALYZE VERBOSE(TQL path)Full suite: 188 passed, flake8 clean, black clean.