Commit 4a03a1d7 authored by Igor Babaev's avatar Igor Babaev

Fixed LP bug #813447.

Do not make substitution of a single-row table if it is an inner
table of an outer join with on expression containing an expensive
subquery.
parent 2e8542f4
......@@ -1539,3 +1539,25 @@ GROUP BY t2.f1, t2.f2;
f1 f1 f2
DROP TABLE t1,t2;
End of 5.1 tests
#
# LP bug #813447: LEFT JOIN with single-row inner table and
# a subquery in ON expression
#
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (0);
CREATE TABLE t2 (a int);
INSERT INTO t2 VALUES (0);
CREATE TABLE t3 (a int);
INSERT INTO t3 VALUES (0), (0);
SELECT t2.a FROM t1 LEFT JOIN t2 ON (6) IN (SELECT a FROM t3);
a
NULL
EXPLAIN EXTENDED
SELECT t2.a FROM t1 LEFT JOIN t2 ON (6) IN (SELECT a FROM t3);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 100.00 Using where
2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` left join `test`.`t2` on(<in_optimizer>(6,<exists>(select `test`.`t3`.`a` from `test`.`t3` where (6 = `test`.`t3`.`a`)))) where 1
DROP TABLE t1,t2,t3;
......@@ -1548,6 +1548,28 @@ GROUP BY t2.f1, t2.f2;
f1 f1 f2
DROP TABLE t1,t2;
End of 5.1 tests
#
# LP bug #813447: LEFT JOIN with single-row inner table and
# a subquery in ON expression
#
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (0);
CREATE TABLE t2 (a int);
INSERT INTO t2 VALUES (0);
CREATE TABLE t3 (a int);
INSERT INTO t3 VALUES (0), (0);
SELECT t2.a FROM t1 LEFT JOIN t2 ON (6) IN (SELECT a FROM t3);
a
NULL
EXPLAIN EXTENDED
SELECT t2.a FROM t1 LEFT JOIN t2 ON (6) IN (SELECT a FROM t3);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 100.00 Using where
2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` left join `test`.`t2` on(<in_optimizer>(6,<exists>(select `test`.`t3`.`a` from `test`.`t3` where (6 = `test`.`t3`.`a`)))) where 1
DROP TABLE t1,t2,t3;
set join_cache_level=default;
show variables like 'join_cache_level';
Variable_name Value
......
......@@ -1409,7 +1409,7 @@ EXPLAIN
SELECT i FROM t1 LEFT JOIN t2 ON (j) IN (SELECT k FROM t3);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1
1 PRIMARY t2 system NULL NULL NULL NULL 1
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where
2 SUBQUERY t3 system NULL NULL NULL NULL 0 const row not found
SELECT i FROM t1 LEFT JOIN t2 ON (j) IN (SELECT k FROM t3);
i
......@@ -1418,7 +1418,7 @@ EXPLAIN
SELECT i FROM t1 LEFT JOIN t2 ON (j) IN (SELECT max(k) FROM t3);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1
1 PRIMARY t2 system NULL NULL NULL NULL 1
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where
2 SUBQUERY t3 system NULL NULL NULL NULL 0 const row not found
SELECT i FROM t1 LEFT JOIN t2 ON (j) IN (SELECT max(k) FROM t3);
i
......@@ -1437,10 +1437,10 @@ SELECT *
FROM t2 LEFT JOIN t2 t3 ON (8, 4) IN (SELECT c1, c1 FROM t1)";
EXECUTE st1;
c2 c2
10 10
10 NULL
EXECUTE st1;
c2 c2
10 10
10 NULL
DROP TABLE t1, t2;
#
# Testcase backport: BUG#46548 IN-subqueries return 0 rows with materialization=on
......
......@@ -1106,3 +1106,24 @@ GROUP BY t2.f1, t2.f2;
DROP TABLE t1,t2;
--echo End of 5.1 tests
--echo #
--echo # LP bug #813447: LEFT JOIN with single-row inner table and
--echo # a subquery in ON expression
--echo #
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (0);
CREATE TABLE t2 (a int);
INSERT INTO t2 VALUES (0);
CREATE TABLE t3 (a int);
INSERT INTO t3 VALUES (0), (0);
SELECT t2.a FROM t1 LEFT JOIN t2 ON (6) IN (SELECT a FROM t3);
EXPLAIN EXTENDED
SELECT t2.a FROM t1 LEFT JOIN t2 ON (6) IN (SELECT a FROM t3);
DROP TABLE t1,t2,t3;
......@@ -3268,7 +3268,9 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
continue;
if (table->file->stats.records <= 1L &&
(table->file->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT) &&
!table->pos_in_table_list->embedding)
!table->pos_in_table_list->embedding &&
!((outer_join & table->map) &&
(*s->on_expr_ref)->is_expensive()))
{ // system table
int tmp= 0;
s->type=JT_SYSTEM;
......
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