Repository navigation
Conversation
… unit Index analysis converts the constant of `time >= INTERVAL 510 MINUTE` to the comparison's common type, the finer `IntervalNanosecond` of the key, with `convertFieldToType`. It had no conversion between two different interval units, so the conversion threw, `KeyCondition` built no atom and every granule was read. Building an `IN` set hit the same exception and failed the query with `TYPE_MISMATCH`. Convert a coarser interval value to a finer unit of the same family when the product fits in `Int64`. That is the value the comparison's own cast produces, so the bound is exact and is used by the primary key, `PREWHERE`, `minmax` skip indexes, partition pruning and `IN` sets. A finer constant, one that overflows the column's unit and units of different families stay rejected: the comparison casts the column side with a wrapping multiplication, or has no common type, so no bound computed from the constant alone would agree with it. Unwrap a `Nullable` / `LowCardinality` interval source type like the temporal ones, so an Array constant with `NULL` reaches the new branch, and the same unit takes the early return instead of failing. Closes ClickHouse#126218 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Hint-unwrap comment: an unwrapped interval hint avoids a type mismatch, not only a raw-number reinterpretation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings over 3 runs; 1 fix round + 1 delta recheck with 0 findings).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261016-094100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261016-092600 |
|
cc @azat @Algunenano, could you review this? |
|
Workflow [PR], commit [021fc5a] Summary: ❌
AI ReviewSummaryAdds exact, overflow-checked conversion from coarser to finer Missing context / blind spots
Final VerdictStatus: ✅ Approve. No new inline findings. |
CI finish ledger - 021fc5aEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The build failure dropped 93 dependent jobs, so no functional test has run on this head yet. Session id: cron:our-pr-ci-monitor:20261017-033003 |
Closes: #126218
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The primary key and
minmaxskip indexes are now used when a column of anIntervaltype is compared with anIntervalconstant of a coarser unit, e.g.time >= INTERVAL 510 MINUTEfor anIntervalNanosecondcolumn.INwith such constants is now accepted instead of failing withTYPE_MISMATCH. Closes #126218.Description
On master,
WHERE time BETWEEN INTERVAL 510 MINUTE AND INTERVAL 515 MINUTEover anIntervalNanosecondsorting key reads every granule (Condition: true), andtime IN (INTERVAL 510 MINUTE, INTERVAL 1 HOUR)fails withTYPE_MISMATCH. The comparison results themselves are correct.Root cause: index analysis converts the constant to the comparison's common type, the finer unit, with
convertFieldToType, which had no conversion between two differentIntervalunits. The exception was swallowed, so no condition was built; building anINset hit the same exception.Change:
convertFieldToTypeconverts anIntervalvalue of a coarser unit to a finer unit of the same family (NanosecondtoWeek, orMonth/Quarter/Year) when the product fits inInt64. That is the value the comparison's own cast produces, so the bound is exact. A finer constant, one that overflows the column's unit, and units of different families are still not converted: the comparison then casts the column, wraps, or has no common type, so no bound computed from the constant alone would match it. ANullableinterval source type is now unwrapped like the temporal ones, which also makestoIntervalMinute(1) IN [NULL, toIntervalMinute(1)]work.Validation: the new test covers
IntervalNanosecond,IntervalMicrosecond,IntervalMillisecondandIntervalSecondkeys andminmaxindexes againstSECONDtoYEARconstants, forBETWEEN,<,>=,IN,NOT INandPREWHERE, plus the cases that must stay rejected. It fails on master and passes 50/50 randomized runs. The converted bound is identical to the one built from a literal in the column's unit.x IN (SELECT <interval>)andhas()with mixed interval units are a separate, pre-existing problem and are not changed here.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/126263]