Skip to content

Conversation

jiparis
Copy link
Member

@jiparis jiparis commented Sep 8, 2025

This query is not ordered, so the index cannot be used directly. Instead, Postgresql was partially using a different index (workflowrun_state_finished_at), and then filtering by creating_at, adding an additional performance penalization.

Limit  (cost=0.29..6.07 rows=1 width=250) (actual time=0.133..0.134 rows=0 loops=1)
  ->  Index Scan using workflowrun_state_finished_at on workflow_runs  (cost=0.29..6.07 rows=1 width=250) (actual time=0.131..0.132 rows=0 loops=1)
        Index Cond: ((state)::text = 'initialized'::text)
        Filter: (created_at <= '2025-06-25 11:42:12.793517+00'::timestamp with time zone)
Planning Time: 1.043 ms
Execution Time: 0.245 ms

With the fixed index, the query is fully optimized:

Limit  (cost=0.29..8.31 rows=1 width=249) (actual time=0.056..0.056 rows=0 loops=1)
  ->  Index Scan using workflowrun_state_created_at on workflow_runs  (cost=0.29..8.31 rows=1 width=249) (actual time=0.055..0.055 rows=0 loops=1)
        Index Cond: (((state)::text = 'initialized'::text) AND (created_at <= '2025-06-25 11:42:12.793517+00'::timestamp with time zone))
Planning Time: 0.674 ms
Execution Time: 0.099 ms

Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Copy link
Member

@migmartri migmartri left a comment

Choose a reason for hiding this comment

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

Dont forget

-- atlas:txmode none

Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
@jiparis
Copy link
Member Author

jiparis commented Sep 9, 2025

Dont forget

-- atlas:txmode none

Thanks, done.

@jiparis jiparis requested a review from migmartri September 9, 2025 08:14
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
@jiparis jiparis merged commit 7a247f2 into chainloop-dev:main Sep 9, 2025
13 checks passed
@jiparis jiparis deleted the PFM-3268 branch September 9, 2025 13:47
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.

3 participants