You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect optimization of multiple OR in the WHERE clause when analyzer is enabled #64487
With 3 or more variants provided in the WHERE clause with OR, a seemingly correct query returns zero results.
A minimal repro:
SET allow_experimental_analyzer=1;
CREATE OR REPLACETABLEfoo (i Date) ENGINE MergeTree ORDER BY i;
INSERT INTO foo VALUES ('2020-01-01');
INSERT INTO foo VALUES ('2020-01-02');
This query returns two records, as expected:
SELECT*FROMdefault.fooWHERE (default.foo.i = parseDateTimeBestEffort('2020-01-01'))
OR (default.foo.i = parseDateTimeBestEffort('2020-01-02'))
ORDER BY i ASCLIMIT1048575
However, if we add a third variant via OR, the query returns an empty result set:
SELECT*FROMdefault.fooWHERE (default.foo.i = parseDateTimeBestEffort('2020-01-01'))
OR (default.foo.i = parseDateTimeBestEffort('2020-01-02'))
OR (default.foo.i = parseDateTimeBestEffort('2020-01-03'))
ORDER BYdefault.foo.i ASCLIMIT1048575
It's a bug in query tree optimization (if you are interested, check out EXPLAIN QUERY TREE dump_ast = 1 for 3 conditions they are rewritten to default.foo.i IN (...) and seems this particular rewrite is incorrect). Current workaround is to disable this optimization with SET optimize_min_equality_disjunction_chain_length = 4294967295;
Activity
chloro-pn commentedon Jun 11, 2024
https://fiddle.clickhouse.com/acab3b08-7eee-427c-8cb6-fc0cd8bb6e2d
It seems that the In operator did not perform the correct type conversion
chloro-pn commentedon Jul 10, 2024
hi bro @yakov-olkhovskiy , have you started this task yet? If not, I found the bug here while fixing another bug. Do you need me to fix it ? : )

yakov-olkhovskiy commentedon Jul 10, 2024
@chloro-pn sure, go ahead, ping me from PR