[MDEV-24818] Concurrent use of InnoDB table is impossible until the first transaction is finished Created: 2021-02-09 Updated: 2023-09-26 Resolved: 2021-03-16 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Storage Engine - InnoDB |
| Affects Version/s: | 10.6 |
| Fix Version/s: | 10.6.0 |
| Type: | Bug | Priority: | Blocker |
| Reporter: | Elena Stepanova | Assignee: | Marko Mäkelä |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | regression | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
After the changes made in the scope of
The second INSERT, which in earlier versions is instant, will now hang until the first connection finishes the transaction (or will time out if it doesn't happen within the timeout interval). While the locking change was clearly intentional and explicitly mentioned at least in the commit comment to The scope of On the other hand, "create/empty a table and start using it concurrently" scenario above is as basic as it gets; and the loss can be not only in performance (in case the first transaction is reasonably fast and other ones are just delayed), but in more extreme cases, when the first transaction remains open for a long time, it can render the application non-functional – everything else will be failing with timeouts. The problem can be happening anywhere within an application, both in business logic and deep in maintenance/service jobs. It will represent as seemingly sporadic not reproducible weird delays and timeouts and will be nearly impossible to investigate – and even if the cause happens to be revealed, changing this logic in all existing applications won't be realistic. I don't think that even a possibility to "opt-out" the new behavior would be sufficient, as users are generally not aware of details of the internal implementation of applications they use, as well as database admins if, for example, they maintain a shared hosting. |
| Comments |
| Comment by Marko Mäkelä [ 2021-02-19 ] | ||||||||||||||
|
I would propose new syntax to make the
This would have the following consequences:
| ||||||||||||||
| Comment by Rick Pizzi [ 2021-02-19 ] | ||||||||||||||
|
| ||||||||||||||
| Comment by Marko Mäkelä [ 2021-02-24 ] | ||||||||||||||
|
I agree that my original proposed syntax is somewhat weird, because transactions are expected to be kind of atomic. Maybe we could make it explicitly refer to the fact that only full and no partial rollback is supported:
Like my original proposal, also this one would reuse existing reserved words. | ||||||||||||||
| Comment by Rick Pizzi [ 2021-02-25 ] | ||||||||||||||
|
What is the problem with adding a new dedicated word?
| ||||||||||||||
| Comment by Sergei Golubchik [ 2021-02-26 ] | ||||||||||||||
|
For the purpose of this bug fix and extra optimizations aside, it would be enough to enable the new optimization only in auto-commit more or under LOCK TABLES. | ||||||||||||||
| Comment by Sergei Golubchik [ 2021-03-02 ] | ||||||||||||||
|
The optimization is moved to MDEV-25036 | ||||||||||||||
| Comment by Marko Mäkelä [ 2021-03-03 ] | ||||||||||||||
|
The following patch would make this feature ‘opt-in’:
That is, explicit
would be required to enable the table-level locking and undo logging of the INSERT statement. The settings are used by the scripts that are generated by mysqldump. We could extend this approach further to allow subsequent INSERT statements in the same transaction to suppress row-level undo logging in the same transaction. That should make loads of mysqldump fast out of the box. I do not think that we really need to detect LOCK TABLES to enable this logic, because unique_checks=0 should never be set unless one really is sure that no duplicate keys are possible. (It allows the InnoDB change buffer to corrupt data when the change buffer merge of a duplicate key eventually occurs.) | ||||||||||||||
| Comment by Marko Mäkelä [ 2021-03-12 ] | ||||||||||||||
|
I found out that the sysbench prepare scripts are usually running in autocommit mode without transaction boundaries. The following would enable the slightly faster insert (and remove the need of subsequent purge of INSERT history that was introduced in
|