Repository navigation
Conversation
hasTypeThatCanContainNulls() enumerates null-capable types via canContainNull() (Nullable / LowCardinality(Nullable) / Variant / Dynamic) and recurses into Array/Tuple/Map. canContainNull() omits Object/JSON, whose paths are dynamically typed and can be NULL like Variant/Dynamic, so a JSON-containing join key was reported null-free and routed to the single-element "equals" runtime-filter path. equals over a JSON value returns Nullable(UInt8), so a matching left row was silently dropped: an equi-join on a JSON (or nested Tuple/Array/Map JSON) key with one distinct right-side value returned no rows under the default enable_join_runtime_filters=1, while the same query with the filter disabled returned the matching row. Add isObject() to hasTypeThatCanContainNulls() so JSON-containing keys take the null-safe Set path. The helper has a single caller (the join runtime filter); canContainNull() is left unchanged (it has many other callers). The existing Array/Tuple/Map recursion covers nested JSON. Closes: ClickHouse#107646 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Original #101415 crash repro ( Session id: cron:clickhouse-worker-slot-3:20260616-172500 |
|
cc @Avogar — could you review this? It is the follow-up to #106931: |
| @@ -33,7 +33,8 @@ bool hasNullable(const DataTypePtr & type) | |||
|
|
|||
| bool hasTypeThatCanContainNulls(const DataTypePtr & type) | |||
| { | |||
| if (canContainNull(*type)) | |||
| // canContainNull omits Object/JSON, but its dynamically typed paths can be NULL like Variant/Dynamic. | |||
| if (canContainNull(*type) || isObject(*type)) | |||
There was a problem hiding this comment.
Why? JSON cannot contain NULLs. If JOIN key would be JSON key, it would be Dynamic or any other type if it has type hint
|
This is wrong |
Closes: #107646
Related: #106931
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix silently dropped rows for an equi-join on a
JSON/Objectkey (or aJSONnested inTuple/Array/Map) when the right side has a single distinct value andenable_join_runtime_filters = 1. The join runtime filter treated aJSON-containing key as null-free and chose the single-element "equals" path;equalsover aJSONvalue returnsNullable(UInt8), so the matching row was dropped.JSON/Objectis now detected as null-capable, forcing the null-safe lookup path.Description
Follow-up to #106931 (Closes #101415), which generalized the runtime-filter null-capable type check to
hasTypeThatCanContainNulls()and was found, in review of that PR, to still missObject/JSON.hasTypeThatCanContainNulls()enumerates null-capable types viacanContainNull()(Nullable/LowCardinality(Nullable)/Variant/Dynamic) and recurses intoArray/Tuple/Map.canContainNull()omitsObject/JSON, whose paths are dynamically typed and can be NULL likeVariant/Dynamic. So aJSON-containing join key was reported null-free and routed to the single-element "equals" runtime-filter path (RuntimeFilterLookup.h), which producesNullable(UInt8)for aJSONargument and silently drops the matching left row.Repro on master (returns
0; withenable_join_runtime_filters = 0returns1):Fix: add
isObject()tohasTypeThatCanContainNulls()soJSON-containing keys take the null-safeSetpath. The helper has a single caller (the join runtime filter);canContainNull()is left unchanged because it has many other callers (CAST, comparison, MergeTree key conditions). The existingArray/Tuple/Maprecursion covers nestedJSON.Regression coverage added to
04327_runtime_filter_nested_variant(top-levelJSONkey,Tuple(JSON),Array(JSON),Map(String, JSON)value,Map(JSON, String)key, plus LEFT ANTI JOIN runtime-filters off-vs-on self-validation). The inner-join cases return no rows without the fix and the expected row with it.