You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PostgreSQL: index for the AT_TIMESTAMP stream seek needs a data migration #467
The AT_TIMESTAMP seek on PostgreSQL runs SELECT MIN(sequence_number) FROM stream_records WHERE shard_id = $1 AND created_at >= $2. The planner takes the minimum off the (shard_id, sequence_number) primary key and applies created_at as a heap filter; the global created_at index cannot yield the minimum sequence without a sort, so it is not chosen. With sequence and creation time correlated, a seek near the tip filters the whole shard.
Measured on one shard of 100,000 records with created_at spread over 24 hours: a seek at the start answers in 0.04 ms (first row qualifies), a mid-range seek in 9.46 ms (49,999 rows removed by filter), a seek near the tip in 19.21 ms (99,899 rows removed). Linear in shard size beyond that.
A covering index (shard_id, created_at, sequence_number) gives the minimum directly. It needs a data migration file under crates/storage-postgres/data_migrations/ and an entry in migrations::DATA_MIGRATIONS, which means existing deployments run extenddb migrate before the upgraded binary serves, and the catalog-converge and backup tests that enumerate the migration list need the new file added. That upgrade step is why the index is not part of the feature change; GetShardIterator runs about once per consumer resume, so the cost is tolerable until a hot shard holds millions of records.
MongoDB and SQLite got their (shard_id, created_at) index in the feature change itself, since both create indexes idempotently at startup.
#468 no longer adds the (shard_id, created_at) index on SQLite and MongoDB. Main moved both schemas into numbered catalog migrations, so the index now needs a migration on SQLite and MongoDB as well as PostgreSQL.
Until then the AT_TIMESTAMP seek uses the existing (shard_id, sequence_number) index on all three. Cassandra needs no index, because its seek reads one shard's sequence range in one partition.
Activity
LeeroyHannigan commentedon Nov 14, 2026
#468 no longer adds the
(shard_id, created_at)index on SQLite and MongoDB. Main moved both schemas into numbered catalog migrations, so the index now needs a migration on SQLite and MongoDB as well as PostgreSQL.Until then the AT_TIMESTAMP seek uses the existing
(shard_id, sequence_number)index on all three. Cassandra needs no index, because its seek reads one shard's sequence range in one partition.