v.21.7Improvement

Correct Memory Tracking in topK Aggregate Function

Correct memory tracking in aggregate function topK. This closes #25259. #25260 (alexey-milovidov).
Correct memory tracking in the aggregate function topK.

Why it matters

This feature fixes incorrect memory usage accounting in the topK aggregate function, ensuring accurate resource tracking and preventing potential memory mismanagement. It improves reliability and stability when using topK in queries.

How to use it

No special action required from users. The fix is applied internally, so using the topK aggregate function in queries will automatically benefit from correct memory tracking.