Skip to content

Commit

Permalink
feat(tianmu): support unsigned/zerofill syntax stoneatom#1716
Browse files Browse the repository at this point in the history
[summary]
1. delete unsigned/zerofill limit.
2. zerofill is deprecated and will be removed in a future release, Use the LPAD function to zero-pad numbers, or store the formatted numbers in a CHAR column.
  • Loading branch information
hustjieke committed May 22, 2023
1 parent 05a8150 commit 1a68d1b
Show file tree
Hide file tree
Showing 4 changed files with 371 additions and 7 deletions.
202 changes: 202 additions & 0 deletions mysql-test/suite/tianmu/r/func_math.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
drop database if exists func_math_test;
create database func_math_test;
create table t1
(f1 varchar(32) not null,
f2 smallint unsigned not null,
f3 int unsigned not null default '0')
engine=tianmu default charset=UTF8MB4;
insert into t1 values ('zombie',0,0),('gold',1,10000),('silver',2,10000);
create table t2
(f1 int unsigned not null,
f2 int unsigned not null,
f3 smallint unsigned not null)
engine=tianmu default charset=UTF8MB4;
insert into t2 values (16777216,16787215,1),(33554432,33564431,2);
select format(t2.f2-t2.f1+1,0) from t1,t2
where t1.f2 = t2.f3 order by t1.f1;
format(t2.f2-t2.f1+1,0)
10,000
10,000
drop table t1, t2;
create table t1(a int unsigned) engine=tianmu default charset=UTF8MB4;
insert into t1 values (11);
select cast(-2 as unsigned), 18446744073709551614, -2 from t1;
cast(-2 as unsigned) 18446744073709551614 -2
18446744073709551614 18446744073709551614 -2
select abs(cast(-2 as unsigned)), abs(18446744073709551614), abs(-2) from t1;
abs(cast(-2 as unsigned)) abs(18446744073709551614) abs(-2)
18446744073709551614 18446744073709551614 2
select ceiling(18446744073709551614) from t1;
ceiling(18446744073709551614)
18446744073709551614
select ceiling(cast(-2 as unsigned)), ceiling(-2) from t1;
ceiling(cast(-2 as unsigned)) ceiling(-2)
18446744073709551614 -2
select floor(18446744073709551614) from t1;
floor(18446744073709551614)
18446744073709551614
select floor(cast(-2 as unsigned)), floor(-2) from t1;
floor(cast(-2 as unsigned)) floor(-2)
18446744073709551614 -2
select format(cast(-2 as unsigned), 2), format(18446744073709551614, 2), format(-2, 2) from t1;
format(cast(-2 as unsigned), 2) format(18446744073709551614, 2) format(-2, 2)
18,446,744,073,709,551,614.00 18,446,744,073,709,551,614.00 -2.00
select sqrt(cast(-2 as unsigned)), sqrt(18446744073709551614), sqrt(-2) from t1;
sqrt(cast(-2 as unsigned)) sqrt(18446744073709551614) sqrt(-2)
4294967296 4294967296 NULL
select round(cast(-2 as unsigned), 1), round(18446744073709551614, 1), round(-2, 1) from t1;
round(cast(-2 as unsigned), 1) round(18446744073709551614, 1) round(-2, 1)
18446744073709551614 18446744073709551614 -2
select round(4, cast(-2 as unsigned)), round(4, 18446744073709551614), round(4, -2) from t1;
round(4, cast(-2 as unsigned)) round(4, 18446744073709551614) round(4, -2)
4 4 0
select truncate(cast(-2 as unsigned), 1), truncate(18446744073709551614, 1), truncate(-2, 1) from t1;
truncate(cast(-2 as unsigned), 1) truncate(18446744073709551614, 1) truncate(-2, 1)
18446744073709551614 18446744073709551614 -2
select truncate(4, cast(-2 as unsigned)), truncate(4, 18446744073709551614), truncate(4, -2) from t1;
truncate(4, cast(-2 as unsigned)) truncate(4, 18446744073709551614) truncate(4, -2)
4 4 0
select mod(cast(-2 as unsigned), 3), mod(18446744073709551614, 3), mod(-2, 3) from t1;
mod(cast(-2 as unsigned), 3) mod(18446744073709551614, 3) mod(-2, 3)
2 2 -2
select mod(5, cast(-2 as unsigned)), mod(5, 18446744073709551614), mod(5, -2) from t1;
mod(5, cast(-2 as unsigned)) mod(5, 18446744073709551614) mod(5, -2)
5 5 1
select pow(cast(-2 as unsigned), 5), pow(18446744073709551614, 5), pow(-2, 5) from t1;
pow(cast(-2 as unsigned), 5) pow(18446744073709551614, 5) pow(-2, 5)
2.13598703592091e96 2.13598703592091e96 -32
SELECT 1e308 + 1e308 from t1;
ERROR 22003: DOUBLE value is out of range in '(1e308 + 1e308)'
SELECT -1e308 - 1e308 from t1;
ERROR 22003: DOUBLE value is out of range in '(-(1e308) - 1e308)'
SELECT 1e300 * 1e300 from t1;
ERROR 22003: DOUBLE value is out of range in '(1e300 * 1e300)'
SELECT 1e300 / 1e-300 from t1;
ERROR 22003: DOUBLE value is out of range in '(1e300 / 1e-300)'
SELECT EXP(750) from t1;
ERROR 22003: DOUBLE value is out of range in 'exp(750)'
SELECT POW(10, 309) from t1;
ERROR 22003: DOUBLE value is out of range in 'pow(10,309)'
SELECT -9999999999999999991 DIV -1 from t1;
ERROR 22003: BIGINT value is out of range in '(-(9999999999999999991) DIV -(1))'
SELECT -9223372036854775808 DIV -1 from t1;
ERROR 22003: BIGINT value is out of range in '(-(9223372036854775808) DIV -(1))'
SELECT -9223372036854775808 MOD -1 from t1;
-9223372036854775808 MOD -1
0
SELECT -9223372036854775808999 MOD -1 from t1;
-9223372036854775808999 MOD -1
0
select 123456789012345678901234567890.123456789012345678901234567890 div 1 as x from t1;
ERROR 22003: BIGINT value is out of range in '(123456789012345678901234567890.123456789012345678901234567890 DIV 1)'
select "123456789012345678901234567890.123456789012345678901234567890" div 1 as x from t1;
ERROR 22003: BIGINT value is out of range in '('123456789012345678901234567890.123456789012345678901234567890' DIV 1)'
SHOW WARNINGS;
Level Code Message
Warning 1292 Truncated incorrect DECIMAL value: '123456789012345678901234567890'
Error 1690 BIGINT value is out of range in '('123456789012345678901234567890.123456789012345678901234567890' DIV 1)'
Error 1105 Unknown error
SELECT 1e308 + 1e308 from t1;
ERROR 22003: DOUBLE value is out of range in '(1e308 + 1e308)'
SELECT -1e308 - 1e308 from t1;
ERROR 22003: DOUBLE value is out of range in '(-(1e308) - 1e308)'
SELECT 1e300 * 1e300 from t1;
ERROR 22003: DOUBLE value is out of range in '(1e300 * 1e300)'
SELECT 1e300 / 1e-300 from t1;
ERROR 22003: DOUBLE value is out of range in '(1e300 / 1e-300)'
SELECT EXP(750) from t1;
ERROR 22003: DOUBLE value is out of range in 'exp(750)'
SELECT POW(10, 309) from t1;
ERROR 22003: DOUBLE value is out of range in 'pow(10,309)'
SELECT COT(0) from t1;
ERROR 22003: DOUBLE value is out of range in 'cot(0)'
SELECT DEGREES(1e307) from t1;
ERROR 22003: DOUBLE value is out of range in 'degrees(1e307)'
SELECT 9223372036854775808 + 9223372036854775808 from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(9223372036854775808 + 9223372036854775808)'
SELECT 18446744073709551615 + 1 from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(18446744073709551615 + 1)'
SELECT 1 + 18446744073709551615 from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(1 + 18446744073709551615)'
SELECT -2 + CAST(1 AS UNSIGNED) from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(-(2) + cast(1 as unsigned))'
SELECT CAST(1 AS UNSIGNED) + -2 from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(cast(1 as unsigned) + -(2))'
SELECT -9223372036854775808 + -9223372036854775808 from t1;
ERROR 22003: BIGINT value is out of range in '(-(9223372036854775808) + -(9223372036854775808))'
SELECT 9223372036854775807 + 9223372036854775807 from t1;
ERROR 22003: BIGINT value is out of range in '(9223372036854775807 + 9223372036854775807)'
SELECT CAST(0 AS UNSIGNED) - 9223372036854775809 from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(cast(0 as unsigned) - 9223372036854775809)'
SELECT 9223372036854775808 - 9223372036854775809 from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(9223372036854775808 - 9223372036854775809)'
SELECT CAST(1 AS UNSIGNED) - 2 from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(cast(1 as unsigned) - 2)'
SELECT 18446744073709551615 - (-1) from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(18446744073709551615 - -(1))'
SELECT -1 - 9223372036854775808 from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(-(1) - 9223372036854775808)'
SELECT -1 - CAST(1 AS UNSIGNED) from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(-(1) - cast(1 as unsigned))'
SELECT -9223372036854775808 - 1 from t1;
ERROR 22003: BIGINT value is out of range in '(-(9223372036854775808) - 1)'
SELECT 9223372036854775807 - -9223372036854775808 from t1;
ERROR 22003: BIGINT value is out of range in '(9223372036854775807 - -(9223372036854775808))'
set SQL_MODE='NO_UNSIGNED_SUBTRACTION';
SELECT 18446744073709551615 - 1 from t1;
ERROR 22003: BIGINT value is out of range in '(18446744073709551615 - 1)'
SELECT 18446744073709551615 - CAST(1 AS UNSIGNED) from t1;
ERROR 22003: BIGINT value is out of range in '(18446744073709551615 - cast(1 as unsigned))'
SELECT 18446744073709551614 - (-1) from t1;
ERROR 22003: BIGINT value is out of range in '(18446744073709551614 - -(1))'
SELECT 9223372036854775807 - -1 from t1;
ERROR 22003: BIGINT value is out of range in '(9223372036854775807 - -(1))'
set SQL_MODE=default;
SELECT 4294967296 * 4294967296 from t1;
ERROR 22003: BIGINT value is out of range in '(4294967296 * 4294967296)'
SELECT 9223372036854775808 * 2 from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(9223372036854775808 * 2)'
SELECT 9223372036854775808 * 2 from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(9223372036854775808 * 2)'
SELECT 7158278827 * 3221225472 from t1;
ERROR 22003: BIGINT value is out of range in '(7158278827 * 3221225472)'
SELECT 9223372036854775807 * (-2) from t1;
ERROR 22003: BIGINT value is out of range in '(9223372036854775807 * -(2))'
SELECT CAST(1 as UNSIGNED) * (-1) from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(cast(1 as unsigned) * -(1))'
SELECT 9223372036854775807 * 2 from t1;
ERROR 22003: BIGINT value is out of range in '(9223372036854775807 * 2)'
SELECT ABS(-9223372036854775808) from t1;
ERROR 22003: BIGINT value is out of range in 'abs(-(9223372036854775808))'
SELECT -9223372036854775808 DIV -1 from t1;
ERROR 22003: BIGINT value is out of range in '(-(9223372036854775808) DIV -(1))'
SELECT 18446744073709551615 DIV -1 from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(18446744073709551615 DIV -(1))'
SET @a:=999999999999999999999999999999999999999999999999999999999999999999999999999999999;
SELECT @a + @a from t1;
ERROR 22003: DECIMAL value is out of range in '((@`a`) + (@`a`))'
SELECT @a * @a from t1;
ERROR 22003: DECIMAL value is out of range in '((@`a`) * (@`a`))'
SELECT -@a - @a from t1;
ERROR 22003: DECIMAL value is out of range in '(-((@`a`)) - (@`a`))'
SELECT @a / 0.5 from t1;
ERROR 22003: DECIMAL value is out of range in '((@`a`) / 0.5)'
drop table if exists t1, t2;
Warnings:
Note 1051 Unknown table 'test.t2'
create table t1(a tinyint zerofill, b int) engine=tianmu;
Warnings:
Warning 1681 The ZEROFILL attribute is deprecated and will be removed in a future release. Use the LPAD function to zero-pad numbers, or store the formatted numbers in a CHAR column.
insert into t1 values (11, 22);
select a-b from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(`test`.`t1`.`a` - `test`.`t1`.`b`)'
select cast((a-b) as unsigned) from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(`test`.`t1`.`a` - `test`.`t1`.`b`)'
create table t2(a tinyint unsigned, b int) engine=tianmu;
insert into t2 values (1, 22);
select a-b from t1;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(`test`.`t1`.`a` - `test`.`t1`.`b`)'
select cast((a-b) as unsigned) from t2;
ERROR 22003: BIGINT UNSIGNED value is out of range in '(`test`.`t2`.`a` - `test`.`t2`.`b`)'
drop table t1, t2;
drop database func_math_test;
169 changes: 169 additions & 0 deletions mysql-test/suite/tianmu/t/func_math.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
--source include/have_tianmu.inc
--disable_warnings
drop database if exists func_math_test;
--enable_warnings
create database func_math_test;
create table t1
(f1 varchar(32) not null,
f2 smallint unsigned not null,
f3 int unsigned not null default '0')
engine=tianmu default charset=UTF8MB4;
insert into t1 values ('zombie',0,0),('gold',1,10000),('silver',2,10000);
create table t2
(f1 int unsigned not null,
f2 int unsigned not null,
f3 smallint unsigned not null)
engine=tianmu default charset=UTF8MB4;
insert into t2 values (16777216,16787215,1),(33554432,33564431,2);
select format(t2.f2-t2.f1+1,0) from t1,t2
where t1.f2 = t2.f3 order by t1.f1;
drop table t1, t2;
create table t1(a int unsigned) engine=tianmu default charset=UTF8MB4;
insert into t1 values (11);
select cast(-2 as unsigned), 18446744073709551614, -2 from t1;
select abs(cast(-2 as unsigned)), abs(18446744073709551614), abs(-2) from t1;
# in stonedb 5.7, for mysql, ceiling(18446744073709551614) is ok, but in tianmu, decimal overflow, need cast(...)
select ceiling(18446744073709551614) from t1;
select ceiling(cast(-2 as unsigned)), ceiling(-2) from t1;
# in stonedb 5.7, for mysql, floor(18446744073709551614) is ok, but in tianmu, decimal overflow, need cast(...)
select floor(18446744073709551614) from t1;
select floor(cast(-2 as unsigned)), floor(-2) from t1;
select format(cast(-2 as unsigned), 2), format(18446744073709551614, 2), format(-2, 2) from t1;
select sqrt(cast(-2 as unsigned)), sqrt(18446744073709551614), sqrt(-2) from t1;
select round(cast(-2 as unsigned), 1), round(18446744073709551614, 1), round(-2, 1) from t1;
select round(4, cast(-2 as unsigned)), round(4, 18446744073709551614), round(4, -2) from t1;
select truncate(cast(-2 as unsigned), 1), truncate(18446744073709551614, 1), truncate(-2, 1) from t1;
select truncate(4, cast(-2 as unsigned)), truncate(4, 18446744073709551614), truncate(4, -2) from t1;
select mod(cast(-2 as unsigned), 3), mod(18446744073709551614, 3), mod(-2, 3) from t1;
select mod(5, cast(-2 as unsigned)), mod(5, 18446744073709551614), mod(5, -2) from t1;
select pow(cast(-2 as unsigned), 5), pow(18446744073709551614, 5), pow(-2, 5) from t1;
--error 1690
SELECT 1e308 + 1e308 from t1;
--error 1690
SELECT -1e308 - 1e308 from t1;
--error 1690
SELECT 1e300 * 1e300 from t1;
--error 1690
SELECT 1e300 / 1e-300 from t1;
--error 1690
SELECT EXP(750) from t1;
--error 1690
SELECT POW(10, 309) from t1;
#
# Bug#57477 SIGFPE when dividing a huge number a negative number
#
--error 1690
SELECT -9999999999999999991 DIV -1 from t1;
--error 1690
SELECT -9223372036854775808 DIV -1 from t1;
SELECT -9223372036854775808 MOD -1 from t1;
SELECT -9223372036854775808999 MOD -1 from t1;
--error 1690
select 123456789012345678901234567890.123456789012345678901234567890 div 1 as x from t1;
--error 1690
select "123456789012345678901234567890.123456789012345678901234567890" div 1 as x from t1;
SHOW WARNINGS;
#
# Bug #8433: Overflow must be an error
#
--error 1690
SELECT 1e308 + 1e308 from t1;
--error 1690
SELECT -1e308 - 1e308 from t1;
--error 1690
SELECT 1e300 * 1e300 from t1;
--error 1690
SELECT 1e300 / 1e-300 from t1;
--error 1690
SELECT EXP(750) from t1;
--error 1690
SELECT POW(10, 309) from t1;
--error 1690
SELECT COT(0) from t1;
--error 1690
SELECT DEGREES(1e307) from t1;
--error 1690
SELECT 9223372036854775808 + 9223372036854775808 from t1;
--error 1690
SELECT 18446744073709551615 + 1 from t1;
--error 1690
SELECT 1 + 18446744073709551615 from t1;
--error 1690
SELECT -2 + CAST(1 AS UNSIGNED) from t1;
--error 1690
SELECT CAST(1 AS UNSIGNED) + -2 from t1;
--error 1690
SELECT -9223372036854775808 + -9223372036854775808 from t1;
--error 1690
SELECT 9223372036854775807 + 9223372036854775807 from t1;
--error 1690
SELECT CAST(0 AS UNSIGNED) - 9223372036854775809 from t1;
--error 1690
SELECT 9223372036854775808 - 9223372036854775809 from t1;
--error 1690
SELECT CAST(1 AS UNSIGNED) - 2 from t1;
--error 1690
SELECT 18446744073709551615 - (-1) from t1;
--error 1690
SELECT -1 - 9223372036854775808 from t1;
--error 1690
SELECT -1 - CAST(1 AS UNSIGNED) from t1;
--error 1690
SELECT -9223372036854775808 - 1 from t1;
--error 1690
SELECT 9223372036854775807 - -9223372036854775808 from t1;
set SQL_MODE='NO_UNSIGNED_SUBTRACTION';
--error 1690
SELECT 18446744073709551615 - 1 from t1;
--error 1690
SELECT 18446744073709551615 - CAST(1 AS UNSIGNED) from t1;
--error 1690
SELECT 18446744073709551614 - (-1) from t1;
--error 1690
SELECT 9223372036854775807 - -1 from t1;
set SQL_MODE=default;
--error 1690
SELECT 4294967296 * 4294967296 from t1;
--error 1690
SELECT 9223372036854775808 * 2 from t1;
--error 1690
SELECT 9223372036854775808 * 2 from t1;
--error 1690
SELECT 7158278827 * 3221225472 from t1;
--error 1690
SELECT 9223372036854775807 * (-2) from t1;
--error 1690
SELECT CAST(1 as UNSIGNED) * (-1) from t1;
--error 1690
SELECT 9223372036854775807 * 2 from t1;
--error 1690
SELECT ABS(-9223372036854775808) from t1;
--error 1690
SELECT -9223372036854775808 DIV -1 from t1;
--error 1690
SELECT 18446744073709551615 DIV -1 from t1;
SET @a:=999999999999999999999999999999999999999999999999999999999999999999999999999999999;
--error 1690
SELECT @a + @a from t1;
--error 1690
SELECT @a * @a from t1;
--error 1690
SELECT -@a - @a from t1;
--error 1690
SELECT @a / 0.5 from t1;
# next is design by tianmu team
drop table if exists t1, t2;
create table t1(a tinyint zerofill, b int) engine=tianmu;
insert into t1 values (11, 22);
--error 1690
select a-b from t1;
--error 1690
select cast((a-b) as unsigned) from t1;
create table t2(a tinyint unsigned, b int) engine=tianmu;
insert into t2 values (1, 22);
--error 1690
select a-b from t1;
--error 1690
select cast((a-b) as unsigned) from t2;
drop table t1, t2;
drop database func_math_test;
5 changes: 0 additions & 5 deletions storage/tianmu/core/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,9 +666,6 @@ AttributeTypeInfo Engine::GetAttrTypeInfo(const Field &field) {
case MYSQL_TYPE_FLOAT:
case MYSQL_TYPE_DOUBLE:
case MYSQL_TYPE_LONGLONG:
if (field.is_flag_set(UNSIGNED_FLAG))
throw common::UnsupportedDataTypeException("UNSIGNED data types are not supported.");
[[fallthrough]];
case MYSQL_TYPE_YEAR:
case MYSQL_TYPE_TIMESTAMP:
case MYSQL_TYPE_DATETIME:
Expand Down Expand Up @@ -710,8 +707,6 @@ AttributeTypeInfo Engine::GetAttrTypeInfo(const Field &field) {
throw common::UnsupportedDataTypeException();
}
case MYSQL_TYPE_NEWDECIMAL: {
if (field.is_flag_set(UNSIGNED_FLAG))
throw common::UnsupportedDataTypeException("UNSIGNED data types are not supported.");
const Field_new_decimal *fnd = ((const Field_new_decimal *)&field);
if (/*fnd->precision > 0 && */ fnd->precision <= 18 /*&& fnd->dec >= 0*/
&& fnd->dec <= fnd->precision)
Expand Down
Loading

0 comments on commit 1a68d1b

Please sign in to comment.