perf(server): index slow projection lookups #22354
Closedsisodias(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/22354/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
- @@ -0,0 +9,21 @@9+ yield* sql`10+ CREATE INDEX IF NOT EXISTS orchestration_v2_projection_turn_items_thread_type_idx11+ ON orchestration_v2_projection_turn_items(thread_id, type)12+ `;13+ yield* sql`14+ CREATE INDEX IF NOT EXISTS orchestration_v2_projection_turn_items_thread_message_idx15+ ON orchestration_v2_projection_turn_items(thread_id, json_extract(payload_json, '$.messageId'))16+ WHERE type IN ('user_message', 'assistant_message')17+ `;18+ yield* sql`19+ CREATE INDEX IF NOT EXISTS orchestration_v2_projection_turn_items_run_status_idx20+ ON orchestration_v2_projection_turn_items(run_id, status)21+ `;22+ yield* sql`23+ CREATE INDEX IF NOT EXISTS orchestration_v2_projection_runs_running_idx24+ ON orchestration_v2_projection_runs(thread_id)25+ WHERE status = 'running'26+ `;27+ yield* sql`28+ CREATE INDEX IF NOT EXISTS orchestration_v2_projection_runs_user_message_idx29+ ON orchestration_v2_projection_runs(json_extract(payload_json, '$.userMessageId'))@@ -0,0 +79,21 @@79+ GROUP BY json_extract(payload_json, '$.messageId')80+ `;81+ assert.deepEqual(afterMessages, beforeMessages);82+ const messagePlan = yield* sql<{ readonly detail: string }>`83+ EXPLAIN QUERY PLAN84+ SELECT json_extract(payload_json, '$.messageId'), MIN(ordinal)85+ FROM orchestration_v2_projection_turn_items86+ WHERE thread_id = 'thread-1' AND type IN ('user_message', 'assistant_message')87+ GROUP BY json_extract(payload_json, '$.messageId')88+ `;89+ assert.isTrue(90+ messagePlan.some((row) =>91+ row.detail.includes("orchestration_v2_projection_turn_items_thread_message_idx"),92+ ),93+ messagePlan.map((row) => row.detail).join("\n"),94+ );95+96+ const runPlan = yield* sql<{ readonly detail: string }>`97+ EXPLAIN QUERY PLAN98+ SELECT thread_id FROM orchestration_v2_projection_runs99+ WHERE json_extract(payload_json, '$.userMessageId') = 'message-1'@@ -0,0 +13,21 @@13+ yield* sql`14+ CREATE INDEX IF NOT EXISTS orchestration_v2_projection_turn_items_thread_message_idx15+ ON orchestration_v2_projection_turn_items(thread_id, json_extract(payload_json, '$.messageId'))16+ WHERE type IN ('user_message', 'assistant_message')17+ `;18+ yield* sql`19+ CREATE INDEX IF NOT EXISTS orchestration_v2_projection_turn_items_run_status_idx20+ ON orchestration_v2_projection_turn_items(run_id, status)21+ `;22+ yield* sql`23+ CREATE INDEX IF NOT EXISTS orchestration_v2_projection_runs_running_idx24+ ON orchestration_v2_projection_runs(thread_id)25+ WHERE status = 'running'26+ `;27+ yield* sql`28+ CREATE INDEX IF NOT EXISTS orchestration_v2_projection_runs_user_message_idx29+ ON orchestration_v2_projection_runs(json_extract(payload_json, '$.userMessageId'))30+ `;31+ yield* sql`32+ CREATE INDEX IF NOT EXISTS orchestration_v2_projection_provider_turns_thread_completed_idx33+ ON orchestration_v2_projection_provider_turns(thread_id, completed_at DESC)
Sign in to join this conversation.
Codex Review Summary#
This comment shows the latest Codex review activity on this pull request.
134b2e6ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.