[MDEV-14088] Strange behavior with SEQUENCE Created: 2017-10-18 Updated: 2017-10-28 Resolved: 2017-10-28 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Sequences |
| Affects Version/s: | 10.3.1, 10.3.2 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Wagner Bianchi (Inactive) | Assignee: | Andrii Nikitin (Inactive) |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Environment: |
CentOS 7.2 |
||
| Description |
|
Folks, Checking the SEQUENCE feature while working with a new schema on MariaDB 10.3.1 and 2, I found the following situation what I think is a bug. I created a simple SEQUENCE, selected some times its NEXTVAL and then, I issued the command flush tables. Continuing with the tests, I selected the SEQUENCE's NEXTVAL again and for my surprise, the numeric sequence got broken for some reason. Below, the sequence of the facts:
Analysizng the results, it's clear that, if it has cached all the values until 1000, as 1001 is the next_not_cached_value, it's not OK to receive 1001 after 2 in case I flush tables; if I'm using on my application the S1.NEXTVAL instead of an AUTO_INCREMENT column, I will have a gap of many positions on my PK. Getting a new record into a table having the INSERT using another existing SEQUENCE, gave me the below after the FLUSH TABLES:
Thanks for checking, cheers! |
| Comments |
| Comment by Andrii Nikitin (Inactive) [ 2017-10-19 ] | ||||||||||||||||||||||||||||||||
|
Cache in Sequence is used to address potential contention for highly concurrent load. If you don't need to address such contention - consider using CACHE = NOCACHE clause in CREATE command as mentioned at https://mariadb.com/kb/en/library/create-sequence/ | ||||||||||||||||||||||||||||||||
| Comment by Wagner Bianchi (Inactive) [ 2017-10-19 ] | ||||||||||||||||||||||||||||||||
|
Andrii, The CACHE=NOCACHE wasn't possible to compile unless I made a mistake, but, I created the SEQUENCE on the following way:
And then, I made the same tests as before:
I'm seeing that the default value for the CACHE when omitted on the sequence creation syntax is 1000, shouldn't be 0? This problem with FLUSH TABLES, is it expected? Cheers guys, Bianchi | ||||||||||||||||||||||||||||||||
| Comment by Andrii Nikitin (Inactive) [ 2017-10-20 ] | ||||||||||||||||||||||||||||||||
|
Yes, default value of CACHE is intentional 1000, which means that 1000 requests to sequence object will not need any IO operation / locking. | ||||||||||||||||||||||||||||||||
| Comment by Andrii Nikitin (Inactive) [ 2017-10-20 ] | ||||||||||||||||||||||||||||||||
|
I've checked the syntax and it should be like this:
|