Skip to content

feat(workflows): Add index by workflow_id and pkey #1402

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

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

javirln
Copy link
Member

@javirln javirln commented Oct 16, 2024

This patch creates a new index on the workflows table by organization_id and id since there are some queries that can benefit from it. Making organization_id the first in the index since it's the most selective column.

Since the records that I have locally are not that much the PostgreSQL query engine does not leverage the use of the index and will perform a regular sequential scan, but deactivating sequential scans, we can see how it used:

# Deactivates seqscan for queries
SET SESSION enable_seqscan = off;

# Query
EXPLAIN ANALYSE
SELECT "workflows"."id",
       "workflows"."name",
       "workflows"."project",
       "workflows"."team",
       "workflows"."runs_count",
       "workflows"."created_at",
       "workflows"."deleted_at",
       "workflows"."public",
       "workflows"."organization_id",
       "workflows"."description",
       "workflows"."workflow_contract"
FROM "workflows"
WHERE ("workflows"."organization_id" = '93d02275-853c-4ad6-9d60-8f562b123fd2' AND "workflows"."deleted_at" IS NULL)
  AND "workflows"."id" IN (
                           'c6bd7e59-9ef6-40fa-91da-898853d0b2c6',
                           '71588af4-d4aa-4cbe-9926-8958b1334a95');

# Result
Bitmap Heap Scan on workflows  (cost=4.29..8.57 rows=1 width=118) (actual time=0.063..0.080 rows=2 loops=1)
  Recheck Cond: ((organization_id = '93d02275-853c-4ad6-9d60-8f562b123fd2'::uuid) AND (deleted_at IS NULL))
"  Filter: (id = ANY ('{c6bd7e59-9ef6-40fa-91da-898853d0b2c6,71588af4-d4aa-4cbe-9926-8958b1334a95}'::uuid[]))"
  Rows Removed by Filter: 26
  Heap Blocks: exact=4
  ->  Bitmap Index Scan on workflow_organization_id_id  (cost=0.00..4.29 rows=19 width=0) (actual time=0.042..0.042 rows=28 loops=1)
        Index Cond: (organization_id = '93d02275-853c-4ad6-9d60-8f562b123fd2'::uuid)
Planning Time: 0.469 ms
Execution Time: 0.150 ms

Refs: #1375

@javirln javirln requested review from migmartri and jiparis October 16, 2024 09:51
@javirln javirln merged commit f1d4092 into chainloop-dev:main Oct 16, 2024
13 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.

2 participants