-
Task
-
Resolution: Unresolved
-
Normal
-
None
-
None
-
None
-
5
-
False
-
-
False
-
Impediment
-
subs-swatch-thunder
-
-
- Review existing indexes on the tally_snapshots table.
- Create a new partial index that can help with read and doesn't affect write process or update existing indexes.
- Check if runInTransaction=false helps since CREATE INDEX CONCURRENTLY cannot run inside a transaction and having this avoids locking issues on the 198M row table. https://docs.liquibase.com/reference-guide/changelog-attributes/runintransaction
- Ensure the index aligns with current query patterns and filtering conditions. Not sure if adding snapshot_date in index will be helpful.
- Include migration and rollback support for index changes.
- Since is_primary defaults to false and index is WHERE true, the index starts empty (should be fast even with 198M)
Example:
<changeSet id="" author="" runInTransaction="false"> <sql> CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_tally_snapshots_primary ON tally_snapshots (org_id, product_id, granularity) WHERE is_primary = true; </sql> <rollback> DROP INDEX IF EXISTS idx_tally_snapshots_primary; </rollback> </changeSet>
We can also try the same locally, by directly doing below for testing purpose
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_tally_snapshots_primary
ON tally_snapshots (org_id, product_id, granularity)
WHERE is_primary_record = true;
AC:
- Index is added to the table
- No functional impact to existing queries or data.
- blocks
-
SWATCH-4493 Add REST endpoint to backfill is_primary in tally_snapshots
-
- Backlog
-
- is blocked by
-
SWATCH-4491 Add is_primary column to tally_snapshots Table and update JPA Entity
-
- Review
-