Repository navigation
Convert a key-filter literal with its own type in the KV storages - #118689
Conversation
`getFilterKeys` converted an equality literal with the two-argument form of `convertFieldToType`, so the source type was unknown and the date-family conversion branches never fired. The raw-`UInt64` fallback then returned a `DateTime` literal's seconds as a `Date` field (and a `Date` literal's day number as a `DateTime` field), the point lookup probed a key that does not exist, and `EmbeddedRocksDB`, `KeeperMap` and `Redis` silently returned no rows - while the same predicate returns the row on `MergeTree`, on the same table once the pushdown is neutralized, and through the `IN` branch, which casts the set with its real type. The literal is now converted with its own type, using `tryConvertFieldToType`, so a combination the conversion rejects outright (a `DateTime64` literal against a `Date` key used to raise `TYPE_MISMATCH`) no longer fails the query. A conversion that yields Null was also treated as "a key filter with zero candidate keys", which answers no rows for a literal that is merely not representable in the key type. Such a condition is not a key filter any more, so it is evaluated over a scan - the way the `IN` branch already behaves when a set element cannot be cast. The multi-column tuple-equality path converted its elements the same way and now passes the element types of the tuple it reads them from. Closes: #118397 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [7170f9d] Summary: ✅
AI ReviewSummaryThis PR fixes Final Verdict✅ No blocking findings in the current diff. LLVM Coverage ReportMeasured on commit 7170f9d.
Changed lines: Changed C/C++ lines covered: 30/35 (85.71%) · Uncovered code |
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. |
…ements `tryConvertFieldToType` chooses its conversion branch by the source type as it is, so a `Nullable(Date)` or `LowCardinality(Date)` literal missed the date-family branches and had its day number reinterpreted as a number of seconds. The wrappers are stripped now, for the single-column equality and for each element of a tuple equality. The tuple `IN` path converted its elements without their types as well, so a date-family element probed the wrong key there too; it now carries the set's element types, with the same unwrapping, and uses `tryConvertFieldToType`, so an element the key type cannot represent drops the candidate instead of raising. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Addressed both carriers. The source type is stripped of The tuple One correction on the |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Trivial. LGTM.
|
@alexey-milovidov @antonio2368 — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
…element `traverseDAGFilter` (multi-column overload, tuple-equality branch) bound a raw `const DataTypeTuple *` to the temporary returned by `removeNullable(recursiveRemoveLowCardinality(right->result_type))`. `recursiveRemoveLowCardinality` allocates a new `DataTypeNullable` / `DataTypeTuple` when a tuple element is `LowCardinality`, so that temporary was the only owner and was destroyed at the end of the declaration, while the per-element loop below kept reading `getElements()` from it. A scalar subquery such as `(SELECT (lc_col, id) FROM t LIMIT 1)` yields `Nullable(Tuple(LowCardinality(String), UInt64))`, which takes the allocating branch, so `WHERE (k, id) = (SELECT ...)` on an `EmbeddedRocksDB` table with a composite `PRIMARY KEY` read freed memory (ASan: heap-use-after-free). Introduced by ClickHouse#118689. Keep the stripped type in a named `DataTypePtr`, the shape the sibling call sites in the same file (single-column `equals`, tuple `IN`) already use. Closes ClickHouse#120527 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #118397
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
EmbeddedRocksDB,KeeperMapandRedisreturning no rows forWHERE key = <literal of another date-family type>, such as aDatekey compared with aDateTimeliteral.Description
getFilterKeysconverted an equality literal with the two-argument form ofconvertFieldToType, so the source type was unknown and the date-family conversion branches never fired. The raw-UInt64fallback then returned theDateTimeliteral's seconds as aDatefield (and aDateliteral's day number as aDateTimefield), the point lookup probed a key that does not exist, and the query silently returned no rows - while the same predicate returns the row onMergeTree, on the same table once the pushdown is neutralized, and through theINbranch, which casts the set with its real type.The literal is now converted with its own type.
tryConvertFieldToTypeis used, so a combination the conversion rejects outright (aDateTime64literal against aDatekey used to raiseTYPE_MISMATCH) no longer fails the query.A conversion that yields Null was also treated as "a key filter with zero candidate keys", which answers no rows for a literal that is merely not representable in the key type. Such a condition is no longer a key filter, so it is evaluated over a scan, like the
INbranch already does when a set element cannot be cast.The multi-column tuple-equality path converted its elements the same way and now passes the element types of the tuple it reads them from.
Workflow [PR]
Sync PR [sync-upstream/pr/118689]
Version info
26.9.1.992(included in26.9and later)