Repository navigation
feat(asap-physical-operators): KMV distinct-count kernel (#697) - #704
Merged
Merged
Conversation
zzylol
force-pushed
the
feat/kmv-kernel-697
branch
from
October 15, 2026 04:30
d48f391 to
7fe09f4
Compare
Wrap asap_sketchlib's KMV (enabling its experimental feature at the pinned rev): build over sample values hashed with CANONICAL_HASH_SEED, merge keeping the k smallest distinct hashes, and the distinct-count estimate. Register it with the summary-kernel and native-family capability checks, the sketch evaluation check, stored-state validation and the accumulator factory, the same way as HLL.
…ple 2 Q1 Raw-sample precompute now checks KMV against its kernel, and Stage 3 over Example 2's KMV candidates selects a plan whose Q1 executes and returns the exact distinct count below k.
zzylol
force-pushed
the
feat/kmv-kernel-697
branch
from
October 15, 2026 05:30
7fe09f4 to
a723dd8
Compare
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.
Closes #697.
Why
Pass 1 offers KMV as a distinct-count candidate and Stage 3 prices it, but
asap-physical-operatorshad no KMV kernel, so a Stage 3-selected plan that uses KMV could not execute. #694 plans to make KMV the certified distinct-count summary at realistic scale, so the executor needs it.What
KmvAccumulatorsummary kernel (summary_kernels/kmv.rs) that wrapsasap_sketchlib::KMV(no local copy): build over sample values, merge, and theCardinalityestimate.k >= 2), native-family validation, sketch-evaluation validation, stored-state validation, and the accumulator factory.asap_sketchlibis now built with itsexperimentalfeature (KMV is gated behind it) at the existing pine6b0314.How
Each sample value is hashed by its bits (
-0.0folded into0.0, NaN skipped), the same convention as the HLL kernel, through the library's sharedCANONICAL_HASH_SEED.KMV::mergekeeps theksmallest distinct hashes of both states, so a merged state equals the union build. A merge across differentkis rejected. The kernel answersCardinalityand a barePointCount(both read the distinct count); other statistics return an error.Key code interfaces added / modified
crates/asap-physical-operators/src/summary_kernels/kmv.rs(new),mod.rscrates/asap-physical-operators/src/capability.rs,summary_kernels/factory.rs,values.rscrates/asap-physical-operators/Cargo.tomlUsage, end to end (Example 2's Q1 through its PromQL stand-in; the numbers come from
stage3_plan_selection_selected_kmv_plan_executes_end_to_end, run at2357ecec):Before this PR
A plan with a KMV summary failed when it was bound to a kernel.
After this PR
A Stage 3-selected KMV plan for Example 2 Q1 executes end to end and returns the exact distinct count when the input has fewer than
kdistinct values. Raw-sample precompute checks KMV against its kernel.Verification
cargo nextest run -p asap-physical-operators: 200 passed, 3 skipped. New kernel tests: fewer-than-kdistinct items are counted exactly; many distinct items are estimated within the KMV error; merge equals the union build; different-kmerges and quantile queries are rejected;-0.0equals0.0and NaN is not an item.cargo nextest run -p asap-integration-tests: 245 passed, 33 skipped (already#[ignore]d on main). New:stage3_plan_selection_selected_kmv_plan_executes_end_to_end.cargo clippy --workspace --all-targets --all-features --locked -- -D warningsandcargo fmt --all -- --check: clean.Limitations and follow-ups
fix(asap-physical-operators): seed each CountSketch row independently #706 (merged after this PR) bumps the
asap_sketchlibpin incrates/asap-physical-operators/Cargo.tomlto9415c5band keepsfeatures = ["experimental"].The end-to-end test covers the exact regime (fewer than
kdistinct values). The certified-bound regime at realistic scale is Certify distinct counts at realistic scale: size HLL from (ε, δ) and give KMV a provable guarantee #694.