mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-18 21:51:57 +00:00
Fixed using column_after_join
for handling WINDOW
expressions in ExpressionAnalyzer
, shall be aggregated_columns
.
This commit is contained in:
parent
988569bdb1
commit
9fc3addea9
@ -793,7 +793,7 @@ void ExpressionAnalyzer::makeWindowDescriptionFromAST(const Context & context_,
|
||||
with_alias->getColumnName(), 1 /* direction */,
|
||||
1 /* nulls_direction */));
|
||||
|
||||
auto actions_dag = std::make_shared<ActionsDAG>(columns_after_join);
|
||||
auto actions_dag = std::make_shared<ActionsDAG>(aggregated_columns);
|
||||
getRootActions(column_ast, false, actions_dag);
|
||||
desc.partition_by_actions.push_back(std::move(actions_dag));
|
||||
}
|
||||
@ -814,7 +814,7 @@ void ExpressionAnalyzer::makeWindowDescriptionFromAST(const Context & context_,
|
||||
order_by_element.direction,
|
||||
order_by_element.nulls_direction));
|
||||
|
||||
auto actions_dag = std::make_shared<ActionsDAG>(columns_after_join);
|
||||
auto actions_dag = std::make_shared<ActionsDAG>(aggregated_columns);
|
||||
getRootActions(column_ast, false, actions_dag);
|
||||
desc.order_by_actions.push_back(std::move(actions_dag));
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ size_t tryReuseStorageOrderingForWindowFunctions(QueryPlan::Node * parent_node,
|
||||
{
|
||||
/// Find the following sequence of steps, add InputOrderInfo and apply prefix sort description to
|
||||
/// SortingStep:
|
||||
/// WindowStep <- SortingStep <- [Expression] <- [SettingQuotaAndLimits] <- ReadFromMergeTree
|
||||
/// WindowStep <- SortingStep <- [Expression] <- ReadFromMergeTree
|
||||
|
||||
auto * window_node = parent_node;
|
||||
auto * window = typeid_cast<WindowStep *>(window_node->step.get());
|
||||
|
@ -10,3 +10,12 @@ No sorting plan
|
||||
optimize_read_in_window_order=1
|
||||
Prefix sort description: n ASC, x ASC
|
||||
Result sort description: n ASC, x ASC
|
||||
Complex ORDER BY
|
||||
optimize_read_in_window_order=0
|
||||
3 3 1
|
||||
4 5 2
|
||||
5 7 3
|
||||
optimize_read_in_window_order=1
|
||||
3 3 1
|
||||
4 5 2
|
||||
5 7 3
|
||||
|
@ -31,6 +31,15 @@ $CLICKHOUSE_CLIENT -q "explain plan actions=1, description=1 select n, sum(x) OV
|
||||
echo ' optimize_read_in_window_order=1'
|
||||
$CLICKHOUSE_CLIENT -q "explain plan actions=1, description=1 select n, sum(x) OVER (ORDER BY n, x ROWS BETWEEN 100 PRECEDING AND CURRENT ROW) from ${name}_n_x SETTINGS optimize_read_in_window_order=1" | grep -i "sort description"
|
||||
|
||||
echo 'Complex ORDER BY'
|
||||
$CLICKHOUSE_CLIENT -q "CREATE TABLE ${name}_complex (unique1 Int32, unique2 Int32, ten Int32) ENGINE=MergeTree ORDER BY tuple() SETTINGS index_granularity = 8192"
|
||||
$CLICKHOUSE_CLIENT -q "INSERT INTO ${name}_complex VALUES (1, 2, 3), (2, 3, 4), (3, 4, 5)"
|
||||
echo ' optimize_read_in_window_order=0'
|
||||
$CLICKHOUSE_CLIENT -q "SELECT ten, sum(unique1) + sum(unique2) AS res, rank() OVER (ORDER BY sum(unique1) + sum(unique2) ASC) AS rank FROM ${name}_complex GROUP BY ten ORDER BY ten ASC SETTINGS optimize_read_in_window_order=0"
|
||||
echo ' optimize_read_in_window_order=1'
|
||||
$CLICKHOUSE_CLIENT -q "SELECT ten, sum(unique1) + sum(unique2) AS res, rank() OVER (ORDER BY sum(unique1) + sum(unique2) ASC) AS rank FROM ${name}_complex GROUP BY ten ORDER BY ten ASC SETTINGS optimize_read_in_window_order=1"
|
||||
|
||||
$CLICKHOUSE_CLIENT -q "drop table ${name}"
|
||||
$CLICKHOUSE_CLIENT -q "drop table ${name}_n"
|
||||
$CLICKHOUSE_CLIENT -q "drop table ${name}_n_x"
|
||||
$CLICKHOUSE_CLIENT -q "drop table ${name}_complex"
|
||||
|
Loading…
Reference in New Issue
Block a user