diff --git a/mysql-test/include/ctype_common.inc b/mysql-test/include/ctype_common.inc index 7d92c3c7b8f..4cb04599679 100644 --- a/mysql-test/include/ctype_common.inc +++ b/mysql-test/include/ctype_common.inc @@ -64,6 +64,14 @@ select a sounds like a from t1; select 1 from t1 order by cast(a as char(1)); drop table t1; +--echo # +--echo # MDEV-6134 SUBSTRING_INDEX returns wrong result for 8bit character sets when delimiter is not found +--echo # +SET character_set_client=latin1; +SET character_set_connection= @test_character_set; +SET collation_connection= @test_collation; +SELECT COLLATION('.'), SUBSTRING_INDEX('.wwwmysqlcom', '.', -2) AS c1; + # # Bug#27580 SPACE() function collation bug? # diff --git a/mysql-test/r/ctype_big5.result b/mysql-test/r/ctype_big5.result index 340c333c77e..55ed8ed6c95 100644 --- a/mysql-test/r/ctype_big5.result +++ b/mysql-test/r/ctype_big5.result @@ -71,6 +71,15 @@ select 1 from t1 order by cast(a as char(1)); 1 1 drop table t1; +# +# MDEV-6134 SUBSTRING_INDEX returns wrong result for 8bit character sets when delimiter is not found +# +SET character_set_client=latin1; +SET character_set_connection= @test_character_set; +SET collation_connection= @test_collation; +SELECT COLLATION('.'), SUBSTRING_INDEX('.wwwmysqlcom', '.', -2) AS c1; +COLLATION('.') c1 +big5_chinese_ci .wwwmysqlcom set names utf8; create table t1 ( name varchar(10), diff --git a/mysql-test/r/ctype_cp1250_ch.result b/mysql-test/r/ctype_cp1250_ch.result index 231755a3f69..6ec4c46086d 100644 --- a/mysql-test/r/ctype_cp1250_ch.result +++ b/mysql-test/r/ctype_cp1250_ch.result @@ -75,6 +75,15 @@ select 1 from t1 order by cast(a as char(1)); 1 1 drop table t1; +# +# MDEV-6134 SUBSTRING_INDEX returns wrong result for 8bit character sets when delimiter is not found +# +SET character_set_client=latin1; +SET character_set_connection= @test_character_set; +SET collation_connection= @test_collation; +SELECT COLLATION('.'), SUBSTRING_INDEX('.wwwmysqlcom', '.', -2) AS c1; +COLLATION('.') c1 +cp1250_general_ci .wwwmysqlcom set names utf8; create table t1 ( name varchar(10), @@ -168,6 +177,15 @@ select 1 from t1 order by cast(a as char(1)); 1 1 drop table t1; +# +# MDEV-6134 SUBSTRING_INDEX returns wrong result for 8bit character sets when delimiter is not found +# +SET character_set_client=latin1; +SET character_set_connection= @test_character_set; +SET collation_connection= @test_collation; +SELECT COLLATION('.'), SUBSTRING_INDEX('.wwwmysqlcom', '.', -2) AS c1; +COLLATION('.') c1 +cp1250_czech_cs .wwwmysqlcom set names utf8; create table t1 ( name varchar(10), diff --git a/mysql-test/r/ctype_euckr.result b/mysql-test/r/ctype_euckr.result index 2006ac57769..ff49c87d1e6 100644 --- a/mysql-test/r/ctype_euckr.result +++ b/mysql-test/r/ctype_euckr.result @@ -71,6 +71,15 @@ select 1 from t1 order by cast(a as char(1)); 1 1 drop table t1; +# +# MDEV-6134 SUBSTRING_INDEX returns wrong result for 8bit character sets when delimiter is not found +# +SET character_set_client=latin1; +SET character_set_connection= @test_character_set; +SET collation_connection= @test_collation; +SELECT COLLATION('.'), SUBSTRING_INDEX('.wwwmysqlcom', '.', -2) AS c1; +COLLATION('.') c1 +euckr_korean_ci .wwwmysqlcom set names utf8; create table t1 ( name varchar(10), diff --git a/mysql-test/r/ctype_gb2312.result b/mysql-test/r/ctype_gb2312.result index 2d3ee3e0900..550d4fee0d6 100644 --- a/mysql-test/r/ctype_gb2312.result +++ b/mysql-test/r/ctype_gb2312.result @@ -71,6 +71,15 @@ select 1 from t1 order by cast(a as char(1)); 1 1 drop table t1; +# +# MDEV-6134 SUBSTRING_INDEX returns wrong result for 8bit character sets when delimiter is not found +# +SET character_set_client=latin1; +SET character_set_connection= @test_character_set; +SET collation_connection= @test_collation; +SELECT COLLATION('.'), SUBSTRING_INDEX('.wwwmysqlcom', '.', -2) AS c1; +COLLATION('.') c1 +gb2312_chinese_ci .wwwmysqlcom set names utf8; create table t1 ( name varchar(10), diff --git a/mysql-test/r/ctype_gbk.result b/mysql-test/r/ctype_gbk.result index 93e060868fb..9da3cf92b1f 100644 --- a/mysql-test/r/ctype_gbk.result +++ b/mysql-test/r/ctype_gbk.result @@ -71,6 +71,15 @@ select 1 from t1 order by cast(a as char(1)); 1 1 drop table t1; +# +# MDEV-6134 SUBSTRING_INDEX returns wrong result for 8bit character sets when delimiter is not found +# +SET character_set_client=latin1; +SET character_set_connection= @test_character_set; +SET collation_connection= @test_collation; +SELECT COLLATION('.'), SUBSTRING_INDEX('.wwwmysqlcom', '.', -2) AS c1; +COLLATION('.') c1 +gbk_chinese_ci .wwwmysqlcom set names utf8; create table t1 ( name varchar(10), diff --git a/mysql-test/r/ctype_latin1.result b/mysql-test/r/ctype_latin1.result index 9ba82279401..ae6a4fd582d 100644 --- a/mysql-test/r/ctype_latin1.result +++ b/mysql-test/r/ctype_latin1.result @@ -308,6 +308,108 @@ select 'a' regexp 'A' collate latin1_general_cs; select 'a' regexp 'A' collate latin1_bin; 'a' regexp 'A' collate latin1_bin 0 +SET @test_character_set= 'latin1'; +SET @test_collation= 'latin1_swedish_ci'; +SET @safe_character_set_server= @@character_set_server; +SET @safe_collation_server= @@collation_server; +SET @safe_character_set_client= @@character_set_client; +SET @safe_character_set_results= @@character_set_results; +SET character_set_server= @test_character_set; +SET collation_server= @test_collation; +CREATE DATABASE d1; +USE d1; +CREATE TABLE t1 (c CHAR(10), KEY(c)); +SHOW FULL COLUMNS FROM t1; +Field Type Collation Null Key Default Extra Privileges Comment +c char(10) latin1_swedish_ci YES MUL NULL +INSERT INTO t1 VALUES ('aaa'),('aaaa'),('aaaaa'); +SELECT c as want3results FROM t1 WHERE c LIKE 'aaa%'; +want3results +aaa +aaaa +aaaaa +DROP TABLE t1; +CREATE TABLE t1 (c1 varchar(15), KEY c1 (c1(2))); +SHOW FULL COLUMNS FROM t1; +Field Type Collation Null Key Default Extra Privileges Comment +c1 varchar(15) latin1_swedish_ci YES MUL NULL +INSERT INTO t1 VALUES ('location'),('loberge'),('lotre'),('boabab'); +SELECT c1 as want3results from t1 where c1 like 'l%'; +want3results +location +loberge +lotre +SELECT c1 as want3results from t1 where c1 like 'lo%'; +want3results +location +loberge +lotre +SELECT c1 as want1result from t1 where c1 like 'loc%'; +want1result +location +SELECT c1 as want1result from t1 where c1 like 'loca%'; +want1result +location +SELECT c1 as want1result from t1 where c1 like 'locat%'; +want1result +location +SELECT c1 as want1result from t1 where c1 like 'locati%'; +want1result +location +SELECT c1 as want1result from t1 where c1 like 'locatio%'; +want1result +location +SELECT c1 as want1result from t1 where c1 like 'location%'; +want1result +location +DROP TABLE t1; +create table t1 (a set('a') not null); +insert into t1 values (),(); +Warnings: +Warning 1364 Field 'a' doesn't have a default value +select cast(a as char(1)) from t1; +cast(a as char(1)) + + +select a sounds like a from t1; +a sounds like a +1 +1 +select 1 from t1 order by cast(a as char(1)); +1 +1 +1 +drop table t1; +# +# MDEV-6134 SUBSTRING_INDEX returns wrong result for 8bit character sets when delimiter is not found +# +SET character_set_client=latin1; +SET character_set_connection= @test_character_set; +SET collation_connection= @test_collation; +SELECT COLLATION('.'), SUBSTRING_INDEX('.wwwmysqlcom', '.', -2) AS c1; +COLLATION('.') c1 +latin1_swedish_ci .wwwmysqlcom +set names utf8; +create table t1 ( +name varchar(10), +level smallint unsigned); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `name` varchar(10) DEFAULT NULL, + `level` smallint(5) unsigned DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +insert into t1 values ('string',1); +select concat(name,space(level)), concat(name, repeat(' ',level)) from t1; +concat(name,space(level)) concat(name, repeat(' ',level)) +string string +drop table t1; +DROP DATABASE d1; +USE test; +SET character_set_server= @safe_character_set_server; +SET collation_server= @safe_collation_server; +SET character_set_client= @safe_character_set_client; +SET character_set_results= @safe_character_set_results; SET collation_connection='latin1_swedish_ci'; create table t1 select repeat('a',4000) a; delete from t1; diff --git a/mysql-test/r/ctype_uca.result b/mysql-test/r/ctype_uca.result index 9bd6618202b..1d5dd4e1cda 100644 --- a/mysql-test/r/ctype_uca.result +++ b/mysql-test/r/ctype_uca.result @@ -2725,6 +2725,15 @@ select 1 from t1 order by cast(a as char(1)); 1 1 drop table t1; +# +# MDEV-6134 SUBSTRING_INDEX returns wrong result for 8bit character sets when delimiter is not found +# +SET character_set_client=latin1; +SET character_set_connection= @test_character_set; +SET collation_connection= @test_collation; +SELECT COLLATION('.'), SUBSTRING_INDEX('.wwwmysqlcom', '.', -2) AS c1; +COLLATION('.') c1 +utf8_swedish_ci .wwwmysqlcom set names utf8; create table t1 ( name varchar(10), diff --git a/mysql-test/r/ctype_ucs.result b/mysql-test/r/ctype_ucs.result index 29f409075a3..c7e1e4e57a5 100644 --- a/mysql-test/r/ctype_ucs.result +++ b/mysql-test/r/ctype_ucs.result @@ -71,6 +71,15 @@ select 1 from t1 order by cast(a as char(1)); 1 1 drop table t1; +# +# MDEV-6134 SUBSTRING_INDEX returns wrong result for 8bit character sets when delimiter is not found +# +SET character_set_client=latin1; +SET character_set_connection= @test_character_set; +SET collation_connection= @test_collation; +SELECT COLLATION('.'), SUBSTRING_INDEX('.wwwmysqlcom', '.', -2) AS c1; +COLLATION('.') c1 +ucs2_general_ci .wwwmysqlcom set names utf8; create table t1 ( name varchar(10), diff --git a/mysql-test/r/ctype_utf16_uca.result b/mysql-test/r/ctype_utf16_uca.result index 77d1048129a..1b0d541bc3c 100644 --- a/mysql-test/r/ctype_utf16_uca.result +++ b/mysql-test/r/ctype_utf16_uca.result @@ -2241,6 +2241,15 @@ select 1 from t1 order by cast(a as char(1)); 1 1 drop table t1; +# +# MDEV-6134 SUBSTRING_INDEX returns wrong result for 8bit character sets when delimiter is not found +# +SET character_set_client=latin1; +SET character_set_connection= @test_character_set; +SET collation_connection= @test_collation; +SELECT COLLATION('.'), SUBSTRING_INDEX('.wwwmysqlcom', '.', -2) AS c1; +COLLATION('.') c1 +utf16_swedish_ci .wwwmysqlcom set names utf8; create table t1 ( name varchar(10), diff --git a/mysql-test/r/ctype_utf32_uca.result b/mysql-test/r/ctype_utf32_uca.result index f585d99941a..e05b81f195a 100644 --- a/mysql-test/r/ctype_utf32_uca.result +++ b/mysql-test/r/ctype_utf32_uca.result @@ -2241,6 +2241,15 @@ select 1 from t1 order by cast(a as char(1)); 1 1 drop table t1; +# +# MDEV-6134 SUBSTRING_INDEX returns wrong result for 8bit character sets when delimiter is not found +# +SET character_set_client=latin1; +SET character_set_connection= @test_character_set; +SET collation_connection= @test_collation; +SELECT COLLATION('.'), SUBSTRING_INDEX('.wwwmysqlcom', '.', -2) AS c1; +COLLATION('.') c1 +utf32_swedish_ci .wwwmysqlcom set names utf8; create table t1 ( name varchar(10), diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index b1750df326d..c2827d75e6a 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -119,7 +119,7 @@ substring_index('aaaaaaaaa1','aaa',-3) aaaaaa1 select substring_index('aaaaaaaaa1','aaa',-4); substring_index('aaaaaaaaa1','aaa',-4) - +aaaaaaaaa1 select substring_index('the king of thethe hill','the',-2); substring_index('the king of thethe hill','the',-2) the hill diff --git a/mysql-test/suite/binlog/r/binlog_row_ctype_cp932.result b/mysql-test/suite/binlog/r/binlog_row_ctype_cp932.result index 8bdad1813ea..aa2f2cca755 100644 --- a/mysql-test/suite/binlog/r/binlog_row_ctype_cp932.result +++ b/mysql-test/suite/binlog/r/binlog_row_ctype_cp932.result @@ -74,6 +74,15 @@ select 1 from t1 order by cast(a as char(1)); 1 1 drop table t1; +# +# MDEV-6134 SUBSTRING_INDEX returns wrong result for 8bit character sets when delimiter is not found +# +SET character_set_client=latin1; +SET character_set_connection= @test_character_set; +SET collation_connection= @test_collation; +SELECT COLLATION('.'), SUBSTRING_INDEX('.wwwmysqlcom', '.', -2) AS c1; +COLLATION('.') c1 +cp932_japanese_ci .wwwmysqlcom set names utf8; create table t1 ( name varchar(10), diff --git a/mysql-test/suite/binlog/r/binlog_stm_ctype_cp932.result b/mysql-test/suite/binlog/r/binlog_stm_ctype_cp932.result index 8bdad1813ea..aa2f2cca755 100644 --- a/mysql-test/suite/binlog/r/binlog_stm_ctype_cp932.result +++ b/mysql-test/suite/binlog/r/binlog_stm_ctype_cp932.result @@ -74,6 +74,15 @@ select 1 from t1 order by cast(a as char(1)); 1 1 drop table t1; +# +# MDEV-6134 SUBSTRING_INDEX returns wrong result for 8bit character sets when delimiter is not found +# +SET character_set_client=latin1; +SET character_set_connection= @test_character_set; +SET collation_connection= @test_collation; +SELECT COLLATION('.'), SUBSTRING_INDEX('.wwwmysqlcom', '.', -2) AS c1; +COLLATION('.') c1 +cp932_japanese_ci .wwwmysqlcom set names utf8; create table t1 ( name varchar(10), diff --git a/mysql-test/t/ctype_latin1.test b/mysql-test/t/ctype_latin1.test index ec9b836a78b..aa66c8132e3 100644 --- a/mysql-test/t/ctype_latin1.test +++ b/mysql-test/t/ctype_latin1.test @@ -79,6 +79,10 @@ select 'a' regexp 'A' collate latin1_general_cs; select 'a' regexp 'A' collate latin1_bin; +SET @test_character_set= 'latin1'; +SET @test_collation= 'latin1_swedish_ci'; +-- source include/ctype_common.inc + SET collation_connection='latin1_swedish_ci'; -- source include/ctype_filesort.inc -- source include/ctype_like_escape.inc diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 469e8d2ac1c..821f9359baf 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1579,6 +1579,8 @@ String *Item_func_substr_index::val_str(String *str) break; } } + if (count) + return res; // Didn't find, return org string } } /* diff --git a/storage/tokudb/mysql-test/tokudb/r/ctype_cp1250_ch.result b/storage/tokudb/mysql-test/tokudb/r/ctype_cp1250_ch.result index 12c10bcd967..3efeb757b61 100644 --- a/storage/tokudb/mysql-test/tokudb/r/ctype_cp1250_ch.result +++ b/storage/tokudb/mysql-test/tokudb/r/ctype_cp1250_ch.result @@ -76,6 +76,15 @@ select 1 from t1 order by cast(a as char(1)); 1 1 drop table t1; +# +# MDEV-6134 SUBSTRING_INDEX returns wrong result for 8bit character sets when delimiter is not found +# +SET character_set_client=latin1; +SET character_set_connection= @test_character_set; +SET collation_connection= @test_collation; +SELECT COLLATION('.'), SUBSTRING_INDEX('.wwwmysqlcom', '.', -2) AS c1; +COLLATION('.') c1 +cp1250_general_ci .wwwmysqlcom set names utf8; create table t1 ( name varchar(10), @@ -169,6 +178,15 @@ select 1 from t1 order by cast(a as char(1)); 1 1 drop table t1; +# +# MDEV-6134 SUBSTRING_INDEX returns wrong result for 8bit character sets when delimiter is not found +# +SET character_set_client=latin1; +SET character_set_connection= @test_character_set; +SET collation_connection= @test_collation; +SELECT COLLATION('.'), SUBSTRING_INDEX('.wwwmysqlcom', '.', -2) AS c1; +COLLATION('.') c1 +cp1250_czech_cs .wwwmysqlcom set names utf8; create table t1 ( name varchar(10),