summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <igor@olga.mysql.com>2007-07-07 12:31:55 -0700
committerunknown <igor@olga.mysql.com>2007-07-07 12:31:55 -0700
commit0671e30ae6e4966d680c28b3d6dcc394f399831e (patch)
tree268c0375c0e1b6d78f5376cca17c18e70e240627
parent8195a213c2fadfb185e755ce6dda2162df1a5529 (diff)
downloadmariadb-git-0671e30ae6e4966d680c28b3d6dcc394f399831e.tar.gz
Fixed bug #29417.
An assertion abort could occur for some grouping queries that employed decimal user variables with assignments to them. The problem appeared the constructors of the class Field_new_decimal because the function my_decimal_length_to_precision did not guarantee returning decimal precision not greater than DECIMAL_MAX_PRECISION. mysql-test/r/type_newdecimal.result: Added a test case for bug #29417. mysql-test/t/type_newdecimal.test: Added a test case for bug #29417. sql/field.cc: Fixed bug #29417. An assertion abort could occur for some grouping queries that employed decimal user variables with assignments to them. The problem appeared the constructors of the class Field_new_decimal because the function my_decimal_length_to_precision did not guarantee returning decimal precision not greater than DECIMAL_MAX_PRECISION. Now if the precision returned by calls to my_decimal_length_to_precision in the constructors of the class Field_new_decimal is greater than DECIMAL_MAX_PRECISION the precision is set to this value.
-rw-r--r--mysql-test/r/type_newdecimal.result8
-rw-r--r--mysql-test/t/type_newdecimal.test13
-rw-r--r--sql/field.cc2
3 files changed, 23 insertions, 0 deletions
diff --git a/mysql-test/r/type_newdecimal.result b/mysql-test/r/type_newdecimal.result
index 9e165721033..c580568f3d4 100644
--- a/mysql-test/r/type_newdecimal.result
+++ b/mysql-test/r/type_newdecimal.result
@@ -1471,4 +1471,12 @@ drop table t1;
SELECT 1.000000000000 * 99.999999999998 / 100 a,1.000000000000 * (99.999999999998 / 100) b;
a b
0.9999999999999800000000000000 0.9999999999999800000000000000
+CREATE TABLE t1 (a int DEFAULT NULL, b int DEFAULT NULL);
+INSERT INTO t1 VALUES (3,30), (1,10), (2,10);
+SET @a= CAST(1 AS decimal);
+SELECT 1 FROM t1 GROUP BY @b := @a, @b;
+1
+1
+1
+DROP TABLE t1;
End of 5.0 tests
diff --git a/mysql-test/t/type_newdecimal.test b/mysql-test/t/type_newdecimal.test
index d2b808bd5e0..da321cc9932 100644
--- a/mysql-test/t/type_newdecimal.test
+++ b/mysql-test/t/type_newdecimal.test
@@ -1162,4 +1162,17 @@ drop table t1;
#
SELECT 1.000000000000 * 99.999999999998 / 100 a,1.000000000000 * (99.999999999998 / 100) b;
+
+#
+# Bug #29417: assertion abort for a grouping query with decimal user variable
+#
+
+CREATE TABLE t1 (a int DEFAULT NULL, b int DEFAULT NULL);
+INSERT INTO t1 VALUES (3,30), (1,10), (2,10);
+
+SET @a= CAST(1 AS decimal);
+SELECT 1 FROM t1 GROUP BY @b := @a, @b;
+
+DROP TABLE t1;
+
--echo End of 5.0 tests
diff --git a/sql/field.cc b/sql/field.cc
index f81b1c33fa7..2e227f0e67e 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -2267,6 +2267,7 @@ Field_new_decimal::Field_new_decimal(char *ptr_arg,
dec_arg, zero_arg, unsigned_arg)
{
precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
+ set_if_smaller(precision, DECIMAL_MAX_PRECISION);
DBUG_ASSERT((precision <= DECIMAL_MAX_PRECISION) &&
(dec <= DECIMAL_MAX_SCALE));
bin_size= my_decimal_get_binary_size(precision, dec);
@@ -2286,6 +2287,7 @@ Field_new_decimal::Field_new_decimal(uint32 len_arg,
0, unsigned_arg)
{
precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
+ set_if_smaller(precision, DECIMAL_MAX_PRECISION);
DBUG_ASSERT((precision <= DECIMAL_MAX_PRECISION) &&
(dec <= DECIMAL_MAX_SCALE));
bin_size= my_decimal_get_binary_size(precision, dec);