Skip to content

Commit

Permalink
Merge pull request #59635 from ClickHouse/backport/23.11/59603
Browse files Browse the repository at this point in the history
Backport #59603 to 23.11: Fix crash in topK when merging empty states
  • Loading branch information
Algunenano committed Feb 6, 2024
2 parents 043a92f + 49a69d4 commit bd86804
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/AggregateFunctions/AggregateFunctionTopK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ class AggregateFunctionTopKGeneric

void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena *) const override
{
if (!this->data(rhs).value.size())
return;

auto & set = this->data(place).value;
if (set.capacity() != reserved)
set.resize(reserved);
Expand Down
3 changes: 3 additions & 0 deletions src/Common/SpaceSaving.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ class SpaceSaving
*/
void merge(const Self & rhs)
{
if (!rhs.size())
return;

UInt64 m1 = 0;
UInt64 m2 = 0;

Expand Down
1 change: 1 addition & 0 deletions tests/queries/0_stateless/02984_topk_empty_merge.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
2 changes: 2 additions & 0 deletions tests/queries/0_stateless/02984_topk_empty_merge.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- https://github.com/ClickHouse/ClickHouse/issues/59107
SELECT topK('102.4') FROM remote('127.0.0.{1,2}', view(SELECT NULL FROM system.one WHERE dummy = 1));

0 comments on commit bd86804

Please sign in to comment.