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
'Not exists' optimization can be used for nested outer joins
only if IS NULL predicate from the WHERE condition is activated.
So we have to check that all guards that wrap this predicate
are in the 'open' state.
This patch supports usage of 'Not exists' optimization for any
outer join, no matter how it's nested in other outer joins.
This patch is also considered as a proper fix for bugs
#49322/#58490 and LP #817360.
1 SIMPLE t2a ALL NULL NULL NULL NULL 3 100.00 Using where
1923
+
1 SIMPLE t1i const PRIMARY PRIMARY 4 const 1 100.00 Using index
1924
+
1 SIMPLE t2i ALL NULL NULL NULL NULL 3 100.00 Using where; Not exists
1925
+
Warnings:
1926
+
Note 1003 select 1 AS `K1`,'T1Row1' AS `Name`,`test`.`t2a`.`K2` AS `K2`,`test`.`t2a`.`K1r` AS `K1r`,`test`.`t2a`.`rowTimestamp` AS `rowTimestamp`,`test`.`t2a`.`Event` AS `Event`,`test`.`t2i`.`K2` AS `K2B`,`test`.`t2i`.`K1r` AS `K1rB`,`test`.`t2i`.`rowTimestamp` AS `rowTimestampB`,`test`.`t2i`.`Event` AS `EventB` from `test`.`t1` `t1a` join `test`.`t2` `t2a` left join (`test`.`t1` `t1i` left join `test`.`t2` `t2i` on((`test`.`t2i`.`K1r` = 1))) on(((`test`.`t1i`.`K1` = 1) and (((`test`.`t2i`.`K1r` = 1) and (`test`.`t2i`.`rowTimestamp` > `test`.`t2a`.`rowTimestamp`)) or ((`test`.`t2i`.`rowTimestamp` = `test`.`t2a`.`rowTimestamp`) and (`test`.`t2i`.`K2` > `test`.`t2a`.`K2`)) or isnull(`test`.`t2i`.`K2`)))) where ((`test`.`t2a`.`K1r` = 1) and isnull(`test`.`t2i`.`K2`))
1927
+
CREATE VIEW v1 AS
1928
+
SELECT t2i.*
1929
+
FROM t1 as t1i LEFT JOIN t2 as t2i ON t2i.K1r = t1i.K1
1930
+
WHERE t1i.K1 = 1 ;
1931
+
SELECT
1932
+
t1a.*, t2a.*, t2b.K2 as K2B, t2b.K1r as K1rB,
1933
+
t2b.rowTimestamp as rowTimestampB, t2b.Event as EventB
1934
+
FROM
1935
+
t1 as t1a JOIN t2 as t2a ON t2a.K1r = t1a.K1
1936
+
LEFT JOIN
1937
+
v1 as t2b
1938
+
ON ((t2b.K1r = t1a.K1 AND t2b.rowTimestamp > t2a.rowTimestamp) OR
1939
+
(t2b.rowTimestamp = t2a.rowTimestamp AND t2b.K2 > t2a.K2))
1940
+
OR (t2b.K2 IS NULL)
1941
+
WHERE
1942
+
t1a.K1 = 1 AND
1943
+
t2b.K2 IS NULL;
1944
+
K1 Name K2 K1r rowTimestamp Event K2B K1rB rowTimestampB EventB
1 SIMPLE t2a ALL NULL NULL NULL NULL 3 100.00 Using where
1962
+
1 SIMPLE t1i const PRIMARY PRIMARY 4 const 1 100.00 Using index
1963
+
1 SIMPLE t2i ALL NULL NULL NULL NULL 3 100.00 Using where; Not exists
1964
+
Warnings:
1965
+
Note 1003 select 1 AS `K1`,'T1Row1' AS `Name`,`t2a`.`K2` AS `K2`,`t2a`.`K1r` AS `K1r`,`t2a`.`rowTimestamp` AS `rowTimestamp`,`t2a`.`Event` AS `Event`,`test`.`t2i`.`K2` AS `K2B`,`test`.`t2i`.`K1r` AS `K1rB`,`test`.`t2i`.`rowTimestamp` AS `rowTimestampB`,`test`.`t2i`.`Event` AS `EventB` from `test`.`t1` `t1a` join `test`.`t2` `t2a` left join (`test`.`t1` `t1i` left join `test`.`t2` `t2i` on((`test`.`t2i`.`K1r` = 1))) on(((`test`.`t1i`.`K1` = 1) and (((`test`.`t2i`.`K1r` = 1) and (`test`.`t2i`.`rowTimestamp` > `t2a`.`rowTimestamp`)) or ((`test`.`t2i`.`rowTimestamp` = `t2a`.`rowTimestamp`) and (`test`.`t2i`.`K2` > `t2a`.`K2`)) or isnull(`test`.`t2i`.`K2`)))) where ((`t2a`.`K1r` = 1) and isnull(`test`.`t2i`.`K2`))
1 SIMPLE t2a ALL NULL NULL NULL NULL 3 100.00 Using where
1934
+
1 SIMPLE t1i const PRIMARY PRIMARY 4 const 1 100.00 Using index
1935
+
1 SIMPLE t2i ALL NULL NULL NULL NULL 3 100.00 Using where; Not exists
1936
+
Warnings:
1937
+
Note 1003 select 1 AS `K1`,'T1Row1' AS `Name`,`test`.`t2a`.`K2` AS `K2`,`test`.`t2a`.`K1r` AS `K1r`,`test`.`t2a`.`rowTimestamp` AS `rowTimestamp`,`test`.`t2a`.`Event` AS `Event`,`test`.`t2i`.`K2` AS `K2B`,`test`.`t2i`.`K1r` AS `K1rB`,`test`.`t2i`.`rowTimestamp` AS `rowTimestampB`,`test`.`t2i`.`Event` AS `EventB` from `test`.`t1` `t1a` join `test`.`t2` `t2a` left join (`test`.`t1` `t1i` left join `test`.`t2` `t2i` on((`test`.`t2i`.`K1r` = 1))) on(((`test`.`t1i`.`K1` = 1) and (((`test`.`t2i`.`K1r` = 1) and (`test`.`t2i`.`rowTimestamp` > `test`.`t2a`.`rowTimestamp`)) or ((`test`.`t2i`.`rowTimestamp` = `test`.`t2a`.`rowTimestamp`) and (`test`.`t2i`.`K2` > `test`.`t2a`.`K2`)) or isnull(`test`.`t2i`.`K2`)))) where ((`test`.`t2a`.`K1r` = 1) and isnull(`test`.`t2i`.`K2`))
1938
+
CREATE VIEW v1 AS
1939
+
SELECT t2i.*
1940
+
FROM t1 as t1i LEFT JOIN t2 as t2i ON t2i.K1r = t1i.K1
1941
+
WHERE t1i.K1 = 1 ;
1942
+
SELECT
1943
+
t1a.*, t2a.*, t2b.K2 as K2B, t2b.K1r as K1rB,
1944
+
t2b.rowTimestamp as rowTimestampB, t2b.Event as EventB
1945
+
FROM
1946
+
t1 as t1a JOIN t2 as t2a ON t2a.K1r = t1a.K1
1947
+
LEFT JOIN
1948
+
v1 as t2b
1949
+
ON ((t2b.K1r = t1a.K1 AND t2b.rowTimestamp > t2a.rowTimestamp) OR
1950
+
(t2b.rowTimestamp = t2a.rowTimestamp AND t2b.K2 > t2a.K2))
1951
+
OR (t2b.K2 IS NULL)
1952
+
WHERE
1953
+
t1a.K1 = 1 AND
1954
+
t2b.K2 IS NULL;
1955
+
K1 Name K2 K1r rowTimestamp Event K2B K1rB rowTimestampB EventB
1 SIMPLE t2a ALL NULL NULL NULL NULL 3 100.00 Using where
1973
+
1 SIMPLE t1i const PRIMARY PRIMARY 4 const 1 100.00 Using index
1974
+
1 SIMPLE t2i ALL NULL NULL NULL NULL 3 100.00 Using where; Not exists
1975
+
Warnings:
1976
+
Note 1003 select 1 AS `K1`,'T1Row1' AS `Name`,`t2a`.`K2` AS `K2`,`t2a`.`K1r` AS `K1r`,`t2a`.`rowTimestamp` AS `rowTimestamp`,`t2a`.`Event` AS `Event`,`test`.`t2i`.`K2` AS `K2B`,`test`.`t2i`.`K1r` AS `K1rB`,`test`.`t2i`.`rowTimestamp` AS `rowTimestampB`,`test`.`t2i`.`Event` AS `EventB` from `test`.`t1` `t1a` join `test`.`t2` `t2a` left join (`test`.`t1` `t1i` left join `test`.`t2` `t2i` on((`test`.`t2i`.`K1r` = 1))) on(((`test`.`t1i`.`K1` = 1) and (((`test`.`t2i`.`K1r` = 1) and (`test`.`t2i`.`rowTimestamp` > `t2a`.`rowTimestamp`)) or ((`test`.`t2i`.`rowTimestamp` = `t2a`.`rowTimestamp`) and (`test`.`t2i`.`K2` > `t2a`.`K2`)) or isnull(`test`.`t2i`.`K2`)))) where ((`t2a`.`K1r` = 1) and isnull(`test`.`t2i`.`K2`))
1977
+
DROP VIEW v1;
1978
+
DROP TABLE t1,t2;
1884
1979
set optimizer_search_depth= @tmp_mdev621;
1885
1980
CREATE TABLE t5 (a int, b int, c int, PRIMARY KEY(a), KEY b_i (b));
1886
1981
CREATE TABLE t6 (a int, b int, c int, PRIMARY KEY(a), KEY b_i (b));
0 commit comments