diff --git a/crates/accuracy/measured/hll_distinct.json b/crates/accuracy/measured/hll_distinct.json new file mode 100644 index 000000000..442f2ce37 --- /dev/null +++ b/crates/accuracy/measured/hll_distinct.json @@ -0,0 +1,228 @@ +{ + "entries": [ + { + "sketch": { + "Hll": { + "precision": 12 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 1000, + "error_at": [ + { + "failure_probability": 0.005, + "error": 0.06353677621283255 + }, + { + "failure_probability": 0.01, + "error": 0.059894486397020795 + }, + { + "failure_probability": 0.02, + "error": 0.05560114895363152 + }, + { + "failure_probability": 0.05, + "error": 0.05066911839820206 + }, + { + "failure_probability": 0.1, + "error": 0.04486266531027467 + } + ] + }, + { + "sketch": { + "Hll": { + "precision": 13 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 1000, + "error_at": [ + { + "failure_probability": 0.005, + "error": 0.0508283325639842 + }, + { + "failure_probability": 0.01, + "error": 0.0491853516522805 + }, + { + "failure_probability": 0.02, + "error": 0.04644684191865471 + }, + { + "failure_probability": 0.05, + "error": 0.042597376285265665 + }, + { + "failure_probability": 0.1, + "error": 0.03884921237907106 + } + ] + }, + { + "sketch": { + "Hll": { + "precision": 14 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 1000, + "error_at": [ + { + "failure_probability": 0.005, + "error": 0.04369184964644585 + }, + { + "failure_probability": 0.01, + "error": 0.042164691521285796 + }, + { + "failure_probability": 0.02, + "error": 0.039939217424338355 + }, + { + "failure_probability": 0.05, + "error": 0.037478877146964615 + }, + { + "failure_probability": 0.1, + "error": 0.035335065197104595 + } + ] + }, + { + "sketch": { + "Hll": { + "precision": 15 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 1000, + "error_at": [ + { + "failure_probability": 0.005, + "error": 0.03895100733180534 + }, + { + "failure_probability": 0.01, + "error": 0.0384065036532398 + }, + { + "failure_probability": 0.02, + "error": 0.03758341669726862 + }, + { + "failure_probability": 0.05, + "error": 0.03423750614761851 + }, + { + "failure_probability": 0.1, + "error": 0.03272800341596966 + } + ] + }, + { + "sketch": { + "Hll": { + "precision": 16 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 1000, + "error_at": [ + { + "failure_probability": 0.005, + "error": 0.035599664558598205 + }, + { + "failure_probability": 0.01, + "error": 0.03449450750525273 + }, + { + "failure_probability": 0.02, + "error": 0.03344325554707844 + }, + { + "failure_probability": 0.05, + "error": 0.03192424584934569 + }, + { + "failure_probability": 0.1, + "error": 0.030906990179087233 + } + ] + }, + { + "sketch": { + "Hll": { + "precision": 17 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 1000, + "error_at": [ + { + "failure_probability": 0.005, + "error": 0.033077548755651116 + }, + { + "failure_probability": 0.01, + "error": 0.03206229101583963 + }, + { + "failure_probability": 0.02, + "error": 0.03170750851634982 + }, + { + "failure_probability": 0.05, + "error": 0.030844099778653395 + }, + { + "failure_probability": 0.1, + "error": 0.030078020753206387 + } + ] + }, + { + "sketch": { + "Hll": { + "precision": 18 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 1000, + "error_at": [ + { + "failure_probability": 0.005, + "error": 0.03103404970094661 + }, + { + "failure_probability": 0.01, + "error": 0.030646300686017487 + }, + { + "failure_probability": 0.02, + "error": 0.030256981837019827 + }, + { + "failure_probability": 0.05, + "error": 0.029729517589990737 + }, + { + "failure_probability": 0.1, + "error": 0.029115712469192007 + } + ] + } + ] +} diff --git a/crates/accuracy/measured/univmon.json b/crates/accuracy/measured/univmon.json new file mode 100644 index 000000000..623a95b49 --- /dev/null +++ b/crates/accuracy/measured/univmon.json @@ -0,0 +1,868 @@ +{ + "entries": [ + { + "sketch": { + "UnivMon": { + "heap_size": 1, + "sketch_rows": 5, + "sketch_cols": 624, + "layers": 1 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.99999 + }, + { + "failure_probability": 0.05, + "error": 0.99999 + }, + { + "failure_probability": 0.1, + "error": 0.99999 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 1, + "sketch_rows": 5, + "sketch_cols": 624, + "layers": 1 + } + }, + "statistic": "FrequencyEntropy", + "accuracy_metric": "absolute", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 5.211860080675258 + }, + { + "failure_probability": 0.05, + "error": 5.210329064060954 + }, + { + "failure_probability": 0.1, + "error": 5.208294412742729 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 1, + "sketch_rows": 5, + "sketch_cols": 2367, + "layers": 1 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.99999 + }, + { + "failure_probability": 0.05, + "error": 0.99999 + }, + { + "failure_probability": 0.1, + "error": 0.99999 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 1, + "sketch_rows": 5, + "sketch_cols": 2367, + "layers": 1 + } + }, + "statistic": "FrequencyEntropy", + "accuracy_metric": "absolute", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 5.21114899162583 + }, + { + "failure_probability": 0.05, + "error": 5.209282924635904 + }, + { + "failure_probability": 0.1, + "error": 5.207427073441291 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 1, + "sketch_rows": 5, + "sketch_cols": 14349, + "layers": 1 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.99999 + }, + { + "failure_probability": 0.05, + "error": 0.99999 + }, + { + "failure_probability": 0.1, + "error": 0.99999 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 1, + "sketch_rows": 5, + "sketch_cols": 14349, + "layers": 1 + } + }, + "statistic": "FrequencyEntropy", + "accuracy_metric": "absolute", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 5.211190821114194 + }, + { + "failure_probability": 0.05, + "error": 5.209324771288973 + }, + { + "failure_probability": 0.1, + "error": 5.2074211463442595 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 1, + "sketch_rows": 5, + "sketch_cols": 56817, + "layers": 1 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.99999 + }, + { + "failure_probability": 0.05, + "error": 0.99999 + }, + { + "failure_probability": 0.1, + "error": 0.99999 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 1, + "sketch_rows": 5, + "sketch_cols": 56817, + "layers": 1 + } + }, + "statistic": "FrequencyEntropy", + "accuracy_metric": "absolute", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 5.21114899162583 + }, + { + "failure_probability": 0.05, + "error": 5.209408464326142 + }, + { + "failure_probability": 0.1, + "error": 5.207427073441291 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 1, + "sketch_rows": 5, + "sketch_cols": 226130, + "layers": 1 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.99999 + }, + { + "failure_probability": 0.05, + "error": 0.99999 + }, + { + "failure_probability": 0.1, + "error": 0.99999 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 1, + "sketch_rows": 5, + "sketch_cols": 226130, + "layers": 1 + } + }, + "statistic": "FrequencyEntropy", + "accuracy_metric": "absolute", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 5.21114899162583 + }, + { + "failure_probability": 0.05, + "error": 5.209408464326142 + }, + { + "failure_probability": 0.1, + "error": 5.207427073441291 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 1, + "sketch_rows": 5, + "sketch_cols": 1409067, + "layers": 1 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.99999 + }, + { + "failure_probability": 0.05, + "error": 0.99999 + }, + { + "failure_probability": 0.1, + "error": 0.99999 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 1, + "sketch_rows": 5, + "sketch_cols": 1409067, + "layers": 1 + } + }, + "statistic": "FrequencyEntropy", + "accuracy_metric": "absolute", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 5.21114899162583 + }, + { + "failure_probability": 0.05, + "error": 5.209408464326142 + }, + { + "failure_probability": 0.1, + "error": 5.207427073441291 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 256, + "sketch_rows": 5, + "sketch_cols": 1024, + "layers": 16 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.14669695248911604 + }, + { + "failure_probability": 0.05, + "error": 0.13458262350936967 + }, + { + "failure_probability": 0.1, + "error": 0.12953498643447536 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 256, + "sketch_rows": 5, + "sketch_cols": 1024, + "layers": 16 + } + }, + "statistic": "FrequencyEntropy", + "accuracy_metric": "absolute", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.34126409732855834 + }, + { + "failure_probability": 0.05, + "error": 0.282783387956588 + }, + { + "failure_probability": 0.1, + "error": 0.24568541649654563 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 13500, + "sketch_rows": 1, + "sketch_cols": 1, + "layers": 19 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.0100481805502726 + }, + { + "failure_probability": 0.05, + "error": 0.008515234482931852 + }, + { + "failure_probability": 0.1, + "error": 0.007209062821833162 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 13500, + "sketch_rows": 1, + "sketch_cols": 1, + "layers": 19 + } + }, + "statistic": "FrequencyEntropy", + "accuracy_metric": "absolute", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 327.7268158812719 + }, + { + "failure_probability": 0.05, + "error": 306.2933393600696 + }, + { + "failure_probability": 0.1, + "error": 298.16916055011677 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 13500, + "sketch_rows": 5, + "sketch_cols": 624, + "layers": 19 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.00954 + }, + { + "failure_probability": 0.05, + "error": 0.00872 + }, + { + "failure_probability": 0.1, + "error": 0.00784 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 13500, + "sketch_rows": 5, + "sketch_cols": 624, + "layers": 19 + } + }, + "statistic": "FrequencyEntropy", + "accuracy_metric": "absolute", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.5040131925856706 + }, + { + "failure_probability": 0.05, + "error": 0.45276958723168015 + }, + { + "failure_probability": 0.1, + "error": 0.39600955984142416 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 13500, + "sketch_rows": 5, + "sketch_cols": 2367, + "layers": 19 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.013086835296777273 + }, + { + "failure_probability": 0.05, + "error": 0.01207683529859262 + }, + { + "failure_probability": 0.1, + "error": 0.011127577805129235 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 13500, + "sketch_rows": 5, + "sketch_cols": 2367, + "layers": 19 + } + }, + "statistic": "FrequencyEntropy", + "accuracy_metric": "absolute", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.25205218012683517 + }, + { + "failure_probability": 0.05, + "error": 0.22671596478998168 + }, + { + "failure_probability": 0.1, + "error": 0.20878732737861938 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 13500, + "sketch_rows": 5, + "sketch_cols": 14349, + "layers": 19 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.012082087865162894 + }, + { + "failure_probability": 0.05, + "error": 0.010775916204064203 + }, + { + "failure_probability": 0.1, + "error": 0.009218557685061917 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 13500, + "sketch_rows": 5, + "sketch_cols": 14349, + "layers": 19 + } + }, + "statistic": "FrequencyEntropy", + "accuracy_metric": "absolute", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.05392991711015327 + }, + { + "failure_probability": 0.05, + "error": 0.046377241801550895 + }, + { + "failure_probability": 0.1, + "error": 0.03975658960483841 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 13500, + "sketch_rows": 5, + "sketch_cols": 56817, + "layers": 19 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.011379485228857613 + }, + { + "failure_probability": 0.05, + "error": 0.010491948776467605 + }, + { + "failure_probability": 0.1, + "error": 0.009192341828325092 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 13500, + "sketch_rows": 5, + "sketch_cols": 56817, + "layers": 19 + } + }, + "statistic": "FrequencyEntropy", + "accuracy_metric": "absolute", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.024807271786290386 + }, + { + "failure_probability": 0.05, + "error": 0.02021158356163255 + }, + { + "failure_probability": 0.1, + "error": 0.016123003463512475 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 54000, + "sketch_rows": 1, + "sketch_cols": 1, + "layers": 19 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.00386 + }, + { + "failure_probability": 0.05, + "error": 0.00364 + }, + { + "failure_probability": 0.1, + "error": 0.00354 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 54000, + "sketch_rows": 1, + "sketch_cols": 1, + "layers": 19 + } + }, + "statistic": "FrequencyEntropy", + "accuracy_metric": "absolute", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 267.24067839715207 + }, + { + "failure_probability": 0.05, + "error": 260.6847771089489 + }, + { + "failure_probability": 0.1, + "error": 251.2735117785696 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 54000, + "sketch_rows": 5, + "sketch_cols": 624, + "layers": 19 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.002694307087612527 + }, + { + "failure_probability": 0.05, + "error": 0.00232 + }, + { + "failure_probability": 0.1, + "error": 0.00194 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 54000, + "sketch_rows": 5, + "sketch_cols": 624, + "layers": 19 + } + }, + "statistic": "FrequencyEntropy", + "accuracy_metric": "absolute", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.5509297281280077 + }, + { + "failure_probability": 0.05, + "error": 0.511945718220506 + }, + { + "failure_probability": 0.1, + "error": 0.4826424715624924 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 54000, + "sketch_rows": 5, + "sketch_cols": 2367, + "layers": 19 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.00668 + }, + { + "failure_probability": 0.05, + "error": 0.00628 + }, + { + "failure_probability": 0.1, + "error": 0.00588 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 54000, + "sketch_rows": 5, + "sketch_cols": 2367, + "layers": 19 + } + }, + "statistic": "FrequencyEntropy", + "accuracy_metric": "absolute", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.26124628298491714 + }, + { + "failure_probability": 0.05, + "error": 0.2314158613498627 + }, + { + "failure_probability": 0.1, + "error": 0.20903519899370693 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 54000, + "sketch_rows": 5, + "sketch_cols": 14349, + "layers": 19 + } + }, + "statistic": "Cardinality", + "accuracy_metric": "relative", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.00554 + }, + { + "failure_probability": 0.05, + "error": 0.0051 + }, + { + "failure_probability": 0.1, + "error": 0.00484 + } + ] + }, + { + "sketch": { + "UnivMon": { + "heap_size": 54000, + "sketch_rows": 5, + "sketch_cols": 14349, + "layers": 19 + } + }, + "statistic": "FrequencyEntropy", + "accuracy_metric": "absolute", + "trials": 200, + "error_at": [ + { + "failure_probability": 0.02, + "error": 0.04927633564544465 + }, + { + "failure_probability": 0.05, + "error": 0.03933266493779186 + }, + { + "failure_probability": 0.1, + "error": 0.03307348088133466 + } + ] + } + ] +} diff --git a/crates/accuracy/proptest-regressions/properties.txt b/crates/accuracy/proptest-regressions/properties.txt index b4b81d868..341ba3ff3 100644 --- a/crates/accuracy/proptest-regressions/properties.txt +++ b/crates/accuracy/proptest-regressions/properties.txt @@ -4,4 +4,3 @@ # # It is recommended to check this file in to source control so that # everyone who runs the test benefits from these saved cases. -cc 3e6f0fa350db7ece01d8cb1bcad6268a7e13c59f4858e6b6d927b7f590ee1047 # shrinks to (algorithm, parameters) = (HLL, Hll { precision: 4 }), failure_probability = 1.0, slack = 0.5, looser = 1.0, factor = 1 diff --git a/crates/accuracy/src/guarantee/hll/tests.rs b/crates/accuracy/src/guarantee/hll/tests.rs index 3d4c18301..6f60bd8a4 100644 --- a/crates/accuracy/src/guarantee/hll/tests.rs +++ b/crates/accuracy/src/guarantee/hll/tests.rs @@ -94,170 +94,3 @@ fn a_distinct_count_is_certified_over_the_source_s_distinct_bound() { assert_eq!(guarantee.spec.failure_probability.evaluate(), None); } } - -// --------------------------------------------------------------------------- -// The certified sparse-exact HLL (level linear counting, no distinct bound -// needed). Expected values come from the independent oracle in asap_sketchlib, -// `tests/oracles/hll_level_certificate.py` (formula only, not this crate). -// --------------------------------------------------------------------------- - -use asap_types::summary_type::SketchAlgorithm; - -/// The planner's guarantee for `count(DISTINCT x)` from HLL at `precision`. -fn distinct_guarantee( - precision: u8, - failure_probability: f64, - max_distinct: Option, -) -> Option { - super::super::theoretical_guarantee( - &FieldDataType::Sketch(SketchAlgorithm::HLL), - &SketchParams::Hll { precision }, - &SketchStatistic::Cardinality, - failure_probability, - Some(ValueSign::NonNegative), - max_distinct, - ) -} - -fn error_and_delta(guarantee: &AccuracyGuarantee) -> (f64, f64) { - ( - guarantee.spec.error.evaluate().unwrap(), - guarantee.spec.failure_probability.evaluate().unwrap(), - ) -} - -/// The oracle's least certified relative error at p 17, δ 5e-6 (the drill's -/// per-host δ, 0.05 / 10,000 hosts), with no distinct bound. -const ORACLE_EPS_P17_DELTA_5E_6: f64 = 0.04095602588013592; - -/// H5: p 17 at δ 5e-6 is certified with no declared distinct bound: relative -/// ε* = 0.04096 (oracle), constant δ* ≤ 5e-6. Today: the relative standard -/// error with an unknown failure probability, so no guarantee. -#[test] -fn hll_certified_without_distinct_bound() { - let guarantee = distinct_guarantee(17, 5e-6, None).expect("p 17 is certified at δ 5e-6"); - assert_eq!(guarantee.spec.accuracy_metric, AccuracyMetric::Relative); - let (error, delta) = error_and_delta(&guarantee); - assert!(error <= 0.05, "{error}"); - assert!((error - ORACLE_EPS_P17_DELTA_5E_6).abs() <= 1e-6, "{error}"); - assert!(delta <= 5e-6, "{delta}"); -} - -/// H4: the E6 bound (100,000 distinct per evaluation) certifies the same or a -/// smaller error. Today: the bound is outside the classic contract, no -/// guarantee. -#[test] -fn hll_certified_at_e6_bound() { - let bounded = distinct_guarantee(17, 5e-6, Some(100_000)).expect("certified"); - let (error, delta) = error_and_delta(&bounded); - assert!(error <= ORACLE_EPS_P17_DELTA_5E_6 + 1e-6, "{error}"); - assert!(delta <= 5e-6, "{delta}"); -} - -/// H2, H4: a declared bound of at most T = m/8 (16,384 at p 17) keeps every -/// state sparse, so the estimate is exact up to 64-bit hash collisions: ε* is -/// the bisection floor 1e-6 at δ 0.01. Today: the classic collision bound. -#[test] -fn declared_bound_at_most_threshold_is_exact() { - let exact = distinct_guarantee(17, 0.01, Some(16_384)).expect("certified"); - let (error, delta) = error_and_delta(&exact); - assert!(error <= 1e-6 + 1e-12, "{error}"); - assert!(delta <= 1e-9, "{delta}"); -} - -/// H5: the least listed precision certified for each (ε, δ), from the oracle: -/// (0.05, 5e-6) → 17, (0.05, 5e-7) → 17, (0.1, 5e-6) → 15, (0.05, 0.01) → 16. -#[test] -fn least_certified_precision_per_target() { - let least = |max_error: f64, failure_probability: f64| { - asap_types::summary_type::parameter_list(SketchAlgorithm::HLL) - .iter() - .filter_map(|parameters| match parameters { - SketchParams::Hll { precision } => Some(*precision), - _ => None, - }) - .find(|&precision| { - distinct_guarantee(precision, failure_probability, None) - .is_some_and(|guarantee| error_and_delta(&guarantee).0 <= max_error) - }) - }; - for (max_error, failure_probability, expected) in [ - (0.05, 5e-6, 17), - (0.05, 5e-7, 17), - (0.1, 5e-6, 15), - (0.05, 0.01, 16), - ] { - assert_eq!( - least(max_error, failure_probability), - Some(expected), - "ε {max_error}, δ {failure_probability}" - ); - } -} - -/// H4: the certificate is non-increasing in the precision and in ε, and so -/// the certified ε* at δ 0.01 is non-increasing in the precision (each -/// precision 12..=18 is certified at δ 0.01). -#[test] -fn certificate_is_monotone() { - use asap_sketchlib::sketches::hll::certified_failure_probability; - let epsilons = [0.02, 0.05, 0.1, 0.2]; - for precision in 12..=18u32 { - for pair in epsilons.windows(2) { - let (tight, loose) = ( - certified_failure_probability(precision, pair[0], None), - certified_failure_probability(precision, pair[1], None), - ); - assert!( - loose <= tight, - "p {precision}: ε {pair:?} gives {tight}, {loose}" - ); - } - if precision < 18 { - for eps in epsilons { - assert!( - certified_failure_probability(precision + 1, eps, None) - <= certified_failure_probability(precision, eps, None), - "ε {eps}: p {precision} → {}", - precision + 1 - ); - } - } - } - let errors: Vec = (12..=18u8) - .map(|precision| { - let guarantee = distinct_guarantee(precision, 0.01, None) - .unwrap_or_else(|| panic!("p {precision} certified at δ 0.01")); - error_and_delta(&guarantee).0 - }) - .collect(); - assert!( - errors.windows(2).all(|pair| pair[1] <= pair[0]), - "{errors:?}" - ); -} - -/// H5: ε 0.005 at δ 1e-6 is beyond p 18 (oracle: ε* = 0.0307 at δ 1e-6; -/// failure probability 1 at ε 0.005), so no HLL meets it. Holds today too -/// (no guarantee at all); fails for a bound that ignores level selection. -#[test] -fn tiny_target_is_not_certified() { - let meets = distinct_guarantee(18, 1e-6, None) - .is_some_and(|guarantee| error_and_delta(&guarantee).0 <= 0.005); - assert!(!meets); -} - -/// H5: every listed HLL precision has a certified guarantee at δ 0.01 with -/// no distinct bound. Today: none has (unknown failure probability). -#[test] -fn every_listed_precision_is_certified_at_one_percent() { - for parameters in asap_types::summary_type::parameter_list(SketchAlgorithm::HLL) { - let SketchParams::Hll { precision } = parameters else { - panic!("{parameters:?}"); - }; - assert!( - distinct_guarantee(*precision, 0.01, None).is_some(), - "p {precision}" - ); - } -} diff --git a/crates/accuracy/src/measured.rs b/crates/accuracy/src/measured.rs index a9ce648e2..2228d681e 100644 --- a/crates/accuracy/src/measured.rs +++ b/crates/accuracy/src/measured.rs @@ -89,6 +89,16 @@ pub enum MeasuredSketchAccuracyError { } impl MeasuredSketchAccuracy { + /// The table in `json` (the serde form of this type, e.g. a + /// calibration's output file), validated ([`Self::validate`]): the + /// loader to call before handing a table to the planner. The error + /// names what failed to parse or which check an entry fails. + pub fn from_json(json: &str) -> Result { + let table: Self = serde_json::from_str(json).map_err(|e| e.to_string())?; + table.validate().map_err(|e| format!("{e:?}"))?; + Ok(table) + } + /// Check every entry: a DDSketch α in (0, 1), at least one point, failure probabilities in /// (0, 1] and at least 3 / trials, errors finite and non-negative, ascending failure /// probability with non-increasing error, and no two entries for one diff --git a/crates/accuracy/src/properties.rs b/crates/accuracy/src/properties.rs index 27246ec9e..1f242bedf 100644 --- a/crates/accuracy/src/properties.rs +++ b/crates/accuracy/src/properties.rs @@ -431,7 +431,10 @@ proptest! { /// fixed by its depth. #[test] fn meeting_a_readout_level_is_monotone( - (algorithm, parameters) in valid_parameters(), + (algorithm, parameters) in valid_parameters() + .prop_filter("HLL needs a declared distinct bound", |(algorithm, _)| { + *algorithm != SketchAlgorithm::HLL + }), failure_probability in probability(), slack in 0.5..2.0f64, looser in 1.0..10.0f64, diff --git a/crates/accuracy/src/readout/mod.rs b/crates/accuracy/src/readout/mod.rs index 7e599e082..377e4b830 100644 --- a/crates/accuracy/src/readout/mod.rs +++ b/crates/accuracy/src/readout/mod.rs @@ -12,9 +12,12 @@ use crate::guarantee::guarantee_before_failure_probability_check; /// The metric of the error reading `statistic` from a state of /// `summary_type` has: its first listed θ's guarantee's, whatever that /// guarantee's failure probability (HLL's distinct count reads a relative -/// error although its failure probability is unknown). `None` for an exact -/// state and for a summary type with no listed θ or no guarantee for the -/// statistic (UnivMon's distinct count). +/// error although its failure probability is unknown). A listed readout +/// with no theoretical guarantee (UnivMon's distinct count and entropy) +/// reads in its statistic's own metric ([`measured_only_metric`]), so a +/// measured entry can supply its guarantee; without one it stays +/// unguaranteed. `None` for an exact state, a summary type with no listed +/// θ, and any other statistic without a guarantee. pub(crate) fn readout_error_metric( summary_type: &FieldDataType, statistic: &SketchStatistic, @@ -23,18 +26,19 @@ pub(crate) fn readout_error_metric( return None; }; let parameters = parameter_list(*algorithm).first()?; - Some( - guarantee_before_failure_probability_check( - summary_type, - parameters, - statistic, - 1.0, - None, - None, - )? - .spec - .accuracy_metric, - ) + guarantee_before_failure_probability_check(summary_type, parameters, statistic, 1.0, None, None) + .map(|guarantee| guarantee.spec.accuracy_metric) + .or_else(|| measured_only_metric(statistic)) +} + +/// The metric a readout with no theoretical guarantee is measured in: a +/// distinct count's relative error, an entropy's absolute error (bits). +fn measured_only_metric(statistic: &SketchStatistic) -> Option { + match statistic { + SketchStatistic::Cardinality => Some(AccuracyMetric::Relative), + SketchStatistic::FrequencyEntropy => Some(AccuracyMetric::ABSOLUTE), + _ => None, + } } /// The metric of `candidate`'s error when it is a readout diff --git a/crates/accuracy/src/readout/tests.rs b/crates/accuracy/src/readout/tests.rs index ac1048bcc..86553d1ab 100644 --- a/crates/accuracy/src/readout/tests.rs +++ b/crates/accuracy/src/readout/tests.rs @@ -26,3 +26,19 @@ fn a_readouts_metric_is_its_algorithms() { None ); } + +/// UnivMon's distinct count and entropy have no theoretical guarantee but +/// read in their statistic's metric (relative, absolute bits), which a +/// measured entry is matched in. +#[test] +fn univmon_readouts_without_a_guarantee_read_their_statistics_metric() { + let univmon = FieldDataType::Sketch(SketchAlgorithm::UnivMon); + assert_eq!( + readout_error_metric(&univmon, &SketchStatistic::Cardinality), + Some(AccuracyMetric::Relative) + ); + assert_eq!( + readout_error_metric(&univmon, &SketchStatistic::FrequencyEntropy), + Some(AccuracyMetric::ABSOLUTE) + ); +} diff --git a/crates/accuracy/tests/hll_measured_accuracy.rs b/crates/accuracy/tests/hll_measured_accuracy.rs new file mode 100644 index 000000000..730683e4a --- /dev/null +++ b/crates/accuracy/tests/hll_measured_accuracy.rs @@ -0,0 +1,184 @@ +//! HLL's measured accuracy table (`measured/hll_distinct.json`): the +//! per-value relative error of the executor's HLL state at each precision +//! 12..=18, measured by ASAPBench's `study_saturation.py --phase hll-tail` +//! (the worst over distinct counts 1..=100,000 and over states merged from +//! 1, 6, 60 and 360 panes). HLL's theoretical guarantee states no failure +//! probability without a small distinct bound, so the table is what lets +//! Pass 2 keep an HLL under an accuracy target. + +use asap_accuracy::{ + theoretical_guarantee, AccuracyEvidence, MeasuredSketchAccuracy, NoMeasuredGuarantees, +}; +use asap_types::accuracy::{AccuracyGuarantee, AccuracyMetric}; +use asap_types::ir::schema::FieldDataType; +use asap_types::stages::ValueSign; +use asap_types::summary_type::{SketchAlgorithm, SketchParams, SketchStatistic}; + +const TABLE: &str = include_str!("../measured/hll_distinct.json"); + +fn table() -> MeasuredSketchAccuracy { + MeasuredSketchAccuracy::from_json(TABLE).expect("the committed table loads") +} + +fn hll() -> FieldDataType { + FieldDataType::Sketch(SketchAlgorithm::HLL) +} + +fn measured( + evidence: &dyn AccuracyEvidence, + precision: u8, + failure_probability: f64, +) -> Option { + evidence.measured_guarantee( + &hll(), + &SketchParams::Hll { precision }, + &SketchStatistic::Cardinality, + failure_probability, + ) +} + +fn error_and_delta(guarantee: &AccuracyGuarantee) -> (f64, f64) { + ( + guarantee.spec.error.evaluate().unwrap(), + guarantee.spec.failure_probability.evaluate().unwrap(), + ) +} + +/// The committed table parses and validates, and holds one entry per +/// precision 12..=18, read for the distinct count in relative error, each +/// recording δ 0.05 from at least 3 / 0.05 = 60 trials. +#[test] +fn table_loads() { + let table = table(); + let precisions: Vec = table + .entries + .iter() + .map(|entry| { + assert_eq!(entry.statistic, SketchStatistic::Cardinality); + assert_eq!(entry.accuracy_metric, AccuracyMetric::Relative); + assert!(entry.trials >= 60, "{entry:?}"); + assert!( + entry + .error_at + .iter() + .any(|point| point.failure_probability == 0.05), + "{entry:?}" + ); + match entry.sketch { + SketchParams::Hll { precision } => precision, + ref other => panic!("{other:?}"), + } + }) + .collect(); + assert_eq!(precisions, [12, 13, 14, 15, 16, 17, 18]); +} + +/// Precision 14 meets relative error 0.05 at failure probability 0.05 per +/// value: its measured guarantee at δ 0.05 is in relative error, at most +/// 0.05, at a recorded failure probability at most 0.05. +#[test] +fn p14_meets_relative_five_percent_at_delta_five_percent_per_value() { + let guarantee = measured(&table(), 14, 0.05).expect("p 14 is measured at δ 0.05"); + assert_eq!(guarantee.spec.accuracy_metric, AccuracyMetric::Relative); + let (error, delta) = error_and_delta(&guarantee); + assert!(error <= 0.05, "{error}"); + assert!(delta <= 0.05, "{delta}"); +} + +/// The measured error does not grow with the precision, at every recorded +/// failure probability: the least listed precision meeting a target is a +/// threshold, as Pass 2 assumes when it keeps the least one. +#[test] +fn measured_error_does_not_grow_with_precision() { + let table = table(); + for delta in [0.005, 0.01, 0.02, 0.05, 0.1] { + let errors: Vec = (12..=18) + .filter_map(|precision| measured(&table, precision, delta)) + .map(|guarantee| error_and_delta(&guarantee).0) + .collect(); + assert_eq!(errors.len(), 7, "δ {delta}"); + assert!( + errors.windows(2).all(|pair| pair[1] <= pair[0] * 1.05), + "δ {delta}: {errors:?}" + ); + } +} + +/// Without a table HLL has no guarantee at δ 0.05 and no distinct bound +/// (the relative standard error states no failure probability), so Pass 2 +/// prunes it under a target; with the table, the same request is answered. +#[test] +fn hll_has_no_guarantee_without_a_table() { + for precision in 12..=18 { + assert_eq!(measured(&NoMeasuredGuarantees, precision, 0.05), None); + assert_eq!( + theoretical_guarantee( + &hll(), + &SketchParams::Hll { precision }, + &SketchStatistic::Cardinality, + 0.05, + Some(ValueSign::NonNegative), + None, + ), + None, + "p {precision}" + ); + assert!( + measured(&table(), precision, 0.05).is_some(), + "p {precision}" + ); + } +} + +/// A request below the smallest recorded failure probability (the table +/// records nothing under 3 / trials) gets no measured guarantee: the +/// measurement is never extrapolated to the δ a whole-result target splits +/// over many groups (0.05 / 10,000 hosts). +#[test] +fn no_measured_guarantee_below_the_recorded_failure_probabilities() { + assert_eq!(measured(&table(), 18, 5e-6), None); +} + +/// UnivMon's committed table (`measured/univmon.json`) loads, and the +/// shape (13,500 heap, 5 x 56,817, 19 layers) reads the entropy within 0.1 +/// bits at δ 0.05 per value, while the entropy has no theoretical +/// guarantee at all. +#[test] +fn univmon_table_loads_and_gives_entropy_a_guarantee() { + let table = MeasuredSketchAccuracy::from_json(include_str!("../measured/univmon.json")) + .expect("the committed UnivMon table loads"); + let univmon = FieldDataType::Sketch(SketchAlgorithm::UnivMon); + let shape = SketchParams::UnivMon { + heap_size: 13_500, + sketch_rows: 5, + sketch_cols: 56_817, + layers: 19, + }; + let entropy = SketchStatistic::FrequencyEntropy; + assert_eq!( + theoretical_guarantee(&univmon, &shape, &entropy, 0.05, None, None), + None + ); + let guarantee = table + .measured_guarantee(&univmon, &shape, &entropy, 0.05) + .expect("measured at δ 0.05"); + assert_eq!(guarantee.spec.accuracy_metric, AccuracyMetric::ABSOLUTE); + let (error, delta) = error_and_delta(&guarantee); + assert!(error <= 0.1 && delta <= 0.05, "{error} at {delta}"); +} + +/// The table covers the switch from linear counting to the harmonic mean +/// (near 2.4 · 2^p), where the error spikes: p12's worst at δ 0.05 is above +/// 0.05 there (0.0507 at n = 9,789), so p13 is the least precision meeting +/// relative 0.05 at δ 0.05 per value. A table measured only on a +/// 10-per-decade count grid missed the spike (0.0477) and passed p12. +#[test] +fn the_switch_band_makes_p13_the_least_precision_for_five_percent() { + let table = table(); + let meets = |precision| { + measured(&table, precision, 0.05) + .is_some_and(|guarantee| error_and_delta(&guarantee).0 <= 0.05) + }; + assert!(!meets(12)); + assert!((13..=18).all(meets)); +} diff --git a/crates/accuracy/tests/measured_sketch_accuracy.rs b/crates/accuracy/tests/measured_sketch_accuracy.rs index 3bcee361c..19aaf0858 100644 --- a/crates/accuracy/tests/measured_sketch_accuracy.rs +++ b/crates/accuracy/tests/measured_sketch_accuracy.rs @@ -355,11 +355,11 @@ fn a_measured_entry_supplies_a_guarantee_where_theory_states_no_failure_probabil assert_eq!(parts(&guarantee), (0.02, 0.01, AccuracyMetric::Relative)); } -/// A readout with no metric of its own (UnivMon's distinct count has no -/// listed guarantee) never gets a measured one: there is no readout metric -/// for the entry's to match. +/// UnivMon's distinct count has no theoretical guarantee, yet it reads a +/// relative error, so a measured entry supplies its guarantee: (0.05, 0.01, +/// Relative) from an entry at δ 0.01. #[test] -fn an_entry_for_a_readout_with_no_metric_is_never_returned() { +fn a_measured_entry_supplies_univmons_distinct_count() { let univmon = FieldDataType::Sketch(SketchAlgorithm::UnivMon); let parameters = SketchParams::UnivMon { heap_size: 32, @@ -376,10 +376,10 @@ fn an_entry_for_a_readout_with_no_metric_is_never_returned() { error_at: vec![point(0.01, 0.05)], }], }; - assert_eq!( - table.measured_guarantee(&univmon, ¶meters, &SketchStatistic::Cardinality, 0.01), - None - ); + let guarantee = table + .measured_guarantee(&univmon, ¶meters, &SketchStatistic::Cardinality, 0.01) + .unwrap(); + assert_eq!(parts(&guarantee), (0.05, 0.01, AccuracyMetric::Relative)); } /// An entry for a DDSketch α outside (0, 1) is rejected: no sketch is diff --git a/crates/integration-tests/tests/hll_distinct_ingest.rs b/crates/integration-tests/tests/hll_distinct_ingest.rs index 20e604e41..ea7bcde7e 100644 --- a/crates/integration-tests/tests/hll_distinct_ingest.rs +++ b/crates/integration-tests/tests/hll_distinct_ingest.rs @@ -1,15 +1,19 @@ //! Distinct counts kept at ingestion time with HLL (test plan //! `hll-distinct-ingest`, §2.4–2.6): Pass 1 offers HLL at every precision -//! 12..=18, Pass 2 keeps the least certified one (the sparse-exact state's -//! certificate needs no distinct bound) and adds its tumbling-window chain, +//! 12..=18, Pass 2 keeps the least one whose measured per-value error meets +//! the target (the measured table `crates/accuracy/measured/hll_distinct.json`, +//! read as the deployment's evidence) and adds its tumbling-window chain, //! Stage 2 offers the chain at ingestion time, and Stage 3 keeps it where it -//! is the cheapest of exact raw, query-time HLL and the chain. +//! is the cheapest of exact raw, query-time HLL and the chain. Targets are +//! per value (`accuracy_scope: per_value`): the table records failure +//! probabilities down to 3 / trials, not the δ a whole-result target splits +//! over 10,000 hosts. //! //! The memo checks read the stages' text (`planning_stages_text`, the //! output `asap_planner --format text` prints), one memo group's block at a //! time, so each expectation reads as the plan does. use asap_cost::{plan_cost, CostInputs}; -use asap_planner::{DeploymentCapabilities, PlanningModels}; +use asap_planner::{DeploymentCapabilities, MeasuredSketchAccuracy, PlanningModels}; use asap_planner_cli::planning_stages::{ lower_promql_roots, lower_sql_roots, run_stages_until, sql_catalog, RunUntil, }; @@ -50,13 +54,27 @@ fn e6_x1_sources() -> Value { }) } +/// HLL's measured per-value accuracy at precisions 12..=18. +fn measured_hll() -> &'static MeasuredSketchAccuracy { + static TABLE: std::sync::LazyLock = std::sync::LazyLock::new(|| { + MeasuredSketchAccuracy::from_json(include_str!("../../accuracy/measured/hll_distinct.json")) + .unwrap() + }); + &TABLE +} + +/// Each value within the error at the failure probability, separately. +const PER_VALUE: &str = "per_value"; +/// The whole result within the error at the failure probability (the +/// default scope): the failure probability is split over the values. +const WHOLE_RESULT: &str = "whole_result"; + /// A workload of `queries` (text, interval in ms) in `language`, each at -/// relative error `max_error` and failure probability `delta`. +/// relative error `max_error` and failure probability `delta` over `scope`. fn workload( language: Value, queries: &[(&str, u64)], - max_error: f64, - delta: f64, + (max_error, delta, scope): (f64, f64, &str), rows_per_second: f64, sources: Value, ) -> PlanningWorkload { @@ -66,7 +84,8 @@ fn workload( "repeating_queries": queries.iter().map(|(query, interval)| json!({ "query": query, "demand": {"fixed_interval_at": {"interval": interval, "evaluation_phase": 0}}, - "requirements": {"accuracy": {"max_error": max_error, "failure_probability": delta}}, + "requirements": {"accuracy": {"max_error": max_error, "failure_probability": delta, + "accuracy_scope": scope}}, "predictability": {"predictable": {"known_at": null}}, })).collect::>(), }, @@ -84,30 +103,41 @@ fn sql() -> Value { json!({"sql": "datafusion_sql"}) } -/// W1: the drill's q1 without its ranking, every 10 s, rel 0.05 δ 0.05, E6 x1. +/// W1: the drill's q1 without its ranking, every 10 s, rel 0.05 δ 0.05 per +/// value, E6 x1. const W1: &str = "SELECT host, count(DISTINCT value) AS c FROM flows \ WHERE ts > now() - INTERVAL '1 hour' GROUP BY host"; fn w1() -> PlanningWorkload { + w1_over(PER_VALUE) +} + +fn w1_over(scope: &str) -> PlanningWorkload { workload( sql(), &[(W1, 10_000)], - 0.05, - 0.05, + (0.05, 0.05, scope), 30_000.0, e6_x1_sources(), ) } -/// The stages' text for `workload` up to `until`, raw data retained. +/// The stages' text for `workload` up to `until`, raw data retained, with +/// HLL's measured accuracy. fn stages_text(workload: &PlanningWorkload, until: RunUntil) -> String { - stages_text_with(workload, until, &DeploymentCapabilities::default()) + stages_text_with( + workload, + until, + &DeploymentCapabilities::default(), + measured_hll(), + ) } fn stages_text_with( workload: &PlanningWorkload, until: RunUntil, capabilities: &DeploymentCapabilities, + evidence: &dyn asap_accuracy::AccuracyEvidence, ) -> String { let roots = match &workload.query_workload.language { language if serde_json::to_value(language).unwrap() == json!("promql") => { @@ -117,7 +147,9 @@ fn stages_text_with( }; let entries: Vec<_> = workload.query_workload.entries().collect(); let data = workload.data_workload.clone().unwrap_or_default(); - let models = PlanningModels::builtin().with_deployment_capabilities(capabilities); + let models = PlanningModels::builtin() + .with_evidence(evidence) + .with_deployment_capabilities(capabilities); let run = run_stages_until(roots, &entries, &data, models, Default::default(), until).unwrap(); planning_stages_text(&run, None, None, false) } @@ -178,10 +210,10 @@ fn group_block<'a>(memo_section: &'a str, header: &str) -> &'a str { blocks[0] } -/// `p*` for W1 (rel 0.05, δ 0.05 / 10,000 hosts = 5e-6): the least listed -/// precision the oracle certifies (asap_sketchlib -/// `tests/oracles/hll_level_certificate.py`). -const W1_PRECISION: u8 = 17; +/// `p*` for W1 (rel 0.05, δ 0.05 per value): the least listed precision +/// whose measured error at δ 0.05 is at most 0.05 in +/// `accuracy/measured/hll_distinct.json`. +const W1_PRECISION: u8 = 13; fn hll_theta(precision: u8) -> String { format!("θ=Hll(precision={precision})") @@ -199,7 +231,7 @@ fn count_distinct_offers_hll_at_every_listed_precision() { let pass1 = section(&text, PASS1); let hll = group_block(pass1, "SummaryAgg HLL"); assert!( - hll.contains("θ: precision ∈ {12, 13, 14, 15, 16, 17, 18}") && hll.contains("7 candidates"), + hll.contains("θ: precision ∈ {12..18} (7 values)") && hll.contains("7 candidates"), "{hll}" ); let kmv = group_block(pass1, "SummaryAgg KMV"); @@ -207,11 +239,10 @@ fn count_distinct_offers_hll_at_every_listed_precision() { } /// H5: in W1's `SummaryAgg HLL` group Pass 2 keeps exactly one Pass 1 θ, -/// p* = 17, and prunes the others for accuracy or as above the reader's -/// threshold, never for want of a guarantee. Today: all 4 pruned -/// (BelowRequiredAccuracy 3, NoGuarantee 1). +/// p*, and prunes the others for accuracy or as above the reader's +/// threshold, never for want of a guarantee. Without the table: all pruned. #[test] -fn pass2_keeps_least_certified_hll() { +fn pass2_keeps_least_measured_hll() { let text = stages_text(&w1(), RunUntil::Pass2); let pass2 = section(&text, PASS2); let hll = group_block(pass2, "SummaryAgg HLL"); @@ -227,6 +258,22 @@ fn pass2_keeps_least_certified_hll() { assert!(kept_pass1[0].contains(&hll_theta(W1_PRECISION)), "{hll}"); } +/// Without the measured table W1's HLL has no guarantee with a known +/// failure probability (no small distinct bound), so Pass 2 keeps none of +/// its θ. +#[test] +fn pass2_prunes_hll_without_a_measured_table() { + let text = stages_text_with( + &w1(), + RunUntil::Pass2, + &DeploymentCapabilities::default(), + &asap_accuracy::NoMeasuredGuarantees, + ); + let hll = group_block(section(&text, PASS2), "SummaryAgg HLL"); + assert!(hll.contains("7 candidates: 7 pruned"), "{hll}"); + assert!(hll.contains("0 kept"), "{hll}"); +} + /// H1: Pass 2 adds W1's HLL pane chain at p*: the 10 s tumbling-window /// chain, its 60 s / 300 s / 900 s levels and a 1 h `TimeRangeCover`, and the /// `SummaryEstimate "Cardinality"` over HLL keeps a ✓ edge. Today: only KMV @@ -275,8 +322,7 @@ fn same_query_distinct_over_time_promql() { let promql = workload( json!("promql"), &[("distinct_over_time(flows[1h])", 10_000)], - 0.05, - 0.05, + (0.05, 0.05, PER_VALUE), 30_000.0, json!({"flows": {"series_count": 10000, "metric_type": "gauge", "sample_interval": 500, "column_signs": {"value": "non_negative"}, "max_distinct_per_evaluation": 100000}}), @@ -316,8 +362,7 @@ fn w2() -> PlanningWorkload { (Box::leak(q2.into_boxed_str()), 10_000), (lightcone, 4_000_000_000), ], - 0.05, - 0.05, + (0.05, 0.05, PER_VALUE), 30_000.0, e6_x1_sources(), ) @@ -325,13 +370,13 @@ fn w2() -> PlanningWorkload { /// H1, H5: q2's `SummaryAgg HLL` group reads the lightcone's (host, user) /// HLL state through a Rollup (`SummaryMerge <- Filter <- SummaryAgg HLL`) -/// with a ✓ edge, at the lightcone's θ (the least certified for -/// δ 0.05 / 100,000 = 5e-7: p 17 by the oracle). Today: HLL pruned, ✗. +/// with a ✓ edge, at the lightcone's θ (the least measured to meet rel 0.05 +/// at δ 0.05 per value, as W1's). Today: HLL pruned, ✗. #[test] fn lightcone_rollup_reads_host_user_hll() { let text = stages_text(&w2(), RunUntil::Pass2); let pass2 = section(&text, PASS2); - let theta = hll_theta(17); + let theta = hll_theta(W1_PRECISION); let rollups: Vec<&str> = group_blocks(pass2, "SummaryAgg HLL") .into_iter() .flat_map(|block| { @@ -350,11 +395,12 @@ fn lightcone_rollup_reads_host_user_hll() { ); } -/// H8: KMV's Pass 2 result for W1 is unchanged: k 26,656 and 106,263 kept -/// (BelowRequiredAccuracy 2), as on main. +/// H8: KMV's Pass 2 result for W1 (over the whole result, as on main) is +/// unchanged by the HLL table: k 26,656 and 106,263 kept +/// (BelowRequiredAccuracy 2). #[test] fn kmv_pass2_unchanged() { - let text = stages_text(&w1(), RunUntil::Pass2); + let text = stages_text(&w1_over(WHOLE_RESULT), RunUntil::Pass2); let kmv = group_block(section(&text, PASS2), "SummaryAgg KMV"); assert!( kmv.contains("4 candidates: 2 pruned (BelowRequiredAccuracy 2), 2 kept"), @@ -410,8 +456,7 @@ fn milp_fixture(interval_ms: u64) -> PlanningWorkload { workload( sql(), &[(W1, interval_ms)], - 0.1, - 0.01, + (0.1, 0.01, PER_VALUE), 20_000.0, json!({"flows": {"series_count": 1000, "sample_interval": 50, "distinct_values_per_label": {"host": 1000}, "rows_held": 72000000, @@ -465,7 +510,9 @@ fn selected_cost( let roots = lower_sql_roots(workload, &sql_catalog(&tables()).unwrap().0).unwrap(); let entries: Vec<_> = workload.query_workload.entries().collect(); let data = workload.data_workload.clone().unwrap_or_default(); - let models = PlanningModels::builtin().with_deployment_capabilities(capabilities); + let models = PlanningModels::builtin() + .with_evidence(measured_hll()) + .with_deployment_capabilities(capabilities); let run = run_stages_until( roots, &entries, @@ -493,10 +540,12 @@ fn keeps_hll_at_ingestion(text: &str) -> bool { .any(|line| line.contains("(IngestionTime, AcrossEvaluations") && line.contains("HLL")) } -/// Every 10 s, the chain (c) is cheaper than (a) and (b) by more than 10× +/// Every 10 s, the chain (c) is cheaper than (a) and (b) by more than 1.5× /// (each priced alone), and the MILP's unforced choice costs the least of -/// the three and keeps the chain. Today: (b) and (c) have no plan (HLL -/// pruned). +/// the three and keeps the chain. Holds with dense HLL pricing (this branch +/// alone) and with the sparse pricing of the cost PR; the margin only keeps +/// the choice clear of a near tie. Without the measured table: (b) and (c) +/// have no plan (HLL pruned). #[test] fn milp_keeps_hll_chain_when_cheaper() { let w = milp_fixture(10_000); @@ -509,7 +558,7 @@ fn milp_keeps_hll_chain_when_cheaper() { let c = selected_cost(&w, &forced('c')); assert!(c.is_ok(), "(c) has no plan: {:?}", c.err()); let c = c.unwrap().0; - assert!(10.0 * c < a.min(b), "a {a}, b {b}, c {c}"); + assert!(1.5 * c < a.min(b), "a {a}, b {b}, c {c}"); let (chosen, text) = selected_cost(&w, &capabilities(true, without_other_sketches())).unwrap(); assert!( (chosen - a.min(b).min(c)).abs() <= 1e-9 * chosen, @@ -518,24 +567,27 @@ fn milp_keeps_hll_chain_when_cheaper() { assert!(keeps_hll_at_ingestion(&text), "{text}"); } -/// Read every hour, the chain's upkeep outweighs its reads: the MILP picks -/// (a) or (b), whichever is cheaper, and keeps no ingestion-time state. -/// Fails today only because (b) has no plan (HLL is pruned). +/// Read every hour, the MILP's unforced choice is still the cheapest of +/// (a), (b) and (c), each priced alone, and it keeps an ingestion-time HLL +/// state exactly when (c) is that cheapest. At the measured p* (13) the +/// chain's upkeep can be small enough that (c) wins even hourly, so the +/// test checks the oracle rather than "drops the chain". #[test] -fn milp_drops_hll_chain_when_rarely_queried() { +fn milp_picks_the_cheapest_when_rarely_queried() { let w = milp_fixture(3_600_000); let cost = |alternative| { selected_cost(&w, &forced(alternative)) .unwrap_or_else(|e| panic!("({alternative}) has no plan: {e}")) .0 }; - let (a, b) = (cost('a'), cost('b')); + let (a, b, c) = (cost('a'), cost('b'), cost('c')); let (chosen, text) = selected_cost(&w, &capabilities(true, without_other_sketches())).unwrap(); + let cheapest = a.min(b).min(c); assert!( - (chosen - a.min(b)).abs() <= 1e-9 * chosen, - "{chosen} vs a {a} b {b}" + (chosen - cheapest).abs() <= 1e-9 * chosen, + "{chosen} vs a {a} b {b} c {c}" ); - assert!(!keeps_hll_at_ingestion(&text), "{text}"); + assert_eq!(keeps_hll_at_ingestion(&text), c == cheapest, "{text}"); } /// Without raw data the ingestion-time HLL chain is the only plan. @@ -567,8 +619,7 @@ fn ranked_distinct_keeps_estimates() { WHERE ts > now() - INTERVAL '1 hour' GROUP BY host ORDER BY c DESC LIMIT 10", 10_000, )], - 0.05, - 0.05, + (0.05, 0.05, WHOLE_RESULT), 30_000.0, e6_x1_sources(), ); diff --git a/crates/integration-tests/tests/main.rs b/crates/integration-tests/tests/main.rs index 831782530..aae0a4741 100644 --- a/crates/integration-tests/tests/main.rs +++ b/crates/integration-tests/tests/main.rs @@ -50,4 +50,5 @@ mod stage3_objective; mod state_views; mod storage_costs; mod time_range; +mod univmon_measured_accuracy; mod view_state_key; diff --git a/crates/integration-tests/tests/univmon_measured_accuracy.rs b/crates/integration-tests/tests/univmon_measured_accuracy.rs new file mode 100644 index 000000000..7fc08f167 --- /dev/null +++ b/crates/integration-tests/tests/univmon_measured_accuracy.rs @@ -0,0 +1,124 @@ +//! UnivMon's entropy has no theoretical bound, so Pass 2 prunes every +//! UnivMon readout of `entropy_over_time` under an accuracy target; a +//! measured entry (absolute error in bits, at a failure probability) lets it +//! keep the measured θ when the entry meets the target. +use asap_accuracy::{ + AccuracyEvidence, ErrorAtFailureProbability, MeasuredAccuracyEntry, MeasuredSketchAccuracy, + NoMeasuredGuarantees, +}; +use asap_planner::PlanningModels; +use asap_planner_cli::planning_stages::{lower_promql_roots, run_stages_until, RunUntil}; +use asap_planner_cli::planning_stages_text::planning_stages_text; +use asap_types::accuracy::AccuracyMetric; +use asap_types::summary_type::{SketchParams, SketchStatistic}; +use asap_types::workload::PlanningWorkload; +use serde_json::json; + +/// `entropy_over_time(data[5m])` every 60 s, absolute error 0.1 bits at δ +/// 0.05 per value, 1,000 gauge series sampled every 15 s. +fn entropy_workload() -> PlanningWorkload { + let workload: PlanningWorkload = serde_json::from_value(json!({ + "query_workload": {"language": "promql", "repeating_queries": [{ + "query": "entropy_over_time(data[5m])", + "demand": {"fixed_interval_at": {"interval": 60000, "evaluation_phase": 0}}, + "predictability": {"predictable": {"known_at": null}}, + "requirements": {"accuracy": {"max_error": 0.1, "failure_probability": 0.05, + "accuracy_metric": "absolute", "accuracy_scope": "per_value"}}, + }]}, + "data_workload": { + "arrival": {"ingesting": {"rows_per_second": 66.66666666666667}}, + "sources": {"data": {"series_count": 1000, "metric_type": "gauge", + "sample_interval": 15000}}, + }, + })) + .unwrap(); + workload.validate().unwrap(); + workload +} + +/// UnivMon's shape for every statistic but L2 and distinct counts. +fn baseline_shape() -> SketchParams { + SketchParams::UnivMon { + heap_size: 256, + sketch_rows: 5, + sketch_cols: 1024, + layers: 16, + } +} + +/// One entry: `shape`'s entropy within `error` bits at δ 0.05. +fn entropy_table(error: f64) -> MeasuredSketchAccuracy { + let table = MeasuredSketchAccuracy { + entries: vec![MeasuredAccuracyEntry { + sketch: baseline_shape(), + statistic: SketchStatistic::FrequencyEntropy, + accuracy_metric: AccuracyMetric::ABSOLUTE, + trials: 200, + error_at: vec![ErrorAtFailureProbability { + failure_probability: 0.05, + error, + }], + }], + }; + table.validate().unwrap(); + table +} + +/// The Pass 2 summary line (`… candidates: …`) of the `SummaryAgg UnivMon` +/// group under `evidence`. +fn univmon_pass2_line(evidence: &dyn AccuracyEvidence) -> String { + let workload = entropy_workload(); + let roots = lower_promql_roots(&workload).unwrap(); + let entries: Vec<_> = workload.query_workload.entries().collect(); + let data = workload.data_workload.clone().unwrap_or_default(); + let models = PlanningModels::builtin().with_evidence(evidence); + let run = run_stages_until( + roots, + &entries, + &data, + models, + Default::default(), + RunUntil::Pass2, + ) + .unwrap(); + let text = planning_stages_text(&run, None, None, false); + let pass2 = &text[text.find("Stage 1 Pass 2 output").unwrap()..]; + pass2 + .lines() + .skip_while(|line| !(line.starts_with('G') && line.contains("SummaryAgg UnivMon"))) + .find(|line| line.contains("candidates:")) + .unwrap_or_else(|| panic!("no UnivMon group:\n{pass2}")) + .to_owned() +} + +/// A measured entry within 0.1 bits at δ 0.05 lets Pass 2 keep UnivMon's +/// entropy readout. +#[test] +fn univmon_entropy_kept_with_a_measured_entry_meeting_the_target() { + let line = univmon_pass2_line(&entropy_table(0.08)); + assert!(!line.contains(", 0 kept"), "{line}"); +} + +/// Without a measured entry (or with one above the target) every UnivMon +/// θ is pruned: entropy has no theoretical bound. +#[test] +fn univmon_entropy_pruned_without_a_meeting_entry() { + for (name, line) in [ + ("no table", univmon_pass2_line(&NoMeasuredGuarantees)), + ("0.2 bits", univmon_pass2_line(&entropy_table(0.2))), + ] { + assert!(line.contains(", 0 kept"), "{name}: {line}"); + } +} + +/// The committed UnivMon table (`crates/accuracy/measured/univmon.json`, +/// measured per value over distinct counts 1..=100,000) has shapes within +/// 0.1 bits at δ 0.05, so Pass 2 keeps UnivMon's entropy readout with it. +#[test] +fn univmon_entropy_kept_with_the_committed_table() { + let table = + MeasuredSketchAccuracy::from_json(include_str!("../../accuracy/measured/univmon.json")) + .unwrap(); + let line = univmon_pass2_line(&table); + assert!(!line.contains(", 0 kept"), "{line}"); +} diff --git a/crates/planner-cli/src/bin/asap_planner.rs b/crates/planner-cli/src/bin/asap_planner.rs index e271eda66..b16bedb5d 100644 --- a/crates/planner-cli/src/bin/asap_planner.rs +++ b/crates/planner-cli/src/bin/asap_planner.rs @@ -50,6 +50,16 @@ // defaults it. To plan for a runtime that builds every summary family, // pass a file listing them all, e.g. // `tools/dag-viewer/deployment-capabilities/every-summary-family.json`. +// - `--measured-accuracy ` (repeatable): the deployment's measured +// sketch accuracy (`MeasuredSketchAccuracy` JSON, checked by +// `MeasuredSketchAccuracy::from_json`; the files' entries are joined +// and must not repeat a sketch, statistic and metric), which Pass 2 +// reads before each summary's theoretical guarantee +// (`PlanningModels::evidence`). Without it no θ has a measured +// guarantee, as `PlanningModels::builtin`. Examples in +// `crates/accuracy/measured/`: `hll_distinct.json` (HLL's per-value +// relative error at each precision 12..=18) and `univmon.json` +// (UnivMon's distinct count and entropy per listed shape). // - `--ignore-accuracy-guarantees`: Stage 3 accepts every query output // regardless of its accuracy guarantee // (`PlanningModels::ignore_accuracy_guarantees`), comparing candidates @@ -166,7 +176,9 @@ use std::collections::{BTreeMap, BTreeSet}; use asap_cost::{CostInputs, PlanCost}; use asap_frontend_promql::{metric_type_warnings, promql_metric_names}; use asap_frontend_sql::SqlCatalog; -use asap_planner::{assumed_data_facts, InstallablePlan, PlanningModels, SelectionError}; +use asap_planner::{ + assumed_data_facts, InstallablePlan, MeasuredSketchAccuracy, PlanningModels, SelectionError, +}; use asap_planner_cli::candidate_labels::operator_label; use asap_planner_cli::planning_stages::{ lower_metricsql_roots, lower_promql_roots, lower_sql_roots, run_stages_until, sql_catalog, @@ -245,6 +257,7 @@ fn run(args: Vec) -> Result<(), Failure> { let mut cost_inputs = CostInputs::default(); let mut deployment_capabilities = DeploymentCapabilities::default(); let mut ignore_accuracy_guarantees = false; + let mut measured_accuracy = MeasuredSketchAccuracy::default(); let mut verbose = false; let mut plan_file = None; let mut report_file = None; @@ -272,6 +285,17 @@ fn run(args: Vec) -> Result<(), Failure> { "--out" => out = Some(value()?), "--cost-inputs" => cost_inputs = read_json(&flag, &value()?)?, "--deployment-capabilities" => deployment_capabilities = read_json(&flag, &value()?)?, + "--measured-accuracy" => { + let path = value()?; + let text = + std::fs::read_to_string(&path).map_err(|e| format!("{flag} {path}: {e}"))?; + let table = MeasuredSketchAccuracy::from_json(&text) + .map_err(|e| format!("{flag} {path}: {e}"))?; + measured_accuracy.entries.extend(table.entries); + measured_accuracy + .validate() + .map_err(|e| format!("{flag} {path}: {e:?}"))?; + } "--ignore-accuracy-guarantees" => ignore_accuracy_guarantees = true, "--verbose" => verbose = true, "--printing-full-candidates" => { @@ -381,6 +405,7 @@ fn run(args: Vec) -> Result<(), Failure> { return Ok(()); } let models = PlanningModels::builtin() + .with_evidence(&measured_accuracy) .with_cost_inputs(&cost_inputs) .with_deployment_capabilities(&deployment_capabilities) .with_ignore_accuracy_guarantees(ignore_accuracy_guarantees); diff --git a/crates/planner-cli/tests/asap_planner.rs b/crates/planner-cli/tests/asap_planner.rs index fc32de16a..4c6ae7bd0 100644 --- a/crates/planner-cli/tests/asap_planner.rs +++ b/crates/planner-cli/tests/asap_planner.rs @@ -2698,3 +2698,72 @@ fn plan_file_flag_misuse_is_a_usage_error() { EARLIER_PLAN_FILE ); } + +/// `--measured-accuracy` reads a measured accuracy table, which Pass 2 +/// uses before a sketch's theoretical guarantee: `distinct_over_time` within +/// relative 0.05 at δ 0.05 per value has no HLL without it (the standard +/// error states no failure probability) and keeps one with HLL's committed +/// table (`crates/accuracy/measured/hll_distinct.json`). A table that fails +/// validation is refused. +#[test] +fn measured_accuracy_flag_lets_pass2_keep_hll() { + let workload = json!({ + "query_workload": {"language": "promql", "repeating_queries": [{ + "query": "distinct_over_time(x[1h])", + "demand": {"fixed_interval_at": {"interval": 10000, "evaluation_phase": 0}}, + "requirements": {"accuracy": {"max_error": 0.05, "failure_probability": 0.05, + "accuracy_scope": "per_value"}}, + "predictability": {"predictable": {"known_at": null}}, + }]}, + "data_workload": { + "arrival": {"ingesting": {"rows_per_second": 1000.0, "max_out_of_order_ms": 2000}}, + "sources": {"x": {"series_count": 1000, "metric_type": "gauge", + "sample_interval": 1000, "column_signs": {"value": "non_negative"}}}, + }, + }); + let file = TempFile::json(&workload); + let table = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("../accuracy/measured/hll_distinct.json") + .to_str() + .unwrap() + .to_owned(); + // The Pass 2 `SummaryAgg HLL` group's summary line of the text output. + let hll_group = |extra: &[&str]| { + let mut args = vec!["--workload", file.path(), "--run-until", "stage1_pass2"]; + args.extend_from_slice(extra); + let output = planner(&args); + let text = String::from_utf8(output.stdout).unwrap(); + let pass2 = &text[text + .find("Stage 1 Pass 2 output") + .expect("a Pass 2 section")..]; + pass2 + .lines() + .skip_while(|line| !(line.starts_with('G') && line.contains("SummaryAgg HLL"))) + .find(|line| line.contains("candidates:")) + .unwrap_or_else(|| panic!("no HLL group:\n{pass2}")) + .to_owned() + }; + let without = hll_group(&[]); + assert!(without.contains(", 0 kept"), "{without}"); + let with = hll_group(&["--measured-accuracy", &table]); + assert!(!with.contains(", 0 kept"), "{with}"); + + let not_monotone = TempFile::new( + r#"{"entries": [{"sketch": {"Hll": {"precision": 14}}, "statistic": "Cardinality", + "accuracy_metric": "relative", "trials": 1000, "error_at": [ + {"failure_probability": 0.01, "error": 0.01}, + {"failure_probability": 0.05, "error": 0.02}]}]}"#, + ); + let stderr = refused(&[ + "--workload", + file.path(), + "--run-until", + "stage0", + "--measured-accuracy", + not_monotone.path(), + ]); + assert!( + stderr.contains("--measured-accuracy") && stderr.contains("NotMonotone"), + "{stderr}" + ); +} diff --git a/crates/planner/src/lib.rs b/crates/planner/src/lib.rs index bd795ff52..18069ec90 100644 --- a/crates/planner/src/lib.rs +++ b/crates/planner/src/lib.rs @@ -39,6 +39,7 @@ mod models; mod pass; mod run; pub mod tutorials; +pub use asap_accuracy::MeasuredSketchAccuracy; pub use models::PlanningModels; pub use pass::{ optimize, OptimizationInput, OptimizationInputError, OptimizationPass, OptimizeError, diff --git a/crates/planner/src/models.rs b/crates/planner/src/models.rs index e2a50fb25..554ce6490 100644 --- a/crates/planner/src/models.rs +++ b/crates/planner/src/models.rs @@ -61,6 +61,14 @@ impl<'a> PlanningModels<'a> { PlanningModels::new(&NoMeasuredGuarantees) } + /// These models with the deployment's measured accuracy, e.g. a + /// `MeasuredSketchAccuracy` table loaded with + /// `MeasuredSketchAccuracy::from_json`. + pub fn with_evidence(mut self, evidence: &'a dyn AccuracyEvidence) -> Self { + self.evidence = evidence; + self + } + /// These models, enforcing no accuracy target when `ignore` /// (`ignore_accuracy_guarantees`). pub fn with_ignore_accuracy_guarantees(mut self, ignore: bool) -> Self { diff --git a/crates/types/src/summary_type/parameter_lists/mod.rs b/crates/types/src/summary_type/parameter_lists/mod.rs index 9d4510d75..6cb4badbd 100644 --- a/crates/types/src/summary_type/parameter_lists/mod.rs +++ b/crates/types/src/summary_type/parameter_lists/mod.rs @@ -77,10 +77,15 @@ const DDSKETCH_PARAMETERS: [SketchParams; 7] = [ SketchParams::DDSketch { alpha: 0.001 }, ]; -/// HLL's precision saturates at 18 from ε = 0.01 on. -const HLL_PARAMETERS: [SketchParams; 4] = [ +/// Every precision 12..=18, so Pass 2 keeps the least one meeting the +/// reader's target with no 2× gap in state between listed precisions; 18 +/// is the executor's largest. +const HLL_PARAMETERS: [SketchParams; 7] = [ + SketchParams::Hll { precision: 12 }, SketchParams::Hll { precision: 13 }, + SketchParams::Hll { precision: 14 }, SketchParams::Hll { precision: 15 }, + SketchParams::Hll { precision: 16 }, SketchParams::Hll { precision: 17 }, SketchParams::Hll { precision: 18 }, ]; diff --git a/crates/types/src/summary_type/parameter_lists/tests.rs b/crates/types/src/summary_type/parameter_lists/tests.rs index 088781644..7ac21f77b 100644 --- a/crates/types/src/summary_type/parameter_lists/tests.rs +++ b/crates/types/src/summary_type/parameter_lists/tests.rs @@ -66,8 +66,8 @@ fn parameter_list_holds_its_algorithm_without_repeats() { assert_eq!(parameter_list(SketchAlgorithm::UnivMon).len(), 40); } -/// HLL lists every precision 12..=18, so Pass 2 keeps the least certified -/// one for the reader's target (no 2× gaps between listed precisions). +/// HLL lists every precision 12..=18, so Pass 2 keeps the least one +/// meeting the reader's target (no 2× gaps between listed precisions). #[test] fn hll_list_is_every_precision_12_to_18() { let precisions: Vec = parameter_list(SketchAlgorithm::HLL) diff --git a/docs/user_guide_docs/asap-planner.md b/docs/user_guide_docs/asap-planner.md index f6fc7fd48..96d7d9ffb 100644 --- a/docs/user_guide_docs/asap-planner.md +++ b/docs/user_guide_docs/asap-planner.md @@ -36,7 +36,7 @@ minutes in a debug build. asap_planner (--workload )... --run-until stage0|stage1_pass1|stage1_pass2|stage2|stage3 [--format text|json] [--verbose] [--out ] [--sql-catalog-table ]... [--cost-inputs ] [--deployment-capabilities ] - [--ignore-accuracy-guarantees] [--plan-file ] + [--measured-accuracy ] [--ignore-accuracy-guarantees] [--plan-file ] ``` | Option | Meaning | @@ -49,6 +49,7 @@ asap_planner (--workload )... --run-until stage0|stage1_pass1|stage1_pass2 | `--sql-catalog-table ` | One SQL table a SQL workload reads, as `{"name", "columns": [{"name", "type", "nullable"}], "time_index"}`. Repeat it per table. | | `--cost-inputs ` | The cost model and its costs (`CostInputs` JSON). The files in `tools/dag-viewer/cost-inputs/` are ready to use. Without it, the built-in usage-over-time model is used. Stage 3 costs only usage-over-time models (`aws-fargate-us-east-1.json` is one); a provisioned- or cluster-capacity model ends Stage 3 with an `UnsupportedCostModel` error. | | `--deployment-capabilities ` | What the deployment can do, e.g. `{"raw_data_retained": true, "query_time_results_retained": false}`. Set it to match your deployment; see [Deployment capabilities](#deployment-capabilities). | +| `--measured-accuracy ` | Measured sketch accuracy (`MeasuredSketchAccuracy` JSON): per sketch configuration and statistic, the error not exceeded except with each recorded failure probability. Pass 2 uses it before a sketch's theoretical guarantee. Repeat it to join several tables. `crates/accuracy/measured/hll_distinct.json` holds HLL's measured relative error per value at each precision 12..=18, and `univmon.json` UnivMon's distinct-count and entropy errors per listed shape. Without a table, HLL (and UnivMon's distinct count and entropy) have no guarantee with a known failure probability and are pruned under an accuracy target. | | `--ignore-accuracy-guarantees` | Accept candidates without an accuracy guarantee. By default each query's accuracy requirement is enforced. | | `--plan-file ` | Also write the plan Stage 3 selects to this file, as `InstallablePlan` JSON; needs `--run-until stage3`. See [Write a plan file](#write-a-plan-file). |