Repository navigation
Conversation
`accurateCast` and `accurateCastOrNull` between two Interval kinds ignored the cast type: finer to coarser truncated (90 seconds became 1 minute), coarser to finer multiplied without an overflow check, and Day/Week to Month/Quarter/Year used the approximate factor 4 weeks per month. `Set::execute` casts the probe column to the set's element type with `castColumnAccurateOrNull` and treats a NULL as "not a member", so every `IN (subquery)` across Interval kinds matched values that are not equal: `time IN (SELECT INTERVAL 510 MINUTE)` over an `IntervalNanosecond` column counted all 60 values inside that minute. The same cast translates set elements for the primary key in `KeyCondition`, so the index and the runtime keep agreeing. Now the accurate modes reject a value the target kind does not hold exactly: a remainder, a multiplication overflow, or a pair of kinds across the month boundary. `accurateCast` throws, `accurateCastOrNull` returns NULL. Plain `CAST` keeps its truncating conversion. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`FunctionArrayIndex` compared the raw counts of two Interval kinds, so `has([INTERVAL 1 MINUTE], toIntervalSecond(60))` returned 0. This covers `has`, `notHas`, `indexOf`, `indexOfAssumeSorted`, `countEqual`, `mapContainsKey` and `mapContainsValue`. Convert the needle to the element kind with the accurate cast; a needle the element kind cannot hold exactly (a remainder or an overflow) is not found. The array itself is not converted: converting a coarser array to a finer kind can overflow, which would break the sorted order `indexOfAssumeSorted` relies on. The `Array(LowCardinality(Interval))` path with a constant needle already resolves the needle with the same cast, so both encodings now agree. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merge the executeDifferentIntervalKinds header into two lines and drop the comment restating the not_representable mask. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (click to expand)
Re-review of the fix commit: no findings. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261016-092600 |
|
Workflow [PR], commit [6831a70] Summary: ✅
AI ReviewSummaryMakes accurate casts between Final VerdictStatus: ✅ Approve |
|
cc @nihalzp @CurtizJ, could you review this, and add |
CI finish ledger - a0b651eEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The build failure dropped 106 dependent jobs, so no functional test has run on this head yet. Session id: cron:our-pr-ci-monitor:20261016-133003 |
…ubquery-and-has # Conflicts: # src/Functions/array/arrayIndex.h
…ts in the common type A constant array is searched by comparing `Field`s, and the `Field` of an `Interval` is the bare count of its own unit, so `has`, `indexOf`, `indexOfAssumeSorted`, `countEqual` and `mapContainsKey` over a constant array of `Tuple` or `Array` values compared the raw counts of two kinds: `has([(INTERVAL 1 MINUTE, 7)], (toIntervalSecond(1), 7))` returned 1 and the same search for `toIntervalSecond(60)` returned 0, while the non-constant array (`materialize`) and `=` return 0 and 1. Such a pair is now brought to its common type first, which is what the non-constant path does, so both encodings of the haystack agree. The top-level `Interval` element keeps its exact needle conversion. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes10 object files changed (+171.03 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units45 translation units recompiled, 342 s compile time in total, 45 of them have a recent master baseline. |
…rted
The previous commit compares a constant array of composite values that
hold an Interval in the common type of the array elements and the needle.
That cast multiplies a coarser Interval into the finer unit and can wrap
on overflow, so the cast array may no longer be sorted, while
`executeConst` binary-searches a constant needle for `indexOfAssumeSorted`:
indexOfAssumeSorted([(toIntervalWeek(0), 7), (toIntervalWeek(20000), 7)],
(toIntervalNanosecond(0), 7))
returned 0 instead of 1 (the cast array is [(0,7),(-6350744073709551616,7)]).
`indexOf`, a materialized haystack and scalar Interval elements returned 1.
For `indexOfAssumeSorted` with a constant needle, search the single row of
the two constants as non-constant columns, which is a linear search, and
return the result as a constant (so constant folding is kept). A
non-constant needle is already searched linearly by `executeConst`.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Dear @yariks5s, 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. |
Related: #126218
Related: #126263
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed wrong results of
IN (subquery),has,indexOf,countEqualand related functions when the two sides areIntervalvalues of different units:toIntervalSecond(90) IN (SELECT INTERVAL 1 MINUTE)returned 1 andhas([INTERVAL 1 MINUTE], toIntervalSecond(60))returned 0, also forIntervalvalues inside theTupleorArrayelements of a constant array.accurateCast,accurateCastOrNullandaccurateCastOrDefaultbetweenIntervalunits now reject a value the target unit cannot hold exactly (a remainder, an overflow, or months versus days and weeks) instead of truncating it; plainCASTstill truncates. AnIN (subquery)whose set column is aTuple,ArrayorMapconverts strictly, so such a value there now raisesCANNOT_CONVERT_TYPE.Description
On 26.8.18.2, over an
IntervalNanosecondcolumn holding one value per second,WHERE time IN (SELECT INTERVAL 510 MINUTE)returns 60 rows instead of 1, andWHERE has([INTERVAL 510 MINUTE], time)returns 0.WHERE time = INTERVAL 510 MINUTEreturns 1.Root cause:
IN:Set::executecasts the probe column to the set's type withcastColumnAccurateOrNull, and a NULL means "not a member". For anIntervaltarget the cast ignored the accurate mode: 90 seconds became 1 minute, an overflowing multiply wrapped, and 28 days became 1 month.hasfamily: the raw counts of the two units were compared, so 60 seconds never equalled 1 minute. Over a constant array this also happened insideTupleandArrayelements.Change:
IntervaltoIntervalcast between different units now rejects a value that has a remainder, overflows, or crosses the month boundary:accurateCastthrows,accurateCastOrNullreturns NULL. This fixes everyINvariant and keeps the primary key analysis of the same set consistent with the runtime. ATuple,ArrayorMapset column is converted strictly, as for other types (IN with a Tuple/Array set key rejects unparsable text at default settings #121232), so there such a value raisesCANNOT_CONVERT_TYPEinstead of matching.has,notHas,indexOf,indexOfAssumeSorted,countEqual,mapContainsKeyandmapContainsValueconvert the needle to the element's unit with that cast, so a needle the unit cannot hold is not found. Over a constant array, aTupleorArrayelement holding anIntervalis compared in the common type, as over a non-constant array and by=.Validation: the new test fails on master and passes with the fix.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/126290]