Uploaded image for project: 'Subscription Watch'
  1. Subscription Watch
  2. SWATCH-4492

Add partial index on tally_snapshots

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: Normal Normal
    • None
    • None
    • swatch-tally
    • None
    • 5
    • False
    • Hide

      None

      Show
      None
    • 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.

              Unassigned Unassigned
              karshah@redhat.com Kartik Shah
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: