Skip to content

feat(sql): emit compact displayQuery preview for wide SELECTs#127

Merged
veksen merged 1 commit into
mainfrom
veksen/display-query
Apr 29, 2026
Merged

feat(sql): emit compact displayQuery preview for wide SELECTs#127
veksen merged 1 commit into
mainfrom
veksen/display-query

Conversation

@veksen
Copy link
Copy Markdown
Member

@veksen veksen commented Apr 21, 2026

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 makes analyze() emit a displayQuery?: string preview alongside formattedQuery so the site can render a compact SELECT ... FROM … form without losing the original.

Implementation

  • New RecentQuery.displayQuery?: string, populated in RecentQuery.create() from a private static computeDisplayQuery(query) helper.
  • Algorithm comes from compactSelectList in @query-doctor/core 0.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 around parse() to debug-log and return undefined on parse failure.
  • Wire format unchanged: the existing WS queryProcessed frame and HTTP RecentQuery payloads automatically carry the new field.
  • Site side: Query-Doctor/Site#2800 (consumer + the core function itself; ships independently).

What's NOT in this PR

  • The compactor algorithm (lives in @query-doctor/core).
  • Algorithm-level edge-case tests (also in core: 28 tests covering thresholds, set-ops, CTEs, subqueries, 'FROM' literals, TRIM(FROM …), comments, escaped quotes, multi-byte safety, lowercase keywords, etc.).

Test plan

  • npm run typecheck — exits 0
  • npx vitest run src/sql/recent-query.test.ts — 29 tests, end-to-end coverage that analyze() populates displayQuery correctly across query shapes (wide SELECT, COUNT(*), DISTINCT, CTE, UNION/INTERSECT/EXCEPT, INSERT/UPDATE/DELETE, parse-failures, etc.)

🤖 Generated with Claude Code

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Query Doctor Analysis

View full run details

2 queries analyzed

2 pre-existing issues

Using assumed statistics (10000000 rows/table). For better results, sync production stats.

@Xetera
Copy link
Copy Markdown
Collaborator

Xetera commented Apr 22, 2026

I think this code has to be part of core to work with pglite too. I'm also concerned about adding yet another big string representation copy into an already large response that could be derived from the raw query

@veksen
Copy link
Copy Markdown
Member Author

veksen commented Apr 23, 2026

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.

@veksen veksen force-pushed the veksen/display-query branch 4 times, most recently from f7fb77c to 241307d Compare April 28, 2026 21:41
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>
@veksen veksen force-pushed the veksen/display-query branch from 241307d to 7631558 Compare April 29, 2026 06:48
@veksen
Copy link
Copy Markdown
Member Author

veksen commented Apr 29, 2026

moved to core

@veksen veksen merged commit ed35bcc into main Apr 29, 2026
6 checks passed
@veksen veksen deleted the veksen/display-query branch April 29, 2026 07:19
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.

2 participants