Repository navigation
Add jsonPathValues tokenizer for JSON text indexes - #114613
Open
rorylshanks wants to merge 127 commits into
Open
rorylshanks wants to merge 127 commits into
rorylshanks wants to merge 127 commits into
Conversation
Correctness: - Evaluate `FUNCTION_EQUALS` text search queries with their own fold mode in `mayBeTrueOnGranule`: an Any-mode query (e.g. float 0/-0 equality) folds postings by union, and intersecting a partially-read union as All-mode could prune granules whose matching token postings were not read yet. - Do not build exact-match tokens from FixedString values: their zero padding participates in zero-pad-aware string comparison but not in the tokens a String or Dynamic path stores. Declared FixedString paths keep using the index since both sides pad consistently. Performance: - Check whether any (possibly wrapped) IN argument is covered by the index before materializing the subquery set in `tryPrepareSetForTextSearch`. - Resolve each shared-data value's type name once in `enumerateJSONValues` and reuse the per-path discriminator cache in both traversal orders. - Precompute pattern prefix ranges in `TextIndexAnalyzer` instead of rebuilding prefix-end strings per dictionary block in `mayMatchPatternsInRange`. Cleanup: - Deduplicate the `toString`/`ifNull`/`coalesce`/`nullIf` wrapper-unwrapping loop (three divergent copies) into `tryUnwrapIndexArgument`. - Define the order-preserving zero-byte escaping in a single helper `appendEscapedComponentBounded` used by all token encoders. - Fold the lazy-mode range derivation in `readRows` into `buildPostingsForMark`. - Remove the never-populated `JSONTextQueryPayload` fields `pattern_token_excluded_prefixes`, `pattern_token_kinds`, and `validation_pattern_kinds` together with their sorting, hashing, and matching logic, and the now test-only `tryGetKind`.
…20260825 # Conflicts: # src/Interpreters/ITokenizer.cpp # src/Interpreters/ITokenizer.h # src/Processors/QueryPlan/Optimizations/optimizeDirectReadFromTextIndex.cpp # src/Storages/MergeTree/MergeTreeIndexJSONSubcolumnHelper.cpp # tests/queries/0_stateless/02346_system_tokenizers.reference
Contributor
|
Workflow [PR], commit [5d27497] Summary: ❌
|
…3-20260825 # Conflicts: # src/Storages/MergeTree/MergeTreeIndexText.cpp
Use memory-tracking containers for tokenizer state, declare `TOO_LARGE_STRING_SIZE`, and sequence component parsing for `clang-tidy`.
Disable `query_plan_optimize_count_from_text_index` only where tests assert the virtual-column direct-read plan.
Give `FunctionsMultiStringSearch` a fixed return type under the default `Dynamic` adaptor, then normalize raw dynamic JSON haystacks to `String` for multi-needle text-index analysis.
Initialize analyzer-visible state, use the preferred string-view API, and make strict field conversion compare the complete type tree. ClickHouse#114613
Read and discard a partial-mark prefix before continuing with fallback columns after the upstream removal of the offset parameter. ClickHouse#114613
…actor::preparePath` The `jsonPathValues` tokenizer of a text index looked up every path of every row in a hash map, although with a few include paths almost none of them are visited. With only literal include paths, a path is visited only if it starts with an include path or an include path starts with it, which is cheaper to check. The index does not change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tokenizer Port the `jsonPathValues` text index onto the refactored text index reader: one map of postings streams, `range_posting` kept local to `buildPostingsForMark`, `fillColumnLazy` without the range posting, and the fallback reader called with `current_range_last_mark`. Keep the lossless-conversion unwrapping and the `JSON` index argument types from master next to the `jsonPathValues` matching. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nctions `IN` uses a `jsonPathValues` index only for `String`/`FixedString` paths, paths inside a typed non-`JSON` ancestor are not indexed, and `hasAnyTokens`/`hasAllTokens` do not use a `jsonPathValues` index. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…`createRegexp` with `similar_to` Master replaced `IDataType::forEachChild` with `getChildren` and the walkers in `DataTypes/TypeTree.h`, and added the `similar_to` parameter to `Regexps::createRegexp`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… `jsonPathValues` checks Master removed `MergeTreeIndexReader::patchSettings`, and `makeTextIndexInputStream` now takes the substream and applies its settings itself. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ionText.h` Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tokenizer # Conflicts: # docs/reference/engines/table-engines/mergetree-family/textindexes.mdx # src/Core/Settings.cpp # src/Functions/hasAnyAllTokens.cpp # src/Interpreters/convertFieldToType.cpp # src/Processors/QueryPlan/Optimizations/optimizeDirectReadFromTextIndex.cpp # src/Storages/MergeTree/MergeTreeIndexConditionText.cpp # src/Storages/MergeTree/MergeTreeIndexText.cpp
This was referenced Nov 2, 2026
…tokenizer Conflicts: - `textindexes.mdx`: kept master's rewritten posting list codec upgrade notes and the `jsonPathValues` serialization note. - `Settings.cpp`: kept master's link to `use_text_index_like_evaluation_by_dictionary_scan` in the `jsonPathValues` wording. - `MergeTreeIndexConditionText.h`/`.cpp`: kept both `JSONTextQueryPayload` and master's `TextIndexAutomatonBudget`; the `TextSearchQuery` constructor takes both, and JSON queries build no dictionary automata because their patterns match decoded values, not raw tokens. - `TextIndexAnalyzer.h`/`.cpp`: kept `queries_by_prefix` next to master's `pattern_cursors`; JSON queries disable dictionary DFA intersection so that prefix and decoded-value lookups are never skipped by a seek. - `MergeTreeIndexText.cpp`: pass `IndexDescription` (PR) together with master's `getMapSubcolumnShadowingCheck` and `automaton_budget`. - `MergeTreeReaderTextIndex.cpp`: kept both the JSON dynamic validation branch and master's phrase fallback branch. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
The `v3_with_tokenizer_config` value was not part of the 26.10 release. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
Contributor
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
The merge commit 1ebcf77 recorded the submodule pointers of the branch from before the merge for 32 submodules (`llvm-project`, `boost`, `aws`, `grpc`, ...), so the PR diff reverted their updates on `master`. Set them back to the commits of the merged `master` (0a399a7). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
…n they need validation `getFoldedPostings`, added on `master` by ClickHouse#122896, fills a virtual column from the postings folded during index analysis. It did not know two properties of `jsonPathValues` queries: - A prefix lookup (`startsWith`, `LIKE 'abc%'`, key existence) has neither tokens nor patterns: its tokens are collected from the dictionary by `pattern_token_prefixes`. Such a query was answered with empty postings, so it matched no row. - A query with dynamic fallback (e.g. `endsWith` over truncated values) has folded postings that also hold the candidate rows that still have to be validated on the column. They were taken as the result, so unvalidated rows matched. Check `hasPatternLookup` as `classifyVirtualColumns` and `buildPostingsForMark` already do, and do not use folded postings for columns with dynamic fallback. Fixes the `Fast test` failures of `04839_json_path_values_core`, `04840_json_path_values_dynamic`, `04841_json_path_values_patterns`, `04842_json_path_values_collections`, `04856_json_path_values_subcolumns` and `04866_json_path_values_regressions`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=114613&sha=df313397ce1ec1fa96b1c82f0ad3e87768aed83b&name_0=PR&name_1=Fast%20test ClickHouse#114613 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
`IMergeTreeReader::readRows` takes a `shared_columns` argument since ClickHouse#124449: a column served from the columns cache comes back there instead of in `res_columns`. The per-mark reads of the `jsonPathValues` dynamic fallback in `MergeTreeReaderTextIndex` still used the old signature, so the build failed after merging `master`. Pass the shared columns and take a column from them when the reader did not fill the mutable one, as the whole-range fallback read above already does. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=114613&sha=e6b2c2eaa9444798c6f6f290531d55938446fd86&name_0=PR&name_1=Build%20(arm_tidy%2C%203%2F4) PR: ClickHouse#114613 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
…ions ClickHouse#122144 replaced the set of column names shadowing Map key subcolumns with the `IsShadowingColumn` callback `is_column_shadowing_map_subcolumn`, so `tryMatchJSONPathValuesNode` no longer compiled after merging `master`. The callback answers for any column or regular subcolumn of the table, while the set held only names shaped like `<map>.key_<k>`. Asking it about every predicate node would refuse typed JSON paths such as `j.a`, so restore `looksLikeMapSubcolumnName` (removed from `master` as unused) and ask the callback only about names of that shape, as `tryParseMapSubcolumnName` does. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=114613&sha=e6b2c2eaa9444798c6f6f290531d55938446fd86&name_0=PR&name_1=Fast%20test PR: ClickHouse#114613 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
…tokenizer Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
The dictionary scan matches tokens with a caseless `OptimizedRegularExpression`, which folds ASCII case only, while `ilike` folds the whole of UTF-8. A row with `Äpfel` was lost for `ILIKE '%äpf%'` and `ILIKE 'äpf%'`. Apply the same guard as `stringLikeToPatterns` and leave such patterns to the predicate. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
`IDataType::equals` treats `UInt8` and `Bool` as equal, so `CAST(data.u, 'Bool')` over `LowCardinality(UInt8)` was treated as transparent and `= true` looked up only the stored value `1`, losing rows with `2`. Require the same type name. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
The token of a `Variant` value holds only its text, so the numeric `42` and the string `'42'` give the same token, and an empty string element gives none. Exact reads of `has` over `Array(Variant(...))` returned rows of the wrong alternative and lost rows with empty strings. Treat `Variant` as having no stable serialization, which declines scalar equality and `has` over such paths. The fallback expression of an exact direct read rebuilt constants as `CAST(<Field>, '<type>')`. A `Field` does not keep the alternative of a `Variant` or the type of a `Dynamic` value, so `CAST(42, 'Variant(String, UInt64)')` threw `CANNOT_CONVERT_TYPE`. Skip the direct read when such a constant is involved. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
Compares results with and without the index for non-ASCII `ilike`, `CAST` to `Bool`, `Variant` constants, and `has` over `Array(Variant(...))`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
…he weight Each cached header keeps its own source type name, path filters and compiled regexps, but `TextIndexHeaderWeightFunction` charged only the sparse index. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
…tting The `jsonPathValues` tokenizer introduces a new persisted token encoding and text index header version together with exact reads, so creating such an index now requires the MergeTree setting `allow_experimental_text_index_json_path_values`, like `support_phrase_search` requires `allow_experimental_text_index_phrase_search`. The check is skipped on attach so that existing tables still load. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #113376
Related: #110757
I first tried to fix the edge cases between
JSONAllValuesand the text index. I kept finding more cases where the index could return an incorrect result. I therefore needed to disable more useful index paths to keep queries correct. The main problem is thatJSONAllValuesstores plain text. It does not retain the path or type of values fromDynamicJSON columns. PR #113376 documents several examples.A tokenizer made specifically for
JSONseemed like a better fit. The newjsonPathValuestokenizer stores the JSON path, type, and value in each token. This gives the index enough information for safe typed comparisons.The path-value format also enables direct reads. This part was inspired by ClickStack's use of text-index direct reads for dynamic map attributes.
jsonPathValuesbrings this model directly toJSONcolumns. It does not require user-defined alias columns or query rewrites. Long values use a bounded prefix and a hash. ClickHouse validates candidate rows when a token is truncated or a runtime type is unsafe. This prevents false-negative results.The tokenizer supports declared and dynamic paths, arrays, scalar leaves in
Array(JSON), and declaredMap(String, String)paths. It supports equality,INon declaredStringsubcolumns,has, map lookups, prefix and suffix searches,LIKE,ILIKE, regular expressions, and multi-search functions.Named
include_paths,include_paths_regexp,skip_paths, andskip_paths_regexparguments can restrict indexing to useful JSON paths; namedmax_token_bytesis also supported. Every part stores its own tokenizer configuration, so parts built with different filters are evaluated independently and incompatible parts fall back to source-row reads. Structural[]fromArray(JSON)is distinct from escaped literal square brackets in a JSON path.\n\nstartsWithuses an ordered dictionary lookup, so it does not require a full dictionary scan. Substring searches still scan the dictionary.Benchmark
We tested
jsonPathValues(1024)with 99,999,984 distinct events from 100 JSONBench files. Both target tables had the same 192-part layout. Each indexed query returned the same result as the query without an index.jsonPathValues(1024)cidlookupstartsWithLIKEThe index used 14.19 GiB, or approximately 152 bytes per JSON object. It made the table 2.53 times larger and made index construction 4.03 times slower.
The exact lookups were 80 to 148 times faster.
startsWithwas 1.81 times faster. Query times are medians from ten warm runs.The
jsonPathValuestokenizer is experimental: creating a text index with it requires the MergeTree settingallow_experimental_text_index_json_path_values = 1.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add the
jsonPathValuestokenizer for bounded, type-safe, selectively filtered text indexes onJSONpaths, arrays, and maps.Workflow [PR]
Sync PR [sync-upstream/pr/114613]