Skip to content

fix: optimize concurrency slot trigger method#2391

Merged
mrkaye97 merged 4 commits into
mainfrom
belanger/optimize-concurrency-trigger
Oct 8, 2025
Merged

fix: optimize concurrency slot trigger method#2391
mrkaye97 merged 4 commits into
mainfrom
belanger/optimize-concurrency-trigger

Conversation

@abelanger5
Copy link
Copy Markdown
Contributor

Description

Optimizes the concurrency slot trigger to avoid slow deletions. The PG query planner doesn't seem to like the JOIN conditions on v1_dag_to_task, v1_concurrency_slot, and v1_task simultaneously. It first selects the v1_concurrency_slot rows and then calls Merge Append on v1_task rows in an inefficient manner.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

@vercel
Copy link
Copy Markdown

vercel Bot commented Oct 7, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
hatchet-docs Ready Ready Preview Comment Oct 8, 2025 3:50pm
hatchet-v0-docs Canceled Canceled Oct 8, 2025 3:50pm

@abelanger5 abelanger5 requested review from Copilot and mrkaye97 October 7, 2025 09:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_dags to pre-filter tasks and avoid inefficient JOIN patterns
  • Simplifies the final_concurrency_slots_for_dags CTE 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.

Copy link
Copy Markdown
Contributor

@mrkaye97 mrkaye97 left a comment

Choose a reason for hiding this comment

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

nice, looks good - sorta bizarre that the planner couldn't figure this out but 🤷

@mrkaye97 mrkaye97 merged commit d08bf6a into main Oct 8, 2025
31 of 32 checks passed
@mrkaye97 mrkaye97 deleted the belanger/optimize-concurrency-trigger branch October 8, 2025 15:50
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