Skip to content

Commit e83d60b

Browse files
author
Antonin Houska
committed
Enforce tuple mapping if attribute has been dropped.
1 parent 1666357 commit e83d60b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pg_rewrite.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,6 +2295,7 @@ make_attrmap_ext(int maplen)
22952295
res = (AttrMapExt *) palloc0(sizeof(AttrMapExt));
22962296
res->maplen = maplen;
22972297
res->attnums = (AttrNumber *) palloc0(sizeof(AttrNumber) * maplen);
2298+
res->dropped_attr = false;
22982299
res->coerceExprs = palloc0_array(Node *, maplen);
22992300
return res;
23002301
}
@@ -2382,7 +2383,10 @@ build_attrmap_by_name_ext(TupleDesc indesc,
23822383
int j;
23832384

23842385
if (outatt->attisdropped)
2386+
{
2387+
attrMap->dropped_attr = true;
23852388
continue; /* attrMap->attnums[i] is already 0 */
2389+
}
23862390
attname = NameStr(outatt->attname);
23872391
atttypid = outatt->atttypid;
23882392
atttypmod = outatt->atttypmod;
@@ -2408,7 +2412,10 @@ build_attrmap_by_name_ext(TupleDesc indesc,
24082412

24092413
inatt = TupleDescAttr(indesc, nextindesc);
24102414
if (inatt->attisdropped)
2415+
{
2416+
attrMap->dropped_attr = true;
24112417
continue;
2418+
}
24122419
if (strcmp(attname, NameStr(inatt->attname)) == 0)
24132420
{
24142421
/* Found it, check type */
@@ -2476,6 +2483,14 @@ check_attrmap_match_ext(TupleDesc indesc,
24762483
{
24772484
int i;
24782485

2486+
/*
2487+
* Dropped attribute in either descriptor makes the function return false,
2488+
* even if it appears in both descriptors and at the same position. Thus
2489+
* we (mis)use the map to get rid of the values of the dropped columns.
2490+
*/
2491+
if (attrMap->dropped_attr)
2492+
return false;
2493+
24792494
/* no match if attribute numbers are not the same */
24802495
if (indesc->natts != outdesc->natts)
24812496
return false;

pg_rewrite.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ typedef struct AttrMapExt
180180
{
181181
AttrNumber *attnums;
182182
int maplen;
183+
bool dropped_attr; /* Has outer or inner descriptor a dropped
184+
* attribute? */
183185
Node **coerceExprs; /* Non-NULL field tells how to convert the input
184186
* value to the output data type. NULL indicates
185187
* that no conversion is needed. */

0 commit comments

Comments
 (0)