mirror of https://github.com/citusdata/citus.git
Merge pull request #1297 from citusdata/subquery_use_original_query
Subquery pushdown planner uses original querypull/1298/head
commit
723e9a1a7f
|
@ -104,28 +104,35 @@ static MultiNode * ApplyCartesianProduct(MultiNode *leftNode, MultiNode *rightNo
|
||||||
* Local functions forward declarations for subquery pushdown. Note that these
|
* Local functions forward declarations for subquery pushdown. Note that these
|
||||||
* functions will be removed with upcoming subqery changes.
|
* functions will be removed with upcoming subqery changes.
|
||||||
*/
|
*/
|
||||||
static MultiNode * SubqueryPushdownMultiPlanTree(Query *queryTree,
|
static MultiNode * SubqueryPushdownMultiPlanTree(Query *queryTree);
|
||||||
List *subqueryEntryList);
|
|
||||||
static void ErrorIfSubqueryJoin(Query *queryTree);
|
static void ErrorIfSubqueryJoin(Query *queryTree);
|
||||||
static MultiTable * MultiSubqueryPushdownTable(RangeTblEntry *subqueryRangeTableEntry);
|
static MultiTable * MultiSubqueryPushdownTable(RangeTblEntry *subqueryRangeTableEntry);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* MultiLogicalPlanCreate takes in a parsed query tree, uses helper functions to
|
* MultiLogicalPlanCreate takes in both the original query and its corresponding modified
|
||||||
* create logical plan and adds a root node to top of it.
|
* query tree yield by the standard planner. It uses helper functions to create logical
|
||||||
|
* plan and adds a root node to top of it. The original query is only used for subquery
|
||||||
|
* pushdown planning.
|
||||||
*/
|
*/
|
||||||
MultiTreeRoot *
|
MultiTreeRoot *
|
||||||
MultiLogicalPlanCreate(Query *queryTree)
|
MultiLogicalPlanCreate(Query *originalQuery, Query *queryTree)
|
||||||
{
|
{
|
||||||
MultiNode *multiQueryNode = NULL;
|
MultiNode *multiQueryNode = NULL;
|
||||||
MultiTreeRoot *rootNode = NULL;
|
MultiTreeRoot *rootNode = NULL;
|
||||||
|
List *subqueryEntryList = NULL;
|
||||||
|
|
||||||
List *subqueryEntryList = SubqueryEntryList(queryTree);
|
/*
|
||||||
|
* We check the existence of subqueries in the modified query given that
|
||||||
|
* if postgres already flattened the subqueries, MultiPlanTree() can plan
|
||||||
|
* corresponding distributed plan.
|
||||||
|
*/
|
||||||
|
subqueryEntryList = SubqueryEntryList(queryTree);
|
||||||
if (subqueryEntryList != NIL)
|
if (subqueryEntryList != NIL)
|
||||||
{
|
{
|
||||||
if (SubqueryPushdown)
|
if (SubqueryPushdown)
|
||||||
{
|
{
|
||||||
multiQueryNode = SubqueryPushdownMultiPlanTree(queryTree, subqueryEntryList);
|
multiQueryNode = SubqueryPushdownMultiPlanTree(originalQuery);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1982,7 +1989,7 @@ ApplyCartesianProduct(MultiNode *leftNode, MultiNode *rightNode,
|
||||||
* from other parts of code although it causes some code duplication.
|
* from other parts of code although it causes some code duplication.
|
||||||
*/
|
*/
|
||||||
static MultiNode *
|
static MultiNode *
|
||||||
SubqueryPushdownMultiPlanTree(Query *queryTree, List *subqueryEntryList)
|
SubqueryPushdownMultiPlanTree(Query *queryTree)
|
||||||
{
|
{
|
||||||
List *targetEntryList = queryTree->targetList;
|
List *targetEntryList = queryTree->targetList;
|
||||||
List *qualifierList = NIL;
|
List *qualifierList = NIL;
|
||||||
|
@ -1997,6 +2004,7 @@ SubqueryPushdownMultiPlanTree(Query *queryTree, List *subqueryEntryList)
|
||||||
MultiExtendedOp *extendedOpNode = NULL;
|
MultiExtendedOp *extendedOpNode = NULL;
|
||||||
MultiNode *currentTopNode = NULL;
|
MultiNode *currentTopNode = NULL;
|
||||||
RangeTblEntry *subqueryRangeTableEntry = NULL;
|
RangeTblEntry *subqueryRangeTableEntry = NULL;
|
||||||
|
List *subqueryEntryList = SubqueryEntryList(queryTree);
|
||||||
|
|
||||||
/* verify we can perform distributed planning on this query */
|
/* verify we can perform distributed planning on this query */
|
||||||
ErrorIfQueryNotSupported(queryTree);
|
ErrorIfQueryNotSupported(queryTree);
|
||||||
|
|
|
@ -295,7 +295,7 @@ CreateDistributedPlan(PlannedStmt *localPlan, Query *originalQuery, Query *query
|
||||||
if ((!distributedPlan || distributedPlan->planningError) && !hasUnresolvedParams)
|
if ((!distributedPlan || distributedPlan->planningError) && !hasUnresolvedParams)
|
||||||
{
|
{
|
||||||
/* Create and optimize logical plan */
|
/* Create and optimize logical plan */
|
||||||
MultiTreeRoot *logicalPlan = MultiLogicalPlanCreate(query);
|
MultiTreeRoot *logicalPlan = MultiLogicalPlanCreate(originalQuery, query);
|
||||||
MultiLogicalPlanOptimize(logicalPlan, plannerRestrictionContext);
|
MultiLogicalPlanOptimize(logicalPlan, plannerRestrictionContext);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -180,7 +180,7 @@ extern bool SubqueryPushdown;
|
||||||
|
|
||||||
|
|
||||||
/* Function declarations for building logical plans */
|
/* Function declarations for building logical plans */
|
||||||
extern MultiTreeRoot * MultiLogicalPlanCreate(Query *queryTree);
|
extern MultiTreeRoot * MultiLogicalPlanCreate(Query *originalQuery, Query *queryTree);
|
||||||
extern bool NeedsDistributedPlanning(Query *queryTree);
|
extern bool NeedsDistributedPlanning(Query *queryTree);
|
||||||
extern MultiNode * ParentNode(MultiNode *multiNode);
|
extern MultiNode * ParentNode(MultiNode *multiNode);
|
||||||
extern MultiNode * ChildNode(MultiUnaryNode *multiNode);
|
extern MultiNode * ChildNode(MultiUnaryNode *multiNode);
|
||||||
|
|
|
@ -178,7 +178,8 @@ SELECT count(*) FROM
|
||||||
(SELECT l_orderkey FROM lineitem_subquery) UNION ALL
|
(SELECT l_orderkey FROM lineitem_subquery) UNION ALL
|
||||||
(SELECT 1::bigint)
|
(SELECT 1::bigint)
|
||||||
) b;
|
) b;
|
||||||
ERROR: could not run distributed query with complex table expressions
|
ERROR: cannot push down this subquery
|
||||||
|
DETAIL: Union All clauses are currently unsupported
|
||||||
---
|
---
|
||||||
-- TEMPORARLY DISABLE UNIONS WITHOUT JOINS
|
-- TEMPORARLY DISABLE UNIONS WITHOUT JOINS
|
||||||
---
|
---
|
||||||
|
|
|
@ -178,7 +178,8 @@ SELECT count(*) FROM
|
||||||
(SELECT l_orderkey FROM lineitem_subquery) UNION ALL
|
(SELECT l_orderkey FROM lineitem_subquery) UNION ALL
|
||||||
(SELECT 1::bigint)
|
(SELECT 1::bigint)
|
||||||
) b;
|
) b;
|
||||||
ERROR: could not run distributed query with complex table expressions
|
ERROR: cannot push down this subquery
|
||||||
|
DETAIL: Union All clauses are currently unsupported
|
||||||
---
|
---
|
||||||
-- TEMPORARLY DISABLE UNIONS WITHOUT JOINS
|
-- TEMPORARLY DISABLE UNIONS WITHOUT JOINS
|
||||||
---
|
---
|
||||||
|
|
Loading…
Reference in New Issue