Commit 2160a25a authored by Sergey Petrunya's avatar Sergey Petrunya

BUG#869001: Wrong result with semijoin + materialization + firstmatch + multipart key

- Make advance_sj_state() not to attempt building duplicate removal strategies
  when we're doing optimization of an SJM-nest.
parent 74497ff2
...@@ -822,5 +822,31 @@ x x g ...@@ -822,5 +822,31 @@ x x g
x x g x x g
set optimizer_switch= @tmp_869012; set optimizer_switch= @tmp_869012;
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
#
# BUG#869001: Wrong result with semijoin + materialization + firstmatch + multipart key
#
set @tmp869001_jcl= @@join_cache_level;
set @tmp869001_os= @@optimizer_switch;
SET join_cache_level=0;
SET optimizer_switch='materialization=on,semijoin=on,firstmatch=on,loosescan=off';
CREATE TABLE t1 ( f2 int, f3 varchar(1), KEY (f3,f2)) engine=innodb;
INSERT INTO t1 VALUES (8,'x'),(NULL,'x'),(8,'c');
CREATE TABLE t2 ( f4 varchar(1)) engine=innodb;
INSERT INTO t2 VALUES ('x');
CREATE TABLE t3 ( f1 int) engine=innodb;
INSERT INTO t3 VALUES (8),(6),(2),(9),(6);
CREATE TABLE t4 ( f3 varchar(1)) engine=innodb;
INSERT INTO t4 VALUES ('p'),('j'),('c');
SELECT *
FROM t1 JOIN t2 ON (t2.f4 = t1.f3 )
WHERE ( 8 ) IN (
SELECT t3.f1 FROM t3 , t4
);
f2 f3 f4
NULL x x
8 x x
DROP TABLE t1, t2, t3, t4;
set join_cache_level= @tmp869001_jcl;
set optimizer_switch= @tmp869001_os;
# This must be the last in the file: # This must be the last in the file:
set optimizer_switch=@subselect_sj2_tmp; set optimizer_switch=@subselect_sj2_tmp;
...@@ -833,6 +833,32 @@ x x g ...@@ -833,6 +833,32 @@ x x g
x x g x x g
set optimizer_switch= @tmp_869012; set optimizer_switch= @tmp_869012;
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
#
# BUG#869001: Wrong result with semijoin + materialization + firstmatch + multipart key
#
set @tmp869001_jcl= @@join_cache_level;
set @tmp869001_os= @@optimizer_switch;
SET join_cache_level=0;
SET optimizer_switch='materialization=on,semijoin=on,firstmatch=on,loosescan=off';
CREATE TABLE t1 ( f2 int, f3 varchar(1), KEY (f3,f2)) engine=innodb;
INSERT INTO t1 VALUES (8,'x'),(NULL,'x'),(8,'c');
CREATE TABLE t2 ( f4 varchar(1)) engine=innodb;
INSERT INTO t2 VALUES ('x');
CREATE TABLE t3 ( f1 int) engine=innodb;
INSERT INTO t3 VALUES (8),(6),(2),(9),(6);
CREATE TABLE t4 ( f3 varchar(1)) engine=innodb;
INSERT INTO t4 VALUES ('p'),('j'),('c');
SELECT *
FROM t1 JOIN t2 ON (t2.f4 = t1.f3 )
WHERE ( 8 ) IN (
SELECT t3.f1 FROM t3 , t4
);
f2 f3 f4
NULL x x
8 x x
DROP TABLE t1, t2, t3, t4;
set join_cache_level= @tmp869001_jcl;
set optimizer_switch= @tmp869001_os;
# This must be the last in the file: # This must be the last in the file:
set optimizer_switch=@subselect_sj2_tmp; set optimizer_switch=@subselect_sj2_tmp;
set join_cache_level=default; set join_cache_level=default;
......
...@@ -834,6 +834,32 @@ x x g ...@@ -834,6 +834,32 @@ x x g
x x g x x g
set optimizer_switch= @tmp_869012; set optimizer_switch= @tmp_869012;
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
#
# BUG#869001: Wrong result with semijoin + materialization + firstmatch + multipart key
#
set @tmp869001_jcl= @@join_cache_level;
set @tmp869001_os= @@optimizer_switch;
SET join_cache_level=0;
SET optimizer_switch='materialization=on,semijoin=on,firstmatch=on,loosescan=off';
CREATE TABLE t1 ( f2 int, f3 varchar(1), KEY (f3,f2)) engine=innodb;
INSERT INTO t1 VALUES (8,'x'),(NULL,'x'),(8,'c');
CREATE TABLE t2 ( f4 varchar(1)) engine=innodb;
INSERT INTO t2 VALUES ('x');
CREATE TABLE t3 ( f1 int) engine=innodb;
INSERT INTO t3 VALUES (8),(6),(2),(9),(6);
CREATE TABLE t4 ( f3 varchar(1)) engine=innodb;
INSERT INTO t4 VALUES ('p'),('j'),('c');
SELECT *
FROM t1 JOIN t2 ON (t2.f4 = t1.f3 )
WHERE ( 8 ) IN (
SELECT t3.f1 FROM t3 , t4
);
f2 f3 f4
NULL x x
8 x x
DROP TABLE t1, t2, t3, t4;
set join_cache_level= @tmp869001_jcl;
set optimizer_switch= @tmp869001_os;
# This must be the last in the file: # This must be the last in the file:
set optimizer_switch=@subselect_sj2_tmp; set optimizer_switch=@subselect_sj2_tmp;
set optimizer_switch=default; set optimizer_switch=default;
......
...@@ -1008,5 +1008,37 @@ set optimizer_switch= @tmp_869012; ...@@ -1008,5 +1008,37 @@ set optimizer_switch= @tmp_869012;
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
--echo #
--echo # BUG#869001: Wrong result with semijoin + materialization + firstmatch + multipart key
--echo #
set @tmp869001_jcl= @@join_cache_level;
set @tmp869001_os= @@optimizer_switch;
SET join_cache_level=0;
SET optimizer_switch='materialization=on,semijoin=on,firstmatch=on,loosescan=off';
CREATE TABLE t1 ( f2 int, f3 varchar(1), KEY (f3,f2)) engine=innodb;
INSERT INTO t1 VALUES (8,'x'),(NULL,'x'),(8,'c');
CREATE TABLE t2 ( f4 varchar(1)) engine=innodb;
INSERT INTO t2 VALUES ('x');
CREATE TABLE t3 ( f1 int) engine=innodb;
INSERT INTO t3 VALUES (8),(6),(2),(9),(6);
CREATE TABLE t4 ( f3 varchar(1)) engine=innodb;
INSERT INTO t4 VALUES ('p'),('j'),('c');
SELECT *
FROM t1 JOIN t2 ON (t2.f4 = t1.f3 )
WHERE ( 8 ) IN (
SELECT t3.f1 FROM t3 , t4
);
DROP TABLE t1, t2, t3, t4;
set join_cache_level= @tmp869001_jcl;
set optimizer_switch= @tmp869001_os;
--echo # This must be the last in the file: --echo # This must be the last in the file:
set optimizer_switch=@subselect_sj2_tmp; set optimizer_switch=@subselect_sj2_tmp;
...@@ -2179,6 +2179,17 @@ void advance_sj_state(JOIN *join, table_map remaining_tables, ...@@ -2179,6 +2179,17 @@ void advance_sj_state(JOIN *join, table_map remaining_tables,
pos->sj_strategy= SJ_OPT_NONE; pos->sj_strategy= SJ_OPT_NONE;
pos->prefix_dups_producing_tables= join->cur_dups_producing_tables; pos->prefix_dups_producing_tables= join->cur_dups_producing_tables;
/* We're performing optimization inside SJ-Materialization nest */
if (join->emb_sjm_nest)
{
pos->invalidate_firstmatch_prefix();
pos->first_loosescan_table= MAX_TABLES;
pos->dupsweedout_tables= 0;
pos->sjm_scan_need_tables= 0;
return;
}
/* Initialize the state or copy it from prev. tables */ /* Initialize the state or copy it from prev. tables */
if (idx == join->const_tables) if (idx == join->const_tables)
{ {
......
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