Skip to content

Commit 1d73005

Browse files
author
Alexander Barkov
committed
MDEV-8360 Clean-up CHARSET_INFO: strnncollsp: diff_if_only_endspace_difference
- Removing the "diff_if_only_endspace_difference" argument from MY_COLLATION_HANDLER::strnncollsp(), my_strnncollsp_simple(), as well as in the function template MY_FUNCTION_NAME(strnncollsp) in strcoll.ic - Removing the "diff_if_only_space_different" from ha_compare_text(), hp_rec_key_cmp(). - Adding a new function my_strnncollsp_padspace_bin() and reusing it instead of duplicate code pieces in my_strnncollsp_8bit_bin(), my_strnncollsp_latin1_de(), my_strnncollsp_tis620(), my_strnncollsp_utf8_cs(). - Adding more tests for better coverage of the trailing space handling. - Removing the unused definition of HA_END_SPACE_ARE_EQUAL
1 parent 282497d commit 1d73005

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+312
-332
lines changed

include/m_ctype.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,7 @@ struct my_collation_handler_st
325325
int (*strnncoll)(CHARSET_INFO *,
326326
const uchar *, size_t, const uchar *, size_t, my_bool);
327327
int (*strnncollsp)(CHARSET_INFO *,
328-
const uchar *, size_t, const uchar *, size_t,
329-
my_bool diff_if_only_endspace_difference);
328+
const uchar *, size_t, const uchar *, size_t);
330329
size_t (*strnxfrm)(CHARSET_INFO *,
331330
uchar *dst, size_t dstlen, uint nweights,
332331
const uchar *src, size_t srclen, uint flags);
@@ -644,8 +643,7 @@ extern int my_strnncoll_simple(CHARSET_INFO *, const uchar *, size_t,
644643
const uchar *, size_t, my_bool);
645644

646645
extern int my_strnncollsp_simple(CHARSET_INFO *, const uchar *, size_t,
647-
const uchar *, size_t,
648-
my_bool diff_if_only_endspace_difference);
646+
const uchar *, size_t);
649647

650648
extern void my_hash_sort_simple(CHARSET_INFO *cs,
651649
const uchar *key, size_t len,
@@ -654,6 +652,17 @@ extern void my_hash_sort_bin(CHARSET_INFO *cs,
654652
const uchar *key, size_t len, ulong *nr1,
655653
ulong *nr2);
656654

655+
/**
656+
Compare a string to an array of spaces, for PAD SPACE comparison.
657+
The function iterates through the string and compares every byte to 0x20.
658+
@param - the string
659+
@param - its length
660+
@return <0 - if a byte less than 0x20 was found in the string.
661+
@return 0 - if all bytes in the string were 0x20, or if length was 0.
662+
@return >0 - if a byte greater than 0x20 was found in the string.
663+
*/
664+
extern int my_strnncollsp_padspace_bin(const uchar *str, size_t length);
665+
657666
extern size_t my_lengthsp_8bit(CHARSET_INFO *cs, const char *ptr, size_t length);
658667

659668
extern uint my_instr_simple(CHARSET_INFO *,

include/my_base.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,7 @@ enum ha_base_keytype {
298298
#define HA_SWAP_KEY 64
299299
#define HA_REVERSE_SORT 128 /* Sort key in reverse order */
300300
#define HA_NO_SORT 256 /* do not bother sorting on this keyseg */
301-
/*
302-
End space in unique/varchar are considered equal. (Like 'a' and 'a ')
303-
Only needed for internal temporary tables.
304-
*/
305-
#define HA_END_SPACE_ARE_EQUAL 512
301+
306302
#define HA_BIT_PART 1024
307303
#define HA_CAN_MEMCMP 2048 /* internal, never stored in frm */
308304

include/my_compare.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ typedef struct st_HA_KEYSEG /* Key-portion */
108108
set_rec_bits(0, bit_ptr, bit_ofs, bit_len)
109109

110110
extern int ha_compare_text(CHARSET_INFO *, const uchar *, uint,
111-
const uchar *, uint , my_bool, my_bool);
111+
const uchar *, uint , my_bool);
112112
extern int ha_key_cmp(HA_KEYSEG *keyseg, const uchar *a,
113113
const uchar *b, uint key_length, uint nextflag,
114114
uint *diff_pos);
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
SELECT strcmp('a','a ');
2-
SELECT strcmp('a\0','a' );
3-
SELECT strcmp('a\0','a ');
4-
SELECT strcmp('a\t','a' );
5-
SELECT strcmp('a\t','a ');
1+
SELECT strcmp('a','a '), strcmp('a ','a');
2+
SELECT strcmp('a\0','a' ), strcmp('a','a\0');
3+
SELECT strcmp('a\0','a '), strcmp('a ','a\0');
4+
SELECT strcmp('a\t','a' ), strcmp('a', 'a\t');
5+
SELECT strcmp('a\t','a '), strcmp('a ', 'a\t');

mysql-test/r/ctype_big5.result

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,21 @@ _ 5F
329329
} 7D
330330
 7F
331331
drop table t1;
332+
SELECT strcmp('a','a '), strcmp('a ','a');
333+
strcmp('a','a ') strcmp('a ','a')
334+
0 0
335+
SELECT strcmp('a\0','a' ), strcmp('a','a\0');
336+
strcmp('a\0','a' ) strcmp('a','a\0')
337+
-1 1
338+
SELECT strcmp('a\0','a '), strcmp('a ','a\0');
339+
strcmp('a\0','a ') strcmp('a ','a\0')
340+
-1 1
341+
SELECT strcmp('a\t','a' ), strcmp('a', 'a\t');
342+
strcmp('a\t','a' ) strcmp('a', 'a\t')
343+
-1 1
344+
SELECT strcmp('a\t','a '), strcmp('a ', 'a\t');
345+
strcmp('a\t','a ') strcmp('a ', 'a\t')
346+
-1 1
332347
SET collation_connection='big5_bin';
333348
create table t1 select repeat('a',4000) a;
334349
delete from t1;
@@ -476,6 +491,21 @@ a hex(b) c
476491
3 F1F2F1F2F1F2F1F2F1F2F1F2F1F2F1F2F1F2F1F2F1F2
477492
4 F1F2F1F2F1F2F1F2F1F2F1F2F1F2F1F2F1F2F1F2F1F2F1F2
478493
DROP TABLE t1;
494+
SELECT strcmp('a','a '), strcmp('a ','a');
495+
strcmp('a','a ') strcmp('a ','a')
496+
0 0
497+
SELECT strcmp('a\0','a' ), strcmp('a','a\0');
498+
strcmp('a\0','a' ) strcmp('a','a\0')
499+
-1 1
500+
SELECT strcmp('a\0','a '), strcmp('a ','a\0');
501+
strcmp('a\0','a ') strcmp('a ','a\0')
502+
-1 1
503+
SELECT strcmp('a\t','a' ), strcmp('a', 'a\t');
504+
strcmp('a\t','a' ) strcmp('a', 'a\t')
505+
-1 1
506+
SELECT strcmp('a\t','a '), strcmp('a ', 'a\t');
507+
strcmp('a\t','a ') strcmp('a ', 'a\t')
508+
-1 1
479509
SET NAMES big5;
480510
CREATE TABLE t1 (a text) character set big5;
481511
INSERT INTO t1 VALUES ('��');

mysql-test/r/ctype_cp1250_ch.result

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -377,21 +377,21 @@ a
377377
abcdefgh�
378378
drop table t1;
379379
set names cp1250 collate cp1250_czech_cs;
380-
SELECT strcmp('a','a ');
381-
strcmp('a','a ')
382-
0
383-
SELECT strcmp('a\0','a' );
384-
strcmp('a\0','a' )
385-
1
386-
SELECT strcmp('a\0','a ');
387-
strcmp('a\0','a ')
388-
1
389-
SELECT strcmp('a\t','a' );
390-
strcmp('a\t','a' )
391-
1
392-
SELECT strcmp('a\t','a ');
393-
strcmp('a\t','a ')
394-
1
380+
SELECT strcmp('a','a '), strcmp('a ','a');
381+
strcmp('a','a ') strcmp('a ','a')
382+
0 0
383+
SELECT strcmp('a\0','a' ), strcmp('a','a\0');
384+
strcmp('a\0','a' ) strcmp('a','a\0')
385+
1 -1
386+
SELECT strcmp('a\0','a '), strcmp('a ','a\0');
387+
strcmp('a\0','a ') strcmp('a ','a\0')
388+
1 -1
389+
SELECT strcmp('a\t','a' ), strcmp('a', 'a\t');
390+
strcmp('a\t','a' ) strcmp('a', 'a\t')
391+
1 -1
392+
SELECT strcmp('a\t','a '), strcmp('a ', 'a\t');
393+
strcmp('a\t','a ') strcmp('a ', 'a\t')
394+
1 -1
395395
create table t1 select repeat('a',4000) a;
396396
delete from t1;
397397
insert into t1 values ('a'), ('a '), ('a\t');

mysql-test/r/ctype_cp1251.result

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,21 @@ FF FF FF D18F FF
388388
Warnings:
389389
Warning 1977 Cannot convert 'cp1251' character 0x98 to 'utf8'
390390
DROP TABLE t1;
391+
SELECT strcmp('a','a '), strcmp('a ','a');
392+
strcmp('a','a ') strcmp('a ','a')
393+
0 0
394+
SELECT strcmp('a\0','a' ), strcmp('a','a\0');
395+
strcmp('a\0','a' ) strcmp('a','a\0')
396+
-1 1
397+
SELECT strcmp('a\0','a '), strcmp('a ','a\0');
398+
strcmp('a\0','a ') strcmp('a ','a\0')
399+
-1 1
400+
SELECT strcmp('a\t','a' ), strcmp('a', 'a\t');
401+
strcmp('a\t','a' ) strcmp('a', 'a\t')
402+
-1 1
403+
SELECT strcmp('a\t','a '), strcmp('a ', 'a\t');
404+
strcmp('a\t','a ') strcmp('a ', 'a\t')
405+
-1 1
391406
set global LC_TIME_NAMES=convert((-8388608) using cp1251);
392407
ERROR HY000: Unknown locale: '-8388608'
393408
#

mysql-test/r/ctype_latin1.result

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,21 @@ SELECT HEX(subject),HEX(pattern),STR_TO_DATE(subject, pattern) FROM t1;
525525
HEX(subject) HEX(pattern) STR_TO_DATE(subject, pattern)
526526
32303031F73031F73031 2559F7256DF72564 2001-01-01 00:00:00.000000
527527
DROP TABLE t1;
528+
SELECT strcmp('a','a '), strcmp('a ','a');
529+
strcmp('a','a ') strcmp('a ','a')
530+
0 0
531+
SELECT strcmp('a\0','a' ), strcmp('a','a\0');
532+
strcmp('a\0','a' ) strcmp('a','a\0')
533+
-1 1
534+
SELECT strcmp('a\0','a '), strcmp('a ','a\0');
535+
strcmp('a\0','a ') strcmp('a ','a\0')
536+
-1 1
537+
SELECT strcmp('a\t','a' ), strcmp('a', 'a\t');
538+
strcmp('a\t','a' ) strcmp('a', 'a\t')
539+
-1 1
540+
SELECT strcmp('a\t','a '), strcmp('a ', 'a\t');
541+
strcmp('a\t','a ') strcmp('a ', 'a\t')
542+
-1 1
528543
SET collation_connection='latin1_bin';
529544
create table t1 select repeat('a',4000) a;
530545
delete from t1;
@@ -621,6 +636,21 @@ select c1 as c2h from t1 where c1 like 'ab#_def' escape '#';
621636
c2h
622637
ab_def
623638
drop table t1;
639+
SELECT strcmp('a','a '), strcmp('a ','a');
640+
strcmp('a','a ') strcmp('a ','a')
641+
0 0
642+
SELECT strcmp('a\0','a' ), strcmp('a','a\0');
643+
strcmp('a\0','a' ) strcmp('a','a\0')
644+
-1 1
645+
SELECT strcmp('a\0','a '), strcmp('a ','a\0');
646+
strcmp('a\0','a ') strcmp('a ','a\0')
647+
-1 1
648+
SELECT strcmp('a\t','a' ), strcmp('a', 'a\t');
649+
strcmp('a\t','a' ) strcmp('a', 'a\t')
650+
-1 1
651+
SELECT strcmp('a\t','a '), strcmp('a ', 'a\t');
652+
strcmp('a\t','a ') strcmp('a ', 'a\t')
653+
-1 1
624654
CREATE TABLE �a (a int);
625655
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '�a (a int)' at line 1
626656
SELECT '�a' as str;

mysql-test/r/ctype_latin2_ch.result

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ select * from t1 where tt like '%AA%';
3030
id tt
3131
drop table t1;
3232
set names latin2 collate latin2_czech_cs;
33-
SELECT strcmp('a','a ');
34-
strcmp('a','a ')
35-
0
36-
SELECT strcmp('a\0','a' );
37-
strcmp('a\0','a' )
38-
1
39-
SELECT strcmp('a\0','a ');
40-
strcmp('a\0','a ')
41-
1
42-
SELECT strcmp('a\t','a' );
43-
strcmp('a\t','a' )
44-
0
45-
SELECT strcmp('a\t','a ');
46-
strcmp('a\t','a ')
47-
0
33+
SELECT strcmp('a','a '), strcmp('a ','a');
34+
strcmp('a','a ') strcmp('a ','a')
35+
0 0
36+
SELECT strcmp('a\0','a' ), strcmp('a','a\0');
37+
strcmp('a\0','a' ) strcmp('a','a\0')
38+
1 -1
39+
SELECT strcmp('a\0','a '), strcmp('a ','a\0');
40+
strcmp('a\0','a ') strcmp('a ','a\0')
41+
1 -1
42+
SELECT strcmp('a\t','a' ), strcmp('a', 'a\t');
43+
strcmp('a\t','a' ) strcmp('a', 'a\t')
44+
0 0
45+
SELECT strcmp('a\t','a '), strcmp('a ', 'a\t');
46+
strcmp('a\t','a ') strcmp('a ', 'a\t')
47+
0 0
4848
#
4949
# MDEV-7149 Constant condition propagation erroneously applied for LIKE
5050
#
@@ -484,21 +484,21 @@ DROP TABLE t1;
484484
# WL#3664 WEIGHT_STRING
485485
#
486486
set names latin2 collate latin2_czech_cs;
487-
SELECT strcmp('a','a ');
488-
strcmp('a','a ')
489-
0
490-
SELECT strcmp('a\0','a' );
491-
strcmp('a\0','a' )
492-
1
493-
SELECT strcmp('a\0','a ');
494-
strcmp('a\0','a ')
495-
1
496-
SELECT strcmp('a\t','a' );
497-
strcmp('a\t','a' )
498-
0
499-
SELECT strcmp('a\t','a ');
500-
strcmp('a\t','a ')
501-
0
487+
SELECT strcmp('a','a '), strcmp('a ','a');
488+
strcmp('a','a ') strcmp('a ','a')
489+
0 0
490+
SELECT strcmp('a\0','a' ), strcmp('a','a\0');
491+
strcmp('a\0','a' ) strcmp('a','a\0')
492+
1 -1
493+
SELECT strcmp('a\0','a '), strcmp('a ','a\0');
494+
strcmp('a\0','a ') strcmp('a ','a\0')
495+
1 -1
496+
SELECT strcmp('a\t','a' ), strcmp('a', 'a\t');
497+
strcmp('a\t','a' ) strcmp('a', 'a\t')
498+
0 0
499+
SELECT strcmp('a\t','a '), strcmp('a ', 'a\t');
500+
strcmp('a\t','a ') strcmp('a ', 'a\t')
501+
0 0
502502
#
503503
# Note:
504504
# latin2_czech_cs does not support WEIGHT_STRING in full extent

mysql-test/r/ctype_tis620.result

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3630,6 +3630,21 @@ hex(weight_string('abc' as char(5) LEVEL 1 DESC))
36303630
select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
36313631
hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
36323632
DFDF9C9D9E
3633+
SELECT strcmp('a','a '), strcmp('a ','a');
3634+
strcmp('a','a ') strcmp('a ','a')
3635+
0 0
3636+
SELECT strcmp('a\0','a' ), strcmp('a','a\0');
3637+
strcmp('a\0','a' ) strcmp('a','a\0')
3638+
-1 1
3639+
SELECT strcmp('a\0','a '), strcmp('a ','a\0');
3640+
strcmp('a\0','a ') strcmp('a ','a\0')
3641+
-1 1
3642+
SELECT strcmp('a\t','a' ), strcmp('a', 'a\t');
3643+
strcmp('a\t','a' ) strcmp('a', 'a\t')
3644+
-1 1
3645+
SELECT strcmp('a\t','a '), strcmp('a ', 'a\t');
3646+
strcmp('a\t','a ') strcmp('a ', 'a\t')
3647+
-1 1
36333648
select hex(weight_string(cast(0xE0A1 as char)));
36343649
hex(weight_string(cast(0xE0A1 as char)))
36353650
A1E0
@@ -3808,6 +3823,21 @@ hex(weight_string('abc' as char(5) LEVEL 1 DESC))
38083823
select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
38093824
hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
38103825
DFDF9C9D9E
3826+
SELECT strcmp('a','a '), strcmp('a ','a');
3827+
strcmp('a','a ') strcmp('a ','a')
3828+
0 0
3829+
SELECT strcmp('a\0','a' ), strcmp('a','a\0');
3830+
strcmp('a\0','a' ) strcmp('a','a\0')
3831+
-1 1
3832+
SELECT strcmp('a\0','a '), strcmp('a ','a\0');
3833+
strcmp('a\0','a ') strcmp('a ','a\0')
3834+
-1 1
3835+
SELECT strcmp('a\t','a' ), strcmp('a', 'a\t');
3836+
strcmp('a\t','a' ) strcmp('a', 'a\t')
3837+
-1 1
3838+
SELECT strcmp('a\t','a '), strcmp('a ', 'a\t');
3839+
strcmp('a\t','a ') strcmp('a ', 'a\t')
3840+
-1 1
38113841
select hex(weight_string(cast(0xE0A1 as char)));
38123842
hex(weight_string(cast(0xE0A1 as char)))
38133843
E0A1

0 commit comments

Comments
 (0)