Hi, While testing CLUSTER for BUG #19519, I found that PostgreSQL still fetches a dropped column's TOAST value when forming a row value. A plain SELECT shows this on unpatched master (93f5e9d405f).
CREATE TEMP TABLE pp (f1 text);
INSERT INTO pp VALUES (repeat('abcdefghijkl', 100000));
SELECT pg_column_size(pp) FROM pp;
-- 13783
ALTER TABLE pp DROP COLUMN f1;
SELECT pp::text, pg_column_size(pp) FROM pp;
-- () | 13783
Both SELECTs read the same row. Before the DROP, the 13783 bytes
include f1, as expected. After the DROP, pp has no columns and prints
as (), yet the SELECT still copies the old value of f1 into the
row value. A row inserted after the DROP gives the expected 24 bytes.
INSERT INTO pp DEFAULT VALUES
RETURNING pp::text, pg_column_size(pp);
-- () | 24
The patch marks dropped fields NULL in toast_build_flattened_tuple().
This skips the TOAST fetch and tells heap_form_tuple() to omit the
field's bytes. After the DROP, the original row also gives () | 24.
Regards,
Rui
v1-0001-Skip-TOAST-fetches-for-dropped-columns-when-forming-a-row-value.patch
Description: Binary data
