fix(db): index two more nullable FK columns missing covering indexes#7000
fix(db): index two more nullable FK columns missing covering indexes#7000jaydeep-pipaliya wants to merge 1 commit into
Conversation
Two gateway-related FK columns shipped without covering indexes, so the per-row referential-integrity trigger seq-scans the child table on every parent delete: - dynamic_secrets.gatewayPoolId (RESTRICT to gateway_pools, nullable). Set only when a dynamic secret is pinned to a pool, most rows are NULL. - pam_sessions.gatewayId (SET NULL to gateways_v2, nullable). Set when a pool-backed PAM session resolves to a specific gateway, most rows are NULL. Both get partial indexes filtered to the non-NULL rows, same shape as the indexes added in Infisical#6965 and Infisical#6966. The partial form keeps the index tiny and imposes near-zero write overhead on the live insert path.
|
| Filename | Overview |
|---|---|
| backend/src/db/migrations/20260624075011_add-fk-indexes-gateway-pool-and-pam-session.ts | Adds partial indexes on two nullable FK columns (dynamic_secrets.gatewayPoolId and pam_sessions.gatewayId) with proper idempotency guards in both up and down migrations. |
Reviews (1): Last reviewed commit: "fix(db): index two more nullable FK colu..." | Re-trigger Greptile
What
Two more nullable FK columns shipped without covering indexes — sister fix to #6965 and #6966. The per-row RI trigger on each parent delete falls back to a seq-scan of the child table on every gateway / gateway-pool delete:
dynamic_secrets.gatewayPoolId(RESTRICT togateway_pools, nullable). Set only when a dynamic secret is pinned to a pool, so most rows are NULL.pam_sessions.gatewayId(SET NULL togateways_v2, nullable). Set when a pool-backed PAM session resolves to a specific gateway, so most rows are NULL.Both get partial indexes filtered to the non-NULL rows (same shape as the previous two migrations). The partial form keeps the index tiny and imposes near-zero write overhead on the live insert path.
Why partial
For pool-pinned dynamic secrets and resolved PAM sessions,
gatewayPoolId/gatewayIdare NULL on the live insert path and only get set as a side effect of pinning / resolution. The cascade lookup only ever walks specific non-null values, so a partial index over the non-NULL rows fully serves the cascade while staying small.Checklist