Repository navigation
perf(db): index a workspace's live files in upload order - #9434
Merged
Merged
Conversation
The live file list filtered on workspace, owner, context and liveness and sorted by uploaded_at, and no index served that filter in that order. The planner combined the context and search keyset indexes, which match the live workspace files of every workspace, filtered to one workspace on the heap, then sorted, on disk for a large workspace. A bounded read such as the SSR seed or an uploadedAt keyset page paid for the whole workspace. workspace_files_workspace_active_uploaded_idx keys on (workspace_id, uploaded_at, id) under the predicate the other live workspace-file indexes share, which the list's filter implies. The key stays narrow: carrying the name and storage key columns would bring an entry near the btree size limit and fail the write. The contract-pending note on workspace_files_workspace_active_keyset_idx now names this index as the one that takes over its workspace-scoped reads. The list now orders upload-time ties by id, so its order is deterministic. explainCaptured in @sim/db/testing/explain EXPLAINs the statement a call sends, with its bound parameters, for plan assertions in integration tests. On a prod-shaped local copy with stale statistics, the largest workspace's 301-row seed went from ~210 ms to under 1 ms and an uploadedAt keyset page from ~205 ms to under 0.1 ms, both ordered index scans with no sort. The unbounded full list keeps its bitmap plan: its estimate is about an eighth of the real row count, at which the planner prices this index above it. Lookups by key, name and id and the name-sorted folder page keep their plans.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
[Medium impact] The PR appears safe to merge, with no new actionable issues. SummaryAdds an index for a workspace’s live file list and bounded server-rendered seed, with stable ordering by
Reviews (2) · Last reviewed commit: "docs(db): say the upload-order index ser..." · Reviewed by Greptile |
Collaborator
Author
Collaborator
Author
|
@cubic-dev-ai review this PR |
Contributor
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
workspace_files_workspace_active_uploaded_idx (workspace_id, uploaded_at, id)with the predicate the other live workspace-file indexes share (deleted_at IS NULL AND context = 'workspace' AND workspace_id IS NOT NULL), built concurrently with the replay-safe recovery patterndate_trunc('milliseconds', uploaded_at)and move to this order in the pagination PR, which aligns their keyset with the plain column)listWorkspaceFilesorders byuploaded_at, id, so ties come back in a stable order across readsworkspace_files_workspace_active_keyset_idxfor retirement once its scans stop after deploy@sim/db/testing/explain(explainCaptured), a test helper that EXPLAINs the SQL a call actually sends, with its bound parametersType of Change
Testing
file-list.integration.ts: active, archived and all scopes list exactly their rows in (uploaded_at, id) order (archived and all fail without the tiebreak); the full list and the SSR seed's bounded read plan on the new index with no Sort (fails with the index dropped)bun run check:migrations origin/staging,drizzle-kit generate(no changes),bun run lint,bun run check:audits,bun run type-checkChecklist
test-auditauthoring gate)