Commit 3cc6e5b7 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-8852 Implicit or explicit CAST from MAX(string) to INT,DOUBLE,DECIMAL...

MDEV-8852 Implicit or explicit CAST from MAX(string) to INT,DOUBLE,DECIMAL does not produce warnings
parent 54db3874
......@@ -2273,3 +2273,13 @@ t2_id GROUP_CONCAT(IF (t6.b, t6.f, t5.f) ORDER BY 1)
EXECUTE stmt;
t2_id GROUP_CONCAT(IF (t6.b, t6.f, t5.f) ORDER BY 1)
DROP TABLE t1,t2,t3,t4,t5,t6;
#
# MDEV-8852 Implicit or explicit CAST from MAX(string) to INT,DOUBLE,DECIMAL does not produce warnings
#
SELECT MAX('x') << 1, CAST(MAX('x') AS DOUBLE), CAST(MAX('x') AS DECIMAL);
MAX('x') << 1 CAST(MAX('x') AS DOUBLE) CAST(MAX('x') AS DECIMAL)
0 0 0
Warnings:
Warning 1292 Truncated incorrect INTEGER value: 'x'
Warning 1292 Truncated incorrect DOUBLE value: 'x'
Warning 1292 Truncated incorrect DECIMAL value: 'x'
......@@ -1718,13 +1718,17 @@ Warnings:
Warning 1292 Truncated incorrect INTEGER value: '%Z'
Warning 1292 Truncated incorrect DOUBLE value: ''
Warning 1292 Incorrect datetime value: '0000-00-00'
SET timestamp=UNIX_TIMESTAMP('2001-01-01 00:00:00');
create table t1(a time);
insert into t1 values ('00:00:00'),('00:01:00');
select 1 from t1 where 1 < some (select cast(a as datetime) from t1);
1
1
1
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: '2001-01-01 00:01:00'
drop table t1;
SET timestamp=DEFAULT;
select time('10:10:10') > 10;
time('10:10:10') > 10
1
......
......@@ -1661,6 +1661,9 @@ INSERT INTO g1 VALUES ('a'),('a');
SELECT 1 FROM g1 WHERE a >= ANY
(SELECT 1 FROM g1 WHERE a = geomfromtext('') OR a) ;
1
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'a'
Warning 1292 Truncated incorrect DOUBLE value: 'a'
DROP TABLE g1;
#
# Bug#16451878 GEOMETRY QUERY CRASHES SERVER
......
......@@ -130,12 +130,16 @@ Warning 1292 Truncated incorrect DOUBLE value: '1.5b'
SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a');
(SELECT 'b',2,'a') = ROW(1.5,2,'a')
0
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'b'
SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a');
(SELECT 1.5,2,'a') = ROW(1.5,'2','a')
1
SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a');
(SELECT 1.5,'c','a') = ROW(1.5,2,'a')
0
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'c'
SELECT (SELECT * FROM (SELECT 'test' a,'test' b) a);
ERROR 21000: Operand should contain 1 column(s)
SELECT 1 as a,(SELECT a+a) b,(SELECT b);
......@@ -4665,6 +4669,8 @@ SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
1
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
1
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'a'
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
1
1
......@@ -5933,6 +5939,8 @@ SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
1
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
1
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'a'
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
1
1
......
......@@ -545,6 +545,10 @@ Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`
select * from t1 group by (a1 in (select col from columns));
a1 a2
1 - 00 2 - 00
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: '1 - 00'
Warning 1292 Truncated incorrect DOUBLE value: '1 - 01'
Warning 1292 Truncated incorrect DOUBLE value: '1 - 02'
/* ORDER BY clause */
explain extended
select * from t1 order by (select col from columns limit 1);
......
......@@ -134,12 +134,16 @@ Warning 1292 Truncated incorrect DOUBLE value: '1.5b'
SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a');
(SELECT 'b',2,'a') = ROW(1.5,2,'a')
0
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'b'
SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a');
(SELECT 1.5,2,'a') = ROW(1.5,'2','a')
1
SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a');
(SELECT 1.5,'c','a') = ROW(1.5,2,'a')
0
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'c'
SELECT (SELECT * FROM (SELECT 'test' a,'test' b) a);
ERROR 21000: Operand should contain 1 column(s)
SELECT 1 as a,(SELECT a+a) b,(SELECT b);
......@@ -4667,6 +4671,8 @@ SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
1
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
1
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'a'
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
1
1
......@@ -5933,6 +5939,8 @@ SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
1
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
1
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'a'
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
1
1
......
......@@ -137,12 +137,16 @@ Warning 1292 Truncated incorrect DOUBLE value: '1.5b'
SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a');
(SELECT 'b',2,'a') = ROW(1.5,2,'a')
0
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'b'
SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a');
(SELECT 1.5,2,'a') = ROW(1.5,'2','a')
1
SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a');
(SELECT 1.5,'c','a') = ROW(1.5,2,'a')
0
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'c'
SELECT (SELECT * FROM (SELECT 'test' a,'test' b) a);
ERROR 21000: Operand should contain 1 column(s)
SELECT 1 as a,(SELECT a+a) b,(SELECT b);
......@@ -4665,6 +4669,8 @@ SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
1
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
1
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'a'
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
1
1
......@@ -5930,6 +5936,8 @@ SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
1
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
1
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'a'
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
1
1
......
......@@ -133,12 +133,16 @@ Warning 1292 Truncated incorrect DOUBLE value: '1.5b'
SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a');
(SELECT 'b',2,'a') = ROW(1.5,2,'a')
0
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'b'
SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a');
(SELECT 1.5,2,'a') = ROW(1.5,'2','a')
1
SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a');
(SELECT 1.5,'c','a') = ROW(1.5,2,'a')
0
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'c'
SELECT (SELECT * FROM (SELECT 'test' a,'test' b) a);
ERROR 21000: Operand should contain 1 column(s)
SELECT 1 as a,(SELECT a+a) b,(SELECT b);
......@@ -4661,6 +4665,8 @@ SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
1
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
1
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'a'
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
1
1
......@@ -5926,6 +5932,8 @@ SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
1
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
1
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'a'
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
1
1
......
......@@ -136,12 +136,16 @@ Warning 1292 Truncated incorrect DOUBLE value: '1.5b'
SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a');
(SELECT 'b',2,'a') = ROW(1.5,2,'a')
0
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'b'
SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a');
(SELECT 1.5,2,'a') = ROW(1.5,'2','a')
1
SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a');
(SELECT 1.5,'c','a') = ROW(1.5,2,'a')
0
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'c'
SELECT (SELECT * FROM (SELECT 'test' a,'test' b) a);
ERROR 21000: Operand should contain 1 column(s)
SELECT 1 as a,(SELECT a+a) b,(SELECT b);
......@@ -4671,6 +4675,8 @@ SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
1
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
1
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'a'
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
1
1
......@@ -5939,6 +5945,8 @@ SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
1
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
1
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'a'
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
1
1
......
......@@ -133,12 +133,16 @@ Warning 1292 Truncated incorrect DOUBLE value: '1.5b'
SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a');
(SELECT 'b',2,'a') = ROW(1.5,2,'a')
0
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'b'
SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a');
(SELECT 1.5,2,'a') = ROW(1.5,'2','a')
1
SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a');
(SELECT 1.5,'c','a') = ROW(1.5,2,'a')
0
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'c'
SELECT (SELECT * FROM (SELECT 'test' a,'test' b) a);
ERROR 21000: Operand should contain 1 column(s)
SELECT 1 as a,(SELECT a+a) b,(SELECT b);
......@@ -4661,6 +4665,8 @@ SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
1
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
1
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'a'
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
1
1
......@@ -5926,6 +5932,8 @@ SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
1
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
1
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'a'
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
1
1
......
......@@ -2288,8 +2288,14 @@ CREATE TABLE t3 (a int, b int) ;
PREPARE st1 FROM "SELECT * FROM t2 LEFT JOIN t1 ON t2.a != 0 AND ('j','r') IN ( SELECT b,a FROM t3)";
EXECUTE st1;
a a
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'j'
Warning 1292 Truncated incorrect DOUBLE value: 'r'
EXECUTE st1;
a a
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'j'
Warning 1292 Truncated incorrect DOUBLE value: 'r'
DROP TABLE t1, t2, t3;
#
# BUG#849776: Wrong result with semijoin + "Impossible where"
......
......@@ -2302,8 +2302,14 @@ CREATE TABLE t3 (a int, b int) ;
PREPARE st1 FROM "SELECT * FROM t2 LEFT JOIN t1 ON t2.a != 0 AND ('j','r') IN ( SELECT b,a FROM t3)";
EXECUTE st1;
a a
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'j'
Warning 1292 Truncated incorrect DOUBLE value: 'r'
EXECUTE st1;
a a
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'j'
Warning 1292 Truncated incorrect DOUBLE value: 'r'
DROP TABLE t1, t2, t3;
#
# BUG#849776: Wrong result with semijoin + "Impossible where"
......
......@@ -566,6 +566,10 @@ Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`
select * from t1 group by (a1 in (select col from columns));
a1 a2
1 - 00 2 - 00
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: '1 - 00'
Warning 1292 Truncated incorrect DOUBLE value: '1 - 01'
Warning 1292 Truncated incorrect DOUBLE value: '1 - 02'
/* ORDER BY clause */
explain extended
select * from t1 order by (select col from columns limit 1);
......
......@@ -1565,3 +1565,8 @@ EXECUTE stmt;
EXECUTE stmt;
DROP TABLE t1,t2,t3,t4,t5,t6;
--echo #
--echo # MDEV-8852 Implicit or explicit CAST from MAX(string) to INT,DOUBLE,DECIMAL does not produce warnings
--echo #
SELECT MAX('x') << 1, CAST(MAX('x') AS DOUBLE), CAST(MAX('x') AS DECIMAL);
......@@ -1036,10 +1036,12 @@ SET time_zone=DEFAULT;
SELECT min(timestampadd(month, 1>'', from_days('%Z')));
SET timestamp=UNIX_TIMESTAMP('2001-01-01 00:00:00');
create table t1(a time);
insert into t1 values ('00:00:00'),('00:01:00');
select 1 from t1 where 1 < some (select cast(a as datetime) from t1);
drop table t1;
SET timestamp=DEFAULT;
select time('10:10:10') > 10;
select time('10:10:10') > 1010;
......
......@@ -9118,28 +9118,18 @@ bool Item_cache_str::cache_value()
double Item_cache_str::val_real()
{
DBUG_ASSERT(fixed == 1);
int err_not_used;
char *end_not_used;
if (!has_value())
return 0.0;
if (value)
return my_strntod(value->charset(), (char*) value->ptr(),
value->length(), &end_not_used, &err_not_used);
return (double) 0;
return value ? double_from_string_with_check(value) : 0.0;
}
longlong Item_cache_str::val_int()
{
DBUG_ASSERT(fixed == 1);
int err;
if (!has_value())
return 0;
if (value)
return my_strntoll(value->charset(), value->ptr(),
value->length(), 10, (char**) 0, &err);
else
return (longlong)0;
return value ? longlong_from_string_with_check(value) : 0;
}
......@@ -9157,11 +9147,7 @@ my_decimal *Item_cache_str::val_decimal(my_decimal *decimal_val)
DBUG_ASSERT(fixed == 1);
if (!has_value())
return NULL;
if (value)
string2my_decimal(E_DEC_FATAL_ERROR, value, decimal_val);
else
decimal_val= 0;
return decimal_val;
return value ? decimal_from_string_with_check(decimal_val, value) : 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