[MDEV-13613] Dropping column from table that is part of a key fails in 10.2.8 Created: 2017-08-22 Updated: 2021-01-26 Resolved: 2017-08-31 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Documentation |
| Affects Version/s: | 10.2.8 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Paul Thompson | Assignee: | Ian Gilfillan |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Docker version 17.06.0-ce, build 02c1d87 running on OSX 10.12.4 (16E195) |
||
| Issue Links: |
|
||||||||||||||||||||||||||||||||
| Description |
| Comments |
| Comment by Sergei Golubchik [ 2017-08-22 ] | ||||||||||
|
Yes, it is a result of a bug fix. Dropping a column in such a case was a bug. Because it did not only drop a column, it also added an additional constraint to the table — that all values in the column B are unique. It also contradicted the SQL standard. In the standard the unique constraint could have been dropped as a whole. Or there could've been an error. But under no circumstances it could've been automatically "adjusted" to mean something else. Now a column cannot be dropped, if it's part of a multi-column UNIQUE constraint. To reiterate — this logic only applies to multi-column and unique indexes. If an index is not unique, or it only covers one single column, the column will be dropped as before. Exactly the same restriction applies to CHECK constraints too — a column cannot be dropped, if it's part of a multi-column CHECK constraint. | ||||||||||
| Comment by Sergei Golubchik [ 2017-08-22 ] | ||||||||||
|
We need to document this change better, though | ||||||||||
| Comment by Marko Mäkelä [ 2017-08-22 ] | ||||||||||
|
On a related note, ALTER TABLE…ALGORITHM=INPLACE in InnoDB in MariaDB 10.2.2 contains code to skip the sorting when the previous ordering of the primary key can be preserved. This is being covered in a test of MySQL 5.7 which is currently missing from MariaDB, innodb.innodb-index-debug:
We should import this test to MariaDB. And we should also have a test that demonstrates that with explicit DROP, ADD clauses for PRIMARY KEY or UNIQUE KEY, the DROP COLUMN will be accepted. In the provided example, the sorting will be necessary in
but it can be skipped in
because the old PRIMARY KEY(A,B) would be sorted in the same way as the new PRIMARY KEY(A). | ||||||||||
| Comment by Paul Thompson [ 2017-08-23 ] | ||||||||||
|
I wouldn't dispute this being a bug, it's certainly something I can entirely understand fixing. I think it's worth triaging these kind of bugfixes to a larger release though. This behaviour has been in
I feel as though fixing it in a minor/major version could have been more appropriate given it's a larger departure from how things have been in the past. | ||||||||||
| Comment by Ian Gilfillan [ 2017-08-23 ] | ||||||||||
|
I have documented this on https://mariadb.com/kb/en/the-mariadb-library/alter-table/#drop-column-if-exists-col_name-cascaderestrict but "Key column 'A' doesn't exist in table" is not the best error message in this case. | ||||||||||
| Comment by Sergei Golubchik [ 2017-08-23 ] | ||||||||||
|
pathompson, right. That's why I've done it in only 10.2, which is not as widely used as 5.5–10.1. But the actual trigger was | ||||||||||
| Comment by Marko Mäkelä [ 2017-08-31 ] | ||||||||||
|
As part of | ||||||||||
| Comment by Ian Gilfillan [ 2017-08-31 ] | ||||||||||
|
Documentation clarified - the misleading error message can be opened as a separate issue | ||||||||||
| Comment by Marko Mäkelä [ 2017-09-14 ] | ||||||||||
|
As part of
| ||||||||||
| Comment by Todd Farmer [ 2018-02-19 ] | ||||||||||
|
Please clarify exactly how this is "fixed" (per JIRA resolution status). Enhanced documentation? The behavior itself does not appear to be changed, despite the fact that this introduced breaking incompatibility with both past versions, upstream MySQL and in a maintenance release. | ||||||||||
| Comment by Sergei Golubchik [ 2018-02-19 ] | ||||||||||
|
Yes, enhanced documentation. The changed behavior was a result of the bug fix, namely, old behavior was considered a bug. | ||||||||||
| Comment by Todd Farmer [ 2018-02-19 ] | ||||||||||
|
Maybe the documentation can be linked, and the JIRA component updated to show that what was "fixed" was just documentation? Right now, it references "Data Definition - Alter Table", which - when coupled with the "Fixed" resolution - suggests behavior was changed. When your bug fix for CHECK CONSTRAINT code changes behavior that triggers schema preparation scripts to fail - as it did for Cloudera Manager - in a maintenance release, when CHECK CONSTRAINTS aren't in use, I will argue that it's most certainly an introduced incompatibility. | ||||||||||
| Comment by Todd Farmer [ 2018-02-19 ] | ||||||||||
|
Thanks - you may also consider adding a note in the 10.2 incompatibilities documentation. | ||||||||||
| Comment by Sergei Golubchik [ 2018-02-19 ] | ||||||||||
|
You're right. Sorry for confusion. "Component" is now Documentation. The bug was that DROP COLUMN X in some cases implicitly meant "add new UNIQUE constraint to the column Y". Now if you want all values in the column Y be unique, you need to add a unique constraint explicitly, it won't automagically appear because of some unrelated operation. | ||||||||||
| Comment by Todd Farmer [ 2018-02-19 ] | ||||||||||
|
Thank you again. I understand you are referencing MySQL Bug#17098. I agree with the assertion that the historical behavior is inappropriate and non-compliant with standards. I disagree with the decision to make such a change in a maintenance release. I'd argue that behavioral changes such as this should only be made in maintenance releases when the consequences of the defect are severe (data loss, service availability,etc,), and that standards compliance enhancements be reserved for major/minor releases. |