perf(postgresql): replace correlated NOT EXISTS with set-based EXCEPT in prune_stale_cooccurrences (#2660)#2797
Open
handnewb wants to merge 1 commit into
Open
Conversation
… in prune_stale_cooccurrences The original Pass-3 correlated NOT EXISTS self-join evaluates per-row against unit_entities, hitting a 300s statement_timeout on large graphs (50K+ entities, 1M+ unit_entities). The set-based EXCEPT rewrite materializes the stale cooccurrence set once and deletes against it — same result, ~90x faster (~3.4s vs 300s for 5.7K stale rows). Closes vectorize-io#2660
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
The original Pass-3
prune_stale_cooccurrencesuses a correlatedNOT EXISTSself-join onunit_entitiesthat evaluates per-row. On large graphs:unit_entitiesrowsentity_cooccurrencesrowsThis hits a 300s
statement_timeoutwith 0 rows pruned because Postgres can't complete the per-row evaluation in time.Changes
Replaced the correlated
NOT EXISTSwith a set-basedEXCEPT:cooccurrences EXCEPT valid_witness_pairsThis produces the identical result set (verified via bidirectional
EXCEPTand ordered digest match) while completing in ~3.4s vs >300s for the correlated form — ~90x faster.Verification
OLD EXCEPT NEW = 0,NEW EXCEPT OLD = 0Closes #2660