Bug #69571 | Please make table creation stricter and not make changes silently | ||
---|---|---|---|
Submitted: | 25 Jun 2013 11:15 | Modified: | 26 Jun 2013 5:38 |
Reporter: | Simon Mudd (OCA) | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: DDL | Severity: | S3 (Non-critical) |
Version: | 5.6.12 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[25 Jun 2013 11:15]
Simon Mudd
[25 Jun 2013 12:05]
MySQL Verification Team
Hello Simon, Thank you for the report. Imho this is not a bug but a documented behavior as manual clearly states that "A PRIMARY KEY is a unique index where all key columns must be defined as NOT NULL. If they are not explicitly declared as NOT NULL, MySQL declares them so implicitly (and silently)" Please see http://dev.mysql.com/doc/refman/5.6/en/create-table.html mysql> create table t3 ( id int not null, a varchar(20) not null, b varchar(20) , primary key (id,a,b) ) engine = innodb default charset latin1; Query OK, 0 rows affected (0.07 sec) mysql> show create table t3\G *************************** 1. row *************************** Table: t3 Create Table: CREATE TABLE `t3` ( `id` int(11) NOT NULL, `a` varchar(20) NOT NULL, `b` varchar(20) NOT NULL DEFAULT '', PRIMARY KEY (`id`,`a`,`b`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec) mysql> I think it is a feature request to show warning if user try .. b VARCHAR(20) NULL, PRIMARY KEY (... b) because that would mean user wanted nullable PK, which is not allowed, so it was set to not null implicitly (and silently). Thanks, Umesh
[25 Jun 2013 12:09]
MySQL Verification Team
Also, see - http://dev.mysql.com/doc/refman/5.6/en/silent-column-changes.html
[26 Jun 2013 5:38]
Simon Mudd
I agree that this is documented but many other RDBMSes give errors when things are not defined correctly. The problem with this is that people get used to it and often do not worry about the implications of what they are doing and in many cases when a table starts to grow performance and storage characteristics may change because of these 'silent' changes. So I agree this is documented but so is "silent truncation" of data which can often get missed. That does not mean that it is good. When MySQL was being used in smaller environments I can imagine that the developers appreciated these "annoyances" going away. I am not so sure that this is good as you scale up and want to have more control or be more aware of "mistakes" and the only way to do that is to be stricter in what you accept. So please consider this stricter behaviour for the future.
[10 Oct 2014 11:53]
Daniƫl van Eeden
Related: Bug #69223 (warning/error if no primary key provided)