Skip to content

fix: fetch every column for whole-row references and skip system columns - #677

Open
anh-nguyenn wants to merge 1 commit into
supabase:mainfrom
anh-nguyenn:fix/whole-row-target-columns
Open

anh-nguyenn wants to merge 1 commit into
supabase:mainfrom
anh-nguyenn:fix/whole-row-target-columns

Conversation

@anh-nguyenn

@anh-nguyenn anh-nguyenn commented Nov 7, 2026 •

Copy link
Copy Markdown

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:

  • A whole-row reference has 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.
  • System columns have varattno < 0. get_attname() does return a name (e.g. tableoid), but the negative attribute number was stored as num: attno as usize, which wrapped and panicked when iterate_foreign_scan() indexed the slot.

Reproduced before the change with a minimal FDW:

select t::text from t order by id;   -- (1,), (2,) instead of (1,alice), (2,bob)
select tableoid from t limit 1;      -- index out of bounds panic

Fix

In extract_target_columns():

  • Expand a whole-row Var (varattno == 0) for a relation RTE into every live attribute of the relation, in attribute order.
  • Skip Vars with varattno < 1, since PostgreSQL fills system columns itself.
  • Deduplicate attributes that appear both explicitly and through a whole-row expansion.

Tests

Added regression coverage in wrappers/src/supabase_wrappers_tests.rs for:

  • a whole-row reference in the target list (select t::text ... order by id);
  • a whole-row reference in a WHERE clause;
  • a system column (tableoid);
  • a whole-row reference through a partitioned parent with a foreign partition, plus tableoid on the parent.

All four new tests fail on unmodified main and 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 failed
  • cargo test -p supabase-wrappers --no-default-features --features pg15 --lib — 36 passed
  • cargo clippy -p supabase-wrappers -p supabase-wrappers-macros --tests --no-deps --features pg15 with RUSTFLAGS="-D warnings" — clean
  • cargo clippy -p wrappers --tests --no-deps --features "pg15 pg_test" with RUSTFLAGS="-D warnings" — clean
  • cargo fmt --check — clean

I 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.

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.
@anh-nguyenn
anh-nguyenn requested a review from a team as a code owner November 7, 2026 08:49

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extract_target_columns: whole-row references read back NULL, and system columns index out of bounds

1 participant