1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-28152 Features for sequences

- 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
This commit is contained in:
Yuchen Pei
2024-01-04 12:12:50 +11:00
parent eeba940311
commit 374783c3d9
34 changed files with 3472 additions and 264 deletions

View File

@@ -298,4 +298,191 @@ SELECT SETVAL (v,0);
UNLOCK TABLES;
DROP VIEW v;
--disable_ps2_protocol
--echo #
--echo # MDEV-28152 Features for sequence
--echo #
create or replace sequence t1 as tinyint unsigned minvalue 1 maxvalue 2;
show create sequence t1;
show create table t1;
select * from t1;
select next value for t1;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
create or replace sequence t1 as tinyint unsigned minvalue 1 maxvalue 2 cycle;
show create sequence t1;
show create table t1;
select * from t1;
select next value for t1;
select next value for t1;
select next value for t1;
--disable_ps_protocol
create or replace sequence t1 minvalue -23 maxvalue 99999 as tinyint;
--enable_ps_protocol
show create sequence t1;
show create table t1;
select * from t1;
select next value for t1;
select next value for t1;
select next value for t1;
#test previous value for bigint unsigned
create or replace sequence t1 as bigint unsigned start with 18446744073709551614;
select previous value for t1;
select next value for t1;
select previous value for t1;
create or replace sequence t1 as tinyint start with 126;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as tinyint unsigned start with 254;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as smallint start with 32766;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as smallint unsigned start with 65534;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as mediumint start with 8388606;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as mediumint unsigned start with 16777214;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as int start with 2147483646;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as int unsigned start with 4294967294;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as bigint start with 9223372036854775806;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as bigint unsigned start with 18446744073709551614;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as tinyint start with -127 increment -1;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as tinyint unsigned start with 1 increment -1;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as smallint start with -32767 increment -1;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as smallint unsigned start with 1 increment -1;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as mediumint start with -8388607 increment -1;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as mediumint unsigned start with 1 increment -1;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as int start with -2147483647 increment -1;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as int unsigned start with 1 increment -1;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
# This overflow caused by the first disjunction bleow is unavoidable and
# taken care of by the second disjunction:
# if (value + increment < min_value || value < min_value - increment)
call mtr.add_suppression("signed integer overflow: -9223372036854775807 \\+ -1000 cannot be represented in type 'long long int'");
create or replace sequence t1 as bigint start with -9223372036854775807 increment -1;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
create or replace sequence t1 as bigint unsigned start with 1 increment -1;
select next value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
alter sequence t1 cycle;
select next value for t1;
drop sequence t1;
--echo #
--echo # End of 11.4 tests
--echo #