Details
-
Bug
-
Status: In Progress (View Workflow)
-
Major
-
Resolution: Unresolved
-
11.4
-
None
-
Can result in unexpected behaviour
Description
EXPLAIN reports a subquery that the optimizer removed and that can never run; ANALYZE FORMAT=JSON shows r_loops 0 for the subquery's table.
create table t1 (t text character set utf8mb4); |
insert into t1 values ('a'),('b'); |
explain select * from t1 where t = 'b' and (1 = 1 or t = (select t from t1 limit 1)); |
explain select * from t1 where t = 'b' and 1 = 0 and t = (select t from t1 limit 1); |
drop table t1; |
id select_type table type possible_keys key key_len ref rows Extra
|
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
|
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
|
id select_type table type possible_keys key key_len ref rows Extra
|
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
|
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
|
The first WHERE reduces to t = 'b' and the second to Impossible WHERE, yet both plans list select#2. A constant IN shows the same thing, for example 'b' in ('b', (select t from t1 limit 1)) and t = 'b'.
The column is utf8mb4, the default character set in 11.8, so no multiple equality is built for t = (select ...). With latin1, the default in 11.4, the multiple equality evaluates the subquery once during optimization (Item_equal::add_const()), before the WHERE is folded. ANALYZE then shows r_loops 1 for the first two queries, on 11.4 and on 11.8 alike. EXPLAIN lists select#2 regardless of the character set. For a table created without a character set, 11.4 lists a subquery that ran once yet is no longer part of the plan, while 11.8 lists a subquery that never runs (r_loops 0). The constant IN example never runs the subquery under either character set.
Attachments
Issue Links
- relates to
-
MDEV-35845 WHERE COL IN (item0, item1, ..., itemN) AND COL = item1 Optimization
-
- In Review
-