Commit 23d03a1b authored by Sergei Golubchik's avatar Sergei Golubchik

parse negative numbers into one item

use Item->neg to convert generate negative Item_num's
instead of Item_func_neg(Item_num).

Based on the following commit:

  Author: Monty <monty@mariadb.org>
  Date:   Mon May 30 22:44:00 2016 +0300

    Make negative number their own token
    The negation (-) operator will call Item->neg() one underlying numeric constants
    and remove itself (like the NOT() function does today for other NOT functions.

    This simplifies things
    - -1 is not anymore an expression but a basic_const_item
      - improves optimizer
      - DEFAULT -1 doesn't need special handling anymore
      - When we add DEFAULT expressions, -1 will be treated exactly like 1
    - printing of items doesn't anymore put braces around all negative numbers

    Other things fixed:
    - Fixed that longlong converted to decimal's has a more appropriate size
    - Fixed that "-0.0" read into a decimal is interpreted as 0.0
parent 60916a8b
......@@ -402,7 +402,7 @@ drop table t1;
create table t1 select -9223372036854775809 bi;
describe t1;
Field Type Null Key Default Extra
bi decimal(19,0) NO NULL
bi decimal(20,0) NO NULL
drop table t1;
#
# Bug #45360: wrong results
......
......@@ -142,7 +142,7 @@ SELECT (CONVERT('0' USING latin1) IN (CHAR(COT('v') USING utf8),''));
ERROR 22003: DOUBLE value is out of range in 'cot('v')'
SET NAMES utf8 COLLATE utf8_latvian_ci ;
SELECT UPDATEXML(-73 * -2465717823867977728,@@global.auto_increment_increment,null);
ERROR 22003: BIGINT value is out of range in '(-(73) * -(2465717823867977728))'
ERROR 22003: BIGINT value is out of range in '(-73 * -2465717823867977728)'
#
# End Bug#57882
#
......
This diff is collapsed.
......@@ -5,7 +5,7 @@ explain extended select 1+1,1-1,1+1*2,8/5,8%5,mod(8,5),mod(8,5)|0,-(1+1)*-2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select (1 + 1) AS `1+1`,(1 - 1) AS `1-1`,(1 + (1 * 2)) AS `1+1*2`,(8 / 5) AS `8/5`,(8 % 5) AS `8%5`,(8 % 5) AS `mod(8,5)`,((8 % 5) | 0) AS `mod(8,5)|0`,(-((1 + 1)) * -(2)) AS `-(1+1)*-2`
Note 1003 select (1 + 1) AS `1+1`,(1 - 1) AS `1-1`,(1 + (1 * 2)) AS `1+1*2`,(8 / 5) AS `8/5`,(8 % 5) AS `8%5`,(8 % 5) AS `mod(8,5)`,((8 % 5) | 0) AS `mod(8,5)|0`,(-((1 + 1)) * -2) AS `-(1+1)*-2`
select 1 | (1+1),5 & 3,bit_count(7) ;
1 | (1+1) 5 & 3 bit_count(7)
3 1 3
......
......@@ -874,7 +874,7 @@ explain extended select period_add("9602",-12),period_diff(199505,"9404"),from_d
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select period_add('9602',-(12)) AS `period_add("9602",-12)`,period_diff(199505,'9404') AS `period_diff(199505,"9404")`,from_days(to_days('960101')) AS `from_days(to_days("960101"))`,dayofmonth('1997-01-02') AS `dayofmonth("1997-01-02")`,month('1997-01-02') AS `month("1997-01-02")`,monthname('1972-03-04') AS `monthname("1972-03-04")`,dayofyear('0000-00-00') AS `dayofyear("0000-00-00")`,hour('1997-03-03 23:03:22') AS `HOUR("1997-03-03 23:03:22")`,minute('23:03:22') AS `MINUTE("23:03:22")`,second(230322) AS `SECOND(230322)`,quarter(980303) AS `QUARTER(980303)`,week('1998-03-03',@@default_week_format) AS `WEEK("1998-03-03")`,yearweek('2000-01-01',1) AS `yearweek("2000-01-01",1)`,week(19950101,1) AS `week(19950101,1)`,year('98-02-03') AS `year("98-02-03")`,(weekday(curdate()) - weekday(now())) AS `weekday(curdate())-weekday(now())`,dayname('1962-03-03') AS `dayname("1962-03-03")`,unix_timestamp() AS `unix_timestamp()`,sec_to_time((time_to_sec('0:30:47') / 6.21)) AS `sec_to_time(time_to_sec("0:30:47")/6.21)`,curtime() AS `curtime()`,utc_time() AS `utc_time()`,curdate() AS `curdate()`,utc_date() AS `utc_date()`,utc_timestamp() AS `utc_timestamp()`,date_format('1997-01-02 03:04:05','%M %W %D %Y %y %m %d %h %i %s %w') AS `date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w")`,from_unixtime(unix_timestamp('1994-03-02 10:11:12')) AS `from_unixtime(unix_timestamp("1994-03-02 10:11:12"))`,('1997-12-31 23:59:59' + interval 1 second) AS `"1997-12-31 23:59:59" + INTERVAL 1 SECOND`,('1998-01-01 00:00:00' - interval 1 second) AS `"1998-01-01 00:00:00" - INTERVAL 1 SECOND`,('1997-12-31' + interval 1 day) AS `INTERVAL 1 DAY + "1997-12-31"`,extract(year from '1999-01-02 10:11:12') AS `extract(YEAR FROM "1999-01-02 10:11:12")`,('1997-12-31 23:59:59' + interval 1 second) AS `date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND)`
Note 1003 select period_add('9602',-12) AS `period_add("9602",-12)`,period_diff(199505,'9404') AS `period_diff(199505,"9404")`,from_days(to_days('960101')) AS `from_days(to_days("960101"))`,dayofmonth('1997-01-02') AS `dayofmonth("1997-01-02")`,month('1997-01-02') AS `month("1997-01-02")`,monthname('1972-03-04') AS `monthname("1972-03-04")`,dayofyear('0000-00-00') AS `dayofyear("0000-00-00")`,hour('1997-03-03 23:03:22') AS `HOUR("1997-03-03 23:03:22")`,minute('23:03:22') AS `MINUTE("23:03:22")`,second(230322) AS `SECOND(230322)`,quarter(980303) AS `QUARTER(980303)`,week('1998-03-03',@@default_week_format) AS `WEEK("1998-03-03")`,yearweek('2000-01-01',1) AS `yearweek("2000-01-01",1)`,week(19950101,1) AS `week(19950101,1)`,year('98-02-03') AS `year("98-02-03")`,(weekday(curdate()) - weekday(now())) AS `weekday(curdate())-weekday(now())`,dayname('1962-03-03') AS `dayname("1962-03-03")`,unix_timestamp() AS `unix_timestamp()`,sec_to_time((time_to_sec('0:30:47') / 6.21)) AS `sec_to_time(time_to_sec("0:30:47")/6.21)`,curtime() AS `curtime()`,utc_time() AS `utc_time()`,curdate() AS `curdate()`,utc_date() AS `utc_date()`,utc_timestamp() AS `utc_timestamp()`,date_format('1997-01-02 03:04:05','%M %W %D %Y %y %m %d %h %i %s %w') AS `date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w")`,from_unixtime(unix_timestamp('1994-03-02 10:11:12')) AS `from_unixtime(unix_timestamp("1994-03-02 10:11:12"))`,('1997-12-31 23:59:59' + interval 1 second) AS `"1997-12-31 23:59:59" + INTERVAL 1 SECOND`,('1998-01-01 00:00:00' - interval 1 second) AS `"1998-01-01 00:00:00" - INTERVAL 1 SECOND`,('1997-12-31' + interval 1 day) AS `INTERVAL 1 DAY + "1997-12-31"`,extract(year from '1999-01-02 10:11:12') AS `extract(YEAR FROM "1999-01-02 10:11:12")`,('1997-12-31 23:59:59' + interval 1 second) AS `date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND)`
SET @TMP='2007-08-01 12:22:49';
CREATE TABLE t1 (d DATETIME);
INSERT INTO t1 VALUES ('2007-08-01 12:22:59');
......
......@@ -83,7 +83,7 @@ explain extended select * from t1 where a=-1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 9.52 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = <cache>(-(1)))
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = -1)
drop table t0, t1;
#
# MDEV-4362: Selectivity estimates for IN (...) do not depend on whether the values are in range
......@@ -110,12 +110,12 @@ explain extended select * from t1 where col1 in (-1,-2,-3);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10000 5.94 Using where
Warnings:
Note 1003 select `test`.`t1`.`col1` AS `col1` from `test`.`t1` where (`test`.`t1`.`col1` in (<cache>(-(1)),<cache>(-(2)),<cache>(-(3))))
Note 1003 select `test`.`t1`.`col1` AS `col1` from `test`.`t1` where (`test`.`t1`.`col1` in (-1,-2,-3))
explain extended select * from t1 where col1<=-1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10000 1.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`col1` AS `col1` from `test`.`t1` where (`test`.`t1`.`col1` <= <cache>(-(1)))
Note 1003 select `test`.`t1`.`col1` AS `col1` from `test`.`t1` where (`test`.`t1`.`col1` <= -1)
drop table t1, t2;
#
# MDEV-5984: EITS: Incorrect filtered% value for single-table select with range access
......
......@@ -878,7 +878,7 @@ ERROR 42000: Column length too big for column 'a' (max = 255); use BLOB or TEXT
CREATE TABLE b15776 (a char(4294967295));
ERROR 42000: Column length too big for column 'a' (max = 255); use BLOB or TEXT instead
CREATE TABLE b15776 (a char(4294967296));
ERROR 42000: Display width out of range for 'a' (max = 4294967295)
ERROR 42000: Column length too big for column 'a' (max = 255); use BLOB or TEXT instead
CREATE TABLE b15776 (a year(4294967295));
Warnings:
Note 1287 'YEAR(4294967295)' is deprecated and will be removed in a future release. Please use YEAR(4) instead
......@@ -888,7 +888,12 @@ a
2042
DROP TABLE b15776;
CREATE TABLE b15776 (a year(4294967296));
ERROR 42000: Display width out of range for 'a' (max = 4294967295)
SHOW CREATE TABLE b15776;
Table Create Table
b15776 CREATE TABLE `b15776` (
`a` year(4) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE b15776;
CREATE TABLE b15776 (a year(0));
Warnings:
Note 1287 'YEAR(0)' is deprecated and will be removed in a future release. Please use YEAR(4) instead
......@@ -900,17 +905,22 @@ ERROR 42000: Too big precision 4294967294 specified for 'a'. Maximum is 6.
CREATE TABLE b15776 (a timestamp(4294967295));
ERROR 42000: Too big precision 4294967295 specified for 'a'. Maximum is 6.
CREATE TABLE b15776 (a timestamp(4294967296));
ERROR 42000: Display width out of range for 'a' (max = 4294967295)
ERROR 42000: Too big precision 4294967296 specified for 'a'. Maximum is 6.
CREATE TABLE b15776 (a timestamp(-1));
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 '-1))' at line 1
CREATE TABLE b15776 (a timestamp(-2));
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 '-2))' at line 1
CREATE TABLE b15776 (a int(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
ERROR 42000: Display width out of range for 'a' (max = 4294967295)
ERROR 42000: Display width out of range for 'a' (max = 255)
CREATE TABLE b15776 (a char(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
ERROR 42000: Display width out of range for 'a' (max = 4294967295)
ERROR 42000: Column length too big for column 'a' (max = 255); use BLOB or TEXT instead
CREATE TABLE b15776 (a year(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
ERROR 42000: Display width out of range for 'a' (max = 4294967295)
SHOW CREATE TABLE b15776;
Table Create Table
b15776 CREATE TABLE `b15776` (
`a` year(4) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE b15776;
CREATE TABLE b15776 select cast(null as char(4294967295));
show columns from b15776;
Field Type Null Key Default Extra
......
......@@ -176,7 +176,7 @@ Table Create Table
t1 CREATE TABLE `t1` (
`round(15.4,-1)` decimal(3,0) NOT NULL,
`truncate(-5678.123451,-3)` decimal(4,0) NOT NULL,
`abs(-1.1)` decimal(3,1) NOT NULL,
`abs(-1.1)` decimal(2,1) NOT NULL,
`-(-1.1)` decimal(2,1) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
......
......@@ -4404,7 +4404,7 @@ SELECT * FROM v1 WHERE a > -1 OR a > 6 AND a = 3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 7 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > <cache>(-(1)))
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > -1)
SELECT * FROM v1 WHERE a > -1 OR a AND a = 0;
a
2
......@@ -4419,7 +4419,7 @@ SELECT * FROM v1 WHERE a > -1 OR a AND a = 0;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 7 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > <cache>(-(1)))
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > -1)
CREATE VIEW v2 AS SELECT * FROM v1;
SELECT * FROM v2 WHERE a > -1 OR a AND a = 0;
a
......@@ -4435,7 +4435,7 @@ SELECT * FROM v2 WHERE a > -1 OR a AND a = 0;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 7 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > <cache>(-(1)))
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > -1)
DROP VIEW v1,v2;
DROP TABLE t1;
CREATE TABLE t1 (a varchar(10), KEY (a)) ;
......
......@@ -22,7 +22,7 @@ a b c
1 -1 -1
explain select * from t2 where c=-1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref c c 5 const 1 Using index condition
1 SIMPLE t2 ref c c 5 const 1
# select_type=SIMPLE, type=ALL
select * from t1 where b=-1;
a b c
......@@ -53,7 +53,7 @@ a b c a b c
explain select * from t1,t3 where t1.c=t3.c and t3.c=-1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 const c c 5 const 1
1 SIMPLE t1 ref c c 5 const 2 Using index condition
1 SIMPLE t1 ref c c 5 const 2
# select_type=PRIMARY, type=index,ALL
select * from t1 where b in (select c from t3);
a b c
......
......@@ -53,7 +53,7 @@ a b c a b c
explain select * from t1,t3 where t1.c=t3.c and t3.c=-1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 const c c 5 const 1
1 SIMPLE t1 ref c c 5 const 2 Using index condition
1 SIMPLE t1 ref c c 5 const 2
# select_type=PRIMARY, type=index,ALL
select * from t1 where b in (select c from t3);
a b c
......
......@@ -586,5 +586,9 @@ SELECT STDDEV_POP(ROUND(0,@A:=2009)) FROM (SELECT 1 UNION SELECT 2) fake_table;
--echo #
--echo # End of 10.0 tests
--echo # Start of 10.2 tests
--echo #
--echo # Test zero
select 0=0, 0=-0, 0.0= -0.0, 0.0 = -(0.0), 0.0E1=-0.0E1, 0.0E1=-(0.0E1);
......@@ -515,7 +515,7 @@ CREATE TABLE b15776 (a char(2147483648));
--error ER_TOO_BIG_FIELDLENGTH
CREATE TABLE b15776 (a char(4294967295));
# Even BLOB won't hold
--error ER_TOO_BIG_DISPLAYWIDTH
--error ER_TOO_BIG_FIELDLENGTH
CREATE TABLE b15776 (a char(4294967296));
......@@ -527,8 +527,9 @@ CREATE TABLE b15776 (a year(4294967295));
INSERT INTO b15776 VALUES (42);
SELECT * FROM b15776;
DROP TABLE b15776;
--error ER_TOO_BIG_DISPLAYWIDTH
CREATE TABLE b15776 (a year(4294967296));
SHOW CREATE TABLE b15776;
DROP TABLE b15776;
CREATE TABLE b15776 (a year(0)); # 0 is special case, means default size
DROP TABLE b15776;
--error ER_PARSE_ERROR
......@@ -539,7 +540,7 @@ CREATE TABLE b15776 (a year(-2));
CREATE TABLE b15776 (a timestamp(4294967294));
--error ER_TOO_BIG_PRECISION
CREATE TABLE b15776 (a timestamp(4294967295));
--error ER_TOO_BIG_DISPLAYWIDTH
--error ER_TOO_BIG_PRECISION
CREATE TABLE b15776 (a timestamp(4294967296));
--error ER_PARSE_ERROR
CREATE TABLE b15776 (a timestamp(-1));
......@@ -550,10 +551,11 @@ CREATE TABLE b15776 (a timestamp(-2));
# widths that are too large to be interpreted cause DISPLAYWIDTH errors.
--error ER_TOO_BIG_DISPLAYWIDTH
CREATE TABLE b15776 (a int(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
--error ER_TOO_BIG_DISPLAYWIDTH
--error ER_TOO_BIG_FIELDLENGTH
CREATE TABLE b15776 (a char(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
--error ER_TOO_BIG_DISPLAYWIDTH
CREATE TABLE b15776 (a year(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
SHOW CREATE TABLE b15776;
DROP TABLE b15776;
## Do not select, too much memory needed.
CREATE TABLE b15776 select cast(null as char(4294967295));
......
......@@ -9769,12 +9769,6 @@ bool Column_definition::check(THD *thd)
}
}
if (length > MAX_FIELD_BLOBLENGTH)
{
my_error(ER_TOO_BIG_DISPLAYWIDTH, MYF(0), field_name, MAX_FIELD_BLOBLENGTH);
DBUG_RETURN(TRUE);
}
if (def)
{
/*
......@@ -10080,6 +10074,12 @@ bool Column_definition::check(THD *thd)
field_name, max_field_charlength); /* purecov: inspected */
DBUG_RETURN(TRUE);
}
else if (length > MAX_FIELD_BLOBLENGTH)
{
my_error(ER_TOO_BIG_DISPLAYWIDTH, MYF(0), field_name, MAX_FIELD_BLOBLENGTH);
DBUG_RETURN(1);
}
if ((~allowed_type_modifier) & flags & conditional_type_modifiers)
{
my_error(ER_WRONG_FIELD_SPEC, MYF(0), field_name);
......
......@@ -5998,9 +5998,64 @@ Item *Item_int_with_ref::clone_item(THD *thd)
}
Item_num *Item_uint::neg(THD *thd)
Item *Item::neg(THD *thd)
{
Item_decimal *item= new (thd->mem_root) Item_decimal(thd, value, 1);
return new (thd->mem_root) Item_func_neg(thd, this);
}
Item *Item_int::neg(THD *thd)
{
/*
The following if should never be true with code generated by
our parser as LONGLONG_MIN values will be stored as decimal.
The code is here in case someone generates an int from inside
MariaDB
*/
if (unlikely(value == LONGLONG_MIN))
{
/* Precision for int not big enough; Convert constant to decimal */
Item_decimal *item= new (thd->mem_root) Item_decimal(thd, value, 0);
return item ? item->neg(thd) : item;
}
if (value > 0)
max_length++;
else if (value < 0 && max_length)
max_length--;
value= -value;
name= 0;
return this;
}
Item *Item_decimal::neg(THD *thd)
{
my_decimal_neg(&decimal_value);
unsigned_flag= 0;
name= 0;
max_length= my_decimal_precision_to_length_no_truncation(
decimal_value.intg + decimals, decimals, unsigned_flag);
return this;
}
Item *Item_float::neg(THD *thd)
{
if (value > 0)
max_length++;
else if (value < 0 && max_length)
max_length--;
value= -value;
name= presentation= 0 ;
return this;
}
Item *Item_uint::neg(THD *thd)
{
Item_decimal *item;
if (((ulonglong)value) <= LONGLONG_MAX)
return new (thd->mem_root) Item_int(thd, -value, max_length+1);
if (value == LONGLONG_MIN)
return new (thd->mem_root) Item_int(thd, value, max_length+1);
if (!(item= new (thd->mem_root) Item_decimal(thd, value, 1)))
return 0;
return item->neg(thd);
}
......
......@@ -1846,6 +1846,8 @@ class Item: public Value_source,
/* how much position should be reserved for Exists2In transformation */
virtual uint exists2in_reserved_items() { return 0; };
virtual Item *neg(THD *thd);
/**
Inform the item that it is located under a NOT, which is a top-level item.
*/
......@@ -2261,7 +2263,6 @@ class Item_num: public Item_basic_constant
{
public:
Item_num(THD *thd): Item_basic_constant(thd) { collation.set_numeric(); }
virtual Item_num *neg(THD *thd)= 0;
Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs);
bool check_partition_func_processor(uchar *int_arg) { return FALSE;}
bool check_vcol_func_processor(uchar *arg) { return FALSE;}
......@@ -2834,7 +2835,7 @@ class Item_int :public Item_num
bool basic_const_item() const { return 1; }
Item *clone_item(THD *thd);
virtual void print(String *str, enum_query_type query_type);
Item_num *neg(THD *thd) { value= -value; return this; }
Item *neg(THD *thd);
uint decimal_precision() const
{ return (uint) (max_length - MY_TEST(value < 0)); }
bool eq(const Item *item, bool binary_cmp) const
......@@ -2855,7 +2856,7 @@ class Item_uint :public Item_int
String *val_str(String*);
Item *clone_item(THD *thd);
virtual void print(String *str, enum_query_type query_type);
Item_num *neg(THD *thd);
Item *neg(THD *thd);
uint decimal_precision() const { return max_length; }
};
......@@ -2899,12 +2900,7 @@ class Item_decimal :public Item_num
bool basic_const_item() const { return 1; }
Item *clone_item(THD *thd);
virtual void print(String *str, enum_query_type query_type);
Item_num *neg(THD *thd)
{
my_decimal_neg(&decimal_value);
unsigned_flag= !decimal_value.sign();
return this;
}
Item *neg(THD *thd);
uint decimal_precision() const { return decimal_value.precision(); }
bool eq(const Item *, bool binary_cmp) const;
void set_decimal_value(my_decimal *value_par);
......@@ -2954,7 +2950,7 @@ class Item_float :public Item_num
my_decimal *val_decimal(my_decimal *);
bool basic_const_item() const { return 1; }
Item *clone_item(THD *thd);
Item_num *neg(THD *thd) { value= -value; return this; }
Item *neg(THD *thd);
virtual void print(String *str, enum_query_type query_type);
bool eq(const Item *item, bool binary_cmp) const
{ return real_eq(value, item); }
......
......@@ -9461,7 +9461,7 @@ simple_expr:
}
| '-' simple_expr %prec NEG
{
$$= new (thd->mem_root) Item_func_neg(thd, $2);
$$= $2->neg(thd);
if ($$ == NULL)
MYSQL_YYABORT;
}
......
......@@ -185,7 +185,7 @@ a b c
8 8 80
explain select * from t where c = -1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t ref c c 5 const 1 Using where; Using index
1 SIMPLE t ref c c 5 const 1 Using index
select * from t where c = -1;
a b c
insert ignore t values (15, 15, -1);
......@@ -211,7 +211,7 @@ a b c
15 15 150
explain select * from t where c = -1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t ref c c 5 const 1 Using where; Using index
1 SIMPLE t ref c c 5 const 1 Using index
select * from t where c = -1;
a b c
drop table t;
......@@ -399,7 +399,7 @@ select * from t where c = 80;
a b c
explain select * from t where c = -1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t ref c c 5 const 1 Using where; Using index
1 SIMPLE t ref c c 5 const 1 Using index
select * from t where c = -1;
a b c
8 8 -1
......@@ -423,7 +423,7 @@ select * from t where c = 150;
a b c
explain select * from t where c = -1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t ref c c 5 const 2 Using where; Using index
1 SIMPLE t ref c c 5 const 2 Using index
select * from t where c = -1;
a b c
8 8 -1
......
......@@ -861,7 +861,7 @@ ERROR 42000: Column length too big for column 'a' (max = 255); use BLOB or TEXT
CREATE TABLE b15776 (a char(4294967295));
ERROR 42000: Column length too big for column 'a' (max = 255); use BLOB or TEXT instead
CREATE TABLE b15776 (a char(4294967296));
ERROR 42000: Display width out of range for 'a' (max = 4294967295)
ERROR 42000: Column length too big for column 'a' (max = 255); use BLOB or TEXT instead
CREATE TABLE b15776 (a year(4294967295));
Warnings:
Note 1287 'YEAR(4294967295)' is deprecated and will be removed in a future release. Please use YEAR(4) instead
......@@ -870,8 +870,6 @@ SELECT * FROM b15776;
a
2042
DROP TABLE b15776;
CREATE TABLE b15776 (a year(4294967296));
ERROR 42000: Display width out of range for 'a' (max = 4294967295)
CREATE TABLE b15776 (a year(0));
Warnings:
Note 1287 'YEAR(0)' is deprecated and will be removed in a future release. Please use YEAR(4) instead
......@@ -879,11 +877,9 @@ DROP TABLE b15776;
CREATE TABLE b15776 (a year(-2));
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 '-2))' at line 1
CREATE TABLE b15776 (a int(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
ERROR 42000: Display width out of range for 'a' (max = 4294967295)
ERROR 42000: Display width out of range for 'a' (max = 255)
CREATE TABLE b15776 (a char(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
ERROR 42000: Display width out of range for 'a' (max = 4294967295)
CREATE TABLE b15776 (a year(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
ERROR 42000: Display width out of range for 'a' (max = 4294967295)
ERROR 42000: Column length too big for column 'a' (max = 255); use BLOB or TEXT instead
CREATE TABLE b15776 select cast(null as char(4294967295));
show columns from b15776;
Field Type Null Key Default Extra
......
......@@ -177,7 +177,7 @@ Table Create Table
t1 CREATE TABLE `t1` (
`round(15.4,-1)` decimal(3,0) NOT NULL,
`truncate(-5678.123451,-3)` decimal(4,0) NOT NULL,
`abs(-1.1)` decimal(3,1) NOT NULL,
`abs(-1.1)` decimal(2,1) NOT NULL,
`-(-1.1)` decimal(2,1) NOT NULL
) ENGINE=ENGINE DEFAULT CHARSET=latin1
drop table t1;
......
......@@ -522,7 +522,7 @@ CREATE TABLE b15776 (a char(2147483648));
--error ER_TOO_BIG_FIELDLENGTH
CREATE TABLE b15776 (a char(4294967295));
# Even BLOB won't hold
--error ER_TOO_BIG_DISPLAYWIDTH
--error ER_TOO_BIG_FIELDLENGTH
CREATE TABLE b15776 (a char(4294967296));
......@@ -534,8 +534,6 @@ CREATE TABLE b15776 (a year(4294967295));
INSERT INTO b15776 VALUES (42);
SELECT * FROM b15776;
DROP TABLE b15776;
--error ER_TOO_BIG_DISPLAYWIDTH
CREATE TABLE b15776 (a year(4294967296));
CREATE TABLE b15776 (a year(0)); # 0 is special case, means default size
DROP TABLE b15776;
--error ER_PARSE_ERROR
......@@ -546,10 +544,8 @@ CREATE TABLE b15776 (a year(-2));
# widths that are too large to be interpreted cause DISPLAYWIDTH errors.
--error ER_TOO_BIG_DISPLAYWIDTH
CREATE TABLE b15776 (a int(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
--error ER_TOO_BIG_DISPLAYWIDTH
--error ER_TOO_BIG_FIELDLENGTH
CREATE TABLE b15776 (a char(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
--error ER_TOO_BIG_DISPLAYWIDTH
CREATE TABLE b15776 (a year(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
## Do not select, too much memory needed.
CREATE TABLE b15776 select cast(null as char(4294967295));
......
......@@ -1005,7 +1005,8 @@ static int ull2dec(ulonglong from, decimal_t *to)
error=E_DEC_OVERFLOW;
}
to->frac=0;
to->intg=intg1*DIG_PER_DEC1;
/* intg can't be bigger than number of digits in a ulonglong (20) */
to->intg= MY_MIN(intg1*DIG_PER_DEC1, 20);
for (buf=to->buf+intg1; intg1; intg1--)
{
......
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