aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-12-25 15:44:15 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2019-12-25 15:44:15 -0500
commitbb4114a4e2c65f27931cc074214c051dba2876c3 (patch)
treef197bcc85c7479e20905e9f821893d5c49eb67b3 /src/backend/commands/tablecmds.c
parent42f74f49367bee1d3da28c4b383faec29364f320 (diff)
downloadpostgresql-bb4114a4e2c65f27931cc074214c051dba2876c3.tar.gz
postgresql-bb4114a4e2c65f27931cc074214c051dba2876c3.zip
Allow whole-row Vars to be used in partitioning expressions.
In the wake of commit 5b9312378, there's no particular reason for this restriction (previously, it was problematic because of the implied rowtype reference). A simple constraint on a whole-row Var probably isn't that useful, but conceivably somebody would want to pass one to a function that extracts a partitioning key. Besides which, we're expending much more code to enforce the restriction than we save by having it, since the latter quantity is now zero. So drop the restriction. Amit Langote Discussion: https://postgr.es/m/CA+HiwqFUzjfj9HEsJtYWcr1SgQ_=iCAvQ=O2Sx6aQxoDu4OiHw@mail.gmail.com
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c40
1 files changed, 10 insertions, 30 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index a776e652f4b..e19772aa903 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -15168,15 +15168,11 @@ ComputePartitionAttrs(ParseState *pstate, Relation rel, List *partParams, AttrNu
*/
/*
- * Cannot have expressions containing whole-row references or
- * system column references.
+ * Cannot allow system column references, since that would
+ * make partition routing impossible: their values won't be
+ * known yet when we need to do that.
*/
pull_varattnos(expr, 1, &expr_attrs);
- if (bms_is_member(0 - FirstLowInvalidHeapAttributeNumber,
- expr_attrs))
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
- errmsg("partition key expressions cannot contain whole-row references")));
for (i = FirstLowInvalidHeapAttributeNumber; i < 0; i++)
{
if (bms_is_member(i - FirstLowInvalidHeapAttributeNumber,
@@ -15196,7 +15192,8 @@ ComputePartitionAttrs(ParseState *pstate, Relation rel, List *partParams, AttrNu
{
AttrNumber attno = i + FirstLowInvalidHeapAttributeNumber;
- if (TupleDescAttr(RelationGetDescr(rel), attno - 1)->attgenerated)
+ if (attno > 0 &&
+ TupleDescAttr(RelationGetDescr(rel), attno - 1)->attgenerated)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("cannot use generated column in partition key"),
@@ -15451,7 +15448,6 @@ QueuePartitionConstraintValidation(List **wqueue, Relation scanrel,
for (i = 0; i < partdesc->nparts; i++)
{
Relation part_rel;
- bool found_whole_row;
List *thisPartConstraint;
/*
@@ -15465,10 +15461,7 @@ QueuePartitionConstraintValidation(List **wqueue, Relation scanrel,
*/
thisPartConstraint =
map_partition_varattnos(partConstraint, 1,
- part_rel, scanrel, &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 constraint");
+ part_rel, scanrel);
QueuePartitionConstraintValidation(wqueue, part_rel,
thisPartConstraint,
@@ -15497,7 +15490,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
TupleDesc tupleDesc;
ObjectAddress address;
const char *trigger_name;
- bool found_whole_row;
Oid defaultPartOid;
List *partBoundConstraint;
@@ -15714,11 +15706,7 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
* numbers.
*/
partConstraint = map_partition_varattnos(partConstraint, 1, attachrel,
- 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");
+ rel);
/* Validate partition constraints against the table being attached. */
QueuePartitionConstraintValidation(wqueue, attachrel, partConstraint,
@@ -15750,7 +15738,7 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
*/
defPartConstraint =
map_partition_varattnos(defPartConstraint,
- 1, defaultrel, rel, NULL);
+ 1, defaultrel, rel);
QueuePartitionConstraintValidation(wqueue, defaultrel,
defPartConstraint, true);
@@ -16004,19 +15992,11 @@ CloneRowTriggersToPartition(Relation parent, Relation partition)
RelationGetDescr(pg_trigger), &isnull);
if (!isnull)
{
- bool found_whole_row;
-
qual = stringToNode(TextDatumGetCString(value));
qual = (Node *) map_partition_varattnos((List *) qual, PRS2_OLD_VARNO,
- partition, parent,
- &found_whole_row);
- if (found_whole_row)
- elog(ERROR, "unexpected whole-row reference found in trigger WHEN clause");
+ partition, parent);
qual = (Node *) map_partition_varattnos((List *) qual, PRS2_NEW_VARNO,
- partition, parent,
- &found_whole_row);
- if (found_whole_row)
- elog(ERROR, "unexpected whole-row reference found in trigger WHEN clause");
+ partition, parent);
}
/*