Description
Wrong result: minmax skip index prunes NaN rows for a negated float range condition
Summary
With a minmax skip index on a Float64 (here Nullable(Float64)) column,
a granule containing only NaN values is pruned for the predicate
NOT (val >= 0. AND val <= 3.) — but row-wise evaluation says the NaN rows
match (NaN >= 0. is false, so the negation is true). The negated
range analysis treats the granule's [nan, nan] minmax range as disjoint
from the complement of [0, 3], which is only valid inside the total order;
NaN compares false against everything, so it always satisfies the negation
of any comparison-based range.
Found by the AST-fuzzer correctness-oracle suite from PR
#99980 (TLP WHERE oracle:
the p / NOT p / p IS NULL partitions lost all NaN rows; two fuzz
instances independently hit the same family via t_minmax_float and
test_negate_nan_ne_float seeds).
Minimal repro
CREATE TABLE t_minmax_float
(
id UInt64,
val Nullable(Float64),
INDEX idx_val val TYPE minmax GRANULARITY 1
)
ENGINE = MergeTree ORDER BY id SETTINGS index_granularity = 3;
INSERT INTO t_minmax_float VALUES (1, NULL), (2, NULL), (3, NULL);
INSERT INTO t_minmax_float VALUES (4, nan), (5, nan), (6, nan);
INSERT INTO t_minmax_float VALUES (7, 1.0), (8, 2.0), (9, 3.0);
SELECT count() FROM t_minmax_float WHERE NOT ((val >= 0.) AND (val <= 3.));
-- index ON (default): 0 (WRONG — rows 4,5,6 have val = NaN, the predicate is true)
-- SETTINGS use_skip_indexes=0: 3 (correct)TLP view (partitions must cover the table exactly once):
SELECT count() FROM t_minmax_float WHERE (val >= 0.) AND (val <= 3.); -- 3
SELECT count() FROM t_minmax_float WHERE NOT ((val >= 0.) AND (val <= 3.)); -- 0, should be 3
SELECT count() FROM t_minmax_float WHERE isNull((val >= 0.) AND (val <= 3.)); -- 3
-- 6 of 9 rows with the index, 9 of 9 without.Reproduced on 26.6.1.1 (master 76c2edca2fd, release build), default
settings.
Fix area
Minmax index condition / KeyCondition range complement logic for floating
point columns: when negating a comparison-based range, a granule whose
min/max are NaN (or whose range may contain NaN — note min/max
aggregation itself may ignore NaN, so a mixed granule's range can look
normal while containing NaN rows) must be treated as "may match". The seed
tests (t_minmax_float from the NaN-ordering test, test_negate_nan_ne_float)
suggest recent work on adjacent cases — this negation path is still open.
Note the all-NaN granule case may extend to mixed granules: if minmax
stats skip NaN, a granule [1.0, 3.0] containing a NaN row would also be
wrongly pruned for NOT (val >= 0 AND val <= 3) — worth covering both in
the fix and tests.
Original fuzzer hits (for reference)
2026-06-10 03:47:00 (cycle 9f instance 01, release, fuzzed query
SELECT id FROM t_minmax_float WHERE (val >= 0.) AND (val <= 3.) ORDER BY id DESC)
and 03:46:02 (instance 06, debug, test_negate_nan_ne_float), run dir
tmp/fuzz_lab/runs/20260610-0322-8d62cab0551/.
Version info
- Resolved by: Fix skip indexes and part pruning dropping rows that hold a NaN under a negated float comparison #107074
- Merged into:
26.10.1.462-master(included in26.10and later)
Activity
qoega commentedon Jun 10, 2026
@groeneai could you please reproduce and fix this one? Repro is in the issue body — deterministic on master
76c2edca2fd, default settings.PedroTadim commentedon Jun 10, 2026
May be a duplicate of #106533
groeneai commentedon Jun 10, 2026
Reproduced on master
fc73f46and fixed in #107074.@PedroTadim was right that this is related to #106533, but it needs two fixes, not one:
KeyConditionnegation guard from Skip not-comparison rewrite for float operands (issue #106533) #106568. Without it,NOT ((val >= 0) AND (val <= 3))is rewritten viainverse_relationsto(val < 0) OR (val > 3), which prunes the[NaN, NaN]granule.[1.0, nan, 3.0](the case you flagged) is a distinct bug in theminmaxindex itself.MergeTreeIndexAggregatorMinMax::updatecomputes extremes withColumnVector::getExtremes, which deliberately skips NaN, so the granule stores the clean range[1.0, 3.0]and the NaN is invisible to range analysis. Since NaN sorts after+infin ClickHouse order, the fix records NaN as the granule max when any row is NaN, which trips the existing NaN guard inKeyCondition::checkInHyperrectangle. Widening a stored minmax range only causes conservative keeps, never wrong skips, so positive-range pruning is unaffected (a NaN granule is still pruned forval < 0,val > 500, etc.).#107074 supersedes #106568 and contains both fixes, closing #106533 and #106948. Regression tests cover the all-NaN granule, the mixed granule, and that positive-range pruning still works.
clickgapai commentedon Jun 13, 2026
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.
TL;DR
minmax skip index prunes NaN granule under negated float range predicate (
NOT ((val >= a) AND (val <= b)))ClickGap verified: reproduced it with the script below on
master; tested 6 version(s) — 4 affected, 2 clean (see Affects); bisected the regression to a single PR (#98964).Reproduction
Bisect
eea8ff0cab02, bisected on master, 9 steps, confidence: HIGH)Affects
master, 26.5, 26.4, 26.326.2, 26.1Suggested next step
Review PR #98964 for the introducing change in
comp-skip-index. If a forward-fix or revert is intended, the bisect data above narrows the search space.Component:
comp-skip-indexSeverity:
P2cc introducing PR author: @alexey-milovidov
cc introducing PR reviewer: @clickhouse-gh[bot]
ClickGap · Finding:
h_issue_106948Triage metadata
comp-skip-indexcomp-mergetreecomp-skip-index): @shankar-iyer @rschu1zeRead pre-V5 float statistics conservatively for NaN part pruning
Trim the fix narrative out of the NaN code comments
Never report a float minmax bound as fully satisfying a condition
zlareb1 commentedon Aug 28, 2026
The 25.12 default flip
use_skip_indexes_for_disjunctions = 1widens this bug's reach: it drops NaN rows in queries where the pre-flip index analysis was still correct, at pure default settings. The trigger is the mixed granule (the second bullet in the comment above), so no all-NaN granule is needed.NOT (nan < 5 AND ...)isNOT (false)= true, so thenanrow must be returned. Both the old and the new analyzer return 4. Reproduced on 26.9.1.1 and on 26.4.1.1 (the flip is default-on in both).Mechanism: with the flip off, each skip index evaluates the whole
WHERE; foridx_ftheg < 100conjunct isFUNCTION_UNKNOWN, andNOT (unknown AND f < 5)stays may-be-true, so the granule survives — the pre-flip correctness here is accidental masking, not soundness. With the flip on,MergeTreeDataSelectExecutor::mergePartialResultsForDisjunctionsrecombines per-atomcan_be_truebits by the real boolean structure, so the masking is gone and the isolatedNOT (f < 5)atom is checked against the granule's NaN-free minmax range[1, 3]fromgetExtremes: the range is fully contained in(-inf, 5), socan_be_falsecomes out definitely-false although the NaN row does not satisfyf < 5; the negation flips it to a definite cannot-match, andfalse OR falsedrops granule 0.EXPLAIN indexes = 1shows the drop under<Combined skip indexes>:Granules: 1/2with the flip on vs2/2off.So
use_skip_indexes_for_disjunctions = 0is only a partial mitigation (a single-columnNOT (f < 5)over a mixed granule still loses the row, per the mixed-granule bullet above), and since 25.12 the default-on disjunction path extends the loss toNOT (a AND b)and OR-of-conditions queries over multiple indexed columns.The mixed-granule fix in #107074 (record NaN as the granule max in
MergeTreeIndexAggregatorMinMax::update) heals this arm as well, because the disjunction path consumes the sameKeyCondition::checkInHyperrectangleverdicts that the NaN bound guard makes conservative.Opt out of implicit min-max indices in 04811_statistics_part_pruning_…
Fix minmax skip index and partition pruning wrongly skipping NaN unde…
Drop the implicit min-max index opt-out from `04811_statistics_part_p…