[MDEV-21842] auto_increment does not increment with compound primary key on partitioned table Created: 2020-02-28 Updated: 2021-03-30 Resolved: 2020-11-24 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data Manipulation - Insert, Partitioning |
| Affects Version/s: | 10.3.21, 10.3.22, 10.4.12, 10.3, 10.4 |
| Fix Version/s: | 10.3.28, 10.4.18, 10.5.9 |
| Type: | Bug | Priority: | Blocker |
| Reporter: | Martijn Smidt | Assignee: | Alexey Botchkov |
| Resolution: | Fixed | Votes: | 5 |
| Labels: | innodb, regression-10.3 | ||
| Environment: |
Ubuntu 18.04.2 |
||
| Issue Links: |
|
||||||||||||
| Description |
|
When a table contains a compound key where the second column is used in the partitioning rule the auto_increment gives out duplicate numbers with concurrent queries. Steps to reproduce: table defenition:
preparation:
reproduce:
result:
|
| Comments |
| Comment by Alice Sherepa [ 2020-03-02 ] | |||||||||||||||||||||||||||
|
Thanks a lot! Reproduced as described on 10.3-10.5, no failure on 10.2:
| |||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2020-07-16 ] | |||||||||||||||||||||||||||
|
I do not think that anything changed in this area in InnoDB between 10.2 and 10.3. The persistent AUTO_INCREMENT ( But, I do see many changes to partitioning, in particular:
includes Adding support for auto_increment in the partition engine, which would be my first suspect. I hope that Kentoku can debug this. | |||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2020-10-17 ] | |||||||||||||||||||||||||||
|
The buggy behavior reported in the following blog post (in Japanese) seems to relate to the present bug. https://techblog.gmo-ap.jp/2020/05/26/mariadb_auto_increment/ | |||||||||||||||||||||||||||
| Comment by Alexander Keremidarski [ 2020-10-26 ] | |||||||||||||||||||||||||||
|
The bug happens with concurrent INSERTs so MyISAM and Aria are "immune", but RocksDB is affected too hence the bug seems to be with partitioning engine and not InnoDB specific. | |||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2020-10-28 ] | |||||||||||||||||||||||||||
|
Reproduced in mariadb-10.3.19 but not in mariadb-10.3.18. The bug seems to be introduced by c9cba59749e1b5a39a9e3a0a5b8bd762507245f9. I will look into this further. | |||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2020-10-30 ] | |||||||||||||||||||||||||||
|
In my understanding, `part_share->next_auto_inc_val` is literally shared stuff, and thus we should not decrement it without careful synchronization. The current implementation of restore_auto_increment() seems to do a sort of blind write. An easy way to fixing the bug without reoccurring Another possible fix would be to decrement `next_insert_id` only and calculate `first_val`, which determines auto_inc_interval_for_cur_row.minimum(), based on reserved values as InnoDB handler does. Currently, the calculation of `first_val` is based on next_auto_inc_val. | |||||||||||||||||||||||||||
| Comment by Alexander Keremidarski [ 2020-10-30 ] | |||||||||||||||||||||||||||
|
Hello, | |||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2020-10-30 ] | |||||||||||||||||||||||||||
|
Yes, `waste of auto-increment counter` refers to the gap On the other hand, I agree that causing gaps in the auto-increment column is trivial issue compared with generating duplicated values. test
result
(sorry for repeated edit) | |||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2020-10-30 ] | |||||||||||||||||||||||||||
|
I've created a draft pull request, for the ease of discussion, along with the former easy way. https://github.com/MariaDB/server/pull/1692 | |||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2020-10-31 ] | |||||||||||||||||||||||||||
|
I think I could finally find a plausible way to fix the present bug after much deliberation. This bug is introduced by 9cba59749e1b5a39a9e3a0a5b8bd762507245f9, which fixed | |||||||||||||||||||||||||||
| Comment by Alexey Botchkov [ 2020-11-24 ] | |||||||||||||||||||||||||||
|
https://github.com/MariaDB/server/commit/75e7132fca1c4634d4aa8d18d386c55932a5e1b6 |