From: Date: September 21 2005 8:10pm Subject: bk commit into 4.1 tree (bar:1.2445) BUG#13046 List-Archive: http://lists.mysql.com/internals/30167 X-Bug: 13046 Message-Id: <200509211810.j8LIAvou093734@bar.intranet.mysql.r18.ru> Below is the list of changes that have just been committed into a local 4.1 repository of bar. When bar does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.2445 05/09/21 23:10:51 bar@stripped +30 -0 Bug#13046: LIKE pattern matching using prefix index doesn't return correct result item_cmpfunc.cc: Use charset of LIKE to decide whether to use 8bit or Unicode "escape" value. But use charset of "escape" to scan escape character. strings/ctype-xxx.c: We cannot reduce "end" pointer using charpos(), because of possible escape characters in the string. Limit the loop using count of written characters instead. ctype_like_escape.inc: new file mysql-test/t/ctype_xxx: mysql-test/r/ctype_xxx: Adding test case. sql/item_cmpfunc.cc 1.199 05/09/21 22:38:43 bar@stripped +3 -2 More fixes. sql/item_cmpfunc.cc 1.198 05/09/21 22:18:11 bar@stripped +1 -1 Use charset of "escape" rather than charset of LIKE. Note: "escape" string is not aggregated with LIKE arguments, so we should use charset of "escape" to scan a character from it. mysql-test/r/ctype_utf8.result 1.65 05/09/21 22:17:30 bar@stripped +36 -0 Adding test case. mysql-test/r/ctype_ujis.result 1.12 05/09/21 22:17:30 bar@stripped +36 -0 Adding test case. mysql-test/r/ctype_ucs.result 1.26 05/09/21 22:17:29 bar@stripped +36 -0 Adding test case. mysql-test/r/ctype_uca.result 1.14 05/09/21 22:17:28 bar@stripped +18 -0 Adding test case. mysql-test/r/ctype_tis620.result 1.9 05/09/21 22:17:28 bar@stripped +36 -0 Adding test case. mysql-test/r/ctype_sjis.result 1.8 05/09/21 22:17:27 bar@stripped +36 -0 Adding test case. mysql-test/r/ctype_latin1.result 1.6 05/09/21 22:17:26 bar@stripped +36 -0 Adding test case. mysql-test/r/ctype_gbk.result 1.2 05/09/21 22:17:25 bar@stripped +36 -0 Adding test case. mysql-test/r/ctype_cp932.result 1.6 05/09/21 22:17:24 bar@stripped +36 -0 Adding test case. mysql-test/r/ctype_big5.result 1.9 05/09/21 22:17:20 bar@stripped +36 -0 Adding test case. mysql-test/t/ctype_utf8.test 1.67 05/09/21 22:13:38 bar@stripped +2 -0 Adding test case. mysql-test/t/ctype_ujis.test 1.15 05/09/21 22:13:37 bar@stripped +2 -0 Adding test case. mysql-test/t/ctype_ucs.test 1.25 05/09/21 22:13:36 bar@stripped +2 -0 Adding test case. mysql-test/t/ctype_uca.test 1.12 05/09/21 22:13:35 bar@stripped +1 -0 Adding test case. mysql-test/t/ctype_tis620.test 1.11 05/09/21 22:13:35 bar@stripped +2 -0 Adding test case. mysql-test/t/ctype_sjis.test 1.9 05/09/21 22:13:34 bar@stripped +2 -0 Adding test case. mysql-test/t/ctype_latin1.test 1.6 05/09/21 22:13:33 bar@stripped +2 -0 Adding test case. mysql-test/t/ctype_gbk.test 1.3 05/09/21 22:13:32 bar@stripped +2 -0 Adding test case. mysql-test/t/ctype_cp932.test 1.7 05/09/21 22:13:27 bar@stripped +2 -0 Adding test case. mysql-test/t/ctype_big5.test 1.9 05/09/21 22:13:01 bar@stripped +2 -0 Adding test case. strings/ctype-ucs2.c 1.44 05/09/21 22:12:22 bar@stripped +4 -2 Bug#13046: LIKE pattern matching using prefix index doesn't return correct result We cannot change "end" pointer using charpos(), because of possible escape characters. Use limit by count of written characters instead strings/ctype-tis620.c 1.82 05/09/21 22:12:21 bar@stripped +3 -68 Bug#13046: LIKE pattern matching using prefix index doesn't return correct result We cannot change "end" pointer using charpos(), because of possible escape characters. Use limit by count of written characters instead strings/ctype-sjis.c 1.81 05/09/21 22:12:18 bar@stripped +4 -7 Bug#13046: LIKE pattern matching using prefix index doesn't return correct result We cannot change "end" pointer using charpos(), because of possible escape characters. Use limit by count of written characters instead strings/ctype-simple.c 1.66 05/09/21 22:12:15 bar@stripped +3 -8 Bug#13046: LIKE pattern matching using prefix index doesn't return correct result We cannot change "end" pointer using charpos(), because of possible escape characters. Use limit by count of written characters instead strings/ctype-mb.c 1.41 05/09/21 22:12:14 bar@stripped +4 -13 Bug#13046: LIKE pattern matching using prefix index doesn't return correct result We cannot change "end" pointer using charpos(), because of possible escape characters. Use limit by count of written characters instead strings/ctype-gbk.c 1.72 05/09/21 22:12:12 bar@stripped +7 -8 Bug#13046: LIKE pattern matching using prefix index doesn't return correct result We cannot change "end" pointer using charpos(), because of possible escape characters. Use limit by count of written characters instead strings/ctype-cp932.c 1.7 05/09/21 22:11:48 bar@stripped +4 -7 Bug#13046: LIKE pattern matching using prefix index doesn't return correct result We cannot change "end" pointer using charpos(), because of possible escape characters. Use limit by count of written characters instead strings/ctype-big5.c 1.78 05/09/21 22:10:01 bar@stripped +7 -8 Bug#13046: LIKE pattern matching using prefix index doesn't return correct result We cannot change "end" pointer using charpos(), because of possible escape characters. Use limit by count of written characters instead. mysql-test/include/ctype_like_escape.inc 1.1 05/09/21 22:09:49 bar@stripped +18 -0 mysql-test/include/ctype_like_escape.inc 1.0 05/09/21 22:09:49 bar@stripped +0 -0 BitKeeper file /usr/home/bar/mysql-4.1/mysql-test/include/ctype_like_escape.inc # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: bar # Host: bar.intranet.mysql.r18.ru # Root: /usr/home/bar/mysql-4.1 --- 1.197/sql/item_cmpfunc.cc 2005-09-12 20:48:12 +05:00 +++ 1.199/sql/item_cmpfunc.cc 2005-09-21 22:38:43 +05:00 @@ -2443,9 +2443,9 @@ String *escape_str= escape_item->val_str(&tmp_value1); if (escape_str) { - CHARSET_INFO *cs= cmp.cmp_collation.collation; - if (use_mb(cs)) + if (use_mb(cmp_collation.collation)) { + CHARSET_INFO *cs= escape_str->charset(); my_wc_t wc; int rc= cs->cset->mb_wc(cs, &wc, (const uchar*) escape_str->ptr(), @@ -2460,6 +2460,7 @@ code instead of Unicode code as "escape" argument. Convert to "cs" if charset of escape differs. */ + CHARSET_INFO *cs= cmp_collation.collation; uint32 unused; if (escape_str->needs_conversion(escape_str->length(), escape_str->charset(), cs, &unused)) --- 1.77/strings/ctype-big5.c 2005-08-17 13:26:27 +05:00 +++ 1.78/strings/ctype-big5.c 2005-09-21 22:10:01 +05:00 @@ -392,16 +392,12 @@ uint res_length, char *min_str,char *max_str, uint *min_length,uint *max_length) { - const char *end; + const char *end= ptr + ptr_length; char *min_org=min_str; char *min_end=min_str+res_length; - uint charlen= my_charpos(cs, ptr, ptr+ptr_length, res_length/cs->mbmaxlen); + uint charlen= res_length / cs->mbmaxlen; - if (charlen < ptr_length) - ptr_length= charlen; - end= ptr + ptr_length; - - for (; ptr != end && min_str != min_end ; ptr++) + for (; ptr != end && min_str != min_end && charlen > 0; ptr++, charlen--) { if (ptr+1 != end && isbig5code(ptr[0],ptr[1])) { @@ -412,7 +408,10 @@ if (*ptr == escape && ptr+1 != end) { ptr++; /* Skip escape */ - *min_str++= *max_str++ = *ptr; + if (isbig5code(ptr[0], ptr[1])) + *min_str++= *max_str++ = *ptr++; + if (min_str < min_end) + *min_str++= *max_str++= *ptr; continue; } if (*ptr == w_one) /* '_' in SQL */ --- 1.71/strings/ctype-gbk.c 2005-08-17 13:26:28 +05:00 +++ 1.72/strings/ctype-gbk.c 2005-09-21 22:12:12 +05:00 @@ -2705,16 +2705,12 @@ uint res_length, char *min_str,char *max_str, uint *min_length,uint *max_length) { - const char *end; + const char *end= ptr + ptr_length; char *min_org=min_str; char *min_end=min_str+res_length; - uint charlen= my_charpos(cs, ptr, ptr+ptr_length, res_length/cs->mbmaxlen); + uint charlen= res_length / cs->mbmaxlen; - if (charlen < ptr_length) - ptr_length= charlen; - end= ptr + ptr_length; - - for (; ptr != end && min_str != min_end ; ptr++) + for (; ptr != end && min_str != min_end && charlen > 0; ptr++, charlen--) { if (ptr+1 != end && isgbkcode(ptr[0],ptr[1])) { @@ -2725,7 +2721,10 @@ if (*ptr == escape && ptr+1 != end) { ptr++; /* Skip escape */ - *min_str++= *max_str++ = *ptr; + if (isgbkcode(ptr[0], ptr[1])) + *min_str++= *max_str++ = *ptr; + if (min_str < min_end) + *min_str++= *max_str++= *ptr; continue; } if (*ptr == w_one) /* '_' in SQL */ --- 1.80/strings/ctype-sjis.c 2005-08-17 13:26:28 +05:00 +++ 1.81/strings/ctype-sjis.c 2005-09-21 22:12:18 +05:00 @@ -322,16 +322,13 @@ uint res_length, char *min_str,char *max_str, uint *min_length,uint *max_length) { - const char *end; + const char *end= ptr + ptr_length; char *min_org=min_str; char *min_end=min_str+res_length; - uint charlen= my_charpos(cs, ptr, ptr+ptr_length, res_length/cs->mbmaxlen); + uint charlen= res_length / cs->mbmaxlen; - if (charlen < ptr_length) - ptr_length= charlen; - end= ptr + ptr_length; - - while (ptr < end && min_str < min_end) { + for ( ; ptr < end && min_str < min_end && charlen > 0 ; charlen--) + { if (ismbchar_sjis(cs, ptr, end)) { *min_str++ = *max_str++ = *ptr++; if (min_str < min_end) --- 1.81/strings/ctype-tis620.c 2005-08-17 13:26:28 +05:00 +++ 1.82/strings/ctype-tis620.c 2005-09-21 22:12:21 +05:00 @@ -641,71 +641,6 @@ } - -/* - Convert SQL LIKE string to C string - - Arg: String, its length, escape character, resource length, - minimal string and maximum string - Ret: Always 0 - - IMPLEMENTATION - We just copy this function from opt_range.cc. No need to convert to - thai2sortable string. min_str and max_str will be use for comparison and - converted there. - - RETURN VALUES - 0 -*/ - -#define max_sort_chr ((char) 255) - -static -my_bool my_like_range_tis620(CHARSET_INFO *cs __attribute__((unused)), - const char *ptr, uint ptr_length, - pbool escape, pbool w_one, pbool w_many, - uint res_length, char *min_str, char *max_str, - uint *min_length, uint *max_length) -{ - const char *end=ptr+ptr_length; - char *min_org=min_str; - char *min_end=min_str+res_length; - - for (; ptr != end && min_str != min_end ; ptr++) - { - if (*ptr == escape && ptr+1 != end) - { - ptr++; /* Skip escape */ - *min_str++ = *max_str++ = *ptr; - continue; - } - if (*ptr == w_one) /* '_' in SQL */ - { - *min_str++='\0'; /* This should be min char */ - *max_str++=max_sort_chr; - continue; - } - if (*ptr == w_many) /* '%' in SQL */ - { - *min_length= (uint) (min_str - min_org); - *max_length=res_length; - do - { - *min_str++ = 0; - *max_str++ = max_sort_chr; - } while (min_str != min_end); - return 0; - } - *min_str++= *max_str++ = *ptr; - } - *min_length= *max_length = (uint) (min_str - min_org); - - while (min_str != min_end) - *min_str++ = *max_str++ = ' '; /* Because of key compression */ - return 0; -} - - static unsigned short cs_to_uni[256]={ 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, @@ -914,7 +849,7 @@ my_strnncoll_tis620, my_strnncollsp_tis620, my_strnxfrm_tis620, - my_like_range_tis620, + my_like_range_simple, my_wildcmp_8bit, /* wildcmp */ my_strcasecmp_8bit, my_instr_simple, /* QQ: To be fixed */ @@ -974,7 +909,7 @@ 1, /* mbminlen */ 1, /* mbmaxlen */ 0, /* min_sort_char */ - 0, /* max_sort_char */ + 255, /* max_sort_char */ 0, /* escape_with_backslash_is_dangerous */ &my_charset_handler, &my_collation_ci_handler @@ -1002,7 +937,7 @@ 1, /* mbminlen */ 1, /* mbmaxlen */ 0, /* min_sort_char */ - 0, /* max_sort_char */ + 255, /* max_sort_char */ 0, /* escape_with_backslash_is_dangerous */ &my_charset_handler, &my_collation_8bit_bin_handler --- 1.8/mysql-test/r/ctype_big5.result 2005-08-02 14:27:49 +05:00 +++ 1.9/mysql-test/r/ctype_big5.result 2005-09-21 22:17:20 +05:00 @@ -89,6 +89,24 @@ c1 abcde111 drop table t1; +select @@collation_connection; +@@collation_connection +big5_chinese_ci +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def +drop table t1; SET collation_connection='big5_bin'; create table t1 select repeat('a',4000) a; delete from t1; @@ -120,6 +138,24 @@ select c1 from t1 where c1 like 'abcde111%' order by c1; c1 abcde111 +drop table t1; +select @@collation_connection; +@@collation_connection +big5_bin +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def drop table t1; SET NAMES big5; CREATE TABLE t1 (a text) character set big5; --- 1.5/mysql-test/r/ctype_latin1.result 2005-07-21 16:03:15 +05:00 +++ 1.6/mysql-test/r/ctype_latin1.result 2005-09-21 22:17:26 +05:00 @@ -315,6 +315,24 @@ latin1_swedish_ci 61 latin1_swedish_ci 6120 drop table t1; +select @@collation_connection; +@@collation_connection +latin1_swedish_ci +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def +drop table t1; SET collation_connection='latin1_bin'; create table t1 select repeat('a',4000) a; delete from t1; @@ -324,6 +342,24 @@ latin1_bin 6109 latin1_bin 61 latin1_bin 6120 +drop table t1; +select @@collation_connection; +@@collation_connection +latin1_bin +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def drop table t1; CREATE TABLE „a (a int); ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '„a (a int)' at line 1 --- 1.7/mysql-test/r/ctype_sjis.result 2005-07-06 17:13:57 +05:00 +++ 1.8/mysql-test/r/ctype_sjis.result 2005-09-21 22:17:27 +05:00 @@ -103,6 +103,24 @@ c1 abcde111 drop table t1; +select @@collation_connection; +@@collation_connection +sjis_japanese_ci +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def +drop table t1; SET collation_connection='sjis_bin'; create table t1 select repeat('a',4000) a; delete from t1; @@ -134,6 +152,24 @@ select c1 from t1 where c1 like 'abcde111%' order by c1; c1 abcde111 +drop table t1; +select @@collation_connection; +@@collation_connection +sjis_bin +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def drop table t1; SET NAMES sjis; SELECT HEX('²“‘@\Œ\') FROM DUAL; --- 1.8/mysql-test/r/ctype_tis620.result 2005-01-13 18:11:55 +04:00 +++ 1.9/mysql-test/r/ctype_tis620.result 2005-09-21 22:17:28 +05:00 @@ -2947,6 +2947,24 @@ tis620_thai_ci 61 tis620_thai_ci 6120 drop table t1; +select @@collation_connection; +@@collation_connection +tis620_thai_ci +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def +drop table t1; SET collation_connection='tis620_bin'; create table t1 select repeat('a',4000) a; delete from t1; @@ -2956,4 +2974,22 @@ tis620_bin 6109 tis620_bin 61 tis620_bin 6120 +drop table t1; +select @@collation_connection; +@@collation_connection +tis620_bin +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def drop table t1; --- 1.8/mysql-test/t/ctype_big5.test 2005-08-02 14:27:49 +05:00 +++ 1.9/mysql-test/t/ctype_big5.test 2005-09-21 22:13:01 +05:00 @@ -15,9 +15,11 @@ SET collation_connection='big5_chinese_ci'; -- source include/ctype_filesort.inc -- source include/ctype_innodb_like.inc +-- source include/ctype_like_escape.inc SET collation_connection='big5_bin'; -- source include/ctype_filesort.inc -- source include/ctype_innodb_like.inc +-- source include/ctype_like_escape.inc # # Bugs#9357: TEXT columns break string with special word in BIG5 charset. --- 1.5/mysql-test/t/ctype_latin1.test 2005-07-28 05:21:40 +05:00 +++ 1.6/mysql-test/t/ctype_latin1.test 2005-09-21 22:13:33 +05:00 @@ -64,8 +64,10 @@ SET collation_connection='latin1_swedish_ci'; -- source include/ctype_filesort.inc +-- source include/ctype_like_escape.inc SET collation_connection='latin1_bin'; -- source include/ctype_filesort.inc +-- source include/ctype_like_escape.inc # # Bug#8041 --- 1.8/mysql-test/t/ctype_sjis.test 2005-07-28 05:21:40 +05:00 +++ 1.9/mysql-test/t/ctype_sjis.test 2005-09-21 22:13:34 +05:00 @@ -67,9 +67,11 @@ SET collation_connection='sjis_japanese_ci'; -- source include/ctype_filesort.inc -- source include/ctype_innodb_like.inc +-- source include/ctype_like_escape.inc SET collation_connection='sjis_bin'; -- source include/ctype_filesort.inc -- source include/ctype_innodb_like.inc +-- source include/ctype_like_escape.inc # Check parsing of string literals in SJIS with multibyte characters that # have an embedded \ in them. (Bug #8303) --- 1.10/mysql-test/t/ctype_tis620.test 2005-09-15 19:17:12 +05:00 +++ 1.11/mysql-test/t/ctype_tis620.test 2005-09-21 22:13:35 +05:00 @@ -155,7 +155,9 @@ SET collation_connection='tis620_thai_ci'; -- source include/ctype_filesort.inc +-- source include/ctype_like_escape.inc SET collation_connection='tis620_bin'; -- source include/ctype_filesort.inc +-- source include/ctype_like_escape.inc # End of 4.1 tests --- 1.25/mysql-test/r/ctype_ucs.result 2005-06-28 14:59:56 +05:00 +++ 1.26/mysql-test/r/ctype_ucs.result 2005-09-21 22:17:29 +05:00 @@ -587,6 +587,24 @@ ucs2_general_ci 0061 ucs2_general_ci 00610020 drop table t1; +select @@collation_connection; +@@collation_connection +ucs2_general_ci +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def +drop table t1; SET NAMES latin1; SET collation_connection='ucs2_bin'; create table t1 select repeat('a',4000) a; @@ -597,6 +615,24 @@ ucs2_bin 00610009 ucs2_bin 0061 ucs2_bin 00610020 +drop table t1; +select @@collation_connection; +@@collation_connection +ucs2_bin +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def drop table t1; select hex(substr(_ucs2 0x00e400e50068,1)); hex(substr(_ucs2 0x00e400e50068,1)) --- 1.64/mysql-test/r/ctype_utf8.result 2005-08-31 14:01:25 +05:00 +++ 1.65/mysql-test/r/ctype_utf8.result 2005-09-21 22:17:30 +05:00 @@ -842,6 +842,24 @@ utf8_general_ci 61 utf8_general_ci 6120 drop table t1; +select @@collation_connection; +@@collation_connection +utf8_general_ci +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def +drop table t1; SET collation_connection='utf8_bin'; create table t1 select repeat('a',4000) a; delete from t1; @@ -851,6 +869,24 @@ utf8_bin 6109 utf8_bin 61 utf8_bin 6120 +drop table t1; +select @@collation_connection; +@@collation_connection +utf8_bin +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def drop table t1; CREATE TABLE t1 ( user varchar(255) NOT NULL default '' --- 1.24/mysql-test/t/ctype_ucs.test 2005-07-28 05:21:40 +05:00 +++ 1.25/mysql-test/t/ctype_ucs.test 2005-09-21 22:13:36 +05:00 @@ -370,9 +370,11 @@ SET collation_connection='ucs2_general_ci'; -- source include/ctype_filesort.inc +-- source include/ctype_like_escape.inc SET NAMES latin1; SET collation_connection='ucs2_bin'; -- source include/ctype_filesort.inc +-- source include/ctype_like_escape.inc # # Bug#10344 Some string functions fail for UCS2 --- 1.66/mysql-test/t/ctype_utf8.test 2005-08-31 14:01:19 +05:00 +++ 1.67/mysql-test/t/ctype_utf8.test 2005-09-21 22:13:38 +05:00 @@ -685,8 +685,10 @@ SET collation_connection='utf8_general_ci'; -- source include/ctype_filesort.inc +-- source include/ctype_like_escape.inc SET collation_connection='utf8_bin'; -- source include/ctype_filesort.inc +-- source include/ctype_like_escape.inc # # Bug #7874 CONCAT() gives wrong results mixing --- 1.43/strings/ctype-ucs2.c 2005-08-17 13:26:29 +05:00 +++ 1.44/strings/ctype-ucs2.c 2005-09-21 22:12:22 +05:00 @@ -1426,10 +1426,12 @@ const char *end=ptr+ptr_length; char *min_org=min_str; char *min_end=min_str+res_length; + uint charlen= res_length / cs->mbmaxlen; - for (; ptr + 1 < end && min_str + 1 < min_end ; ptr+=2) + for ( ; ptr + 1 < end && min_str + 1 < min_end && charlen > 0 + ; ptr+=2, charlen--) { - if (ptr[0] == '\0' && ptr[1] == escape && ptr+2 < end) + if (ptr[0] == '\0' && ptr[1] == escape && ptr + 1 < end) { ptr+=2; /* Skip escape */ *min_str++= *max_str++ = ptr[0]; --- 1.40/strings/ctype-mb.c 2005-07-26 16:36:27 +05:00 +++ 1.41/strings/ctype-mb.c 2005-09-21 22:12:14 +05:00 @@ -502,17 +502,13 @@ char *min_str,char *max_str, uint *min_length,uint *max_length) { - const char *end; + const char *end= ptr + ptr_length; char *min_org= min_str; char *min_end= min_str + res_length; char *max_end= max_str + res_length; - uint charlen= my_charpos(cs, ptr, ptr+ptr_length, res_length/cs->mbmaxlen); + uint charlen= res_length / cs->mbmaxlen; - if (charlen < ptr_length) - ptr_length= charlen; - end= ptr + ptr_length; - - for (; ptr != end && min_str != min_end ; ptr++) + for (; ptr != end && min_str != min_end && charlen > 0 ; ptr++, charlen--) { if (*ptr == escape && ptr+1 != end) { @@ -522,14 +518,8 @@ } if (*ptr == w_one || *ptr == w_many) /* '_' and '%' in SQL */ { - charlen= my_charpos(cs, min_org, min_str, res_length/cs->mbmaxlen); - - if (charlen < (uint) (min_str - min_org)) - min_str= min_org + charlen; - /* Write min key */ *min_length= (uint) (min_str - min_org); - *max_length= res_length; do { *min_str++= (char) cs->min_sort_char; @@ -540,6 +530,7 @@ representation of the max_sort_char character, and copy it into max_str in a loop. */ + *max_length= res_length; pad_max_char(cs, max_str, max_end); return 0; } --- 1.65/strings/ctype-simple.c 2005-07-26 16:36:29 +05:00 +++ 1.66/strings/ctype-simple.c 2005-09-21 22:12:15 +05:00 @@ -997,17 +997,12 @@ char *min_str,char *max_str, uint *min_length,uint *max_length) { - const char *end; + const char *end= ptr + ptr_length; char *min_org=min_str; char *min_end=min_str+res_length; -#ifdef USE_MB - uint charlen= my_charpos(cs, ptr, ptr+ptr_length, res_length/cs->mbmaxlen); - if (charlen < ptr_length) - ptr_length= charlen; -#endif - end= ptr + ptr_length; + uint charlen= res_length / cs->mbmaxlen; - for (; ptr != end && min_str != min_end ; ptr++) + for (; ptr != end && min_str != min_end && charlen > 0 ; ptr++, charlen--) { if (*ptr == escape && ptr+1 != end) { --- New file --- +++ mysql-test/include/ctype_like_escape.inc 05/09/21 22:09:49 # # Bugs: #13046: # LIKE pattern matching using prefix index doesn't return correct result # select @@collation_connection; create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; insert into t1 values('abcdef'); insert into t1 values('_bcdef'); insert into t1 values('a_cdef'); insert into t1 values('ab_def'); insert into t1 values('abc_ef'); insert into t1 values('abcd_f'); insert into t1 values('abcde_'); -- should return ab_def select c1 as c1u from t1 where c1 like 'ab\_def'; -- should return ab_def select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; drop table t1; --- 1.1/mysql-test/r/ctype_gbk.result 2005-07-22 21:03:37 +05:00 +++ 1.2/mysql-test/r/ctype_gbk.result 2005-09-21 22:17:25 +05:00 @@ -89,6 +89,24 @@ c1 abcde111 drop table t1; +select @@collation_connection; +@@collation_connection +gbk_chinese_ci +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def +drop table t1; SET collation_connection='gbk_bin'; create table t1 select repeat('a',4000) a; delete from t1; @@ -120,6 +138,24 @@ select c1 from t1 where c1 like 'abcde111%' order by c1; c1 abcde111 +drop table t1; +select @@collation_connection; +@@collation_connection +gbk_bin +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def drop table t1; SET NAMES gbk; CREATE TABLE t1 (a text) character set gbk; --- 1.13/mysql-test/r/ctype_uca.result 2005-04-04 17:54:45 +05:00 +++ 1.14/mysql-test/r/ctype_uca.result 2005-09-21 22:17:28 +05:00 @@ -2396,3 +2396,21 @@ utf8_unicode_ci 61 utf8_unicode_ci 6120 drop table t1; +select @@collation_connection; +@@collation_connection +utf8_unicode_ci +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def +drop table t1; --- 1.2/mysql-test/t/ctype_gbk.test 2005-07-28 05:21:40 +05:00 +++ 1.3/mysql-test/t/ctype_gbk.test 2005-09-21 22:13:32 +05:00 @@ -15,9 +15,11 @@ SET collation_connection='gbk_chinese_ci'; -- source include/ctype_filesort.inc -- source include/ctype_innodb_like.inc +-- source include/ctype_like_escape.inc SET collation_connection='gbk_bin'; -- source include/ctype_filesort.inc -- source include/ctype_innodb_like.inc +-- source include/ctype_like_escape.inc # # Bug#11987 mysql will truncate the text when --- 1.11/mysql-test/t/ctype_uca.test 2005-07-28 05:21:40 +05:00 +++ 1.12/mysql-test/t/ctype_uca.test 2005-09-21 22:13:35 +05:00 @@ -455,5 +455,6 @@ SET collation_connection='utf8_unicode_ci'; -- source include/ctype_filesort.inc +-- source include/ctype_like_escape.inc # End of 4.1 tests --- 1.11/mysql-test/r/ctype_ujis.result 2005-07-06 17:13:57 +05:00 +++ 1.12/mysql-test/r/ctype_ujis.result 2005-09-21 22:17:30 +05:00 @@ -2239,6 +2239,24 @@ c1 abcde111 drop table t1; +select @@collation_connection; +@@collation_connection +ujis_japanese_ci +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def +drop table t1; SET collation_connection='ujis_bin'; create table t1 select repeat('a',4000) a; delete from t1; @@ -2270,4 +2288,22 @@ select c1 from t1 where c1 like 'abcde111%' order by c1; c1 abcde111 +drop table t1; +select @@collation_connection; +@@collation_connection +ujis_bin +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def drop table t1; --- 1.14/mysql-test/t/ctype_ujis.test 2005-09-15 19:17:12 +05:00 +++ 1.15/mysql-test/t/ctype_ujis.test 2005-09-21 22:13:37 +05:00 @@ -1146,8 +1146,10 @@ SET collation_connection='ujis_japanese_ci'; -- source include/ctype_filesort.inc -- source include/ctype_innodb_like.inc +-- source include/ctype_like_escape.inc SET collation_connection='ujis_bin'; -- source include/ctype_filesort.inc -- source include/ctype_innodb_like.inc +-- source include/ctype_like_escape.inc # End of 4.1 tests --- 1.5/mysql-test/r/ctype_cp932.result 2005-08-24 21:37:22 +05:00 +++ 1.6/mysql-test/r/ctype_cp932.result 2005-09-21 22:17:24 +05:00 @@ -8624,6 +8624,24 @@ c1 abcde111 drop table t1; +select @@collation_connection; +@@collation_connection +cp932_japanese_ci +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def +drop table t1; SET collation_connection='cp932_bin'; create table t1 select repeat('a',4000) a; delete from t1; @@ -8655,4 +8673,22 @@ select c1 from t1 where c1 like 'abcde111%' order by c1; c1 abcde111 +drop table t1; +select @@collation_connection; +@@collation_connection +cp932_bin +create table t1 ROW_FORMAT=DYNAMIC select repeat('a',50) as c1 ; +insert into t1 values('abcdef'); +insert into t1 values('_bcdef'); +insert into t1 values('a_cdef'); +insert into t1 values('ab_def'); +insert into t1 values('abc_ef'); +insert into t1 values('abcd_f'); +insert into t1 values('abcde_'); +select c1 as c1u from t1 where c1 like 'ab\_def'; +c1u +ab_def +select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; +c2h +ab_def drop table t1; --- 1.6/mysql-test/t/ctype_cp932.test 2005-08-24 21:37:22 +05:00 +++ 1.7/mysql-test/t/ctype_cp932.test 2005-09-21 22:13:27 +05:00 @@ -427,8 +427,10 @@ SET collation_connection='cp932_japanese_ci'; -- source include/ctype_filesort.inc -- source include/ctype_innodb_like.inc +-- source include/ctype_like_escape.inc SET collation_connection='cp932_bin'; -- source include/ctype_filesort.inc -- source include/ctype_innodb_like.inc +-- source include/ctype_like_escape.inc # End of 4.1 tests --- 1.6/strings/ctype-cp932.c 2005-08-17 13:26:27 +05:00 +++ 1.7/strings/ctype-cp932.c 2005-09-21 22:11:48 +05:00 @@ -322,16 +322,13 @@ uint res_length, char *min_str,char *max_str, uint *min_length,uint *max_length) { - const char *end; + const char *end= ptr + ptr_length; char *min_org=min_str; char *min_end=min_str+res_length; - uint charlen= my_charpos(cs, ptr, ptr+ptr_length, res_length/cs->mbmaxlen); + uint charlen= res_length / cs->mbmaxlen; - if (charlen < ptr_length) - ptr_length= charlen; - end= ptr + ptr_length; - - while (ptr < end && min_str < min_end) { + for ( ; ptr < end && min_str < min_end && charlen > 0 ; charlen--) + { if (ismbchar_cp932(cs, ptr, end)) { *min_str++ = *max_str++ = *ptr++; if (min_str < min_end)