Skip to content

Commit 144e1dc

Browse files
Backport #62597 to 24.3: Fix memory leak in groupArraySorted
1 parent 027e883 commit 144e1dc

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/AggregateFunctions/AggregateFunctionGroupArraySorted.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ enum class GroupArraySortedStrategy
5353
sort
5454
};
5555

56+
5657
constexpr size_t group_array_sorted_sort_strategy_max_elements_threshold = 1000000;
5758

5859
template <typename T, GroupArraySortedStrategy strategy>
@@ -209,6 +210,14 @@ struct GroupArraySortedData
209210
result_array_data[result_array_data_insert_begin + i] = values[i];
210211
}
211212
}
213+
214+
~GroupArraySortedData()
215+
{
216+
for (auto & value : values)
217+
{
218+
value.~T();
219+
}
220+
}
212221
};
213222

214223
template <typename T>

tests/queries/0_stateless/03094_grouparraysorted_memory.reference

Whitespace-only changes.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
CREATE TABLE 03094_grouparrysorted_dest
2+
(
3+
ServiceName LowCardinality(String) CODEC(ZSTD(1)),
4+
-- aggregates
5+
SlowSpans AggregateFunction(groupArraySorted(100),
6+
Tuple(NegativeDurationNs Int64, Timestamp DateTime64(9), TraceId String, SpanId String)
7+
) CODEC(ZSTD(1))
8+
)
9+
ENGINE = AggregatingMergeTree()
10+
ORDER BY (ServiceName);
11+
12+
CREATE TABLE 03094_grouparrysorted_src
13+
(
14+
ServiceName String,
15+
Duration Int64,
16+
Timestamp DateTime64(9),
17+
TraceId String,
18+
SpanId String
19+
)
20+
ENGINE = MergeTree()
21+
ORDER BY ();
22+
23+
CREATE MATERIALIZED VIEW 03094_grouparrysorted_mv TO 03094_grouparrysorted_dest
24+
AS SELECT
25+
ServiceName,
26+
groupArraySortedState(100)(
27+
CAST(
28+
tuple(-Duration, Timestamp, TraceId, SpanId),
29+
'Tuple(NegativeDurationNs Int64, Timestamp DateTime64(9), TraceId String, SpanId String)'
30+
)) as SlowSpans
31+
FROM 03094_grouparrysorted_src
32+
GROUP BY
33+
ServiceName;
34+
35+
36+
INSERT INTO 03094_grouparrysorted_src SELECT * FROM generateRandom() LIMIT 5000000;

0 commit comments

Comments
 (0)