Hi there -
I would like to propose that this is the incorrect resolution to this issue.
While at face value, the proposal to "automatically drop a constraint" sounds like the wrong thing, this is very much the standard approach to a constraint that relies solely upon a single column in a table.
Consider the behavior in the same kind of situation for the following types of constraints:
- NOT NULL constraint - is implicitly dropped with the column:
MariaDB [test]> create table t1 (a int NOT NULL, b int);
|
Query OK, 0 rows affected (0.04 sec)
|
|
MariaDB [test]> alter table t1 drop column a;
|
Query OK, 0 rows affected (0.04 sec)
|
Records: 0 Duplicates: 0 Warnings: 0
|
|
- UNIQUE constraint - is implicitly dropped with the column:
MariaDB [test]> create table t1 (a int, b int, unique key a (a));
|
Query OK, 0 rows affected (0.02 sec)
|
|
MariaDB [test]> alter table t1 drop column a;
|
Query OK, 0 rows affected (0.04 sec)
|
Records: 0 Duplicates: 0 Warnings: 0
|
|
- CHECK constraint - is implicitly dropped when you drop the whole table.
The above behaviors illustrate that the implicit dropping of constraints is a completely reasonable behavior and already is the behavior in most cases for MariaDB as well as most other databases. The case of CHECK CONSTRAINT here is entirely inconsistent with that of all other kinds of constraints.
The change is also backwards incompatible with all MySQL versions and MariaDB versions prior to 10.2. Application code that emits CREATE TABLE statements which include CHECK constraints now produce a table where columns cannot be dropped - this because MariaDB 10.2 has made CHECK constraints actually do something whereas in all prior version and MySQL versions, the CHECK syntax was silently ignored but accepted.
Finally, preventing the column from being dropped due to a CHECK constraint that refers to it alone is inconsistent with the behavior of most other major database systems.
- Postgresql - CHECK constraint is implicitly dropped:
psql (9.5.7)
|
Type "help" for help.
|
|
test=# create table t1 (a int, b int, check(a>0));
|
CREATE TABLE
|
test=# alter table t1 drop column a;
|
ALTER TABLE
|
test=#
|
- Oracle - CHECK constraint is implicitly dropped:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
|
|
SQL> create table t1 (a int, b int, check(a>0));
|
|
Table created.
|
|
SQL> alter table t1 drop column a;
|
|
Table altered.
|
- Microsoft SQL Server does have this limitation:
Msg 5074, Level 16, State 1, Line 4
|
The object 'CK__t1__a__25DD32AA' is dependent on column 'a'.
|
Msg 4922, Level 16, State 9, Line 4
|
ALTER TABLE DROP COLUMN a failed because one or more objects access this column.
|
However, in the case of SQL server, the change is at least not backwards incompatible.
Given MariaDB's mission of staying as close to cross-compatibility with MySQL as possible, the decision to prevent DROP COLUMN without locating all CHECK constraints and explicitly dropping them as well will only make it that more difficult. At least provide an option to DROP COLUMN and/or a SQL mode setting which makes this possible, however as noted above it's inconsistent that no such limitation exists for all other kinds of constraints. Explicitly dropping constraints that were not given explicit names in particular is very inconvenient as the name of the constraint is required to handle the DROP.
I don't think it's a bug, I do prefer an error over automatic dropping of a constraint.