id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 system NULL NULL NULL NULL 1
1 PRIMARY alias2 system NULL NULL NULL NULL 1
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
test case:
SET SESSION optimizer_switch='semijoin=off';
CREATE TABLE t1 ( f1 int );
INSERT INTO t1 VALUES (0),(0);
CREATE TABLE t2 ( f1 int , KEY (f1)) ;
INSERT INTO t2 VALUES (0);
SELECT MAX( alias1.f1 ) AS field1
FROM t2 AS alias1 , t2 AS alias2
WHERE ( 3 ) IN ( SELECT f1 FROM t1 )
HAVING field1 IS NOT NULL;
Here is an example where the subquery does not return a single null, but instead returns 1 or more rows. So , it is not such an edge case:
total optimizer switch in effect:
index_merge= on,index_ merge_union= on,index_ merge_sort_ union=on, index_merge_ intersection= on,index_ merge_sort_ intersection= off,index_ condition_ pushdown= on,derived_ merge=on, derived_ with_keys= on,firstmatch= off,loosescan= off,materializa tion=off, in_to_exists= on,semijoin= off,partial_ match_rowid_ merge=on, partial_ match_table_ scan=on, subquery_ cache=off, mrr=on, mrr_cost_ based=off, mrr_sort_ keys=on, outer_join_ with_cache= off,semijoin_ with_cache= off,join_ cache_increment al=on,join_ cache_hashed= on,join_ cache_bka= on,optimize_ join_buffer_ size=on, table_eliminati on=on
minimal optimizer switch: semijoin=off
explain:
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 system NULL NULL NULL NULL 1
1 PRIMARY alias2 system NULL NULL NULL NULL 1
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
test case:
SET SESSION optimizer_ switch= 'semijoin= off';
CREATE TABLE t1 ( f1 int );
INSERT INTO t1 VALUES (0),(0);
CREATE TABLE t2 ( f1 int , KEY (f1)) ;
INSERT INTO t2 VALUES (0);
SELECT MAX( alias1.f1 ) AS field1
FROM t2 AS alias1 , t2 AS alias2
WHERE ( 3 ) IN ( SELECT f1 FROM t1 )
HAVING field1 IS NOT NULL;