openvibers/openrestream Commits

outbox: partial index for the rejected count (#232)

OP OpenVibers committed 5 days ago · 35783f699a · 1 file, +7 −0

The SDK's status().rejected counts rows WHERE rejected_at IS NOT NULL, and the outbox has no index on it: the count reads the whole table. Add the partial index for event_outbox as an expand migration. openvibe-sdk 0.99.0 ships the same index in outboxSchema() for new outboxes.

Changes

ddiff --git a/migrations/0007_outbox_rejected_index.sql b/migrations/0007_outbox_rejected_index.sql
nnew file mode 100644
iindex 0000000..833da61
---- /dev/null
++++ b/migrations/0007_outbox_rejected_index.sql
@@@ -0,0 +1,7 @@
++-- phase: expand
++-- The SDK's outbox status().rejected counts SELECT count(*) FROM event_outbox WHERE rejected_at IS NOT NULL.
++-- Without an index on rejected_at that count reads the whole outbox (0 rejected rows still cost 523 ms and
++-- 112 M buffers a day on Deals on 2026-11-08). This partial index holds only rejected rows, so the count is an
++-- index-only scan over an index that is usually empty. openvibe-sdk 0.99.0 adds the same index to outboxSchema()
++-- for new outboxes; this table already exists, so the statement goes here.
++CREATE INDEX IF NOT EXISTS event_outbox_rejected ON event_outbox (rejected_at) WHERE rejected_at IS NOT NULL;