feat(sql): emit compact displayQuery preview for wide SELECTs#127
Open
feat(sql): emit compact displayQuery preview for wide SELECTs#127
Conversation
Splices the top-level SELECT target list out of the query string using libpg_query AST offsets + token scan for the terminating FROM keyword, so the site can render "SELECT ... FROM users WHERE id = $1" instead of a dozen columns crowding a line-clamp cell. Skips non-SELECT, set-ops, short lists (≤2 targets and ≤40 chars), and parse failures — the site falls back to query when undefined. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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 |
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
computeDisplayQuery()that parses with libpg_query and scans tokens with paren-depth tracking to splice the top-level SELECT target list out of the original query string, yielding previews likeSELECT ... FROM users WHERE id = \$1.displayQuery?: stringonRecentQuery(populated inanalyze()next toformattedQuery) so it flows through the existing WSqueryProcessedframe and HTTP payloads automatically. Skips non-SELECT, UNION/INTERSECT/EXCEPT, targetless SELECTs, short lists (≤2 targets AND ≤40 chars), and parse failures — site falls back toquerywhen undefined.FROM.Site side: Query-Doctor/Site#2800
Test plan
npx vitest run src/sql/display-query.test.ts src/sql/recent-query.test.ts— 52 tests, covering below-threshold, wide SELECT, subquery/CTE both directions, COUNT(*), DISTINCT, line comment in target list, UNION/INTERSECT/EXCEPT, trailing;, unparseable, non-SELECT,'FROM'string literal,TRIM(FROM …), lowercase keywords, multi-byte splicenpx vitest runfull suite — 195 tests passnpm run typecheckclean🤖 Generated with Claude Code