[MDEV-29588] Swap atomically a view in place of an altered table Created: 2022-09-21 Updated: 2024-01-19 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 10.11 |
| Fix Version/s: | 10.11 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Michael Widenius | Assignee: | Oleksandr Byelkin |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
|
In some scenarios it there is a need to add/drop columns for a table and replace it with a view to allow old applications to work unchanged until they are updated. As MariaDB does not have transactional DDL, we have to do it in some other way. The following 'almost' works:
The task is to allow the above rename table to succeed. Another possible solution to do this nicely (from the user's point of view) is to extend alter table: alter table t1 add column (b int) rename as t1 replace with v1; Where the 'replace with v1 means: rename v1 to t1' |
| Comments |
| Comment by Oleksandr Byelkin [ 2024-01-15 ] | ||||||||||||||||
|
actually this shows better the first problem:
it breaks here:
| ||||||||||||||||
| Comment by Oleksandr Byelkin [ 2024-01-15 ] | ||||||||||||||||
|
i.e. we are trying to rename table under lock. IMHO it hange semantic of our lock:
or we should rewrite our admin operation so it will not be sequence of action but renaming several tables will be looked as one action? | ||||||||||||||||
| Comment by Michael Widenius [ 2024-01-19 ] | ||||||||||||||||
|
Note that this works on a locked table:
This transforms the lock from t1 to t2. We still have a problem with the original problem as v1 refers to t1. The correct query to solve is the following:
We cannot unfortunately use:
As then for a short time 't1' would not be locked and anyone trying to access it would get a table does not exist error. | ||||||||||||||||
| Comment by Sergei Golubchik [ 2024-01-19 ] | ||||||||||||||||
|
What about
this works without any table locks whatsoever |