Bug #116503 | duplicate-key error will hold gap lock when there are multi unique keys | ||
---|---|---|---|
Submitted: | 30 Oct 2024 6:55 | Modified: | 31 Oct 2024 14:11 |
Reporter: | Xiaolong Wang | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 8.0 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[30 Oct 2024 6:55]
Xiaolong Wang
[30 Oct 2024 10:14]
MySQL Verification Team
Hi Mr. Wang, Thank you for your bug report. We truly do not understand what do you mean by primary key not existing for some row in InnoDB ??? For each record or gap lock there is a corresponding primary key. If user does not define a primary key for InnoDB, InnoDB will create an invisible primary key. There can be no InnoDB table without a primary key. Can you clarify that ????
[30 Oct 2024 10:17]
MySQL Verification Team
Mr Wang, Gap locks are VERY much necessary for the INSERT operation, whenever a new row has to be inserted between two existing rows. Hence, gap locks are always necessary.
[31 Oct 2024 14:11]
Xiaolong Wang
Hi, Just like my first case shows, when INSERT (2,1), there is Duplicate entry error for `1`, and `2` does not exist in Primary Key. There are gap lock between Primary Key 1 to 5. However this gap lock does not match the document description: "If a duplicate-key error occurs, a shared lock on the duplicate index record is set." I totally understand gap locks are very much necessary, but in this special duplicate-key error case, why this gap lock is needed? Or in another words, if there is no gap lock in the above case, what's the impact? What kind of issue will it cause? Would you give an example?
[31 Oct 2024 14:18]
MySQL Verification Team
Hi Mr. Wang, This is all done in accordance with the current standards that are set for the transactional processing. You have two columns. For the first one, you want to insert a new row in the gap between values 1 and 5. However, after that lock is secured, you go to check for second column and there you find a duplicate. That is simply expected behaviour.
[31 Oct 2024 14:25]
MySQL Verification Team
Hi, One short additional comment ..... The burden of checking the errors in on the users side. In most cases, it is something that should be built into the application. Whenever a transaction is not in auto-commit mode, an error is returned the the application and the application is the one that is responsible for issuing the ROLLBACK command. That is why that command exists ..... Standard does not allow that engine itself issues a ROLLBACK, except in the cases like lock wait timeout, timeout on waiting on mutex, deadlocks and similar situations. Last, but not least, in auto-commit mode, there should be no lingering locks ...... Not a bug.