diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2025-03-03 12:43:29 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2025-03-03 12:43:29 -0500 |
commit | aac07b56256e96f42b6d477e0a21c1266e3ffe15 (patch) | |
tree | 38ae1d00bcb34dfe3b4b589413e6fc1a44e3a23d /src/include | |
parent | ebe919e95336cbe0a0b5078189e1525bfb038385 (diff) |
Fix broken handling of domains in atthasmissing logic.
If a domain type has a default, adding a column of that type (without
any explicit DEFAULT clause) failed to install the domain's default
value in existing rows, instead leaving the new column null. This
is unexpected, and it used to work correctly before v11. The cause
is confusion in the atthasmissing mechanism about which default value
to install: we'd only consider installing an explicitly-specified
default, and then we'd decide that no table rewrite is needed.
To fix, take the responsibility for filling attmissingval out of
StoreAttrDefault, and instead put it into ATExecAddColumn's existing
logic that derives the correct value to fill the new column with.
Also, centralize the logic that determines the need for
default-related table rewriting there, instead of spreading it over
four or five places.
In the back branches, we'll leave the attmissingval-filling code
in StoreAttrDefault even though it's now dead, for fear that some
extension may be depending on that functionality to exist there.
A separate HEAD-only patch will clean up the now-useless code.
Reported-by: jian he <jian.universality@gmail.com>
Author: jian he <jian.universality@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CACJufxHFssPvkP1we7WMhPD_1kwgbG52o=kQgL+TnVoX5LOyCQ@mail.gmail.com
Backpatch-through: 13
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/catalog/heap.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/include/catalog/heap.h b/src/include/catalog/heap.h index bec795abacf..ca5cec12996 100644 --- a/src/include/catalog/heap.h +++ b/src/include/catalog/heap.h @@ -28,7 +28,7 @@ typedef struct RawColumnDefault { AttrNumber attnum; /* attribute to attach default to */ Node *raw_default; /* default value (untransformed parse tree) */ - bool missingMode; /* true if part of add column processing */ + bool missingMode; /* obsolete, no longer used */ char generated; /* attgenerated setting */ } RawColumnDefault; @@ -113,6 +113,9 @@ extern List *AddRelationNewConstraints(Relation rel, const char *queryString); extern void RelationClearMissing(Relation rel); + +extern void StoreAttrMissingVal(Relation rel, AttrNumber attnum, + Datum missingval); extern void SetAttrMissing(Oid relid, char *attname, char *value); extern Oid StoreAttrDefault(Relation rel, AttrNumber attnum, |