Skip to content

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

Open
rustyconover wants to merge 1 commit into
apache:masterfrom
rustyconover:fix/count-min-allocator
Open

rustyconover wants to merge 1 commit into
apache:masterfrom
rustyconover:fix/count-min-allocator

Conversation

@rustyconover

Copy link
Copy Markdown

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>

This branch has not been deployed

No deployments
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.

1 participant