Repository navigation
Fix missing rows in EmbeddedRocksDB, KeeperMap and Redis key lookups for a float compared with a Decimal key - #128086
Conversation
`=` compares a float with a `Decimal`, `DateTime64` or `Time64` value as `Float64`, and `IN` compares the key cast to the set element type, so a float can equal keys other than its cast to the key type. `getFilterKeys` cast the float into the key type, which truncates (`19.99` becomes `19.98`), and looked up only that key, so `EmbeddedRocksDB`, `KeeperMap` and `Redis` returned no rows for `k = 19.99` over a `Decimal(10, 2)` key holding `19.99`, and `ALTER DELETE` with that condition deleted nothing. At a high scale several stored values share one float image. Reuse `floatValuesMissKeyValues`, which the MergeTree key analysis uses for the same comparison, to decline the key filter (full scan, the condition is still applied) for `=`, for `IN` sets and per element of a tuple `=` / `IN` over a composite key. An exact float over a `Decimal32` or `Decimal64` key keeps the lookup. A constant node of an `ActionsDAG` holds a `ColumnConst` of 0 rows, and the helper walks the rows of its column, so the constant is passed as a 1-row column (`cloneResized(1)`), the value `getField()` reads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A scalar subquery returns a `Nullable(Tuple(...))` constant, so the tuple `=` branch did not see a `ColumnTuple` and checked the whole tuple against every key column: any float element declined the lookup, also for an exact `(a, b) = (SELECT (12.5, 1))` over a `Decimal` key and for a composite key with no float compared with a `Decimal`. Unwrap one outer `Nullable` of the column and the type before the per-element check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (2 rounds): 2 major resolved, 1 nit noted
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261028-155600 |
|
cc @GrigoryPervakov @tiandiwonder, could you review this and add the |
|
Workflow [PR], commit [0df1333] Summary: ✅
AI ReviewSummaryThe PR prevents incomplete key lookups in Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units353 translation units recompiled, 3746 s compile time in total, 353 of them have a recent master baseline. |
The tuple IN branch builds each lookup key from a `Field`, and a `Field` holds a `Float32` as `Float64`, so `tryConvertFieldToType` scales the widened value in `Float64`. `floatValuesMissKeyValues` cast the original `Float32` column instead, in `Float32` arithmetic. The two can disagree: `toFloat32(0.29)` is `0.28999999165534973`; times 100 in `Float32` that rounds to 29 (key `0.29`, which the check proves is the only match), while in `Float64` it is `28.999999165534973` and truncates to 28, so the lookup probed `0.28` and `(a, b) IN (SELECT toFloat32(0.29), 1)` missed the stored `(0.29, 1)` (also inside `Nullable`/`LowCardinality`). Widen a `Float32` set column to `Float64` before the check, so it proves the key the lookup actually builds. The comparison type stays the set column's own type. A lookup whose `Float64` cast is exact is kept (`toFloat32(12.5)` still reads `GetKeys`). The `=` branches compare in `Float64`. An exhaustive search over the keys the check can accept there (every `Decimal32`/`Decimal64` key at scales 1-18 that a `Float32` product can produce exactly) found none where the two casts disagree, so they stay as they are. The single-column IN branch already converts with the same typed cast as the check. Found by the automated review on ClickHouse#128086. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 8f2da1dEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The new test Session id: cron:our-pr-ci-monitor:20261029-043003 |
|
@groeneai merge latest master |
…ecimal-float-constant
…ixed-string-variant-constant Resolve the conflict in src/Storages/KVStorageUtils.cpp with master's float/Decimal key checks (ClickHouse#128086): keep master's floatValuesMissKeyValues checks before the constant-type resolution, and extend master's tuple column extraction with the Dynamic/Variant unwrapping of this PR. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #128086 to 26.10: Fix missing rows in `EmbeddedRocksDB`, `KeeperMap` and `Redis` key lookups for a float compared with a `Decimal` key
…eperMap` and `Redis` key lookups for a float compared with a `Decimal` key
Backport #128086 to 26.10: Fix missing rows in `EmbeddedRocksDB`, `KeeperMap` and `Redis` key lookups for a float compared with a `Decimal` key
Related: #126584
Related: #127676
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
EmbeddedRocksDB,KeeperMapandRedistables with aDecimal,DateTime64orTime64primary key returning no rows for a float constant such asWHERE key = 19.99orkey IN (SELECT 19.99)when the key holds the matching value, andALTER TABLE ... DELETE/UPDATEwith such a condition changing nothing. Such a condition now reads the whole table unless it is aFloat32orFloat64constant proven to match only its cast to aDecimal32orDecimal64key (key = 12.5); a constant written in the key's type (key = '19.99') still uses the key lookup.Description
On 26.8.28.14 and 26.9.19.9,
SELECT count() FROM t WHERE k = 19.99over anEmbeddedRocksDBtable with aDecimal(10, 2)key holding19.99returns 0, while the full scannot(not(k = 19.99))returns 1.=compares a float with aDecimal-like value asFloat64, andINcompares the key cast to the set element type, so a float can equal keys other than its cast. The key filter (getFilterKeys) cast the float into the key type, which truncates (19.99is19.98999..., cast to19.98), and looked up only that key. At a high scale (Decimal(38, 30),DateTime64(9)) several stored values share one float image, and only one was looked up.The filter now declines the lookup (a full scan; the condition still applies) when
floatValuesMissKeyValues, the MergeTree key analysis check for the same comparison (#126584), says the float can match a key other than its cast: for=,INsets, and per element of a tuple=/INover a composite key. It proves uniqueness only for aFloat32/Float64value over aDecimal32/Decimal64key (k = 12.5keeps the lookup); other floats (widerDecimal,DateTime64,Time64keys, or insideDynamic/Variant) read the whole table, as in MergeTree.Validation: the new test fails on master and every reference line equals the full-scan answer; a 684-case sweep over 7 key types finds 80 lookup/scan mismatches on master and 0 with the fix; 50/50 randomized runs; the existing KV engine tests and
05408_key_condition_decimal_float_constantbehave as on master.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128086]
Version info
26.11.1.1215-master(included in26.11and later)26.10.8.26