From fd8df25daf4e2e45d33f9e0a3cef824644d19920 Mon Sep 17 00:00:00 2001 From: Onder Kalaci Date: Mon, 20 Feb 2017 14:00:25 +0200 Subject: [PATCH] Disallow INSERT ... SELECT to pushdown joins on non-partition keys With this commit, we disallow JOINs on non-partition keys. Simply, while instantiating the qual we check whether the qual is on the partition key. --- src/backend/distributed/planner/multi_router_planner.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/backend/distributed/planner/multi_router_planner.c b/src/backend/distributed/planner/multi_router_planner.c index a10c53d68..641864893 100644 --- a/src/backend/distributed/planner/multi_router_planner.c +++ b/src/backend/distributed/planner/multi_router_planner.c @@ -387,6 +387,7 @@ RouterModifyTaskForShardInterval(Query *originalQuery, ShardInterval *shardInter List *originalBaserestrictInfo = restriction->relOptInfo->baserestrictinfo; InstantiateQualContext instantiateQualWalker; Var *relationPartitionKey = PartitionKey(restriction->relationId); + Var *relationPartitionKey = PartitionKey(restriction->relationId); /* * We haven't added the quals if all participating tables are reference @@ -3047,6 +3048,13 @@ InstantiatePartitionQualWalker(Node *node, void *context) return node; } + /* if the qual is not on the partition column, do not instantiate */ + if (relationPartitionColumn && currentColumn && + currentColumn->varattno != relationPartitionColumn->varattno) + { + return node; + } + /* get the integer >=, <= operators from the catalog */ integer4GEoperatorId = get_opfamily_member(INTEGER_BTREE_FAM_OID, INT4OID, INT4OID,