Repository navigation
Do not raise "Inconsistent KeyCondition behavior" when the index lacks key columns - #111964
Conversation
…s key columns
`MergeTreeDataSelectExecutor::markRangesFromPKRange` throws the debug-only
`Inconsistent KeyCondition behavior` logical error when `matchesExactContinuousRange`
reports that the filter describes one continuous key range, yet the exact mark range
computed by the binary search still contains rows the filter rejects.
That check silently assumes the in-memory primary index resolves every key column the
filter references. A part can keep only a prefix of the key in memory - see the
`MergeTree` setting `primary_key_ratio_of_unique_prefix_values_to_skip_suffix_columns`
- and the key columns beyond that prefix are then analysed as constant coordinates
over the whole universe, or over the part's partition minmax bound, rather than from
per-mark values. A granule strictly inside the binary-search boundary can therefore
legitimately hold rows the filter rejects even though the condition itself really does
describe one continuous key range. The assertion fires on a plain
`WHERE a = 5 AND b = 3`, with no monotonic function and no reverse-sorted key column
involved:
CREATE TABLE t (a UInt16, b UInt16, c UInt16) ENGINE = MergeTree ORDER BY (a, b, c)
SETTINGS index_granularity = 4,
primary_key_ratio_of_unique_prefix_values_to_skip_suffix_columns = 0.01;
INSERT INTO t SELECT intDiv(number, 100), intDiv(number % 100, 10), number % 10 FROM numbers(1000);
SELECT count() FROM t WHERE a = 5 AND b = 3; -- SIGABRT on a debug build
Only `a` is kept in memory, so the binary search returns the marks for `a = 5`, and the
granules inside that boundary do contain rows with `b != 3`.
Restrict the check to the case where the in-memory index resolved the whole used key
prefix. It keeps firing for the widening-cast manifestation of #90461, which is what it
is actually catching in CI. Release builds are unaffected: the exact range is dropped
there already, and that is the correct outcome here too.
CI reports for this failure (`Logical error: Inconsistent KeyCondition behavior`,
STID 5182-2f27). The first one is the manifestation fixed here - its participating
conditions are `(column 0 in [5, 5]), (column 1 in [3, 3]), and, (column 0 in (-Inf, 100])`,
with no cast - while the other three are the widening-cast class already addressed by
#109023:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=b59441bd06c2fcb6b103a30874528cc398afc723&name_0=MasterCI&name_1=Stress%20test%20%28arm_debug%29&name_1=Stress%20test%20%28arm_debug%29
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=859a9abe2597d0c2c26b898066a32a375ea6b62f&name_0=MasterCI&name_1=Stress%20test%20%28arm_debug%29&name_1=Stress%20test%20%28arm_debug%29
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=10116111a8db9ece9c215d65d7afa38d9f02ebdf&name_0=MasterCI&name_1=Stress%20test%20%28arm_debug%29&name_1=Stress%20test%20%28arm_debug%29
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=e7b490a6a1e7b00ceb20d0b23ba43fc64fca87d4&name_0=MasterCI&name_1=Stress%20test%20%28amd_debug%29&name_1=Stress%20test%20%28amd_debug%29
Related: #90461
Related: #109023
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [491a805] Summary: ✅
AI ReviewSummaryThis PR narrows the debug-only exact-range consistency check in Final Verdict✅ No blocking issues found. |
|
The only red job,
The Also merged |
|
The single red job on the previous commit,
with the key condition The fix for that class, #109023, has since merged, so I merged |
|
The only red job, Related: #110518 Nothing in this PR touches parallel replicas — it only narrows a debug-only assertion in |
|
It has not stalled, and your PR's red is the exact case it fixes. #111689 is approved (by you, on 2026-07-28) and On your job: the aborting query in that run is So #111689 is the fixing PR for this red, not just for the issue. The signature is still live on |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 2/2 (100.00%) · Uncovered code |
Pull in the master fixes for the two unrelated CI failures on the previous head: - ClickHouse#111991: fix test 04627_analyzer_compatibility_final_all_joined_tables with old analyzer - ClickHouse#109023 / ClickHouse#111964: fix logical error `Inconsistent KeyCondition behavior` CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=102194&sha=5086241c961abbe0a7cb89990fa1a0fee4c4939e&name_0=PR PR: ClickHouse#102194 Co-Authored-By: Claude Fable 5 <[email protected]>
Related: #90461
Related: #109023
Related: #111421
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Fixes one manifestation of the recurring debug-only
Inconsistent KeyCondition behaviorlogical error (Logical error: Inconsistent KeyCondition behavior, STID 5182-2f27) thrown fromMergeTreeDataSelectExecutor::markRangesFromPKRange.Root cause
The check fires when
KeyCondition::matchesExactContinuousRangereports that the filter describes one continuous key range, yet the exact mark range computed by the binary search still contains rows the filter rejects.It silently assumes the in-memory primary index resolves every key column the filter references. A part can keep only a prefix of the key in memory - see the
MergeTreesettingprimary_key_ratio_of_unique_prefix_values_to_skip_suffix_columns- and the key columns beyond that prefix are then analysed as constant coordinates over the whole universe, or over the part's partition minmax bound, instead of from per-mark values. A granule strictly inside the binary-search boundary can therefore legitimately hold rows the filter rejects even though the condition itself really does describe one continuous key range.No monotonic function and no reverse-sorted key column are needed - a plain
WHERE a = 5 AND b = 3aborts a debug build:Only
ais kept in memory, so the binary search returns the marks coveringa = 5, and the granules inside that boundary do contain rows withb != 3.The fix
Restrict the check to the case where the in-memory index resolved the whole used key prefix (
used_key_prefix_size <= index->size()). Where it does not, the exact range is dropped, exactly as a release build already does - which is the correct outcome, since exactness genuinely cannot be proven from a truncated index.Release builds are unaffected: the check is compiled out under
NDEBUG, and the results were already correct there.Relationship to #109023
These are two distinct root causes behind the same assertion, and both are needed.
Of the four CI reports below, the first is the manifestation fixed here - its participating conditions are
(column 0 in [5, 5]), (column 1 in [3, 3]), and, (column 0 in (-Inf, 100]), with no cast. The other three are the widening-cast class ((_CAST(column 0) in ['5', '5'])), which #109023 fixes by demotingPOINTtoRANGEfor a non-empty monotonic-function chain; that change cannot help here, because the chain is empty.I sampled 15 further recent failures of this STID from CIDB: all 15 are the widening-cast class, so #109023 remains the high-volume fix. This PR does not touch it, and the canary still fires for that class after this change (verified on a debug build).
Not a regression from #111059
The stress-test hit rate for this STID jumped from ~1-3/day to 45 on 2026-07-24, the day #111059 merged, because the tables added by
04612_reverse_key_index_analysis.sqlgave the AST fuzzer the right material to mutate. The underlying interaction is long-standing and independent of reverse-sorted keys: the minimal reproducer above uses an ascending key. The only pre-existing test using this setting,02998_primary_key_skip_columns.sql, uses range conditions only - which never reach the exact-range path - and is taggedno-debug.Testing
New test
04647_exact_range_unloaded_key_columns.sql, which asserts its own premise by comparingprimary_key_bytes_in_memoryagainst an identically shaped table without the setting.masterserver at its first query (clickhouse-testreportsClickHouse server died); passes with this change.primary_key/key_condition/index_analysis/exact_range/implicit_projection/minmaxrun against both this branch and unmodifiedmasteron the same local server config: identical sets of 47 environment-related failures, no differences.-DNDEBUG -Wunused-variable.CI reports
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=b59441bd06c2fcb6b103a30874528cc398afc723&name_0=MasterCI&name_1=Stress%20test%20%28arm_debug%29&name_1=Stress%20test%20%28arm_debug%29
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=859a9abe2597d0c2c26b898066a32a375ea6b62f&name_0=MasterCI&name_1=Stress%20test%20%28arm_debug%29&name_1=Stress%20test%20%28arm_debug%29
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=10116111a8db9ece9c215d65d7afa38d9f02ebdf&name_0=MasterCI&name_1=Stress%20test%20%28arm_debug%29&name_1=Stress%20test%20%28arm_debug%29
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=e7b490a6a1e7b00ceb20d0b23ba43fc64fca87d4&name_0=MasterCI&name_1=Stress%20test%20%28amd_debug%29&name_1=Stress%20test%20%28amd_debug%29
Documentation entry for user-facing changes
🤖 Generated with Claude Code
Version info
26.8.1.526(included in26.8and later)