From 6ed5151e50da0b337cb56f44d24b04cdb4f33ea5 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sat, 13 Jun 2026 00:46:06 +0200 Subject: [PATCH] fix(timeline): drop join-table indexes redundant with composite PKs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit idx_timeline_event_persons_event_id and idx_timeline_event_documents_event_id duplicated the leading column of their composite primary keys — Postgres already serves timeline_event_id lookups from the PK index, so the extra indexes only added write overhead. The inverse-side indexes (person_id, document_id) stay; they cover the FK cascade path. Deviates from the #774 task list ("all four FK columns") per PR #816 review. Co-Authored-By: Claude Opus 4.8 --- .../main/resources/db/migration/V77__add_timeline_events.sql | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/backend/src/main/resources/db/migration/V77__add_timeline_events.sql b/backend/src/main/resources/db/migration/V77__add_timeline_events.sql index aba99c10..b83745e2 100644 --- a/backend/src/main/resources/db/migration/V77__add_timeline_events.sql +++ b/backend/src/main/resources/db/migration/V77__add_timeline_events.sql @@ -56,10 +56,9 @@ CREATE TABLE timeline_event_documents ( ); -- Indexes added up-front (avoid the V62 FK-index retrofit debt): the two query columns plus --- explicit indexes on all four FK columns. +-- the inverse-side FK columns. timeline_event_id needs no extra index on either join table — +-- it is the leading column of the composite PK, so the PK index already serves those lookups. CREATE INDEX idx_timeline_events_event_date ON timeline_events (event_date); CREATE INDEX idx_timeline_events_type ON timeline_events (type); CREATE INDEX idx_timeline_event_persons_person_id ON timeline_event_persons (person_id); -CREATE INDEX idx_timeline_event_persons_event_id ON timeline_event_persons (timeline_event_id); CREATE INDEX idx_timeline_event_documents_document_id ON timeline_event_documents (document_id); -CREATE INDEX idx_timeline_event_documents_event_id ON timeline_event_documents (timeline_event_id);