perf(gsi): add index on (base_pk, base_sk_*) for cascade deletes#116
Closed
parsnips wants to merge 1 commit into
Closed
perf(gsi): add index on (base_pk, base_sk_*) for cascade deletes#116parsnips wants to merge 1 commit into
parsnips wants to merge 1 commit into
Conversation
Cascade-delete from base-table writes runs `DELETE FROM <gsi> WHERE base_pk = $1 [AND base_sk_<type> = $n ...]` against every GSI table. Neither the PK constraint nor the existing ordering index can serve this lookup because both lead with `pk`, so PostgreSQL falls back to a Seq Scan. In a recent benchmark this missing index accounted for ~74% of total DB time. Create an index that mirrors the cascade-delete predicate at GSI table creation time. Column order matches the PK constraint minus the leading `pk`, so for a single-bytes base SK this produces `(base_pk, base_sk_b)`. The index is created unconditionally — HASH-only base tables still benefit from `(base_pk)` alone. Only applies to GSI tables created after this change; existing deployments need a backfill migration to pick up the index. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Author
|
looks like #127 will fix this. |
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.
What
Cascade-delete from base-table writes runs
DELETE FROM <gsi> WHERE base_pk = $1 [AND base_sk_<type> = $n ...]against every GSI table. Neither the PK constraint nor the existing ordering index can serve this lookup because both lead withpk, so PostgreSQL falls back to a Seq Scan. In a recent benchmark this missing index accounted for ~74% of total DB time.Create an index that mirrors the cascade-delete predicate at GSI table creation time. Column order matches the PK constraint minus the leading
pk, so for a single-bytes base SK this produces(base_pk, base_sk_b). The index is created unconditionally — HASH-only base tables still benefit from(base_pk)alone.Only applies to GSI tables created after this change; existing deployments need a backfill migration to pick up the index.
Why
GSI Ops should be fast.
Closes #115
Testing done
Manually applied and ran an internal benchmark and plan.
Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.