Ensure ROLLUP and CUBE respect HAVING (no change to TOTALS)

This commit is contained in:
Samuel Chou 2018-12-14 22:27:40 -08:00
parent af31ff24b9
commit fcde47b45e
3 changed files with 42 additions and 4 deletions

View File

@ -606,6 +606,8 @@ void InterpreterSelectQuery::executeImpl(Pipeline & pipeline, const BlockInputSt
executeRollupOrCube(pipeline, Modificator::ROLLUP);
else if (query.group_by_with_cube)
executeRollupOrCube(pipeline, Modificator::CUBE);
if ((query.group_by_with_rollup || query.group_by_with_cube) && expressions.has_having)
executeHaving(pipeline, expressions.before_having);
}
else if (expressions.has_having)
executeHaving(pipeline, expressions.before_having);
@ -625,10 +627,15 @@ void InterpreterSelectQuery::executeImpl(Pipeline & pipeline, const BlockInputSt
executeTotalsAndHaving(pipeline, expressions.has_having, expressions.before_having, aggregate_overflow_row, final);
}
if (query.group_by_with_rollup && !aggregate_final)
executeRollupOrCube(pipeline, Modificator::ROLLUP);
else if (query.group_by_with_cube && !aggregate_final)
executeRollupOrCube(pipeline, Modificator::CUBE);
if ((query.group_by_with_rollup || query.group_by_with_cube) && !aggregate_final)
{
if (query.group_by_with_rollup)
executeRollupOrCube(pipeline, Modificator::ROLLUP);
else if (query.group_by_with_cube)
executeRollupOrCube(pipeline, Modificator::CUBE);
if (expressions.has_having)
executeHaving(pipeline, expressions.before_having);
}
}
if (expressions.has_order_by)
@ -1483,3 +1490,4 @@ void InterpreterSelectQuery::initSettings()
}
}

View File

@ -0,0 +1,15 @@
a \N 1
a b 1
a \N 2
a b 1
a \N 1
a b 1
a \N 2
\N \N 2
\N \N 2
a b 1
a \N 1
\N \N 1
\N \N 1

View File

@ -0,0 +1,15 @@
DROP TABLE IF EXISTS test.rollup_having;
CREATE TABLE test.rollup_having (
a Nullable(String),
b Nullable(String)
) ENGINE = Memory;
INSERT INTO test.rollup_having VALUES (NULL, NULL);
INSERT INTO test.rollup_having VALUES ('a', NULL);
INSERT INTO test.rollup_having VALUES ('a', 'b');
SELECT a, b, count(*) FROM test.rollup_having GROUP BY a, b WITH ROLLUP HAVING a IS NOT NULL;
SELECT a, b, count(*) FROM test.rollup_having GROUP BY a, b WITH ROLLUP HAVING a IS NOT NULL and b IS NOT NULL;
SELECT a, b, count(*) FROM test.rollup_having GROUP BY a, b WITH ROLLUP WITH TOTALS HAVING a IS NOT NULL;
SELECT a, b, count(*) FROM test.rollup_having GROUP BY a, b WITH ROLLUP WITH TOTALS HAVING a IS NOT NULL and b IS NOT NULL;