Repository navigation
feat: log the inspector's query call tree under --debug (#285, #644, #654) - #655
Conversation
…654) Every catalog query the inspector issues is now attributed to the BuildIR step that issued it. With --debug, the finished tree is logged when BuildIR returns: one line per step with its query count, summed query time and wall time, and each step with more than one query broken down by query shape (sqlc query name, or the collapsed leading SQL). Steps inside a concurrent group are listed heaviest first. On a schema with grants, the per-row role and constraint-column lookups behind #644 and #654 show up by name with their counts, so slow plans over high-latency connections can be diagnosed from the CLI without server-side statement logging - the original ask in #285. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
Static review identified no blocking correctness or synchronization issues; tests were not executed.
0 open findings
What changed in this PR
Adds inspector query tracing under --debug to help diagnose slow schema inspection without changing query behavior.
Changes:
- Records query counts, timings, and shapes in a named
BuildIRcall tree. - Adds tests for attribution, nesting, log ordering, and concurrent recording.
| File | Description |
|---|---|
| ir/trace.go | Implements query wrapping, span aggregation, and debug logging. |
| ir/trace_test.go | Tests trace attribution, formatting, and concurrency. |
| ir/inspector.go | Integrates tracing into sequential and concurrent inspection steps. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
[Medium impact] The PR appears safe to merge. SummaryAdds a query call tree to inspection logs under
No actionable issues found. Tests were not run during this review. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[BuildIR root] --> B[Sequential steps]
A --> C[Concurrent groups]
C --> D[Named steps]
B --> E[tracingDB]
D --> E
E --> F[PostgreSQL]
E --> G[Count and time queries by shape]
G --> H[Log completed tree when debug is enabled]
Reviews (1) · Last reviewed commit: "feat: log the inspector's query call tre..." · Reviewed by Greptile |
Summary
--debugnow logs a call tree of every catalog query the inspector issues, one line perBuildIRstep, so a slowdumporplanover a high-latency connection can be diagnosed from the CLI alone.tracingDBwrapper that attributes it to the step carried in the context (newir/trace.go).BuildIRsteps are named; each sequential step, each concurrent group, and each step inside a group is a node with its query count, summed query time, and wall time.--debug; the cost with it off is a mutex and a map update per query.Example against the
employeefixture with grants to two roles (7 tables):The two per-row lookups behind #644 / #654 are visible by name with their counts.
query_timeis the sum of round trips (send to first response);wallis elapsed time for the node, so a step with large query_time and small wall is being hidden by parallel siblings.Refs #285 (original ask for query-level diagnostics), #644, #654. This is observability only; the N+1 fix itself is tracked in #644.
Test plan
ir/trace_test.go: span attribution and nesting, shape keys, heaviest-first ordering, concurrent recording under-racego test ./ir/... -racePGSCHEMA_TEST_FILTER=create_table/add_column go test ./cmd -run TestPlanAndApplygo test ./cmd/dump -run 'TestDumpCommand_Employee|TestDumpCommand_Sakila'go vet ./...pgschema --debug dump --schema publicagainst a local Postgres produces the tree above🤖 Generated with Claude Code