Repository navigation
Do not match a JSON subcolumn inside a typed path to a skip index - #119321
Conversation
A `JSONAllPaths` skip index silently returned no rows for a filter on a subcolumn that reaches inside a
typed path of a `JSON` column:
CREATE TABLE t (json JSON(a JSON), INDEX idx JSONAllPaths(json) TYPE bloom_filter GRANULARITY 1)
ENGINE = MergeTree ORDER BY tuple() SETTINGS index_granularity = 2;
INSERT INTO t SELECT '{"a":{"b":42}}' FROM numbers(4);
SELECT count() FROM t WHERE json.a.b = 42; -- 0
SELECT count() FROM t WHERE json.a.b = 42 SETTINGS use_skip_indexes = 0; -- 4
`JSONAllPaths` reports a declared typed path verbatim and never recurses into its contents, so the
granule path set here is `['a']`, both for a nested `JSON` typed path and for a structured one such as
`JSON(a Tuple(b Int64))`. The query side derives the path `a.b` from the subcolumn `json.a.b` and asks
whether any granule contains it; none does, so every granule was pruned, even though the value lives
inside the typed path's own column and reading the subcolumn returns it. The assumption behind the
match - a path absent from `JSONAllPaths` means the subcolumn is `NULL` - holds for a dynamic path but
not for the substructure of a typed path.
Refuse the match when the derived path has a strict prefix that is a declared typed path of the `JSON`
type, so such a filter simply does not use the index. The type is taken from the argument of the JSON
index function in the index expression, collected per index sample block position and passed to the
condition, so it is available regardless of how the column is named inside the index function. This
covers every index type sharing the matcher (`bloom_filter`, `tokenbf_v1`, `ngrambf_v1`, `text`) and
every predicate routed through it. The shapes the index is designed for are unaffected: a scalar typed
path is reported by its own name, and a dynamic path is reported with all of its components, so both
keep using the index.
Closes: #117938
|
Workflow [PR], commit [ccf28d2] Summary: ✅
AI ReviewSummaryThis PR fixes a real wrong-result case where Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit ccf28d2.
Changed lines: Changed C/C++ lines covered: 92/97 (94.85%) · Uncovered code |
|
The red stateless jobs are all the same unrelated test: |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units34 translation units recompiled, 348 s compile time in total, 34 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
…d-path-subcolumn-117938 Both sides added a trailing constructor parameter to the bloom filter, text bloom filter and text index conditions (`columns_shadowing_map_subcolumns_` on master, `json_argument_types_` in this branch); keep both.
… path Typed paths of a `JSON` type may overlap: `JSON(a Array(JSON), a.b Int64)` declares both `a` and `a.b`, and the subcolumn `json.a.b` reads the typed path `a.b` itself, which `JSONAllPaths` reports verbatim. `pathIsInsideTypedPath` returned true on the shorter typed prefix `a`, so such a filter stopped using the skip index. A path that is a declared typed path is now exempt from the strict-prefix check; the test pins it with `force_data_skipping_indices`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
# Conflicts: # src/Storages/MergeTree/MergeTreeIndexConditionText.cpp # src/Storages/MergeTree/MergeTreeIndexConditionText.h
… `JSON` index argument `collectJSONIndexArgumentTypes` only recognized a bare `DataTypeObject`, so for an index `JSONAllPaths(json)` over `Nullable(JSON(a JSON))` the typed paths were not known and a subcolumn inside a typed path (`json.a.b`) was still matched to the index, pruning every granule. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp # src/Storages/MergeTree/MergeTreeIndexBloomFilter.h
…mn test `MergeTreeIndexConditionText` has its own matchers for `JSONAllValues` and `JSONAllPaths`, which the fix also guards. Add regressions for both with `tokenizer = 'array'` over `JSON(a JSON)`: without the fix a filter on `json.a.b` prunes every granule and returns 0 rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix a
JSONAllPathsskip index silently pruning every granule for a filter on a subcolumn inside a declared typed path of aJSONcolumn (for examplejson.a.bforJSON(a JSON)orJSON(a Tuple(b Int64))). Such a filter no longer uses the index.Documentation entry for user-facing changes
...
A
JSONAllPathsskip index silently returned no rows for a filter on a subcolumn that reaches inside a typed path of aJSONcolumn:JSONAllPathsreports a declared typed path verbatim and never recurses into its contents, so the granule path set here is['a'], both for a nestedJSONtyped path and for a structured one such asJSON(a Tuple(b Int64)). The query side derives the patha.bfrom the subcolumnjson.a.band asks whether any granule contains it; none does, so every granule was pruned, even though the value lives inside the typed path's own column and reading the subcolumn returns it. The assumption behind the match — a path absent fromJSONAllPathsmeans the subcolumn isNULL— holds for a dynamic path but not for the substructure of a typed path.Refuse the match when the derived path has a strict prefix that is a declared typed path of the
JSONtype, so such a filter simply does not use the index. The type is taken from the argument of the JSON index function in the index expression, collected per index sample block position and passed to the condition, so it is available regardless of how the column is named inside the index function. This covers every index type sharing the matcher (bloom_filter,tokenbf_v1,ngrambf_v1,text) and every predicate routed through it. The shapes the index is designed for are unaffected: a scalar typed path is reported by its own name, and a dynamic path is reported with all of its components, so both keep using the index — the new test pins that withforce_data_skipping_indices.New test:
05198_json_skip_index_typed_path_subcolumn. Verified in both directions, and a differential run of theskip_index/bloom_filter/text_index/json_path/tokenbf/ngrambfstateless tests (344 tests) shows no new failures.Closes: #117938
Workflow [PR]
Sync PR [sync-upstream/pr/119321]
Version info
26.10.1.1372-master(included in26.10and later)