Obtain required table lock during cross-table updates, redux.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 3 Jul 2025 17:46:07 +0000 (13:46 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 3 Jul 2025 17:46:07 +0000 (13:46 -0400)
commita10f21e6ce549705f194b8fdb28e685403e7579d
treeb1c66dd449c7b30f236742057ab63de1008a5aa7
parenta604affaded028b6bfba024127931289c2b756c2
Obtain required table lock during cross-table updates, redux.

Commits 8319e5cb5 et al missed the fact that ATPostAlterTypeCleanup
contains three calls to ATPostAlterTypeParse, and the other two
also need protection against passing a relid that we don't yet
have lock on.  Add similar logic to those code paths, and add
some test cases demonstrating the need for it.

In v18 and master, the test cases demonstrate that there's a
behavioral discrepancy between stored generated columns and virtual
generated columns: we disallow changing the expression of a stored
column if it's used in any composite-type columns, but not that of
a virtual column.  Since the expression isn't actually relevant to
either sort of composite-type usage, this prohibition seems
unnecessary; but changing it is a matter for separate discussion.
For now we are just documenting the existing behavior.

Reported-by: jian he <jian.universality@gmail.com>
Author: jian he <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: CACJufxGKJtGNRRSXfwMW9SqVOPEMdP17BJ7DsBf=tNsv9pWU9g@mail.gmail.com
Backpatch-through: 13
src/backend/commands/tablecmds.c
src/test/regress/expected/alter_table.out
src/test/regress/expected/generated_stored.out
src/test/regress/expected/generated_virtual.out
src/test/regress/sql/alter_table.sql
src/test/regress/sql/generated_stored.sql
src/test/regress/sql/generated_virtual.sql