Repository navigation
Conversation
…ntext The aggregate scan stored a heap tuple formed in the scan's tmp_ctx with shouldFree = true. When a consumer stops at that row (SELECT ... INTO, SPI with tcount = 1), end_foreign_scan deletes tmp_ctx first and ExecEndPlan then frees the tuple from deleted memory. Form the tuple in the slot's memory context, which outlives the scan state. Fixes supabase#660
This branch has not been deployed
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.
Why
A pushed-down aggregate read by a consumer that stops at the row, such as
SELECT count(*) INTO n FROM ftin PL/pgSQL, frees memory that is already freed. The issue showspfree called with invalid pointerat executor end. On a pgrx pg15 build without assertions, the backend segfaults instead.Fixes #660.
What changed
The aggregate branch of
iterate_foreign_scanformed its heap tuple in the scan'stmp_ctxand stored it withshouldFree = true.end_foreign_scandrops theFdwState, which deletestmp_ctx. ThenExecEndPlanclears the slot and frees the tuple from that deleted context.The tuple is now formed in the slot's own context (
tts_mcxt), which outlives the scan state. The slot still owns it and frees it on the next clear, as before.Tests
clickhouse_aggregate_pushdown_testnow runsSELECT COUNT(*) INTO n FROM agg_testin aDOblock. On main the pg15 test backend dies with signal 11 at that statement. With this change it passes.Run locally on pg15 against a native ClickHouse server:
cargo pgrx test --features "clickhouse_fdw pg15" pg15: 19 passedcargo test -p supabase-wrappers --no-default-features --features pg15 --lib: 36 passedRUSTFLAGS="-D warnings" cargo clippy --tests --no-deps --features "clickhouse_fdw pg15"inwrappers/: cleancargo fmt --check -p supabase-wrappers -p wrappers: cleanNot run: the other native FDW suites.