Repository navigation
Add a regression test for the const / variable NaN-endpoint monotonicity guard - #119461
Conversation
The `NaN`-endpoint guard added in #118468 declines `divide`/`multiply` monotonicity for both operand orders, but `05113_arithmetic_monotonicity_nan_endpoint` only exercised `variable / const`. The `const / variable` branch has its own false-pruning shape: for `inf / k` over a range whose right end is `+inf` the transform is decreasing, so `KeyCondition` inverts the range and the transformed `NaN` becomes the left bound. Verified against the current binary with positive and negative controls: with the guard, `EXPLAIN indexes = 1` for `inf / k = inf` reports `Granules: 100/100` and the query returns all matching rows, while a finite constant dividend (`100 / k > 2`) still prunes down to `Granules: 49/100`. Related: #118468 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [21e1bdc] Summary: ✅ AI ReviewSummaryThis PR adds a focused stateless regression test for the Final Verdict
|
…r is really covered `clickhouse-test` randomizes `auto_statistics_types` and `materialize_statistics_on_insert`, and only a materialized `basic` (or `minmax`) statistic gives the pruner the column min/max it reads: without one, `StatisticsPartPruner::isUseless` is true and `filterPartsByStatistics` hands back every part untouched. So the `use_primary_key = 0` queries, which exist to isolate the statistics layer, covered nothing in the runs where the randomizer dropped `basic`. Pin `auto_statistics_types = 'basic'` on both tables and `materialize_statistics_on_insert = 1` for the inserts, and assert the layer is live: a predicate outside the part's `[1, +inf]` statistics range still prunes the part, so `EXPLAIN indexes = 1` reports a `Statistics` entry. Measured against a binary built from `master`, which already carries the guard, that new assertion is what fails in exactly the windows the review pointed at: - `auto_statistics_types = 'uniq_v2'`: `system.parts_columns` shows `['UniqV2']` with a `NULL` `estimates.min`, no `Statistics` entry in `EXPLAIN`, and `inf / k = inf` still returns `3` - the test passed while exercising nothing; - `auto_statistics_types = 'basic'` with `materialize_statistics_on_insert = 0`: the statistics array is empty, again no `Statistics` entry; - pinned and materialized: `['Basic']` with min `1` and max `inf`, and the `Statistics` entry appears. `SET parallel_replicas_local_plan = 1` keeps both `EXPLAIN indexes = 1` checks on the local plan when the runner enables parallel replicas. Addresses #119461 (comment)
…s, not just that statistics exist The previous liveness probe used `k < 0`, a plain comparison. That proves the table has materialized `basic` statistics, but not that `StatisticsPartPruner` builds a condition for the *arithmetic* predicate under test: `getKeyConditionForEstimates` returns `nullptr` when the condition is `alwaysUnknownOrTrue`, so if the monotonic-function chain stopped being recognized on the statistics path, every `use_primary_key = 0` query would answer by full scan and pass while covering nothing. Nothing positive can be asserted on `inf / k = inf` itself: `filterPartsByStatistics` records its `IndexStat` only when it actually drops a part, so a held guard and an unanalyzed predicate both show no `Statistics` entry. The probe therefore has to be the same transform shape with endpoints that stay finite, so the guard does not fire and pruning is allowed: - `100 / k > 200` over `[1, +inf]` transforms to `[0, 100]`, cannot match, and must prune - so a `Statistics` entry appears (verified: `Parts: 0/1`); - `0 * k = 5` over `[1, 100]` is the `multiply` counterpart. It needs a range without `+inf`, since `0 * inf` is exactly the `NaN` the guard declines. A non-zero multiplier would not work at all: the overflow check in `FunctionBinaryArithmetic::getMonotonicityForRange` dispatches on the result type and has no `Float` case, falling through to `: true /* unknown type */`, so `multiply` monotonicity is always declined for a `Float` result. Also assert the complement - no `Statistics` entry for `inf / k = inf` - so the "keeps every part" half of the contract is pinned explicitly rather than only through the row count, and pin `explain_query_plan_default = 'legacy'` so the `%Statistics%` and `Granules:` matches do not depend on the default plan printer, as `04811_statistics_part_pruning_nan_negation` does. Re-ran the whole test clean under `enable_analyzer` 0/1, `explain_query_plan_default` legacy/pretty, `optimize_move_to_prewhere = 0`, `materialize_statistics_on_insert = 0` (the in-test `SET` overrides it), `use_statistics = 0` + `use_statistics_cache = 0`, `query_plan_merge_filters = 0` and `merge_tree_coarse_index_granularity = 32`. Addresses #119461 (comment)
|
🕵 Addressed in d8e2351. The finding is right: One correction to the suggested fix, though. Asserting on
I also kept the complement you were after — asserting there is no Re-ran the whole test clean under (The trailing reference in that commit message is a placeholder anchor, not a real permalink; the review |
|
🕵 Evidence that it is not caused by this change, from
Tracked by #101325 (open; #101490 was closed as a duplicate of it). A fix is already in progress and targets exactly this function: #113589 — " The one remaining red, |
…city-nan-const-dividend
|
🕵 Merged Status of the two reds on the previous head:
Everything else is green and there are no unresolved review threads. |
|
📊 Cloud Performance Report ✅ AI verdict: This is a test-only change: it adds one new stateless regression test (05182_arithmetic_monotonicity_nan_const_dividend) covering the const/variable NaN-endpoint monotonicity guard, plus internal tooling documentation. No production/query-execution code is touched, so it cannot plausibly move any ClickBench median. The single flagged query (Q28, -5.5%) is therefore treated as run-to-run variance and downgraded to not_sure; its measurements were noisier than baseline and the two tests disagreed, consistent with noise rather than a real shift. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
…city-nan-const-dividend
… liveness probes to an integer key Add an `EXPLAIN indexes = 1` liveness probe with `use_statistics_for_part_pruning = 0` showing that `KeyCondition` still skips granules for `0 * k = 5`, and a matching check that it keeps every granule for `0 * k = 0` over a range ending at `+inf`. Also move the statistics liveness probes from the `Float64` table to a `UInt64` one: after #107074 the statistics pruner declines every function chain over a `Float` column (its min/max can hide a `NaN`), so the `Float64` probes could no longer report a `Statistics` entry on current master. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Follow-up to #118468, which declined
divide/multiplymonotonicity when a range endpoint maps toNaN. The guard there covers both operand orders, but its test05113_arithmetic_monotonicity_nan_endpointonly exercisedvariable / const.The
const / variablebranch has its own false-pruning shape. Forinf / kover a range whose right end is+inf,inf / infisNaN; the transform is decreasing, soKeyConditioninverts the range and the transformedNaNbecomes the left bound — the same "no point compares into the range, prune everything" outcome, reached from the other side.Verified against a binary built from current
master, with positive and negative controls:EXPLAIN indexes = 1forWHERE inf / k = infreportsGranules: 100/100(nothing pruned) and the query returns all matching rows;WHERE 100 / k > 2, still prunes toGranules: 49/100, so pruning for ranges that stay finite is unaffected.The test also covers
const * variable(0 * k) and each pruning layer — the primary key index anduse_statistics_for_part_pruning— on its own.basiccolumn statistics are pinned on both tables and materialized on insert, becauseclickhouse-testrandomizesauto_statistics_typesandmaterialize_statistics_on_insertandStatisticsPartPruneris inert without a materializedbasicorminmaxstatistic; the test also asserts that the pruner actually analyzes these transforms rather than assuming it. SincefilterPartsByStatisticsrecords anIndexStatonly when it drops a part, that probe has to be the same transform shape with endpoints that stay finite, so the guard does not fire and pruning is allowed:100 / k > 200over[1, +inf]and, formultiply,0 * k = 5over[1, 100]— both must report aStatisticsentry inEXPLAIN indexes = 1, whileinf / k = infmust report none. Granule counts are compared rather than pinned, since the test runner randomizes the settings they depend on. Test only; no behavior change.Addresses the review comment on #118468 (comment)
Related: #118468
Related: #118121
Changelog category (leave one):
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/119461]
Version info
26.10.1.2082-master(included in26.10and later)