Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Instance History indexing to checksum & uuid fields #2564

Merged
merged 1 commit into from
Mar 7, 2024

Conversation

KipSigei
Copy link
Contributor

@KipSigei KipSigei commented Mar 7, 2024

Changes / Features implemented

  • Create indexing for uuid and checksum columns on the Instance History table

Steps taken to verify this change does what is intended

  • Applied migrations and ran EXPLAIN ANALYZE on a query against the logger_instancehistory table

Side effects of implementing this change

  • Optimizes ORDER BY queries against the Instance History table
db=> EXPLAIN ANALYZE SELECT "logger_instancehistory"."id", "logger_instancehistory"."xform_instance_id" FROM "logger_instancehistory" INNER JOIN "logger_instance" ON ("logger_instancehistory"."xform_instance_id" = "logger_instance"."id") WHERE ("logger_instancehistory"."uuid" = 'random-uuid' AND "logger_instance"."deleted_at" IS NULL AND "logger_instance"."xform_id" = <xform_id>) ORDER BY "logger_instancehistory"."id" ASC LIMIT 1;
                                                                                QUERY PLAN                                                                                
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=15.97..15.98 rows=1 width=8) (actual time=0.020..0.020 rows=0 loops=1)
   ->  Sort  (cost=15.97..15.98 rows=1 width=8) (actual time=0.019..0.020 rows=0 loops=1)
         Sort Key: logger_instancehistory.id
         Sort Method: quicksort  Memory: 25kB
         ->  Nested Loop  (cost=1.12..15.96 rows=1 width=8) (actual time=0.016..0.016 rows=0 loops=1)
               ->  Index Scan using logger_instancehistory_uuid_idx on logger_instancehistory  (cost=0.56..5.61 rows=4 width=8) (actual time=0.015..0.015 rows=0 loops=1)
                     Index Cond: ((uuid)::text = '<random-uuid>'::text)
               ->  Index Scan using logger_instance_id_xform_id_index on logger_instance  (cost=0.57..2.59 rows=1 width=4) (never executed)
                     Index Cond: ((xform_id = <xform-id>) AND (id = logger_instancehistory.xform_instance_id))
                     Filter: (deleted_at IS NULL)
 Planning Time: 0.276 ms
 Execution Time: 0.039 ms
(12 rows)

Before submitting this PR for review, please make sure you have:

  • Included tests
  • Updated documentation

Closes #

@KipSigei KipSigei force-pushed the add-instance-history-indexing branch from 7ace3b7 to 96214c7 Compare March 7, 2024 07:41
@KipSigei KipSigei merged commit 7c60107 into main Mar 7, 2024
9 checks passed
@KipSigei KipSigei deleted the add-instance-history-indexing branch March 7, 2024 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants