fix: optimize concurrency slot trigger method#2391
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes the PostgreSQL query performance in the cleanup_workflow_concurrency_slots function by restructuring complex JOIN operations that were causing inefficient query execution plans.
- Introduces a new CTE
relevant_tasks_for_dagsto pre-filter tasks and avoid inefficient JOIN patterns - Simplifies the
final_concurrency_slots_for_dagsCTE by removing problematic multi-table JOINs - Uses EXISTS subqueries instead of direct JOINs for better query performance
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| sql/schema/v1-core.sql | Updates the main function with optimized query structure using new CTE approach |
| cmd/hatchet-migrate/migrate/migrations/20251007083410_v1_0_46.sql | Migration file containing both the new optimized function and rollback to previous version |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
mrkaye97
approved these changes
Oct 7, 2025
Contributor
mrkaye97
left a comment
There was a problem hiding this comment.
nice, looks good - sorta bizarre that the planner couldn't figure this out but 🤷
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Optimizes the concurrency slot trigger to avoid slow deletions. The PG query planner doesn't seem to like the
JOINconditions onv1_dag_to_task,v1_concurrency_slot, andv1_tasksimultaneously. It first selects thev1_concurrency_slotrows and then callsMerge Appendonv1_taskrows in an inefficient manner.Type of change