From 46d472d636a0b33dfffb77b8b61eead94e285839 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 Jul 2005 14:44:28 +0200 Subject: [PATCH 1/3] BUG#11635 mysqldump exports TYPE instead of USING for HASH Cluster indexes - Change output from SHOW CREATE TABLE to use USING instead of TYPE mysql-test/r/ctype_utf8.result: Update test results mysql-test/r/show_check.result: Update test results mysql-test/r/sql_mode.result: Update test results mysql-test/t/show_check.test: Add test for BUG#11635 sql/sql_show.cc: Change TYPE to USING as output from SHOW CREATE TABLE --- mysql-test/r/ctype_utf8.result | 8 ++++---- mysql-test/r/show_check.result | 25 ++++++++++++++++++++----- mysql-test/r/sql_mode.result | 6 +++--- mysql-test/t/show_check.test | 9 +++++++++ sql/sql_show.cc | 6 +++--- 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index 3a8265b01f7..d4e12ea84b7 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -412,7 +412,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `c` char(10) character set utf8 default NULL, - UNIQUE KEY `a` TYPE HASH (`c`(1)) + UNIQUE KEY `a` USING HASH (`c`(1)) ) ENGINE=HEAP DEFAULT CHARSET=latin1 insert into t1 values ('a'),('b'),('c'),('d'),('e'),('f'); insert into t1 values ('aa'); @@ -448,7 +448,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `c` char(10) character set utf8 default NULL, - UNIQUE KEY `a` TYPE BTREE (`c`(1)) + UNIQUE KEY `a` USING BTREE (`c`(1)) ) ENGINE=HEAP DEFAULT CHARSET=latin1 insert into t1 values ('a'),('b'),('c'),('d'),('e'),('f'); insert into t1 values ('aa'); @@ -570,7 +570,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `c` char(10) character set utf8 collate utf8_bin default NULL, - UNIQUE KEY `a` TYPE HASH (`c`(1)) + UNIQUE KEY `a` USING HASH (`c`(1)) ) ENGINE=HEAP DEFAULT CHARSET=latin1 insert into t1 values ('a'),('b'),('c'),('d'),('e'),('f'); insert into t1 values ('aa'); @@ -606,7 +606,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `c` char(10) character set utf8 collate utf8_bin default NULL, - UNIQUE KEY `a` TYPE BTREE (`c`(1)) + UNIQUE KEY `a` USING BTREE (`c`(1)) ) ENGINE=HEAP DEFAULT CHARSET=latin1 insert into t1 values ('a'),('b'),('c'),('d'),('e'),('f'); insert into t1 values ('aa'); diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result index 4a9e28e9ea4..1e5e8f442a8 100644 --- a/mysql-test/r/show_check.result +++ b/mysql-test/r/show_check.result @@ -420,7 +420,7 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) default NULL, - KEY `i` TYPE HASH (`i`) + KEY `i` USING HASH (`i`) ) ENGINE=HEAP DEFAULT CHARSET=latin1 DROP TABLE t1; CREATE TABLE t1 (i int, KEY USING BTREE (i)) ENGINE=MEMORY; @@ -428,7 +428,7 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) default NULL, - KEY `i` TYPE BTREE (`i`) + KEY `i` USING BTREE (`i`) ) ENGINE=HEAP DEFAULT CHARSET=latin1 DROP TABLE t1; CREATE TABLE t1 (i int, KEY (i)) ENGINE=MyISAM; @@ -444,7 +444,7 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) default NULL, - KEY `i` TYPE BTREE (`i`) + KEY `i` USING BTREE (`i`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t1; CREATE TABLE t1 (i int, KEY (i)) ENGINE=MyISAM; @@ -467,14 +467,14 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) default NULL, - KEY `i` TYPE BTREE (`i`) + KEY `i` USING BTREE (`i`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 ALTER TABLE t1 ENGINE=MEMORY; SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) default NULL, - KEY `i` TYPE BTREE (`i`) + KEY `i` USING BTREE (`i`) ) ENGINE=HEAP DEFAULT CHARSET=latin1 DROP TABLE t1; CREATE TABLE t1( @@ -498,3 +498,18 @@ def Comment 253 255 0 N 129 31 63 Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment t1 0 PRIMARY 1 field1 A 0 1000 NULL BTREE drop table t1; +create table t1 ( +c1 int NOT NULL, +c2 int NOT NULL, +PRIMARY KEY USING HASH (c1), +INDEX USING BTREE(c2) +); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL default '0', + `c2` int(11) NOT NULL default '0', + PRIMARY KEY USING HASH (`c1`), + KEY `c2` USING BTREE (`c2`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; diff --git a/mysql-test/r/sql_mode.result b/mysql-test/r/sql_mode.result index 652913d1fdb..4e1693e15ec 100644 --- a/mysql-test/r/sql_mode.result +++ b/mysql-test/r/sql_mode.result @@ -17,7 +17,7 @@ t1 CREATE TABLE `t1` ( `pseudo` varchar(35) character set latin2 NOT NULL default '', `email` varchar(60) character set latin2 NOT NULL default '', PRIMARY KEY (`a`), - UNIQUE KEY `email` TYPE BTREE (`email`) + UNIQUE KEY `email` USING BTREE (`email`) ) ENGINE=HEAP DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC set @@sql_mode="ansi_quotes"; show variables like 'sql_mode'; @@ -30,7 +30,7 @@ t1 CREATE TABLE "t1" ( "pseudo" varchar(35) character set latin2 NOT NULL default '', "email" varchar(60) character set latin2 NOT NULL default '', PRIMARY KEY ("a"), - UNIQUE KEY "email" TYPE BTREE ("email") + UNIQUE KEY "email" USING BTREE ("email") ) ENGINE=HEAP DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC set @@sql_mode="no_table_options"; show variables like 'sql_mode'; @@ -43,7 +43,7 @@ t1 CREATE TABLE `t1` ( `pseudo` varchar(35) character set latin2 NOT NULL default '', `email` varchar(60) character set latin2 NOT NULL default '', PRIMARY KEY (`a`), - UNIQUE KEY `email` TYPE BTREE (`email`) + UNIQUE KEY `email` USING BTREE (`email`) ) set @@sql_mode="no_key_options"; show variables like 'sql_mode'; diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test index f80e720275a..76691ad79b1 100644 --- a/mysql-test/t/show_check.test +++ b/mysql-test/t/show_check.test @@ -368,3 +368,12 @@ show index from t1; --disable_metadata drop table t1; +# Test for BUG#11635: mysqldump exports TYPE instead of USING for HASH +create table t1 ( + c1 int NOT NULL, + c2 int NOT NULL, + PRIMARY KEY USING HASH (c1), + INDEX USING BTREE(c2) +); +SHOW CREATE TABLE t1; +DROP TABLE t1; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 7e0ee0dab68..636c88847eb 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1414,15 +1414,15 @@ store_create_info(THD *thd, TABLE *table, String *packet) !limited_mysql_mode && !foreign_db_mode) { if (key_info->algorithm == HA_KEY_ALG_BTREE) - packet->append(" TYPE BTREE", 11); + packet->append(" USING BTREE", 12); if (key_info->algorithm == HA_KEY_ALG_HASH) - packet->append(" TYPE HASH", 10); + packet->append(" USING HASH", 11); // +BAR: send USING only in non-default case: non-spatial rtree if ((key_info->algorithm == HA_KEY_ALG_RTREE) && !(key_info->flags & HA_SPATIAL)) - packet->append(" TYPE RTREE", 11); + packet->append(" USING RTREE", 12); // No need to send TYPE FULLTEXT, it is sent as FULLTEXT KEY } From a78764e869f78659dad97667b0c1c0bb305d58d3 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 Jul 2005 18:20:13 +0200 Subject: [PATCH 2/3] Merge to 5.0 mysql-test/r/ctype_utf8.result: Correct wrong merge mysql-test/r/show_check.result: Correct wrong merge Fix output from new test for SHOW CREATE TABLE, default '0' is not displayed in 5.0 mysql-test/r/sql_mode.result: Correct wrong merge --- mysql-test/r/ctype_utf8.result | 8 ++++---- mysql-test/r/show_check.result | 10 +++++----- mysql-test/r/sql_mode.result | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index 7b0e4a17538..b8ff3c70aa1 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -413,7 +413,7 @@ Table Create Table t1 CREATE TABLE `t1` ( `c` char(10) character set utf8 default NULL, UNIQUE KEY `a` USING HASH (`c`(1)) -) ENGINE=HEAP DEFAULT CHARSET=latin1 +) ENGINE=MEMORY DEFAULT CHARSET=latin1 insert into t1 values ('a'),('b'),('c'),('d'),('e'),('f'); insert into t1 values ('aa'); ERROR 23000: Duplicate entry 'aa' for key 1 @@ -449,7 +449,7 @@ Table Create Table t1 CREATE TABLE `t1` ( `c` char(10) character set utf8 default NULL, UNIQUE KEY `a` USING BTREE (`c`(1)) -) ENGINE=HEAP DEFAULT CHARSET=latin1 +) ENGINE=MEMORY DEFAULT CHARSET=latin1 insert into t1 values ('a'),('b'),('c'),('d'),('e'),('f'); insert into t1 values ('aa'); ERROR 23000: Duplicate entry 'aa' for key 1 @@ -571,7 +571,7 @@ Table Create Table t1 CREATE TABLE `t1` ( `c` char(10) character set utf8 collate utf8_bin default NULL, UNIQUE KEY `a` USING HASH (`c`(1)) -) ENGINE=HEAP DEFAULT CHARSET=latin1 +) ENGINE=MEMORY DEFAULT CHARSET=latin1 insert into t1 values ('a'),('b'),('c'),('d'),('e'),('f'); insert into t1 values ('aa'); ERROR 23000: Duplicate entry 'aa' for key 1 @@ -607,7 +607,7 @@ Table Create Table t1 CREATE TABLE `t1` ( `c` char(10) character set utf8 collate utf8_bin default NULL, UNIQUE KEY `a` USING BTREE (`c`(1)) -) ENGINE=HEAP DEFAULT CHARSET=latin1 +) ENGINE=MEMORY DEFAULT CHARSET=latin1 insert into t1 values ('a'),('b'),('c'),('d'),('e'),('f'); insert into t1 values ('aa'); ERROR 23000: Duplicate entry 'aa' for key 1 diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result index 71ffde5779b..dcab877abf9 100644 --- a/mysql-test/r/show_check.result +++ b/mysql-test/r/show_check.result @@ -420,7 +420,7 @@ Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) default NULL, KEY `i` USING HASH (`i`) -) ENGINE=HEAP DEFAULT CHARSET=latin1 +) ENGINE=MEMORY DEFAULT CHARSET=latin1 DROP TABLE t1; CREATE TABLE t1 (i int, KEY USING BTREE (i)) ENGINE=MEMORY; SHOW CREATE TABLE t1; @@ -428,7 +428,7 @@ Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) default NULL, KEY `i` USING BTREE (`i`) -) ENGINE=HEAP DEFAULT CHARSET=latin1 +) ENGINE=MEMORY DEFAULT CHARSET=latin1 DROP TABLE t1; CREATE TABLE t1 (i int, KEY (i)) ENGINE=MyISAM; SHOW CREATE TABLE t1; @@ -474,7 +474,7 @@ Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) default NULL, KEY `i` USING BTREE (`i`) -) ENGINE=HEAP DEFAULT CHARSET=latin1 +) ENGINE=MEMORY DEFAULT CHARSET=latin1 DROP TABLE t1; CREATE TABLE t1( field1 text NOT NULL, @@ -506,8 +506,8 @@ INDEX USING BTREE(c2) SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( - `c1` int(11) NOT NULL default '0', - `c2` int(11) NOT NULL default '0', + `c1` int(11) NOT NULL, + `c2` int(11) NOT NULL, PRIMARY KEY USING HASH (`c1`), KEY `c2` USING BTREE (`c2`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 diff --git a/mysql-test/r/sql_mode.result b/mysql-test/r/sql_mode.result index fa43d527c6a..f65e0421968 100644 --- a/mysql-test/r/sql_mode.result +++ b/mysql-test/r/sql_mode.result @@ -18,7 +18,7 @@ t1 CREATE TABLE `t1` ( `email` varchar(60) character set latin2 NOT NULL default '', PRIMARY KEY (`a`), UNIQUE KEY `email` USING BTREE (`email`) -) ENGINE=HEAP DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC +) ENGINE=MEMORY DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC set @@sql_mode="ansi_quotes"; show variables like 'sql_mode'; Variable_name Value @@ -31,7 +31,7 @@ t1 CREATE TABLE "t1" ( "email" varchar(60) character set latin2 NOT NULL default '', PRIMARY KEY ("a"), UNIQUE KEY "email" USING BTREE ("email") -) ENGINE=HEAP DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC +) ENGINE=MEMORY DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC set @@sql_mode="no_table_options"; show variables like 'sql_mode'; Variable_name Value From 077e335eb35d7217e2c950a2caa7c025f78f7a3b Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 Jul 2005 21:47:18 +0500 Subject: [PATCH 3/3] Fix for bug #8449(Silent column changes) mysql-test/r/show_check.result: test result fixed mysql-test/r/sql_mode.result: test result fixed mysql-test/r/type_decimal.result: test result fixed mysql-test/r/type_float.result: test result fixed mysql-test/r/type_newdecimal.result: test result fixed mysql-test/t/type_decimal.test: test fixed mysql-test/t/type_float.test: test fixed mysql-test/t/type_newdecimal.test: test case added sql/share/errmsg.txt: error messages added sql/sql_parse.cc: now precision/scale parameters are handled in required way --- mysql-test/r/show_check.result | 6 ++--- mysql-test/r/sql_mode.result | 6 ++--- mysql-test/r/type_decimal.result | 27 ++----------------- mysql-test/r/type_float.result | 14 ++-------- mysql-test/r/type_newdecimal.result | 15 +++++++++++ mysql-test/t/type_decimal.test | 13 ++------- mysql-test/t/type_float.test | 7 ++--- mysql-test/t/type_newdecimal.test | 15 +++++++++++ sql/share/errmsg.txt | 6 +++++ sql/sql_parse.cc | 41 ++++++++++++++++------------- 10 files changed, 72 insertions(+), 78 deletions(-) diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result index dd07e0ba755..13f4a4fe214 100644 --- a/mysql-test/r/show_check.result +++ b/mysql-test/r/show_check.result @@ -267,9 +267,9 @@ drop table t1; create table t1 (c decimal(3,3), d double(3,3), f float(3,3)); show columns from t1; Field Type Null Key Default Extra -c decimal(4,3) YES NULL -d double(4,3) YES NULL -f float(4,3) YES NULL +c decimal(3,3) YES NULL +d double(3,3) YES NULL +f float(3,3) YES NULL drop table t1; SET @old_sql_mode= @@sql_mode, sql_mode= ''; SET @old_sql_quote_show_create= @@sql_quote_show_create, sql_quote_show_create= OFF; diff --git a/mysql-test/r/sql_mode.result b/mysql-test/r/sql_mode.result index f65e0421968..9be5f5bc0d2 100644 --- a/mysql-test/r/sql_mode.result +++ b/mysql-test/r/sql_mode.result @@ -120,7 +120,7 @@ create table t1 ( min_num dec(6,6) default .000001); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `min_num` decimal(7,6) default '0.000001' + `min_num` decimal(6,6) default '0.000001' ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1 ; set session sql_mode = 'IGNORE_SPACE'; @@ -128,14 +128,14 @@ create table t1 ( min_num dec(6,6) default 0.000001); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `min_num` decimal(7,6) default '0.000001' + `min_num` decimal(6,6) default '0.000001' ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1 ; create table t1 ( min_num dec(6,6) default .000001); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `min_num` decimal(7,6) default '0.000001' + `min_num` decimal(6,6) default '0.000001' ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1 ; set @@SQL_MODE=NULL; diff --git a/mysql-test/r/type_decimal.result b/mysql-test/r/type_decimal.result index 93467d1d7da..15f9b839994 100644 --- a/mysql-test/r/type_decimal.result +++ b/mysql-test/r/type_decimal.result @@ -476,12 +476,7 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp CREATE TABLE t1 (a_dec DECIMAL(-1,1)); ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1,1))' at line 1 CREATE TABLE t1 (a_dec DECIMAL(0,11)); -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a_dec` decimal(11,11) default NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -DROP TABLE t1; +ERROR 42000: Scale may not be larger than the precision (column 'a_dec'). create table t1(a decimal(7,3)); insert into t1 values ('1'),('+1'),('-1'),('0000000001'),('+0000000001'),('-0000000001'),('10'),('+10'),('-10'),('0000000010'),('+0000000010'),('-0000000010'),('100'),('+100'),('-100'),('0000000100'),('+0000000100'),('-0000000100'),('1000'),('+1000'),('-1000'),('0000001000'),('+0000001000'),('-0000001000'),('10000'),('+10000'),('-10000'),('0000010000'),('+0000010000'),('-0000010000'),('100000'),('+100000'),('-100000'),('0000100000'),('+0000100000'),('-0000100000'),('1000000'),('+1000000'),('-1000000'),('0001000000'),('+0001000000'),('-0001000000'),('10000000'),('+10000000'),('-10000000'),('0010000000'),('+0010000000'),('-0010000000'),('100000000'),('+100000000'),('-100000000'),('0100000000'),('+0100000000'),('-0100000000'),('1000000000'),('+1000000000'),('-1000000000'),('1000000000'),('+1000000000'),('-1000000000'); select * from t1; @@ -699,24 +694,6 @@ select * from t1; d 1 drop table t1; -create table t1 (d decimal(64,99)); -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `d` decimal(64,30) default NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -insert into t1 values (1); -select * from t1; -d -1.000000000000000000000000000000 -drop table t1; -create table t1 (d decimal(10,12)); -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `d` decimal(13,12) default NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -drop table t1; create table t1 (d decimal(5)); show create table t1; Table Create Table @@ -732,7 +709,7 @@ t1 CREATE TABLE `t1` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; create table t1 (d decimal(66,0)); -ERROR 42000: Incorrect column specifier for column 'd' +ERROR 42000: Too big precision 66 specified for column 'd'. Maximum is 65. CREATE TABLE t1 (i INT, d1 DECIMAL(9,2), d2 DECIMAL(9,2)); INSERT INTO t1 VALUES (1, 101.40, 21.40), (1, -80.00, 0.00), (2, 0.00, 0.00), (2, -13.20, 0.00), (2, 59.60, 46.40), diff --git a/mysql-test/r/type_float.result b/mysql-test/r/type_float.result index b0b3ab147b0..d243985332e 100644 --- a/mysql-test/r/type_float.result +++ b/mysql-test/r/type_float.result @@ -103,7 +103,7 @@ select max(a),min(a),avg(a) from t1; max(a) min(a) avg(a) 1 1 1 drop table t1; -create table t1 (f float, f2 float(24), f3 float(6,2), d double, d2 float(53), d3 double(10,3), de decimal, de2 decimal(6), de3 decimal(5,2), n numeric, n2 numeric(8), n3 numeric(5,6)); +create table t1 (f float, f2 float(24), f3 float(6,2), d double, d2 float(53), d3 double(10,3), de decimal, de2 decimal(6), de3 decimal(5,2), n numeric, n2 numeric(8), n3 numeric(7,6)); show full columns from t1; Field Type Collation Null Key Default Extra Privileges Comment f float NULL YES NULL # @@ -133,17 +133,7 @@ min(a) -0.010 drop table t1; create table t1 (a float(200,100), b double(200,100)); -insert t1 values (1.0, 2.0); -select * from t1; -a b -1.000000000000000000000000000000 2.000000000000000000000000000000 -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` float(200,30) default NULL, - `b` double(200,30) default NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -drop table t1; +ERROR 42000: Too big scale 100 specified for column 'a'. Maximum is 30. create table t1 (c20 char); insert into t1 values (5000.0); Warnings: diff --git a/mysql-test/r/type_newdecimal.result b/mysql-test/r/type_newdecimal.result index f4e75402009..964a69ffb12 100644 --- a/mysql-test/r/type_newdecimal.result +++ b/mysql-test/r/type_newdecimal.result @@ -940,3 +940,18 @@ cast('1.00000001335143196001808973960578441619873046875E-10' as decimal(30,15)) select ln(14000) c1, convert(ln(14000),decimal(2,3)) c2, cast(ln(14000) as decimal(2,3)) c3; c1 c2 c3 9.5468126085974 9.547 9.547 +create table t1 (sl decimal(70,30)); +ERROR 42000: Too big precision 70 specified for column 'sl'. Maximum is 65. +create table t1 (sl decimal(32,31)); +ERROR 42000: Too big scale 31 specified for column 'sl'. Maximum is 30. +create table t1 (sl decimal(0,38)); +ERROR 42000: Too big scale 38 specified for column 'sl'. Maximum is 30. +create table t1 (sl decimal(0,30)); +ERROR 42000: Scale may not be larger than the precision (column 'sl'). +create table t1 (sl decimal(5, 5)); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `sl` decimal(5,5) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; diff --git a/mysql-test/t/type_decimal.test b/mysql-test/t/type_decimal.test index 7ce54847506..2901592fd9e 100644 --- a/mysql-test/t/type_decimal.test +++ b/mysql-test/t/type_decimal.test @@ -247,9 +247,8 @@ CREATE TABLE t1 (a_dec DECIMAL(-1,0)); CREATE TABLE t1 (a_dec DECIMAL(-2,1)); --error 1064 CREATE TABLE t1 (a_dec DECIMAL(-1,1)); +--error 1427 CREATE TABLE t1 (a_dec DECIMAL(0,11)); -SHOW CREATE TABLE t1; -DROP TABLE t1; # # Zero prepend overflow bug @@ -293,21 +292,13 @@ create table t1 (d decimal(64,0)); insert into t1 values (1); select * from t1; drop table t1; -create table t1 (d decimal(64,99)); -show create table t1; -insert into t1 values (1); -select * from t1; -drop table t1; -create table t1 (d decimal(10,12)); -show create table t1; -drop table t1; create table t1 (d decimal(5)); show create table t1; drop table t1; create table t1 (d decimal); show create table t1; drop table t1; ---error 1063 +--error 1426 create table t1 (d decimal(66,0)); # diff --git a/mysql-test/t/type_float.test b/mysql-test/t/type_float.test index 41812ef2652..a27fd4c58b4 100644 --- a/mysql-test/t/type_float.test +++ b/mysql-test/t/type_float.test @@ -67,7 +67,7 @@ drop table t1; # FLOAT/DOUBLE/DECIMAL handling # -create table t1 (f float, f2 float(24), f3 float(6,2), d double, d2 float(53), d3 double(10,3), de decimal, de2 decimal(6), de3 decimal(5,2), n numeric, n2 numeric(8), n3 numeric(5,6)); +create table t1 (f float, f2 float(24), f3 float(6,2), d double, d2 float(53), d3 double(10,3), de decimal, de2 decimal(6), de3 decimal(5,2), n numeric, n2 numeric(8), n3 numeric(7,6)); # We mask out Privileges column because it differs for embedded server --replace_column 8 # show full columns from t1; @@ -79,11 +79,8 @@ select a from t1 order by a; select min(a) from t1; drop table t1; +--error 1425 create table t1 (a float(200,100), b double(200,100)); -insert t1 values (1.0, 2.0); -select * from t1; -show create table t1; -drop table t1; # # float in a char(1) field diff --git a/mysql-test/t/type_newdecimal.test b/mysql-test/t/type_newdecimal.test index 92f0bc9024b..55d004b361f 100644 --- a/mysql-test/t/type_newdecimal.test +++ b/mysql-test/t/type_newdecimal.test @@ -983,3 +983,18 @@ select cast('1.00000001335143196001808973960578441619873046875E-10' as decimal(3 # Bug #11708 (conversion to decimal fails in decimal part) # select ln(14000) c1, convert(ln(14000),decimal(2,3)) c2, cast(ln(14000) as decimal(2,3)) c3; + +# +# Bug #8449 (Silent column changes) +# +--error 1426 +create table t1 (sl decimal(70,30)); +--error 1425 +create table t1 (sl decimal(32,31)); +--error 1425 +create table t1 (sl decimal(0,38)); +--error 1427 +create table t1 (sl decimal(0,30)); +create table t1 (sl decimal(5, 5)); +show create table t1; +drop table t1; diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index bdcd88a7205..622c570fa9a 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5362,3 +5362,9 @@ ER_NO_DEFAULT_FOR_VIEW_FIELD eng "Field of view '%-.64s.%-.64s' underlying table doesn't have a default value" ER_SP_NO_RECURSION eng "Recursive stored routines are not allowed." +ER_TOO_BIG_SCALE 42000 S1009 + eng "Too big scale %d specified for column '%-.64s'. Maximum is %d." +ER_TOO_BIG_PRECISION 42000 S1009 + eng "Too big precision %d specified for column '%-.64s'. Maximum is %d." +ER_SCALE_BIGGER_THAN_PRECISION 42000 S1009 + eng "Scale may not be larger than the precision (column '%-.64s')." diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index a57ad84da5b..cc10d9c8eac 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -5564,8 +5564,14 @@ new_create_field(THD *thd, char *field_name, enum_field_types type, new_field->flags= type_modifier; new_field->unireg_check= (type_modifier & AUTO_INCREMENT_FLAG ? Field::NEXT_NUMBER : Field::NONE); - new_field->decimals= decimals ? (uint) set_zone(atoi(decimals),0, - NOT_FIXED_DEC-1) : 0; + new_field->decimals= decimals ? (uint)atoi(decimals) : 0; + if (new_field->decimals >= NOT_FIXED_DEC) + { + my_error(ER_TOO_BIG_SCALE, MYF(0), new_field->decimals, field_name, + NOT_FIXED_DEC-1); + DBUG_RETURN(NULL); + } + new_field->sql_type=type; new_field->length=0; new_field->change=change; @@ -5586,11 +5592,6 @@ new_create_field(THD *thd, char *field_name, enum_field_types type, length=0; /* purecov: inspected */ sign_len=type_modifier & UNSIGNED_FLAG ? 0 : 1; - if (new_field->length && new_field->decimals && - new_field->length < new_field->decimals+1 && - new_field->decimals != NOT_FIXED_DEC) - new_field->length=new_field->decimals+1; /* purecov: inspected */ - switch (type) { case FIELD_TYPE_TINY: if (!length) new_field->length=MAX_TINYINT_WIDTH+sign_len; @@ -5616,22 +5617,24 @@ new_create_field(THD *thd, char *field_name, enum_field_types type, break; case FIELD_TYPE_NEWDECIMAL: if (!length) + new_field->length= 10; + if (new_field->length > DECIMAL_MAX_PRECISION) { - if (!(new_field->length= new_field->decimals)) - new_field->length= 10; // Default length for DECIMAL + my_error(ER_TOO_BIG_PRECISION, MYF(0), new_field->length, field_name, + DECIMAL_MAX_PRECISION); + DBUG_RETURN(NULL); } + if (new_field->length < new_field->decimals) + { + my_error(ER_SCALE_BIGGER_THAN_PRECISION, MYF(0), field_name); + DBUG_RETURN(NULL); + } + new_field->length= + my_decimal_precision_to_length(new_field->length, new_field->decimals, + type_modifier & UNSIGNED_FLAG); new_field->pack_length= my_decimal_get_binary_size(new_field->length, new_field->decimals); - if (new_field->length <= DECIMAL_MAX_PRECISION && - new_field->length >= new_field->decimals) - { - new_field->length= - my_decimal_precision_to_length(new_field->length, new_field->decimals, - type_modifier & UNSIGNED_FLAG); - break; - } - my_error(ER_WRONG_FIELD_SPEC, MYF(0), field_name); - DBUG_RETURN(NULL); + break; case MYSQL_TYPE_VARCHAR: /* Long VARCHAR's are automaticly converted to blobs in mysql_prepare_table