Explain why utility statements have no query plan - #414
Conversation
The Query Plan panel built its request by concatenating EXPLAIN with the captured statement text, but pg_stat_statements records utility and DDL commands as well as DML, so a Top Queries row can hold bare VACUUM, ANALYZE, REINDEX or CLUSTER text. PostgreSQL's EXPLAIN accepts only SELECT, INSERT, UPDATE, DELETE, MERGE, VALUES, EXECUTE, DECLARE, CREATE TABLE AS and CREATE MATERIALIZED VIEW (the grammar additionally accepts REFRESH MATERIALIZED VIEW), so those requests could only ever fail, and the panel rendered the raw syntax error back at the user. The new sqlHelpers module classifies a statement from its leading keyword, ignoring leading whitespace, comments and parentheses, and useQueryPlan now reports the statement type through notExplainable rather than issuing a doomed request; the panel renders a friendly informational message naming the statement type instead of a Postgres syntax error. The classification was verified against PostgreSQL 18. Closes #368
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 51 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
Comment |
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| ErrorProne | 2 high (2 false positives) |
| Security | 1 high |
🟢 Metrics 45 complexity
Metric Results Complexity 45
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
Closing in favour of #385, which fixes the same issue more correctly. Verified against PostgreSQL 18.4: The |
Summary
The Query Plan panel built its request by concatenating
EXPLAINwiththe captured statement text, and because
pg_stat_statementsrecordsutility and DDL commands alongside DML, a Top Queries row can hold bare
VACUUM,ANALYZE,REINDEX ...orCLUSTER ...text; wrapping anyof those in
EXPLAINis invalid SQL, so the panel surfaced a rawsyntax error at or near "VACUUM"back at the user.This change adds
client/src/utils/sqlHelpers.ts, which classifies astatement from its leading keyword after skipping leading whitespace,
line and block comments, and opening parentheses.
useQueryPlannowchecks that classification before building the request and reports the
statement type through a new
notExplainablefield instead of firing arequest that can only fail, whilst
QueryPlanPanelrenders a friendlyinformational alert naming the statement type in place of the Postgres
error.
The explainable set is SELECT, INSERT, UPDATE, DELETE, MERGE, VALUES,
EXECUTE, DECLARE, WITH, TABLE, CREATE TABLE AS and CREATE MATERIALIZED
VIEW, plus REFRESH MATERIALIZED VIEW, which the EXPLAIN grammar accepts
even though the documentation omits it. Every case in the test tables
was verified empirically against PostgreSQL 18.4 rather than assumed.
Test plan
sqlHelpersunit tests cover keyword extraction, comment andparenthesis stripping, and eighteen explainable and twenty-three
non-explainable statements; the file reports 100% line, branch and
function coverage.
useQueryPlantests assert that VACUUM, ANALYZE, REINDEX,CLUSTER, CREATE INDEX and TRUNCATE issue no API call at all, that the
detected keyword is reported, and that the flag clears when a
plannable query follows; the hook reports 98.68% line coverage.
QueryPlanPaneltests assert the friendly message renders, thatthe plan tabs stay hidden, and that the notice takes precedence over
a stale error; the component reports 100% line coverage.
npm run lintreports 0 errors, andnpm run buildsucceeds.Closes #368