Hi, The attached SQL script shows a clear index corruption case caused by incomplete tracking of whole-row vars in index expressions and the invalidation of those when the table's layout is modified by DDL. It has similar effects as the bug reported by Ayush Tiwari and fixed with a4639d64e2; the index wasn't built with new data after the table's whole-row expression changed for existing rows through DDL.
I've attached a patch which adds explicit tracking for whole-row expressions in pg_depend, and use it to make sure we're rebuilding indexes and revalidating constraints where and when required, without O(N) dependency scans. (This was triggered by some traffic on the list and in the commit log on the topic of whole-row support, apparently without noticing this pre-existing issue that I've known existed but haven't had the time to address or advocate for.) There is one item that I haven't touched in this patch that might also affect whole-row expressions, and that is column renaming: Technically, changes in names can affect a function's output (see e.g. row_to_json), but I haven't yet found an immutable function that has a `record` argument and exposes column names in output, nor have I worked up the courage to wire up index rebuilds into ExecRenameStmt/renameatt(). Kind regards, Matthias van de Meent Databricks (https://www.databricks.com)
whole-row-var-index-corruptions.sql
Description: application/sql
v1-0001-Track-whole-row-Var-dependencies-in-pg_depend.patch
Description: Binary data
