Skip to content

Commit

Permalink
reduce memory usage for some window functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lgbo-ustc committed Jun 25, 2024
1 parent cf04f0f commit 8164f92
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions cpp-ch/local-engine/Parser/WindowRelParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,25 @@ DB::WindowFrame WindowRelParser::parseWindowFrame(const WindowInfo & win_info)
const auto & signature_function_name = win_info.signature_function_name;
const auto & window_function = win_info.measure->measure();
win_frame.type = parseWindowFrameType(signature_function_name, window_function);
parseBoundType(window_function.lower_bound(), true, win_frame.begin_type, win_frame.begin_offset, win_frame.begin_preceding);
parseBoundType(window_function.upper_bound(), false, win_frame.end_type, win_frame.end_offset, win_frame.end_preceding);

/// row_number is not related to window frame bound settings.
/// This is a tricky way, but OOM has happened to many times in practice .
/// Let's wait for a new fix in `CH` and remove this later. https://github.com/ClickHouse/ClickHouse/issues/65642
if (signature_function_name == "row_number")
{
win_frame.begin_type = DB::WindowFrame::BoundaryType::Offset;
win_frame.begin_offset = 1;
win_frame.begin_preceding = true;

win_frame.end_type = DB::WindowFrame::BoundaryType::Current;
win_frame.end_offset = 0;
win_frame.end_preceding = false;
}
else
{
parseBoundType(window_function.lower_bound(), true, win_frame.begin_type, win_frame.begin_offset, win_frame.begin_preceding);
parseBoundType(window_function.upper_bound(), false, win_frame.end_type, win_frame.end_offset, win_frame.end_preceding);
}

// special cases
if (signature_function_name == "lead" || signature_function_name == "lag")
Expand Down

0 comments on commit 8164f92

Please sign in to comment.