diff options
author | Sergey Glukhov <Sergey.Glukhov@sun.com> | 2008-12-24 19:24:11 +0400 |
---|---|---|
committer | Sergey Glukhov <Sergey.Glukhov@sun.com> | 2008-12-24 19:24:11 +0400 |
commit | ce985aa36e2fb9cb036ae66376bf3c0dfab433be (patch) | |
tree | fdc0f2ea6cae40151c879a4a9e0fc6abfded9632 | |
parent | 7103f4c91631dd1e725996429a6f8ccaf4d844d8 (diff) | |
download | mariadb-git-ce985aa36e2fb9cb036ae66376bf3c0dfab433be.tar.gz |
Bug#40953 SELECT query throws "ERROR 1062 (23000): Duplicate entry..." error
Table could be marked dependent because it is
either 1) an inner table of an outer join, or 2) it is a part of
STRAIGHT_JOIN. In case of STRAIGHT_JOIN table->maybe_null should not
be assigned. The fix is to set st_table::maybe_null to 'true' only
for those tables which are used in outer join.
mysql-test/r/select.result:
test result
mysql-test/t/select.test:
test case
sql/sql_select.cc:
Table could be marked dependent because it is
either 1) an inner table of an outer join, or 2) it is a part of
STRAIGHT_JOIN. In case of STRAIGHT_JOIN table->maybe_null should not
be assigned. The fix is to set st_table::maybe_null to 'true' only
for those tables which are used in outer join.
sql/sql_select.h:
added comment
-rw-r--r-- | mysql-test/r/select.result | 33 | ||||
-rw-r--r-- | mysql-test/t/select.test | 36 | ||||
-rw-r--r-- | sql/sql_select.cc | 2 | ||||
-rw-r--r-- | sql/sql_select.h | 6 |
4 files changed, 75 insertions, 2 deletions
diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index c2cd2129a32..67ce231a157 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -4355,4 +4355,37 @@ Handler_read_prev 0 Handler_read_rnd 0 Handler_read_rnd_next 6 DROP TABLE t1, t2; +CREATE TABLE t1 (f1 bigint(20) NOT NULL default '0', +f2 int(11) NOT NULL default '0', +f3 bigint(20) NOT NULL default '0', +f4 varchar(255) NOT NULL default '', +PRIMARY KEY (f1), +KEY key1 (f4), +KEY key2 (f2)); +CREATE TABLE t2 (f1 int(11) NOT NULL default '0', +f2 enum('A1','A2','A3') NOT NULL default 'A1', +f3 int(11) NOT NULL default '0', +PRIMARY KEY (f1), +KEY key1 (f3)); +CREATE TABLE t3 (f1 bigint(20) NOT NULL default '0', +f2 datetime NOT NULL default '1980-01-01 00:00:00', +PRIMARY KEY (f1)); +insert into t1 values (1, 1, 1, 'abc'); +insert into t1 values (2, 1, 2, 'def'); +insert into t1 values (3, 1, 2, 'def'); +insert into t2 values (1, 'A1', 1); +insert into t3 values (1, '1980-01-01'); +SELECT a.f3, cr.f4, count(*) count +FROM t2 a +STRAIGHT_JOIN t1 cr ON cr.f2 = a.f1 +LEFT JOIN +(t1 cr2 +JOIN t3 ae2 ON cr2.f3 = ae2.f1 +) ON a.f1 = cr2.f2 AND ae2.f2 < now() - INTERVAL 7 DAY AND +cr.f4 = cr2.f4 +GROUP BY a.f3, cr.f4; +f3 f4 count +1 abc 1 +1 def 2 +drop table t1, t2, t3; End of 5.0 tests diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 1ee87957643..1e8dc7ac2f6 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -3701,4 +3701,40 @@ SELECT DISTINCT b FROM t1 LEFT JOIN t2 USING(a) WHERE c <= 3; SHOW STATUS LIKE 'Handler_read%'; DROP TABLE t1, t2; +# +# Bug#40953 SELECT query throws "ERROR 1062 (23000): Duplicate entry..." error +# +CREATE TABLE t1 (f1 bigint(20) NOT NULL default '0', + f2 int(11) NOT NULL default '0', + f3 bigint(20) NOT NULL default '0', + f4 varchar(255) NOT NULL default '', + PRIMARY KEY (f1), + KEY key1 (f4), + KEY key2 (f2)); +CREATE TABLE t2 (f1 int(11) NOT NULL default '0', + f2 enum('A1','A2','A3') NOT NULL default 'A1', + f3 int(11) NOT NULL default '0', + PRIMARY KEY (f1), + KEY key1 (f3)); +CREATE TABLE t3 (f1 bigint(20) NOT NULL default '0', + f2 datetime NOT NULL default '1980-01-01 00:00:00', + PRIMARY KEY (f1)); + +insert into t1 values (1, 1, 1, 'abc'); +insert into t1 values (2, 1, 2, 'def'); +insert into t1 values (3, 1, 2, 'def'); +insert into t2 values (1, 'A1', 1); +insert into t3 values (1, '1980-01-01'); + +SELECT a.f3, cr.f4, count(*) count +FROM t2 a +STRAIGHT_JOIN t1 cr ON cr.f2 = a.f1 +LEFT JOIN +(t1 cr2 + JOIN t3 ae2 ON cr2.f3 = ae2.f1 +) ON a.f1 = cr2.f2 AND ae2.f2 < now() - INTERVAL 7 DAY AND +cr.f4 = cr2.f4 +GROUP BY a.f3, cr.f4; + +drop table t1, t2, t3; --echo End of 5.0 tests diff --git a/sql/sql_select.cc b/sql/sql_select.cc index d2c469f99da..230b9bb36cf 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2489,7 +2489,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds, if (s->dependent & table->map) s->dependent |= table->reginfo.join_tab->dependent; } - if (s->dependent) + if (outer_join & s->table->map) s->table->maybe_null= 1; } /* Catch illegal cross references for outer joins */ diff --git a/sql/sql_select.h b/sql/sql_select.h index c2f0780f5be..8ece01d3286 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -235,7 +235,11 @@ public: fetching data from a cursor */ bool resume_nested_loop; - table_map const_table_map,found_const_table_map,outer_join; + table_map const_table_map,found_const_table_map; + /* + Bitmap of all inner tables from outer joins + */ + table_map outer_join; ha_rows send_records,found_records,examined_rows,row_limit, select_limit; /* Used to fetch no more than given amount of rows per one |