perf(shadow-indexer): skip payload rewrite on canonical-only upsert - #4746
Open
wbj-cb wants to merge 1 commit into
Open
perf(shadow-indexer): skip payload rewrite on canonical-only upsert#4746wbj-cb wants to merge 1 commit into
wbj-cb wants to merge 1 commit into
Conversation
A same-hash conflict only reaches DO UPDATE to stamp canonical_hash. Guard payload/created_at with CASE so a same-hash conflict reassigns payload to itself, keeping the existing TOAST pointer and avoiding a rewrite (plus full-page WAL) of the ~176KB JSONB. New candidate hashes still land wholesale.
Collaborator
🟡 Heimdall Review Status
|
|
✅ All benchmarks green — 14 within ±2% (deterministic instruction counts). View run Benchmark details (14)
|
Contributor
|
Review: No issues found. The SQL change is correct and well-targeted:
Clean optimization with no behavioral change. |
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
Skip the ~176KB JSONB payload rewrite when a
shadow_blocksupsert only needs to stamp acanonical_hash.Background
insert_rowsupserts blocks withON CONFLICT (number) DO UPDATE. Two kinds of conflict reach theDO UPDATE:canonical_hash— the block is unchanged; we only want to record that it became canonical.Previously both cases assigned
payload = EXCLUDED.payloadunconditionally. In case (2) this reassigns the large JSONB payload to a byte-identical value, but Postgres still rewrites the row's TOAST chunks and emits full-page WAL for the tuple — hundreds of KB of write amplification just to set one hash column.Change
Guard
payloadandcreated_atwith aCASEkeyed on whether the hash actually changed:New hash (case 1):
payload/created_atland wholesale, exactly as before.payloadis reassigned to itself. Postgres keeps the existing TOAST pointer, so no payload rewrite and no full-page WAL for the payload — onlycanonical_hash/updated_atchange.The
WHEREclause is unchanged: redeliveries that neither change the hash nor add a canonical hash are still dropped.Impact
Testing
cargo test -p base-shadow-indexer-db— 4/4 passcargo clippy -p base-shadow-indexer-db— cleancargo check -p base-shadow-indexer-db— cleanNotes