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 index for run id lookup in response-consumer #369

Conversation

dehort
Copy link
Contributor

@dehort dehort commented Jun 25, 2024

SELECT "id","status","response_full" FROM "runs" WHERE (org_id = '5318290') AND (correlation_id = '7978185d-88c8-47f3-8273-bbeaf67d67c9') ORDER BY "runs"."id" LIMIT 50

;
                                                           QUERY PLAN                                                           
--------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=51.57..51.58 rows=1 width=21) (actual time=0.233..0.234 rows=0 loops=1)
   ->  Sort  (cost=51.57..51.58 rows=1 width=21) (actual time=0.233..0.233 rows=0 loops=1)
         Sort Key: id
         Sort Method: quicksort  Memory: 25kB
         ->  Seq Scan on runs  (cost=0.00..51.56 rows=1 width=21) (actual time=0.229..0.229 rows=0 loops=1)
               Filter: (((org_id)::text = '5318290'::text) AND (correlation_id = '7978185d-88c8-47f3-8273-bbeaf67d67c9'::uuid))
               Rows Removed by Filter: 1104
 Planning Time: 0.112 ms
 Execution Time: 0.274 ms
(9 rows)

playbook-dispatcher=# CREATE INDEX concurrently if not exists runs_org_id_service_created_at_desc_index ON runs (org_id, correlation_id, id);
CREATE INDEX
playbook-dispatcher=# explain analyze                                                                                                        
SELECT "id","status","response_full" FROM "runs" WHERE (org_id = '5318290') AND (correlation_id = '7978185d-88c8-47f3-8273-bbeaf67d67c9') ORDER BY "runs"."id" LIMIT 50

;

create index

playbook-dispatcher=# explain analyze 
SELECT "id","status","response_full" FROM "runs" WHERE (org_id = '5318290') AND (correlation_id = '7978185d-88c8-47f3-8273-bbeaf67d67c9') ORDER BY "runs"."id" LIMIT 50

;
                                                                      QUERY PLAN                                                                       
-------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=0.28..8.30 rows=1 width=21) (actual time=0.010..0.010 rows=0 loops=1)
   ->  Index Scan using runs_org_id_service_created_at_desc_index on runs  (cost=0.28..8.30 rows=1 width=21) (actual time=0.008..0.008 rows=0 loops=1)
         Index Cond: (((org_id)::text = '5318290'::text) AND (correlation_id = '7978185d-88c8-47f3-8273-bbeaf67d67c9'::uuid))
 Planning Time: 0.106 ms
 Execution Time: 0.021 ms
(5 rows)


Copy link
Member

@tahmidefaz tahmidefaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 🤞

@dehort
Copy link
Contributor Author

dehort commented Jun 25, 2024

/retest

@dehort
Copy link
Contributor Author

dehort commented Jun 25, 2024

Kicking off another test...

I want to hop on the ephemeral env and make sure the db migration looks like it did the right thing.

@dehort
Copy link
Contributor Author

dehort commented Jun 25, 2024


playbook-dispatcher=# \di
                                        List of relations
 Schema |                  Name                   | Type  |      Owner       |       Table       
--------+-----------------------------------------+-------+------------------+-------------------
 public | run_hosts_pkey                          | index | BZV8qO2CxQdYnlb8 | run_hosts
 public | run_hosts_run_id_host_key               | index | BZV8qO2CxQdYnlb8 | run_hosts
 public | runs_labels_index                       | index | BZV8qO2CxQdYnlb8 | runs
 public | runs_org_id_correlation_id_run_id_index | index | BZV8qO2CxQdYnlb8 | runs
 public | runs_org_id_index                       | index | BZV8qO2CxQdYnlb8 | runs
 public | runs_pkey                               | index | BZV8qO2CxQdYnlb8 | runs
 public | schema_migrations_pkey                  | index | BZV8qO2CxQdYnlb8 | schema_migrations
(7 rows)

playbook-dispatcher=# select * from schema_migrations ;
 version | dirty 
---------+-------
      15 | f

@dehort dehort merged commit 94a284e into RedHatInsights:master Jun 25, 2024
13 of 18 checks passed
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.

None yet

2 participants