Commit 431ded10 authored by Igor Babaev's avatar Igor Babaev

Merge

parents 13ba0dd2 db1db8fa
...@@ -2122,4 +2122,45 @@ the value below *must* be 1 ...@@ -2122,4 +2122,45 @@ the value below *must* be 1
show status like 'Created_tmp_disk_tables'; show status like 'Created_tmp_disk_tables';
Variable_name Value Variable_name Value
Created_tmp_disk_tables 1 Created_tmp_disk_tables 1
#
# Bug #1002146: Unneeded filesort if usage of join buffer is not allowed
# (bug mdev-645)
#
CREATE TABLE t1 (pk int PRIMARY KEY, a int, INDEX idx(a));
INSERT INTO t1 VALUES (3,2), (2,3), (5,3), (6,4);
CREATE TABLE t2 (pk int PRIMARY KEY, a int, INDEX idx(a));
INSERT INTO t2 VALUES (9,0), (10,3), (6,4), (1,6), (3,100), (5,200);
set join_cache_level=0;
EXPLAIN
SELECT t2.a FROM t2 STRAIGHT_JOIN t1 ON t2.a <> 0 WHERE t2.a <> 6
GROUP BY t2.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range idx idx 5 NULL 5 Using where; Using index
1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 Using index
SELECT t2.a FROM t2 STRAIGHT_JOIN t1 ON t2.a <> 0 WHERE t2.a <> 6
GROUP BY t2.a;
a
3
4
100
200
set join_cache_level=default;
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='outer_join_with_cache=off';
EXPLAIN
SELECT t2.a FROM t2 LEFT JOIN t1 ON t2.a <> 0 WHERE t2.a <> 6
GROUP BY t2.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range idx idx 5 NULL 5 Using where; Using index
1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 Using where; Using index
SELECT t2.a FROM t2 LEFT JOIN t1 ON t2.a <> 0 WHERE t2.a <> 6
GROUP BY t2.a;
a
0
3
4
100
200
set optimizer_switch=@save_optimizer_switch;
DROP TABLE t1,t2;
# End of 5.3 tests # End of 5.3 tests
...@@ -2978,7 +2978,7 @@ EXPLAIN ...@@ -2978,7 +2978,7 @@ EXPLAIN
SELECT a FROM t1 t WHERE a IN (SELECT b FROM t1, t2 WHERE b = a) SELECT a FROM t1 t WHERE a IN (SELECT b FROM t1, t2 WHERE b = a)
GROUP BY a HAVING a != 'z'; GROUP BY a HAVING a != 'z';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t index idx_a idx_a 4 NULL 3 Using index; Using temporary; Using filesort 1 PRIMARY t index idx_a idx_a 4 NULL 1 Using index
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using where 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using where
2 MATERIALIZED t1 ref idx_a idx_a 4 test.t2.b 2 Using index 2 MATERIALIZED t1 ref idx_a idx_a 4 test.t2.b 2 Using index
...@@ -2992,7 +2992,7 @@ EXPLAIN ...@@ -2992,7 +2992,7 @@ EXPLAIN
SELECT a FROM t1 t WHERE a IN (SELECT b FROM t1, t2 WHERE b = a) SELECT a FROM t1 t WHERE a IN (SELECT b FROM t1, t2 WHERE b = a)
GROUP BY a HAVING a != 'z'; GROUP BY a HAVING a != 'z';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t index idx_a idx_a 4 NULL 3 Using index; Using temporary; Using filesort 1 PRIMARY t index idx_a idx_a 4 NULL 1 Using index
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using where 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using where
2 MATERIALIZED t1 ref idx_a idx_a 4 test.t2.b 2 Using index 2 MATERIALIZED t1 ref idx_a idx_a 4 test.t2.b 2 Using index
......
...@@ -1486,4 +1486,39 @@ DROP TABLE t1; ...@@ -1486,4 +1486,39 @@ DROP TABLE t1;
--echo the value below *must* be 1 --echo the value below *must* be 1
show status like 'Created_tmp_disk_tables'; show status like 'Created_tmp_disk_tables';
--echo #
--echo # Bug #1002146: Unneeded filesort if usage of join buffer is not allowed
--echo # (bug mdev-645)
--echo #
CREATE TABLE t1 (pk int PRIMARY KEY, a int, INDEX idx(a));
INSERT INTO t1 VALUES (3,2), (2,3), (5,3), (6,4);
CREATE TABLE t2 (pk int PRIMARY KEY, a int, INDEX idx(a));
INSERT INTO t2 VALUES (9,0), (10,3), (6,4), (1,6), (3,100), (5,200);
set join_cache_level=0;
EXPLAIN
SELECT t2.a FROM t2 STRAIGHT_JOIN t1 ON t2.a <> 0 WHERE t2.a <> 6
GROUP BY t2.a;
SELECT t2.a FROM t2 STRAIGHT_JOIN t1 ON t2.a <> 0 WHERE t2.a <> 6
GROUP BY t2.a;
set join_cache_level=default;
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='outer_join_with_cache=off';
EXPLAIN
SELECT t2.a FROM t2 LEFT JOIN t1 ON t2.a <> 0 WHERE t2.a <> 6
GROUP BY t2.a;
SELECT t2.a FROM t2 LEFT JOIN t1 ON t2.a <> 0 WHERE t2.a <> 6
GROUP BY t2.a;
set optimizer_switch=@save_optimizer_switch;
DROP TABLE t1,t2;
--echo # End of 5.3 tests --echo # End of 5.3 tests
...@@ -7422,8 +7422,9 @@ get_best_combination(JOIN *join) ...@@ -7422,8 +7422,9 @@ get_best_combination(JOIN *join)
if ( !(keyuse= join->best_positions[tablenr].key)) if ( !(keyuse= join->best_positions[tablenr].key))
{ {
j->type=JT_ALL; j->type=JT_ALL;
if (tablenr != join->const_tables) if (join->best_positions[tablenr].use_join_buffer &&
join->full_join=1; tablenr != join->const_tables)
join->full_join= 1;
} }
/*if (join->best_positions[tablenr].sj_strategy == SJ_OPT_LOOSE_SCAN) /*if (join->best_positions[tablenr].sj_strategy == SJ_OPT_LOOSE_SCAN)
...@@ -8436,7 +8437,9 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -8436,7 +8437,9 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
We will use join cache here : prevent sorting of the first We will use join cache here : prevent sorting of the first
table only and sort at the end. table only and sort at the end.
*/ */
if (i != join->const_tables && join->table_count > join->const_tables + 1) if (i != join->const_tables &&
join->table_count > join->const_tables + 1 &&
join->best_positions[i].use_join_buffer)
join->full_join= 1; join->full_join= 1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment