From a593cbdbbb437636d44ceb86c81c82c831ba612a Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Mon, 18 Jun 2012 15:17:57 +0900 Subject: Fix for bug 3535915: INSERT SELECT for partially replicated tables Remote DML planning was not taking into account the node list to be used on a relation when modifying data on it. This has been enlighten by a test case with INSERT SELECT on tables replicated defined on a sub-cluster. For example, in the case of a cluster with 2 Datanodes dn1 and dn2: CREATE TABLE aa1 (a int) DISTRIBUTE BY REPLICATION TO NODE dn1; CREATE TABLE aa2 (a int) DISTRIBUTE BY HASH(a); INSERT INTO aa2 VALUES (1),(2),(3),(4); INSERT INTO aa1 SELECT * FROM aa2; The last INSERT SELECT was inserting data on all the nodes instead of doing it only on Datanode dn1. --- src/backend/optimizer/plan/createplan.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index 0099d9d886..6972cd3e53 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -5624,7 +5624,7 @@ create_remoteinsert_plan(PlannerInfo *root, Plan *topplan) fstep->exec_nodes = makeNode(ExecNodes); fstep->exec_nodes->baselocatortype = rel_loc_info->locatorType; fstep->exec_nodes->primarynodelist = NULL; - fstep->exec_nodes->nodeList = NULL; + fstep->exec_nodes->nodeList = rel_loc_info->nodeList; fstep->exec_nodes->en_relid = ttab->relid; fstep->exec_nodes->accesstype = RELATION_ACCESS_INSERT; fstep->exec_nodes->en_expr = pgxc_set_en_expr(ttab->relid, resultRelationIndex); @@ -5872,6 +5872,7 @@ create_remoteupdate_plan(PlannerInfo *root, Plan *topplan) fstep->exec_nodes = GetRelationNodes(rel_loc_info, 0, true, UNKNOWNOID, RELATION_ACCESS_UPDATE); fstep->exec_nodes->baselocatortype = rel_loc_info->locatorType; fstep->exec_nodes->en_relid = ttab->relid; + fstep->exec_nodes->nodeList = rel_loc_info->nodeList; fstep->exec_nodes->accesstype = RELATION_ACCESS_UPDATE; fstep->exec_nodes->en_expr = pgxc_set_en_expr(ttab->relid, resultRelationIndex); SetRemoteStatementName((Plan *) fstep, NULL, tot_prepparams, param_types, 0); @@ -6019,6 +6020,7 @@ create_remotedelete_plan(PlannerInfo *root, Plan *topplan) RELATION_ACCESS_UPDATE); fstep->exec_nodes->baselocatortype = rel_loc_info->locatorType; fstep->exec_nodes->en_relid = ttab->relid; + fstep->exec_nodes->nodeList = rel_loc_info->nodeList; fstep->exec_nodes->accesstype = RELATION_ACCESS_UPDATE; SetRemoteStatementName((Plan *) fstep, NULL, tot_prepparams, param_types, 0); pfree(buf->data); -- cgit v1.2.3