Repository navigation
Regression test for KeyCondition over a LowCardinality key exposed through Merge - #110326
Conversation
…ough Merge
KeyCondition::applyFunction executed a monotonic key function on the raw
index column while the function was resolved against the plain key type.
When a Merge table declares a plain header (e.g. UInt32) over a source
whose key column is LowCardinality(UInt32), the index column loaded from
the child part is LowCardinality but the function expects the plain type,
so the function received a LowCardinality column dispatched as its plain
type and threw a LOGICAL_ERROR ("Arguments of 'minus' have incorrect data
types") during primary-key index analysis - a server abort in debug and
sanitizer builds.
Strip LowCardinality from the argument column and its type in lockstep
before executing, mirroring the sibling applyFunctionChainToColumn which
already does convertToFullColumnIfLowCardinality + removeLowCardinality.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260713-222100 |
|
cc @CurtizJ @KochetovNicolai — could you review this? It fixes a LOGICAL_ERROR during primary-key index analysis: |
|
Workflow [PR], commit [cc7850f] Summary: ✅ AI ReviewSummaryThis PR is now a test-only addition for the Final VerdictStatus: ✅ Approve |
…e caller The sparse primary-key analysis path forwarded the raw key type (sparse_data_types[sparse_pos]) into applyMonotonicFunctionsChainToRange, while the monotonic function chain is built in extractAtomFromTree against a LowCardinality-stripped key type. When a key column is analysed as a partition-minmax constant coordinate over a LowCardinality source (e.g. a Merge table whose header declares the plain type), the explicit-field applyFunctionForField built a LowCardinality const column against a chain prepared on the plain type. With a CAST wrapper the dictionary-unpack step is elided and the inner cast wrapper rejects the LowCardinality column with a Bad cast LOGICAL_ERROR (server abort in debug/sanitizer builds). Strip LowCardinality here too, mirroring the dense checkInHyperrectangle caller. Regression test extended with the sparse constant-coordinate path. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…tion site extractAtomFromTree builds the monotonic function chain against recursiveRemoveLowCardinality(key_column_type), but the applyFunction cache-miss branch stripped only a top-level LowCardinality wrapper. A Merge table with a plain Array(T) header over a child Array(LowCardinality(T)) then leaves the argument type plain while the column is a ColumnArray whose nested data is ColumnLowCardinality, diverging from the type the chain was built on. Use recursiveRemoveLowCardinality for both the column and its type so nested LowCardinality is unwrapped in lockstep. Extend the Merge regression with an Array(LowCardinality(T)) key exposed through a plain Array(T) header.
…field path The monotonic function chain loop in applyMonotonicFunctionsChainToRange propagates current_type = result_type, so an intermediate function that returns LowCardinality (e.g. toLowCardinality) reverts the running type to LowCardinality even though the caller passed the recursively-stripped key type. On the partition-minmax constant-coordinate (explicit field) path this reached applyFunctionForField with a LowCardinality arg_type, building a LowCardinality const column that the next function (a Bool CAST wrapper) rejected with a Bad cast (ColumnLowCardinality to ColumnVector<char8_t>) LOGICAL_ERROR during PK/partition index analysis (server abort in debug/sanitizer builds). Strip LowCardinality recursively in applyFunctionForField, mirroring the cached branch of applyFunction. Found by AST fuzzer (STID 1499-6033) on this PR's own regression test. Co-Authored-By: Claude Opus 4.8 <[email protected]>
CI finish ledger — 5de1d6cCI is fully finished on this head (Finish Workflow + Mergeable Check + PR all green). Every failure has an owner.
Session id: cron:our-pr-ci-monitor:20260714-110000 |
CI finish ledger — 5de1d6cCI is fully finished and clean. No test failures.
Session id: cron:our-pr-ci-monitor:20260715-053000 |
…ey-over-merge Reconcile the KeyCondition::applyFunction cache-miss LowCardinality strip with the sibling fix from ClickHouse#110006 (merged): keep the recursive strip (covers nested Array(LowCardinality(T))) for the input column and type, and keep ClickHouse#110006's result hardening (removeLowCardinality on the result type + convertToFullColumnIfLowCardinality on the result column). applyFunctionForField and the sparse checkInHyperrectangle caller retain their recursive strips.
CI finish ledger — 929e3be (merge-resolution head)CI is complete on this head (Finish Workflow + Config Workflow pass; Mergeable/PR reflect the one failure below). This ledger covers the new head after the master merge-conflict resolution; the prior ledger (issuecomment-4968486612) covered
Session id: cron:our-pr-ci-monitor:20260720-180000 |
|
Fixing PR for the |
CI finish ledger - 71c512bEvery failure below has an owner: a fixing PR, or a full-effort fix task whose
Session id: cron:our-pr-ci-monitor:20260729-083000 |
A monotonic key function is resolved against the previous chain link's result
type, while applyMonotonicFunctionsChainToRange propagates
current_type = result_type and the caller passes a recursively-stripped key
type. The running type and the type a link was built against can therefore
disagree over LowCardinality in either direction. FunctionCast keeps
useDefaultImplementationForLowCardinalityColumns = false and its wrapper casts
the column to the declared argument type, so either disagreement is a bad cast
and throws a LOGICAL_ERROR exception, which terminates debug and sanitizer
builds.
Align both execution sites with the declared argument type, guarded by equality
once LowCardinality is removed so only LowCardinality-ness is ever adjusted and
never the value type:
- applyFunctionForField (explicit-field path) builds the const column against
the declared type.
- the applyFunction cache-miss branch strips column and type in lockstep and
then restores the declared representation. Stripping must be recursive: a
top-level lowCardinality() check misses a nested Array(LowCardinality(T))
under a plain Array(T) Merge header.
Measured against an ENGINE = Memory twin as the oracle, on a Merge table with a
plain Bool header over a LowCardinality(Bool) key source. A one-directional
strip is not sufficient: CAST(toLowCardinality(b), 'UInt64') > 0 threw
Bad cast ColumnVector<char8_t> -> ColumnLowCardinality, while reverting the
strip instead threw for
toLowCardinality(b) > toNullable(toLowCardinality(false)) in the opposite
direction. Both directions pass after aligning.
The regression test asserts the previously throwing cases and pins pruning for
the dense, sparse and nested-Array carriers.
Closes: ClickHouse#109699.
CI finish ledger — a9799c4Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260729-103000 |
The three CREATE TABLE statements that pin index_granularity_bytes = 0 kept the default min_bytes_for_wide_part = 10485760, so MergeTreeData logged a warning at CREATE time for each of them: Table can't create parts with adaptive granularity, but settings min_rows_for_wide_part = 0, min_bytes_for_wide_part = 10485760. ... will be ignored. clickhouse-test runs with send_logs_level=warning and fails any test whose stderr is non-empty, so the warning alone reddened Fast test with "Reason: having stderror" while stdout already matched the reference exactly. Fast test does not install tests/config/config.d/polymorphic_parts.xml (that symlink is gated on USE_POLYMORPHIC_PARTS), which is why the setting keeps its non-zero default there. Setting min_bytes_for_wide_part = 0 on those three tables cannot change the part layout: with adaptive granularity off, MergeTreeData::choosePartFormat returns Wide/Full before it reads either wide-part threshold, which is exactly what the warning means by "will be ignored". Verified locally that the part type, part count and mark count are unchanged, that stderr goes from 471 bytes to 0, and that the test's stdout is byte-identical to the reference.
CI finish ledger - e1e384bEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
STID 5217-5b3d over 30 days: 118 hits across 104 distinct PRs including 9 on master, so it is Session id: cron:our-pr-ci-monitor:20260729-203000 |
|
Following up on the CI finish ledger: the fixing PR for the Root cause is not in this PR's diff. That suite set its embedded Keeper's maximum session |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 31/31 (100.00%) · Uncovered code |
CI finish ledger - 9864ff3Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260801-230000 |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
…dition-lowcardinality-key-over-merge Resolved the conflict in `src/Storages/MergeTree/KeyCondition.cpp` by taking `master`'s version wholesale, which makes this pull request test-only. `master` already normalizes the chain's input type inside `applyMonotonicFunctionsChainToRange` (ClickHouse#111050), and ClickHouse#117054 reworked the sparse `checkInHyperrectangle` site that this branch had edited so that it always goes through that helper. Every branch this pull request added to `KeyCondition.cpp` was measured on the previous merge base to change no statement outcome of the regression test, and the review thread asked to either drop the hunks or guard them; dropping them is the accurate resolution. Co-Authored-By: Claude Fable 5.1 <[email protected]>
The pull request is test-only now, so the comment must not speak of "this fix". Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 Merged Verified locally on the merged tree: |
|
🕵 Pass 2026-09-13 (head The only red is @groeneai, investigate the failure: https://github.com/ClickHouse/clickhouse-private/actions/runs/34762093395/job/103737190142 ( |
|
The accounting fix for the mechanism that produces this exact message is already open: #111925. It is still needed on master: I cannot open the job you linked: my account gets 404 on Public CI gives me no signal for this occurrence. Over the last 30 days this test has 0 failures in 12,399 recorded runs of There is one hole in the test that I can close without the log. Separate pull request from me: pin If the private artifacts show the expired part was never dropped long after the test finished, then the cause is the leaked slot rather than the pool limit, and #111925 is the fix for it. |
|
Opened #119884 for the |
…dition-lowcardinality-key-over-merge
…ion` over `Merge` test Address review: through `Merge` the array `CAST` keeps this query off the `applyFunction` path (confirmed earlier with an instrumented binary: the recursive-strip branch it was written for never fires), and with only `count()` as the oracle a full scan or a declined chain passes too. The direct `Array(LowCardinality(...))` arithmetic case is already covered by `04141_array_lowcard_arithmetic_monotonicity`, so the block added no regression coverage. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Four sentences prescribed a repair that master did not take, so they read against the code a reader would go on to open. `applyMonotonicFunctionsChainToRange` normalizes the chain's seed type (`KeyCondition.cpp:5599-5601`) instead of each caller, `applyFunctionForField` builds its const column on the running type it is handed (`:1627`, `:1607-1619`), and the cached branch normalizes the chain's input only, deliberately keeping every interior link's own result representation (`:1650-1662`). State that invariant instead. The scenarios, the statements and the reference are unchanged. Co-Authored-By: Claude Opus 5 <[email protected]>
…pins Both OR arms asked for `b = 1`, so partition pruning removed the other partition before primary-key analysis ran, and the granule line read `52/500` whether or not the constant-coordinate bound on `b` was used, and whether or not the chain was applied at all. The setting the statement pins was inert. Ask for different `b` values instead. Min-Max and Partition then prune nothing, so `PrimaryKey` pruning is left to the bound on `b`: `52/1000` with it, the leading-key-only `103/1000` without. Two mutations now fail the test, where before neither did: setting `use_partition_minmax_for_primary_key_pruning = 0`, and replacing the `CAST` chain with `sipHash64(b)` so the chain is declined. Also execute the predicate with the index, beside the existing no-index run. The granule line is only explained, so nothing asserted that the pruning it reports loses no rows. Both return 51. Co-Authored-By: Claude Opus 5 <[email protected]>
…iant Chain construction advances the argument type to each link's result type (`KeyCondition.cpp:3413`) and execution does the same (`:5654`), so after `toLowCardinality(b)` the running type is LowCardinality, never the plain key type the comment claimed. State what the two statements really pin: normalizing past the chain's seed is what would break them. The other block called itself the `DENSE` path, which now reads as the dense primary-key overload; the property it exercises is the block-backed `FieldRef` that reaches `applyFunction`'s cache, in either overload. Name that instead. Co-Authored-By: Claude Opus 5 <[email protected]>
…ntations The file pins `use_lightweight_primary_key_index_analysis = 1` for the sparse blocks and the setting is session-wide, so the cached-column block only ever ran the lightweight implementation while the header called it the dense path. Run its granule assertion once more with the setting at 0. The chain reaches `applyFunction` under either implementation, because both build block-backed `FieldRef`s from the in-memory index (`MergeTreeDataSelectExecutor.cpp:2341-2364` and `:2384-2405`), and both prune to `Granules: 1/13` here. Pointing the new statement at `notEmpty(v)` turns its `1` into `0`, so it is live. Also drop `dense` from the header's list of pinned paths: it named an implementation of primary-key analysis rather than the path through the chain. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Pushed 64c9b97 on top of your drop: same conclusion on the array block, so I discarded my own commit for it. Three changes to the blocks that stayed, tests only. The sparse block's granule assertion was inert. Both That granule line is only explained, never executed, so the predicate now also runs with the index, beside the existing no-index run. Both return 51. The cached-column block only ever ran the lightweight implementation, because the file pins I also rewrote four comments that prescribed stripping 20 of 20 runs pass with randomization on a debug build at this head. I did not squash: that would need a force-push over your commits. |
…ion cache `filterPartsByQueryConditionCache` gates only on `use_query_condition_cache`, the analyzer, `apply_deleted_mask`, a filter DAG, vector search, FINAL and mutations (`MergeTreeDataSelectExecutor.cpp:1651-1658`); none of `use_primary_key`, `use_partition_pruning` or `use_skip_indexes` appears. So the control arm consults the cache under a predicate the arm above it just executed, and the runner randomizes `use_query_condition_cache` (`tests/clickhouse-test:1837`). Today the two arms do not in fact share a verdict: the exclusions produced by index analysis are written under `getSkipIndexProfiledConditionHash`, which folds in `indexes.use_skip_indexes` (`MergeTreeDataSelectExecutor.cpp:1552`), and the control sets that to 0 while the arm above runs with the default 1. Measured on a server with the cache primed, the control reads 1000 of 1000 marks with 0 cache hits, exactly what it reads on a cold cache. Align the two arms on `use_skip_indexes` and it instead reads the indexed arm's 52 marks with 2 hits, so the reuse is real and only a salt in another subsystem keeps it away from this test. With the cache pinned off the control reads 1000 marks in that configuration too. The bare condition hash is not a route for it either way: entries start all-matching and `write()` only clears the ranges it is given, which are the ones a reader actually evaluated, so a granule index analysis excluded is never cleared. Pinned per statement rather than file-wide, so the other nine executed statements keep running with the randomized value. The `Granules:` oracles are unaffected: in the `SELECT ... FROM (EXPLAIN indexes = 1 ...)` form they report 1000/1000 with a primed cache, identical to the cache off. Reference unchanged. 20/20 with randomization, and the pair still reddens: moving the indexed arm to `a >= 950` fails 2/2 with `-51 / +26`. Co-Authored-By: Claude Opus 5 <[email protected]>
…erge slot count max_number_of_merges_with_ttl_in_pool is a per-table setting, but StorageMergeTree::selectPartsToMerge compares it against MergeTreeData::getTotalMergesWithTTLInMergeList(), which returns the single per-server MergeList::merges_with_ttl_counter, and MergeSelectorApplier gates every TTL selector, TTLPartDropMergeSelector included, behind that comparison. The setting defaults to 2, so two concurrent TTL merges on any other table in the same parallel-run server keep this test's writable control table from dropping its expired part for the whole 60 s window, which is the "writable control table TTL did not run in the background" failure. The same predicate also makes the following negative assertion pass for the wrong reason: "readonly ttl rows: 2" holds just as well when no table in the server could have scheduled a TTL merge at all. Pin the setting on both TTL tables so the assertions depend only on this test's own tables, as 02293_part_log_has_merge_reason.sh and 01921_concurrent_ttl_and_normal_merges_zookeeper_long.sh already do for the same reason. Measured on a debug build: with the pin the expired part is dropped while two TTL merges from another database hold the counter, without it the drop is not selected until the counter frees. Dump system.parts and system.merges on a wait timeout, on the failure path only, so the next red says which of the three causes it was: other tables holding the global TTL slots, a pool busy with something else, or nothing ever selected for these tables. Requested by @ alexey-milovidov in ClickHouse#110326 (comment) Co-Authored-By: Claude Opus 5 <[email protected]>
Related: #109699
Related: #111050
Related: #117054
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
A regression test for the
LowCardinalityhandling inKeyCondition's monotonic-function chain execution. This pull request is now test-only.It started as a bug fix for the AST fuzzer
LOGICAL_ERROR"Arguments ofminus/plushave incorrect data types" (STID 2735-50e2, AST fuzzer (amd_debug)):KeyCondition::applyFunctionexecuted a monotonic key function on the raw index column while the function was resolved against the plain key type, which happens when aMergetable declares a plain header (e.g.UInt32) over a source whose key column isLowCardinality(UInt32).The exception is already fixed on
masterby #111050 (merged 2026-08-05), which normalizes the chain's input type insideapplyMonotonicFunctionsChainToRangeand declares the appended supertype cast against the chain's own result type. #117054 (merged 2026-09-12) then reworked the sparsecheckInHyperrectanglesite so that it always goes through that helper. The test added here passes in full againstmaster'sKeyCondition.cpp, and instrumenting every branch this pull request used to add toKeyCondition.cppshowed that none of them changed the outcome of any statement in the test. Those production hunks were therefore dropped when resolving the merge conflict with #117054, as the review asked; the changelog category isNot for changelog, andCloses: #109699was downgraded toRelated:because that fuzzer issue is closed by #111050.What lands:
tests/queries/0_stateless/05136_key_condition_lowcardinality_key_over_merge.sql— regression coverage for the shapes Fix Bad cast in KeyCondition for nested CAST that re-introduces LowCardinality #111050 fixed: the dense cached-column path, the sparse constant-coordinate (partition-minmax) path, the explicit-field path in bothLowCardinalitydirections, and two-link cast chains whose intermediate result type re-introducesLowCardinality. Each case pairs its count with anEXPLAIN indexes = 1granule-pruning oracle and a full-scan control, so a silently declined chain cannot pass the test.Workflow [PR]
Sync PR [sync-upstream/pr/110326]
Version info
26.9.1.1482(included in26.9and later)