Commit 78277501 authored by unknown's avatar unknown

Merge bk-internal.mysql.com:/home/bk/mysql-5.1-new-maint

into  polly.local:/home/kaa/src/maint/m51-new-maint--07OGx


sql/sql_class.h:
  Auto merged
parents 40828100 06aadcd5
...@@ -200,3 +200,10 @@ CEMPNUM EMPMUM1 EMPNUM2 ...@@ -200,3 +200,10 @@ CEMPNUM EMPMUM1 EMPNUM2
0.00 0 0.00 0.00 0 0.00
2.00 2 NULL 2.00 2 NULL
DROP TABLE t1,t2; DROP TABLE t1,t2;
SELECT CASE 1 WHEN 1 THEN 18446744073709551615 ELSE 1 END;
CASE 1 WHEN 1 THEN 18446744073709551615 ELSE 1 END
18446744073709551615
SELECT COALESCE(18446744073709551615);
COALESCE(18446744073709551615)
18446744073709551615
End of 4.1 tests
...@@ -128,3 +128,10 @@ f1 f2 if(f1, 40.0, 5.00) ...@@ -128,3 +128,10 @@ f1 f2 if(f1, 40.0, 5.00)
0 0 5.00 0 0 5.00
1 1 40.00 1 1 40.00
drop table t1; drop table t1;
SELECT IF(1 != 0, 18446744073709551615, 1);
IF(1 != 0, 18446744073709551615, 1)
18446744073709551615
SELECT IFNULL(NULL, 18446744073709551615);
IFNULL(NULL, 18446744073709551615)
18446744073709551615
End of 4.1 tests
...@@ -204,3 +204,10 @@ NULL ...@@ -204,3 +204,10 @@ NULL
SELECT GREATEST(1.5E+2,1.3E+2,NULL) FROM DUAL; SELECT GREATEST(1.5E+2,1.3E+2,NULL) FROM DUAL;
GREATEST(1.5E+2,1.3E+2,NULL) GREATEST(1.5E+2,1.3E+2,NULL)
NULL NULL
SELECT GREATEST(1, 18446744073709551615);
GREATEST(1, 18446744073709551615)
18446744073709551615
SELECT LEAST(1, 18446744073709551615);
LEAST(1, 18446744073709551615)
1
End of 4.1 tests
...@@ -301,3 +301,4 @@ select @var; ...@@ -301,3 +301,4 @@ select @var;
@var @var
3 3
drop table t1; drop table t1;
End of 4.1 tests
...@@ -133,8 +133,6 @@ select min(a), min(case when 1=1 then a else NULL end), ...@@ -133,8 +133,6 @@ select min(a), min(case when 1=1 then a else NULL end),
from t1 where b=3 group by b; from t1 where b=3 group by b;
drop table t1; drop table t1;
# End of 4.1 tests
# #
# Tests for bug #9939: conversion of the arguments for COALESCE and IFNULL # Tests for bug #9939: conversion of the arguments for COALESCE and IFNULL
...@@ -154,3 +152,12 @@ SELECT IFNULL(t2.EMPNUM,t1.EMPNUM) AS CEMPNUM, ...@@ -154,3 +152,12 @@ SELECT IFNULL(t2.EMPNUM,t1.EMPNUM) AS CEMPNUM,
FROM t1 LEFT JOIN t2 ON t1.EMPNUM=t2.EMPNUM; FROM t1 LEFT JOIN t2 ON t1.EMPNUM=t2.EMPNUM;
DROP TABLE t1,t2; DROP TABLE t1,t2;
#
# Bug #20924: CAST(expr as UNSIGNED) returns SIGNED value when used in various
# functions
# - UNSIGNED values in CASE and COALESCE are treated as SIGNED
#
SELECT CASE 1 WHEN 1 THEN 18446744073709551615 ELSE 1 END;
SELECT COALESCE(18446744073709551615);
--echo End of 4.1 tests
...@@ -97,3 +97,18 @@ create table t1 (f1 int, f2 int); ...@@ -97,3 +97,18 @@ create table t1 (f1 int, f2 int);
insert into t1 values(1,1),(0,0); insert into t1 values(1,1),(0,0);
select f1, f2, if(f1, 40.0, 5.00) from t1 group by f1 order by f2; select f1, f2, if(f1, 40.0, 5.00) from t1 group by f1 order by f2;
drop table t1; drop table t1;
#
# Bug #20924: CAST(expr as UNSIGNED) returns SIGNED value when used in various
# functions
# - UNSIGNED values in IF() are treated as SIGNED
#
SELECT IF(1 != 0, 18446744073709551615, 1);
#
# Bug #20924: CAST(expr as UNSIGNED) returns SIGNED value when used in various
# functions
# - UNSIGNED values in IFNULL() are treated as SIGNED
#
SELECT IFNULL(NULL, 18446744073709551615);
--echo End of 4.1 tests
...@@ -108,8 +108,6 @@ select 5.1 mod 3, 5.1 mod -3, -5.1 mod 3, -5.1 mod -3; ...@@ -108,8 +108,6 @@ select 5.1 mod 3, 5.1 mod -3, -5.1 mod 3, -5.1 mod -3;
select 5 mod 3, 5 mod -3, -5 mod 3, -5 mod -3; select 5 mod 3, 5 mod -3, -5 mod 3, -5 mod -3;
# End of 4.1 tests
# #
# Bug#6726: NOT BETWEEN parse failure # Bug#6726: NOT BETWEEN parse failure
# #
...@@ -127,3 +125,13 @@ SELECT GREATEST(1,NULL) FROM DUAL; ...@@ -127,3 +125,13 @@ SELECT GREATEST(1,NULL) FROM DUAL;
SELECT LEAST('xxx','aaa',NULL,'yyy') FROM DUAL; SELECT LEAST('xxx','aaa',NULL,'yyy') FROM DUAL;
SELECT LEAST(1.1,1.2,NULL,1.0) FROM DUAL; SELECT LEAST(1.1,1.2,NULL,1.0) FROM DUAL;
SELECT GREATEST(1.5E+2,1.3E+2,NULL) FROM DUAL; SELECT GREATEST(1.5E+2,1.3E+2,NULL) FROM DUAL;
#
# Bug #20924: CAST(expr as UNSIGNED) returns SIGNED value when used in various
# functions
# - UNSIGNED values in GREATEST() and LEAST() are treated as SIGNED
#
SELECT GREATEST(1, 18446744073709551615);
SELECT LEAST(1, 18446744073709551615);
--echo End of 4.1 tests
...@@ -144,8 +144,6 @@ select @@version; ...@@ -144,8 +144,6 @@ select @@version;
--replace_column 1 # --replace_column 1 #
select @@global.version; select @@global.version;
# End of 4.1 tests
# #
# Bug #6598: problem with cast(NULL as signed integer); # Bug #6598: problem with cast(NULL as signed integer);
# #
...@@ -212,3 +210,5 @@ insert into t1 values (1,2),(2,3),(3,1); ...@@ -212,3 +210,5 @@ insert into t1 values (1,2),(2,3),(3,1);
select @var:=f2 from t1 group by f1 order by f2 desc limit 1; select @var:=f2 from t1 group by f1 order by f2 desc limit 1;
select @var; select @var;
drop table t1; drop table t1;
--echo End of 4.1 tests
...@@ -745,11 +745,7 @@ int Arg_comparator::compare_int_signed_unsigned() ...@@ -745,11 +745,7 @@ int Arg_comparator::compare_int_signed_unsigned()
if (!(*b)->null_value) if (!(*b)->null_value)
{ {
owner->null_value= 0; owner->null_value= 0;
if (sval1 < 0 || (ulonglong)sval1 < uval2) return ::compare_int_signed_unsigned(sval1, uval2);
return -1;
if ((ulonglong)sval1 == uval2)
return 0;
return 1;
} }
} }
owner->null_value= 1; owner->null_value= 1;
...@@ -770,13 +766,7 @@ int Arg_comparator::compare_int_unsigned_signed() ...@@ -770,13 +766,7 @@ int Arg_comparator::compare_int_unsigned_signed()
if (!(*b)->null_value) if (!(*b)->null_value)
{ {
owner->null_value= 0; owner->null_value= 0;
if (sval2 < 0) return ::compare_int_unsigned_signed(uval1, sval2);
return 1;
if (uval1 < (ulonglong)sval2)
return -1;
if (uval1 == (ulonglong)sval2)
return 0;
return 1;
} }
} }
owner->null_value= 1; owner->null_value= 1;
...@@ -1417,11 +1407,13 @@ Item_func_ifnull::int_op() ...@@ -1417,11 +1407,13 @@ Item_func_ifnull::int_op()
if (!args[0]->null_value) if (!args[0]->null_value)
{ {
null_value=0; null_value=0;
unsigned_flag= args[0]->unsigned_flag;
return value; return value;
} }
value=args[1]->val_int(); value=args[1]->val_int();
if ((null_value=args[1]->null_value)) if ((null_value=args[1]->null_value))
return 0; return 0;
unsigned_flag= args[1]->unsigned_flag;
return value; return value;
} }
...@@ -1572,6 +1564,7 @@ Item_func_if::val_int() ...@@ -1572,6 +1564,7 @@ Item_func_if::val_int()
Item *arg= args[0]->val_bool() ? args[1] : args[2]; Item *arg= args[0]->val_bool() ? args[1] : args[2];
longlong value=arg->val_int(); longlong value=arg->val_int();
null_value=arg->null_value; null_value=arg->null_value;
unsigned_flag= arg->unsigned_flag;
return value; return value;
} }
...@@ -1820,6 +1813,7 @@ longlong Item_func_case::val_int() ...@@ -1820,6 +1813,7 @@ longlong Item_func_case::val_int()
} }
res=item->val_int(); res=item->val_int();
null_value=item->null_value; null_value=item->null_value;
unsigned_flag= item->unsigned_flag;
return res; return res;
} }
...@@ -2006,7 +2000,10 @@ longlong Item_func_coalesce::int_op() ...@@ -2006,7 +2000,10 @@ longlong Item_func_coalesce::int_op()
{ {
longlong res=args[i]->val_int(); longlong res=args[i]->val_int();
if (!args[i]->null_value) if (!args[i]->null_value)
{
unsigned_flag= args[i]->unsigned_flag;
return res; return res;
}
} }
null_value=1; null_value=1;
return 0; return 0;
......
...@@ -1411,3 +1411,17 @@ inline Item *and_conds(Item *a, Item *b) ...@@ -1411,3 +1411,17 @@ inline Item *and_conds(Item *a, Item *b)
} }
Item *and_expressions(Item *a, Item *b, Item **org_item); Item *and_expressions(Item *a, Item *b, Item **org_item);
inline int compare_int_signed_unsigned(longlong sval, ulonglong uval)
{
if (sval < 0 || (ulonglong)sval < uval)
return -1;
if ((ulonglong)sval == uval)
return 0;
return 1;
}
inline int compare_int_unsigned_signed(ulonglong uval, longlong sval)
{
return -compare_int_signed_unsigned(sval, uval);
}
...@@ -2169,18 +2169,33 @@ longlong Item_func_min_max::val_int() ...@@ -2169,18 +2169,33 @@ longlong Item_func_min_max::val_int()
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
longlong value=0; longlong value=0;
my_bool arg_unsigned_flag;
my_bool cmp;
for (uint i=0; i < arg_count ; i++) for (uint i=0; i < arg_count ; i++)
{ {
longlong tmp= args[i]->val_int();
if ((null_value= args[i]->null_value))
break;
arg_unsigned_flag= args[i]->unsigned_flag;
if (i == 0) if (i == 0)
value=args[i]->val_int(); {
value= tmp;
unsigned_flag= arg_unsigned_flag;
}
else else
{ {
longlong tmp=args[i]->val_int(); if (unsigned_flag == arg_unsigned_flag)
if (!args[i]->null_value && (tmp < value ? cmp_sign : -cmp_sign) > 0) cmp= tmp < value;
value=tmp; else if (unsigned_flag)
cmp= compare_int_signed_unsigned(tmp, value) < 0;
else
cmp= compare_int_unsigned_signed(tmp, value) < 0;
if ((cmp ? cmp_sign : -cmp_sign) > 0)
{
value= tmp;
unsigned_flag= arg_unsigned_flag;
}
} }
if ((null_value= args[i]->null_value))
break;
} }
return value; return value;
} }
...@@ -3821,7 +3836,7 @@ Item_func_set_user_var::update() ...@@ -3821,7 +3836,7 @@ Item_func_set_user_var::update()
case REAL_RESULT: case REAL_RESULT:
{ {
res= update_hash((void*) &save_result.vreal,sizeof(save_result.vreal), res= update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
REAL_RESULT, &my_charset_bin, DERIVATION_IMPLICIT); REAL_RESULT, &my_charset_bin, DERIVATION_IMPLICIT, 0);
break; break;
} }
case INT_RESULT: case INT_RESULT:
...@@ -3835,23 +3850,23 @@ Item_func_set_user_var::update() ...@@ -3835,23 +3850,23 @@ Item_func_set_user_var::update()
{ {
if (!save_result.vstr) // Null value if (!save_result.vstr) // Null value
res= update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin, res= update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin,
DERIVATION_IMPLICIT); DERIVATION_IMPLICIT, 0);
else else
res= update_hash((void*) save_result.vstr->ptr(), res= update_hash((void*) save_result.vstr->ptr(),
save_result.vstr->length(), STRING_RESULT, save_result.vstr->length(), STRING_RESULT,
save_result.vstr->charset(), save_result.vstr->charset(),
DERIVATION_IMPLICIT); DERIVATION_IMPLICIT, 0);
break; break;
} }
case DECIMAL_RESULT: case DECIMAL_RESULT:
{ {
if (!save_result.vdec) // Null value if (!save_result.vdec) // Null value
res= update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin, res= update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin,
DERIVATION_IMPLICIT); DERIVATION_IMPLICIT, 0);
else else
res= update_hash((void*) save_result.vdec, res= update_hash((void*) save_result.vdec,
sizeof(my_decimal), DECIMAL_RESULT, sizeof(my_decimal), DECIMAL_RESULT,
&my_charset_bin, DERIVATION_IMPLICIT); &my_charset_bin, DERIVATION_IMPLICIT, 0);
break; break;
} }
case ROW_RESULT: case ROW_RESULT:
......
...@@ -1202,7 +1202,7 @@ class Item_func_set_user_var :public Item_func ...@@ -1202,7 +1202,7 @@ class Item_func_set_user_var :public Item_func
String *val_str(String *str); String *val_str(String *str);
my_decimal *val_decimal(my_decimal *); my_decimal *val_decimal(my_decimal *);
bool update_hash(void *ptr, uint length, enum Item_result type, bool update_hash(void *ptr, uint length, enum Item_result type,
CHARSET_INFO *cs, Derivation dv, bool unsigned_arg= 0); CHARSET_INFO *cs, Derivation dv, bool unsigned_arg);
bool send(Protocol *protocol, String *str_arg); bool send(Protocol *protocol, String *str_arg);
void make_field(Send_field *tmp_field); void make_field(Send_field *tmp_field);
bool check(bool use_result_field); bool check(bool use_result_field);
......
...@@ -3923,7 +3923,7 @@ int User_var_log_event::exec_event(struct st_relay_log_info* rli) ...@@ -3923,7 +3923,7 @@ int User_var_log_event::exec_event(struct st_relay_log_info* rli)
a single record and with a single column. Thus, like a single record and with a single column. Thus, like
a column value, it could always have IMPLICIT derivation. a column value, it could always have IMPLICIT derivation.
*/ */
e.update_hash(val, val_len, type, charset, DERIVATION_IMPLICIT); e.update_hash(val, val_len, type, charset, DERIVATION_IMPLICIT, 0);
free_root(thd->mem_root,0); free_root(thd->mem_root,0);
rli->inc_event_relay_log_pos(); rli->inc_event_relay_log_pos();
......
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