Repository navigation
Conversation
A text index on mapKeys(m) / mapValues(m) was used for m['key'] = 'value'
but not for m[CAST('key' AS Nullable(String))] = 'value'. The Nullable
wrapper makes arrayElement return Nullable(String) and the comparison return
Nullable(UInt8), and the map-element analysis rejected both, falling back to
a full scan.
Strip the Nullable wrapper in the map-element key and value analysis. This is
safe for a non-NULL constant key: arrayElement returns the value-type default
(empty string) for an absent key, not NULL, so the pruning invariant holds. A
NULL key still declines the mapKeys path.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-5:20260710-162000 |
|
cc @CurtizJ @ahmadov — could you review? Small fix in the text-index map-element condition analysis ( |
|
Workflow [PR], commit [524edc2] Summary: ❌
AI ReviewSummaryThis PR extends Final VerdictStatus: ✅ Approve LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 32/35 (91.43%) · Uncovered code |
|
@groeneai look LowCardinality case and LowCardinality(Nullable) case too. |
Extend the map-element key analysis in MergeTreeIndexConditionText to also
strip LowCardinality and LowCardinality(Nullable) wrappers on the constant
key, not just Nullable. Previously m[CAST('key' AS LowCardinality(String))]
and m[CAST('key' AS LowCardinality(Nullable(String)))] failed the mapKeys
type gate (removeNullable does not strip LowCardinality), so the text index
on mapKeys(m) was not used and the query fell back to a full scan. Use
removeLowCardinalityAndNullable at the type gates and recursiveRemoveLowCardinality
on the key column before reading its value.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Done in d802e70. The map-element key gates now use `removeLowCardinalityAndNullable` (not just `removeNullable`) and `recursiveRemoveLowCardinality` on the key column, so `m[CAST('key' AS LowCardinality(String))]` and `m[CAST('key' AS LowCardinality(Nullable(String)))]` now use the mapKeys text index. Note: a constant-folded key (e.g. a literal cast) is rewritten to a map subcolumn reference and already pruned. The gap was only on the non-folded path ( |
Only see through a CAST on the map element value when it reduces to the same base type after stripping LowCardinality/Nullable. A byte-changing cast (e.g. FixedString(N), which pads with trailing zero bytes) would make hasIndexForMapElementValue search the mapValues text index for a token that differs from the raw String stored in the index, wrongly pruning a matching granule. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Fixed in 0beac82. Confirmed both directions on a debug build:
Added a focused regression to |
…able-map-key-110018
The idx_vals name appears both in the Prewhere filter column and the index Name line of EXPLAIN indexes=1 output on current master, so an exact count() on lines mentioning idx_vals is fragile. Use count() > 0 (is the index used?) which is what the assertions actually check. Co-Authored-By: Claude Opus 4.8 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 32/35 (91.43%) · Uncovered code |
CI finish ledger — 99ea083Every failure below has an owner (a fixing PR or a full-effort fix task). Only
Prior-SHA-only failures (0beac82), already fixed on 99ea083 by the reference/EXPLAIN-assertion fix: Session id: cron:our-pr-ci-monitor:20260711-023000 |
|
@PedroTadim Could you please ping the text index team for Groene fixes in the text index area? The LLM tends to produce sloppy and overly verbose code which we should check before integrating into the codebase. Thanks! |
Ok, maybe I should flag the text index team first, then let them decide whether to request groeneai? |
|
It's totally fine if you say "fix" at Groene (you don't need to wait). Just make sure that the resulting PR gets some eyes by someone familiar with the code (tagging colleagues is enough). Thanks. |
|
Another Groene PR that adds lots of new code to support a questionable use case. I'll look at it when I find some time (haven't done anything else but reviewing Groene PRs today). @groeneai Please don't push new commits |
|
@rschu1ze understood, no further commits - it is yours to review when you have time. Re the automated review re-surfacing on the |
…able-map-key-110018
CI finish ledger — 524edc2CI is fully finished on this head (174 check-runs, 0 incomplete,
The The other 172 checks are green. Session id: cron:our-pr-ci-monitor:20260803-220000 |
|
Dear @rschu1ze, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
Superseded by #120220. |
`RPNBuilderTreeNode::tryGetConstant` now returns the type of the value
the constant holds: `LowCardinality` is removed, and `Nullable` is
removed when the value is not NULL. A `Field` is the plain value, so
every consumer of `tryGetConstant` (`KeyCondition`, the text index, the
bloom filter indexes, the selectivity estimator) sees `String` for
`toLowCardinality('x')` and `CAST('x', 'LowCardinality(Nullable(String))')`.
The per-consumer stripping added by ClickHouse#110017
in `MergeTreeIndexConditionText` and `MergeTreeConditionBloomFilterText`
is removed, together with the special case that made a `LowCardinality`
`hasToken` needle with a separator behave differently from a `String` one.
`MergeTreeIndexConditionText::traverseMapElementKeyNode` accepts a
predicate result of `Nullable(UInt8)` or `LowCardinality(UInt8)`, which a
`Nullable` map key produces; NULL reads as false, as in WHERE. The
constant key is read through `tryGetConstant` instead of unwrapping the
column by hand. This supersedes ClickHouse#110031.
The absent-key guards in `MergeTreeConditionBloomFilterText` compare the
constant with its `FixedString` padding stripped. `FixedString` reports
'' as its default while the constant holds N zero bytes, so
`m['missing'] = CAST('', 'FixedString(N)')` used the `mapKeys` index and
returned no rows instead of all rows.
`RPNBuilderTreeNode` holds a const reference to the tree context, so a
node can be built from a const function node.
Closes: ClickHouse#110018
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A text index defined on
mapKeys(m)/mapValues(m)is now used form[key] = valuewhen the constant map key is wrapped inNullable(e.g.m[CAST('key' AS Nullable(String))]), instead of falling back to a full scan.Description
Closes #110018.
A text index on
mapKeys(m)/mapValues(m)was used forWHERE m['key'] = 'value'but not for the semantically equivalentWHERE m[CAST('key' AS Nullable(String))] = 'value'. TheNullablewrapper makesarrayElementreturnNullable(String)and the comparison returnNullable(UInt8), and the map-element analysis in the text index condition rejected both types.Fix: strip the
Nullablewrapper in the map-element key/value analysis (MergeTreeIndexConditionText), mirroring what the JSON-subcolumn path already does. This is safe for a non-NULL constant key:arrayElement(m, key)returns the value-type default (empty string) for an absent key, notNULL, so the "predicate is false on the default value" invariant the map-element optimization relies on still holds. ANULLconstant key still declines themapKeyspath (it would break the invariant); the value index remains a safe over-approximation there.Verified with
EXPLAIN indexes = 1: both themapKeysandmapValuesindexes now prune granules (2/128) for a Nullable (andLowCardinality(Nullable)) constant key, matching the plain-key behaviour. Regression test:02346_text_index_bug110018.