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
Bug#21067109: Assert 'join == __NULL' failed in ::optimize()
Patch # 4 of 5
Currently, optimize_cond() builds multiple equalities for all WHERE
conditions and all join conditions. But there is one omission: If
WHERE condition is NULL, then no multiple equalities are built for
any join conditions.
This patch fixes that problem by the following logic:
- Invoke optimize_cond() when we have a WHERE condition or an outer join
(an outer join usually implies at least one join condition).
- Inside optimize_cond(), call build_equal_items() whenever there is a
join list (ie this is not called for HAVING).
- build_equal_items() then inspects the WHERE clause and the various
join conditions, and analyzes any conditions that are not NULL.
There are several test changes due to this patch. Most changes just
reverse the order that operands are tested, this is due to the nature
of multiple equality processing. The more interesting test changes are
documented below.
Test change in main.subquery_sj_all:
select * from t1 left join t2 on (t2.A= t1.A And t2.A in (select pk from t10));
Due to multiple equality analysis, a table with REF access is shifted up
so that it can be evaluated before a table where table scan is applied.
SELECT *
FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a AND
(ot1.a, ot2.a) IN (SELECT it1.a, it2.a
Due to multiple equality analysis, a join condition can be evaluated earlier
than it used to be.
Test change in main.derived:
SELECT * FROM (SELECT v1.a
FROM v1 LEFT OUTER JOIN v2 ON v1.a = v2.b
WHERE v1.a = 3
GROUP BY v1.a) p, t q
WHERE q.id BETWEEN 1 AND 10;
Due to the multiple equality analysis, a "func" ref is changed to a "const",
which is slightly simpler to evaluate.
Test change in main.join_nested:
Two queries have a WHERE clause moved from third to second table in
join order.
Test change in main.join_outer:
Comparison against column is replaced with comparison against literal due
to multiple equality analysis.
Copy file name to clipboardExpand all lines: mysql-test/r/derived.result
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -3048,7 +3048,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
3048
3048
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
3049
3049
4 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
3050
3050
Warnings:
3051
-
Note 1003 /* select#1 */ select `test`.`sq1_t1`.`pk` AS `field1`,`test`.`sq2_t1`.`pk` AS `field2` from `test`.`t2` `table3` left join (`test`.`t2` `sq2_t1`) on(((NULL = `test`.`sq2_t1`.`col_varchar_key`) and (not(<in_optimizer>(`test`.`sq2_t1`.`col_int_key`,<exists>(/* select#4 */ select 1 from `test`.`t2` `child_sq1_t1` where <if>(outer_field_is_not_null, ((<cache>(`test`.`sq2_t1`.`col_int_key`) = NULL) or isnull(NULL)), true) having <if>(outer_field_is_not_null, <is_not_null_test>(NULL), true))))))) left join (`test`.`t1` `sq1_t1`) on((NULL = `test`.`sq2_t1`.`col_varchar_key`))
3051
+
Note 1003 /* select#1 */ select `test`.`sq1_t1`.`pk` AS `field1`,`test`.`sq2_t1`.`pk` AS `field2` from `test`.`t2` `table3` left join (`test`.`t2` `sq2_t1`) on(((not(<in_optimizer>(`test`.`sq2_t1`.`col_int_key`,<exists>(/* select#4 */ select 1 from `test`.`t2` `child_sq1_t1` where <if>(outer_field_is_not_null, ((<cache>(`test`.`sq2_t1`.`col_int_key`) = NULL) or isnull(NULL)), true) having <if>(outer_field_is_not_null, <is_not_null_test>(NULL), true))))) and multiple equal(NULL, `test`.`sq2_t1`.`col_varchar_key`))) left join (`test`.`t1` `sq1_t1`) on(multiple equal(NULL, `test`.`sq2_t1`.`col_varchar_key`))
3052
3052
SELECT table1.pk AS field1,
3053
3053
table2.pk field2
3054
3054
FROM (SELECT sq1_t1.*
@@ -3454,9 +3454,9 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
3454
3454
1 PRIMARY q NULL range PRIMARY PRIMARY 4 NULL 4 100.00 Using where
3455
3455
1 PRIMARY <derived2> NULL ALL NULL NULL NULL NULL 8 100.00 Using join buffer (Block Nested Loop)
3456
3456
2 DERIVED t NULL ALL NULL NULL NULL NULL 4 100.00 Using temporary; Using filesort
3457
-
2 DERIVED t NULL ref c2 c2 5 func 2 100.00 Using where; Using index
3457
+
2 DERIVED t NULL ref c2 c2 5 const 2 100.00 Using where; Using index
3458
3458
Warnings:
3459
-
Note 1003 /* select#1 */ select `p`.`a` AS `a`,`test`.`q`.`id` AS `id`,`test`.`q`.`c1` AS `c1`,`test`.`q`.`c2` AS `c2` from (/* select#2 */ select `test`.`t`.`c1` AS `a` from `test`.`t` left join (`test`.`t`) on(((`test`.`t`.`c1` = `test`.`t`.`c2`) and (`test`.`t`.`c1` = 10) and (`test`.`t`.`c2` > 3))) where 1 group by `test`.`t`.`c1`) `p` join `test`.`t` `q` where (`test`.`q`.`id` between 1 and 10)
3459
+
Note 1003 /* select#1 */ select `p`.`a` AS `a`,`test`.`q`.`id` AS `id`,`test`.`q`.`c1` AS `c1`,`test`.`q`.`c2` AS `c2` from (/* select#2 */ select `test`.`t`.`c1` AS `a` from `test`.`t` left join (`test`.`t`) on(((`test`.`t`.`c1` = 10) and (`test`.`t`.`c2` = 10) and (10 > 3))) where 1 group by `test`.`t`.`c1`) `p` join `test`.`t` `q` where (`test`.`q`.`id` between 1 and 10)
2 DERIVED it_b NULL ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (Block Nested Loop)
1025
1025
Warnings:
1026
-
Note 1003 /* select#1 */ select distinct `subselect`.`b` AS `b` from `test`.`t1` left join (/* select#2 */ select `test`.`it_b`.`a` AS `a`,`test`.`it_b`.`b` AS `b` from `test`.`t1` `it_a` left join `test`.`t1` `it_b` on(TRUE) where 1) `subselect` on((`test`.`t1`.`a` = `subselect`.`b`)) where 1
1026
+
Note 1003 /* select#1 */ select distinct `subselect`.`b` AS `b` from `test`.`t1` left join (/* select#2 */ select `test`.`it_b`.`a` AS `a`,`test`.`it_b`.`b` AS `b` from `test`.`t1` `it_a` left join `test`.`t1` `it_b` on(TRUE) where 1) `subselect` on((`subselect`.`b` = `test`.`t1`.`a`)) where 1
1027
1027
SELECT DISTINCT subselect.b
1028
1028
FROM t1 LEFT JOIN
1029
1029
(SELECT it_b.* FROM t1 as it_a LEFT JOIN t1 as it_b ON true) AS subselect
@@ -1057,7 +1057,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
1057
1057
1 SIMPLE t3 NULL const PRIMARY NULL NULL NULL 1 100.00 Impossible ON condition
1058
1058
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 2 100.00 Using temporary; Distinct
1059
1059
Warnings:
1060
-
Note 1003 /* select#1 */ select distinct `test`.`t3`.`a` AS `t3_date` from `test`.`t1` left join `test`.`t3` on((NULL = `test`.`t3`.`b`)) where 1 limit 1
1060
+
Note 1003 /* select#1 */ select distinct `test`.`t3`.`a` AS `t3_date` from `test`.`t1` left join `test`.`t3` on(multiple equal(NULL, `test`.`t3`.`b`)) where 1 limit 1
Copy file name to clipboardExpand all lines: mysql-test/r/explain_json_all.result
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2463,7 +2463,7 @@ EXPLAIN
2463
2463
} /* query_block */
2464
2464
}
2465
2465
Warnings:
2466
-
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,group_concat(`test`.`t2`.`b` separator ',') AS `b` from `test`.`t1` left join `test`.`t2` on((`test`.`t1`.`a` = `test`.`t2`.`a`)) where 1 group by `test`.`t1`.`a` order by `test`.`t1`.`b`
2466
+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,group_concat(`test`.`t2`.`b` separator ',') AS `b` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`a` = `test`.`t1`.`a`)) where 1 group by `test`.`t1`.`a` order by `test`.`t1`.`b`
Copy file name to clipboardExpand all lines: mysql-test/r/explain_json_none.result
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2508,7 +2508,7 @@ EXPLAIN
2508
2508
} /* query_block */
2509
2509
}
2510
2510
Warnings:
2511
-
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,group_concat(`test`.`t2`.`b` separator ',') AS `b` from `test`.`t1` left join `test`.`t2` on((`test`.`t1`.`a` = `test`.`t2`.`a`)) where 1 group by `test`.`t1`.`a` order by `test`.`t1`.`b`
2511
+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,group_concat(`test`.`t2`.`b` separator ',') AS `b` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`a` = `test`.`t1`.`a`)) where 1 group by `test`.`t1`.`a` order by `test`.`t1`.`b`
Note 1003 /* select#1 */ select `test`.`dept`.`dname` AS `dname`,count(0) AS `COUNT(*)` from `test`.`emp` left join `test`.`dept` on((`test`.`emp`.`deptno` = `test`.`dept`.`deptno`)) where 1 group by `test`.`dept`.`deptno`
1651
+
Note 1003 /* select#1 */ select `test`.`dept`.`dname` AS `dname`,count(0) AS `COUNT(*)` from `test`.`emp` left join `test`.`dept` on((`test`.`dept`.`deptno` = `test`.`emp`.`deptno`)) where 1 group by `test`.`dept`.`deptno`
Note 1003 /* select#1 */ select `test`.`dept`.`dname` AS `dname`,count(0) AS `COUNT(*)` from `test`.`emp` left join `test`.`dept` on((`test`.`emp`.`deptno` = `test`.`dept`.`deptno`)) where 1 group by `test`.`dept`.`deptno`
1037
+
Note 1003 /* select#1 */ select `test`.`dept`.`dname` AS `dname`,count(0) AS `COUNT(*)` from `test`.`emp` left join `test`.`dept` on((`test`.`dept`.`deptno` = `test`.`emp`.`deptno`)) where 1 group by `test`.`dept`.`deptno`
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` left join `test`.`t2` on((`test`.`t1`.`b` = `test`.`t2`.`b`)) where 1 order by `test`.`t1`.`a`
123
+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`b` = `test`.`t1`.`b`)) where 1 order by `test`.`t1`.`a`
124
124
select * from t1 left join t2 on t1.b = t2.b order by t1.a;
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` left join `test`.`t2` on((`test`.`t1`.`a` = `test`.`t2`.`a`)) where 1 order by `test`.`t1`.`b`
1604
+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`a` = `test`.`t1`.`a`)) where 1 order by `test`.`t1`.`b`
1605
1605
select * from t1 left join t2 on t1.a = t2.a order by t1.b;
Copy file name to clipboardExpand all lines: mysql-test/r/join_cache_bka.result
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1479,7 +1479,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
1479
1479
1 SIMPLE t1 NULL index PRIMARY PRIMARY 4 NULL 8 100.00 Using index; Using temporary; Using filesort
1480
1480
1 SIMPLE t2 NULL ALL i_a NULL NULL NULL 10 100.00 Using where; Using join buffer (Block Nested Loop)
1481
1481
Warnings:
1482
-
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,count(`test`.`t2`.`p`) AS `count` from `test`.`t1` left join `test`.`t2` on(((`test`.`t1`.`a` = `test`.`t2`.`a`) and ((`test`.`t2`.`p` % 2) = 1))) where 1 group by `test`.`t1`.`a`
1482
+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,count(`test`.`t2`.`p`) AS `count` from `test`.`t1` left join `test`.`t2` on(((`test`.`t2`.`a` = `test`.`t1`.`a`) and ((`test`.`t2`.`p` % 2) = 1))) where 1 group by `test`.`t1`.`a`
1483
1483
select t1.a, count(t2.p) as count
1484
1484
from t1 left join t2 on t1.a=t2.a and t2.p % 2 = 1 group by t1.a;
1485
1485
a count
@@ -2110,7 +2110,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
2110
2110
1 SIMPLE t3 NULL eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index
2111
2111
1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 0 0.00 Using where
2112
2112
Warnings:
2113
-
Note 1003 /* select#1 */ select 1 AS `1` from `test`.`t2` left join (`test`.`t1` join `test`.`t3` left join `test`.`t4` on(1)) on((1 and (`test`.`t1`.`a` = `test`.`t3`.`pk`))) where 1
2113
+
Note 1003 /* select#1 */ select 1 AS `1` from `test`.`t2` left join (`test`.`t1` join `test`.`t3` left join `test`.`t4` on(1)) on(((`test`.`t3`.`pk` = `test`.`t1`.`a`) and 1)) where 1
2114
2114
SELECT 1
2115
2115
FROM t2 LEFT JOIN
2116
2116
((t1 JOIN t3 ON t1.a = t3.pk)
@@ -2161,7 +2161,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
2161
2161
1 SIMPLE t3 NULL ALL PRIMARY NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop)
2162
2162
1 SIMPLE t4 NULL index carrier_id carrier_id 5 NULL 2 100.00 Using where; Using index; Using join buffer (Block Nested Loop)
2163
2163
Warnings:
2164
-
Note 1003 /* select#1 */ select count(0) AS `COUNT(*)` from `test`.`t2` join `test`.`t1` left join (`test`.`t3` join `test`.`t4`) on(((`test`.`t3`.`carrier` = `test`.`t1`.`carrier`) and (`test`.`t3`.`id` = `test`.`t4`.`carrier_id`))) where 1
2164
+
Note 1003 /* select#1 */ select count(0) AS `COUNT(*)` from `test`.`t2` join `test`.`t1` left join (`test`.`t3` join `test`.`t4`) on(((`test`.`t4`.`carrier_id` = `test`.`t3`.`id`) and (`test`.`t3`.`carrier` = `test`.`t1`.`carrier`))) where 1
2165
2165
2166
2166
DROP TABLE t1,t2,t3,t4;
2167
2167
#
@@ -2562,7 +2562,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
2562
2562
1 SIMPLE t1 NULL index col_int_key,col_varchar_key col_varchar_key 7 NULL 3 100.00 Using index; Using temporary; Using filesort
Note 1003 /* select#1 */ select min(`test`.`t2`.`col_datetime_key`) AS `field1`,`test`.`t1`.`col_int_key` AS `field2` from `test`.`t1` left join `test`.`t2` FORCE INDEX (`col_varchar_key`) on((`test`.`t1`.`col_varchar_key` = `test`.`t2`.`col_varchar_key`)) where 1 group by `field2` order by `field1`
2565
+
Note 1003 /* select#1 */ select min(`test`.`t2`.`col_datetime_key`) AS `field1`,`test`.`t1`.`col_int_key` AS `field2` from `test`.`t1` left join `test`.`t2` FORCE INDEX (`col_varchar_key`) on((`test`.`t2`.`col_varchar_key` = `test`.`t1`.`col_varchar_key`)) where 1 group by `field2` order by `field1`
2566
2566
SELECT MIN(t2.col_datetime_key) AS field1,
2567
2567
t1.col_int_key AS field2
2568
2568
FROM t1
@@ -2622,7 +2622,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
2622
2622
1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 20 100.00 Using temporary; Using filesort
Note 1003 /* select#1 */ select `test`.`t2`.`col_varchar_key` AS `field1`,count(distinct `test`.`t1`.`col_varchar_nokey`) AS `COUNT(DISTINCT t1.col_varchar_nokey)`,`test`.`t2`.`pk` AS `field4` from `test`.`t2` left join `test`.`t1` on((`test`.`t2`.`pk` = `test`.`t1`.`col_int_key`)) where 1 group by `field1`,`field4` order by `test`.`t1`.`col_datetime_key`
2625
+
Note 1003 /* select#1 */ select `test`.`t2`.`col_varchar_key` AS `field1`,count(distinct `test`.`t1`.`col_varchar_nokey`) AS `COUNT(DISTINCT t1.col_varchar_nokey)`,`test`.`t2`.`pk` AS `field4` from `test`.`t2` left join `test`.`t1` on((`test`.`t1`.`col_int_key` = `test`.`t2`.`pk`)) where 1 group by `field1`,`field4` order by `test`.`t1`.`col_datetime_key`
2626
2626
SELECT t2.col_varchar_key AS field1 , COUNT(DISTINCT t1.col_varchar_nokey), t2.pk AS field4
2627
2627
FROM t1
2628
2628
RIGHT JOIN t2 ON t2.pk = t1.col_int_key
@@ -2728,7 +2728,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
2728
2728
1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (Block Nested Loop)
Note 1003 /* select#1 */ select `test`.`t2`.`pk` AS `t2_pk`,`test`.`t4`.`pk` AS `t4_pk`,`test`.`t4`.`k` AS `t4_k`,`test`.`t4`.`i` AS `t4_i` from `test`.`t1` left join `test`.`t2` on((`test`.`t1`.`k` = `test`.`t2`.`pk`)) left join `test`.`t3` on(`test`.`t3`.`i`) left join `test`.`t4` on((`test`.`t4`.`pk` = `test`.`t2`.`pk`)) where 1
2731
+
Note 1003 /* select#1 */ select `test`.`t2`.`pk` AS `t2_pk`,`test`.`t4`.`pk` AS `t4_pk`,`test`.`t4`.`k` AS `t4_k`,`test`.`t4`.`i` AS `t4_i` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`pk` = `test`.`t1`.`k`)) left join `test`.`t3` on(`test`.`t3`.`i`) left join `test`.`t4` on((`test`.`t4`.`pk` = `test`.`t2`.`pk`)) where 1
2732
2732
SELECT t2.pk as t2_pk, t4.pk as t4_pk, t4.k as t4_k, t4.i
0 commit comments