diff options
author | Sergey Petrunya <psergey@askmonty.org> | 2011-09-26 13:56:09 +0400 |
---|---|---|
committer | Sergey Petrunya <psergey@askmonty.org> | 2011-09-26 13:56:09 +0400 |
commit | 4908d27b57ee00dba3694e300a858b0fcdb224ee (patch) | |
tree | 893ad6d892fc772b47b41fe5f1b6991eff15c939 | |
parent | 9ea133fb3be4c46741e059ab78118f75afe791a1 (diff) | |
download | mariadb-git-4908d27b57ee00dba3694e300a858b0fcdb224ee.tar.gz |
BUG#858732: Wrong result with semijoin + loosescan + comma join
- Fix wrong loop bounds in setup_semijoin_dups_elimination()
-rw-r--r-- | mysql-test/r/subselect_sj2.result | 23 | ||||
-rw-r--r-- | mysql-test/r/subselect_sj2_jcl6.result | 23 | ||||
-rw-r--r-- | mysql-test/r/subselect_sj2_mat.result | 23 | ||||
-rw-r--r-- | mysql-test/t/subselect_sj2.test | 23 | ||||
-rw-r--r-- | sql/opt_subselect.cc | 2 |
5 files changed, 93 insertions, 1 deletions
diff --git a/mysql-test/r/subselect_sj2.result b/mysql-test/r/subselect_sj2.result index e4e66ce01f2..b69651258d4 100644 --- a/mysql-test/r/subselect_sj2.result +++ b/mysql-test/r/subselect_sj2.result @@ -764,4 +764,27 @@ a b c 1 r r DROP VIEW v1; DROP TABLE t1, t2; +# +# BUG#858732: Wrong result with semijoin + loosescan + comma join +# +CREATE TABLE t1 (f13 int(11) NOT NULL , PRIMARY KEY (f13)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (16),(24); +CREATE TABLE t2 (f14 int(11) NOT NULL, f12 varchar(1) NOT NULL, KEY (f12,f14)) ENGINE=InnoDB; +INSERT INTO t2 VALUES (6,'y'); +CREATE TABLE t3 (f12 varchar(1) NOT NULL) ENGINE=InnoDB; +INSERT INTO t3 VALUES ('r'),('s'),('t'),('v'),('w'),('x'),('y'); +# The following must use LooseScan but not join buffering +explain +SELECT * FROM t3 +WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 const PRIMARY PRIMARY 4 const 1 Using index +1 PRIMARY alias2 index f12 f12 7 NULL 1 Using index; LooseScan +1 PRIMARY t1 index NULL PRIMARY 4 NULL 2 Using index; FirstMatch(alias2) +1 PRIMARY t3 ALL NULL NULL NULL NULL 7 Using where; Using join buffer (flat, BNL join) +SELECT * FROM t3 +WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24); +f12 +y +DROP TABLE t1,t2,t3; set optimizer_switch=@subselect_sj2_tmp; diff --git a/mysql-test/r/subselect_sj2_jcl6.result b/mysql-test/r/subselect_sj2_jcl6.result index 234fd625886..1049625fa1d 100644 --- a/mysql-test/r/subselect_sj2_jcl6.result +++ b/mysql-test/r/subselect_sj2_jcl6.result @@ -775,6 +775,29 @@ a b c 1 r r DROP VIEW v1; DROP TABLE t1, t2; +# +# BUG#858732: Wrong result with semijoin + loosescan + comma join +# +CREATE TABLE t1 (f13 int(11) NOT NULL , PRIMARY KEY (f13)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (16),(24); +CREATE TABLE t2 (f14 int(11) NOT NULL, f12 varchar(1) NOT NULL, KEY (f12,f14)) ENGINE=InnoDB; +INSERT INTO t2 VALUES (6,'y'); +CREATE TABLE t3 (f12 varchar(1) NOT NULL) ENGINE=InnoDB; +INSERT INTO t3 VALUES ('r'),('s'),('t'),('v'),('w'),('x'),('y'); +# The following must use LooseScan but not join buffering +explain +SELECT * FROM t3 +WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 const PRIMARY PRIMARY 4 const 1 Using index +1 PRIMARY alias2 index f12 f12 7 NULL 1 Using index; LooseScan +1 PRIMARY t1 index NULL PRIMARY 4 NULL 2 Using index; FirstMatch(alias2) +1 PRIMARY t3 ALL NULL NULL NULL NULL 7 Using where; Using join buffer (flat, BNL join) +SELECT * FROM t3 +WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24); +f12 +y +DROP TABLE t1,t2,t3; set optimizer_switch=@subselect_sj2_tmp; set join_cache_level=default; show variables like 'join_cache_level'; diff --git a/mysql-test/r/subselect_sj2_mat.result b/mysql-test/r/subselect_sj2_mat.result index 3541653a863..b5e15946037 100644 --- a/mysql-test/r/subselect_sj2_mat.result +++ b/mysql-test/r/subselect_sj2_mat.result @@ -777,6 +777,29 @@ a b c 1 r r DROP VIEW v1; DROP TABLE t1, t2; +# +# BUG#858732: Wrong result with semijoin + loosescan + comma join +# +CREATE TABLE t1 (f13 int(11) NOT NULL , PRIMARY KEY (f13)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (16),(24); +CREATE TABLE t2 (f14 int(11) NOT NULL, f12 varchar(1) NOT NULL, KEY (f12,f14)) ENGINE=InnoDB; +INSERT INTO t2 VALUES (6,'y'); +CREATE TABLE t3 (f12 varchar(1) NOT NULL) ENGINE=InnoDB; +INSERT INTO t3 VALUES ('r'),('s'),('t'),('v'),('w'),('x'),('y'); +# The following must use LooseScan but not join buffering +explain +SELECT * FROM t3 +WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 const PRIMARY PRIMARY 4 const 1 Using index +1 PRIMARY alias2 index f12 f12 7 NULL 1 Using index; LooseScan +1 PRIMARY t1 index NULL PRIMARY 4 NULL 2 Using index; FirstMatch(alias2) +1 PRIMARY t3 ALL NULL NULL NULL NULL 7 Using where; Using join buffer (flat, BNL join) +SELECT * FROM t3 +WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24); +f12 +y +DROP TABLE t1,t2,t3; set optimizer_switch=@subselect_sj2_tmp; set optimizer_switch=default; select @@optimizer_switch like '%materialization=on%'; diff --git a/mysql-test/t/subselect_sj2.test b/mysql-test/t/subselect_sj2.test index ed96168a6c8..8a04b10b06e 100644 --- a/mysql-test/t/subselect_sj2.test +++ b/mysql-test/t/subselect_sj2.test @@ -962,4 +962,27 @@ EXECUTE st1; DROP VIEW v1; DROP TABLE t1, t2; +--echo # +--echo # BUG#858732: Wrong result with semijoin + loosescan + comma join +--echo # +CREATE TABLE t1 (f13 int(11) NOT NULL , PRIMARY KEY (f13)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (16),(24); + +CREATE TABLE t2 (f14 int(11) NOT NULL, f12 varchar(1) NOT NULL, KEY (f12,f14)) ENGINE=InnoDB; +INSERT INTO t2 VALUES (6,'y'); + +CREATE TABLE t3 (f12 varchar(1) NOT NULL) ENGINE=InnoDB; +INSERT INTO t3 VALUES ('r'),('s'),('t'),('v'),('w'),('x'),('y'); + +--echo # The following must use LooseScan but not join buffering +explain +SELECT * FROM t3 +WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24); + +SELECT * FROM t3 +WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24); + +DROP TABLE t1,t2,t3; + + set optimizer_switch=@subselect_sj2_tmp; diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index beeb0ac878e..7ac09eaa434 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -3834,7 +3834,7 @@ int setup_semijoin_dups_elimination(JOIN *join, ulonglong options, { /* We jump from the last table to the first one */ tab->loosescan_match_tab= tab + pos->n_sj_tables - 1; - for (uint j= i; j < pos->n_sj_tables; j++) + for (uint j= i; j < i + pos->n_sj_tables; j++) join->join_tab[j].inside_loosescan_range= TRUE; /* Calculate key length */ |