Fix HLL union estimate/serialization regression from lazy KxQ rebuild - #512
Open
SavicStefan wants to merge 1 commit into
Open
Fix HLL union estimate/serialization regression from lazy KxQ rebuild#512SavicStefan wants to merge 1 commit into
SavicStefan wants to merge 1 commit into
Conversation
Since the lazy KxQ/curMin rebuild was introduced ("skip updating kxq in HLL
merge"), Hll8Array::mergeHll only sets rebuild_kxq_curmin_ and defers the
recompute. Several consumers read that deferred state without honoring the
flag, so unioning HLL sketches with different lgConfigK could:
- discard accumulated data: isEmpty() reads curMin_/numAtCurMin_, which stay at
empty-sketch defaults after a downsampling merge, so a populated gadget looks
empty and the next union update overwrites it;
- corrupt the estimate: internalCouponUpdate does incremental KxQ/HIP updates
against the stale base;
- serialize non-deterministically: copyAs() rebuilds via register replay
(convertToHll8) while estimate/bounds rebuild via the direct sum, so equivalent
merges could serialize to different bytes.
The effect was estimates collapsing to ~one input's cardinality (merge-order
dependent) and merge-order-dependent serialization; 4.0.1 had neither.
Fix, keeping the lazy-merge optimization:
- isEmpty(): a pending rebuild means the array is non-empty.
- internalCouponUpdate(): rebuild before an incremental update reads KxQ, only
when the coupon changes a register (duplicate coupons stay lazy).
- copyAs(): make every same-type result use the direct-sum rebuild so all paths
agree, keeping serialization merge-order independent.
Adds a regression test covering estimate order-independence, is_empty() after a
downsampling merge, scalar-after-merge accumulation, and merge-order-independent
serialization.
Co-authored-by: Isaac
Co-authored-by: Stefan Savić <stefan.savic@databricks.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since the lazy KxQ/curMin rebuild was introduced ("skip updating kxq in HLL merge"), Hll8Array::mergeHll only sets rebuild_kxq_curmin_ and defers the recompute. Several consumers read that deferred state without honoring the flag, so unioning HLL sketches with different lgConfigK could:
The effect was estimates collapsing to ~one input's cardinality (merge-order dependent) and merge-order-dependent serialization; 4.0.1 had neither.
Fix, keeping the lazy-merge optimization:
Adds a regression test covering estimate order-independence, is_empty() after a downsampling merge, scalar-after-merge accumulation, and merge-order-independent serialization.