Repository navigation
Respect validate_enum_literals_in_operators in index analysis and notEquals - #122672
Conversation
…n `notEquals` With the setting off, comparing an `Enum` column with a string literal that names none of its elements must not throw: `equals` is false and `notEquals` is true for every row. Three paths ignored that. `KeyCondition` converted the literal to the key type and threw `UNKNOWN_ELEMENT_OF_ENUM` whenever the enum column was part of the primary or partition key. It now folds `equals` to `ALWAYS_FALSE` and `notEquals` to `ALWAYS_TRUE`, declines the other operators, and reads the setting once in the constructor. The `bloom_filter` skip index did the same conversion in `traverseTreeEquals`. `equals` now folds to `ALWAYS_FALSE` there, including the `arrayJoin(col) = const` form. The operator guard in `executeWithConstString` was inverted, so `notEquals` fell through to the throwing conversion while the ordering operators silently returned false. Only `equals` and `notEquals` take the shortcut now; `<`, `<=`, `>`, `>=` against an unknown element keep throwing. Add `isUnknownEnumElement` to `DataTypeEnum`, shared by both index paths. Closes: #122235 Closes: #111545 Related: #121723 Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Workflow [PR], commit [a52b196] Summary: ✅
AI ReviewSummaryThis PR fixes the Findings
Final Verdict
LLVM Coverage ReportMeasured on commit a52b196.
Changed lines: Changed C/C++ lines covered: 51/55 (92.73%) · Uncovered code |
|
|
||
| /// With validation off, `equals` against a name the enum lacks is constant false for every row, | ||
| /// so the conversion below must not throw; `KeyCondition` folds the same way. | ||
| if (function_name == "equals" && !validate_enum_literals_in_operators && isUnknownEnumElement(*actual_type, value_field)) |
There was a problem hiding this comment.
equals is now guarded, but the other bloom_filter derivations from #111545 still feed the missing enum label into a throwing conversion. has(arr, 'c') goes through convertConstantForArrayIndexFunction at 1040, hasAny/hasAll go through createColumnFromConstantArray at 1067, and mapContains* reaches the same conversion at 1184. With validate_enum_literals_in_operators = 0, the runtime functions already tolerate an unknown label (for example tests/queries/0_stateless/02893_array_enum_has_hasAny.sql expects has(value, 'x') to return no rows, not throw), so a table-level bloom_filter index still changes those queries back into UNKNOWN_ELEMENT_OF_ENUM. If this PR is closing #111545, these carriers need the same setting-aware fold/skip logic and coverage too.
There was a problem hiding this comment.
Show repro which current patch does not cover
There was a problem hiding this comment.
Concrete repro on the current PR head:
DROP TABLE IF EXISTS t_enum_bf_has;
CREATE TABLE t_enum_bf_has
(
arr Array(Enum8('a' = 1, 'b' = 2)),
INDEX bf_arr arr TYPE bloom_filter GRANULARITY 1
)
ENGINE = MergeTree
ORDER BY tuple()
SETTINGS index_granularity = 1, index_granularity_bytes = 0, min_bytes_for_wide_part = 0;
INSERT INTO t_enum_bf_has VALUES (['a']), (['b']);
SELECT count() FROM t_enum_bf_has WHERE has(arr, 'missing')
SETTINGS validate_enum_literals_in_operators = 0, use_skip_indexes = 0; -- 0
SELECT count() FROM t_enum_bf_has WHERE has(arr, 'missing')
SETTINGS validate_enum_literals_in_operators = 0, use_skip_indexes = 1; -- Code: 691The runtime contract is already covered by tests/queries/0_stateless/02893_array_enum_has_hasAny.sql:8, which expects has(Array(Enum), 'x') to return no rows. The index path still reaches convertConstantForArrayIndexFunction at src/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp:1040, so it calls convertFieldToType(... Enum ...) and throws before scan fallback can happen. The same untouched conversion is also reused by hasAny/hasAll at 1067 and by mapContains* / has(map, ...) at 1185.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units560 translation units recompiled, 4876 s compile time in total, 560 of them have a recent master baseline. |
Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
@nihalzp feel free to review whenever you have a chance |
Cherry pick #122672 to 26.7: Respect validate_enum_literals_in_operators in index analysis and notEquals
… in index analysis and notEquals
Cherry pick #122672 to 26.8: Respect validate_enum_literals_in_operators in index analysis and notEquals
… in index analysis and notEquals
Backport #122672 to 26.9: Respect validate_enum_literals_in_operators in index analysis and notEquals
Backport #122672 to 26.7: Respect validate_enum_literals_in_operators in index analysis and notEquals
|
@vdimir the 26.7 backport (#124247, merged) and the open 26.8 one (#124276) fail 26.7 and 26.8 predate #116544, so The client stops at that statement, so the rest of the file has not run on those branches yet. One more difference there: they also predate #117803, which adds For 26.7/26.8, do you prefer (a) extending that bloom filter guard to |
…_operators in index analysis and notEquals
Backport #122672 to 26.8: Respect validate_enum_literals_in_operators in index analysis and notEquals
The row pinned `CAST('a', 'Enum8(\'a\' = 1)') < 'zz'` at 0 to show this
change leaves Enum targets alone. Since ClickHouse#122672 master rejects a
non-member literal in an ordering comparison with
UNKNOWN_ELEMENT_OF_ENUM before the conversion this change touches, so
the row can no longer reach that code and master's own
05243_enum_unknown_literal_key_condition covers the new behaviour.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #122235
Closes: #111545
Related: #121723
With
validate_enum_literals_in_operators = 0,enum_col = 'unknown'is false andenum_col != 'unknown'is true for every row, but three paths still threwUNKNOWN_ELEMENT_OF_ENUM:KeyConditionconverted the literal to the key type whenever the enum column was in the primary or partition key, so the same query failed only on key columns; thebloom_filterskip index did the same conversion; and an inverted guard inexecuteWithConstStringmadenotEqualsthrow while the ordering operators silently returned false.KeyConditionand the bloom filter now fold such comparisons to constants, andnotEqualstakes the same shortcut asequals.<,<=,>,>=against an unknown element keep throwing, as there is no position to compare against.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Comparing an
Enumcolumn with a string literal that is not one of its elements no longer throwsUNKNOWN_ELEMENT_OF_ENUMwhenvalidate_enum_literals_in_operatorsis disabled (the default) and the column is part of the primary key, the partition key, or abloom_filterindex.!=with such a literal now returns true for every row instead of throwing. Closes #122235, #111545.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122672]
Version info
26.10.1.1266-master(included in26.10and later)26.9.12.10,26.8.22.14,26.7.25.7