]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Need to do CommandCounterIncrement after StoreAttrMissingVal.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 2 Apr 2025 15:13:01 +0000 (11:13 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 2 Apr 2025 15:13:01 +0000 (11:13 -0400)
Without this, an additional change to the same pg_attribute row
within the same command will fail.  This is possible at least with
ALTER TABLE ADD COLUMN on a multiple-inheritance-pathway structure.
(Another potential hazard is that immediately-following operations
might not see the missingval.)

Introduced by 95f650674, which split the former coding that
used a single pg_attribute update to change both atthasdef and
atthasmissing/attmissingval into two updates, but missed that
this should entail two CommandCounterIncrements as well.  Like
that fix, back-patch through v13.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Tender Wang <tndrwang@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/025a3ffa-5eff-4a88-97fb-8f583b015965@gmail.com
Backpatch-through: 13

src/backend/commands/tablecmds.c
src/test/regress/expected/inherit.out
src/test/regress/sql/inherit.sql

index b6aa4a8f754f6629089f1ddfadfc251691e81f81..40fe7685239492129d82bd272ec10b75079df741 100644 (file)
@@ -7214,6 +7214,8 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
                                if (!missingIsNull)
                                {
                                        StoreAttrMissingVal(rel, attribute.attnum, missingval);
+                                       /* Make the additional catalog change visible */
+                                       CommandCounterIncrement();
                                        has_missing = true;
                                }
                                FreeExecutorState(estate);
index 8f831c95c38c8e452f4d148117742b07ceea8c00..89306e158eff7965176c4db2e69b772b2d11a102 100644 (file)
@@ -1093,17 +1093,30 @@ CREATE TABLE inhta ();
 CREATE TABLE inhtb () INHERITS (inhta);
 CREATE TABLE inhtc () INHERITS (inhtb);
 CREATE TABLE inhtd () INHERITS (inhta, inhtb, inhtc);
-ALTER TABLE inhta ADD COLUMN i int;
+ALTER TABLE inhta ADD COLUMN i int, ADD COLUMN j bigint DEFAULT 1;
 NOTICE:  merging definition of column "i" for child "inhtd"
 NOTICE:  merging definition of column "i" for child "inhtd"
+NOTICE:  merging definition of column "j" for child "inhtd"
+NOTICE:  merging definition of column "j" for child "inhtd"
 \d+ inhta
                                    Table "public.inhta"
  Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description 
 --------+---------+-----------+----------+---------+---------+--------------+-------------
  i      | integer |           |          |         | plain   |              | 
+ j      | bigint  |           |          | 1       | plain   |              | 
 Child tables: inhtb,
               inhtd
 
+\d+ inhtd
+                                   Table "public.inhtd"
+ Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description 
+--------+---------+-----------+----------+---------+---------+--------------+-------------
+ i      | integer |           |          |         | plain   |              | 
+ j      | bigint  |           |          | 1       | plain   |              | 
+Inherits: inhta,
+          inhtb,
+          inhtc
+
 DROP TABLE inhta, inhtb, inhtc, inhtd;
 -- Test for renaming in diamond inheritance
 CREATE TABLE inht2 (x int) INHERITS (inht1);
index b5b554a125ba59548e2085c2b02b89c76d1b7280..b8e875c2868e3e009ffc7699a42783ee368f55c5 100644 (file)
@@ -377,8 +377,9 @@ CREATE TABLE inhta ();
 CREATE TABLE inhtb () INHERITS (inhta);
 CREATE TABLE inhtc () INHERITS (inhtb);
 CREATE TABLE inhtd () INHERITS (inhta, inhtb, inhtc);
-ALTER TABLE inhta ADD COLUMN i int;
+ALTER TABLE inhta ADD COLUMN i int, ADD COLUMN j bigint DEFAULT 1;
 \d+ inhta
+\d+ inhtd
 DROP TABLE inhta, inhtb, inhtc, inhtd;
 
 -- Test for renaming in diamond inheritance