Repository navigation
Type IN (subquery) over LowCardinality the same as IN (literal list) - #114229
Conversation
…lt type Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [853a919] Summary: ✅
AI ReviewSummaryThis PR makes Final Verdict✅ No findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 8/13 (61.54%) · Uncovered code |
…mpensating cast Co-Authored-By: Claude Fable 5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units8 translation units recompiled, 28 s compile time in total, 8 of them have a recent master baseline. |
|
📊 Cloud Performance Report ✅ AI verdict: This is a correctness fix: it makes IN over a LowCardinality argument resolve the same result type whether the right-hand side is a literal list or a subquery set, and relaxes the matching distributed-plan type check. The three flagged ClickBench queries (Q16, Q17, Q18) are all plain GROUP BY aggregations with no IN or subquery, so they never touch the changed code path. The two flagged improvements (Q16 -11.9%, Q17 -16.2%) are therefore downgraded to not_sure as off-path variance, and the Q18 -6.6% suppression to no_change is correct. No real PR-attributable performance change is present in this benchmark set. clickbenchFlagged queries (2 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
…d analyzer
The old analyzer replaces `in` with `inIgnoreSet` while it only needs the
types, passing the left operand as the stand-in for the set that is not built
yet. The general typing rule wraps the result in `LowCardinality` only when
every other argument is a constant, so two full `LowCardinality` arguments
typed the expression as plain `UInt8`, while executing the real `in` against
the constant `Set` column yields `LowCardinality(UInt8)`.
A query reading such a column across a subquery boundary then recorded
`UInt8` in the outer `ActionsDAG` and got `LowCardinality(UInt8)` in the
header, failing the type check in `ActionsDAG::updateHeader`:
SET enable_analyzer = 0;
SELECT tuple(*) FROM (SELECT s, s IN (SELECT 'a') AS f FROM t);
-- Unexpected return type from tuple. Expected Tuple(LowCardinality(String), UInt8).
-- Got Tuple(LowCardinality(String), LowCardinality(UInt8)). (LOGICAL_ERROR)
Pass a constant `UInt8` as the stand-in instead. It is indistinguishable from
the real `Set` argument in every dimension the typing rule inspects, so
analysis and execution agree by construction for all eight `in` variants and
every operand shape. A `Set`-typed stand-in would mirror execution more
literally, but the window-definition expressions built by
`getRootActionsNoMakeSet` end up in an executed plan, and a `ColumnSet` with
no set behind it would be dereferenced when such a plan is serialized.
`allow_experimental_analyzer = 1` was fixed for the same root cause in
ClickHouse#114229, whose test is tagged
`no-old-analyzer`; the divergence appeared when `ColumnSet` became always
constant in ClickHouse#100226.
…here
`04894_in_subquery_lowcardinality_type_old_analyzer` fails on this
branch only in its new-analyzer half:
-- the analyzer
-LowCardinality(UInt8) LowCardinality(UInt8)
-LowCardinality(UInt8)
+LowCardinality(UInt8) UInt8
+UInt8
The old-analyzer half - what this backport fixes - passes. Under
`enable_analyzer = 1` this branch still types `s IN (SELECT 'a')` as
plain `UInt8` while `s IN ('a')` is `LowCardinality(UInt8)`: for a
subquery set the argument is `DataTypeSet` with no column yet, so
`IFunctionOverloadResolver::getReturnType` counts it as a full column
and suppresses the `LowCardinality` wrap. Making the two forms agree
is #114229, which is labelled `pr-improvement` and therefore not a
candidate for a release branch.
So the two `toTypeName` controls are dropped from the analyzer block
rather than re-pinned to this branch's output, which would write a
known inconsistency into the reference. The value assertions stay -
`tuple(*)`, `arrayFilter` and the two `count()`s are the ones that
used to fail `ActionsDAG::updateHeader` with `Unexpected return type
from tuple`, and they pass here.
Related: #113826
Follow-up to the review of the
ActionsDAGtype-check relaxation in the PR above: revert the relaxation and fix the root cause outside ofActionsDAGinstead.The result type of
INover aLowCardinalityargument used to depend on the form of the right-hand side: with a literal list it wasLowCardinality(UInt8), with a subquery it was plainUInt8. The general typing rule wraps the result inLowCardinalityonly when all other arguments are constants, and during analysis the set from a subquery is not built yet and has no column, so it did not count as a constant — while a set is always a constant column in the plan (ColumnSetis always wrapped inColumnConst). A worker deserializing a distributed plan rebuilt the function with the constant set, got the wrapped type, and the type check failed; the previous fix accepted the difference in the check.The typing rule now counts a
Set-typed argument as a constant.x IN (subquery)over aLowCardinalitycolumn returnsLowCardinality(UInt8), the same asx IN (literal list), in both analyzers, and the serialized and rebuilt types agree, so the strict type check inActionsDAG::deserializeis restored exactly as before the PR above. A mixed-version window exists only between that PR and this one (both master-only, no stable release in between, and the affected path is the experimentalmake_distributed_plan): a not-yet-upgraded initiator sends the unwrapped type and an upgraded worker rejects the plan with a clearINCORRECT_DATAerror.The visible type change:
toTypeName(x IN (subquery)),EXPLAINheaders, and column types ofCREATE ... AS SELECTover such expressions now showLowCardinality(UInt8)instead ofUInt8. The values do not change. A sweep of the stateless suite found no existing test that observes the type. Execution ofINoverLowCardinalitywith a subquery also becomes cheaper: it now takes the same probe-per-distinct-value path as literal lists.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
x IN (subquery)over aLowCardinalitycolumn now returnsLowCardinality(UInt8)— the same type asx IN (literal list). Previously the two forms returned different types, and distributed plans with such anINneeded a special case in the plan type check.Version info
26.8.1.1173(included in26.8and later)