feat(sql): emit compact displayQuery preview for wide SELECTs#127
Merged
Conversation
There was a problem hiding this comment.
Query Doctor Analysis
2 queries analyzed
2 pre-existing issues
SELECT "guests"."id", "guests"."session_id", "guests"."username", "guests"."avatar_path", "guests"."color", "guests"."side", "guests"."audio_recording_path", "guests"."audio_recording_public", "gue...
indexassets(event_id, inserted_at desc)
cost 31,003,449 → 1,493 (100% reduction)SELECT * FROM guest_ip_addresses WHERE ip_address = '127.0.0.1';
indexguest_ip_addresses(ip_address)
cost 154,402 → 8 (100% reduction)
Using assumed statistics (10000000 rows/table). For better results, sync production stats.
Collaborator
|
I think this code has to be part of |
Member
Author
|
The problem with doing it with the raw query is the amount of edge cases there are if we try to do it with regex. |
f7fb77c to
241307d
Compare
Populate RecentQuery.displayQuery via compactSelectList from @query-doctor/core 0.8.7 — a display-only preview with the top-level SELECT target list replaced by `...`, e.g. `SELECT ... FROM users WHERE id = $1`. The site renders this in its truncated cells (live queries list, sidebar, detail header, CI run list/detail, project catalog) so ORM-written queries with long target lists stop drowning out the table/filter parts. The algorithm lives in @query-doctor/core so the analyzer service and the in-browser pglite path call the same implementation. Site side: Query-Doctor/Site#2800. RecentQuery.computeDisplayQuery wraps the call in a try/catch around parse() so a parse failure debug-logs and returns undefined; the site then falls back to the raw query. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
241307d to
7631558
Compare
Member
Author
|
moved to core |
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.
Summary
ORM-written queries with long target lists (
SELECT col1, col2, …, col30 FROM users …) dominate the truncated cells across the site's live-queries list, sidebar, detail header, CI run list/detail, and project catalog. This PR makesanalyze()emit adisplayQuery?: stringpreview alongsideformattedQueryso the site can render a compactSELECT ... FROM …form without losing the original.Implementation
RecentQuery.displayQuery?: string, populated inRecentQuery.create()from a private staticcomputeDisplayQuery(query)helper.compactSelectListin@query-doctor/core0.8.7+, imported and called with the parsed AST. Single source of truth — same function the in-browser pglite path calls. Wraps the call in a try/catch aroundparse()to debug-log and returnundefinedon parse failure.queryProcessedframe and HTTPRecentQuerypayloads automatically carry the new field.What's NOT in this PR
@query-doctor/core).'FROM'literals,TRIM(FROM …), comments, escaped quotes, multi-byte safety, lowercase keywords, etc.).Test plan
npm run typecheck— exits 0npx vitest run src/sql/recent-query.test.ts— 29 tests, end-to-end coverage thatanalyze()populatesdisplayQuerycorrectly across query shapes (wide SELECT, COUNT(*), DISTINCT, CTE, UNION/INTERSECT/EXCEPT, INSERT/UPDATE/DELETE, parse-failures, etc.)🤖 Generated with Claude Code