Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): message ordinals are read through an index, not a scan #30873

Mergednavidnadali(GitHub profile, opens in a new tab)merged 24 commits intomain fromrefs/pull/30873/headmerged by juliusmarminge View on GitHub

Showing 8 changed files with 196 additions and 15 deletions (loading 5).

x
0 of 8 viewed, 8 left
3 additions and 1 deletionapps/server/src/orchestration-v2/Orchestrator.control-reads.test.tsModified
View file
@@ -2671,7 +2671,9 @@
(detail.includes("TEMP B-TREE FOR GROUP BY") && query.includes("json_each")) ||
(/^SEARCH .*(node|turn_item).* \(thread_id=\?\)$/.test(detail) &&
- !detail.includes("USING COVERING INDEX")) ||
+ !detail.includes("USING COVERING INDEX") &&
+ // That full ordering pass, through an index that holds only message items.
+ !(detail.includes("message_ordinal_idx") && !query.includes("json_each"))) ||
// Every active run in the environment, not only this thread's.
/^SEARCH .*runs.* \(status=\?\)$/.test(detail) ||
// A status-filtered read that fetches every typed row to check its status.
188 additions and 11 deletionsapps/server/src/orchestration-v2/ProjectionStore.test.tsModified
View file
@@ -1311,17 +1311,8 @@
.pipe(Effect.withTracer(tracer));
assert.lengthOf(userMessages.messages, 3);
const ordinalLookup = statements.find((statement) => statement.includes("MIN(ordinal)"));
- assert.isDefined(ordinalLookup);
- const sql = yield* SqlClient.SqlClient;
- const plan = (yield* sql.unsafe<{ readonly detail: string }>(
- `EXPLAIN QUERY PLAN ${ordinalLookup}`,
- [threadId, "[]"],
- )).map((row) => row.detail);
- // User-only reads must stay on a type-bounded index instead of scanning every turn item.
- assert.isTrue(
- plan.some((detail) => /turn_items_(user_message|thread_type)_idx/.test(detail)),
- plan.join("\n"),
- );