From bf6cc19e347d4cb8dfc8f05a59171ac06e18b5e5 Mon Sep 17 00:00:00 2001 From: Andrew Gierth Date: Wed, 5 Feb 2020 19:49:47 +0000 Subject: Force tuple conversion when the source has missing attributes. Tuple conversion incorrectly concluded that no conversion was needed as long as all the attributes lined up. But if the source tuple has a missing attribute (from addition of a column with default), then the destination tupdesc might not reflect the same default. The typical symptom was that the affected columns would be unexpectedly NULL. Repair by always forcing conversion if the source has missing attributes, which will be filled in by the deform operation. (In theory we could optimize for when the destination has the same default, but that seemed overkill.) Backpatch to 11 where missing attributes were added. Per bug #16242. Vik Fearing (discovery, code, testing) and me (analysis, testcase). Discussion: https://postgr.es/m/16242-d1c9fca28445966b@postgresql.org --- src/backend/access/common/attmap.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/backend/access/common/attmap.c') diff --git a/src/backend/access/common/attmap.c b/src/backend/access/common/attmap.c index a074852a015..2cd16d7eafb 100644 --- a/src/backend/access/common/attmap.c +++ b/src/backend/access/common/attmap.c @@ -294,8 +294,14 @@ check_attrmap_match(TupleDesc indesc, for (i = 0; i < attrMap->maplen; i++) { - Form_pg_attribute inatt; - Form_pg_attribute outatt; + Form_pg_attribute inatt = TupleDescAttr(indesc, i); + Form_pg_attribute outatt = TupleDescAttr(outdesc, i); + + /* + * If the input column has a missing attribute, we need a conversion. + */ + if (inatt->atthasmissing) + return false; if (attrMap->attnums[i] == (i + 1)) continue; @@ -305,8 +311,6 @@ check_attrmap_match(TupleDesc indesc, * dropped, we don't need a conversion. However, attlen and attalign * must agree. */ - inatt = TupleDescAttr(indesc, i); - outatt = TupleDescAttr(outdesc, i); if (attrMap->attnums[i] == 0 && inatt->attisdropped && inatt->attlen == outatt->attlen && -- cgit v1.2.3