Optimized processing of ORDER BY in window functions#34632
Optimized processing of ORDER BY in window functions#34632novikd merged 18 commits intoClickHouse:masterfrom
Conversation
6013df4 to
154e61e
Compare
src/Processors/QueryPlan/Optimizations/reuseStorageOrdering.cpp
Outdated
Show resolved
Hide resolved
src/Processors/QueryPlan/Optimizations/reuseStorageOrdering.cpp
Outdated
Show resolved
Hide resolved
|
Please resolve conflicts. |
28be3af to
99fbfde
Compare
0c1da3d to
9effb26
Compare
novikd
left a comment
There was a problem hiding this comment.
Looks good. Please, add a test with over (partition by ... order by ...).
| } | ||
|
|
||
| void makeWindowDescriptionFromAST(const Context & context, | ||
| void ExpressionAnalyzer::makeWindowDescriptionFromAST(const Context & context_, |
There was a problem hiding this comment.
You can remove the first parameter because it's a member function now.
There was a problem hiding this comment.
It is still static member and we can't easily make that because basically lots of code for that class is made through static functions in corresponding cpp file. And same in two other cases in InterpreterSelectQuery.cpp.
| } | ||
|
|
||
| static SortDescription getSortDescription(const ASTSelectQuery & query, ContextPtr context) | ||
| SortDescription InterpreterSelectQuery::getSortDescription(const ASTSelectQuery & query, ContextPtr context_) |
There was a problem hiding this comment.
Here you can remove the second parameter.
src/Processors/QueryPlan/Optimizations/reuseStorageOrderingForWindowFunctions.cpp
Outdated
Show resolved
Hide resolved
src/Processors/QueryPlan/Optimizations/reuseStorageOrderingForWindowFunctions.cpp
Outdated
Show resolved
Hide resolved
|
High memory usage for UNBOUNDED PRECEDING + UNBOUNDED FOLLOWING looks expected: we can not start steaming out any row before the last row in the window will be read. So we need to store all the seen rows + all the whole window. But in practice, we sometimes see almost 3.5x memory usage. select number, lagInFrame(number) OVER (ORDER BY number ASC ROWS
BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS prev from test format Null;
-- Peak memory usage (for query): 11.81 GiB. -- while the data size is 3.2 GbThat additional memory increase looks related to the block sizes (and their size prediction?) set max_block_size = 256;
-- Peak memory usage (for query): 11.95 GiB.
SET max_block_size = 8192;
-- Peak memory usage (for query): 11.93 GiB.
set max_block_size = 65505; -- default
-- Peak memory usage (for query): 11.81 GiB.
SET max_block_size = 80000
-- Peak memory usage (for query): 9.58 GiB.
SET max_block_size = 90000
-- Peak memory usage (for query): 8.70 GiB.
SET max_block_size = 100000;
-- Peak memory usage (for query): 7.49 GiB.
SET max_block_size = 130000
-- Peak memory usage (for query): 6.50 GiB.
SET max_block_size = 524288
-- Peak memory usage (for query): 6.51 GiB. |
novikd
left a comment
There was a problem hiding this comment.
LGTM, but needs to fix flaky check:
Stateless tests flaky check (address, actions) — Timeout, fail: 77, passed: 0
5a16111 to
e218a9b
Compare
tests/queries/0_stateless/01655_plan_optimizations_optimize_read_in_window_order_long.sh
Outdated
Show resolved
Hide resolved
e218a9b to
9f17929
Compare
|
|
@Mergifyio update |
❌ Pull request can't be updated with latest base branch changesDetailsMergify needs the author permission to update the base branch of the pull request. |
9f17929 to
ca69c57
Compare
|
Rebased. |
ad5462b to
ea156fe
Compare
Unrelated
Created an issue #38247 |
Window functions and GCP fixes ClickHouse#36944, ClickHouse#34632, ClickHouse#37659 and ClickHouse#37882
Window functions and GCP fixes ClickHouse#36944, ClickHouse#34632, ClickHouse#37659 and ClickHouse#37882
Window functions and GCP fixes ClickHouse#36944, ClickHouse#34632, ClickHouse#37659 and ClickHouse#37882
…4632, ClickHouse#37659 and ClickHouse#37882 Merge pull request ClickHouse#36944 from excitoon-favorites/better_exp_smooth Merge pull request ClickHouse#34632 from excitoon-favorites/optimizedprocessing Merge pull request ClickHouse#37659 from frew/master Support `batch_delete` capability for GCS Merge pull request ClickHouse#37882 from excitoon-favorites/nodeleteobjects Fixes for objects removal in `S3ObjectStorage`
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Optimized processing of ORDER BY in window functions.
Closes: #19289