Skip to content

Commit eb26d80

Browse files
committed
perf(webapp): index EnvironmentVariableValue.environmentId
The /api/v1/projects/:projectRef/envvars/:slug/:name loader calls `getEnvironmentWithRedactedSecrets`, which runs a Prisma findMany on EnvironmentVariableValue filtered by environmentId + isSecret. The only existing indexes are the primary key and a unique on (variableId, environmentId), so environmentId is never the leading column. Postgres plans a Parallel Seq Scan over the whole table (roughly 2.2M rows / 400MB heap) to find an average of 24 matching rows. Adding a btree on environmentId alone flips the plan to an index scan (~24 row average per environment, 536 max in our sample), which removes the CPU + buffer-pin (LWLock:BufferContent) contention this query generates on the writer. The composite (variableId, environmentId) unique stays where it is; this is purely additive.
1 parent 6b46a34 commit eb26d80

3 files changed

Lines changed: 10 additions & 0 deletions

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+
Add an index on `EnvironmentVariableValue(environmentId)` so the env-var lookups behind `GET /api/v1/projects/:projectRef/envvars/:slug/:name` use an index scan instead of a parallel sequential scan over the whole table.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- CreateIndex
2+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "EnvironmentVariableValue_environmentId_idx"
3+
ON "EnvironmentVariableValue"("environmentId");

internal-packages/database/prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,7 @@ model EnvironmentVariableValue {
20202020
lastUpdatedBy Json?
20212021
20222022
@@unique([variableId, environmentId])
2023+
@@index([environmentId])
20232024
}
20242025

20252026
model Checkpoint {

0 commit comments

Comments
 (0)