Files
lincodex/backend/db/migrations/00004_add_outbox_relay_index.sql
T

14 lines
639 B
SQL

-- +goose Up
-- Supports the relay check that an outbox row is the earliest unpublished
-- event of its aggregate. The relay publishes only that row for each
-- aggregate per pass, so the check runs once for every candidate row. Without
-- this index the lookup reads every published event of the aggregate through
-- the unique key. The index covers only unpublished rows and shrinks as
-- events are published.
CREATE INDEX outbox_events_unpublished_aggregate_idx
ON outbox_events (aggregate_type, aggregate_id, aggregate_version, position)
WHERE published_at IS NULL;
-- +goose Down
DROP INDEX outbox_events_unpublished_aggregate_idx;