diff --git a/src/backend/distributed/planner/multi_logical_optimizer.c b/src/backend/distributed/planner/multi_logical_optimizer.c index 7acf85d7e..787937079 100644 --- a/src/backend/distributed/planner/multi_logical_optimizer.c +++ b/src/backend/distributed/planner/multi_logical_optimizer.c @@ -259,6 +259,7 @@ MultiLogicalPlanOptimize(MultiTreeRoot *multiLogicalPlan) MultiTable *tableNode = (MultiTable *) lfirst(tableNodeCell); if (tableNode->relationId == SUBQUERY_RELATION_ID) { + ErrorIfContainsUnsupportedAggregate((MultiNode *) tableNode); TransformSubqueryNode(tableNode); } } @@ -2145,8 +2146,9 @@ ErrorIfUnsupportedAggregateDistinct(Aggref *aggregateExpression, bool distinctSupported = true; List *repartitionNodeList = NIL; Var *distinctColumn = NULL; - - AggregateType aggregateType = GetAggregateType(aggregateExpression->aggfnoid); + List *multiTableNodeList = NIL; + ListCell *multiTableNodeCell = NULL; + AggregateType aggregateType = AGGREGATE_INVALID_FIRST; /* check if logical plan includes a subquery */ List *subqueryMultiTableList = SubqueryMultiTableList(logicalPlanNode); @@ -2157,7 +2159,20 @@ ErrorIfUnsupportedAggregateDistinct(Aggref *aggregateExpression, errdetail("distinct in the outermost query is unsupported"))); } + multiTableNodeList = FindNodesOfType(logicalPlanNode, T_MultiTable); + foreach(multiTableNodeCell, multiTableNodeList) + { + MultiTable *multiTable = (MultiTable *) lfirst(multiTableNodeCell); + if (multiTable->relationId == SUBQUERY_RELATION_ID) + { + ereport(ERROR, (errmsg("cannot compute count (distinct)"), + errdetail("Subqueries with aggregate (distinct) are " + "not supported yet"))); + } + } + /* if we have a count(distinct), and distinct approximation is enabled */ + aggregateType = GetAggregateType(aggregateExpression->aggfnoid); if (aggregateType == AGGREGATE_COUNT && CountDistinctErrorRate != DISABLE_DISTINCT_APPROXIMATION) { diff --git a/src/test/regress/expected/multi_single_relation_subquery.out b/src/test/regress/expected/multi_single_relation_subquery.out index 1573e3a0a..3a01f8a3a 100644 --- a/src/test/regress/expected/multi_single_relation_subquery.out +++ b/src/test/regress/expected/multi_single_relation_subquery.out @@ -171,6 +171,18 @@ from l_tax) as distributed_table; ERROR: cannot perform distributed planning on this query DETAIL: Subqueries without aggregates are not supported yet +-- Check that we don't support subqueries with count(distinct). +select + different_shipment_days +from + (select + count(distinct l_shipdate) as different_shipment_days + from + lineitem + group by + l_partkey) as distributed_table; +ERROR: cannot compute count (distinct) +DETAIL: Subqueries with aggregate (distinct) are not supported yet -- Check that if subquery is pulled, we don't error and run query properly. SELECT max(l_suppkey) FROM ( diff --git a/src/test/regress/sql/multi_single_relation_subquery.sql b/src/test/regress/sql/multi_single_relation_subquery.sql index 19e56f60e..08853b639 100644 --- a/src/test/regress/sql/multi_single_relation_subquery.sql +++ b/src/test/regress/sql/multi_single_relation_subquery.sql @@ -125,6 +125,18 @@ from group by l_tax) as distributed_table; +-- Check that we don't support subqueries with count(distinct). + +select + different_shipment_days +from + (select + count(distinct l_shipdate) as different_shipment_days + from + lineitem + group by + l_partkey) as distributed_table; + -- Check that if subquery is pulled, we don't error and run query properly. SELECT max(l_suppkey) FROM