Repository navigation
Fix uniq and GROUP BY for JSON/Dynamic types - #69203
Conversation
|
This is an automated comment for commit 228ac44 with description of existing statuses. It's updated for the latest CI running ❌ Click here to open a full report in a separate page
Successful checks
|
| { | ||
| auto path_size = unalignedLoad<size_t>(pos); | ||
| pos += sizeof(size_t); | ||
| std::string_view path(pos, path_size); |
There was a problem hiding this comment.
Shouldn't we have some sanity check here? Can we read such column from client, for example or we validated it beforehand? Anyway, if it's possible to check size with maximal it's worth doing at least to protect from some bug for example
There was a problem hiding this comment.
Can we read such column from client, for example or we validated it beforehand?
AFAIK methods serializeValueIntoArena/serializePathAndValueIntoArena are used only internally in aggregation and the data cannot be serialized/deserialized from outside (we can have serialized aggregate functions states, but it's different). And I don't see any similar checks in other columns implementation.
If you have good suggestion for max size to check, we can add it
Backport #69203 to 24.8: Fix uniq and GROUP BY for JSON/Dynamic types
`count(DISTINCT)`, `uniq*`, `SELECT DISTINCT`, `arrayDistinct` and hash
`JOIN` identify a row by the SipHash of `IColumn::updateHashWithValue`
alone. `ColumnObject::updateHashWithValue` hashed every path without its
size and every object without its number of paths, and
`ColumnDynamic::updateHashWithValue` hashed the type name without its
size. Different values could therefore give the same byte stream:
the paths of adjacent objects of an `Array(JSON)` ran together
(`[{a},{b,c}]` vs `[{a,b},{c}]`, ClickHouse#129458), a path ran into the type name
after it (`x` + `UInt64` vs `xU` + `Int64`), and in `Dynamic` a type
name ran into the value (`Date` + `32` vs `Date32`). The framing dates
from ClickHouse#69203; `GROUP BY` was correct because it keys on the arena
serialization, which writes the count and every size.
Now the object hash starts with the number of paths, as
`serializeDynamicPathsAndSharedDataIntoArena` computes it, every path is
preceded by its size, and a non-NULL `Dynamic` value hashes a zero tag,
the size of the type name and the name. The tag differs from the
`NULL_DISCRIMINATOR` hashed for NULL. One helper,
`ColumnDynamic::updateHashWithTypeName`, is used for dynamic paths and
for shared data, so the hash stays independent of where a path is
stored.
Bucketed `Map` parts place a key in bucket `SipHash(key) % N`, and a
`m[key]` lookup reads only that bucket, so the new hash would miss keys
with `JSON` or `Dynamic` written by an older version, and an older
version would miss keys written by this one. Such a `Map` is now read
whole (the guard ClickHouse#125713 added for float zeros) and written in one
bucket, which every version reads whole.
Hash values of `JSON` and `Dynamic` rows change, so `uniq*` states of
such arguments stored by older versions do not deduplicate against new
ones. `sipHash64` of `JSON` uses `serializeForHashCalculation` and is not
changed.
Closes ClickHouse#129458
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix incorrect results of Fix uniq and GROUP BY for JSON/Dynamic types.
Implement
updateHashWithValue/serializeValueIntoArena/deserializeAndInsertFromArena/skipSerializedInArenamethods properly for JSON/Dynamic columns.Documentation entry for user-facing changes
CI Settings (Only check the boxes if you know what you are doing):