Repository navigation
fix: fetch every column for whole-row references and skip system columns - #677
Open
anh-nguyenn wants to merge 1 commit into
Open
anh-nguyenn wants to merge 1 commit into
anh-nguyenn wants to merge 1 commit into
Conversation
extract_target_columns() dropped whole-row Vars (varattno == 0) because get_attname() returns NULL for them, so only the explicitly named columns were fetched and the rest of the whole-row value came back NULL. System-column Vars (varattno < 0) were recorded with a negative attribute number, which wrapped and panicked when indexing the scan slot. Expand a whole-row reference to every live attribute of the relation, deduplicate repeated attributes, and skip Vars with varattno < 1. Adds regression coverage for whole-row references in the target list, in WHERE clauses, through a partitioned parent, and for tableoid.
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.
Fixes #657.
Problem
extract_target_columns()builds the fetch list from the Vars in the base relation's target list and restriction clauses. Two kinds of Var are mishandled:varattno = 0.get_attname()returns NULL for it, so the Var was skipped. Only the columns named elsewhere in the query were fetched, and PostgreSQL built the whole-row value from a slot whose remaining attributes were NULL.varattno < 0.get_attname()does return a name (e.g.tableoid), but the negative attribute number was stored asnum: attno as usize, which wrapped and panicked wheniterate_foreign_scan()indexed the slot.Reproduced before the change with a minimal FDW:
Fix
In
extract_target_columns():varattno == 0) for a relation RTE into every live attribute of the relation, in attribute order.varattno < 1, since PostgreSQL fills system columns itself.Tests
Added regression coverage in
wrappers/src/supabase_wrappers_tests.rsfor:select t::text ... order by id);WHEREclause;tableoid);tableoidon the parent.All four new tests fail on unmodified
mainand pass with the fix.Validation run locally (PostgreSQL 15.19, Rust 1.97.1, pgrx 0.19.2):
cargo pgrx test --features pg15— 18 passed, 0 failedcargo test -p supabase-wrappers --no-default-features --features pg15 --lib— 36 passedcargo clippy -p supabase-wrappers -p supabase-wrappers-macros --tests --no-deps --features pg15withRUSTFLAGS="-D warnings"— cleancargo clippy -p wrappers --tests --no-deps --features "pg15 pg_test"withRUSTFLAGS="-D warnings"— cleancargo fmt --check— cleanI did not run the suite against other PostgreSQL major versions locally; CI covers the default configuration.
Risk
The change only affects the attribute list handed to
begin_scan(). Queries without whole-row or system-column references keep the same target list. Generated columns keep the existing "not supported" warning behaviour.