Commit 6ae94723 authored by unknown's avatar unknown
Browse files

Fixed bug #25971: indexes on text columns were ignored when ref accesses

were evaluated.
According to the new rules for string comparison partial indexes on text
columns can be used in the same cases when partial indexes on varchar
columns can be used.


mysql-test/r/endspace.result:
  Adjusted results after the fix for bug #25971.
mysql-test/r/innodb.result:
  Adjusted results after the fix for bug #25971.
mysql-test/r/myisam.result:
  Adjusted results after the fix for bug #25971.
mysql-test/r/select.result:
  Added a test case for bug #25971.
mysql-test/r/type_blob.result:
  Adjusted results after the fix for bug #25971.
mysql-test/t/select.test:
  Added a test case for bug #25971.
parent c039eed8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ concat('|', text1, '|')
|teststring |
explain select concat('|', text1, '|') from t1 where text1='teststring ';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	key1	key1	22	NULL	2	Using where
1	SIMPLE	t1	ref	key1	key1	22	const	2	Using where
select concat('|', text1, '|') from t1 where text1 like 'teststring_%';
concat('|', text1, '|')
|teststring	|
+1 −1
Original line number Diff line number Diff line
@@ -1991,7 +1991,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1	SIMPLE	t1	ref	c	c	11	const	#	Using where; Using index
explain select count(*) from t1 where t='a  ';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	t	t	13	NULL	#	Using where
1	SIMPLE	t1	ref	t	t	13	const	#	Using where
explain select count(*) from t1 where v like 'a%';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	v	v	13	NULL	#	Using where; Using index
+1 −1
Original line number Diff line number Diff line
@@ -1071,7 +1071,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1	SIMPLE	t1	ref	c	c	11	const	#	Using where; Using index
explain select count(*) from t1 where t='a  ';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	t	t	13	NULL	#	Using where
1	SIMPLE	t1	ref	t	t	13	const	#	Using where
explain select count(*) from t1 where v like 'a%';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	v	v	13	NULL	#	Using where; Using index
+148 −0
Original line number Diff line number Diff line
@@ -3785,4 +3785,152 @@ case when 1 then cast(1111111111111111111 as unsigned) else 1 end c,
coalesce(cast(1111111111111111111 as unsigned), 1) co;
i	c	co
1111111111111111111	1111111111111111111	1111111111111111111
CREATE TABLE t1 (name varchar(255));
CREATE TABLE t2 (name varchar(255), n int, KEY (name(3)));
INSERT INTO t1 VALUES ('ccc'), ('bb'), ('cc '), ('aa  '), ('aa');
INSERT INTO t2 VALUES ('bb',1), ('aa',2), ('cc   ',3);
INSERT INTO t2 VALUES (concat('cc ', 0x06), 4);
INSERT INTO t2 VALUES ('cc',5), ('bb ',6), ('cc ',7);
SELECT * FROM t2;
name	n
bb	1
aa	2
cc   	3
cc 	4
cc	5
bb 	6
cc 	7
SELECT * FROM t2 ORDER BY name;
name	n
aa	2
bb	1
bb 	6
cc 	4
cc   	3
cc	5
cc 	7
SELECT name, LENGTH(name), n FROM t2 ORDER BY name;
name	LENGTH(name)	n
aa	2	2
bb	2	1
bb 	3	6
cc 	4	4
cc   	5	3
cc	2	5
cc 	3	7
EXPLAIN SELECT name, LENGTH(name), n FROM t2 WHERE name='cc ';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ref	name	name	6	const	3	Using where
SELECT name, LENGTH(name), n FROM t2 WHERE name='cc ';
name	LENGTH(name)	n
cc   	5	3
cc	2	5
cc 	3	7
EXPLAIN SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	range	name	name	6	NULL	3	Using where
SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%';
name	LENGTH(name)	n
cc   	5	3
cc 	4	4
cc	2	5
cc 	3	7
EXPLAIN SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%' ORDER BY name;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	range	name	name	6	NULL	3	Using where; Using filesort
SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%' ORDER BY name;
name	LENGTH(name)	n
cc 	4	4
cc   	5	3
cc	2	5
cc 	3	7
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON t1.name=t2.name;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
1	SIMPLE	t2	ref	name	name	6	test.t1.name	2	
SELECT * FROM t1 LEFT JOIN t2 ON t1.name=t2.name;
name	name	n
ccc	NULL	NULL
bb	bb	1
bb	bb 	6
cc 	cc   	3
cc 	cc	5
cc 	cc 	7
aa  	aa	2
aa	aa	2
DROP TABLE t1,t2;
CREATE TABLE t1 (name text);
CREATE TABLE t2 (name text, n int, KEY (name(3)));
INSERT INTO t1 VALUES ('ccc'), ('bb'), ('cc '), ('aa  '), ('aa');
INSERT INTO t2 VALUES ('bb',1), ('aa',2), ('cc   ',3);
INSERT INTO t2 VALUES (concat('cc ', 0x06), 4);
INSERT INTO t2 VALUES ('cc',5), ('bb ',6), ('cc ',7);
SELECT * FROM t2;
name	n
bb	1
aa	2
cc   	3
cc 	4
cc	5
bb 	6
cc 	7
SELECT * FROM t2 ORDER BY name;
name	n
aa	2
bb	1
bb 	6
cc 	4
cc   	3
cc	5
cc 	7
SELECT name, LENGTH(name), n FROM t2 ORDER BY name;
name	LENGTH(name)	n
aa	2	2
bb	2	1
bb 	3	6
cc 	4	4
cc   	5	3
cc	2	5
cc 	3	7
EXPLAIN SELECT name, LENGTH(name), n FROM t2 WHERE name='cc ';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ref	name	name	6	const	3	Using where
SELECT name, LENGTH(name), n FROM t2 WHERE name='cc ';
name	LENGTH(name)	n
cc   	5	3
cc	2	5
cc 	3	7
EXPLAIN SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	range	name	name	6	NULL	3	Using where
SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%';
name	LENGTH(name)	n
cc   	5	3
cc 	4	4
cc	2	5
cc 	3	7
EXPLAIN SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%' ORDER BY name;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	range	name	name	6	NULL	3	Using where; Using filesort
SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%' ORDER BY name;
name	LENGTH(name)	n
cc 	4	4
cc   	5	3
cc	2	5
cc 	3	7
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON t1.name=t2.name;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
1	SIMPLE	t2	ref	name	name	6	test.t1.name	2	
SELECT * FROM t1 LEFT JOIN t2 ON t1.name=t2.name;
name	name	n
ccc	NULL	NULL
bb	bb	1
bb	bb 	6
cc 	cc   	3
cc 	cc	5
cc 	cc 	7
aa  	aa	2
aa	aa	2
DROP TABLE t1,t2;
End of 5.0 tests
+2 −2
Original line number Diff line number Diff line
@@ -610,12 +610,12 @@ create table t1 (id integer primary key auto_increment, txt text, index txt_inde
insert into t1 (txt) values ('Chevy'), ('Chevy '), (NULL);
select * from t1 where txt='Chevy' or txt is NULL;
id	txt
3	NULL
1	Chevy
2	Chevy 
3	NULL
explain select * from t1 where txt='Chevy' or txt is NULL;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	txt_index	txt_index	23	NULL	2	Using where
1	SIMPLE	t1	ref_or_null	txt_index	txt_index	23	const	2	Using where
select * from t1 where txt='Chevy ';
id	txt
1	Chevy
Loading