Skip to content

fix: count_min_sketch allocated its hash seeds with std::allocator - #559

Merged
proost merged 1 commit into
apache:masterfrom
rustyconover:fix/count-min-allocator
Oct 30, 2026
Merged

proost merged 1 commit into
apache:masterfrom
rustyconover:fix/count-min-allocator

Conversation

@rustyconover

Copy link
Copy Markdown
Contributor

count_min_sketch keeps its per-row hash seeds in std::vector<uint64_t> hash_seeds, with the default allocator. So a sketch built with a custom allocator still allocates from the global heap, and so do its copies. This makes the vector use the sketch's allocator, rebound to uint64_t, and constructs it with _allocator.

Test

Added CountMin sketch test allocator: hash seeds use the sketch's allocator to count_min_allocation_test.cpp. With test_allocator, a sketch with 5 hashes and 100 buckets, and a copy of it, must allocate the counters and the hash seeds through the allocator. Without the fix it fails with 4000 == 4040: the 40 missing bytes are the 5 seeds. With it, all Count-Min tests pass.

We found this in the DuckDB DataSketches extension. There, aggregate states keep their sketches in DuckDB's per-query arena so they count toward the memory limit, and memory allocated outside the arena is never accounted for.

🤖 Generated with Claude Code

hash_seeds was a std::vector<uint64_t> with the default allocator, so every
sketch made with a custom allocator also allocated from the global heap, and
so did its copies. Rebind the sketch's allocator for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rustyconover
rustyconover force-pushed the fix/count-min-allocator branch from f0b6523 to 8fe284a Compare October 29, 2026 16:05

@proost proost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!

@proost
proost merged commit a2675fa into apache:master Oct 30, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants