Skip to content

Commit 9211032

Browse files
authored
chore(database): drop unused TaskRun status composite index (#3743)
## Summary Drops the `TaskRun_status_runtimeEnvironmentId_createdAt_id_idx` index from the `TaskRun` table. After #3742 gated the legacy `WAITING_FOR_DEPLOY` drain to V1-engine workers only, this index sees zero scans on both writer and reader replicas. Removing it cuts index maintenance on every `TaskRun` INSERT/UPDATE. ## Why The index existed to support `WHERE status = X AND runtimeEnvironmentId = Y` queries from `ExecuteTasksWaitingForDeployService`, which is V1-only and no longer triggered on V2 deployments. A code grep across `apps/webapp` and `internal-packages/run-engine` confirmed no V2 production query uses this access pattern — every other `status:` filter on `TaskRun` is paired with `id`/`friendlyId`/`parentSpanId` and uses a different index. Dropping it also unlocks HOT updates on the dequeue path. The dequeue `UPDATE` modifies `status` (`QUEUED` -> `DEQUEUED`), and `status` is the leading column of this index — its presence blocked HOT eligibility for every `TaskRun` UPDATE. With the index gone, dequeue UPDATEs can become HOT, reducing WAL bytes and removing the B-tree page contention on this index's right-edge leaves. Uses `DROP INDEX CONCURRENTLY` to avoid blocking writes during the drop. ## Sequencing Should only ship once #3742 has soaked long enough to confirm the index is genuinely cold (24h+ of zero scans on `pg_stat_user_indexes`).
1 parent 9cb6fd1 commit 9211032

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: improvement
4+
---
5+
6+
Reduce primary database write load on `TaskRun` by dropping an unused composite index on `(status, runtimeEnvironmentId, createdAt, id)`. After gating the legacy `WAITING_FOR_DEPLOY` drain to V1-engine workers only, no V2 Prisma query uses this index while it was still being maintained on every `TaskRun` INSERT/UPDATE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- DropIndex
2+
DROP INDEX CONCURRENTLY IF EXISTS "public"."TaskRun_status_runtimeEnvironmentId_createdAt_id_idx";

internal-packages/database/prisma/schema.prisma

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,6 @@ model TaskRun {
10891089
@@index([runtimeEnvironmentId, batchId])
10901090
@@index([runtimeEnvironmentId, createdAt(sort: Desc)])
10911091
@@index([createdAt], type: Brin)
1092-
@@index([status, runtimeEnvironmentId, createdAt, id(sort: Desc)])
10931092
}
10941093

10951094
model TaskRunTemplate {

0 commit comments

Comments
 (0)