Repository navigation
Conversation
`__bitSwapLastTwo` computes only on `UInt8`, but its return type was resolved for every integer width and both float types, so the argument type was checked only in `BitSwapLastTwoImpl::apply`, when a row was processed. `EXPLAIN` and a query over an empty table accepted `__bitSwapLastTwo(toFloat64(c0))`, and with rows it failed with `BAD_ARGUMENTS` at execution. `getReturnTypeImpl` now rejects every argument other than (`Nullable`/`LowCardinality` of) `UInt8` or `Bool` with `ILLEGAL_TYPE_OF_ARGUMENT`, the code the function already returned for `String` and `Enum8`. Requested in ClickHouse#117613 (comment) The only in-tree caller besides SQL is the set skip index, which rewrites `NOT` into `__bitSwapLastTwo` over the `UInt8` masks built by `__bitWrapperFunc`, the unknown constant, or the other mask functions, so it never passes another type; a type x predicate x settings matrix over set indexes measured no difference in counts or errors between the old and the new build. With analysis rejecting other types, the throw in `apply` is unreachable from SQL, so it is a `LOGICAL_ERROR` again and the comment saying it was callable from SQL is removed. 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; 1 finding), plus my own review (2 nits, both addressed in the PR description: the sibling functions and the compatibility line).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20260928-191100 |
|
Workflow [PR], commit [29023c0] Summary: ❌
|
|
|
||
| DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override | ||
| { | ||
| if (!isUInt8(arguments[0])) |
There was a problem hiding this comment.
Moving this check into getReturnTypeImpl changes table-metadata restoration, not just ad-hoc query analysis. Existing MergeTree metadata such as ORDER BY __bitSwapLastTwo(toUInt16(x)) currently loads and only fails once the expression is executed during INSERT; after this change the table itself stops loading, and with async_load_databases = 0 that can prevent server startup. Per the compatibility rule for new validation on existing metadata, this needs a gate or to be limited to newly created metadata rather than unconditional analysis-time rejection.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 8 s compile time in total, 7 of them have a recent master baseline. |
…eject-non-uint8 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #117613 (comment)
Related: #117613
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The internal function
__bitSwapLastTworejects arguments of types other thanUInt8while the query is analyzed, withILLEGAL_TYPE_OF_ARGUMENT, instead of raisingBAD_ARGUMENTSwhen a row is processed.EXPLAINand queries that process no rows now also reject such arguments.Description
Improvement, notBug Fix:__bitSwapLastTwois an internal function, not a documented user surface.On master
EXPLAIN header = 1 SELECT __bitSwapLastTwo(toFloat64(c0)) FROM tsucceeds, and so does theSELECTover an emptyt; with rows it fails at execution withCode: 36 ... It's a bug! Only UInt8 type is supported by __bitSwapLastTwo, or returns a value once the expression is JIT-compiled (#117613).FunctionBitSwapLastTwo::getReturnTypeImplnow accepts onlyUInt8(Boolincluded,NullableandLowCardinalityare stripped before it) and raises the messageStringarguments already get. The throw inapplyis then unreachable from SQL, so it is aLOGICAL_ERRORagain.The set skip index is the only other caller: it rewrites
NOTinto__bitSwapLastTwooverUInt8masks. Measured on 332 cases (17 column types, 22 predicates, aset(0)index and a never-executedset(1)index), each under 8 combinations of the skip index settings: all 2656 queries return the same count or error on both builds, and in 1952 of themsystem.query_log.used_functionsshows that the index built__bitSwapLastTwo.Compatibility: a table that applies
__bitSwapLastTwoto another type in aMergeTreesorting or partition key, TTL or skip index (everyINSERTinto it already failed) or in aDistributedsharding key no longer loads, so queries to it and tosystem.tablesof its database fail; withasync_load_databases = 0the server does not start. I added no compatibility setting:system.functionssays this internal function "may change or be removed at any time".__bitWrapperFunc,__bitBoolMaskAndand__bitBoolMaskOrhave the same shape (accepted during analysis,BAD_ARGUMENTSon the first row). I left them unchanged and can extend this PR to them if wanted.Test
05056of #117613 expectsBAD_ARGUMENTSfor these arguments; whichever PR merges second updates it toILLEGAL_TYPE_OF_ARGUMENT.Workflow [PR]
Sync PR [sync-upstream/pr/122748]