[MDEV-17030] Reset Sequence doesn't reset the value the second time. Created: 2018-08-22 Updated: 2020-08-25 Resolved: 2018-08-22 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Sequences |
| Affects Version/s: | 10.2.14 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Critical |
| Reporter: | Pramod Mahto | Assignee: | Ian Gilfillan |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Description |
|
Reset Sequence doesn't reset the value the second time.
|
| Comments |
| Comment by Alice Sherepa [ 2018-08-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
from documentation https://mariadb.com/kb/en/library/setval/ The result returned by SETVAL() is next_value or NULL if the given next_value and round is smaller than the current value. SETVAL() will not set the SEQUENCE value to a something that is less than its current value. This is needed to ensure that SETVAL() is replication safe. If you want to set the SEQUENCE to a smaller number use ALTER SEQUENCE." I guess it is not very clear documented about round option and no examples there, but to return the correct results, round option should be used:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Widenius [ 2018-08-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
This is as expected and documented: "The result returned by SETVAL() is next_value or NULL if the given next_value and round is smaller than the current value." The problem here is that the second setval() command in the example is same as: As the sequence has already done one cycle, it's internal cycle_count (ie round) is 1 and this is what setval() fails. Another option to change the sequence that 'always' work independent of the current sequence value is to use ALTER SEQUENCE. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ian Gilfillan [ 2018-08-28 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The documentation needed expanding here, as there were no examples with round. I've added an example and clarification to make this clearer. |