From 424db02ad45b17b792bf3650ea7f5bf55400b58f Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Mon, 29 Jun 2026 12:17:52 -0700 Subject: [PATCH] Add comment threads reverse lookup index --- ddl/migrations/0226_comment_threads_comment_id_idx.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 ddl/migrations/0226_comment_threads_comment_id_idx.sql diff --git a/ddl/migrations/0226_comment_threads_comment_id_idx.sql b/ddl/migrations/0226_comment_threads_comment_id_idx.sql new file mode 100644 index 00000000..ec227235 --- /dev/null +++ b/ddl/migrations/0226_comment_threads_comment_id_idx.sql @@ -0,0 +1,10 @@ +-- Supports deferred comment triggers that classify a freshly inserted comment +-- by checking whether it has a comment_threads row: +-- +-- WHERE comment_id = ? +-- +-- The primary key is ordered as (parent_comment_id, comment_id), which is ideal +-- for parent-thread lookups but not for this reverse lookup used during comment +-- create handling. +CREATE INDEX CONCURRENTLY IF NOT EXISTS comment_threads_comment_id_idx + ON public.comment_threads USING btree (comment_id);