[MDEV-32236] ALTER TABLE NOWAIT / WAIT can cause table statistics to be wrong Created: 2023-09-24 Updated: 2023-11-28 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | Data Definition - Alter Table |
| Affects Version/s: | 10.4 |
| Fix Version/s: | 10.4, 10.5, 10.6, 10.11, 11.0, 11.1, 11.2 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Michael Widenius | Assignee: | Oleksandr Byelkin |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
|
ALTER TABLE .. NOWAIT/WAIT is implemented by doing an implicit This is a unworkable solution because of the following problem:
At least for the persistent statistics tables the update will be silently ignored, which will result in totally wrong (for example in case of rename of columns or indexes) or stale statistics (in case of removing columns). For DBUG servers, there can be crashes because of lock errors that where not properly handled (as seen by Elena). Instead of implementing this with SET STATEMENT, the timeout settings should be done inside ALTER TABLE and ONLY be around the execution of the ALTER. The lock timeouts should be restored before any logging calls or calls to delete table statistics. |
| Comments |
| Comment by Oleksandr Byelkin [ 2023-09-29 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
with help of Serg and Elena guideline for fixing was formulated like this (should be moved in docs) WAIT/NOWAIT clause of the command should not affect system tables opened implicitly because of internals of the sever implementation (like statistic, routine descriptions, logs and privileges), but affect tables inherited from tables/functions listed in the command (like underlying tables of views, triggers, functions) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2023-10-10 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Here is the code which shows the problem: at the end the t2 table is deleted but statistics about it present. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2023-10-11 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Fixed test case which will work even with waiting for stat_tables
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2023-10-11 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
After talking to Serg, it should be implemented as handler calls table->file->extra(HA_EXTRA_SKIP_LOCKED) and table->file->extra_opt(HA_EXTRA_LOCK_WAIT, value). Remove TL_READ_SKIP_LOCKED and TL_WRITE_SKIP_LOCKED |