fix pushdown of having

This commit is contained in:
Anton Popov 2021-04-07 17:01:04 +03:00
parent c5354885a6
commit fa9a19cbdd
3 changed files with 15 additions and 2 deletions

View File

@ -38,7 +38,7 @@ static size_t tryAddNewFilterStep(
auto * filter = static_cast<FilterStep *>(parent.get());
const auto & expression = filter->getExpression();
const auto & filter_column_name = filter->getFilterColumnName();
const auto filter_column_name = filter->getFilterColumnName();
bool removes_filter = filter->removesFilterColumn();
// std::cerr << "Filter: \n" << expression->dumpDAG() << std::endl;
@ -75,9 +75,10 @@ static size_t tryAddNewFilterStep(
/// New filter column is added to the end.
auto split_filter_column_name = (*split_filter->getIndex().rbegin())->result_name;
bool remove_split_filter_column = (split_filter_column_name != filter_column_name || removes_filter);
node.step = std::make_unique<FilterStep>(
node.children.at(0)->step->getOutputStream(),
std::move(split_filter), std::move(split_filter_column_name), true);
std::move(split_filter), std::move(split_filter_column_name), remove_split_filter_column);
return 3;
}

View File

@ -0,0 +1 @@
1 1 2

View File

@ -0,0 +1,11 @@
DROP TABLE IF EXISTS t_having;
CREATE TABLE t_having (c0 Int32, c1 UInt64) ENGINE = Memory;
INSERT INTO t_having SELECT number, number FROM numbers(1000);
SELECT sum(c0 = 0), min(c0 + 1), sum(c0 + 2) FROM t_having
GROUP BY c0 HAVING c0 = 0
SETTINGS enable_optimize_predicate_expression=0;
DROP TABLE t_having;