Repository navigation
chore(relay): drop the live-basis partial index that the planner never picks - #21305
Conversation
…r picks Added in #21301 on the reasoning that the composite (active, deadline) index spans all 6.65M rows to find a few hundred live ones. Measured post-merge against production-shaped history, that reasoning does not hold: a basis is inserted active and flipped to 0, so the partial index accumulates one dead entry per deactivation exactly as the composite one does. Scan buffers are identical to composite-only in every state, 11,099 cold, 2,522 warm, 9 after VACUUM, and the planner picks the composite index throughout. The extra index costs ~65 bytes of WAL per basis insert, about 22% more. The relief is the reaper plus vacuum, which #21301 already ships. Removes the statement from SCHEMA, restores the plan test to pinning the composite index by name, and records why a narrower index is not the cure so the next reader does not re-derive it.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe relay schema removes the Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The retained composite index continues to support the cleanup sweeps, and the related planner and schema expectations are aligned with its removal. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description is detailed and covers the change, rationale, testing, operational ordering, and checklist. However, the required Linked Issue field is incomplete: it contains
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Drops
relay_connection_bases_live_deadlinefromSCHEMA— removes theCREATE INDEX ... WHERE active = 1statement and itsschema-deferrablecomment block; replaces them with a-- Why not a partial index on active = 1note above the surviving composite index that records the measurement. - Re-pins the maintenance-sweep plan test —
postgres-maintenance-sweep-plans.test.tsnarrows its regex back torelay_connection_bases_active_deadlineinstead of accepting either index. - Re-pins the credential-sweep plan test —
credential-cleanup-sweep-postgres.test.tsswapstoMatch(/..._(active|live)_deadline/)fortoContain('using relay_connection_bases_active_deadline')and updates the explanatory comment to say why the partial index was a dead end. - Updates the lock-target golden — removes the live-deadline entry from
GOLDEN_LOCK_TAKINGand from the expected deferrable-statement list inrelay-schema-lock-targets.test.ts.
Checked repo-wide: no remaining references to relay_connection_bases_live_deadline in code, tests, docs, or workflow YAML. relayPostgresSchemaStatements() is SCHEMA.split(';') plus migrations, so the golden census and the pre-check test (which derives its counts at runtime) both lose exactly one entry consistently. The new comment correctly omits the schema-deferrable marker, which the composite index never had. The one operational hazard — deploy this image before running DROP INDEX CONCURRENTLY, so the old image's name-only pre-check cannot send a non-concurrent build over the 1.5 GB table — is well covered in the PR description, and is moot once this image is live.
I was unable to run the relay suite locally to confirm the plan assertions: the cloud/ workspace keeps its own node_modules that the root pnpm install does not populate (ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL … node_modules missing), which is environmental and unrelated to this diff. The change is schema text with no behavioral surface and the author reports the three touched tests and the full relay suite green.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…r picks (stablyai#21305) Added in stablyai#21301 on the reasoning that the composite (active, deadline) index spans all 6.65M rows to find a few hundred live ones. Measured post-merge against production-shaped history, that reasoning does not hold: a basis is inserted active and flipped to 0, so the partial index accumulates one dead entry per deactivation exactly as the composite one does. Scan buffers are identical to composite-only in every state, 11,099 cold, 2,522 warm, 9 after VACUUM, and the planner picks the composite index throughout. The extra index costs ~65 bytes of WAL per basis insert, about 22% more. The relief is the reaper plus vacuum, which stablyai#21301 already ships. Removes the statement from SCHEMA, restores the plan test to pinning the composite index by name, and records why a narrower index is not the cure so the next reader does not re-derive it.

ELI5
In the previous change we added an extra index to help one relay housekeeping query find the small number of rows it cares about. We then measured it on real data instead of trusting the reasoning, and it turned out to help nothing: it gets just as cluttered as the index we already had, the database never chooses it, and it makes every write slightly more expensive. This removes it. The thing that actually fixes the problem, deleting old rows and reclaiming the space, already shipped.
What Changed
Removes
relay_connection_bases_live_deadlinefromSCHEMA, added in #21301 and merged as cbd0470.Before and after, as the user experiences it: no difference. This index was never chosen by the planner, so removing it changes no query plan. The user-visible win from #21301, the fleet no longer stalling every ten minutes, came from the other four indexes, the role gating, and the reapers, all of which stay.
Mechanism. The index was added on the reasoning that the existing composite index spans all 6.65M rows to find a few hundred live ones, so a partial index on
active = 1would hold only the rows the sweep wants. Measured after the merge against production-shaped history, the reasoning does not survive:active = 1and later flipped to0. That update moves the row out of the partial index's predicate, which in Postgres means deleting the index entry, and the dead entry stays until vacuum. So the partial index accumulates exactly one dead entry per deactivation, the same as the composite one. It is only small on a table that has already been vacuumed, which is the state where nothing needed help.VACUUMThe cure for this table is the reaper plus vacuum, which #21301 ships. The 9-buffer row above is what that looks like.
Also in this PR:
postgres-maintenance-sweep-plans.test.tsgoes back to pinningrelay_connection_bases_active_deadlineby name. perf(relay): index and gate the credential cleanup sweeps that seq-scan relay_invites #21301 had widened it to accept either index, which was correct while both existed and is now just looser than it needs to be.credential-cleanup-sweep-postgres.test.tsis pinned to the composite index for the same reason.-- Why notcomment sits beside the composite index inSCHEMArecording the measurement, so the next person reading "6.65M rows scanned to find a few hundred" does not re-derive the same idea and re-add the same index.Operator step, and the order matters
Deploy this schema change first, then drop the index in production:
Not the other way round. The boot-time catalog pre-check is name-only: it skips a
CREATE INDEXonce an index of that name exists. Dropping the index while the current image is still serving would make it absent, so the next boot of any director would send theCREATE INDEX IF NOT EXISTSstatement, take its relation lock, and build it non-concurrently over a 1.5 GB table, with all 28 directors reaching it at once. That is the exact failure mode the rule besideSCHEMAexists to prevent. Once this image is live the statement is gone fromSCHEMAentirely, and the drop is safe.DROP INDEX CONCURRENTLYtakes no lock that blocks readers or writers, so there is no window to schedule around.Why
Why remove it rather than leave it? It is not free. It adds ~22% WAL per basis insert and a second index to maintain on every insert and every deactivation, on the hottest write path this table has. An index that is never chosen and never smaller than the one beside it is pure cost.
Why not instead drop the composite index and keep this one? The composite index is the only one covering
active = 0, which is what the reaper matches. #21301 measured that directly: the drained reaper costs 5 buffers with the composite index and 1,274 without it. Keeping the partial one and dropping the composite would break the reaper to keep an index the planner does not use.Why did the original reasoning look right? Because the row-count ratio is real: a few hundred live rows against 6.65M. What it missed is that the ratio describes live tuples, and index bloat is driven by dead ones. A predicate that a row leaves as part of its normal lifecycle does not keep an index small, it just relocates where the dead entries land. That is the generalisable lesson and it is now in the schema comment.
Alternative considered: keep it and rely on more frequent vacuum. Rejected. It would make the partial index useful only in the state where the composite index is also fast (the 9-buffer row), so it would still never be picked. Tuning autovacuum for this table is worth doing on its own merits and does nothing for this index.
Linked Issue
Follow-up to #21301.
Fixes #
Visual Proof
N/A— schema-only change with no UI surface, and by construction no change to any query plan.Testing
Ran from
cloud/against PostgreSQL 16 in a container on a fresh database, since the relay Postgres suite leaves state behind and fails on a re-used one.The three plan and schema tests this change touches:
Full relay suite:
pnpm -F @orca-cloud/relay typecheckclean.oxlintdoes not cover this code:cloud/**is in the root config'signorePatterns. No lint suppressions were added.The plan assertions are the real check here and they are not vacuous: with the partial index gone they still resolve to
using relay_connection_bases_active_deadlineon a table seeded 20,000 settled to 50 live, and thenot.toMatch(/Seq Scan on relay_connection_bases/)half is unchanged from before #21301.One note for whoever runs these locally:
npx viteston these files fails to resolve@orca-cloud/postgres-schema, because the package is consumed fromdistand thepretestscript is what builds it. Run them throughpnpm -F @orca-cloud/relay test <paths>.Review
Cross-platform: schema text only, no paths, shells, or processes. SQLite is unaffected either way, since it applies
SCHEMAin order and simply has one fewer statement. SSH and mobile are unaffected: no wire field, stream opcode, or published content changes. Backwards compatible in both directions, with one ordering constraint on the operator drop, described above and the only thing in this PR that needs care. Security is unchanged: no predicate, no read path, and no retention policy is touched.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Nothing in this PR is urgent. The index is inert, so the only cost of leaving it in place a while longer is the WAL overhead on basis inserts. The ordering constraint on the production drop is the one thing that must not be got wrong.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)