summaryrefslogtreecommitdiff
path: root/src/backend/utils/cache/relcache.c
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2021-06-18 07:44:58 -0400
committerAndrew Dunstan <andrew@dunslane.net>2021-06-18 07:46:21 -0400
commit6432bfe8a372a1c1d4ee8edc91be7fe9910bf51d (patch)
treef2fed26584c44999e2e030746077db8badeac798 /src/backend/utils/cache/relcache.c
parent70293e946e60bb7eb58f74656667458406a1b461 (diff)
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/utils/cache/relcache.c')
-rw-r--r--src/backend/utils/cache/relcache.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 2babf525380..be50de462ed 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -552,6 +552,7 @@ RelationBuildTupleDesc(Relation relation)
{
Form_pg_attribute attp;
int attnum;
+ bool atthasmissing;
attp = (Form_pg_attribute) GETSTRUCT(pg_attribute_tuple);
@@ -565,6 +566,22 @@ RelationBuildTupleDesc(Relation relation)
attp,
ATTRIBUTE_FIXED_PART_SIZE);
+ /*
+ * Fix atthasmissing flag - it's only for plain tables. Others
+ * should not have missing values set, but there may be some left from
+ * before when we placed that check, so this code defensively ignores
+ * such values.
+ */
+ atthasmissing = attp->atthasmissing;
+ if (relation->rd_rel->relkind != RELKIND_RELATION && atthasmissing)
+ {
+ Form_pg_attribute nattp;
+
+ atthasmissing = false;
+ nattp = TupleDescAttr(relation->rd_att, attnum - 1);
+ nattp->atthasmissing = false;
+ }
+
/* Update constraint/default info */
if (attp->attnotnull)
constr->has_not_null = true;
@@ -586,7 +603,7 @@ RelationBuildTupleDesc(Relation relation)
}
/* Likewise for a missing value */
- if (attp->atthasmissing)
+ if (atthasmissing)
{
Datum missingval;
bool missingNull;