set optimizer_switch='semijoin=on,materialization=on,firstmatch=on,loosescan=on,index_condition_pushdown=on,mrr=on'; SET sql_mode = 'NO_ENGINE_SUBSTITUTION'; create table t1 (id int); insert into t1 values (null), (0); create table t2 (id int); insert into t2 values (null); select * from t1, t2 where t1.id = t2.id; id id alter table t1 add key id (id); select * from t1, t2 where t1.id = t2.id; id id drop table t1,t2; create table t1 ( id integer, id2 integer not null, index (id), index (id2) ); insert into t1 values(null,null),(1,1); Warnings: Warning 1048 Column 'id2' cannot be null select * from t1; id id2 NULL 0 1 1 select * from t1 where id <=> null; id id2 NULL 0 select * from t1 where id <=> null or id > 0; id id2 NULL 0 1 1 select * from t1 where id is null or id > 0; id id2 NULL 0 1 1 select * from t1 where id2 <=> null or id2 > 0; id id2 1 1 select * from t1 where id2 is null or id2 > 0; id id2 1 1 delete from t1 where id <=> NULL; select * from t1; id id2 1 1 drop table t1; CREATE TABLE t1 (a int); CREATE TABLE t2 (a int, b int, INDEX idx(a)); CREATE TABLE t3 (b int, INDEX idx(b)); CREATE TABLE t4 (b int, INDEX idx(b)); INSERT INTO t1 VALUES (1), (2), (3), (4); INSERT INTO t2 VALUES (1, 1), (3, 1); INSERT INTO t3 VALUES (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL); INSERT INTO t4 SELECT * FROM t3; INSERT INTO t3 SELECT * FROM t4; INSERT INTO t4 SELECT * FROM t3; INSERT INTO t3 SELECT * FROM t4; INSERT INTO t4 SELECT * FROM t3; INSERT INTO t3 SELECT * FROM t4; INSERT INTO t4 SELECT * FROM t3; INSERT INTO t3 SELECT * FROM t4; INSERT INTO t4 SELECT * FROM t3; INSERT INTO t3 SELECT * FROM t4; INSERT INTO t4 SELECT * FROM t3; INSERT INTO t3 SELECT * FROM t4; INSERT INTO t4 SELECT * FROM t3; INSERT INTO t3 SELECT * FROM t4; INSERT INTO t4 SELECT * FROM t3; INSERT INTO t3 SELECT * FROM t4; INSERT INTO t3 VALUES (2), (3); ANALYZE table t1, t2, t3; Table Op Msg_type Msg_text test.t1 analyze status OK test.t2 analyze status OK test.t3 analyze status OK SELECT COUNT(*) FROM t3; COUNT(*) 15972 EXPLAIN SELECT SQL_CALC_FOUND_ROWS * FROM t1 LEFT JOIN t2 ON t1.a=t2.a LEFT JOIN t3 ON t2.b=t3.b; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL # 100.00 NULL 1 SIMPLE t2 NULL ALL idx NULL NULL NULL # 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t3 NULL ref idx idx 5 test.t2.b # 100.00 Using index Warnings: Warning 1287 SQL_CALC_FOUND_ROWS is deprecated and will be removed in a future release. Consider using two separate queries instead. Note 1003 /* select#1 */ select sql_calc_found_rows `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`b` AS `b` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`a` = `test`.`t1`.`a`)) left join `test`.`t3` on((`test`.`t3`.`b` = `test`.`t2`.`b`)) where true FLUSH STATUS ; SELECT SQL_CALC_FOUND_ROWS * FROM t1 LEFT JOIN t2 ON t1.a=t2.a LEFT JOIN t3 ON t2.b=t3.b; a a b b 1 1 1 NULL 3 3 1 NULL 2 NULL NULL NULL 4 NULL NULL NULL Warnings: Warning 1287 SQL_CALC_FOUND_ROWS is deprecated and will be removed in a future release. Consider using two separate queries instead. SELECT FOUND_ROWS(); FOUND_ROWS() 4 Warnings: Warning 1287 FOUND_ROWS() is deprecated and will be removed in a future release. Consider using COUNT(*) instead. SHOW STATUS LIKE "handler_read%"; Variable_name Value Handler_read_first 2 Handler_read_key 4 Handler_read_last 0 Handler_read_next 0 Handler_read_prev 0 Handler_read_rnd 0 Handler_read_rnd_next 8 DROP TABLE t1,t2,t3,t4; CREATE TABLE t1 ( a int(11) default NULL, b int(11) default NULL, KEY a (a,b) ); Warnings: Warning 1681 Integer display width is deprecated and will be removed in a future release. Warning 1681 Integer display width is deprecated and will be removed in a future release. INSERT INTO t1 VALUES (0,10),(0,11),(0,12); CREATE TABLE t2 ( a int(11) default NULL, b int(11) default NULL, KEY a (a) ); Warnings: Warning 1681 Integer display width is deprecated and will be removed in a future release. Warning 1681 Integer display width is deprecated and will be removed in a future release. INSERT INTO t2 VALUES (3,NULL),(3,11),(3,12); SELECT * FROM t2 inner join t1 WHERE ( t1.a = 0 OR t1.a IS NULL) AND t2.a = 3 AND t2.b = t1.b; a b a b 3 11 0 11 3 12 0 12 drop table t1, t2; End of 5.0 tests # # Bug#54608 Query using IN + OR + IS TRUE and IS NULL returns # NULL when should be empty # CREATE TABLE t1 (a INT, KEY (a)); INSERT INTO t1 VALUES (1), (2), (NULL); explain SELECT a FROM t1 WHERE a IN (42) OR (a IS TRUE AND a IS NULL); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ref_or_null a a 5 const 2 100.00 Using where; Using index Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 42) or (((0 <> `test`.`t1`.`a`) is true) and (`test`.`t1`.`a` is null))) SELECT a FROM t1 WHERE a IN (42) OR (a IS TRUE AND a IS NULL); a explain SELECT a FROM t1 WHERE a IN (42) OR (a=NULL); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ref_or_null a a 5 const # 100.00 Using where; Using index Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 42) or (`test`.`t1`.`a` = NULL)) SELECT a FROM t1 WHERE a IN (42) OR (a=NULL); a drop table t1; SET sql_mode = default; set optimizer_switch=default;