Repository navigation
Conversation
`ToStringMonotonicity` stripped `LowCardinality` but not `Nullable`, so over a `Nullable(Enum)`, a `Nullable(DateTime)` in a zone that changes its offset or a `Nullable(Time)` primary key every type guard was bypassed and the generic same-digit-count branch declared `toString` monotonic; key analysis then mapped granule bounds through `toString` and returned wrong counts. `Nullable` now comes off like `LowCardinality`. Where `toString` is monotonic on the wrapped type, a `Nullable` key is now pruned as a plain one is. `CAST(k AS String)` resolves to the same struct. ClickHouse#119557
|
Workflow [PR], commit [7406eed] Summary: ❌
AI ReviewSummaryThis PR fixes the wrong monotonicity verdict for Final Verdict
LLVM Coverage ReportMeasured on commit 7406eed.
Changed lines: Changed C/C++ lines covered: 8/8 (100.00%) · Uncovered code |
|
@navneet83 Can you please review #118581? |
…ill throws on it `NULL` sorts last and reaches the monotonicity check as an infinite bound. With `Nullable` unwrapped, `CAST(s AS String) = 'cc'` over a `Nullable(String)` key pruned that granule and returned a count where it used to raise `CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN`.
Build profile diff (arm_release)Comparing commit See the job log for details. |
`isNull` on a range bound is also the infinite bound of a part's first and last granule, so the guard in `ToStringMonotonicity` cost `toString` those granules on every `Nullable` key. `CAST` to a non-`Nullable` type is the function that throws on a `NULL`, so it is `CAST` that treats a range open on one side as not monotonic; `toString` prunes a `Nullable` key like a plain one.
…tself `KeyCondition` evaluates a function chain over the whole index column the first time a mark needs it, and on a part holding a `NULL` the last mark is that `NULL`, so `CAST` to a non-`Nullable` type raises the row-level error during the analysis whether or not a range is declared non-monotonic, as `CAST` to `Date` does on a `Nullable(DateTime)` key today. The guard only traded `toString` pruning on a part's last granule for nothing, so it goes; `05230` pins the error on a part with a `NULL` and the pruning on one without.
Read in key order, `LIMIT` stops before the `NULL` row and the query returns, as `ORDER BY CAST(d AS Date) LIMIT 1` does on a `Nullable(DateTime)` key today; without the order the whole column is evaluated and `CAST` raises.
|
Superseded by #121081, squashed. |
Closes: #119557
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed wrong results of
WHERE toString(key) ...andWHERE CAST(key AS String) ...over aNullable(Enum),Nullable(DateTime)orNullable(Time)primary key withallow_nullable_key.Documentation entry for user-facing changes
ToStringMonotonicityunwrappedLowCardinalitybut notNullable, so for aNullablekey every type guard was skipped and the generic integer branch declaredtoStringmonotonic; key analysis then mapped granule bounds throughtoStringand dropped or over-counted granules.Nullableis now unwrapped likeLowCardinality;CAST(key AS String)resolves to the same struct. WheretoStringis monotonic on the wrapped type (String,Date, a fixed-offsetDateTime), aNullablekey is now used for pruning as a plain one is, andORDER BY toString(key)reads in order,NULLlast in both orders.CAST(key AS String)resolves to the same struct. On a part holding aNULLthe index analysis evaluates the chain over the index column, whose last mark is thatNULL, soCASTto a non-Nullabletype raises the error the row-level evaluation would, asCASTtoDatedoes on aNullable(DateTime)key today. Nothing is hidden by pruning;05230pins the error and the pruning on a part withoutNULL.Workflow [PR]
Sync PR [sync-upstream/pr/120680]