Add check for count distinct on single table subqueries

Fixes #314
pull/335/head
Metin Doslu 2016-02-12 19:12:42 +02:00
parent 2160a2951b
commit 6123022ca7
3 changed files with 41 additions and 2 deletions

View File

@ -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)
{

View File

@ -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
(

View File

@ -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