Commit ef325a47 authored by unknown's avatar unknown

a proper fix for the bug #2298 Trailing whitespace inconsistently handled in WHERE clause.

<monty> ramil, in MySQL/MyISAM we should only strip end space, not 'space-like' characters.
<monty> This is according to SQL;  When doing a comparision end space and only end space are ignored.



myisam/mi_key.c:
  a proper fix for the bug #2298 Trailing whitespace inconsistently handled in WHERE clause.
myisam/mi_search.c:
  a proper fix for the bug #2298 Trailing whitespace inconsistently handled in WHERE clause.
mysql-test/r/select.result:
  test case for the bug #2298 Trailing whitespace inconsistently handled in WHERE clause.
mysql-test/t/select.test:
  test case for the bug #2298 Trailing whitespace inconsistently handled in WHERE clause.
sql/sql_string.cc:
  a proper fix for the bug #2298 Trailing whitespace inconsistently handled in WHERE clause.
parent 9d59b348
......@@ -62,7 +62,7 @@ uint _mi_make_key(register MI_INFO *info, uint keynr, uchar *key,
end=pos+length;
if (type != HA_KEYTYPE_NUM)
{
while (end > pos && (end[-1] == ' ' || end[-1] == '\t'))
while (end > pos && end[-1] == ' ')
end--;
}
else
......@@ -186,7 +186,7 @@ uint _mi_pack_key(register MI_INFO *info, uint keynr, uchar *key, uchar *old,
end=pos+length;
if (type != HA_KEYTYPE_NUM)
{
while (end > pos && (end[-1] == ' ' || end[-1] == '\t'))
while (end > pos && end[-1] == ' ')
end--;
}
else
......
......@@ -795,9 +795,9 @@ int _mi_key_cmp(register MI_KEYSEG *keyseg, register uchar *a,
uint length=(uint) (end-a), a_length=length, b_length=length;
if (!(nextflag & SEARCH_PREFIX))
{
while (a_length && (a[a_length-1] == ' ' || a[a_length-1] == '\t'))
while (a_length && a[a_length-1] == ' ')
a_length--;
while (b_length && (b[b_length-1] == ' ' || b[b_length-1] == '\t'))
while (b_length && b[b_length-1] == ' ')
b_length--;
}
if (piks &&
......@@ -849,9 +849,9 @@ int _mi_key_cmp(register MI_KEYSEG *keyseg, register uchar *a,
if (!(nextflag & (SEARCH_PREFIX | SEARCH_UPDATE)))
{
while (a_length && (a[a_length-1] == ' ' || a[a_length-1] == '\t'))
while (a_length && a[a_length-1] == ' ')
a_length--;
while (b_length && (b[b_length-1] == ' ' || b[b_length-1] == '\t'))
while (b_length && b[b_length-1] == ' ')
b_length--;
}
if (piks &&
......
......@@ -2307,3 +2307,23 @@ left join t4 on id3 = id4 where id2 = 1 or id4 = 1;
id1 id2 id3 id4 id44
1 1 NULL NULL NULL
drop table t1,t2,t3,t4;
create table t1(s varchar(10) not null);
create table t2(s varchar(10) not null primary key);
create table t3(s varchar(10) not null primary key);
insert into t1 values ('one\t'), ('two\t');
insert into t2 values ('one\r'), ('two\t');
insert into t3 values ('one '), ('two\t');
select * from t1 where s = 'one';
s
select * from t2 where s = 'one';
s
select * from t3 where s = 'one';
s
one
select * from t1,t2 where t1.s = t2.s;
s s
two two
select * from t2,t3 where t2.s = t3.s;
s s
two two
drop table t1, t2, t3;
......@@ -1858,3 +1858,19 @@ left join t4 on id3 = id4 where id2 = 1 or id4 = 1;
drop table t1,t2,t3,t4;
#
# Bug #2298
#
create table t1(s varchar(10) not null);
create table t2(s varchar(10) not null primary key);
create table t3(s varchar(10) not null primary key);
insert into t1 values ('one\t'), ('two\t');
insert into t2 values ('one\r'), ('two\t');
insert into t3 values ('one '), ('two\t');
select * from t1 where s = 'one';
select * from t2 where s = 'one';
select * from t3 where s = 'one';
select * from t1,t2 where t1.s = t2.s;
select * from t2,t3 where t2.s = t3.s;
drop table t1, t2, t3;
......@@ -467,9 +467,9 @@ int sortcmp(const String *x,const String *y)
if (use_strcoll(default_charset_info))
{
#ifndef CMP_ENDSPACE
while (x_len && isspace(s[x_len-1]))
while (x_len && s[x_len-1] == ' ')
x_len--;
while (y_len && isspace(t[y_len-1]))
while (y_len && t[y_len-1] == ' ')
y_len--;
#endif
return my_strnncoll(default_charset_info,
......@@ -493,14 +493,14 @@ int sortcmp(const String *x,const String *y)
{
const char *end=t+y_len;
for (; t != end ; t++)
if (!isspace(*t))
if (*t != ' ')
return -1;
}
else
{
const char *end=s+x_len;
for (; s != end ; s++)
if (!isspace(*s))
if (*s != ' ')
return 1;
}
return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment