Note 1003 select `test`.`t3`.`b` AS `b`,`test`.`t1`.`a` AS `a` from `test`.`t3` left join (`test`.`t2` join `test`.`t1`) on((`test`.`t3`.`a` <> 0)) where ((`test`.`t1`.`a` = `test`.`t1`.`a`) or (`test`.`t3`.`b` <> 0))
DROP VIEW v1;
DROP TABLE t1,t2,t3;
#
# LP bug #806510: subquery with outer reference
# to a derived_table/view
#
CREATE TABLE t1 (a int) ;
INSERT INTO t1 VALUES (4), (NULL);
CREATE TABLE t2 (a int) ;
INSERT INTO t2 VALUES (8), (0);
CREATE TABLE t3 (a int, b int) ;
INSERT INTO t3 VALUES (7,8);
CREATE VIEW v1 AS SELECT * FROM t1;
SELECT * FROM t1 t
WHERE EXISTS (SELECT t3.a FROM t3, t2
WHERE t2.a = t3.b AND t.a != 0);
a
4
EXPLAIN
SELECT * FROM t1 t
WHERE EXISTS (SELECT t3.a FROM t3, t2
WHERE t2.a = t3.b AND t.a != 0);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t ALL NULL NULL NULL NULL 2 Using where
2 DEPENDENT SUBQUERY t3 system NULL NULL NULL NULL 1
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where
SELECT * FROM (SELECT * FROM t1) t
WHERE EXISTS (SELECT t3.a FROM t3, t2
WHERE t2.a = t3.b AND t.a != 0);
a
4
EXPLAIN
SELECT * FROM (SELECT * FROM t1) t
WHERE EXISTS (SELECT t3.a FROM t3, t2
WHERE t2.a = t3.b AND t.a != 0);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
3 DEPENDENT SUBQUERY t3 system NULL NULL NULL NULL 1
3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where
SELECT * FROM v1 t
WHERE EXISTS (SELECT t3.a FROM t3, t2
WHERE t2.a = t3.b AND t.a != 0);
a
4
EXPLAIN
SELECT * FROM v1 t
WHERE EXISTS (SELECT t3.a FROM t3, t2
WHERE t2.a = t3.b AND t.a != 0);
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 DEPENDENT SUBQUERY t3 system NULL NULL NULL NULL 1
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where