mirror of
https://github.com/block/buzz.git
synced 2026-11-13 21:01:53 +00:00
Co-authored-by: npub1t2tgm7d8f995uqvmnm8h88sg3wnpp9a5xysjf6dg3tjmgt3ltulqdp8ehr <5a968df9a7494b4e019b9ecf739e088ba61097b4312124e9a88ae5b42e3f5f3e@sprout-oss.stage.blox.sqprod.co> Signed-off-by: npub1t2tgm7d8f995uqvmnm8h88sg3wnpp9a5xysjf6dg3tjmgt3ltulqdp8ehr <5a968df9a7494b4e019b9ecf739e088ba61097b4312124e9a88ae5b42e3f5f3e@sprout-oss.stage.blox.sqprod.co> Co-authored-by: coder 0 <d97ebdbb198c7237c94f84ea8bb8a73583ea067407eebd0062abbb3962527fb1@buzz.block.builderlab.xyz> Signed-off-by: coder 0 <d97ebdbb198c7237c94f84ea8bb8a73583ea067407eebd0062abbb3962527fb1@buzz.block.builderlab.xyz>
22 lines
1.2 KiB
SQL
22 lines
1.2 KiB
SQL
-- ── Thread reply keyset pagination index ─────────────────────────────────────
|
|
-- Thread subtree reads filter by tenant and root, then page in ascending
|
|
-- (event_created_at, event_id) order. Include the keyset columns so PostgreSQL
|
|
-- can satisfy both the filter and ordering from one index scan.
|
|
--
|
|
-- Lock note: built without CONCURRENTLY because sqlx runs each migration inside
|
|
-- a transaction and CREATE INDEX CONCURRENTLY cannot run in one. This takes a
|
|
-- SHARE lock on `thread_metadata` (blocking writes, not reads) for the duration
|
|
-- of the build. `thread_metadata` is on the event insertion path and may be
|
|
-- large on brownfield databases, so operators should pre-build it by hand before
|
|
-- deploying this migration:
|
|
--
|
|
-- CREATE INDEX CONCURRENTLY idx_thread_metadata_root_keyset
|
|
-- ON thread_metadata (community_id, root_event_id, event_created_at, event_id);
|
|
--
|
|
-- IF NOT EXISTS then makes this migration a no-op on that database.
|
|
--
|
|
-- Additive migration: previously applied files must not change checksum.
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_thread_metadata_root_keyset
|
|
ON thread_metadata (community_id, root_event_id, event_created_at, event_id);
|