openvibers/openvibe.connect Commits

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

OP OpenVibers committed 5 days ago · 8c886777cb · 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 service_outbox as an expand migration. openvibe-sdk 0.99.0 ships the same index in outboxSchema() for new outboxes.

Changes

ddiff --git a/migrations/0014_outbox_rejected_index.sql b/migrations/0014_outbox_rejected_index.sql
nnew file mode 100644
iindex 0000000..5a90cb9
---- /dev/null
++++ b/migrations/0014_outbox_rejected_index.sql
@@@ -0,0 +1,7 @@
++-- phase: expand
++-- The SDK's outbox status().rejected counts SELECT count(*) FROM service_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 service_outbox_rejected ON service_outbox (rejected_at) WHERE rejected_at IS NOT NULL;