Skip to content

Do not rewrite a comparison chain into IN across String and FixedString - #117293

Open
alexey-milovidov wants to merge 41 commits into
masterfrom
fix-chain-to-in-fixed-string-padding
Open

alexey-milovidov wants to merge 41 commits into
masterfrom
fix-chain-to-in-fixed-string-padding

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

Closes: #116852
Related: #115311

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix silently wrong results when a chain of comparisons against FixedString constants over a String
column is rewritten into IN/NOT IN. x != c1 AND x != c2 AND x != c3 evaluated to true while
x != c1 alone evaluated to false in the same query, and the OR/IN direction lost rows the same
way. Also do not rewrite such a chain over a floating-point expression, where the rewrite dropped
-0.0 rows (-0.0 = 0.0 is true while -0.0 IN (0.0) is false) and mishandled NaN.

Description

equals compares the string family zero-padded, so 'a' = toFixedString('a', 2) is true. Set
membership is bytewise, so 'a' IN (toFixedString('a', 2)) is false. The chain rewrites in
LogicalExpressionOptimizerPass (optimize_min_equality_disjunction_chain_length /
optimize_min_inequality_conjunction_chain_length) swapped one for the other, and the query became
internally inconsistent: a conjunction was true while one of its terms was false, a disjunction false
while one of its terms was true. In WHERE position the NOT IN spelling kept a row that every
individual conjunct excludes.

The existing lossless-conversion guard in both loops does not cover this. Converting a
FixedString(2) 'a\0' to String preserves the bytes exactly; what differs is the comparison
semantics, not the value.

ArrayExistsToHasPass already declines such a pair for precisely this reason
(stringFamilyPairIsNotEqualityEquivalent, added for #115311). That helper moves to
Analyzer/Utils and both passes share it, so the two rewrites cannot drift apart.

The same rewrites were also unsound for floating-point expressions: equals compares floats
numerically while the set is keyed on the raw bits, so -0.0 = 0.0 is true but -0.0 IN (0.0) is
false, and nan = nan is false but nan IN (nan) is true. f = 0.0 OR f = 1.0 OR f = 2.0 lost the
-0.0 rows once rewritten, and the NOT IN direction kept them. Both chain rewrites now decline
when the expression's type contains a float (Float32, Float64, BFloat16, also inside
Nullable, LowCardinality, Array, Tuple, Map and Variant), as HasToInPass already does.

Test 05227_chain_to_in_fixed_string_padding covers both directions, the WHERE position, and that a
chain of same-type constants is still rewritten to IN. Test 05228_chain_to_in_float_negative_zero_nan
covers -0.0 and NaN for both directions and the float carriers above, and that an integer column
compared with float literals is still rewritten.
Test 05243_chain_to_in_float_variant covers a Variant with a floating-point alternative.

The range/notEquals pruning in the same pass (addComparisonFilter, optimize_redundant_comparisons) compared constants of composite float carriers (Tuple(Float64, ...), Array(Float64), Map, Variant) as Field containers, which order a nested NaN after all values: tup = (1, 1) AND tup < (1, nan) was pruned to tup = (1, 1). Such filters are now kept out of the analysis; test 05397_chain_comparison_composite_float_nan covers it.

ArrayExistsToHasPass likewise no longer rewrites arrayExists(x -> x = c, arr) to has when has does not compare the element numerically: a composite carrier of floats, BFloat16, or Array(LowCardinality(Float64)), where has matches a stored NaN while equals does not. Tests 05407_array_exists_to_has_composite_float_nan and 05408_array_exists_to_has_bfloat16_low_cardinality_nan cover it.


Workflow [PR]
Sync PR [sync-upstream/pr/117293]

…dString`

`equals` compares the string family zero-padded - `'a' = toFixedString('a', 2)` is true - while
set membership is bytewise, so `'a' IN (toFixedString('a', 2))` is false. Rewriting a chain of
comparisons into `IN`/`NOT IN` therefore made a query contradict itself: with a `String` column
and `FixedString` constants,
`s != toFixedString('a', 2) AND s != toFixedString('b', 2) AND s != toFixedString('c', 2)`
evaluated to true while its own first conjunct evaluated to false, and the `OR`/`IN` direction
lost rows the same way.

`ArrayExistsToHasPass` already declines such a pair for the identical reason; its helper moves to
`Analyzer/Utils` and both passes now share it. The existing lossless-conversion check does not
cover this: converting `FixedString(2)` 'a\0' to `String` preserves the bytes, it is the
comparison semantics that differ.

Closes: #116852
@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8a7b8b2]

Summary: ✅


AI Review

Summary

The PR preserves comparison semantics by declining unsafe rewrites to IN, NOT IN, and has, and by keeping unsafe string and composite float comparisons out of redundant-filter pruning. Reviewed the current diff at 8a7b8b29e01a07d47448cb2b6df20a4fef23202e, surrounding comparison and membership implementations, and all prior discussion. The earlier findings are addressed; no new actionable findings remain. The current-head Fast test report confirms all 11 added regression tests and both modified tests pass. Tests were not rerun locally.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 31, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 8a7b8b29e with master 0b5613b71 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

91 translation units recompiled, 489 s compile time in total, 91 of them have a recent master baseline.

Job report

…redundancy pruning

`addComparisonFilter` converted the constant to the column type and used the result as the
pruning key. For a `String` column and a `FixedString` constant that key is bytewise narrower
than the padded `equals` semantics: `s = toFixedString('a', 2)` converts to `s = 'a\0'`, which
made the pass drop `s != 'a'` as implied, so
`s = toFixedString('a', 2) AND s != 'a'` returned true for `s = 'a'`.

Such filters are now kept opaque, so they take part in neither pruning nor contradiction
detection. Also tag the test `no-old-analyzer`: the rewrite lives in the analyzer and
`EXPLAIN QUERY TREE` is analyzer-only.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: Container memory budget exceeded (/docker) in Integration tests (amd_asan_ubsan, db disk, old analyzer, 2/6, 5/6, 6/6) — https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117293&sha=2865d955377f0f10aca55617c8c8ed16c5813c81&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%202%2F6%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

It is a job-level container memory-budget guard with no individual test failures, and this pull request only changes an analyzer pass, so it cannot be the cause. I could not find an open issue or pull request tracking it.

The 05079_chain_to_in_fixed_string_padding failure in the old-analyzer stateless shard was mine and is fixed (the test is analyzer-only and is now tagged no-old-analyzer).

@groeneai

groeneai commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Confirmed: every test passed on all three jobs (1141, 949 and 1189 passed, zero failed), and only the job-level guard failed them. Each half already has an owner, so there is nothing new for me to author here.

The victim class in each job's own kernel record picks the owner. Every kill is oom_memcg=/docker/<dind>/docker:

shard CONSTRAINT_MEMCG kills victims fixing PR
2/6 2 gdb x2 #117202, merged 2026-08-31
5/6 3 gdb x3 #117202
6/6 6 gdb x4, clickhouse x2 gdb: #117202. clickhouse: #117412, merged 2026-09-01, plus #117564

2865d955 predates both. Its real merge base is 54a63093 (2026-08-31T08:29:34Z), taken from each job's own Merge ... into ... line rather than from the clock: compare/<fix merge commit>...54a63093 is ahead_by=0 against both #117202 and #117412, so the base is a strict ancestor of each and carries neither. The jobs' own environment agrees: CI_DIND_INIT_RESERVE=17179869184 with /docker: peak 40.78 GiB of 40.78 GiB, which is the pre-#117412 sizing (INTEGRATION_DIND_INIT_RESERVE is min(max(LIMITED_MEM // 3, 8 * 1024**3), 16 * 1024**3) at that base and 8 * 1024**3 at master). Your current head 9f3902d5 is behind_by=0 against both, so only the 6/6 residual below applies to it.

Per shard, not in aggregate. Trees carrying the /docker row since 2026-09-02T00:00:00Z, a window that excludes the pre-#117412 arm:

1/6  0/487      2/6  0/488      3/6  0/484
4/6  0/485      5/6  0/487      6/6  78/486 = 16.1%

The entire live residual is 6/6, and there it is a container leak rather than sizing. test_refreshable_mat_view/test.py:33 and test_refreshable_mat_view_replicated/test.py:37 still declare started_cluster with scope="session" at master, so a leaf module's 10 ClickHouse servers plus its MinIO, nginx and resolver containers stay resident until the xdist worker's session ends instead of when its module ends. Those two modules run on 6/6 only (153 and 61 mentions in its log, 0 in the 2/6 and 5/6 logs), which is what ties the two task=clickhouse victims to them. #117564 changes the three fixture scopes and is open.

I could not find an open issue either, and I have not filed one: two merged fixes plus an open successor track this more precisely than a new issue would. Say so and I will file it.

@clickhouse-gh clickhouse-gh Bot added the comp-query-analyzer Semantic analysis + logical/physical planning + rewrites (Analyzer and Planner modules). label Sep 4, 2026
alexey-milovidov and others added 2 commits September 10, 2026 05:07
Master took `05079` for two other tests, so move
`05079_chain_to_in_fixed_string_padding` to `05166`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (the branch was ~3800 commits behind) and renumbered the test to 05166_chain_to_in_fixed_string_padding, because master meanwhile took 05079 for two other tests. The test passes locally against the merged build, and the diff against master is unchanged otherwise.

Both reds on 1209779b are unrelated to this pull request, which only touches analyzer passes for String/FixedString comparisons:

1. AST fuzzer (amd_release, oracle) — subquery-wrap oracle mismatch. The reproducer has no string columns at all, so stringFamilyPairIsNotEqualityEquivalent (the only behaviour this pull request adds) never fires for it:

SELECT 1, * FROM (SELECT 2 AS x) AS a LEFT JOIN (SELECT 1, 3 AS y) AS b ON y = x
-- 1  2  0  0
SELECT * FROM (SELECT 1, * FROM (SELECT 2 AS x) AS a LEFT JOIN (SELECT 1, 3 AS y) AS b ON y = x)
-- 0  2  0  0

I reproduced it on an unrelated build of the same master revision, so it is not caused by this branch. It is the duplicate-output-name class already tracked by #118739 and #118986 (here both the outer constant and b's constant are named 1, and wrapping makes the outer one take the joined value).

2. Stress test (arm_debug) — Logical error: 'storage.is_readonly'. This is chassert(storage.is_readonly) in ReplicatedMergeTreeRestartingThread::runImpl (src/Storages/MergeTree/ReplicatedMergeTreeRestartingThread.cpp:134), reached on the first activation when the replica is not readonly but the ZooKeeper session has expired. It is a replication-startup race in a debug assertion, with no relation to an analyzer pass. CIDB shows no other occurrence in 60 days and I could not find an open issue or pull request for it.

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117293&sha=1209779bd81c5de44849dc0908019d0bda7b670a&name_0=PR&name_1=Stress%20test%20%28arm_debug%29 and provide a fix in a separate pull request. If the fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

Acknowledged. There is no fix in progress for this one: the signature (STID 2508-4d0e) has exactly one occurrence in 90 days of CIDB and I found no open issue or pull request for it, so I am investigating and will follow up here with a separate pull request.

Comment thread src/Analyzer/Utils.cpp Resolved
@groeneai

Copy link
Copy Markdown
Collaborator

Fix: #119264

ReplicatedMergeTreeRestartingThread::run has two executors: its own BackgroundSchedulePool task, whose executions are serialized by exec_mutex, and the inline restarting_thread.run the attach path takes, which bypasses the task. The task is created schedulable, so the inline activation can be overtaken by its own side effects: runImpl arms queue_updating_task, the session expires, queueUpdatingTask catches ZSESSIONEXPIRED and calls restarting_thread.wakeup, and a pool thread enters run while the inline executor is still between setNotReadonly and first_time = false. It then reads first_time == true with is_readonly == false, which is exactly the state the assertion rules out, and the stack in your report aborts on the pool executor.

The fix is one line: create the task deactivated, which is the convention the storage constructor already states for its other tasks. The refused wakeup is coalesced by the start(/*schedule=*/ true) the attach path runs immediately after, not lost.

A new integration test forces the interleaving with a failpoint plus SYSTEM RECONNECT ZOOKEEPER. It aborts the server in 5 of 5 runs without the one-line change and passes 20 of 20 with it.

alexey-milovidov and others added 3 commits September 10, 2026 18:33
…the test

`equals` compares floating-point values numerically, while the set built for `IN` is
keyed on the raw bits: `-0.0 = 0.0` is true but `-0.0 IN (0.0)` is false, and `nan = nan`
is false but `nan IN (nan)` is true. Rewriting `f = 0.0 OR f = 1.0 OR f = 2.0` into
`f IN (0.0, 1.0, 2.0)` therefore lost the `-0.0` rows, and the `NOT IN` direction had the
symmetric bug. Decline both chain rewrites when the expression's type contains a float
(`Float32`, `Float64`, `BFloat16`, also inside `Nullable`, `LowCardinality`, `Array`, `Tuple`
and `Map`), the same way `HasToInPass` already does.

The existing test is renumbered from `05166` to `05227` because `master` took `05166` for
other tests meanwhile.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator

Verified the test gap raised on #121770 (two equals on one expression), and measured the block both ways against this PR.

The file covers the IN / NOT IN chains and the equality-plus-inequality pair, but not two equals on the same expression. That shape needs no chain and no settings: optimize_redundant_comparisons is true by default and is not randomized by clickhouse-test, and addComparisonFilter compares the converted constant 'a\0', so the conjunction folds to constant false while both of its terms are true.

Measured on master 95a6488, the same commit with and without this PR's src/ diff. The four files the PR touches are byte-identical between 95a6488 and its base 0fb497f8 (git diff over them is empty), so this is your head's behaviour on these paths:

query on t_chain_fixed_string (one row, 'a') without with expected
SELECT s = 'a' AND s = toFixedString('a', 2), s = 'a', s = toFixedString('a', 2) 0 1 1 1 1 1 1 1 1
WHERE s = 'a' AND s = toFixedString('a', 2) 0 1 1
the same over toLowCardinality(s) 0 1 1
WHERE s = 'a' AND s = 'b' (control) 0 0 0

EXPLAIN QUERY TREE for the second row is WHERE CONSTANT id: 4, constant_value: UInt64_0 without the diff; with it both equals survive under the and. A LowCardinality(String) column measures the same as toLowCardinality(s), so the block needs no second table. Reversing the operands (s = toFixedString('a', 2) AND s = 'a') behaves identically.

Block, to go in before the final DROP TABLE:

-- Two `equals` on the same expression need no chain: the `FixedString` constant converts to
-- `'a\0'`, which contradicts `s = 'a'`, so the conjunction was folded to constant false while
-- both of its terms are true. `optimize_redundant_comparisons` is on by default here.
SELECT 'equals pair';
SELECT (s = 'a' AND s = toFixedString('a', 2)) AS pair,
       (s = 'a') AS lhs,
       (s = toFixedString('a', 2)) AS rhs
FROM t_chain_fixed_string;
SELECT count() FROM t_chain_fixed_string WHERE s = 'a' AND s = toFixedString('a', 2);
SELECT count() FROM t_chain_fixed_string WHERE toLowCardinality(s) = 'a' AND toLowCardinality(s) = toFixedString('a', 2);
-- A pair of same-type constants is still folded.
SELECT count() FROM t_chain_fixed_string WHERE s = 'a' AND s = 'b';

and for .reference:

equals pair
1	1	1
1
1
0

With the block appended, the file's output on your code is exactly the current .reference plus those five lines, and three of the five differ without the diff. Flipping optimize_extract_common_expressions, which clickhouse-test does randomize, leaves both columns unchanged.

Not pushing to your branch and not opening a competing PR: take the block or drop it as you prefer.

alexey-milovidov and others added 2 commits September 24, 2026 00:50
`ORDER BY f` ties `-0.0` with `0.0`, so their relative order varied between runs and the
test failed in `Stateless tests (amd_debug, parallel)` and the flaky check. Order by
`toString(f)` instead, which yields the reference order.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117293&sha=b5a565ca735c0ba7a006740105dfdf4a663e311e&name_0=PR

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… or `LowCardinality` floats

`has` compares only `Float32` and `Float64` numerically. An `Array(BFloat16)` goes through the
generic column comparison and an `Array(LowCardinality(Float64))` through dictionary lookup; both
match a stored NaN, while the `equals` in the lambda does not. Keep the plain-float exemption only
for `Float32` / `Float64` elements that are not dictionary-encoded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: 03821_drop_workload_during_query_race in https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117293&sha=fbcefb1a3852e32ca14449a3892192166788ec31&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20AsyncInsert%2C%20s3%20storage%2C%20sequential%29 (exception from RequestQueue::enqueueRequest printed while the workload is dropped during a query; unrelated to this PR) and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

Already fixed by my #126345 (merged 2026-10-19 10:34 UTC), so I am not opening a new PR.

This CI run was created 2026-10-18 07:17 UTC, so the merge commit it tested predates the fix. Its stdout is exactly what that PR handles: RequestQueue::enqueueRequest throws INVALID_SCHEDULER_NODE (expected for a query in a just-dropped workload) from the CPULeaseAllocation constructor on the query thread, and the test's old line-by-line grep -v let the stack frames through. 61/61 reruns passed.

Since the merge the test ran 861 times on master; its 3 failures there are on commits from before the merge, and every PR failure since comes from a workflow created before it. The CI for the new head 1919c10a was dispatched after the merge, so the tree it tests already includes the fix.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, thanks for confirming that 03821_drop_workload_during_query_race was fixed by #126345. CI on the current head 1919c10 is green, and no review threads are unresolved, so this PR needs nothing more from me.

alexey-milovidov and others added 7 commits October 26, 2026 07:56
…members into set lookups

`equals` and `notEquals` on tuples propagate the NULL of a member, while set
membership and `has` treat it as an ordinary value. Decline the equality chain
to `IN`, the inequality chain to `NOT IN`, and the `arrayExists` to `has`
rewrites when either side is a tuple with a `Nullable` member.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ullable` members

The previous commit stops rewriting an equality chain over a tuple with a
`Nullable` member into a set lookup, because tuple `equals` propagates the
member's NULL while membership treats it as a value. The test pinned the old
rewrite of `tu = (1, 1) OR ...` for `tu Tuple(Nullable(Int32), Int32)`; it now
expects the chain to stay as it is. The result lines are unchanged.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117293&sha=217cb5aad77fdae4c27ae5939451ede3ebde8cc1&name_0=PR&name_1=Fast%20test
#117293

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…NULL

`tupleHasNullableMember` checked only for a `Nullable` wrapper, so a tuple member of type
`Variant` (or `Dynamic`), which carries NULL without one, passed the guard. `equals` on
`Tuple(Variant(UInt64))` propagates the member's NULL while set membership and `has` treat it
as a value, so the equality chain to `IN`, the inequality chain to `NOT IN`, and the
`arrayExists` to `has` rewrites still changed results.

Rename the helper to `tupleMemberCanContainNull` and test each member with `canContainNull`.
Test `05453_chain_to_in_tuple_variant_member` covers the reviewer's reproducers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ng_distributed` reachable

The test added on master asserts that `x = ... OR x = ... OR x = ...` over
`Tuple(DateTime, Variant(UInt64))` is rewritten into `IN`. This PR makes that
rewrite decline for tuples with a member that can contain NULL, because tuple
`equals` propagates the member's NULL while set membership does not. Move the
`Variant` into an `Array` member, which compares its elements as values, so the
rewrite still fires and the test still checks that the named member type and the
raw `DateTime` timestamp survive serialization to a secondary server.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117293&sha=1e6af916dcf7f00101051cd32905631e56664c9c&name_0=PR&name_1=Fast%20test
PR: #117293

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master and fixed the Fast test failure in 05059_nested_variant_constant_folding_distributed (940ac9e). The test was added on master and expects the OR-to-IN rewrite over Tuple(DateTime, Variant(UInt64)). This PR now declines that rewrite on purpose, because a Variant tuple member can hold NULL. The test now puts the Variant inside an Array member, so the rewrite still fires and the test still checks how the named member type and the raw DateTime timestamp are serialized. On a local server the old section returns 1, 0, as in CI, and the new one returns 1, 1. 05452 and 05453 still pass.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The only failure on 940ac9e, 05397_clickhouse_local_locked_path_untouched in Fast test (arm_darwin), is unrelated to this PR. It was fixed on master by #128088 (skip the test on macOS), so I merged master (8500a26) to pull in the fix. The merge was clean and did not touch src/Analyzer.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (37c966452c02) to refresh the branch, which was last updated on 2026-10-30. The merge was clean. clickhouse builds, and all 11 of this PR's own chain-to-IN and arrayExists-to-has tests pass locally. The two 05059 tests need a server, so they will be checked by CI; neither changed on master since the last green run. There are no unresolved review threads.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The only failure on 37c966452c02, Upgrade check (amd_release), is unrelated to this PR: GitHub returned 504 Gateway Time-out on all 10 attempts to download the previous release package (v26.10.2.103-stable/clickhouse-client_26.10.2.103_amd64.deb), so the check reported Failed to download previous release packages before testing anything (report). All other checks pass. I re-ran the failed job.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (be845e6d1383) to refresh the branch, which was last updated on 2026-11-08. The merge was clean, and the PR's diff against master is unchanged. clickhouse builds, and all 11 of this PR's chain-to-IN and arrayExists-to-has tests pass locally. The two 05059 tests need a server with test clusters, so CI will check them. There are no unresolved review threads.

alexey-milovidov and others added 2 commits November 20, 2026 00:49
…ed-string-padding

Conflict in `05059_nested_variant_constant_folding_distributed.sql`: master
(#113470) made the `OR`-to-`IN`
rewrite decline any `Variant` in the expression type and moved the `Variant`
into the constants only, while this PR made the rewrite decline a tuple constant
with a `Variant` member and moved the `Variant` into an `Array`. Together no
`Tuple` chain with a `Variant` reaches the rewrite (`Array(UInt64)` vs
`Array(Variant(UInt64))` does not type-check either), so the case is split in
two: a `Tuple(DateTime, UInt64)` chain pins the raw `DateTime` timestamp in the
`IN` constant, and a `UInt64` chain with `Variant` constants pins the named
member cast.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Master (#113470) now declines the
equality-chain-to-`IN` rewrite for any expression with a `Variant` in its type,
including a single-alternative `Variant(UInt64)`, so the "still rewritten"
check no longer holds. Keep it as a positive control on a plain `UInt64`
column, which shows the float guard does not over-decline.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117293&sha=092c493e7704049920edf85219ee565d1752ade2&name_0=PR&name_1=Fast%20test
PR: #117293

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Fixed the Fast test failure in 05243_chain_to_in_float_variant (c4dfc5c). After the last master merge, #113470 makes the equality-chain-to-IN rewrite decline for any expression with a Variant in its type, including a single-alternative Variant(UInt64). That broke the test's "still rewritten" check. The check is now a positive control on a plain UInt64 column. The rest of this PR's chain-to-IN and arrayExists-to-has tests pass locally on the merged tree. The Finish Workflow failure only happened because Bugfix validation was dropped after Fast test failed.

…ed-string-padding

Conflict in `LogicalExpressionOptimizerPass.cpp`: keep both the `stringFamilyPairIsNotEqualityEquivalent` / `tupleMemberCanContainNull` guards of this branch and the `loses_type_in_field` guard for `Variant` and `Dynamic` constants added on master.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@alexey-milovidov

alexey-milovidov commented Nov 23, 2026 •

Copy link
Copy Markdown
Member Author

🕵 Merged master (0b5613b71424) to resolve the conflict in LogicalExpressionOptimizerPass.cpp (8a7b8b2). It came from #133127, which added a loses_type_in_field guard for Variant and Dynamic constants in the same place where this PR adds the stringFamilyPairIsNotEqualityEquivalent and tupleMemberCanContainNull guards of the equals chain. Both sets of guards are kept. clickhouse builds, and the 11 chain-to-IN and arrayExists-to-has tests of this PR plus 05837_or_chain_to_in_variant_constant from master pass locally. The two 05059 tests need a server with test clusters and were not run locally, so CI will check them. The diff of the PR against master is unchanged, and there are no unresolved review threads.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-analyzer Semantic analysis + logical/physical planning + rewrites (Analyzer and Planner modules). pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

2 participants