Skip to content

perf(ai): run_sql seeks trace-id lookups through trace_index and stops at the row cap - #1960

Merged
Makisuo merged 16 commits into
fix/run-sql-identifier-hintsfrom
perf/run-sql-trace-seek-row-cap
Oct 30, 2026
Merged

Makisuo merged 16 commits into
fix/run-sql-identifier-hintsfrom
perf/run-sql-trace-seek-row-cap

Merge branch 'fix/run-sql-identifier-hints' into perf/run-sql-trace-s…

c25d423
Select commit
Loading
Failed to load commit list.
Maple Review Bot / Maple / review succeeded Oct 30, 2026 in 1m 35s

Confidence 10/10 · No issues found

🟢 Confidence 10/10 · safe to merge
The sql-identifiers edits come from the base branch, and F5 cannot fire: only a statement-terminal LIMIT matches the end-anchored OWN_LIMIT.
no findings · tests covered · risk medium

run_sql now seeks literal trace-id reads through trace_index and truncates at the 1,000-row cap with an atRowCap notice instead of failing. The seek is added only where it cannot change rows, and the cap notice stays truthful. Safe to merge.

  • withTraceIndexSeek ANDs the trace_index seek onto an unbounded literal trace-id conjunct
  • run_sql falls back to the SQL as written when the seeked form is refused as invalid SQL
  • truncateAtCap makes the row-cap wrapper fetch 1,000 rows instead of 1,001
  • atRowCap is reported unless the statement's own terminal LIMIT asked for a full page

Fixed since the last review

  • ✅ F5 · limitedWithinCap reads a subquery LIMIT as the statement's own cap
What was checked
  • Ran OWN_LIMIT in node: a nested LIMIT is always followed by ), so only a statement-terminal one matches
  • The seek text matches inTraces (packages/query-engine/src/ch/tables.ts:142) over the same trace_index sort-key prefix
  • The added $__orgFilter inside the seek subquery passes orgFilterIssue (its WHERE is its own scope), so the seeked form validates

c25d423 · Updated on every push. Reply "won't fix" to dismiss a finding, or mention @maple-review-bot to ask about one.