diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2021-06-18 06:51:12 -0400 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2021-06-18 06:51:12 -0400 |
commit | 0a4efdc7ebf2584257b166c87e82797eb92815b5 (patch) | |
tree | 72ba741ef759f1ccb2709bc4ac0e4357974ea289 /src/backend | |
parent | 981524d2e3aa3f28d364c472e34f5386be846811 (diff) | |
download | postgresql-0a4efdc7ebf2584257b166c87e82797eb92815b5.tar.gz postgresql-0a4efdc7ebf2584257b166c87e82797eb92815b5.zip |
Don't set a fast default for anything but a plain table
The fast default code added in Release 11 omitted to check that the
table a fast default was being added to was a plain table. Thus one
could be added to a foreign table, which predicably blows up. Here we
perform that check.
In addition, on the back branches, since some of these might have
escaped into the wild, if we encounter a missing value for
an attribute of something other than a plain table we ignore it.
Fixes bug #17056
Backpatch to release 11,
Reviewed by: Andres Freund, Álvaro Herrera and Tom Lane
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/catalog/heap.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index afa830d9248..1293dc04caa 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -2161,6 +2161,13 @@ SetAttrMissing(Oid relid, char *attname, char *value) /* lock the table the attribute belongs to */ tablerel = table_open(relid, AccessExclusiveLock); + /* Don't do anything unless it's a plain table */ + if (tablerel->rd_rel->relkind != RELKIND_RELATION) + { + table_close(tablerel, AccessExclusiveLock); + return; + } + /* Lock the attribute row and get the data */ attrrel = table_open(AttributeRelationId, RowExclusiveLock); atttup = SearchSysCacheAttName(relid, attname); @@ -2287,7 +2294,8 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, valuesAtt[Anum_pg_attribute_atthasdef - 1] = true; replacesAtt[Anum_pg_attribute_atthasdef - 1] = true; - if (add_column_mode && !attgenerated) + if (rel->rd_rel->relkind == RELKIND_RELATION && add_column_mode && + !attgenerated) { expr2 = expression_planner(expr2); estate = CreateExecutorState(); |