Fix memory like in groupArraySorted

This commit is contained in:
Antonio Andelic 2024-04-12 14:00:27 +02:00
parent 53cef82acd
commit ddd477afad
3 changed files with 45 additions and 0 deletions

View File

@ -53,6 +53,7 @@ enum class GroupArraySortedStrategy
sort
};
constexpr size_t group_array_sorted_sort_strategy_max_elements_threshold = 1000000;
template <typename T, GroupArraySortedStrategy strategy>
@ -209,6 +210,14 @@ struct GroupArraySortedData
result_array_data[result_array_data_insert_begin + i] = values[i];
}
}
~GroupArraySortedData()
{
for (auto & value : values)
{
value.~T();
}
}
};
template <typename T>

View File

@ -0,0 +1,36 @@
CREATE TABLE 03094_grouparrysorted_dest
(
ServiceName LowCardinality(String) CODEC(ZSTD(1)),
-- aggregates
SlowSpans AggregateFunction(groupArraySorted(100),
Tuple(NegativeDurationNs Int64, Timestamp DateTime64(9), TraceId String, SpanId String)
) CODEC(ZSTD(1))
)
ENGINE = AggregatingMergeTree()
ORDER BY (ServiceName);
CREATE TABLE 03094_grouparrysorted_src
(
ServiceName String,
Duration Int64,
Timestamp DateTime64(9),
TraceId String,
SpanId String
)
ENGINE = MergeTree()
ORDER BY ();
CREATE MATERIALIZED VIEW 03094_grouparrysorted_mv TO 03094_grouparrysorted_dest
AS SELECT
ServiceName,
groupArraySortedState(100)(
CAST(
tuple(-Duration, Timestamp, TraceId, SpanId),
'Tuple(NegativeDurationNs Int64, Timestamp DateTime64(9), TraceId String, SpanId String)'
)) as SlowSpans
FROM 03094_grouparrysorted_src
GROUP BY
ServiceName;
INSERT INTO 03094_grouparrysorted_src SELECT * FROM generateRandom() LIMIT 5000000;