summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <jani@a193-229-222-105.elisa-laajakaista.fi>2005-09-09 20:02:13 +0300
committerunknown <jani@a193-229-222-105.elisa-laajakaista.fi>2005-09-09 20:02:13 +0300
commit19fa54f04e5580a5ba9ac11dac0e57f60462bd6a (patch)
treeb28646c4168054d8d84d9156e6d80928ab9f1d40
parent6c7f692d2ccc39133d159955c187a4d5d715d7bc (diff)
downloadmariadb-git-19fa54f04e5580a5ba9ac11dac0e57f60462bd6a.tar.gz
Fixed Bug#10716, Procedure Analyse results in wrong values for optimal field type
Added test case.
-rw-r--r--mysql-test/r/analyse.result6
-rw-r--r--mysql-test/t/analyse.test9
-rw-r--r--sql/sql_analyse.cc15
3 files changed, 25 insertions, 5 deletions
diff --git a/mysql-test/r/analyse.result b/mysql-test/r/analyse.result
index 09c606b5a04..0ebd4a3e409 100644
--- a/mysql-test/r/analyse.result
+++ b/mysql-test/r/analyse.result
@@ -102,3 +102,9 @@ select * from t1 procedure analyse();
Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
test.t1.v " \\ 1 19 0 0 3.7619 NULL ENUM('"','""','"c','\'\0\\"','\'','\'\'','\'b','a\0\0\0b','a\0','a""""b','a\'\'\'\'b','abc','abc\'def\\hij"klm\0opq','a\\\\\\\\b','b\'','c"','d\\','The\ZEnd','\\','\\d','\\\\') NOT NULL
drop table t1;
+create table t1 (d double);
+insert into t1 values (100000);
+select * from t1 procedure analyse (1,1);
+Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
+test.t1.d 100000 100000 6 6 0 0 100000 0 MEDIUMINT(6) UNSIGNED NOT NULL
+drop table t1;
diff --git a/mysql-test/t/analyse.test b/mysql-test/t/analyse.test
index e7fbf09c19a..e38e43381bc 100644
--- a/mysql-test/t/analyse.test
+++ b/mysql-test/t/analyse.test
@@ -48,4 +48,13 @@ insert into t1 values ('abc'),('abc\'def\\hij\"klm\0opq'),('\''),('\"'),('\\'),(
select * from t1 procedure analyse();
drop table t1;
+#
+# Bug#10716 - Procedure Analyse results in wrong values for optimal field type
+#
+
+create table t1 (d double);
+insert into t1 values (100000);
+select * from t1 procedure analyse (1,1);
+drop table t1;
+
# End of 4.1 tests
diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc
index fb5d0eb0a3f..c2cb427a5eb 100644
--- a/sql/sql_analyse.cc
+++ b/sql/sql_analyse.cc
@@ -789,18 +789,23 @@ void field_real::get_opt_type(String *answer,
if (!max_notzero_dec_len)
{
if (min_arg >= -128 && max_arg <= (min_arg >= 0 ? 255 : 127))
- sprintf(buff, "TINYINT(%d)", (int) max_length - (item->decimals + 1));
+ sprintf(buff, "TINYINT(%d)", (int) max_length -
+ ((item->decimals == NOT_FIXED_DEC) ? 0 : (item->decimals + 1)));
else if (min_arg >= INT_MIN16 && max_arg <= (min_arg >= 0 ?
UINT_MAX16 : INT_MAX16))
- sprintf(buff, "SMALLINT(%d)", (int) max_length - (item->decimals + 1));
+ sprintf(buff, "SMALLINT(%d)", (int) max_length -
+ ((item->decimals == NOT_FIXED_DEC) ? 0 : (item->decimals + 1)));
else if (min_arg >= INT_MIN24 && max_arg <= (min_arg >= 0 ?
UINT_MAX24 : INT_MAX24))
- sprintf(buff, "MEDIUMINT(%d)", (int) max_length - (item->decimals + 1));
+ sprintf(buff, "MEDIUMINT(%d)", (int) max_length -
+ ((item->decimals == NOT_FIXED_DEC) ? 0 : (item->decimals + 1)));
else if (min_arg >= INT_MIN32 && max_arg <= (min_arg >= 0 ?
UINT_MAX32 : INT_MAX32))
- sprintf(buff, "INT(%d)", (int) max_length - (item->decimals + 1));
+ sprintf(buff, "INT(%d)", (int) max_length -
+ ((item->decimals == NOT_FIXED_DEC) ? 0 : (item->decimals + 1)));
else
- sprintf(buff, "BIGINT(%d)", (int) max_length - (item->decimals + 1));
+ sprintf(buff, "BIGINT(%d)", (int) max_length -
+ ((item->decimals == NOT_FIXED_DEC) ? 0 : (item->decimals + 1)));
answer->append(buff, (uint) strlen(buff));
if (min_arg >= 0)
answer->append(" UNSIGNED");