Skip to content

Commit

Permalink
Ensure that fields declared with NOT NULL doesn't have DEFAULT values…
Browse files Browse the repository at this point in the history
… if not specified and if not timestamp or auto_increment

In original code, sometimes one got an automatic DEFAULT value in some cases, in other cases not.

For example:
create table t1 (a int primary key)      - No default
create table t2 (a int, primary key(a))  - DEFAULT 0
create table t1 SELECT ....              - Default for all fields, even if they where defined as NOT NULL
ALTER TABLE ... MODIFY could sometimes add an unexpected DEFAULT value.

The patch is quite big because we had some many test cases that used
CREATE ... SELECT or CREATE ... (...PRIMARY KEY(xxx)) which doesn't have an automatic DEFAULT anymore.

Other things:
- Removed warnings from InnoDB when waiting from semaphore (got this when testing things with --big)
  • Loading branch information
montywi committed Aug 18, 2015
1 parent 92fd658 commit 6b20342
Show file tree
Hide file tree
Showing 184 changed files with 6,776 additions and 6,305 deletions.
1 change: 1 addition & 0 deletions mysql-test/mysql-test-run.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4374,6 +4374,7 @@ ($$)
qr/InnoDB: Redo log crypto: Can't initialize to key version -1u/,
qr/InnoDB: Dumping buffer pool.*/,
qr/InnoDB: Buffer pool.*/,
qr/InnoDB: Warning: Writer thread is waiting this semaphore/,
qr/Slave: Unknown table 't1' .* 1051/,
qr/Slave SQL:.*(Internal MariaDB error code: [[:digit:]]+|Query:.*)/,
qr/slave SQL thread aborted/,
Expand Down
9 changes: 9 additions & 0 deletions mysql-test/r/alter_table.result
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,15 @@ t2 CREATE TABLE `t2` (
drop table if exists t1, t2;
create table t1 (a int, b int, c int, d int, e int, f int, g int, h int,i int, primary key (a,b,c,d,e,f,g,i,h)) engine=MyISAM;
insert into t1 (a) values(1);
Warnings:
Warning 1364 Field 'b' doesn't have a default value
Warning 1364 Field 'c' doesn't have a default value
Warning 1364 Field 'd' doesn't have a default value
Warning 1364 Field 'e' doesn't have a default value
Warning 1364 Field 'f' doesn't have a default value
Warning 1364 Field 'g' doesn't have a default value
Warning 1364 Field 'h' doesn't have a default value
Warning 1364 Field 'i' doesn't have a default value
show table status like 't1';
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
t1 MyISAM 10 Fixed 1 37 X X X X X X X X latin1_swedish_ci NULL
Expand Down
8 changes: 4 additions & 4 deletions mysql-test/r/bigint.result
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ create table t1 select 1 as 'a';
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(1) NOT NULL DEFAULT '0'
`a` int(1) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 select 9223372036854775809 as 'a';
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bigint(19) unsigned NOT NULL DEFAULT '0'
`a` bigint(19) unsigned NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
select * from t1;
a
Expand Down Expand Up @@ -397,12 +397,12 @@ select -(-9223372036854775808), -(-(-9223372036854775808));
create table t1 select -9223372036854775808 bi;
describe t1;
Field Type Null Key Default Extra
bi bigint(20) NO 0
bi bigint(20) NO NULL
drop table t1;
create table t1 select -9223372036854775809 bi;
describe t1;
Field Type Null Key Default Extra
bi decimal(19,0) NO 0
bi decimal(19,0) NO NULL
drop table t1;
#
# Bug #45360: wrong results
Expand Down
36 changes: 18 additions & 18 deletions mysql-test/r/case.result
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ CASE WHEN 1 THEN 0.1e1 else '1' END AS c12
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c1` varchar(1) CHARACTER SET latin1 COLLATE latin1_danish_ci NOT NULL DEFAULT '',
`c2` varchar(1) CHARACTER SET latin1 COLLATE latin1_danish_ci NOT NULL DEFAULT '',
`c3` varchar(1) NOT NULL DEFAULT '',
`c4` varchar(1) NOT NULL DEFAULT '',
`c5` varchar(4) NOT NULL DEFAULT '',
`c6` varchar(4) NOT NULL DEFAULT '',
`c7` decimal(2,1) NOT NULL DEFAULT '0.0',
`c8` decimal(2,1) NOT NULL DEFAULT '0.0',
`c1` varchar(1) CHARACTER SET latin1 COLLATE latin1_danish_ci NOT NULL,
`c2` varchar(1) CHARACTER SET latin1 COLLATE latin1_danish_ci NOT NULL,
`c3` varchar(1) NOT NULL,
`c4` varchar(1) NOT NULL,
`c5` varchar(4) NOT NULL,
`c6` varchar(4) NOT NULL,
`c7` decimal(2,1) NOT NULL,
`c8` decimal(2,1) NOT NULL,
`c9` decimal(2,1) DEFAULT NULL,
`c10` double NOT NULL DEFAULT '0',
`c11` double NOT NULL DEFAULT '0',
`c12` varchar(5) NOT NULL DEFAULT ''
`c10` double NOT NULL,
`c11` double NOT NULL,
`c12` varchar(5) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
SELECT CASE
Expand Down Expand Up @@ -151,13 +151,13 @@ Note 1003 select coalesce(1) AS `COALESCE(1)`,coalesce(1.0) AS `COALESCE(1.0)`,c
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`COALESCE(1)` int(1) NOT NULL DEFAULT '0',
`COALESCE(1.0)` decimal(2,1) NOT NULL DEFAULT '0.0',
`COALESCE('a')` varchar(1) NOT NULL DEFAULT '',
`COALESCE(1,1.0)` decimal(2,1) NOT NULL DEFAULT '0.0',
`COALESCE(1,'1')` varchar(1) NOT NULL DEFAULT '',
`COALESCE(1.1,'1')` varchar(4) NOT NULL DEFAULT '',
`COALESCE('a' COLLATE latin1_bin,'b')` varchar(1) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT ''
`COALESCE(1)` int(1) NOT NULL,
`COALESCE(1.0)` decimal(2,1) NOT NULL,
`COALESCE('a')` varchar(1) NOT NULL,
`COALESCE(1,1.0)` decimal(2,1) NOT NULL,
`COALESCE(1,'1')` varchar(1) NOT NULL,
`COALESCE(1.1,'1')` varchar(4) NOT NULL,
`COALESCE('a' COLLATE latin1_bin,'b')` varchar(1) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
CREATE TABLE t1 SELECT IFNULL('a' COLLATE latin1_swedish_ci, 'b' COLLATE latin1_bin);
Expand Down
36 changes: 18 additions & 18 deletions mysql-test/r/cast.result
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ create table t1 select cast(_koi8r'
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`t` varchar(4) CHARACTER SET cp1251 NOT NULL DEFAULT ''
`t` varchar(4) CHARACTER SET cp1251 NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
select
Expand Down Expand Up @@ -438,11 +438,11 @@ ab a ab a 6100
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c1` varbinary(2) NOT NULL DEFAULT '',
`c2` varbinary(2) NOT NULL DEFAULT '',
`c3` varbinary(2) NOT NULL DEFAULT '',
`c4` varbinary(2) NOT NULL DEFAULT '',
`c5` varbinary(2) NOT NULL DEFAULT ''
`c1` varbinary(2) NOT NULL,
`c2` varbinary(2) NOT NULL,
`c3` varbinary(2) NOT NULL,
`c4` varbinary(2) NOT NULL,
`c5` varbinary(2) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
select
Expand Down Expand Up @@ -471,11 +471,11 @@ c1 c2 c3 c4 c5
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c1` varchar(2) CHARACTER SET utf8 NOT NULL DEFAULT '',
`c2` varchar(2) CHARACTER SET utf8 NOT NULL DEFAULT '',
`c3` varchar(2) CHARACTER SET utf8 NOT NULL DEFAULT '',
`c4` varchar(2) CHARACTER SET utf8 NOT NULL DEFAULT '',
`c5` varchar(2) CHARACTER SET utf8 NOT NULL DEFAULT ''
`c1` varchar(2) CHARACTER SET utf8 NOT NULL,
`c2` varchar(2) CHARACTER SET utf8 NOT NULL,
`c3` varchar(2) CHARACTER SET utf8 NOT NULL,
`c4` varchar(2) CHARACTER SET utf8 NOT NULL,
`c5` varchar(2) CHARACTER SET utf8 NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 (a binary(4), b char(4) character set koi8r);
Expand Down Expand Up @@ -582,12 +582,12 @@ create table t1 select cast(1 as unsigned), cast(1 as signed), cast(1 as double
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`cast(1 as unsigned)` int(1) unsigned NOT NULL DEFAULT '0',
`cast(1 as signed)` int(1) NOT NULL DEFAULT '0',
`cast(1 as unsigned)` int(1) unsigned NOT NULL,
`cast(1 as signed)` int(1) NOT NULL,
`cast(1 as double(5,2))` double(5,2) DEFAULT NULL,
`cast(1 as decimal(5,3))` decimal(5,3) NOT NULL DEFAULT '0.000',
`cast("A" as binary)` varbinary(1) NOT NULL DEFAULT '',
`cast("A" as char(100))` varbinary(100) NOT NULL DEFAULT '',
`cast(1 as decimal(5,3))` decimal(5,3) NOT NULL,
`cast("A" as binary)` varbinary(1) NOT NULL,
`cast("A" as char(100))` varbinary(100) NOT NULL,
`cast("2001-1-1" as DATE)` date DEFAULT NULL,
`cast("2001-1-1" as DATETIME)` datetime DEFAULT NULL,
`cast("1:2:3" as TIME)` time DEFAULT NULL
Expand Down Expand Up @@ -751,8 +751,8 @@ Warning 1292 Truncated incorrect INTEGER value: '9999999999999999999999999999999
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`CONCAT(CAST(REPEAT('9', 1000) AS SIGNED))` varchar(21) NOT NULL DEFAULT '',
`CONCAT(CAST(REPEAT('9', 1000) AS UNSIGNED))` varchar(21) NOT NULL DEFAULT ''
`CONCAT(CAST(REPEAT('9', 1000) AS SIGNED))` varchar(21) NOT NULL,
`CONCAT(CAST(REPEAT('9', 1000) AS UNSIGNED))` varchar(21) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
# End of test for Bug#13581962, Bug#14096619
Expand Down
12 changes: 6 additions & 6 deletions mysql-test/r/create-big.result
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ERROR 42S01: Table 't1' already exists
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(1) NOT NULL DEFAULT '0'
`i` int(1) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
set debug_sync='create_table_select_before_create SIGNAL parked WAIT_FOR go';
Expand All @@ -21,7 +21,7 @@ ERROR 42S01: Table 't1' already exists
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(1) NOT NULL DEFAULT '0'
`i` int(1) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t3 (j char(5));
Expand All @@ -34,7 +34,7 @@ ERROR 42S01: Table 't1' already exists
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(1) NOT NULL DEFAULT '0'
`i` int(1) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
set debug_sync='create_table_select_before_create SIGNAL parked WAIT_FOR go';
Expand All @@ -46,7 +46,7 @@ ERROR 42S01: Table 't1' already exists
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(1) NOT NULL DEFAULT '0'
`i` int(1) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
set debug_sync='create_table_select_before_create SIGNAL parked WAIT_FOR go';
Expand All @@ -58,7 +58,7 @@ ERROR 42S01: Table 't1' already exists
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(1) NOT NULL DEFAULT '0'
`i` int(1) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
set debug_sync='create_table_select_before_create SIGNAL parked WAIT_FOR go';
Expand All @@ -70,7 +70,7 @@ ERROR 42S01: Table 't1' already exists
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(1) NOT NULL DEFAULT '0'
`i` int(1) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1,t3;
set debug_sync='create_table_select_before_open SIGNAL parked WAIT_FOR go';
Expand Down
24 changes: 12 additions & 12 deletions mysql-test/r/create.result
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ drop table t2;
create table t2 select now() as a , curtime() as b, curdate() as c , 1+1 as d , 1.0 + 1 as e , 33333333333333333 + 3 as f;
describe t2;
Field Type Null Key Default Extra
a datetime NO 0000-00-00 00:00:00
b time NO 00:00:00
c date NO 0000-00-00
d int(3) NO 0
e decimal(3,1) NO 0.0
f bigint(19) NO 0
a datetime NO NULL
b time NO NULL
c date NO NULL
d int(3) NO NULL
e decimal(3,1) NO NULL
f bigint(19) NO NULL
drop table t2;
create table t2 select CAST("2001-12-29" AS DATE) as d, CAST("20:45:11" AS TIME) as t, CAST("2001-12-29 20:45:11" AS DATETIME) as dt;
describe t2;
Expand Down Expand Up @@ -481,10 +481,10 @@ from t1;
explain t2;
Field Type Null Key Default Extra
a int(11) YES NULL
b bigint(11) NO 0
c bigint(10) unsigned NO 0
b bigint(11) NO NULL
c bigint(10) unsigned NO NULL
d date YES NULL
e varchar(1) NO
e varchar(1) NO NULL
f datetime YES NULL
g time YES NULL
h longblob NO NULL
Expand Down Expand Up @@ -727,7 +727,7 @@ Table Create Table
t1 CREATE TABLE `t1` (
`b` int(11) NOT NULL,
`a` varchar(12) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`c` int(1) NOT NULL DEFAULT '0',
`c` int(1) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
Expand All @@ -740,7 +740,7 @@ Table Create Table
t1 CREATE TABLE `t1` (
`b` int(11) DEFAULT NULL,
`a` varchar(12) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`c` int(1) NOT NULL DEFAULT '0',
`c` int(1) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
Expand All @@ -763,7 +763,7 @@ b int not null, primary key (a)
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` varchar(12) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
`a` varchar(12) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`b` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
Expand Down
4 changes: 2 additions & 2 deletions mysql-test/r/create_or_replace.result
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ CREATE OR REPLACE TABLE t1 AS SELECT 1;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`1` int(1) NOT NULL DEFAULT '0'
`1` int(1) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
create table t1 (a int);
Expand Down Expand Up @@ -142,7 +142,7 @@ CREATE OR REPLACE TABLE t1 AS SELECT 1;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`1` int(1) NOT NULL DEFAULT '0'
`1` int(1) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a int);
Expand Down
Loading

0 comments on commit 6b20342

Please sign in to comment.