From 08cb36417aa22436647a1831a7d1ff6b41232280 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Thu, 7 Sep 2017 10:55:45 -0400 Subject: Even if some partitions are foreign, allow tuple routing. This doesn't allow routing tuple to the foreign partitions themselves, but it permits tuples to be routed to regular partitions despite the presence of foreign partitions in the same inheritance hierarchy. Etsuro Fujita, reviewed by Amit Langote and by me. Discussion: http://postgr.es/m/bc3db4c1-1693-3b8a-559f-33ad2b50b7ad@lab.ntt.co.jp --- src/backend/executor/execMain.c | 25 ++++++++++++++++--------- src/backend/executor/nodeModifyTable.c | 2 +- src/include/executor/executor.h | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 4582a3caa00..9dcc358ec27 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -1097,8 +1097,9 @@ InitPlan(QueryDesc *queryDesc, int eflags) * CheckValidRowMarkRel. */ void -CheckValidResultRel(Relation resultRel, CmdType operation) +CheckValidResultRel(ResultRelInfo *resultRelInfo, CmdType operation) { + Relation resultRel = resultRelInfo->ri_RelationDesc; TriggerDesc *trigDesc = resultRel->trigdesc; FdwRoutine *fdwroutine; @@ -1169,10 +1170,16 @@ CheckValidResultRel(Relation resultRel, CmdType operation) break; case RELKIND_FOREIGN_TABLE: /* Okay only if the FDW supports it */ - fdwroutine = GetFdwRoutineForRelation(resultRel, false); + fdwroutine = resultRelInfo->ri_FdwRoutine; switch (operation) { case CMD_INSERT: + /* + * If foreign partition to do tuple-routing for, skip the + * check; it's disallowed elsewhere. + */ + if (resultRelInfo->ri_PartitionRoot) + break; if (fdwroutine->ExecForeignInsert == NULL) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), @@ -3305,11 +3312,6 @@ ExecSetupPartitionTupleRouting(Relation rel, partrel = heap_open(lfirst_oid(cell), NoLock); part_tupdesc = RelationGetDescr(partrel); - /* - * Verify result relation is a valid target for the current operation. - */ - CheckValidResultRel(partrel, CMD_INSERT); - /* * Save a tuple conversion map to convert a tuple routed to this * partition from the parent's type to the partition's. @@ -3323,8 +3325,10 @@ ExecSetupPartitionTupleRouting(Relation rel, rel, estate->es_instrument); - estate->es_leaf_result_relations = - lappend(estate->es_leaf_result_relations, leaf_part_rri); + /* + * Verify result relation is a valid target for INSERT. + */ + CheckValidResultRel(leaf_part_rri, CMD_INSERT); /* * Open partition indices (remember we do not support ON CONFLICT in @@ -3335,6 +3339,9 @@ ExecSetupPartitionTupleRouting(Relation rel, leaf_part_rri->ri_IndexRelationDescs == NULL) ExecOpenIndices(leaf_part_rri, false); + estate->es_leaf_result_relations = + lappend(estate->es_leaf_result_relations, leaf_part_rri); + leaf_part_rri++; i++; } diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index 70a6b847a0e..83267580a35 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -1853,7 +1853,7 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags) /* * Verify result relation is a valid target for the current operation */ - CheckValidResultRel(resultRelInfo->ri_RelationDesc, operation); + CheckValidResultRel(resultRelInfo, operation); /* * If there are indices on the result relation, open them and save diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h index eacbea3c365..379e7c77a18 100644 --- a/src/include/executor/executor.h +++ b/src/include/executor/executor.h @@ -177,7 +177,7 @@ extern void ExecutorEnd(QueryDesc *queryDesc); extern void standard_ExecutorEnd(QueryDesc *queryDesc); extern void ExecutorRewind(QueryDesc *queryDesc); extern bool ExecCheckRTPerms(List *rangeTable, bool ereport_on_violation); -extern void CheckValidResultRel(Relation resultRel, CmdType operation); +extern void CheckValidResultRel(ResultRelInfo *resultRelInfo, CmdType operation); extern void InitResultRelInfo(ResultRelInfo *resultRelInfo, Relation resultRelationDesc, Index resultRelationIndex, -- cgit v1.2.3