summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Didriksen <tor.didriksen@oracle.com>2011-08-19 09:06:50 +0200
committerTor Didriksen <tor.didriksen@oracle.com>2011-08-19 09:06:50 +0200
commitcb24e8feb92b49583e97608d9a3b927927354366 (patch)
tree73cea93f02979761076fafb51153522053e8bf3a
parent5247e2b80632662e97f8a65814e4abb41feadfb2 (diff)
downloadmariadb-git-cb24e8feb92b49583e97608d9a3b927927354366.tar.gz
Backport from trunk of:
Bug#12532830 - SIGFPE OR ASSERTION (PRECISION <= ((9 * 9) - 8*2)) && (DEC <= 30)
-rw-r--r--mysql-test/r/func_if.result14
-rw-r--r--mysql-test/suite/innodb/r/innodb_bug54044.result11
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug54044.test14
-rw-r--r--mysql-test/t/func_if.test12
-rw-r--r--sql/field.cc3
-rw-r--r--sql/item_cmpfunc.cc46
-rw-r--r--sql/item_cmpfunc.h2
7 files changed, 77 insertions, 25 deletions
diff --git a/mysql-test/r/func_if.result b/mysql-test/r/func_if.result
index c70589a27b7..7946d8f328c 100644
--- a/mysql-test/r/func_if.result
+++ b/mysql-test/r/func_if.result
@@ -196,3 +196,17 @@ c
NULL
0
DROP TABLE t1;
+#
+# Bug#12532830
+# SIGFPE OR ASSERTION (PRECISION <= ((9 * 9) - 8*2)) && (DEC <= 30)
+#
+select
+sum(distinct(if('a',
+(select adddate(elt(convert(9999999999999999999999999999999999999,decimal(64,0)),count(*)),
+interval 1 day))
+, .1))) as foo;
+foo
+0.1
+Warnings:
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
diff --git a/mysql-test/suite/innodb/r/innodb_bug54044.result b/mysql-test/suite/innodb/r/innodb_bug54044.result
index 90ab812f2ae..350c500cb9b 100644
--- a/mysql-test/suite/innodb/r/innodb_bug54044.result
+++ b/mysql-test/suite/innodb/r/innodb_bug54044.result
@@ -1,3 +1,12 @@
CREATE TEMPORARY TABLE table_54044 ENGINE = INNODB
AS SELECT IF(NULL IS NOT NULL, NULL, NULL);
-ERROR HY000: Can't create table 'test.table_54044' (errno: -1)
+SHOW CREATE TABLE table_54044;
+Table Create Table
+table_54044 CREATE TEMPORARY TABLE `table_54044` (
+ `IF(NULL IS NOT NULL, NULL, NULL)` binary(0) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+DROP TABLE table_54044;
+CREATE TABLE tmp ENGINE = INNODB AS SELECT COALESCE(NULL, NULL, NULL);
+ERROR HY000: Can't create table 'test.tmp' (errno: -1)
+CREATE TABLE tmp ENGINE = INNODB AS SELECT GREATEST(NULL, NULL);
+ERROR HY000: Can't create table 'test.tmp' (errno: -1)
diff --git a/mysql-test/suite/innodb/t/innodb_bug54044.test b/mysql-test/suite/innodb/t/innodb_bug54044.test
index a6722ed6399..0bbd7da0065 100644
--- a/mysql-test/suite/innodb/t/innodb_bug54044.test
+++ b/mysql-test/suite/innodb/t/innodb_bug54044.test
@@ -3,9 +3,17 @@
--source include/have_innodb.inc
-# This 'create table' operation should fail because of
-# using NULL datatype
---error ER_CANT_CREATE_TABLE
+# This 'create table' operation no longer uses the NULL datatype.
+
CREATE TEMPORARY TABLE table_54044 ENGINE = INNODB
AS SELECT IF(NULL IS NOT NULL, NULL, NULL);
+SHOW CREATE TABLE table_54044;
+DROP TABLE table_54044;
+# These 'create table' operations should fail because of
+# using NULL datatype
+
+--error ER_CANT_CREATE_TABLE
+CREATE TABLE tmp ENGINE = INNODB AS SELECT COALESCE(NULL, NULL, NULL);
+--error ER_CANT_CREATE_TABLE
+CREATE TABLE tmp ENGINE = INNODB AS SELECT GREATEST(NULL, NULL);
diff --git a/mysql-test/t/func_if.test b/mysql-test/t/func_if.test
index 91f70bb98d7..41115a2da30 100644
--- a/mysql-test/t/func_if.test
+++ b/mysql-test/t/func_if.test
@@ -177,3 +177,15 @@ INSERT INTO t1 VALUES (NULL, 0), (NULL, 1);
SELECT IF(b, (SELECT a FROM t1 LIMIT 1), b) c FROM t1 GROUP BY c;
DROP TABLE t1;
+
+--echo #
+--echo # Bug#12532830
+--echo # SIGFPE OR ASSERTION (PRECISION <= ((9 * 9) - 8*2)) && (DEC <= 30)
+--echo #
+
+let $nines= 9999999999999999999999999999999999999;
+eval select
+sum(distinct(if('a',
+ (select adddate(elt(convert($nines,decimal(64,0)),count(*)),
+ interval 1 day))
+ , .1))) as foo;
diff --git a/sql/field.cc b/sql/field.cc
index e1a24e82718..ef66c1ba9bb 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -9159,8 +9159,9 @@ void Create_field::init_for_tmp_table(enum_field_types sql_type_arg,
pack_flag= FIELDFLAG_INTERVAL;
break;
- case MYSQL_TYPE_DECIMAL:
case MYSQL_TYPE_NEWDECIMAL:
+ DBUG_ASSERT(decimals_arg <= DECIMAL_MAX_SCALE);
+ case MYSQL_TYPE_DECIMAL:
case MYSQL_TYPE_FLOAT:
case MYSQL_TYPE_DOUBLE:
pack_flag= FIELDFLAG_NUMBER |
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index e28221109d9..f30b6adcb93 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -2625,37 +2625,43 @@ Item_func_if::fix_fields(THD *thd, Item **ref)
}
-void
-Item_func_if::fix_length_and_dec()
+void Item_func_if::cache_type_info(Item *source)
{
- maybe_null=args[1]->maybe_null || args[2]->maybe_null;
- decimals= max(args[1]->decimals, args[2]->decimals);
- unsigned_flag=args[1]->unsigned_flag && args[2]->unsigned_flag;
+ collation.set(source->collation);
+ cached_field_type= source->field_type();
+ cached_result_type= source->result_type();
+ decimals= source->decimals;
+ max_length= source->max_length;
+ maybe_null= source->maybe_null;
+ unsigned_flag= source->unsigned_flag;
+}
- enum Item_result arg1_type=args[1]->result_type();
- enum Item_result arg2_type=args[2]->result_type();
- bool null1=args[1]->const_item() && args[1]->null_value;
- bool null2=args[2]->const_item() && args[2]->null_value;
- if (null1)
+void
+Item_func_if::fix_length_and_dec()
+{
+ // Let IF(cond, expr, NULL) and IF(cond, NULL, expr) inherit type from expr.
+ if (args[1]->type() == NULL_ITEM)
{
- cached_result_type= arg2_type;
- collation.set(args[2]->collation);
- cached_field_type= args[2]->field_type();
- max_length= args[2]->max_length;
+ cache_type_info(args[2]);
+ maybe_null= true;
+ // If both arguments are NULL, make resulting type BINARY(0).
+ if (args[2]->type() == NULL_ITEM)
+ cached_field_type= MYSQL_TYPE_STRING;
return;
}
-
- if (null2)
+ if (args[2]->type() == NULL_ITEM)
{
- cached_result_type= arg1_type;
- collation.set(args[1]->collation);
- cached_field_type= args[1]->field_type();
- max_length= args[1]->max_length;
+ cache_type_info(args[1]);
+ maybe_null= true;
return;
}
agg_result_type(&cached_result_type, args + 1, 2);
+ maybe_null= args[1]->maybe_null || args[2]->maybe_null;
+ decimals= max(args[1]->decimals, args[2]->decimals);
+ unsigned_flag=args[1]->unsigned_flag && args[2]->unsigned_flag;
+
if (cached_result_type == STRING_RESULT)
{
if (agg_arg_charsets_for_string_result(collation, args + 1, 2))
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index b6928d63ea0..a735f01fb39 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -750,6 +750,8 @@ public:
void fix_length_and_dec();
uint decimal_precision() const;
const char *func_name() const { return "if"; }
+private:
+ void cache_type_info(Item *source);
};