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

Adding an index on org_id, correlation_id and status on runs #343

Conversation

dehort
Copy link
Contributor

@dehort dehort commented Feb 21, 2024

  • research concurrently on the create index
  • test with more data
insights=# EXPLAIN ANALYZE UPDATE runs SET status='running', events='{}', updated_at=NOW() WHERE (org_id = '5318290') AND (correlation_id = '7978185d-88c8-47f3-8273-bbeaf67d67c9') AND status not in ('success','failure');
                                                                                    QUERY PLAN                                                                                     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Update on runs  (cost=0.00..479.00 rows=1 width=286) (actual time=1.225..1.225 rows=0 loops=1)
   ->  Seq Scan on runs  (cost=0.00..479.00 rows=1 width=286) (actual time=1.224..1.224 rows=0 loops=1)
         Filter: ((status <> ALL ('{success,failure}'::runs_status[])) AND ((org_id)::text = '5318290'::text) AND (correlation_id = '7978185d-88c8-47f3-8273-bbeaf67d67c9'::uuid))
         Rows Removed by Filter: 10000
 Planning Time: 0.099 ms
 Execution Time: 1.251 ms
(6 rows)

insights=# create index idx_new_index on runs (org_id, correlation_id, status);
CREATE INDEX
insights=# EXPLAIN ANALYZE UPDATE runs SET status='running', events='{}', updated_at=NOW() WHERE (org_id = '5318290') AND (correlation_id = '7978185d-88c8-47f3-8273-bbeaf67d67c9') AND status not in ('success','failure');
                                                          QUERY PLAN                                                          
------------------------------------------------------------------------------------------------------------------------------
 Update on runs  (cost=0.29..8.31 rows=1 width=286) (actual time=0.009..0.009 rows=0 loops=1)
   ->  Index Scan using idx_new_index on runs  (cost=0.29..8.31 rows=1 width=286) (actual time=0.009..0.009 rows=0 loops=1)
         Index Cond: (((org_id)::text = '5318290'::text) AND (correlation_id = '7978185d-88c8-47f3-8273-bbeaf67d67c9'::uuid))
         Filter: (status <> ALL ('{success,failure}'::runs_status[]))
 Planning Time: 0.130 ms
 Execution Time: 0.025 ms
(6 rows)

@dehort
Copy link
Contributor Author

dehort commented Mar 14, 2024

I modified this update statement to include the run id (primary key...indexed) in the where clause.

@dehort dehort closed this Mar 14, 2024
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.

1 participant