Skip to content

fix: force gin for olap lists - #4403

Merged
mrkaye97 merged 15 commits into
mainfrom
fix--force-gin-for-olap
Jul 14, 2026
Merged

fix: force gin for olap lists#4403
mrkaye97 merged 15 commits into
mainfrom
fix--force-gin-for-olap

Conversation

@grutt

@grutt grutt commented Jul 10, 2026

Copy link
Copy Markdown
Member

Description

Adds GIN and updates queries to favor GINS if tenant entitlement flag is enabled.
Introduces a new AND filter which is more performant and preferred. Sets UI to use this by default.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

What's Changed

  • Adds a tenant entitlement for strict additional metadata filters.
  • Routes workflow-run and task-list metadata filters through jsonb containment when the entitlement is enabled.
  • Adds OLAP GIN indexes and a migration for existing run/task partitions.
  • Updates sqlc models and entitlement upsert/read paths for the new flag.

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
  • I acknowledge that an LLM was used in the creation of this Pull Request, in accordance with Hatchet's AI_POLICY.md.

  • Details: Cursor was used to draft the PR description and fix a Go lint shadowing issue before opening the PR.

@vercel

vercel Bot commented Jul 10, 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 14, 2026 8:15pm

Request Review

@github-actions github-actions Bot added the engine Related to the core Hatchet engine label Jul 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Benchmark results

goos: linux
goarch: amd64
pkg: github.com/hatchet-dev/hatchet/pkg/scheduling/v1
cpu: AMD Ryzen 9 7950X3D 16-Core Processor          
                                         │ /tmp/old.txt │            /tmp/new.txt            │
                                         │    sec/op    │    sec/op     vs base              │
RateLimiter-8                              54.30µ ± 12%   52.35µ ± 26%       ~ (p=0.937 n=6)
Scheduler_Replenish_DenseSharedActions-8   14.05m ±  1%   13.80m ±  1%  -1.74% (p=0.004 n=6)
geomean                                    873.5µ         850.1µ        -2.68%

                                         │ /tmp/old.txt │            /tmp/new.txt            │
                                         │     B/op     │     B/op      vs base              │
RateLimiter-8                              137.7Ki ± 0%   137.7Ki ± 0%       ~ (p=0.154 n=6)
Scheduler_Replenish_DenseSharedActions-8   11.69Mi ± 0%   11.69Mi ± 0%       ~ (p=0.699 n=6)
geomean                                    1.254Mi        1.254Mi       -0.00%

                                         │ /tmp/old.txt │            /tmp/new.txt             │
                                         │  allocs/op   │  allocs/op   vs base                │
RateLimiter-8                               1.022k ± 0%   1.022k ± 0%       ~ (p=1.000 n=6) ¹
Scheduler_Replenish_DenseSharedActions-8    17.46k ± 0%   17.46k ± 0%       ~ (p=0.913 n=6)
geomean                                     4.224k        4.224k       -0.00%
¹ all samples are equal

Compared against main (c686cf5)

@github-actions github-actions Bot added the dashboard Related to the Hatchet dashboard label Jul 13, 2026
@grutt
grutt requested a review from mrkaye97 July 13, 2026 20:49
@grutt

grutt commented Jul 13, 2026

Copy link
Copy Markdown
Member Author
image image

spanContext, span := telemetry.NewSpan(ctx.Request().Context(), "v1-workflow-runs-list")
defer span.End()

strictAdditionalMetadata := false

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.

not sure I understand the naming here - what's the difference between strict metadata and using the "and" operator here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated name... but i want to drop this later this week anyway before we lose context on this whole thing

-- +goose StatementBegin

ALTER TABLE tenant_entitlement
ADD COLUMN IF NOT EXISTS strict_additional_metadata_filters BOOLEAN NOT NULL DEFAULT FALSE;

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.

let's rm IF NOT EXISTS (and IF EXISTS in the down)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

already ran via script... i think this is fine for now

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.

fwiw, this is about the local dev experience, not really about any risk in prod - having IF NOT EXISTS on things like this just masks bugs with no real value: either we don't need it (the schema is up to date with the migrations), or if we do need it, the schema isn't, which is a bug

Comment on lines +22 to +26
CREATE INDEX IF NOT EXISTS ix_v1_tasks_olap_additional_metadata_gin
ON ONLY v1_tasks_olap USING gin (additional_metadata jsonb_path_ops);

CREATE INDEX IF NOT EXISTS ix_v1_runs_olap_additional_metadata_gin
ON ONLY v1_runs_olap USING gin (additional_metadata jsonb_path_ops);

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.

rm if not exists for these too? I'd prefer if we deployed by running your script, and once it completed, we create the parent index

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

same

Comment thread pkg/repository/olap.go Outdated
params.Values = append(params.Values, value.(string))
countParams.Keys = append(countParams.Keys, key)
countParams.Values = append(countParams.Values, value.(string))
if opts.StrictAdditionalMetadata && len(opts.AdditionalMetadata) > 0 {

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.

should this check the operator and not this strict flag?

Comment on lines +84 to +86
const countTasksMetadataContainsAll = `-- name: CountTasksMetadataContainsAll :one
WITH filtered AS (
SELECT

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.

the split queries here kind of suck - is there no other way that doesn't require all this duplication?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

not that ensures we use the right indexes afict

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Optional test failure: The old-engine-new-sdk (TypeScript) job failed on this PR. This check is non-mandatory and does not block merging, but may be worth investigating. View logs

@mrkaye97
mrkaye97 merged commit a73d6aa into main Jul 14, 2026
60 checks passed
@mrkaye97
mrkaye97 deleted the fix--force-gin-for-olap branch July 14, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dashboard Related to the Hatchet dashboard engine Related to the core Hatchet engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants