Reset Sequence doesn't reset the value the second time.
|
Test case:-
|
|
MariaDB [test1]> set sql_mode=ORACLE;
|
Query OK, 0 rows affected (0.001 sec)
|
|
MariaDB [test1]> CREATE or replace SEQUENCE "entkaisgc_sg" start with 1 minvalue 1 maxvalue 9999999999999999 increment by 1 cache 20 cycle ;
|
Query OK, 0 rows affected (0.022 sec)
|
|
MariaDB [test1]> select entkaisgc_sg.nextval;
|
+----------------------+
|
| entkaisgc_sg.nextval |
|
+----------------------+
|
| 1 |
|
+----------------------+
|
1 row in set (0.012 sec)
|
|
MariaDB [test1]> select entkaisgc_sg.nextval;
|
+----------------------+
|
| entkaisgc_sg.nextval |
|
+----------------------+
|
| 2 |
|
+----------------------+
|
1 row in set (0.001 sec)
|
|
MariaDB [test1]> SELECT setval(entkaisgc_sg,9999999999999999);
|
+---------------------------------------+
|
| setval(entkaisgc_sg,9999999999999999) |
|
+---------------------------------------+
|
| 9999999999999999 |
|
+---------------------------------------+
|
1 row in set (0.001 sec)
|
|
MariaDB [test1]> select entkaisgc_sg.nextval;
|
+----------------------+
|
| entkaisgc_sg.nextval |
|
+----------------------+
|
| 1 |
|
+----------------------+
|
1 row in set (0.001 sec)
|
|
MariaDB [test1]> select entkaisgc_sg.nextval;
|
+----------------------+
|
| entkaisgc_sg.nextval |
|
+----------------------+
|
| 2 |
|
+----------------------+
|
1 row in set (0.000 sec)
|
|
MariaDB [test1]> SELECT setval(entkaisgc_sg,9999999999999999);
|
+---------------------------------------+
|
| setval(entkaisgc_sg,9999999999999999) |
|
+---------------------------------------+
|
| NULL |
|
+---------------------------------------+
|
1 row in set (0.000 sec)
|
|
MariaDB [test1]> select entkaisgc_sg.nextval;
|
+----------------------+
|
| entkaisgc_sg.nextval |
|
+----------------------+
|
| 3 |
|
+----------------------+
|
1 row in set (0.001 sec)
|
|
|
{"report":{"fcp":838.8000000119209,"ttfb":263.40000000596046,"pageVisibility":"visible","entityId":69302,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"3f1d1ebd-f373-453c-a39a-2483ee3477c1","navigationType":0,"readyForUser":917.6999999880791,"redirectCount":0,"resourceLoadedEnd":577.3000000119209,"resourceLoadedStart":268.59999999403954,"resourceTiming":[{"duration":13.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":268.59999999403954,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":268.59999999403954,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":282.09999999403954,"responseStart":0,"secureConnectionStart":0},{"duration":13.699999988079071,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":268.80000001192093,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":268.80000001192093,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":282.5,"responseStart":0,"secureConnectionStart":0},{"duration":173.09999999403954,"initiatorType":"script","name":"https://jira.mariadb.org/s/e9b27a47da5fb0f74a35acd57e9847fb-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":268.90000000596046,"connectEnd":268.90000000596046,"connectStart":268.90000000596046,"domainLookupEnd":268.90000000596046,"domainLookupStart":268.90000000596046,"fetchStart":268.90000000596046,"redirectEnd":0,"redirectStart":0,"requestStart":287.19999998807907,"responseEnd":442,"responseStart":311.80000001192093,"secureConnectionStart":268.90000000596046},{"duration":308.10000002384186,"initiatorType":"script","name":"https://jira.mariadb.org/s/c32eb0da7ad9831253f8397e6cc26afd-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":269.19999998807907,"connectEnd":269.19999998807907,"connectStart":269.19999998807907,"domainLookupEnd":269.19999998807907,"domainLookupStart":269.19999998807907,"fetchStart":269.19999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":287.59999999403954,"responseEnd":577.3000000119209,"responseStart":312.30000001192093,"secureConnectionStart":269.19999998807907},{"duration":51.39999997615814,"initiatorType":"script","name":"https://jira.mariadb.org/s/bc0bcb146314416123c992714ee00ff7-CDN/lu2bv2/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":269.30000001192093,"connectEnd":269.30000001192093,"connectStart":269.30000001192093,"domainLookupEnd":269.30000001192093,"domainLookupStart":269.30000001192093,"fetchStart":269.30000001192093,"redirectEnd":0,"redirectStart":0,"requestStart":288.69999998807907,"responseEnd":320.69999998807907,"responseStart":318.69999998807907,"secureConnectionStart":269.30000001192093},{"duration":52.69999998807907,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":269.5,"connectEnd":269.5,"connectStart":269.5,"domainLookupEnd":269.5,"domainLookupStart":269.5,"fetchStart":269.5,"redirectEnd":0,"redirectStart":0,"requestStart":289.69999998807907,"responseEnd":322.19999998807907,"responseStart":319.69999998807907,"secureConnectionStart":269.5},{"duration":53.80000001192093,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":269.59999999403954,"connectEnd":269.59999999403954,"connectStart":269.59999999403954,"domainLookupEnd":269.59999999403954,"domainLookupStart":269.59999999403954,"fetchStart":269.59999999403954,"redirectEnd":0,"redirectStart":0,"requestStart":292.09999999403954,"responseEnd":323.40000000596046,"responseStart":320.80000001192093,"secureConnectionStart":269.59999999403954},{"duration":20.19999998807907,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bv2/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":269.90000000596046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":269.90000000596046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":290.09999999403954,"responseStart":0,"secureConnectionStart":0},{"duration":113.5,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":270,"connectEnd":270,"connectStart":270,"domainLookupEnd":270,"domainLookupStart":270,"fetchStart":270,"redirectEnd":0,"redirectStart":0,"requestStart":295.30000001192093,"responseEnd":383.5,"responseStart":381.90000000596046,"secureConnectionStart":270},{"duration":21.100000023841858,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bv2/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":270.19999998807907,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":270.19999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":291.30000001192093,"responseStart":0,"secureConnectionStart":0},{"duration":53.19999998807907,"initiatorType":"script","name":"https://jira.mariadb.org/s/719848dd97ebe0663199f49a3936487a-CDN/lu2bv2/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":270.40000000596046,"connectEnd":270.40000000596046,"connectStart":270.40000000596046,"domainLookupEnd":270.40000000596046,"domainLookupStart":270.40000000596046,"fetchStart":270.40000000596046,"redirectEnd":0,"redirectStart":0,"requestStart":296,"responseEnd":323.59999999403954,"responseStart":321.5,"secureConnectionStart":270.40000000596046},{"duration":253.30000001192093,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":271.09999999403954,"connectEnd":271.09999999403954,"connectStart":271.09999999403954,"domainLookupEnd":271.09999999403954,"domainLookupStart":271.09999999403954,"fetchStart":271.09999999403954,"redirectEnd":0,"redirectStart":0,"requestStart":306.69999998807907,"responseEnd":524.4000000059605,"responseStart":519.1999999880791,"secureConnectionStart":271.09999999403954},{"duration":249.19999998807907,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":275.90000000596046,"connectEnd":275.90000000596046,"connectStart":275.90000000596046,"domainLookupEnd":275.90000000596046,"domainLookupStart":275.90000000596046,"fetchStart":275.90000000596046,"redirectEnd":0,"redirectStart":0,"requestStart":324.09999999403954,"responseEnd":525.0999999940395,"responseStart":522.1999999880791,"secureConnectionStart":275.90000000596046},{"duration":112.19999998807907,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":581.8000000119209,"connectEnd":581.8000000119209,"connectStart":581.8000000119209,"domainLookupEnd":581.8000000119209,"domainLookupStart":581.8000000119209,"fetchStart":581.8000000119209,"redirectEnd":0,"redirectStart":0,"requestStart":664.8000000119209,"responseEnd":694,"responseStart":693.4000000059605,"secureConnectionStart":581.8000000119209}],"fetchStart":0,"domainLookupStart":37,"domainLookupEnd":43,"connectStart":43,"connectEnd":62,"secureConnectionStart":52,"requestStart":62,"responseStart":263,"responseEnd":269,"domLoading":266,"domInteractive":1021,"domContentLoadedEventStart":1021,"domContentLoadedEventEnd":1081,"domComplete":1679,"loadEventStart":1679,"loadEventEnd":1679,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":992.0999999940395},{"name":"bigPipe.sidebar-id.end","time":992.9000000059605},{"name":"bigPipe.activity-panel-pipe-id.start","time":993},{"name":"bigPipe.activity-panel-pipe-id.end","time":996.0999999940395},{"name":"activityTabFullyLoaded","time":1097.5}],"measures":[],"correlationId":"ef947eb736276b","effectiveType":"4g","downlink":9.7,"rtt":0,"serverDuration":102,"dbReadsTimeInMs":12,"dbConnsTimeInMs":21,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
from documentation https://mariadb.com/kb/en/library/setval/
"For SEQUENCE tables defined with CYCLE one should use both next_value and round to define the next value. In this case the current sequence value is defined to be round, next_value.
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:
MariaDB [test]> CREATE or replace SEQUENCE "s" start with 1 minvalue 1 maxvalue 99 increment by 1 cache 20 cycle;
Query OK, 0 rows affected (0.030 sec)
MariaDB [test]> select setval(s,99,true);
+-------------------+
| setval(s,99,true) |
+-------------------+
| 99 |
+-------------------+
1 row in set (0.001 sec)
MariaDB [test]> select * from s;
+-----------------------+---------------+---------------+-------------+-----------+------------+--------------+-------------+
| next_not_cached_value | minimum_value | maximum_value | start_value | increment | cache_size | cycle_option | cycle_count |
+-----------------------+---------------+---------------+-------------+-----------+------------+--------------+-------------+
| 100 | 1 | 99 | 1 | 1 | 20 | 1 | 0 |
+-----------------------+---------------+---------------+-------------+-----------+------------+--------------+-------------+
1 row in set (0.000 sec)
MariaDB [test]> select s.nextval;
+-----------+
| s.nextval |
+-----------+
| 1 |
+-----------+
1 row in set (0.000 sec)
MariaDB [test]> select * from s; ##cycle_count=1
+-----------------------+---------------+---------------+-------------+-----------+------------+--------------+-------------+
| next_not_cached_value | minimum_value | maximum_value | start_value | increment | cache_size | cycle_option | cycle_count |
+-----------------------+---------------+---------------+-------------+-----------+------------+--------------+-------------+
| 21 | 1 | 99 | 1 | 1 | 20 | 1 | 1 |
+-----------------------+---------------+---------------+-------------+-----------+------------+--------------+-------------+
1 row in set (0.000 sec)
MariaDB [test]> select setval(s,99,true,1);
+---------------------+
| setval(s,99,true,1) |
+---------------------+
| 99 |
+---------------------+
1 row in set (0.000 sec)
MariaDB [test]> select * from s;
+-----------------------+---------------+---------------+-------------+-----------+------------+--------------+-------------+
| next_not_cached_value | minimum_value | maximum_value | start_value | increment | cache_size | cycle_option | cycle_count |
+-----------------------+---------------+---------------+-------------+-----------+------------+--------------+-------------+
| 100 | 1 | 99 | 1 | 1 | 20 | 1 | 1 |
+-----------------------+---------------+---------------+-------------+-----------+------------+--------------+-------------+
1 row in set (0.000 sec)
MariaDB [test]> select s.nextval;
+-----------+
| s.nextval |
+-----------+
| 1 |
+-----------+
1 row in set (0.000 sec)
MariaDB [test]> select * from s;
+-----------------------+---------------+---------------+-------------+-----------+------------+--------------+-------------+
| next_not_cached_value | minimum_value | maximum_value | start_value | increment | cache_size | cycle_option | cycle_count |
+-----------------------+---------------+---------------+-------------+-----------+------------+--------------+-------------+
| 21 | 1 | 99 | 1 | 1 | 20 | 1 | 2 |
+-----------------------+---------------+---------------+-------------+-----------+------------+--------------+-------------+
1 row in set (0.000 sec)
MariaDB [test]> select setval(s,99,true,1);
+---------------------+
| setval(s,99,true,1) |
+---------------------+
| NULL |
+---------------------+
1 row in set (0.000 sec)
MariaDB [test]> select setval(s,99,true,2);
+---------------------+
| setval(s,99,true,2) |
+---------------------+
| 99 |
+---------------------+
1 row in set (0.000 sec)