Skip to content

fix: make sure we use partial index when creating scheduled and cron refs#4260

Merged
mnafees merged 2 commits into
mainfrom
nafees/workflow-version-partial-index
Jun 23, 2026
Merged

fix: make sure we use partial index when creating scheduled and cron refs#4260
mnafees merged 2 commits into
mainfrom
nafees/workflow-version-partial-index

Conversation

@mnafees

@mnafees mnafees commented Jun 23, 2026

Copy link
Copy Markdown
Member

Description

When creating scheduled and cron refs we were not properly filtering for latest workflow version and hence not using the desired partial index idx_workflow_version_workflow_id_order which can lead to high CPU when there are millions of rows in the respective tables.

Type of change

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

What's Changed

  • Add a clause deletedAt IS NULL to existing SQL CTEs when filtering for latest workflow versions.

Checklist

Changes have been:

  • Tested (unit, integration, or manually with steps specified)
  • Linted and formatted

🤖 AI Disclosure
  • I acknowledge that an LLM was used in the creation of this Pull Request, in accordance with Hatchet's AI_POLICY.md.
  • Details: [e.g. generating tests, writing docs]

@mnafees mnafees requested review from grutt and mrkaye97 June 23, 2026 06:40
@mnafees mnafees self-assigned this Jun 23, 2026
Copilot AI review requested due to automatic review settings June 23, 2026 06:40
@mnafees mnafees added the engine Related to the core Hatchet engine label Jun 23, 2026
@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
hatchet-docs Ignored Ignored Preview Jun 23, 2026 7:05am

Request Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes workflow version lookup used when creating cron and scheduled trigger refs so queries filter to non-deleted workflow versions, allowing Postgres to use the intended partial index (idx_workflow_version_workflow_id_order) and avoid high CPU on large tables.

Changes:

  • Add AND "deletedAt" IS NULL to the latest_version CTE used for cron trigger ref creation.
  • Add AND "deletedAt" IS NULL to the latest_version CTE used for scheduled trigger ref creation.
  • Regenerate/update the corresponding sqlc-generated .sql.go query constants.

Reviewed changes

Copilot reviewed 2 out of 4 changed files in this pull request and generated no comments.

File Description
pkg/repository/sqlcv1/workflows.sql Adds "deletedAt" IS NULL filter to latest workflow version selection for cron refs.
pkg/repository/sqlcv1/workflows.sql.go sqlc-generated output updated to match the cron ref query change.
pkg/repository/sqlcv1/workflow_schedules.sql Adds "deletedAt" IS NULL filter to latest workflow version selection for scheduled refs.
pkg/repository/sqlcv1/workflow_schedules.sql.go sqlc-generated output updated to match the scheduled ref query change.
Files not reviewed (2)
  • pkg/repository/sqlcv1/workflow_schedules.sql.go: Generated file
  • pkg/repository/sqlcv1/workflows.sql.go: Generated file

@mnafees mnafees changed the title Make sure we use the partial index when creating scheduled and cron refs fix: make sure we use partial index when creating scheduled and cron refs Jun 23, 2026
@mnafees mnafees merged commit 3234ff5 into main Jun 23, 2026
57 of 58 checks passed
@mnafees mnafees deleted the nafees/workflow-version-partial-index branch June 23, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine Related to the core Hatchet engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants