mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 23:52:03 +00:00
Fix "Column is not under aggregate function and not in GROUP BY" with PREWHERE
In 21.7 the function column type is unknown: (lldb) p tmp_actions_dag->dumpDAG() (std::string) $14 = "0 : INPUT () (no column) Int32 key\n1 : COLUMN () Const(UInt8) UInt8 1\n2 : FUNCTION (0) (no column) UInt8 ignore(key) [ignore]\n3 : FUNCTION (1, 2) (no column) UInt8 or(1, ignore(key)) [or]\nIndex: 0 1 2 3\n" ^^^^^^^^^^^ While in 21.8+ it is const: (lldb) p tmp_actions_dag->dumpDAG() (std::string) $22 = "0 : INPUT () (no column) Int32 key\n1 : COLUMN () Const(UInt8) UInt8 1\n2 : FUNCTION (0) (no column) UInt8 ignore(key) [ignore]\n3 : FUNCTION (1, 2) Const(UInt8) UInt8 or(1, ignore(key)) [or]\nIndex: 0 1 2 3\n" ^^^^^ This is after getRootActions() in SelectQueryExpressionAnalyzer::appendPrewhere() v1: fix for SELECT only, but breaks virtual columns v2: hacky fix, that also touches MergeTree code v3: allow_remove_inputs=false v4: allow_constant_folding=false instead
This commit is contained in:
parent
dd7bffcaf9
commit
fbf98bea0b
@ -1045,7 +1045,12 @@ ActionsDAGPtr SelectQueryExpressionAnalyzer::appendPrewhere(
|
||||
/// Remove unused source_columns from prewhere actions.
|
||||
auto tmp_actions_dag = std::make_shared<ActionsDAG>(sourceColumns());
|
||||
getRootActions(select_query->prewhere(), only_types, tmp_actions_dag);
|
||||
tmp_actions_dag->removeUnusedActions(NameSet{prewhere_column_name});
|
||||
/// Constants cannot be removed since they can be used in other parts of the query.
|
||||
/// And if they are not used anywhere, except PREWHERE, they will be removed on the next step.
|
||||
tmp_actions_dag->removeUnusedActions(
|
||||
NameSet{prewhere_column_name},
|
||||
/* allow_remove_inputs= */ true,
|
||||
/* allow_constant_folding= */ false);
|
||||
|
||||
auto required_columns = tmp_actions_dag->getRequiredColumnsNames();
|
||||
NameSet required_source_columns(required_columns.begin(), required_columns.end());
|
||||
|
Loading…
Reference in New Issue
Block a user