Skip to content

feat: add verbose mode to explain_query for scan-level metrics#42

Merged
sunng87 merged 3 commits into
mainfrom
feat/explain-query-verbose
Jun 17, 2026
Merged

feat: add verbose mode to explain_query for scan-level metrics#42
sunng87 merged 3 commits into
mainfrom
feat/explain-query-verbose

Conversation

@killme2008

Copy link
Copy Markdown
Member

Problem

explain_query only ever issued EXPLAIN or EXPLAIN ANALYZE, never EXPLAIN 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-partition ScanMetricsSet and only render under VERBOSE (and only when > 0). Non-verbose output just shows the coarse partition_count (files / file_ranges), which says nothing about row-group-level pruning.

The query_performance_tuning prompt even acknowledged the gap: it told users to fall back to execute_sql with EXPLAIN ANALYZE VERBOSE <query> because the tool couldn't produce it.

Change

  • Add a verbose: bool = False parameter to explain_query, orthogonal to analyze.
    • SQL path: EXPLAIN [ANALYZE] [VERBOSE] <query>
    • TQL path: TQL ANALYZE|EXPLAIN [VERBOSE] ... (TQL supports VERBOSE too, verified against a live instance)
  • Update the query_performance_tuning prompt to use explain_query(analyze=true, verbose=true) instead of the execute_sql workaround.
  • Sync tool descriptions in README, docs/llm-instructions.md, and the table_operation prompt.

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.

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.
@killme2008 killme2008 requested review from Copilot and sunng87 June 16, 2026 15:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_query with verbose: bool = False and assemble EXPLAIN [ANALYZE] [VERBOSE] <query> (plus TQL 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.0 to 0.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.

Comment thread README.md Outdated
Comment thread docs/llm-instructions.md Outdated
Comment thread src/greptimedb_mcp_server/templates/table_operation/template.md Outdated
@sunng87 sunng87 merged commit ba3b732 into main Jun 17, 2026
2 checks passed
@sunng87 sunng87 deleted the feat/explain-query-verbose branch June 17, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants