[MDEV-8351] alter table - failing to ADD KEY IF NOT EXISTS when existing dropping the same index name earlier in the alter table Created: 2015-06-22 Updated: 2023-09-25 |
|
| Status: | Confirmed |
| Project: | MariaDB Server |
| Component/s: | Data Definition - Alter Table |
| Affects Version/s: | 10.0, 10.1, 10.2, 10.3, 10.4 |
| Fix Version/s: | 10.4 |
| Type: | Bug | Priority: | Major |
| Reporter: | Daniel Black | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||||||
| Description |
|
expected results: A table with a unique key. holyfoot says in |
| Comments |
| Comment by Sergei Golubchik [ 2015-07-16 ] | ||||||||||||||||||
|
My expectation would be for a key to be created. That is, if this
succeeds, then this
must succeed too and the key should be created. But I think it's not a major issue. And this behavior is pretty difficult to achieve in the current implementation. So, we consider fixing this bug, but not in the next few releases. | ||||||||||||||||||
| Comment by Alice Sherepa [ 2019-11-29 ] | ||||||||||||||||||
|
from
| ||||||||||||||||||
| Comment by Manuel Arostegui [ 2019-11-29 ] | ||||||||||||||||||
|
Any ETA on this bug getting fixed? | ||||||||||||||||||
| Comment by Manuel Arostegui [ 2020-05-04 ] | ||||||||||||||||||
|
Any progress on this? | ||||||||||||||||||
| Comment by Daniel Black [ 2020-10-20 ] | ||||||||||||||||||
|
I've started to look at this. It seems this can be done during the parsing of the ALTER TABLE statement alone without looking at the table structure.. An ADD KEY/COLUMN/FOREIGN KEY/CONSTRAINT (intentionally leaving off PARTITIONS for now), IF NOT EXISTS id during parsing time needs to search through alter_info.drop_list for an element of the same name/type. When the mirror pair is found, the IF NOT EXISTS ddl_option can be cleared from the parsing structure of the ADD as its known that the condition is true without needing to examine the table structure. A DROP after an ADD, is syntactical odd (why would you drop something just added), because I think all DROPs are considered before ADDs. So this just needs do the above process is reverse. So for any DROP entry, find an ADD and clear the IF NOT EXISTS flag on it if there is one. An edge case that needs to be considered is the double ADD or double DROP. e.g. DROP KEY bob, ADD KEY bob(bob) ADD KEY IF NOT EXISTS bob(bob) cannot sanely drop the IF NOT EXISTS flag on the second key add. It could however drop the entire clause and push a note/warning like it currently does and eliminate the element from the parse structures. For COLUMNS, CHANGE/RENAME COLUMN maybe needs accounting for {{ rename column id to ed, drop column if exists ed}} seems to rename rather than drop. From 10.5 RENAME KEY needs to be accounted for. So I've started down this path. | ||||||||||||||||||
| Comment by Sergei Golubchik [ 2023-09-25 ] | ||||||||||||||||||
|
danblack, all IF [NOT] EXISTS in ALTER TABLE are processed in one function. Might be not to difficult to add a logic there like "if ADD KEY IF NOT EXISTS and the key exists but it's also present in the keys-to-drop list, then it's ok" |