Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Interpreters/ActionsDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ ActionsDAG::ActionsDAG(const NamesAndTypesList & inputs_)
outputs.push_back(&addInput(input.name, input.type));
}

ActionsDAG::ActionsDAG(const ColumnsWithTypeAndName & inputs_)
ActionsDAG::ActionsDAG(const ColumnsWithTypeAndName & inputs_, bool duplicate_const_columns)
{
for (const auto & input : inputs_)
{
if (input.column && isColumnConst(*input.column))
if (input.column && isColumnConst(*input.column) && duplicate_const_columns)
{
addInput(input);

Expand Down
2 changes: 1 addition & 1 deletion src/Interpreters/ActionsDAG.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class ActionsDAG
ActionsDAG & operator=(ActionsDAG &&) = default;
ActionsDAG & operator=(const ActionsDAG &) = delete;
explicit ActionsDAG(const NamesAndTypesList & inputs_);
explicit ActionsDAG(const ColumnsWithTypeAndName & inputs_);
explicit ActionsDAG(const ColumnsWithTypeAndName & inputs_, bool duplicate_const_columns = true);

const Nodes & getNodes() const { return nodes; }
static Nodes detachNodes(ActionsDAG && dag) { return std::move(dag.nodes); }
Expand Down
4 changes: 3 additions & 1 deletion src/Planner/PlannerExpressionAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ std::optional<AggregationAnalysisResult> analyzeAggregation(const QueryTreeNodeP
Names aggregation_keys;

ActionsAndProjectInputsFlagPtr before_aggregation_actions = std::make_shared<ActionsAndProjectInputsFlag>();
before_aggregation_actions->dag = ActionsDAG(input_columns);
/// Here it is OK to materialize const columns: if column is used in GROUP BY, it may be expected to become non-const
/// See https://github.com/ClickHouse/ClickHouse/issues/70655 for example
before_aggregation_actions->dag = ActionsDAG(input_columns, false);
before_aggregation_actions->dag.getOutputs().clear();

std::unordered_set<std::string_view> before_aggregation_actions_output_node_names;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ iphone 1
iphone 1
iphone 1

iphone 1
\N 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Const column in grouping set, analyzer on:
0 0 value 0 1
0 0 value 1 1
0 0 value 2 1
0 0 value 3 1
1 0 0 1
1 0 1 1
1 0 2 1
1 0 3 1
Non-const column in grouping set, analyzer on:
0 0 value 0 1
0 0 value 1 1
0 0 value 2 1
0 0 value 3 1
1 0 0 1
1 0 1 1
1 0 2 1
1 0 3 1
Const column in grouping set, analyzer off:
0 0 value 0 1
0 0 value 1 1
0 0 value 2 1
0 0 value 3 1
1 0 0 1
1 0 1 1
1 0 2 1
1 0 3 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
SET enable_analyzer=1;

SELECT 'Const column in grouping set, analyzer on:';

SELECT grouping(key_a), grouping(key_b), key_a, key_b, count() FROM (
SELECT 'value' as key_a, number as key_b FROM numbers(4)
)
GROUP BY GROUPING SETS((key_b), (key_a, key_b))
ORDER BY (grouping(key_a), grouping(key_b), key_a, key_b);

SELECT 'Non-const column in grouping set, analyzer on:';

SELECT grouping(key_a), grouping(key_b), key_a, key_b, count() FROM (
SELECT materialize('value') as key_a, number as key_b FROM numbers(4)
)
GROUP BY GROUPING SETS((key_b), (key_a, key_b))
ORDER BY (grouping(key_a), grouping(key_b), key_a, key_b);

SELECT 'Const column in grouping set, analyzer off:';

SELECT grouping(key_a), grouping(key_b), key_a, key_b, count() FROM (
SELECT 'value' as key_a, number as key_b FROM numbers(4)
)
GROUP BY GROUPING SETS((key_b), (key_a, key_b))
ORDER BY (grouping(key_a), grouping(key_b), key_a, key_b)
SETTINGS allow_experimental_analyzer=0;
Loading