Skip to content

fix(api): use the AND operator with the gin index when there's only one k-v pair set - #4436

Merged
mrkaye97 merged 2 commits into
mainfrom
mk/use-index-for-single-key-queries
Jul 15, 2026
Merged

fix(api): use the AND operator with the gin index when there's only one k-v pair set#4436
mrkaye97 merged 2 commits into
mainfrom
mk/use-index-for-single-key-queries

Conversation

@mrkaye97

Copy link
Copy Markdown
Contributor

Description

Improves the performance of the run list API(s) when only one k-v pair for the additional meta filter is provided by always using the AND query in that case, since it'll use the index and is the fastest option

Type of change

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

Checklist

Changes have been:

  • Tested (unit, integration, or manually with steps specified)
  • Linted and formatted
  • Documented (where applicable)
  • Added to CHANGELOG (where applicable) -- see Keep a Changelog

🤖 AI Disclosure

No AI use

@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
hatchet-docs Ready Ready Preview, Comment Jul 15, 2026 2:07pm

Request Review

@mrkaye97
mrkaye97 requested review from Copilot and grutt July 15, 2026 13:57
@github-actions github-actions Bot added the engine Related to the core Hatchet engine label Jul 15, 2026

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 aims to improve performance for the workflow-run/task-run list endpoints when filtering by additional_metadata with a single k-v pair by forcing use of the GIN-backed containment path (and AND semantics, which are equivalent for a single pair).

Changes:

  • Forces UseGinIndex when exactly one additional_metadata filter is provided.
  • Updates additionalMetadataOperator to take a filter count so the handler can force AND when only one filter exists.
  • Minor refactor of option struct initialization formatting.

Comment on lines 145 to +161
@@ -156,6 +157,8 @@ func (t *V1WorkflowRunsService) WithDags(ctx context.Context, request gen.V1Work
opts.AdditionalMetadata = additionalMetadataFilters
}

opts.AdditionalMetadataOperator = additionalMetadataOperator(request.Params.AdditionalMetadataOperator, numAdditionalMetaFilters)

Comment on lines 298 to +314
@@ -306,6 +310,8 @@ func (t *V1WorkflowRunsService) OnlyTasks(ctx context.Context, request gen.V1Wor
opts.AdditionalMetadata = additionalMetadataFilters
}

opts.AdditionalMetadataOperator = additionalMetadataOperator(request.Params.AdditionalMetadataOperator, numAdditionalMetaFilters)

Comment on lines 391 to +397
// additionalMetadataOperator maps the optional additional_metadata_operator query
// param to the repository operator, defaulting to OR
func additionalMetadataOperator(param *gen.V1AdditionalMetadataOperator) v1.AdditionalMetadataOperator {
func additionalMetadataOperator(param *gen.V1AdditionalMetadataOperator, numFilters int) v1.AdditionalMetadataOperator {
// if we only have one filter, always use the `AND` since it's the most performant way, and both methods are equivalent
if numFilters <= 1 {
return v1.AdditionalMetadataOperatorAnd
}

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread api/v1/server/handlers/v1/workflow-runs/list.go
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Optional test failure: The load-deadlock job failed on this PR (optimistic-scheduling=true). This check is non-mandatory and does not block merging, but may be worth investigating. View logs

@mrkaye97
mrkaye97 merged commit 40f8a99 into main Jul 15, 2026
54 of 55 checks passed
@mrkaye97
mrkaye97 deleted the mk/use-index-for-single-key-queries branch July 15, 2026 14:27
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.

3 participants