Skip to content

Commit 55ada73

Browse files
committed
Document Queries feature behavior
1 parent 820396a commit 55ada73

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

Architecture/query-insights.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ The query table uses the per-query samples as follows:
116116
- First-snapshot context rows show one representative execution with average per-execution counters so a fresh view can still show useful rows without pretending the whole cumulative provider history happened inside the selected window.
117117
- The detail sheet and AI recommendation prompt use the same selected-window query row shown in the table.
118118

119+
## View Interaction Contract
120+
121+
- The `Queries` view MUST render under the Studio `Visualizer` navigation item and MUST NOT be available when `Adapter.queryInsights` is absent.
122+
- The top-level description SHOULD explain that Studio monitors database activity and helps identify poorly performing queries.
123+
- The activity chart MUST show `Queries/s` and `Avg latency` summaries, share one selected range with the query table, and expose `1m`, `5m`, `15m`, and `1h` range controls.
124+
- The query table SHOULD include `Latency`, `Query`, `Executions`, `Rows Returned`, and `Last Seen` columns. `Rows Returned` is the user-facing label for `rowsReturned`; `reads` remains an internal and AI-prompt signal.
125+
- When AI recommendations are available, the query table SHOULD add an `Analysis` column with queued, running, manual analyze, and completed severity states.
126+
- The table filter SHOULD use touched tables derived from the selected-window rows, not from stale cumulative provider data.
127+
- Sorting SHOULD operate on selected-window row values, not provider cumulative counters.
128+
- Clicking a query row SHOULD open a detail sheet with SQL, touched tables, selected-window metrics, and optional recommendations.
129+
- The detail sheet SHOULD support previous/next navigation through the currently visible sorted table rows.
130+
- Pause/resume SHOULD stop and restart polling the provider without clearing already retained local samples.
131+
119132
## @prisma/sqlcommenter-query-insights Mapping
120133

121134
When SQL includes `@prisma/sqlcommenter-query-insights` metadata, embedders SHOULD remove the `prismaQuery` tag from the displayed `query` and map it into `prismaQueryInfo`.
@@ -263,4 +276,9 @@ Changes to query insights MUST include tests covering:
263276
- navigation visibility and stale `view=queries` fallback
264277
- rendering provider snapshots in the Queries view
265278
- hiding AI recommendations when no `llm` hook is configured
279+
- chart and table metrics scoped to the selected time range
280+
- first-snapshot context rows that do not create fake throughput
281+
- cumulative counter deltas, counter resets, and stale/equal snapshots
282+
- long chart gaps, short connected gaps, and isolated sample markers
283+
- serial automatic AI analysis with the five-query cap and manual analysis beyond that cap
266284
- demo aggregation behavior for successful query executions

FEATURES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ Users can pan/zoom, inspect key and nullable markers, and jump from a node direc
141141
Embedders can optionally provide live query snapshots through Studio's BFF bridge, and Studio shows them in a dedicated `Queries` view directly under the schema visualizer.
142142
The view plots live query throughput and average latency from recent snapshot rows and successive snapshot updates, defaulting to the most recent 5 minutes with quick switches for 1 minute, 15 minutes, and 1 hour. The chart summary and query list follow the selected time window, including row execution and rows-returned counters, while historical first-snapshot rows render as latency context points instead of fake throughput spikes or cumulative totals. Live throughput points use one-second buckets at the query's observed time, live lines stay connected across short bursts, long unmeasured gaps break into separate segments, isolated samples render as points, and hovering the plot shows exact readings.
143143
Users can filter by touched table, sort by operational signals, and open a detail sheet for SQL, metrics, query metadata, and optional recommendations.
144+
The table labels returned-row volume as `Rows Returned`, while lower-level read estimates remain available to AI prompts and sort logic when a provider can supply them.
144145
When Studio's shared `llm` hook is available, the query table adds an Analysis column that analyzes newly observed query groups in the background, one at a time, and stops automatic work after the first five groups. Rows show a running indicator, a manual Analyze action, and a completed all-good, info, or warning icon; the detail sheet uses the same analysis queue for manual recommendations. Without that hook, the AI analysis UI is hidden.
145146
If an embedder does not provide query insights, Studio hides the `Queries` menu item and stale `view=queries` URLs fall back to the normal default view.
146147

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,23 @@ const adapter = createPostgresAdapter({
240240

241241
If your BFF does not implement `query-insights`, leave `queryInsights` undefined. Studio will hide the `Queries` menu item and stale `view=queries` URLs will fall back to the normal default view.
242242

243+
What the `Queries` view renders:
244+
245+
- a live chart for `Queries/s` and average latency with `1m`, `5m`, `15m`, and `1h` ranges
246+
- a query table with `Latency`, sanitized SQL, `Executions`, `Rows Returned`, `Last Seen`, and optional `Analysis`
247+
- table filtering and sorting by rows returned, latency, execution count, or last-seen time
248+
- a detail sheet with the selected query SQL, touched tables, selected-window metrics, and optional AI recommendations
249+
- a pause/resume control for polling the injected snapshot provider
250+
251+
The chart and table always use the same selected time range. Studio derives visible `Executions`, `Rows Returned`, reads, latency, and last-seen values from the samples it can place inside that range; it does not show cumulative provider counters as if they all happened in the visible window. The first snapshot can still show recent rows as context when their `lastSeen` timestamp is inside the selected range, but those context rows do not create live throughput values.
252+
243253
Consumer migration notes:
244254

245255
- The Studio route is `#view=queries`. Do not link to `#view=query-insights`.
246256
- `queryInsights` is an adapter capability, not a top-level `<Studio />` prop. Pass it into `createPostgresAdapter`, `createMySQLAdapter`, or `createSQLiteAdapter` alongside the executor.
247257
- The packaged BFF bridge uses snapshot polling with `procedure: "query-insights"`. Studio does not require a Prisma Streams `streamUrl`; hosts with SSE, pg_stat_statements, ppg.query_stats, proxy logs, or control-plane telemetry should adapt that source into a `StudioQueryInsightsSnapshot`.
248258
- AI recommendations use the shared `llm` hook with `task: "query-insights"`. Studio does not expose a separate query-specific `analyze()` or `enableAiRecommendations()` transport. Hosts that need consent should enforce it in the `llm` implementation they pass to Studio.
259+
- Automatic AI analysis runs serially, with at most one `llm` request in flight, and stops after the first five automatically discovered query groups. Users can still manually analyze additional rows from the table or detail sheet.
249260

250261
Snapshot rows should be aggregated by a stable normalized query identity. Do not send raw parameter values or sensitive payloads; use parameterized SQL or another sanitized query representation. `reads`, `rowsReturned`, `duration`, `count`, and `lastSeen` are best-effort operational signals for display and sorting, not accounting-grade telemetry. Studio derives visible chart and table metrics from deltas between cumulative snapshots inside the selected time window; it does not display cumulative provider counters as selected-window totals. A first snapshot can render recent rows as context, but live throughput is only available after Studio has two increasing snapshots to compare.
251262

0 commit comments

Comments
 (0)