Merge pull request #64999 from ClickHouse/backport/24.3/64767

Backport #64767 to 24.3: Fix crash with DISTINCT and window functions
This commit is contained in:
robot-ch-test-poll4 2024-06-07 21:31:05 +02:00 committed by GitHub
commit 137bbd221e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 2 deletions

View File

@ -173,8 +173,12 @@ namespace
if (typeid_cast<const WindowStep *>(current_step))
{
actions_chain.push_back(std::move(dag_stack));
dag_stack.clear();
/// it can be empty in case of 2 WindowSteps following one another
if (!dag_stack.empty())
{
actions_chain.push_back(std::move(dag_stack));
dag_stack.clear();
}
}
if (const auto * const expr = typeid_cast<const ExpressionStep *>(current_step); expr)

View File

@ -0,0 +1,31 @@
DROP TABLE IF EXISTS atable;
CREATE TABLE atable
(
cdu_date Int16,
loanx_id String,
rating_sp String
)
ENGINE = MergeTree
ORDER BY tuple();
-- disable parallelization after window function otherwise
-- generated pipeline contains enormous number of transformers (should be fixed separately)
SET query_plan_enable_multithreading_after_window_functions=0;
-- max_threads is randomized, and can significantly increase number of parallel transformers after window func, so set to small value explicitly
SET max_threads=3;
SELECT DISTINCT
loanx_id,
rating_sp,
cdu_date,
row_number() OVER (PARTITION BY cdu_date) AS row_number,
last_value(cdu_date) OVER (PARTITION BY loanx_id ORDER BY cdu_date ASC) AS last_cdu_date
FROM atable
GROUP BY
cdu_date,
loanx_id,
rating_sp
SETTINGS query_plan_remove_redundant_distinct = 1;
DROP TABLE atable;