Commit 1b9f594f authored by unknown's avatar unknown

Fixed bug #28625:

DECIMAL column was used instead of BIGINT for the minimal possible
BIGINT (-9223372036854775808).

The Item_func_neg::fix_length_and_dec has been adjusted to
to inherit the type of the argument in the case when it's an 
Item_int object whose value is equal to LONGLONG_MIN.


sql/item_func.cc:
  Fixed bug #28625.
  The Item_func_neg::fix_length_and_dec has been adjusted to
  to inherit the type of the argument in the case when it's an 
  Item_int object whose value is equal to LONGLONG_MIN.
mysql-test/t/bigint.test:
  Added test result for bug #28625.
mysql-test/r/bigint.result:
  Added test case for bug #28625.
parent 865f294f
...@@ -362,3 +362,29 @@ cast(-19999999999999999999 as signed) ...@@ -362,3 +362,29 @@ cast(-19999999999999999999 as signed)
-9223372036854775808 -9223372036854775808
Warnings: Warnings:
Error 1292 Truncated incorrect DECIMAL value: '' Error 1292 Truncated incorrect DECIMAL value: ''
select -9223372036854775808;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def -9223372036854775808 8 20 20 N 32897 0 63
-9223372036854775808
-9223372036854775808
select -(9223372036854775808);
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def -(9223372036854775808) 8 20 20 N 32897 0 63
-(9223372036854775808)
-9223372036854775808
select -((9223372036854775808));
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def -((9223372036854775808)) 8 20 20 N 32897 0 63
-((9223372036854775808))
-9223372036854775808
select -(-(9223372036854775808));
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def -(-(9223372036854775808)) 246 21 19 N 129 0 63
-(-(9223372036854775808))
9223372036854775808
select --9223372036854775808, ---9223372036854775808, ----9223372036854775808;
--9223372036854775808 ---9223372036854775808 ----9223372036854775808
9223372036854775808 -9223372036854775808 9223372036854775808
select -(-9223372036854775808), -(-(-9223372036854775808));
-(-9223372036854775808) -(-(-9223372036854775808))
9223372036854775808 -9223372036854775808
...@@ -294,3 +294,16 @@ drop table t1; ...@@ -294,3 +294,16 @@ drop table t1;
select cast(19999999999999999999 as signed); select cast(19999999999999999999 as signed);
select cast(-19999999999999999999 as signed); select cast(-19999999999999999999 as signed);
#
# Bug #28625: -9223372036854775808 doesn't fit in BIGINT.
#
--enable_metadata
select -9223372036854775808;
select -(9223372036854775808);
select -((9223372036854775808));
select -(-(9223372036854775808));
--disable_metadata
select --9223372036854775808, ---9223372036854775808, ----9223372036854775808;
select -(-9223372036854775808), -(-(-9223372036854775808));
...@@ -1523,16 +1523,20 @@ void Item_func_neg::fix_length_and_dec() ...@@ -1523,16 +1523,20 @@ void Item_func_neg::fix_length_and_dec()
Use val() to get value as arg_type doesn't mean that item is Use val() to get value as arg_type doesn't mean that item is
Item_int or Item_real due to existence of Item_param. Item_int or Item_real due to existence of Item_param.
*/ */
if (hybrid_type == INT_RESULT && if (hybrid_type == INT_RESULT && args[0]->const_item())
args[0]->type() == INT_ITEM &&
((ulonglong) args[0]->val_int() >= (ulonglong) LONGLONG_MIN))
{ {
/* longlong val= args[0]->val_int();
Ensure that result is converted to DECIMAL, as longlong can't hold if ((ulonglong) val >= (ulonglong) LONGLONG_MIN &&
the negated number ((ulonglong) val != (ulonglong) LONGLONG_MIN ||
*/ args[0]->type() != INT_ITEM))
hybrid_type= DECIMAL_RESULT; {
DBUG_PRINT("info", ("Type changed: DECIMAL_RESULT")); /*
Ensure that result is converted to DECIMAL, as longlong can't hold
the negated number
*/
hybrid_type= DECIMAL_RESULT;
DBUG_PRINT("info", ("Type changed: DECIMAL_RESULT"));
}
} }
unsigned_flag= 0; unsigned_flag= 0;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
......
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