Repository navigation
Conversation
An index column of type Dynamic or Variant, which an undeclared JSON path such as j.a resolves to, took its per-granule Range from getExtremes. ColumnVariant::getExtremes, which ColumnDynamic delegates to, ignores its row range and returns Null() for both bounds, so the granule range became Range(NULL, true, NULL, true). That range is vacuous in Range arithmetic: a plain-Null bound is neither < nor == any value, so every early return in intersectsRange and containsRange fails and both report true. In checkInHyperrectangle a contained key range means the atom is definitely TRUE on the granule, and BoolMask::operator! turns that into definitely FALSE for a negated atom, which returns before the exact evaluation and drops every granule whatever the data. != and IS NULL therefore returned no rows at all. The default bulk-filtering path never reads the hyperrectangle, which is why this went unnoticed; a query with two useful skip indexes and a disjunction, or secondary_indices_enable_bulk_filtering = 0, routes to the pre-check and loses rows at otherwise default settings. It was found as a TLP aggregate oracle mismatch reported by the AST fuzzer on ClickHouse#115581. Push Range::createWholeUniverse() for such a coordinate at both producers of set_hyperrectangle, the granule read path and the aggregator build path, so the coordinate cannot exclude a granule while the other coordinates of a composite index keep their measured ranges and the exact evaluation over the stored set still decides. createWholeUniverse is used rather than the type-aware helper, which would return the WithoutNull universe for Dynamic and reintroduce the IS NULL half of the bug. Nothing on disk changes: the hyperrectangle is not serialized, it is recomputed on every read. Unlike minmax, the set index is not refused at DDL for these types: its exact evaluation is correct, only the pre-check was unsound, and refusing would break tables that work today without repairing existing ones.
Review round 1 asked for oracles that the round-0 test did not have. No source change: MergeTreeIndexSet.cpp is byte-identical. The aggregator half of the fix had no oracle. The granule range is never serialized and there is no build-time granule cache, so an ordinary query always rebuilds it in deserializeBinary and the aggregator's copy is never read back. Deleting that hunk left every existing arm green. It is not dead code: WhatIfEmpiricalEstimator builds granules with createIndexAggregator() and calls mayBeTrueOnGranule on them directly, so before the fix EXPLAIN WHATIF reports a 100% skip ratio for a hypothetical set index over a Dynamic column that would in fact skip nothing. Case 10 asserts that estimate, modelled on 04408_hypothetical_index_partial_read, and pins source: empirical so a fallback to the statistical or applicability-only estimator cannot silence it. Verified at hunk level: removing only the aggregator hunk makes exactly this line fail, and the other 26 assertion lines stay green. Three count-only arms could also survive a change that stops matching a JSON subcolumn or a Variant column to the index, which is live right now, so they gain a Granules: 16/16 plan oracle. The arm labelled bulk did not pin its route: secondary_indices_enable_bulk_filtering is randomized, so in half of CI runs it silently duplicated the granule arm. Arity-1 Tuple(Dynamic) and Tuple(Variant(UInt64, String)) were measured rather than assumed: both give Granules: 16/16 on the base and fixed binaries, so no comparison atom is built for a tuple-typed index column at any arity and no arm was added for them. no-replicated-database is added because hypothetical indexes are session-scoped and not replicated.
Review round 2 asked for a direct oracle on set_hyperrectangle. No source change: MergeTreeIndexSet.cpp is byte-identical. Nothing asserted what the granule range contains, although changing its contents is the whole point of the fix. mayBeTrueOnGranule uses the hyperrectangle only as a conservative pre-filter and otherwise falls through to the exact scan over the stored set, which is ground truth, so widening a measurable coordinate to the whole universe changes no query result and no EXPLAIN granule count. A helper that answered false for every type would leave every SQL assertion green. The property is not observable from SQL either: the class emits no ProfileEvents and there is no counter for the hyperrectangle. The tests cover both producers of set_hyperrectangle for both kinds of coordinate: a UInt64 column keeps the bounds measured from its values, and a Dynamic column gets the whole universe, each asserted on the aggregator's granule and again after a serializeBinary and deserializeBinary round trip, which is the path a query takes when it reads the index from a part. The last test builds a composite (Dynamic, UInt64) index from two blocks and pins the per-coordinate alignment: the second block widens the measurable coordinate to the union of both blocks while the Dynamic coordinate is neither re-pushed nor widened. Every bound is checked with its inclusion flags. The exclusive universe is contained in the range an IS NULL atom carries and KeyCondition inverts that mask, so a later switch to createWholeUniverseTypeAware, which returns the exclusive universe for a non-Nullable type such as Dynamic, would again drop every granule; asserting left_included and right_included makes that fail here rather than in a row count. Measured against the base source: the two Dynamic arms fail on both producers while the measurable arms pass, and forcing the helper to false reddens the measurable arms and the composite coordinate instead.
hasMeaningfulFieldExtremes recurses into children, so a Tuple(UInt64, Dynamic) index column also gets the whole universe instead of measured bounds. Nothing pinned that recursion: dropping it left every existing assertion green, because ColumnTuple::getExtremes then writes Tuple Fields as the bounds, and no query can see the difference (KeyCondition builds no granule-excluding atom for a tuple-typed index column at any arity, so a SQL arm would assert nothing). The granule bounds are only reachable from C++, which is where this belongs.
hasMeaningfulFieldExtremes rejects a Variant child as well as a Dynamic one,
and nothing pinned that half of the recursive condition: deleting only
`|| isVariant(child)` left all five existing unit tests and all 27 assertion
lines of the SQL test green, because the one nested arm is
Tuple(UInt64, Dynamic) so the isDynamic child arm still fires, and the Variant
arm of the SQL test is top level. Tuple(UInt64, Variant(UInt64, String)) is a
declarable index coordinate with the same pathology, since ColumnTuple's
getExtremes delegates per element to the ColumnVariant placeholder that
ColumnDynamic also delegates to, so the bounds become Tuple{0, Null} and
Tuple{9, Null} instead of the inclusive whole universe. As with the Dynamic
case, no query observes those bounds, so the assertion belongs in C++.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex), five rounds: 7 gate findings plus 8
Also checked, unraised: the Provenance, since the changelog category asserts it: the pre-check this fixes arrived in Severity: ❌ blocker / Review sessions: |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260918-100600 |
|
Workflow [PR], commit [ed0df4f] Summary: ❌
AI ReviewSummaryThis PR fixes the Final Verdict✅ No new findings. LLVM Coverage ReportMeasured on commit ed0df4f.
Changed lines: Changed C/C++ lines covered: 123/123 (100.00%) · Uncovered code |
CI finish ledger - ed0df4fEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260918-220128 |
6a2edb4
Related: #115581
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
setskip index whose expression has typeDynamicorVariant, which includes an undeclaredJSONpath such asj.a, silently returning no rows for!=andIS NULL. The index reported an unbounded range for such a granule, and index analysis read that as proof that a negated condition is false, so every granule was skipped.Description
From the
AST fuzzer (amd_release, oracle)TLP aggregate mismatch on #115581 (report); not caused by that PR.Wrong results at default settings:
With one index:
secondary_indices_enable_bulk_filtering = 0.An undeclared
JSONpath resolves toDynamic, whichsetIndexValidatoraccepts.MergeTreeIndexSetbuilds each granule'sRangefromgetExtremes, butColumnVariant::getExtremesignores its rows and returnsNull()bounds, whichRangereads as unbounded.containsRangeis then vacuously true, socheckInHyperrectanglecalls the atom definitely true, and a negated atom inverts that to definitely false: the granule is dropped before the exact evaluation. The default bulk path never reads the hyperrectangle, hence it survived.The fix pushes
Range::createWholeUniverse()for such a coordinate at both producers, so it cannot exclude a granule; other coordinates keep their ranges. Nothing on disk changes: the hyperrectangle is recomputed per read.minmaxrefuses these types at DDL; forsetonly the pre-check was unsound, so refusing would break working tables. Aminmaxindex overDynamicis still reachable through a hand-writtenATTACHand drops granules for=; it is pre-existing and serializes its bounds, so I left it out, but can fold it in if you prefer.05227_set_index_dynamic_granule_rangecoversDynamic,Variant, present and absentJSONpaths, a composite index and both routes; its negated andIS NULLarms return no rows on master, its positive-atom controls still prune on both. A unit test pins the range, which no query observes. The reported identity goes from 64 versus 0 to 64 versus 64.Workflow [PR]
Sync PR [sync-upstream/pr/120780]
Version info
26.10.1.490-master(included in26.10and later)