mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 16:12:01 +00:00
Fix wrong columns order for queries with parallel FINAL.
This commit is contained in:
parent
561b094e69
commit
30ccfa1638
@ -254,6 +254,32 @@ namespace ErrorCodes
|
|||||||
extern const int LOGICAL_ERROR;
|
extern const int LOGICAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void reorderColumns(ActionsDAG & dag, const Block & header, const std::string & filter_column)
|
||||||
|
{
|
||||||
|
std::unordered_map<std::string_view, const ActionsDAG::Node *> inputs_map;
|
||||||
|
for (const auto * input : dag.getInputs())
|
||||||
|
inputs_map[input->result_name] = input;
|
||||||
|
|
||||||
|
for (const auto & col : header)
|
||||||
|
{
|
||||||
|
auto & input = inputs_map[col.name];
|
||||||
|
if (!input)
|
||||||
|
input = &dag.addInput(col);
|
||||||
|
}
|
||||||
|
|
||||||
|
ActionsDAG::NodeRawConstPtrs new_outputs;
|
||||||
|
new_outputs.reserve(header.columns() + 1);
|
||||||
|
|
||||||
|
new_outputs.push_back(&dag.findInOutputs(filter_column));
|
||||||
|
for (const auto & col : header)
|
||||||
|
{
|
||||||
|
auto & input = inputs_map[col.name];
|
||||||
|
new_outputs.push_back(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
dag.getOutputs() = std::move(new_outputs);
|
||||||
|
}
|
||||||
|
|
||||||
Pipes buildPipesForReadingByPKRanges(
|
Pipes buildPipesForReadingByPKRanges(
|
||||||
const KeyDescription & primary_key,
|
const KeyDescription & primary_key,
|
||||||
ExpressionActionsPtr sorting_expr,
|
ExpressionActionsPtr sorting_expr,
|
||||||
@ -279,6 +305,7 @@ Pipes buildPipesForReadingByPKRanges(
|
|||||||
continue;
|
continue;
|
||||||
auto syntax_result = TreeRewriter(context).analyze(filter_function, primary_key.expression->getRequiredColumnsWithTypes());
|
auto syntax_result = TreeRewriter(context).analyze(filter_function, primary_key.expression->getRequiredColumnsWithTypes());
|
||||||
auto actions = ExpressionAnalyzer(filter_function, syntax_result, context).getActionsDAG(false);
|
auto actions = ExpressionAnalyzer(filter_function, syntax_result, context).getActionsDAG(false);
|
||||||
|
reorderColumns(*actions, pipes[i].getHeader(), filter_function->getColumnName());
|
||||||
ExpressionActionsPtr expression_actions = std::make_shared<ExpressionActions>(std::move(actions));
|
ExpressionActionsPtr expression_actions = std::make_shared<ExpressionActions>(std::move(actions));
|
||||||
auto description = fmt::format(
|
auto description = fmt::format(
|
||||||
"filter values in [{}, {})", i ? ::toString(borders[i - 1]) : "-inf", i < borders.size() ? ::toString(borders[i]) : "+inf");
|
"filter values in [{}, {})", i ? ::toString(borders[i - 1]) : "-inf", i < borders.size() ? ::toString(borders[i]) : "+inf");
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
1000000
|
@ -0,0 +1,5 @@
|
|||||||
|
drop table if exists tab2;
|
||||||
|
create table tab2 (id String, version Int64, l String, accountCode String, z Int32) engine = ReplacingMergeTree(z) PRIMARY KEY (accountCode, id) ORDER BY (accountCode, id, version, l);
|
||||||
|
insert into tab2 select toString(number), number, toString(number), toString(number), 0 from numbers(1e6);
|
||||||
|
set max_threads=2;
|
||||||
|
select count() from tab2 final;
|
Loading…
Reference in New Issue
Block a user