From 8aac6cf92df2c48584bf4de22e722cbbd0072c40 Mon Sep 17 00:00:00 2001 From: James Maes Date: Wed, 14 Oct 2026 15:26:08 -0500 Subject: [PATCH] docs(schema): add the missing lookup, retention and FK indexes The reference Postgres schema gains six IF NOT EXISTS indexes: - assistant_usage (turn_id): ScheduledTurn.cost - assistant_turn_event (create_date), assistant_tool_call (create_date) and assistant_conversation (modify_date): the retention filters - assistant_scheduled_run (conversation_id) and (turn_id): the ON DELETE SET NULL foreign keys UPGRADE.md notes them. Co-Authored-By: Claude Opus 5.5 --- UPGRADE.md | 10 ++++++++++ docs/schema-postgres.sql | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index c68d1ef..8d6eb23 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,15 @@ # Upgrading qbit-assistant +## Index audit (2026-10-14) + +Recommended, not required: apply the "Index audit" block at the end of +`docs/schema-postgres.sql`. It adds six indexes, every one `IF NOT EXISTS`: +- usage by turn (read on each scheduled run) +- the three retention date filters (turn events, tool calls, inactive conversations) +- the two `ON DELETE SET NULL` foreign keys on `assistant_scheduled_run` + +No code change. + ## X1/Y1: channel wall and audit attribution Requires QQQ 4.1.0-RC.6. Every assistant table, process, report and widget is diff --git a/docs/schema-postgres.sql b/docs/schema-postgres.sql index e9e618f..fb6dc31 100644 --- a/docs/schema-postgres.sql +++ b/docs/schema-postgres.sql @@ -577,3 +577,14 @@ CREATE INDEX assistant_scheduled_run_owner ON assistant_scheduled_run(user_id, s -- X1/Y1: encoded audit filters can exceed the old 500-character record links. ALTER TABLE assistant_tool_call ALTER COLUMN audit_href TYPE TEXT; + +-- Index audit (2026-10-14): lookup, retention and FK paths with no leading index. +-- ScheduledTurn.cost reads usage by turn on every scheduled run. +CREATE INDEX IF NOT EXISTS assistant_usage_turn ON assistant_usage (turn_id); +-- Retention: deleteTurnEventsBefore, clearToolResultsBefore and listConversationsInactiveSince filter by date. +CREATE INDEX IF NOT EXISTS assistant_turn_event_create_date ON assistant_turn_event (create_date); +CREATE INDEX IF NOT EXISTS assistant_tool_call_create_date ON assistant_tool_call (create_date); +CREATE INDEX IF NOT EXISTS assistant_conversation_modify_date ON assistant_conversation (modify_date); +-- ON DELETE SET NULL children: deleting a conversation or turn would scan scheduled runs without these. +CREATE INDEX IF NOT EXISTS assistant_scheduled_run_conversation ON assistant_scheduled_run (conversation_id); +CREATE INDEX IF NOT EXISTS assistant_scheduled_run_turn ON assistant_scheduled_run (turn_id); -- 2.54.0