mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
374783c3d9
- Add `as <int_type>` to sequence creation options - int_type can be signed or unsigned integer types, including tinyint, smallint, mediumint, int and bigint - Limitation: when alter sequence as <new_int_type>, cannot have any other alter options in the same statement - Limitation: increment remains signed longlong, and the hidden constraint (cache_size x abs(increment) < longlong_max) stays for unsigned types. This means for bigint unsigned, neither abs(increment) nor (cache_size x abs(increment)) can be between longlong_max and ulonglong_max - Truncating maxvalue and minvalue from user input to the nearest max or min value of the type, plus or minus 1. When the truncation happens, a warning is emitted - Information schema table for sequences
256 lines
6.4 KiB
Text
256 lines
6.4 KiB
Text
--source include/have_sequence.inc
|
|
--source include/have_innodb.inc
|
|
|
|
drop table if exists t1;
|
|
|
|
--echo #
|
|
--echo # Test setval function
|
|
--echo #
|
|
|
|
--disable_ps2_protocol
|
|
CREATE SEQUENCE t1 cache 10 engine=myisam;
|
|
select next_not_cached_value,cycle_count from t1;
|
|
do setval(t1,10);
|
|
select next_not_cached_value,cycle_count from t1;
|
|
select next value for t1;
|
|
do setval(t1,12,1);
|
|
select next_not_cached_value,cycle_count from t1;
|
|
select next value for t1;
|
|
do setval(t1,15,0);
|
|
select next_not_cached_value,cycle_count from t1;
|
|
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;
|
|
select next_not_cached_value,cycle_count from t1;
|
|
do setval(t1,2000,0);
|
|
select next value for t1;
|
|
select next_not_cached_value,cycle_count from t1;
|
|
# Set smaller value
|
|
select setval(t1,1000,0);
|
|
select next value for t1;
|
|
select setval(t1,1000,TRUE);
|
|
select next value for t1;
|
|
select next_not_cached_value,cycle_count from t1;
|
|
select setval(t1,2002,0);
|
|
select next value for t1;
|
|
select setval(t1,2010,0);
|
|
select next value for t1;
|
|
select next_not_cached_value,cycle_count from t1;
|
|
drop sequence t1;
|
|
|
|
--echo #
|
|
--echo # Testing with cycle
|
|
--echo #
|
|
|
|
CREATE SEQUENCE t1 cache=10 maxvalue=100 cycle engine=innodb;
|
|
select next_not_cached_value,cycle_count from t1;
|
|
select setval(t1,100,0);
|
|
select next_not_cached_value,cycle_count from t1;
|
|
select next value for t1;
|
|
select next_not_cached_value,cycle_count from t1;
|
|
select setval(t1,100,0);
|
|
select next_not_cached_value,cycle_count from t1;
|
|
select next value for t1;
|
|
select next_not_cached_value,cycle_count from t1;
|
|
select next value for t1;
|
|
select setval(t1,100,0,1);
|
|
select next_not_cached_value,cycle_count from t1;
|
|
select next value for t1;
|
|
select setval(t1,100,1,2);
|
|
select next_not_cached_value,cycle_count from t1;
|
|
select next value for t1;
|
|
select setval(t1,100,0,3);
|
|
select next_not_cached_value,cycle_count from t1;
|
|
select next value for t1;
|
|
drop sequence t1;
|
|
|
|
--echo #
|
|
--echo # Testing extreme values
|
|
--echo #
|
|
|
|
CREATE SEQUENCE t1 cache=10 maxvalue=100 engine=innodb;
|
|
select next_not_cached_value,cycle_count from t1;
|
|
select setval(t1,200);
|
|
select next_not_cached_value,cycle_count from t1;
|
|
--error ER_SEQUENCE_RUN_OUT
|
|
select next value for t1;
|
|
drop sequence t1;
|
|
|
|
CREATE SEQUENCE t1 cache=10 maxvalue=100 cycle engine=innodb;
|
|
select next_not_cached_value,cycle_count from t1;
|
|
select setval(t1,200);
|
|
select next_not_cached_value,cycle_count from t1;
|
|
select next value for t1;
|
|
drop sequence t1;
|
|
|
|
CREATE SEQUENCE t1 cache=10 maxvalue=0 increment=-10;
|
|
select setval(t1,-10);
|
|
select next_not_cached_value,cycle_count from t1;
|
|
select next value for t1;
|
|
select setval(t1,-15);
|
|
select next_not_cached_value,cycle_count from t1;
|
|
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);
|
|
select next_not_cached_value,cycle_count from t1;
|
|
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;
|
|
select next_not_cached_value,cycle_count from t1;
|
|
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;
|
|
|
|
|
|
--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
|
|
|
|
--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
|
|
|
|
--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
|