aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2025-04-02 11:13:01 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2025-04-02 11:13:01 -0400
commit0941aadcd55b58a03af5d06f3374ca168522097f (patch)
tree38ffc94ec2dbfd4e079d038f81e587c2d9aa0347 /src
parentb19893b94bdea3b206cb544619d84cea6276f648 (diff)
downloadpostgresql-0941aadcd55b58a03af5d06f3374ca168522097f.tar.gz
postgresql-0941aadcd55b58a03af5d06f3374ca168522097f.zip
Need to do CommandCounterIncrement after StoreAttrMissingVal.
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
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/tablecmds.c2
-rw-r--r--src/test/regress/expected/inherit.out15
-rw-r--r--src/test/regress/sql/inherit.sql3
3 files changed, 18 insertions, 2 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 932cf549564..535c74feb03 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -7345,6 +7345,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);
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
index 85240a9b0bb..689f4242a1f 100644
--- a/src/test/regress/expected/inherit.out
+++ b/src/test/regress/expected/inherit.out
@@ -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);
diff --git a/src/test/regress/sql/inherit.sql b/src/test/regress/sql/inherit.sql
index 51251b0e511..572512cba01 100644
--- a/src/test/regress/sql/inherit.sql
+++ b/src/test/regress/sql/inherit.sql
@@ -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