Skip to content

Fix: Improve performance of status metrics query#3800

Merged
mrkaye97 merged 1 commit intomainfrom
mk/improve-status-metric-query
May 5, 2026
Merged

Fix: Improve performance of status metrics query#3800
mrkaye97 merged 1 commit intomainfrom
mk/improve-status-metric-query

Conversation

@mrkaye97
Copy link
Copy Markdown
Contributor

@mrkaye97 mrkaye97 commented May 1, 2026

Description

Fixes #3790

Adds some additional filters to the runs CTE to prune partitions and make use of the tenant index, which should hopefully improve performance a lot

Type of change

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

Copilot AI review requested due to automatic review settings May 1, 2026 17:17
@vercel
Copy link
Copy Markdown

vercel Bot commented May 1, 2026

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

Project Deployment Actions Updated (UTC)
hatchet-docs Ready Ready Preview, Comment May 1, 2026 5:19pm

Request Review

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

Improves performance of the GetTenantStatusMetrics OLAP query (used by GET /api/v1/stable/tenants/:tenant/task-metrics) by pushing tenant/time/workflow filters down into the task_external_ids CTE so Postgres can better prune partitions and use existing indexes.

Changes:

  • Added tenant_id, inserted_at (createdAfter/createdBefore), and workflow_id filters to the task_external_ids CTE in GetTenantStatusMetrics.
  • Regenerated the sqlc output to reflect the updated SQL.

Reviewed changes

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

File Description
pkg/repository/sqlcv1/olap.sql Pushes existing filters into the task_external_ids CTE to reduce scanned partitions/rows for status metrics.
pkg/repository/sqlcv1/olap.sql.go Regenerated sqlc output reflecting the updated query definition.

)
)
AND tenant_id = @tenantId::UUID
AND inserted_at >= @createdAfter::TIMESTAMPTZ
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.

this isnt breaking?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

don't think so, why would it be?

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.

my fault, missed that we already had created after later in the query

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

all good!

@mrkaye97 mrkaye97 merged commit 5851bb0 into main May 5, 2026
56 checks passed
@mrkaye97 mrkaye97 deleted the mk/improve-status-metric-query branch May 5, 2026 18:29
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.

[BUG] Extremelly poor performance of GetTenantStatusMetrics query

3 participants