-
Notifications
You must be signed in to change notification settings - Fork 364
Fix: Attempt at improving worker actions query #3774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
616945b
86f2f27
8a5e712
484b9b8
0692172
83f9563
b1b63fa
efed1f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| -- +goose Up | ||
| -- +goose StatementBegin | ||
| ALTER TABLE "Worker" ADD COLUMN "actionHash" BYTEA; | ||
| -- +goose StatementEnd | ||
|
|
||
| -- +goose Down | ||
| -- +goose StatementBegin | ||
| ALTER TABLE "Worker" DROP COLUMN "actionHash"; | ||
| -- +goose StatementEnd |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| -- +goose no transaction | ||
|
|
||
| -- +goose Up | ||
| -- +goose StatementBegin | ||
| CREATE INDEX CONCURRENTLY IF NOT EXISTS "Worker_tenantId_actionHash_idx" ON "Worker" ("tenantId", "actionHash"); | ||
| -- +goose StatementEnd | ||
|
|
||
| -- +goose Down | ||
| -- +goose StatementBegin | ||
| DROP INDEX CONCURRENTLY IF EXISTS "Worker_tenantId_actionHash_idx"; | ||
| -- +goose StatementEnd |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -247,19 +247,28 @@ GROUP BY "tenantId" | |||||||
| ; | ||||||||
|
|
||||||||
| -- name: GetWorkerActionsByWorkerId :many | ||||||||
| WITH inputs AS ( | ||||||||
| SELECT UNNEST(@workerIds::UUID[]) AS "workerId" | ||||||||
| ) | ||||||||
|
|
||||||||
| SELECT | ||||||||
| w."id" AS "workerId", | ||||||||
| a."actionId" AS actionId | ||||||||
| FROM "Worker" w | ||||||||
| JOIN inputs i ON w."id" = i."workerId" | ||||||||
| LEFT JOIN "_ActionToWorker" aw ON w.id = aw."B" | ||||||||
| LEFT JOIN "Action" a ON aw."A" = a.id | ||||||||
| JOIN "_ActionToWorker" aw ON w.id = aw."B" | ||||||||
| JOIN "Action" a ON aw."A" = a.id | ||||||||
| WHERE | ||||||||
| a."tenantId" = @tenantId::UUID | ||||||||
| AND w.id = ANY(@workerIds::UUID[]) | ||||||||
| ; | ||||||||
|
|
||||||||
| -- name: GetWorkerActionsByWorkerActionHash :many | ||||||||
| SELECT DISTINCT ON (w."actionHash") | ||||||||
|
||||||||
| SELECT DISTINCT ON (w."actionHash") | |
| SELECT |
Copilot
AI
Apr 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetWorkerActionsByWorkerActionHash doesn’t constrain w."tenantId", so the new (tenantId, actionHash) index won’t be used and (if any cross-tenant links ever exist) results could bleed across tenants. Add AND w."tenantId" = @tenantId::UUID to the WHERE clause to match the index and keep the join tenant-scoped.
| a."tenantId" = @tenantId::UUID | |
| a."tenantId" = @tenantId::UUID | |
| AND w."tenantId" = @tenantId::UUID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goal here is we'll just move to this completely in a little bit, once all the workers have hashes