1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-16 06:01:02 +03:00

Teach map_partition_varattnos to handle whole-row expressions.

Otherwise, partitioned tables with RETURNING expressions or subject
to a WITH CHECK OPTION do not work properly.

Amit Langote, reviewed by Amit Khandekar and Etsuro Fujita.  A few
comment changes by me.

Discussion: http://postgr.es/m/9a39df80-871e-6212-0684-f93c83be4097@lab.ntt.co.jp
This commit is contained in:
Robert Haas
2017-08-03 11:21:29 -04:00
parent 5ff3d73813
commit 610e8ebb0f
11 changed files with 157 additions and 25 deletions

View File

@ -1989,7 +1989,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
expr = map_variable_attnos(stringToNode(check[i].ccbin),
1, 0,
newattno, tupleDesc->natts,
&found_whole_row);
InvalidOid, &found_whole_row);
/*
* For the moment we have to reject whole-row variables. We
@ -8874,7 +8874,7 @@ ATPrepAlterColumnType(List **wqueue,
map_variable_attnos(def->cooked_default,
1, 0,
attmap, RelationGetDescr(rel)->natts,
&found_whole_row);
InvalidOid, &found_whole_row);
if (found_whole_row)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@ -13713,6 +13713,7 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
Oid part_relid = lfirst_oid(lc);
Relation part_rel;
Expr *constr;
bool found_whole_row;
/* Lock already taken */
if (part_relid != RelationGetRelid(attachRel))
@ -13738,7 +13739,12 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
constr = linitial(partConstraint);
tab->partition_constraint = (Expr *)
map_partition_varattnos((List *) constr, 1,
part_rel, rel);
part_rel, rel,
&found_whole_row);
/* There can never be a whole-row reference here */
if (found_whole_row)
elog(ERROR, "unexpected whole-row reference found in partition key");
/* keep our lock until commit */
if (part_rel != attachRel)
heap_close(part_rel, NoLock);