summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authorunknown <gkodinov/kgeorge@macbook.gmz>2006-10-16 18:09:58 +0300
committerunknown <gkodinov/kgeorge@macbook.gmz>2006-10-16 18:09:58 +0300
commitffc1facce894359d5339ca7513a5518c2d829f29 (patch)
treeddf7474cc07baef2f6c1c4ff063b7613f711b03b /mysql-test
parent78bf02870c9a277ae785ab5705b4a5c0556b149e (diff)
downloadmariadb-git-ffc1facce894359d5339ca7513a5518c2d829f29.tar.gz
Bug #22367: Optimizer uses ref join type instead of eq_ref for simple join on
strings MySQL is setting the flag HA_END_SPACE_KEYS for all the keys that reference text or varchar columns with collation different than binary. This was done to handle correctly the situation where a lookup on such a key may return more than 1 row because of the presence of many rows that differ only by the amount of trailing space in the table's string column. Inserting such values however appears to violate the unique checks on INSERT/UPDATE. Thus that flag must not be set as it will prevent the optimizer from choosing a faster access method. This fix removes the setting of the HA_END_SPACE_KEYS flag. include/my_base.h: Bug #22367: Optimizer uses ref join type instead of eq_ref for simple join on strings - disabled HA_END_SPACE_KEY as it's no longer needed mysql-test/r/func_str.result: Bug #22367: Optimizer uses ref join type instead of eq_ref for simple join on strings - fixed explain in an existing case mysql-test/r/merge.result: Bug #22367: Optimizer uses ref join type instead of eq_ref for simple join on strings - fixed explain in an existing case mysql-test/r/select.result: Bug #22367: Optimizer uses ref join type instead of eq_ref for simple join on strings - test case mysql-test/r/subselect.result: Bug #22367: Optimizer uses ref join type instead of eq_ref for simple join on strings - fixed explain in an existing case mysql-test/t/select.test: Bug #22367: Optimizer uses ref join type instead of eq_ref for simple join on strings - test case
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/func_str.result4
-rw-r--r--mysql-test/r/merge.result2
-rw-r--r--mysql-test/r/select.result10
-rw-r--r--mysql-test/r/subselect.result10
-rw-r--r--mysql-test/t/select.test14
5 files changed, 32 insertions, 8 deletions
diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result
index 00642e1a570..c2c12f8d291 100644
--- a/mysql-test/r/func_str.result
+++ b/mysql-test/r/func_str.result
@@ -1143,9 +1143,9 @@ EXPLAIN EXTENDED
SELECT * FROM t1 INNER JOIN t2 ON code=id
WHERE id='a12' AND (LENGTH(code)=5 OR code < 'a00');
id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 const PRIMARY PRIMARY 12 const 1 Using index
1 SIMPLE t1 ref code code 13 const 3 Using where; Using index
-1 SIMPLE t2 ref PRIMARY PRIMARY 12 const 1 Using where; Using index
Warnings:
-Note 1003 select `test`.`t1`.`code` AS `code`,`test`.`t2`.`id` AS `id` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`code` = _latin1'a12') and (`test`.`t2`.`id` = _latin1'a12') and (length(`test`.`t1`.`code`) = 5))
+Note 1003 select `test`.`t1`.`code` AS `code`,`test`.`t2`.`id` AS `id` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`code` = _latin1'a12') and (length(`test`.`t1`.`code`) = 5))
DROP TABLE t1,t2;
End of 5.0 tests
diff --git a/mysql-test/r/merge.result b/mysql-test/r/merge.result
index b8fdd24be74..5196462e97e 100644
--- a/mysql-test/r/merge.result
+++ b/mysql-test/r/merge.result
@@ -626,7 +626,7 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT * FROM t2 WHERE fileset_id = 2
AND file_code = '0000000115' LIMIT 1;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ref PRIMARY,files PRIMARY 35 const,const 1 Using where
+1 SIMPLE t2 const PRIMARY,files PRIMARY 35 const,const 1
DROP TABLE t2, t1;
create table t1 (x int, y int, index xy(x, y));
create table t2 (x int, y int, index xy(x, y));
diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result
index 0c62d3f570f..5f059260b95 100644
--- a/mysql-test/r/select.result
+++ b/mysql-test/r/select.result
@@ -3517,3 +3517,13 @@ id a b c d e
2 NULL NULL NULL 2 40
2 NULL NULL NULL 2 50
DROP TABLE t1,t2,t3;
+CREATE TABLE t1 (a int, b varchar(20) NOT NULL, PRIMARY KEY(a));
+CREATE TABLE t2 (a int, b varchar(20) NOT NULL,
+PRIMARY KEY (a), UNIQUE KEY (b));
+INSERT INTO t1 VALUES (1,'a'),(2,'b'),(3,'c');
+INSERT INTO t2 VALUES (1,'a'),(2,'b'),(3,'c');
+EXPLAIN SELECT t1.a FROM t1 LEFT JOIN t2 ON t2.b=t1.b WHERE t1.a=3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
+1 SIMPLE t2 const b b 22 const 1 Using index
+DROP TABLE t1,t2;
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 6bf85979002..abe840e96d9 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -363,12 +363,12 @@ INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t8 ref PRIMARY PRIMARY 37 const 1 Using where; Using index
-4 SUBQUERY t8 ref PRIMARY PRIMARY 37 1 Using where; Using index
-2 SUBQUERY t8 ref PRIMARY PRIMARY 37 const 1 Using where
-3 SUBQUERY t8 ref PRIMARY PRIMARY 37 1 Using where; Using index
+1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 Using index
+4 SUBQUERY t8 const PRIMARY PRIMARY 37 1 Using index
+2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1
+3 SUBQUERY t8 const PRIMARY PRIMARY 37 1 Using index
Warnings:
-Note 1003 select `test`.`t8`.`pseudo` AS `pseudo`,(select `test`.`t8`.`email` AS `email` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select `test`.`t8`.`pseudo` AS `pseudo` from `test`.`t8` where (`test`.`t8`.`pseudo` = _latin1'joce')))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select `test`.`t8`.`pseudo` AS `pseudo` from `test`.`t8` where (`test`.`t8`.`pseudo` = _latin1'joce')))
+Note 1003 select `test`.`t8`.`pseudo` AS `pseudo`,(select `test`.`t8`.`email` AS `email` from `test`.`t8` where 1) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where 1
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
t8 WHERE pseudo='joce');
ERROR 21000: Operand should contain 1 column(s)
diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test
index 36b3749b4d7..1a5a3d2b254 100644
--- a/mysql-test/t/select.test
+++ b/mysql-test/t/select.test
@@ -2998,3 +2998,17 @@ SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id
DROP TABLE t1,t2,t3;
+
+#
+# Bug #22367: Optimizer uses ref join type instead of eq_ref for simple
+# join on strings
+#
+CREATE TABLE t1 (a int, b varchar(20) NOT NULL, PRIMARY KEY(a));
+CREATE TABLE t2 (a int, b varchar(20) NOT NULL,
+ PRIMARY KEY (a), UNIQUE KEY (b));
+INSERT INTO t1 VALUES (1,'a'),(2,'b'),(3,'c');
+INSERT INTO t2 VALUES (1,'a'),(2,'b'),(3,'c');
+
+EXPLAIN SELECT t1.a FROM t1 LEFT JOIN t2 ON t2.b=t1.b WHERE t1.a=3;
+
+DROP TABLE t1,t2;