Commit eb26d80
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
- .server-changes
- internal-packages/database/prisma
- migrations/20260520120000_add_environment_variable_value_environment_id_idx
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2020 | 2020 | | |
2021 | 2021 | | |
2022 | 2022 | | |
| 2023 | + | |
2023 | 2024 | | |
2024 | 2025 | | |
2025 | 2026 | | |
| |||
0 commit comments