2017-05-08 01:44:55 +02:00
|
|
|
--source include/have_sequence.inc
|
|
|
|
--source include/have_innodb.inc
|
|
|
|
|
|
|
|
drop table if exists t1;
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # Test setval function
|
|
|
|
--echo #
|
|
|
|
|
2023-05-31 06:57:45 +02:00
|
|
|
--disable_ps2_protocol
|
2017-05-08 01:44:55 +02:00
|
|
|
CREATE SEQUENCE t1 cache 10 engine=myisam;
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
do setval(t1,10);
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select next value for t1;
|
|
|
|
do setval(t1,12,1);
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select next value for t1;
|
|
|
|
do setval(t1,15,0);
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select next value for t1;
|
|
|
|
select setval(t1,16,0);
|
|
|
|
select next value for t1;
|
|
|
|
do setval(t1,1000,0);
|
|
|
|
select next value for t1;
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
do setval(t1,2000,0);
|
|
|
|
select next value for t1;
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
# Set smaller value
|
|
|
|
select setval(t1,1000,0);
|
|
|
|
select next value for t1;
|
|
|
|
select setval(t1,1000,TRUE);
|
|
|
|
select next value for t1;
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select setval(t1,2002,0);
|
|
|
|
select next value for t1;
|
|
|
|
select setval(t1,2010,0);
|
|
|
|
select next value for t1;
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
drop sequence t1;
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # Testing with cycle
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
CREATE SEQUENCE t1 cache=10 maxvalue=100 cycle engine=innodb;
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select setval(t1,100,0);
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select next value for t1;
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select setval(t1,100,0);
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select next value for t1;
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select next value for t1;
|
|
|
|
select setval(t1,100,0,1);
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select next value for t1;
|
|
|
|
select setval(t1,100,1,2);
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select next value for t1;
|
|
|
|
select setval(t1,100,0,3);
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select next value for t1;
|
|
|
|
drop sequence t1;
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # Testing extreme values
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
CREATE SEQUENCE t1 cache=10 maxvalue=100 engine=innodb;
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select setval(t1,200);
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
--error ER_SEQUENCE_RUN_OUT
|
|
|
|
select next value for t1;
|
|
|
|
drop sequence t1;
|
|
|
|
|
|
|
|
CREATE SEQUENCE t1 cache=10 maxvalue=100 cycle engine=innodb;
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select setval(t1,200);
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select next value for t1;
|
|
|
|
drop sequence t1;
|
|
|
|
|
|
|
|
CREATE SEQUENCE t1 cache=10 maxvalue=0 increment=-10;
|
|
|
|
select setval(t1,-10);
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select next value for t1;
|
|
|
|
select setval(t1,-15);
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select next value for t1;
|
|
|
|
select setval(t1,-500,FALSE);
|
|
|
|
select next value for t1;
|
|
|
|
select next value for t1;
|
|
|
|
select setval(t1,-525,0);
|
|
|
|
select next value for t1;
|
|
|
|
select next value for t1;
|
|
|
|
drop sequence t1;
|
|
|
|
|
|
|
|
CREATE SEQUENCE t1 cache=10 maxvalue=0 increment=-10;
|
|
|
|
select setval(t1,-10,0);
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
select next value for t1;
|
|
|
|
drop sequence t1;
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # Other testing
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
CREATE SEQUENCE t1;
|
|
|
|
select setval(t1,10,0),setval(t1,15,1),setval(t1,5,1);
|
|
|
|
select next value for t1;
|
2017-06-03 15:08:23 +02:00
|
|
|
select next_not_cached_value,cycle_count from t1;
|
2017-05-08 01:44:55 +02:00
|
|
|
explain extended select setval(t1,100),setval(t1,100,TRUE),setval(t1,100,FALSE,50);
|
|
|
|
drop sequence t1;
|
|
|
|
|
|
|
|
#
|
|
|
|
# Some error testing
|
|
|
|
#
|
|
|
|
|
|
|
|
create table t1 (a int);
|
|
|
|
--error ER_NOT_SEQUENCE
|
|
|
|
select setval(t1,10);
|
|
|
|
drop table t1;
|
2017-05-20 14:29:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # MDEV-12854 Synchronize CREATE..SELECT data type and result set metadata data type for INT functions
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
--enable_metadata
|
|
|
|
--disable_ps_protocol
|
|
|
|
CREATE SEQUENCE s1;
|
|
|
|
SELECT SETVAL(s1,10);
|
|
|
|
DROP SEQUENCE s1;
|
|
|
|
--enable_ps_protocol
|
|
|
|
--disable_metadata
|
2018-04-25 21:32:47 +02:00
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # MDEV-15732: Assertion `next_free_value % real_increment == offset &&
|
|
|
|
--echo # next_free_value >= reserved_until' failed in
|
|
|
|
--echo # sequence_definition::adjust_values upon SETVAL for sequence with
|
|
|
|
--echo # INCREMENT 0
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
CREATE SEQUENCE s INCREMENT 0;
|
|
|
|
SELECT NEXTVAL(s);
|
|
|
|
SELECT SETVAL(s, 10);
|
|
|
|
|
|
|
|
# Cleanup
|
|
|
|
DROP SEQUENCE s;
|
|
|
|
|
|
|
|
--echo # End of 10.3 tests
|
2024-01-04 02:12:50 +01:00
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # MDEV-28152 Features for sequence
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
# out of bounds for the type: returns NULL
|
|
|
|
create sequence s;
|
|
|
|
select setval(s, 12345678901234567890);
|
|
|
|
select nextval(s);
|
|
|
|
drop sequence s;
|
|
|
|
|
|
|
|
create sequence s increment -1;
|
|
|
|
select setval(s, 12345678901234567890);
|
|
|
|
select nextval(s);
|
|
|
|
drop sequence s;
|
|
|
|
|
|
|
|
create sequence s as smallint;
|
|
|
|
select setval(s, 55555);
|
|
|
|
select setval(s, -55555);
|
|
|
|
select nextval(s);
|
|
|
|
drop sequence s;
|
|
|
|
|
|
|
|
create sequence s as smallint increment -1;
|
|
|
|
select setval(s, 55555);
|
|
|
|
select setval(s, -55555);
|
|
|
|
select nextval(s);
|
|
|
|
drop sequence s;
|
|
|
|
|
|
|
|
create sequence s as bigint unsigned;
|
|
|
|
select setval(s, -123);
|
|
|
|
select nextval(s);
|
|
|
|
drop sequence s;
|
|
|
|
|
|
|
|
create sequence s as bigint unsigned increment -1;
|
|
|
|
select setval(s, -123);
|
|
|
|
select nextval(s);
|
|
|
|
drop sequence s;
|
|
|
|
|
|
|
|
# large setval values for bigint unsigned
|
|
|
|
create sequence s as bigint unsigned;
|
|
|
|
select setval(s, -123);
|
|
|
|
select setval(s, 0);
|
|
|
|
select nextval(s);
|
|
|
|
select setval(s, 12345678901234567890);
|
|
|
|
select nextval(s);
|
|
|
|
select setval(s, 12345678901234567890);
|
|
|
|
select nextval(s);
|
|
|
|
select setval(s, 18446744073709551614, 0);
|
|
|
|
select nextval(s);
|
|
|
|
--error ER_SEQUENCE_RUN_OUT
|
|
|
|
select nextval(s);
|
|
|
|
--error ER_SEQUENCE_RUN_OUT
|
|
|
|
select setval(s, 12345678901234567890, 0, 1);
|
|
|
|
alter sequence s cycle;
|
|
|
|
select setval(s, 12345678901234567890, 0, 1);
|
|
|
|
select nextval(s);
|
|
|
|
drop sequence s;
|
|
|
|
|
|
|
|
# extreme setval values for bigint unsigned
|
|
|
|
create sequence s as bigint unsigned;
|
|
|
|
--error ER_PARSE_ERROR
|
|
|
|
select setval(s, 18446744073709551616);
|
|
|
|
select setval(s, 18446744073709551615);
|
|
|
|
--error ER_SEQUENCE_RUN_OUT
|
|
|
|
select nextval(s);
|
|
|
|
drop sequence s;
|
|
|
|
|
|
|
|
create sequence s as bigint unsigned;
|
|
|
|
select setval(s, 18446744073709551615, 0);
|
|
|
|
--error ER_SEQUENCE_RUN_OUT
|
|
|
|
select nextval(s);
|
|
|
|
drop sequence s;
|
|
|
|
|
|
|
|
create sequence s as bigint unsigned cycle;
|
|
|
|
select setval(s, 18446744073709551615);
|
|
|
|
select nextval(s);
|
|
|
|
drop sequence s;
|
|
|
|
|
|
|
|
create sequence s as bigint unsigned cycle;
|
|
|
|
select setval(s, 18446744073709551615, 0);
|
|
|
|
select nextval(s);
|
|
|
|
drop sequence s;
|
|
|
|
|
|
|
|
# a small range for bigint unsigned
|
|
|
|
create sequence s as bigint unsigned minvalue 123 maxvalue 456;
|
|
|
|
select setval(s, 100);
|
|
|
|
select nextval(s);
|
|
|
|
select setval(s, 500);
|
|
|
|
--error ER_SEQUENCE_RUN_OUT
|
|
|
|
select nextval(s);
|
|
|
|
drop sequence s;
|
|
|
|
|
|
|
|
create sequence s as smallint;
|
|
|
|
select setval(s, 32767);
|
|
|
|
--error ER_SEQUENCE_RUN_OUT
|
|
|
|
select nextval(s);
|
|
|
|
drop sequence s;
|
|
|
|
--enable_ps2_protocol
|
|
|
|
|
|
|
|
--echo # End of 11.4 tests
|