summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <yuchen.pei@mariadb.com>2023-03-20 12:41:30 +1100
committerYuchen Pei <yuchen.pei@mariadb.com>2023-03-21 18:22:46 +1100
commitbd4a2fac119d50741e1b8eedcb1f9e64bd8e111c (patch)
treebf3aa8ccdc3c472eb8d177cb7504d04c6d04bac3
parentdb507f32b571dba912809c78594dda4efa125eeb (diff)
downloadmariadb-git-bb-11.0-mdev-28152-round-2.tar.gz
MDEV-28152 Addressing round 1 review commentsbb-11.0-mdev-28152-round-2
... at https://lists.launchpad.net/maria-developers/msg13297.html Also implemented setval and auto increment for unsigned sequences.
-rw-r--r--mysql-test/main/func_hybrid_type.result4
-rw-r--r--mysql-test/main/mysqldump.result26
-rw-r--r--mysql-test/suite/funcs_1/r/is_columns_is.result10
-rw-r--r--mysql-test/suite/funcs_1/r/is_columns_is_embedded.result10
-rw-r--r--mysql-test/suite/sql_sequence/alter.result277
-rw-r--r--mysql-test/suite/sql_sequence/alter.test134
-rw-r--r--mysql-test/suite/sql_sequence/alter_notembedded.result2
-rw-r--r--mysql-test/suite/sql_sequence/aria.result2
-rw-r--r--mysql-test/suite/sql_sequence/auto_increment.result14
-rw-r--r--mysql-test/suite/sql_sequence/auto_increment.test12
-rw-r--r--mysql-test/suite/sql_sequence/concurrent_create.result3
-rw-r--r--mysql-test/suite/sql_sequence/concurrent_create.test1
-rw-r--r--mysql-test/suite/sql_sequence/create.result271
-rw-r--r--mysql-test/suite/sql_sequence/create.test61
-rw-r--r--mysql-test/suite/sql_sequence/mysqldump.result158
-rw-r--r--mysql-test/suite/sql_sequence/mysqldump.test80
-rw-r--r--mysql-test/suite/sql_sequence/next.result214
-rw-r--r--mysql-test/suite/sql_sequence/next.test146
-rw-r--r--mysql-test/suite/sql_sequence/replication.result4
-rw-r--r--mysql-test/suite/sql_sequence/setval.result149
-rw-r--r--mysql-test/suite/sql_sequence/setval.test97
-rw-r--r--mysql-test/suite/sql_sequence/slave_nextval.result4
-rw-r--r--sql/item_func.cc21
-rw-r--r--sql/item_func.h7
-rw-r--r--sql/share/errmsg-utf8.txt8
-rw-r--r--sql/sql_lex.cc2
-rw-r--r--sql/sql_lex.h5
-rw-r--r--sql/sql_sequence.cc280
-rw-r--r--sql/sql_sequence.h77
-rw-r--r--sql/sql_show.cc36
-rw-r--r--sql/sql_type.cc2
-rw-r--r--sql/sql_yacc.yy316
32 files changed, 2032 insertions, 401 deletions
diff --git a/mysql-test/main/func_hybrid_type.result b/mysql-test/main/func_hybrid_type.result
index 550f61d46e8..1a50d84aa3a 100644
--- a/mysql-test/main/func_hybrid_type.result
+++ b/mysql-test/main/func_hybrid_type.result
@@ -4148,7 +4148,7 @@ ERROR HY000: Illegal parameter data types bigint unsigned and row for operation
# COALESCE
CREATE TABLE t1 (a TINYINT UNSIGNED, b TINYINT);
SELECT COALESCE(a,a)=ROW(1,1) FROM t1;
-ERROR HY000: Illegal parameter data types tiny unsigned and row for operation '='
+ERROR HY000: Illegal parameter data types tinyint unsigned and row for operation '='
SELECT COALESCE(b,b)=ROW(1,1) FROM t1;
ERROR HY000: Illegal parameter data types tinyint and row for operation '='
DROP TABLE t1;
@@ -4278,7 +4278,7 @@ DROP TABLE t1;
# SUM
CREATE TABLE t1 (a TINYINT UNSIGNED, b TINYINT);
SELECT MAX(a)=ROW(1,1) FROM t1;
-ERROR HY000: Illegal parameter data types tiny unsigned and row for operation '='
+ERROR HY000: Illegal parameter data types tinyint unsigned and row for operation '='
SELECT MAX(b)=ROW(1,1) FROM t1;
ERROR HY000: Illegal parameter data types tinyint and row for operation '='
DROP TABLE t1;
diff --git a/mysql-test/main/mysqldump.result b/mysql-test/main/mysqldump.result
index 41607ea3068..44ed94e43c9 100644
--- a/mysql-test/main/mysqldump.result
+++ b/mysql-test/main/mysqldump.result
@@ -6369,16 +6369,16 @@ NEXTVAL(d.s1) NEXTVAL(d.s2) NEXTVAL(d.s3) NEXTVAL(d.s4)
# Show create before dump
show create sequence d.s1;
Table Create Table
-s1 CREATE SEQUENCE `s1` as bigint start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
+s1 CREATE SEQUENCE `s1` start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s2;
Table Create Table
-s2 CREATE SEQUENCE `s2` as bigint start with 200 minvalue 200 maxvalue 1200 increment by 20 cache 1000 cycle ENGINE=MyISAM
+s2 CREATE SEQUENCE `s2` start with 200 minvalue 200 maxvalue 1200 increment by 20 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s3;
Table Create Table
-s3 CREATE SEQUENCE `s3` as bigint start with 300 minvalue 300 maxvalue 1300 increment by 30 cache 1000 cycle ENGINE=MyISAM
+s3 CREATE SEQUENCE `s3` start with 300 minvalue 300 maxvalue 1300 increment by 30 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s4;
Table Create Table
-s4 CREATE SEQUENCE `s4` as bigint start with 400 minvalue 400 maxvalue 1400 increment by 40 cache 1000 cycle ENGINE=MyISAM
+s4 CREATE SEQUENCE `s4` start with 400 minvalue 400 maxvalue 1400 increment by 40 cache 1000 cycle ENGINE=MyISAM
# Dump sequence without `--no-data`
# Restore from mysqldump
SETVAL(`s1`, 1101, 0)
@@ -6392,16 +6392,16 @@ SETVAL(`s4`, 1401, 0)
# Show create after restore
show create sequence d.s1;
Table Create Table
-s1 CREATE SEQUENCE `s1` as bigint start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
+s1 CREATE SEQUENCE `s1` start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s2;
Table Create Table
-s2 CREATE SEQUENCE `s2` as bigint start with 200 minvalue 200 maxvalue 1200 increment by 20 cache 1000 cycle ENGINE=MyISAM
+s2 CREATE SEQUENCE `s2` start with 200 minvalue 200 maxvalue 1200 increment by 20 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s3;
Table Create Table
-s3 CREATE SEQUENCE `s3` as bigint start with 300 minvalue 300 maxvalue 1300 increment by 30 cache 1000 cycle ENGINE=MyISAM
+s3 CREATE SEQUENCE `s3` start with 300 minvalue 300 maxvalue 1300 increment by 30 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s4;
Table Create Table
-s4 CREATE SEQUENCE `s4` as bigint start with 400 minvalue 400 maxvalue 1400 increment by 40 cache 1000 cycle ENGINE=MyISAM
+s4 CREATE SEQUENCE `s4` start with 400 minvalue 400 maxvalue 1400 increment by 40 cache 1000 cycle ENGINE=MyISAM
SELECT NEXTVAL(d.s1),NEXTVAL(d.s2),NEXTVAL(d.s3), NEXTVAL(d.s4);
NEXTVAL(d.s1) NEXTVAL(d.s2) NEXTVAL(d.s3) NEXTVAL(d.s4)
100 200 300 400
@@ -6418,16 +6418,16 @@ SETVAL(`s4`, 1401, 0)
# Show create after restore `--no-data`
show create sequence d.s1;
Table Create Table
-s1 CREATE SEQUENCE `s1` as bigint start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
+s1 CREATE SEQUENCE `s1` start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s2;
Table Create Table
-s2 CREATE SEQUENCE `s2` as bigint start with 200 minvalue 200 maxvalue 1200 increment by 20 cache 1000 cycle ENGINE=MyISAM
+s2 CREATE SEQUENCE `s2` start with 200 minvalue 200 maxvalue 1200 increment by 20 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s3;
Table Create Table
-s3 CREATE SEQUENCE `s3` as bigint start with 300 minvalue 300 maxvalue 1300 increment by 30 cache 1000 cycle ENGINE=MyISAM
+s3 CREATE SEQUENCE `s3` start with 300 minvalue 300 maxvalue 1300 increment by 30 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s4;
Table Create Table
-s4 CREATE SEQUENCE `s4` as bigint start with 400 minvalue 400 maxvalue 1400 increment by 40 cache 1000 cycle ENGINE=MyISAM
+s4 CREATE SEQUENCE `s4` start with 400 minvalue 400 maxvalue 1400 increment by 40 cache 1000 cycle ENGINE=MyISAM
SELECT NEXTVAL(d.s1),NEXTVAL(d.s2),NEXTVAL(d.s3), NEXTVAL(d.s4);
NEXTVAL(d.s1) NEXTVAL(d.s2) NEXTVAL(d.s3) NEXTVAL(d.s4)
100 200 300 400
@@ -6443,7 +6443,7 @@ SETVAL(`s4`, 1401, 0)
1401
show create sequence d2.s1;
Table Create Table
-s1 CREATE SEQUENCE `s1` as bigint start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
+s1 CREATE SEQUENCE `s1` start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
drop sequence d.s1, d.s2, d.s3, d.s4;
drop database d;
drop database d2;
diff --git a/mysql-test/suite/funcs_1/r/is_columns_is.result b/mysql-test/suite/funcs_1/r/is_columns_is.result
index 03eece0b4ae..ba3bd6b4f90 100644
--- a/mysql-test/suite/funcs_1/r/is_columns_is.result
+++ b/mysql-test/suite/funcs_1/r/is_columns_is.result
@@ -339,11 +339,8 @@ def information_schema SCHEMA_PRIVILEGES IS_GRANTABLE 5 NULL NO varchar 3 9 NULL
def information_schema SCHEMA_PRIVILEGES PRIVILEGE_TYPE 4 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select NEVER NULL
def information_schema SCHEMA_PRIVILEGES TABLE_CATALOG 2 NULL NO varchar 512 1536 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(512) select NEVER NULL
def information_schema SCHEMA_PRIVILEGES TABLE_SCHEMA 3 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select NEVER NULL
-def information_schema SEQUENCES CYCLE_OPTION 12 NULL NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select NEVER NULL
+def information_schema SEQUENCES CYCLE_OPTION 12 NULL NO varchar 3 9 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(3) select NEVER NULL
def information_schema SEQUENCES DATA_TYPE 4 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select NEVER NULL
-def information_schema SEQUENCES DECLARED_DATA_TYPE 13 NULL YES int NULL NULL 10 0 NULL NULL NULL int(21) select NEVER NULL
-def information_schema SEQUENCES DECLARED_NUMERIC_PRECISION 14 NULL YES int NULL NULL 10 0 NULL NULL NULL int(21) select NEVER NULL
-def information_schema SEQUENCES DECLARED_NUMERIC_SCALE 15 NULL YES int NULL NULL 10 0 NULL NULL NULL int(21) select NEVER NULL
def information_schema SEQUENCES INCREMENT 11 NULL NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select NEVER NULL
def information_schema SEQUENCES MAXIMUM_VALUE 10 NULL NO decimal NULL NULL 21 0 NULL NULL NULL decimal(21,0) select NEVER NULL
def information_schema SEQUENCES MINIMUM_VALUE 9 NULL NO decimal NULL NULL 21 0 NULL NULL NULL decimal(21,0) select NEVER NULL
@@ -916,10 +913,7 @@ NULL information_schema SEQUENCES START_VALUE decimal NULL NULL NULL NULL decima
NULL information_schema SEQUENCES MINIMUM_VALUE decimal NULL NULL NULL NULL decimal(21,0)
NULL information_schema SEQUENCES MAXIMUM_VALUE decimal NULL NULL NULL NULL decimal(21,0)
NULL information_schema SEQUENCES INCREMENT bigint NULL NULL NULL NULL bigint(21)
-NULL information_schema SEQUENCES CYCLE_OPTION bigint NULL NULL NULL NULL bigint(21)
-NULL information_schema SEQUENCES DECLARED_DATA_TYPE int NULL NULL NULL NULL int(21)
-NULL information_schema SEQUENCES DECLARED_NUMERIC_PRECISION int NULL NULL NULL NULL int(21)
-NULL information_schema SEQUENCES DECLARED_NUMERIC_SCALE int NULL NULL NULL NULL int(21)
+3.0000 information_schema SEQUENCES CYCLE_OPTION varchar 3 9 utf8mb3 utf8mb3_general_ci varchar(3)
3.0000 information_schema SESSION_STATUS VARIABLE_NAME varchar 64 192 utf8mb3 utf8mb3_general_ci varchar(64)
3.0000 information_schema SESSION_STATUS VARIABLE_VALUE varchar 2048 6144 utf8mb3 utf8mb3_general_ci varchar(2048)
3.0000 information_schema SESSION_VARIABLES VARIABLE_NAME varchar 64 192 utf8mb3 utf8mb3_general_ci varchar(64)
diff --git a/mysql-test/suite/funcs_1/r/is_columns_is_embedded.result b/mysql-test/suite/funcs_1/r/is_columns_is_embedded.result
index 87cc440cdbc..65f601168b7 100644
--- a/mysql-test/suite/funcs_1/r/is_columns_is_embedded.result
+++ b/mysql-test/suite/funcs_1/r/is_columns_is_embedded.result
@@ -339,11 +339,8 @@ def information_schema SCHEMA_PRIVILEGES IS_GRANTABLE 5 NULL NO varchar 3 9 NULL
def information_schema SCHEMA_PRIVILEGES PRIVILEGE_TYPE 4 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) NEVER NULL
def information_schema SCHEMA_PRIVILEGES TABLE_CATALOG 2 NULL NO varchar 512 1536 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(512) NEVER NULL
def information_schema SCHEMA_PRIVILEGES TABLE_SCHEMA 3 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) NEVER NULL
-def information_schema SEQUENCES CYCLE_OPTION 12 NULL NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) NEVER NULL
+def information_schema SEQUENCES CYCLE_OPTION 12 NULL NO varchar 3 9 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(3) NEVER NULL
def information_schema SEQUENCES DATA_TYPE 4 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) NEVER NULL
-def information_schema SEQUENCES DECLARED_DATA_TYPE 13 NULL YES int NULL NULL 10 0 NULL NULL NULL int(21) NEVER NULL
-def information_schema SEQUENCES DECLARED_NUMERIC_PRECISION 14 NULL YES int NULL NULL 10 0 NULL NULL NULL int(21) NEVER NULL
-def information_schema SEQUENCES DECLARED_NUMERIC_SCALE 15 NULL YES int NULL NULL 10 0 NULL NULL NULL int(21) NEVER NULL
def information_schema SEQUENCES INCREMENT 11 NULL NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) NEVER NULL
def information_schema SEQUENCES MAXIMUM_VALUE 10 NULL NO decimal NULL NULL 21 0 NULL NULL NULL decimal(21,0) NEVER NULL
def information_schema SEQUENCES MINIMUM_VALUE 9 NULL NO decimal NULL NULL 21 0 NULL NULL NULL decimal(21,0) NEVER NULL
@@ -916,10 +913,7 @@ NULL information_schema SEQUENCES START_VALUE decimal NULL NULL NULL NULL decima
NULL information_schema SEQUENCES MINIMUM_VALUE decimal NULL NULL NULL NULL decimal(21,0)
NULL information_schema SEQUENCES MAXIMUM_VALUE decimal NULL NULL NULL NULL decimal(21,0)
NULL information_schema SEQUENCES INCREMENT bigint NULL NULL NULL NULL bigint(21)
-NULL information_schema SEQUENCES CYCLE_OPTION bigint NULL NULL NULL NULL bigint(21)
-NULL information_schema SEQUENCES DECLARED_DATA_TYPE int NULL NULL NULL NULL int(21)
-NULL information_schema SEQUENCES DECLARED_NUMERIC_PRECISION int NULL NULL NULL NULL int(21)
-NULL information_schema SEQUENCES DECLARED_NUMERIC_SCALE int NULL NULL NULL NULL int(21)
+3.0000 information_schema SEQUENCES CYCLE_OPTION varchar 3 9 utf8mb3 utf8mb3_general_ci varchar(3)
3.0000 information_schema SESSION_STATUS VARIABLE_NAME varchar 64 192 utf8mb3 utf8mb3_general_ci varchar(64)
3.0000 information_schema SESSION_STATUS VARIABLE_VALUE varchar 2048 6144 utf8mb3 utf8mb3_general_ci varchar(2048)
3.0000 information_schema SESSION_VARIABLES VARIABLE_NAME varchar 64 192 utf8mb3 utf8mb3_general_ci varchar(64)
diff --git a/mysql-test/suite/sql_sequence/alter.result b/mysql-test/suite/sql_sequence/alter.result
index e6cd599ec40..2b1a9d3fd40 100644
--- a/mysql-test/suite/sql_sequence/alter.result
+++ b/mysql-test/suite/sql_sequence/alter.result
@@ -14,7 +14,7 @@ next value for t1
alter sequence t1 start=50;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 50 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 50 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
2 1 9223372036854775806 50 1 0 0 0
@@ -24,7 +24,7 @@ next value for t1
alter sequence t1 minvalue=-100;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 50 minvalue -100 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 50 minvalue -100 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
3 -100 9223372036854775806 50 1 0 0 0
@@ -33,14 +33,14 @@ ERROR HY000: Sequence 'test.t1' has out of range value for options
alter sequence t1 minvalue=100 start=100 restart=100;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 100 minvalue 100 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 100 minvalue 100 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
100 100 9223372036854775806 100 1 0 0 0
alter sequence t1 maxvalue=500;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 100 minvalue 100 maxvalue 500 increment by 1 nocache nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 100 minvalue 100 maxvalue 500 increment by 1 nocache nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
100 100 500 100 1 0 0 0
@@ -49,20 +49,20 @@ CREATE SEQUENCE t1 engine=myisam;
alter sequence t1 nocache;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
alter sequence t1 cache=100;
flush tables;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 100 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 100 nocycle ENGINE=MyISAM
alter sequence t1 nocache;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
flush tables;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1 1 9223372036854775806 1 1 0 0 0
@@ -83,19 +83,19 @@ CREATE SEQUENCE t1 maxvalue=100 engine=myisam;
alter sequence t1 no maxvalue;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1 1 9223372036854775806 1 1 1000 0 0
alter sequence t1 cycle;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 cycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 cycle ENGINE=MyISAM
alter sequence t1 nocycle;
alter sequence t1 start=15 restart minvalue=10 maxvalue=20 cycle;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 15 minvalue 10 maxvalue 20 increment by 1 cache 1000 cycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 15 minvalue 10 maxvalue 20 increment by 1 cache 1000 cycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
15 10 20 15 1 1000 1 0
@@ -129,7 +129,7 @@ CREATE SEQUENCE t1 maxvalue=100;
alter sequence t1 increment=-2 start with 50 minvalue=-100;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 50 minvalue -100 maxvalue 100 increment by -2 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 50 minvalue -100 maxvalue 100 increment by -2 cache 1000 nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1 -100 100 50 -2 1000 0 0
@@ -159,7 +159,7 @@ next value for t1
alter sequence t1 start=100;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 100 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 10 nocycle ENGINE=InnoDB
+t1 CREATE SEQUENCE `t1` start with 100 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 10 nocycle ENGINE=InnoDB
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
11 1 9223372036854775806 100 1 10 0 0
@@ -185,15 +185,15 @@ next value for t1
alter table t1 comment="foo";
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB COMMENT='foo'
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB COMMENT='foo'
alter table t1 engine=myisam;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM COMMENT='foo'
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM COMMENT='foo'
alter table t1 engine=innodb;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB COMMENT='foo'
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB COMMENT='foo'
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
3001 1 9223372036854775806 1 1 1000 0 0
@@ -254,13 +254,13 @@ DROP SEQUENCE s;
create sequence s maxvalue 12345;
show create sequence s;
Table Create Table
-s CREATE SEQUENCE `s` as bigint start with 1 minvalue 1 maxvalue 12345 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+s CREATE SEQUENCE `s` start with 1 minvalue 1 maxvalue 12345 increment by 1 cache 1000 nocycle ENGINE=MyISAM
alter sequence s maxvalue 123456789012345678901234;
Warnings:
Note 1292 Truncated incorrect INTEGER value: 'MAXVALUE'
show create sequence s;
Table Create Table
-s CREATE SEQUENCE `s` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+s CREATE SEQUENCE `s` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
drop sequence s;
create sequence s as tinyint;
show create sequence s;
@@ -314,7 +314,7 @@ drop sequence s;
create sequence s;
show create sequence s;
Table Create Table
-s CREATE SEQUENCE `s` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+s CREATE SEQUENCE `s` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
show create table s;
Table Create Table
s CREATE TABLE `s` (
@@ -330,7 +330,7 @@ s CREATE TABLE `s` (
alter sequence s maxvalue 123;
show create sequence s;
Table Create Table
-s CREATE SEQUENCE `s` as bigint start with 1 minvalue 1 maxvalue 123 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+s CREATE SEQUENCE `s` start with 1 minvalue 1 maxvalue 123 increment by 1 cache 1000 nocycle ENGINE=MyISAM
show create table s;
Table Create Table
s CREATE TABLE `s` (
@@ -378,6 +378,8 @@ s CREATE TABLE `s` (
) ENGINE=MyISAM SEQUENCE=1
alter sequence s as tinyint;
ERROR 22003: Out of range value for column 'maximum_value' at row 1
+alter sequence s maxvalue 126;
+alter sequence s as tinyint;
drop sequence s;
create sequence s as tinyint;
show create sequence s;
@@ -398,6 +400,23 @@ s CREATE TABLE `s` (
alter sequence s as int maxvalue 123;
ERROR 42000: This version of MariaDB doesn't yet support 'ALTER SEQUENCE with both AS <type> and something else.'
drop sequence s;
+create sequence s as smallint;
+select next value for s;
+next value for s
+1
+alter sequence s as int;
+select next value for s;
+next value for s
+1001
+drop sequence s;
+create sequence s as tinyint;
+select next value for s;
+next value for s
+1
+alter sequence s cache 100;
+select next value for s;
+ERROR HY000: Sequence 'test.s' has run out
+drop sequence s;
create sequence s as int;
show create sequence s;
Table Create Table
@@ -431,3 +450,221 @@ s CREATE TABLE `s` (
`cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
) ENGINE=MyISAM SEQUENCE=1
drop sequence s;
+create sequence s as tinyint;
+alter sequence s maxvalue 123456789012345678901;
+Warnings:
+Note 1292 Truncated incorrect INTEGER value: 'MAXVALUE'
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as tinyint start with 1 minvalue 1 maxvalue 126 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+alter sequence s maxvalue 126;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as tinyint start with 1 minvalue 1 maxvalue 126 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1
+alter sequence s maxvalue 63;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as tinyint start with 1 minvalue 1 maxvalue 63 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+ERROR HY000: Sequence 'test.s' has run out
+drop sequence s;
+create sequence s as tinyint unsigned;
+alter sequence s maxvalue 123456789012345678901;
+Warnings:
+Note 1292 Truncated incorrect INTEGER value: 'MAXVALUE'
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as tinyint unsigned start with 1 minvalue 1 maxvalue 254 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+alter sequence s maxvalue 254;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as tinyint unsigned start with 1 minvalue 1 maxvalue 254 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1
+alter sequence s maxvalue 120;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as tinyint unsigned start with 1 minvalue 1 maxvalue 120 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+ERROR HY000: Sequence 'test.s' has run out
+drop sequence s;
+create sequence s as smallint;
+alter sequence s maxvalue 123456789012345678901;
+Warnings:
+Note 1292 Truncated incorrect INTEGER value: 'MAXVALUE'
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as smallint start with 1 minvalue 1 maxvalue 32766 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+alter sequence s maxvalue 32766;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as smallint start with 1 minvalue 1 maxvalue 32766 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1
+alter sequence s maxvalue 16030;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as smallint start with 1 minvalue 1 maxvalue 16030 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1001
+drop sequence s;
+create sequence s as smallint unsigned;
+alter sequence s maxvalue 123456789012345678901;
+Warnings:
+Note 1292 Truncated incorrect INTEGER value: 'MAXVALUE'
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as smallint unsigned start with 1 minvalue 1 maxvalue 65534 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+alter sequence s maxvalue 65534;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as smallint unsigned start with 1 minvalue 1 maxvalue 65534 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1
+alter sequence s maxvalue 32000;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as smallint unsigned start with 1 minvalue 1 maxvalue 32000 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1001
+drop sequence s;
+create sequence s as mediumint;
+alter sequence s maxvalue 123456789012345678901;
+Warnings:
+Note 1292 Truncated incorrect INTEGER value: 'MAXVALUE'
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as mediumint start with 1 minvalue 1 maxvalue 8388606 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+alter sequence s maxvalue 8388606;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as mediumint start with 1 minvalue 1 maxvalue 8388606 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1
+alter sequence s maxvalue 4223212;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as mediumint start with 1 minvalue 1 maxvalue 4223212 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1001
+drop sequence s;
+create sequence s as mediumint unsigned;
+alter sequence s maxvalue 123456789012345678901;
+Warnings:
+Note 1292 Truncated incorrect INTEGER value: 'MAXVALUE'
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as mediumint unsigned start with 1 minvalue 1 maxvalue 16777214 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+alter sequence s maxvalue 16777214;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as mediumint unsigned start with 1 minvalue 1 maxvalue 16777214 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1
+alter sequence s maxvalue 8389231;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as mediumint unsigned start with 1 minvalue 1 maxvalue 8389231 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1001
+drop sequence s;
+create sequence s as int;
+alter sequence s maxvalue 123456789012345678901;
+Warnings:
+Note 1292 Truncated incorrect INTEGER value: 'MAXVALUE'
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as int start with 1 minvalue 1 maxvalue 2147483646 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+alter sequence s maxvalue 2147483646;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as int start with 1 minvalue 1 maxvalue 2147483646 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1
+alter sequence s maxvalue 1234567890;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as int start with 1 minvalue 1 maxvalue 1234567890 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1001
+drop sequence s;
+create sequence s as int unsigned;
+alter sequence s maxvalue 123456789012345678901;
+Warnings:
+Note 1292 Truncated incorrect INTEGER value: 'MAXVALUE'
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as int unsigned start with 1 minvalue 1 maxvalue 4294967294 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+alter sequence s maxvalue 4294967294;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as int unsigned start with 1 minvalue 1 maxvalue 4294967294 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1
+alter sequence s maxvalue 2123834923;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as int unsigned start with 1 minvalue 1 maxvalue 2123834923 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1001
+drop sequence s;
+create sequence s as bigint;
+alter sequence s maxvalue 123456789012345678901;
+Warnings:
+Note 1292 Truncated incorrect INTEGER value: 'MAXVALUE'
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+alter sequence s maxvalue 9223372036854775806;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1
+alter sequence s maxvalue 4683883928492758294;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` start with 1 minvalue 1 maxvalue 4683883928492758294 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1001
+drop sequence s;
+create sequence s as bigint unsigned;
+alter sequence s maxvalue 123456789012345678901;
+Warnings:
+Note 1292 Truncated incorrect INTEGER value: 'MAXVALUE'
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as bigint unsigned start with 1 minvalue 1 maxvalue 18446744073709551614 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+alter sequence s maxvalue 18446744073709551614;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as bigint unsigned start with 1 minvalue 1 maxvalue 18446744073709551614 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1
+alter sequence s maxvalue 9432738420582397432;
+show create sequence s;
+Table Create Table
+s CREATE SEQUENCE `s` as bigint unsigned start with 1 minvalue 1 maxvalue 9432738420582397432 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+select next value for s;
+next value for s
+1001
+drop sequence s;
diff --git a/mysql-test/suite/sql_sequence/alter.test b/mysql-test/suite/sql_sequence/alter.test
index 4949075f492..b47629b8902 100644
--- a/mysql-test/suite/sql_sequence/alter.test
+++ b/mysql-test/suite/sql_sequence/alter.test
@@ -204,6 +204,8 @@ show create sequence s;
show create table s;
--error ER_WARN_DATA_OUT_OF_RANGE
alter sequence s as tinyint;
+alter sequence s maxvalue 126;
+alter sequence s as tinyint;
drop sequence s;
# cannot alter both value type and something else yet.
@@ -214,6 +216,22 @@ show create table s;
alter sequence s as int maxvalue 123;
drop sequence s;
+# alter sequence causes discarding of cache values
+## alter type then next
+create sequence s as smallint;
+select next value for s; # 1
+alter sequence s as int;
+select next value for s; # 1001
+drop sequence s;
+
+## alter a tinyint sequence
+create sequence s as tinyint;
+select next value for s; # 1
+alter sequence s cache 100;
+--error ER_SEQUENCE_RUN_OUT
+select next value for s;
+drop sequence s;
+
# from signed to unsigned
create sequence s as int;
show create sequence s;
@@ -222,3 +240,119 @@ alter sequence s as int unsigned;
show create sequence s;
show create table s;
drop sequence s;
+
+# for each type
+create sequence s as tinyint;
+alter sequence s maxvalue 123456789012345678901;
+show create sequence s;
+alter sequence s maxvalue 126;
+show create sequence s;
+select next value for s;
+alter sequence s maxvalue 63;
+show create sequence s;
+#fixme: should not run out
+--error ER_SEQUENCE_RUN_OUT
+select next value for s;
+drop sequence s;
+
+create sequence s as tinyint unsigned;
+alter sequence s maxvalue 123456789012345678901;
+show create sequence s;
+alter sequence s maxvalue 254;
+show create sequence s;
+select next value for s;
+alter sequence s maxvalue 120;
+show create sequence s;
+#fixme: should not run out
+--error ER_SEQUENCE_RUN_OUT
+select next value for s;
+drop sequence s;
+
+create sequence s as smallint;
+alter sequence s maxvalue 123456789012345678901;
+show create sequence s;
+alter sequence s maxvalue 32766;
+show create sequence s;
+select next value for s;
+alter sequence s maxvalue 16030;
+show create sequence s;
+select next value for s;
+drop sequence s;
+
+create sequence s as smallint unsigned;
+alter sequence s maxvalue 123456789012345678901;
+show create sequence s;
+alter sequence s maxvalue 65534;
+show create sequence s;
+select next value for s;
+alter sequence s maxvalue 32000;
+show create sequence s;
+select next value for s;
+drop sequence s;
+
+create sequence s as mediumint;
+alter sequence s maxvalue 123456789012345678901;
+show create sequence s;
+alter sequence s maxvalue 8388606;
+show create sequence s;
+select next value for s;
+alter sequence s maxvalue 4223212;
+show create sequence s;
+select next value for s;
+drop sequence s;
+
+create sequence s as mediumint unsigned;
+alter sequence s maxvalue 123456789012345678901;
+show create sequence s;
+alter sequence s maxvalue 16777214;
+show create sequence s;
+select next value for s;
+alter sequence s maxvalue 8389231;
+show create sequence s;
+select next value for s;
+drop sequence s;
+
+create sequence s as int;
+alter sequence s maxvalue 123456789012345678901;
+show create sequence s;
+alter sequence s maxvalue 2147483646;
+show create sequence s;
+select next value for s;
+alter sequence s maxvalue 1234567890;
+show create sequence s;
+select next value for s;
+drop sequence s;
+
+create sequence s as int unsigned;
+alter sequence s maxvalue 123456789012345678901;
+show create sequence s;
+alter sequence s maxvalue 4294967294;
+show create sequence s;
+select next value for s;
+alter sequence s maxvalue 2123834923;
+show create sequence s;
+select next value for s;
+drop sequence s;
+
+create sequence s as bigint;
+alter sequence s maxvalue 123456789012345678901;
+show create sequence s;
+alter sequence s maxvalue 9223372036854775806;
+show create sequence s;
+select next value for s;
+alter sequence s maxvalue 4683883928492758294;
+show create sequence s;
+select next value for s;
+drop sequence s;
+
+create sequence s as bigint unsigned;
+alter sequence s maxvalue 123456789012345678901;
+show create sequence s;
+alter sequence s maxvalue 18446744073709551614;
+show create sequence s;
+select next value for s;
+alter sequence s maxvalue 9432738420582397432;
+show create sequence s;
+select next value for s;
+drop sequence s;
+
diff --git a/mysql-test/suite/sql_sequence/alter_notembedded.result b/mysql-test/suite/sql_sequence/alter_notembedded.result
index c2ea6633d1d..f3e1f5f18cd 100644
--- a/mysql-test/suite/sql_sequence/alter_notembedded.result
+++ b/mysql-test/suite/sql_sequence/alter_notembedded.result
@@ -12,7 +12,7 @@ select nextval(s1);
ERROR 42000: INSERT command denied to user 'normal_1'@'localhost' for table `s_db`.`s1`
show create sequence s1;
Table Create Table
-s1 CREATE SEQUENCE `s1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+s1 CREATE SEQUENCE `s1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
alter sequence s1 restart 50;
ERROR 42000: ALTER command denied to user 'normal_1'@'localhost' for table `s_db`.`s1`
connection default;
diff --git a/mysql-test/suite/sql_sequence/aria.result b/mysql-test/suite/sql_sequence/aria.result
index 1e42be58240..cfc7d946772 100644
--- a/mysql-test/suite/sql_sequence/aria.result
+++ b/mysql-test/suite/sql_sequence/aria.result
@@ -2,7 +2,7 @@ set @@default_storage_engine="aria";
CREATE SEQUENCE t1 cache=10;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 10 nocycle ENGINE=Aria
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 10 nocycle ENGINE=Aria
select NEXT VALUE for t1,seq from seq_1_to_20;
NEXT VALUE for t1 seq
1 1
diff --git a/mysql-test/suite/sql_sequence/auto_increment.result b/mysql-test/suite/sql_sequence/auto_increment.result
index bf0a04bbaf1..7fcf26d6cf6 100644
--- a/mysql-test/suite/sql_sequence/auto_increment.result
+++ b/mysql-test/suite/sql_sequence/auto_increment.result
@@ -28,3 +28,17 @@ nextval(s)
1997
drop sequence s;
set global auto_increment_increment= default, auto_increment_offset= default;
+#
+# MDEV-28152 Features for sequence
+#
+set global auto_increment_increment= 100;
+set global auto_increment_offset= 42;
+create sequence s as bigint unsigned start with 9223372036854775800 increment 0;
+select next value for s;
+next value for s
+9223372036854775842
+select next value for s;
+next value for s
+9223372036854775942
+drop sequence s;
+set global auto_increment_increment= default, auto_increment_offset= default;
diff --git a/mysql-test/suite/sql_sequence/auto_increment.test b/mysql-test/suite/sql_sequence/auto_increment.test
index 335bef7ea37..e9d5a253757 100644
--- a/mysql-test/suite/sql_sequence/auto_increment.test
+++ b/mysql-test/suite/sql_sequence/auto_increment.test
@@ -28,3 +28,15 @@ drop sequence s;
# Clean up
set global auto_increment_increment= default, auto_increment_offset= default;
+
+--echo #
+--echo # MDEV-28152 Features for sequence
+--echo #
+
+set global auto_increment_increment= 100;
+set global auto_increment_offset= 42;
+create sequence s as bigint unsigned start with 9223372036854775800 increment 0;
+select next value for s;
+select next value for s;
+drop sequence s;
+set global auto_increment_increment= default, auto_increment_offset= default;
diff --git a/mysql-test/suite/sql_sequence/concurrent_create.result b/mysql-test/suite/sql_sequence/concurrent_create.result
index e28c98e46be..a03f512a4c3 100644
--- a/mysql-test/suite/sql_sequence/concurrent_create.result
+++ b/mysql-test/suite/sql_sequence/concurrent_create.result
@@ -30,6 +30,9 @@ PREPARE stmt FROM "CREATE TABLE s2 LIKE s1";
execute stmt;
drop table s2;
execute stmt;
+show create sequence s2;
+Table Create Table
+s2 CREATE SEQUENCE `s2` as mediumint unsigned start with 1 minvalue 1 maxvalue 16777214 increment by 1 cache 1000 nocycle ENGINE=InnoDB
drop table s2;
execute stmt;
select * from s2;
diff --git a/mysql-test/suite/sql_sequence/concurrent_create.test b/mysql-test/suite/sql_sequence/concurrent_create.test
index b4def8d7ce5..1a88b1a6d3e 100644
--- a/mysql-test/suite/sql_sequence/concurrent_create.test
+++ b/mysql-test/suite/sql_sequence/concurrent_create.test
@@ -47,6 +47,7 @@ PREPARE stmt FROM "CREATE TABLE s2 LIKE s1";
execute stmt;
drop table s2;
execute stmt;
+show create sequence s2;
drop table s2;
execute stmt;
select * from s2;
diff --git a/mysql-test/suite/sql_sequence/create.result b/mysql-test/suite/sql_sequence/create.result
index f2d376774a7..5b888993368 100644
--- a/mysql-test/suite/sql_sequence/create.result
+++ b/mysql-test/suite/sql_sequence/create.result
@@ -4,7 +4,7 @@ Note 1051 Unknown table 'test.t1'
create or replace sequence t1 engine=myisam;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -23,7 +23,7 @@ next_not_cached_value minimum_value maximum_value start_value increment cache_si
create or replace sequence t1 engine=innodb;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -42,7 +42,7 @@ next_not_cached_value minimum_value maximum_value start_value increment cache_si
create or replace sequence t1 engine=maria;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -65,59 +65,59 @@ ERROR 42S02: Table 'test.t1' doesn't exist
create or replace sequence t1 start with 10;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 10 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 10 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
10 1 9223372036854775806 10 1 1000 0 0
create or replace sequence t1 minvalue=11;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 11 minvalue 11 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 11 minvalue 11 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
11 11 9223372036854775806 11 1 1000 0 0
create or replace sequence t1 maxvalue=13 increment by -1;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 13 minvalue -9223372036854775807 maxvalue 13 increment by -1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 13 minvalue -9223372036854775807 maxvalue 13 increment by -1 cache 1000 nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
13 -9223372036854775807 13 13 -1 1000 0 0
create or replace sequence t1 increment by -1 cache 100;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with -1 minvalue -9223372036854775807 maxvalue -1 increment by -1 cache 100 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with -1 minvalue -9223372036854775807 maxvalue -1 increment by -1 cache 100 nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
-1 -9223372036854775807 -1 -1 -1 100 0 0
create or replace sequence t1 cycle;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 cycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 cycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1 1 9223372036854775806 1 1 1000 1 0
create or replace sequence t1 nocycle;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1 1 9223372036854775806 1 1 1000 0 0
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
create or replace sequence t1 cycle minvalue= 14;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 14 minvalue 14 maxvalue 9223372036854775806 increment by 1 cache 1000 cycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 14 minvalue 14 maxvalue 9223372036854775806 increment by 1 cache 1000 cycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
14 14 9223372036854775806 14 1 1000 1 0
create or replace sequence t1 cycle increment by -1;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with -1 minvalue -9223372036854775807 maxvalue -1 increment by -1 cache 1000 cycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with -1 minvalue -9223372036854775807 maxvalue -1 increment by -1 cache 1000 cycle ENGINE=MyISAM
drop sequence t1;
create sequence if not exists t1;
create sequence if not exists t1 start with 10;
@@ -128,18 +128,18 @@ next_not_cached_value minimum_value maximum_value start_value increment cache_si
1 1 9223372036854775806 1 1 1000 0 0
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
create or replace sequence t1 start with 10 minvalue=10 maxvalue=11 nocache cycle;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 10 minvalue 10 maxvalue 11 increment by 1 nocache cycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 10 minvalue 10 maxvalue 11 increment by 1 nocache cycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
10 10 11 10 1 0 1 0
create or replace sequence t1 start with 10 minvalue=-10 maxvalue=11 cache=10 cycle increment by 10;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 10 minvalue -10 maxvalue 11 increment by 10 cache 10 cycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 10 minvalue -10 maxvalue 11 increment by 10 cache 10 cycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
10 -10 11 10 10 10 1 0
@@ -153,7 +153,7 @@ drop sequence if exists t1;
create sequence t1 increment by 0;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 0 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 0 cache 1000 nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1 1 9223372036854775806 1 0 1000 0 0
@@ -186,6 +186,8 @@ create sequence t1 RESTART WITH 10;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'RESTART' at line 1
create or replace sequence t1 start with 10 NO MINVALUE minvalue=1;
ERROR HY000: Option 'MINVALUE' used twice in statement
+create sequence s increment by 3234567890123456789;
+ERROR HY000: Sequence 'test.s' has out of range value for options
create or replace sequence t1;
show fields from t1;
Field Type Null Key Default Extra
@@ -233,7 +235,7 @@ flush tables;
create or replace sequence t1 comment= "test 1";
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM COMMENT='test 1'
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM COMMENT='test 1'
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -249,7 +251,7 @@ t1 CREATE TABLE `t1` (
create or replace sequence t1 comment= "test 2" min_rows=1 max_rows=2;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM COMMENT='test 2'
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM COMMENT='test 2'
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -278,7 +280,7 @@ CREATE TABLE t1 (
) sequence=1;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -547,7 +549,7 @@ t CREATE TABLE `t` (
) ENGINE=MyISAM SEQUENCE=1
show create sequence t;
Table Create Table
-t CREATE SEQUENCE `t` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t CREATE SEQUENCE `t` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
drop tables t, s;
#
# MDEV-13714 SEQUENCE option fix
@@ -723,21 +725,21 @@ Warnings:
Note 1292 Truncated incorrect INTEGER value: 'MINVALUE'
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with -9223372036854775807 minvalue -9223372036854775807 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with -9223372036854775807 minvalue -9223372036854775807 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
create or replace sequence t1 minvalue -9223372036854775808;
Warnings:
Note 1292 Truncated incorrect INTEGER value: 'MINVALUE'
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with -9223372036854775807 minvalue -9223372036854775807 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with -9223372036854775807 minvalue -9223372036854775807 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
create or replace sequence t1 minvalue -9223372036854775807;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with -9223372036854775807 minvalue -9223372036854775807 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with -9223372036854775807 minvalue -9223372036854775807 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
create or replace sequence t1 minvalue 9223372036854775805;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 9223372036854775805 minvalue 9223372036854775805 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 9223372036854775805 minvalue 9223372036854775805 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
create or replace sequence t1 minvalue 9223372036854775806;
ERROR HY000: Sequence 'test.t1' has out of range value for options
create or replace sequence t1 minvalue 9223372036854775807;
@@ -755,29 +757,29 @@ ERROR HY000: Sequence 'test.t1' has out of range value for options
create or replace sequence t1 maxvalue -9223372036854775806 increment by -1;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with -9223372036854775806 minvalue -9223372036854775807 maxvalue -9223372036854775806 increment by -1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with -9223372036854775806 minvalue -9223372036854775807 maxvalue -9223372036854775806 increment by -1 cache 1000 nocycle ENGINE=MyISAM
create or replace sequence t1 maxvalue 9223372036854775806;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
create or replace sequence t1 maxvalue 9223372036854775807;
Warnings:
Note 1292 Truncated incorrect INTEGER value: 'MAXVALUE'
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
create or replace sequence t1 maxvalue 9223372036854775808;
Warnings:
Note 1292 Truncated incorrect INTEGER value: 'MAXVALUE'
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
create or replace sequence t1 maxvalue 9999999999999999999999;
Warnings:
Note 1292 Truncated incorrect INTEGER value: 'MAXVALUE'
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
# -----
# Create with value types
# -----
@@ -848,7 +850,7 @@ t1 CREATE TABLE `t1` (
create or replace sequence t1 as bigint;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -864,7 +866,7 @@ t1 CREATE TABLE `t1` (
create or replace sequence t1 as tinyint unsigned;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as tiny unsigned start with 1 minvalue 1 maxvalue 254 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` as tinyint unsigned start with 1 minvalue 1 maxvalue 254 increment by 1 cache 1000 nocycle ENGINE=MyISAM
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -941,10 +943,168 @@ t1 CREATE TABLE `t1` (
`cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
`cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
) ENGINE=MyISAM SEQUENCE=1
+create or replace sequence t1 increment -1 as tinyint;
+show create sequence t1;
+Table Create Table
+t1 CREATE SEQUENCE `t1` as tinyint start with -1 minvalue -127 maxvalue -1 increment by -1 cache 1000 nocycle ENGINE=MyISAM
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `next_not_cached_value` tinyint(5) NOT NULL,
+ `minimum_value` tinyint(5) NOT NULL,
+ `maximum_value` tinyint(5) NOT NULL,
+ `start_value` tinyint(5) NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used',
+ `increment` bigint(21) NOT NULL COMMENT 'increment value',
+ `cache_size` bigint(21) unsigned NOT NULL,
+ `cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
+ `cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
+) ENGINE=MyISAM SEQUENCE=1
+create or replace sequence t1 increment -1 as smallint;
+show create sequence t1;
+Table Create Table
+t1 CREATE SEQUENCE `t1` as smallint start with -1 minvalue -32767 maxvalue -1 increment by -1 cache 1000 nocycle ENGINE=MyISAM
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `next_not_cached_value` smallint(7) NOT NULL,
+ `minimum_value` smallint(7) NOT NULL,
+ `maximum_value` smallint(7) NOT NULL,
+ `start_value` smallint(7) NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used',
+ `increment` bigint(21) NOT NULL COMMENT 'increment value',
+ `cache_size` bigint(21) unsigned NOT NULL,
+ `cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
+ `cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
+) ENGINE=MyISAM SEQUENCE=1
+create or replace sequence t1 increment -1 as mediumint;
+show create sequence t1;
+Table Create Table
+t1 CREATE SEQUENCE `t1` as mediumint start with -1 minvalue -8388607 maxvalue -1 increment by -1 cache 1000 nocycle ENGINE=MyISAM
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `next_not_cached_value` mediumint(10) NOT NULL,
+ `minimum_value` mediumint(10) NOT NULL,
+ `maximum_value` mediumint(10) NOT NULL,
+ `start_value` mediumint(10) NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used',
+ `increment` bigint(21) NOT NULL COMMENT 'increment value',
+ `cache_size` bigint(21) unsigned NOT NULL,
+ `cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
+ `cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
+) ENGINE=MyISAM SEQUENCE=1
+create or replace sequence t1 increment -1 as int;
+show create sequence t1;
+Table Create Table
+t1 CREATE SEQUENCE `t1` as int start with -1 minvalue -2147483647 maxvalue -1 increment by -1 cache 1000 nocycle ENGINE=MyISAM
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `next_not_cached_value` int(12) NOT NULL,
+ `minimum_value` int(12) NOT NULL,
+ `maximum_value` int(12) NOT NULL,
+ `start_value` int(12) NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used',
+ `increment` bigint(21) NOT NULL COMMENT 'increment value',
+ `cache_size` bigint(21) unsigned NOT NULL,
+ `cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
+ `cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
+) ENGINE=MyISAM SEQUENCE=1
+create or replace sequence t1 increment -1 as bigint;
+show create sequence t1;
+Table Create Table
+t1 CREATE SEQUENCE `t1` start with -1 minvalue -9223372036854775807 maxvalue -1 increment by -1 cache 1000 nocycle ENGINE=MyISAM
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `next_not_cached_value` bigint(21) NOT NULL,
+ `minimum_value` bigint(21) NOT NULL,
+ `maximum_value` bigint(21) NOT NULL,
+ `start_value` bigint(21) NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used',
+ `increment` bigint(21) NOT NULL COMMENT 'increment value',
+ `cache_size` bigint(21) unsigned NOT NULL,
+ `cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
+ `cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
+) ENGINE=MyISAM SEQUENCE=1
+create or replace sequence t1 increment -1 as tinyint unsigned;
+show create sequence t1;
+Table Create Table
+t1 CREATE SEQUENCE `t1` as tinyint unsigned start with 254 minvalue 1 maxvalue 254 increment by -1 cache 1000 nocycle ENGINE=MyISAM
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `next_not_cached_value` tinyint(5) unsigned NOT NULL,
+ `minimum_value` tinyint(5) unsigned NOT NULL,
+ `maximum_value` tinyint(5) unsigned NOT NULL,
+ `start_value` tinyint(5) unsigned NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used',
+ `increment` bigint(21) NOT NULL COMMENT 'increment value',
+ `cache_size` bigint(21) unsigned NOT NULL,
+ `cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
+ `cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
+) ENGINE=MyISAM SEQUENCE=1
+create or replace sequence t1 increment -1 as smallint unsigned;
+show create sequence t1;
+Table Create Table
+t1 CREATE SEQUENCE `t1` as smallint unsigned start with 65534 minvalue 1 maxvalue 65534 increment by -1 cache 1000 nocycle ENGINE=MyISAM
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `next_not_cached_value` smallint(7) unsigned NOT NULL,
+ `minimum_value` smallint(7) unsigned NOT NULL,
+ `maximum_value` smallint(7) unsigned NOT NULL,
+ `start_value` smallint(7) unsigned NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used',
+ `increment` bigint(21) NOT NULL COMMENT 'increment value',
+ `cache_size` bigint(21) unsigned NOT NULL,
+ `cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
+ `cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
+) ENGINE=MyISAM SEQUENCE=1
+create or replace sequence t1 increment -1 as mediumint unsigned;
+show create sequence t1;
+Table Create Table
+t1 CREATE SEQUENCE `t1` as mediumint unsigned start with 16777214 minvalue 1 maxvalue 16777214 increment by -1 cache 1000 nocycle ENGINE=MyISAM
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `next_not_cached_value` mediumint(10) unsigned NOT NULL,
+ `minimum_value` mediumint(10) unsigned NOT NULL,
+ `maximum_value` mediumint(10) unsigned NOT NULL,
+ `start_value` mediumint(10) unsigned NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used',
+ `increment` bigint(21) NOT NULL COMMENT 'increment value',
+ `cache_size` bigint(21) unsigned NOT NULL,
+ `cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
+ `cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
+) ENGINE=MyISAM SEQUENCE=1
+create or replace sequence t1 increment -1 as int unsigned;
+show create sequence t1;
+Table Create Table
+t1 CREATE SEQUENCE `t1` as int unsigned start with 4294967294 minvalue 1 maxvalue 4294967294 increment by -1 cache 1000 nocycle ENGINE=MyISAM
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `next_not_cached_value` int(12) unsigned NOT NULL,
+ `minimum_value` int(12) unsigned NOT NULL,
+ `maximum_value` int(12) unsigned NOT NULL,
+ `start_value` int(12) unsigned NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used',
+ `increment` bigint(21) NOT NULL COMMENT 'increment value',
+ `cache_size` bigint(21) unsigned NOT NULL,
+ `cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
+ `cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
+) ENGINE=MyISAM SEQUENCE=1
+create or replace sequence t1 increment -1 as bigint unsigned;
+show create sequence t1;
+Table Create Table
+t1 CREATE SEQUENCE `t1` as bigint unsigned start with 18446744073709551614 minvalue 1 maxvalue 18446744073709551614 increment by -1 cache 1000 nocycle ENGINE=MyISAM
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `next_not_cached_value` bigint(21) unsigned NOT NULL,
+ `minimum_value` bigint(21) unsigned NOT NULL,
+ `maximum_value` bigint(21) unsigned NOT NULL,
+ `start_value` bigint(21) unsigned NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used',
+ `increment` bigint(21) NOT NULL COMMENT 'increment value',
+ `cache_size` bigint(21) unsigned NOT NULL,
+ `cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
+ `cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
+) ENGINE=MyISAM SEQUENCE=1
create or replace sequence t1 as tinyint zerofill;
ERROR HY000: Incorrect value 'ZEROFILL' for option 'AS'
-create or replace sequence t1 as mediumint unsigned increment by -1;
-ERROR HY000: Sequence 'test.t1' has out of range value for options
create or replace sequence t1 as bigint unsigned start with 12345678901234567890;
show create sequence t1;
Table Create Table
@@ -961,6 +1121,8 @@ t1 CREATE TABLE `t1` (
`cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
`cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
) ENGINE=MyISAM SEQUENCE=1
+create or replace sequence t1 as bigint unsigned increment 12345678901234567;
+ERROR HY000: Sequence 'test.t1' has out of range value for options
# -----
# value types + truncating
# -----
@@ -970,7 +1132,7 @@ Note 1292 Truncated incorrect INTEGER value: 'MINVALUE'
Note 1292 Truncated incorrect INTEGER value: 'MAXVALUE'
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as tiny unsigned start with 1 minvalue 1 maxvalue 254 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` as tinyint unsigned start with 1 minvalue 1 maxvalue 254 increment by 1 cache 1000 nocycle ENGINE=MyISAM
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -1064,7 +1226,7 @@ t1 CREATE TABLE `t1` (
create or replace sequence t1 as bigint maxvalue -1 increment by -1;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with -1 minvalue -9223372036854775807 maxvalue -1 increment by -1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with -1 minvalue -9223372036854775807 maxvalue -1 increment by -1 cache 1000 nocycle ENGINE=MyISAM
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -1082,7 +1244,7 @@ Warnings:
Note 1292 Truncated incorrect INTEGER value: 'MAXVALUE'
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -1130,7 +1292,7 @@ t1 CREATE SEQUENCE `t1` as bigint unsigned start with 1 minvalue 1 maxvalue 1844
create or replace sequence t1 start with 1 as tinyint unsigned;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as tiny unsigned start with 1 minvalue 1 maxvalue 254 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` as tinyint unsigned start with 1 minvalue 1 maxvalue 254 increment by 1 cache 1000 nocycle ENGINE=MyISAM
create or replace sequence t1 start with 254 as tinyint unsigned;
create or replace sequence t1 start with 255 as tinyint unsigned;
ERROR HY000: Sequence 'test.t1' has out of range value for options
@@ -1139,12 +1301,35 @@ ERROR HY000: Sequence 'test.t1' has out of range value for options
create or replace sequence t1 start with 123456789012345678901 as tinyint unsigned;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '123456789012345678901 as tinyint unsigned' at line 1
drop sequence t1;
+# -----
+# information_schema.sequences
+# -----
create sequence s1 as tinyint unsigned increment by 23;
create sequence s2 start with 42 minvalue -9223372036854775807;
create sequence s3 as bigint unsigned start with 12345678901234567890 cycle;
-select * from information_schema.sequences;
-SEQUENCE_CATALOG SEQUENCE_SCHEMA SEQUENCE_NAME DATA_TYPE NUMERIC_PRECISION NUMERIC_PRECISION_RADIX NUMERIC_SCALE START_VALUE MINIMUM_VALUE MAXIMUM_VALUE INCREMENT CYCLE_OPTION DECLARED_DATA_TYPE DECLARED_NUMERIC_PRECISION DECLARED_NUMERIC_SCALE
-def test s3 bigint unsigned 64 2 0 12345678901234567890 1 18446744073709551614 1 1 NULL NULL NULL
-def test s2 bigint 64 2 0 42 -9223372036854775807 9223372036854775806 1 0 NULL NULL NULL
-def test s1 tiny unsigned 8 2 0 1 1 254 23 0 NULL NULL NULL
-drop sequence s1, s2, s3;
+create sequence s4 as tinyint;
+create sequence s5 as smallint;
+create sequence s6 as mediumint;
+create sequence s7 as int;
+create sequence s8 as bigint;
+create sequence s9 as tinyint unsigned;
+create sequence s10 as smallint unsigned;
+create sequence s11 as mediumint unsigned;
+create sequence s12 as int unsigned;
+create sequence s13 as bigint unsigned;
+select * from information_schema.sequences order by sequence_name;
+SEQUENCE_CATALOG SEQUENCE_SCHEMA SEQUENCE_NAME DATA_TYPE NUMERIC_PRECISION NUMERIC_PRECISION_RADIX NUMERIC_SCALE START_VALUE MINIMUM_VALUE MAXIMUM_VALUE INCREMENT CYCLE_OPTION
+def test s1 tinyint unsigned 8 2 0 1 1 254 23 0
+def test s10 smallint unsigned 16 2 0 1 1 65534 1 0
+def test s11 mediumint unsigned 24 2 0 1 1 16777214 1 0
+def test s12 int unsigned 32 2 0 1 1 4294967294 1 0
+def test s13 bigint unsigned 64 2 0 1 1 18446744073709551614 1 0
+def test s2 bigint 64 2 0 42 -9223372036854775807 9223372036854775806 1 0
+def test s3 bigint unsigned 64 2 0 12345678901234567890 1 18446744073709551614 1 1
+def test s4 tinyint 8 2 0 1 1 126 1 0
+def test s5 smallint 16 2 0 1 1 32766 1 0
+def test s6 mediumint 24 2 0 1 1 8388606 1 0
+def test s7 int 32 2 0 1 1 2147483646 1 0
+def test s8 bigint 64 2 0 1 1 9223372036854775806 1 0
+def test s9 tinyint unsigned 8 2 0 1 1 254 1 0
+drop sequence s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13;
diff --git a/mysql-test/suite/sql_sequence/create.test b/mysql-test/suite/sql_sequence/create.test
index 388b2fd3fe9..07bf9b29090 100644
--- a/mysql-test/suite/sql_sequence/create.test
+++ b/mysql-test/suite/sql_sequence/create.test
@@ -118,6 +118,9 @@ create or replace sequence t1 start with 10 min_value=1 NO MINVALUE;
create sequence t1 RESTART WITH 10;
--error ER_DUP_ARGUMENT
create or replace sequence t1 start with 10 NO MINVALUE minvalue=1;
+# hidden constraints cache < (LONGLONG_MAX - max_increment) / max_increment
+--error ER_SEQUENCE_INVALID_DATA
+create sequence s increment by 3234567890123456789;
#
# Test with LIST COLUMNS as first command
@@ -623,17 +626,50 @@ show create table t1;
create or replace sequence t1 as bigint unsigned;
show create sequence t1;
show create table t1;
+create or replace sequence t1 increment -1 as tinyint;
+show create sequence t1;
+show create table t1;
+create or replace sequence t1 increment -1 as smallint;
+show create sequence t1;
+show create table t1;
+create or replace sequence t1 increment -1 as mediumint;
+show create sequence t1;
+show create table t1;
+create or replace sequence t1 increment -1 as int;
+show create sequence t1;
+show create table t1;
+create or replace sequence t1 increment -1 as bigint;
+show create sequence t1;
+show create table t1;
+create or replace sequence t1 increment -1 as tinyint unsigned;
+show create sequence t1;
+show create table t1;
+create or replace sequence t1 increment -1 as smallint unsigned;
+show create sequence t1;
+show create table t1;
+create or replace sequence t1 increment -1 as mediumint unsigned;
+show create sequence t1;
+show create table t1;
+create or replace sequence t1 increment -1 as int unsigned;
+show create sequence t1;
+show create table t1;
+create or replace sequence t1 increment -1 as bigint unsigned;
+show create sequence t1;
+show create table t1;
+
#zerofill is not supported
--error ER_BAD_OPTION_VALUE
create or replace sequence t1 as tinyint zerofill;
-#an unsigned sequence has to have positive increment
---error ER_SEQUENCE_INVALID_DATA
-create or replace sequence t1 as mediumint unsigned increment by -1;
+
#start with a number between longlong_max and ulonglong_max
create or replace sequence t1 as bigint unsigned start with 12345678901234567890;
show create sequence t1;
show create table t1;
+# hidden constraints cache < (LONGLONG_MAX - max_increment) / max_increment
+--error ER_SEQUENCE_INVALID_DATA
+create or replace sequence t1 as bigint unsigned increment 12345678901234567;
+
--echo # -----
--echo # value types + truncating
--echo # -----
@@ -698,9 +734,22 @@ create or replace sequence t1 start with 123456789012345678901 as tinyint unsign
drop sequence t1;
-# information_schema.sequences
+--echo # -----
+--echo # information_schema.sequences
+--echo # -----
create sequence s1 as tinyint unsigned increment by 23;
create sequence s2 start with 42 minvalue -9223372036854775807;
create sequence s3 as bigint unsigned start with 12345678901234567890 cycle;
-select * from information_schema.sequences;
-drop sequence s1, s2, s3;
+#test support of all types in information schema
+create sequence s4 as tinyint;
+create sequence s5 as smallint;
+create sequence s6 as mediumint;
+create sequence s7 as int;
+create sequence s8 as bigint;
+create sequence s9 as tinyint unsigned;
+create sequence s10 as smallint unsigned;
+create sequence s11 as mediumint unsigned;
+create sequence s12 as int unsigned;
+create sequence s13 as bigint unsigned;
+select * from information_schema.sequences order by sequence_name;
+drop sequence s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13;
diff --git a/mysql-test/suite/sql_sequence/mysqldump.result b/mysql-test/suite/sql_sequence/mysqldump.result
index 3316fdac5ae..b6936a2794e 100644
--- a/mysql-test/suite/sql_sequence/mysqldump.result
+++ b/mysql-test/suite/sql_sequence/mysqldump.result
@@ -3,9 +3,9 @@ CREATE TABLE t1(a INT, KEY (a)) KEY_BLOCK_SIZE=1024;
insert into t1 values (1),(2);
CREATE SEQUENCE x1 engine=innodb;
# dump whole database
-CREATE SEQUENCE `a1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
+CREATE SEQUENCE `a1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
SELECT SETVAL(`a1`, 1, 0);
-CREATE SEQUENCE `x1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
+CREATE SEQUENCE `x1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
SELECT SETVAL(`x1`, 1, 0);
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
@@ -18,9 +18,9 @@ INSERT INTO `t1` VALUES
(1),
(2);
# dump by tables order 1
-CREATE SEQUENCE `a1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
+CREATE SEQUENCE `a1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
SELECT SETVAL(`a1`, 1, 0);
-CREATE SEQUENCE `x1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
+CREATE SEQUENCE `x1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
SELECT SETVAL(`x1`, 1, 0);
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
@@ -33,9 +33,9 @@ INSERT INTO `t1` VALUES
(1),
(2);
# dump by tables order 2
-CREATE SEQUENCE `a1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
+CREATE SEQUENCE `a1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
SELECT SETVAL(`a1`, 1, 0);
-CREATE SEQUENCE `x1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
+CREATE SEQUENCE `x1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
SELECT SETVAL(`x1`, 1, 0);
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
@@ -59,9 +59,9 @@ INSERT INTO `t1` VALUES
(1),
(2);
# dump by tables only sequences
-CREATE SEQUENCE `a1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
+CREATE SEQUENCE `a1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
SELECT SETVAL(`a1`, 1, 0);
-CREATE SEQUENCE `x1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
+CREATE SEQUENCE `x1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
SELECT SETVAL(`x1`, 1, 0);
# end of dumps
DROP TABLE a1,t1,x1;
@@ -73,3 +73,145 @@ next_not_cached_value minimum_value maximum_value start_value increment cache_si
1 1 9223372036854775806 1 1 1000 0 0
unlock tables;
drop table t1;
+#
+# MDEV-28152 Features for sequence
+#
+CREATE DATABASE test1;
+CREATE DATABASE test2;
+USE test1;
+CREATE SEQUENCE s1 as tinyint;
+CREATE SEQUENCE s2 as smallint;
+CREATE SEQUENCE s3 as mediumint;
+CREATE SEQUENCE s4 as int;
+CREATE SEQUENCE s5 as bigint;
+CREATE SEQUENCE s6 as tinyint unsigned;
+CREATE SEQUENCE s7 as smallint unsigned;
+CREATE SEQUENCE s8 as mediumint unsigned;
+CREATE SEQUENCE s9 as int unsigned;
+CREATE SEQUENCE s10 as bigint unsigned;
+# Dump database 1
+# Restore from database 1 to database 2
+SETVAL(`s1`, 1, 0)
+1
+SETVAL(`s10`, 1, 0)
+1
+SETVAL(`s2`, 1, 0)
+1
+SETVAL(`s3`, 1, 0)
+1
+SETVAL(`s4`, 1, 0)
+1
+SETVAL(`s5`, 1, 0)
+1
+SETVAL(`s6`, 1, 0)
+1
+SETVAL(`s7`, 1, 0)
+1
+SETVAL(`s8`, 1, 0)
+1
+SETVAL(`s9`, 1, 0)
+1
+USE test2;
+SHOW CREATE SEQUENCE s1;
+Table Create Table
+s1 CREATE SEQUENCE `s1` as tinyint start with 1 minvalue 1 maxvalue 126 increment by 1 cache 1000 nocycle ENGINE=InnoDB
+SHOW CREATE SEQUENCE s2;
+Table Create Table
+s2 CREATE SEQUENCE `s2` as smallint start with 1 minvalue 1 maxvalue 32766 increment by 1 cache 1000 nocycle ENGINE=InnoDB
+SHOW CREATE SEQUENCE s3;
+Table Create Table
+s3 CREATE SEQUENCE `s3` as mediumint start with 1 minvalue 1 maxvalue 8388606 increment by 1 cache 1000 nocycle ENGINE=InnoDB
+SHOW CREATE SEQUENCE s4;
+Table Create Table
+s4 CREATE SEQUENCE `s4` as int start with 1 minvalue 1 maxvalue 2147483646 increment by 1 cache 1000 nocycle ENGINE=InnoDB
+SHOW CREATE SEQUENCE s5;
+Table Create Table
+s5 CREATE SEQUENCE `s5` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB
+SHOW CREATE SEQUENCE s6;
+Table Create Table
+s6 CREATE SEQUENCE `s6` as tinyint unsigned start with 1 minvalue 1 maxvalue 254 increment by 1 cache 1000 nocycle ENGINE=InnoDB
+SHOW CREATE SEQUENCE s7;
+Table Create Table
+s7 CREATE SEQUENCE `s7` as smallint unsigned start with 1 minvalue 1 maxvalue 65534 increment by 1 cache 1000 nocycle ENGINE=InnoDB
+SHOW CREATE SEQUENCE s8;
+Table Create Table
+s8 CREATE SEQUENCE `s8` as mediumint unsigned start with 1 minvalue 1 maxvalue 16777214 increment by 1 cache 1000 nocycle ENGINE=InnoDB
+SHOW CREATE SEQUENCE s9;
+Table Create Table
+s9 CREATE SEQUENCE `s9` as int unsigned start with 1 minvalue 1 maxvalue 4294967294 increment by 1 cache 1000 nocycle ENGINE=InnoDB
+SHOW CREATE SEQUENCE s10;
+Table Create Table
+s10 CREATE SEQUENCE `s10` as bigint unsigned start with 1 minvalue 1 maxvalue 18446744073709551614 increment by 1 cache 1000 nocycle ENGINE=InnoDB
+DROP DATABASE test1;
+DROP DATABASE test2;
+## test ORACLE mode
+set sql_mode=ORACLE;
+CREATE DATABASE test1;
+CREATE DATABASE test2;
+USE test1;
+CREATE SEQUENCE s1 as tinyint;
+CREATE SEQUENCE s2 as smallint;
+CREATE SEQUENCE s3 as mediumint;
+CREATE SEQUENCE s4 as int;
+CREATE SEQUENCE s5 as bigint;
+CREATE SEQUENCE s6 as tinyint unsigned;
+CREATE SEQUENCE s7 as smallint unsigned;
+CREATE SEQUENCE s8 as mediumint unsigned;
+CREATE SEQUENCE s9 as int unsigned;
+CREATE SEQUENCE s10 as bigint unsigned;
+# Dump database 1
+# Restore from database 1 to database 2
+SETVAL(`s1`, 1, 0)
+1
+SETVAL(`s10`, 1, 0)
+1
+SETVAL(`s2`, 1, 0)
+1
+SETVAL(`s3`, 1, 0)
+1
+SETVAL(`s4`, 1, 0)
+1
+SETVAL(`s5`, 1, 0)
+1
+SETVAL(`s6`, 1, 0)
+1
+SETVAL(`s7`, 1, 0)
+1
+SETVAL(`s8`, 1, 0)
+1
+SETVAL(`s9`, 1, 0)
+1
+USE test2;
+SHOW CREATE SEQUENCE s1;
+Table Create Table
+s1 CREATE SEQUENCE "s1" start with 1 minvalue 1 maxvalue 126 increment by 1 cache 1000 nocycle
+SHOW CREATE SEQUENCE s2;
+Table Create Table
+s2 CREATE SEQUENCE "s2" start with 1 minvalue 1 maxvalue 32766 increment by 1 cache 1000 nocycle
+SHOW CREATE SEQUENCE s3;
+Table Create Table
+s3 CREATE SEQUENCE "s3" start with 1 minvalue 1 maxvalue 8388606 increment by 1 cache 1000 nocycle
+SHOW CREATE SEQUENCE s4;
+Table Create Table
+s4 CREATE SEQUENCE "s4" start with 1 minvalue 1 maxvalue 2147483646 increment by 1 cache 1000 nocycle
+SHOW CREATE SEQUENCE s5;
+Table Create Table
+s5 CREATE SEQUENCE "s5" start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle
+SHOW CREATE SEQUENCE s6;
+Table Create Table
+s6 CREATE SEQUENCE "s6" start with 1 minvalue 1 maxvalue 254 increment by 1 cache 1000 nocycle
+SHOW CREATE SEQUENCE s7;
+Table Create Table
+s7 CREATE SEQUENCE "s7" start with 1 minvalue 1 maxvalue 65534 increment by 1 cache 1000 nocycle
+SHOW CREATE SEQUENCE s8;
+Table Create Table
+s8 CREATE SEQUENCE "s8" start with 1 minvalue 1 maxvalue 16777214 increment by 1 cache 1000 nocycle
+SHOW CREATE SEQUENCE s9;
+Table Create Table
+s9 CREATE SEQUENCE "s9" start with 1 minvalue 1 maxvalue 4294967294 increment by 1 cache 1000 nocycle
+SHOW CREATE SEQUENCE s10;
+Table Create Table
+s10 CREATE SEQUENCE "s10" start with 1 minvalue 1 maxvalue 18446744073709551614 increment by 1 cache 1000 nocycle
+DROP DATABASE test1;
+DROP DATABASE test2;
+set sql_mode=default;
diff --git a/mysql-test/suite/sql_sequence/mysqldump.test b/mysql-test/suite/sql_sequence/mysqldump.test
index d2afb2fd675..dab61f1bfda 100644
--- a/mysql-test/suite/sql_sequence/mysqldump.test
+++ b/mysql-test/suite/sql_sequence/mysqldump.test
@@ -35,3 +35,83 @@ LOCK TABLES t1 READ;
SELECT * FROM t1;
unlock tables;
drop table t1;
+
+
+--echo #
+--echo # MDEV-28152 Features for sequence
+--echo #
+
+CREATE DATABASE test1;
+CREATE DATABASE test2;
+USE test1;
+CREATE SEQUENCE s1 as tinyint;
+CREATE SEQUENCE s2 as smallint;
+CREATE SEQUENCE s3 as mediumint;
+CREATE SEQUENCE s4 as int;
+CREATE SEQUENCE s5 as bigint;
+CREATE SEQUENCE s6 as tinyint unsigned;
+CREATE SEQUENCE s7 as smallint unsigned;
+CREATE SEQUENCE s8 as mediumint unsigned;
+CREATE SEQUENCE s9 as int unsigned;
+CREATE SEQUENCE s10 as bigint unsigned;
+
+--echo # Dump database 1
+--exec $MYSQL_DUMP test1 > $MYSQLTEST_VARDIR/tmp/dumptest1.sql
+--echo # Restore from database 1 to database 2
+
+--exec $MYSQL test2 < $MYSQLTEST_VARDIR/tmp/dumptest1.sql
+USE test2;
+SHOW CREATE SEQUENCE s1;
+SHOW CREATE SEQUENCE s2;
+SHOW CREATE SEQUENCE s3;
+SHOW CREATE SEQUENCE s4;
+SHOW CREATE SEQUENCE s5;
+SHOW CREATE SEQUENCE s6;
+SHOW CREATE SEQUENCE s7;
+SHOW CREATE SEQUENCE s8;
+SHOW CREATE SEQUENCE s9;
+SHOW CREATE SEQUENCE s10;
+
+--remove_file $MYSQLTEST_VARDIR/tmp/dumptest1.sql
+DROP DATABASE test1;
+DROP DATABASE test2;
+
+--echo ## test ORACLE mode
+set sql_mode=ORACLE;
+
+CREATE DATABASE test1;
+CREATE DATABASE test2;
+USE test1;
+CREATE SEQUENCE s1 as tinyint;
+CREATE SEQUENCE s2 as smallint;
+CREATE SEQUENCE s3 as mediumint;
+CREATE SEQUENCE s4 as int;
+CREATE SEQUENCE s5 as bigint;
+CREATE SEQUENCE s6 as tinyint unsigned;
+CREATE SEQUENCE s7 as smallint unsigned;
+CREATE SEQUENCE s8 as mediumint unsigned;
+CREATE SEQUENCE s9 as int unsigned;
+CREATE SEQUENCE s10 as bigint unsigned;
+
+--echo # Dump database 1
+--exec $MYSQL_DUMP test1 > $MYSQLTEST_VARDIR/tmp/dumptest1.sql
+--echo # Restore from database 1 to database 2
+
+--exec $MYSQL test2 < $MYSQLTEST_VARDIR/tmp/dumptest1.sql
+USE test2;
+SHOW CREATE SEQUENCE s1;
+SHOW CREATE SEQUENCE s2;
+SHOW CREATE SEQUENCE s3;
+SHOW CREATE SEQUENCE s4;
+SHOW CREATE SEQUENCE s5;
+SHOW CREATE SEQUENCE s6;
+SHOW CREATE SEQUENCE s7;
+SHOW CREATE SEQUENCE s8;
+SHOW CREATE SEQUENCE s9;
+SHOW CREATE SEQUENCE s10;
+
+--remove_file $MYSQLTEST_VARDIR/tmp/dumptest1.sql
+DROP DATABASE test1;
+DROP DATABASE test2;
+
+set sql_mode=default;
diff --git a/mysql-test/suite/sql_sequence/next.result b/mysql-test/suite/sql_sequence/next.result
index 76f42143305..b2ec860b74f 100644
--- a/mysql-test/suite/sql_sequence/next.result
+++ b/mysql-test/suite/sql_sequence/next.result
@@ -554,7 +554,7 @@ DROP VIEW v;
create or replace sequence t1 as tinyint unsigned minvalue 1 maxvalue 2;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as tiny unsigned start with 1 minvalue 1 maxvalue 2 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` as tinyint unsigned start with 1 minvalue 1 maxvalue 2 increment by 1 cache 1000 nocycle ENGINE=MyISAM
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -581,7 +581,7 @@ ERROR HY000: Sequence 'test.t1' has run out
create or replace sequence t1 as tinyint unsigned minvalue 1 maxvalue 2 cycle;
show create sequence t1;
Table Create Table
-t1 CREATE SEQUENCE `t1` as tiny unsigned start with 1 minvalue 1 maxvalue 2 increment by 1 cache 1000 cycle ENGINE=MyISAM
+t1 CREATE SEQUENCE `t1` as tinyint unsigned start with 1 minvalue 1 maxvalue 2 increment by 1 cache 1000 cycle ENGINE=MyISAM
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -636,4 +636,214 @@ next value for t1
select next value for t1;
next value for t1
-21
+create or replace sequence t1 as bigint unsigned start with 18446744073709551614;
+select previous value for t1;
+previous value for t1
+NULL
+select next value for t1;
+next value for t1
+18446744073709551614
+select previous value for t1;
+previous value for t1
+18446744073709551614
+create or replace sequence t1 as tinyint start with 126;
+select next value for t1;
+next value for t1
+126
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+1
+create or replace sequence t1 as tinyint unsigned start with 254;
+select next value for t1;
+next value for t1
+254
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+1
+create or replace sequence t1 as smallint start with 32766;
+select next value for t1;
+next value for t1
+32766
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+1
+create or replace sequence t1 as smallint unsigned start with 65534;
+select next value for t1;
+next value for t1
+65534
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+1
+create or replace sequence t1 as mediumint start with 8388606;
+select next value for t1;
+next value for t1
+8388606
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+1
+create or replace sequence t1 as mediumint unsigned start with 16777214;
+select next value for t1;
+next value for t1
+16777214
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+1
+create or replace sequence t1 as int start with 2147483646;
+select next value for t1;
+next value for t1
+2147483646
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+1
+create or replace sequence t1 as int unsigned start with 4294967294;
+select next value for t1;
+next value for t1
+4294967294
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+1
+create or replace sequence t1 as bigint start with 9223372036854775806;
+select next value for t1;
+next value for t1
+9223372036854775806
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+1
+create or replace sequence t1 as bigint unsigned start with 18446744073709551614;
+select next value for t1;
+next value for t1
+18446744073709551614
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+1
+create or replace sequence t1 as tinyint start with -127 increment -1;
+select next value for t1;
+next value for t1
+-127
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+-1
+create or replace sequence t1 as tinyint unsigned start with 1 increment -1;
+select next value for t1;
+next value for t1
+1
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+254
+create or replace sequence t1 as smallint start with -32767 increment -1;
+select next value for t1;
+next value for t1
+-32767
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+-1
+create or replace sequence t1 as smallint unsigned start with 1 increment -1;
+select next value for t1;
+next value for t1
+1
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+65534
+create or replace sequence t1 as mediumint start with -8388607 increment -1;
+select next value for t1;
+next value for t1
+-8388607
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+-1
+create or replace sequence t1 as mediumint unsigned start with 1 increment -1;
+select next value for t1;
+next value for t1
+1
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+16777214
+create or replace sequence t1 as int start with -2147483647 increment -1;
+select next value for t1;
+next value for t1
+-2147483647
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+-1
+create or replace sequence t1 as int unsigned start with 1 increment -1;
+select next value for t1;
+next value for t1
+1
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+4294967294
+create or replace sequence t1 as bigint start with -9223372036854775807 increment -1;
+select next value for t1;
+next value for t1
+-9223372036854775807
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+-1
+create or replace sequence t1 as bigint unsigned start with 1 increment -1;
+select next value for t1;
+next value for t1
+1
+select next value for t1;
+ERROR HY000: Sequence 'test.t1' has run out
+alter sequence t1 cycle;
+select next value for t1;
+next value for t1
+18446744073709551614
drop sequence t1;
diff --git a/mysql-test/suite/sql_sequence/next.test b/mysql-test/suite/sql_sequence/next.test
index f2054e5f116..62caad8e215 100644
--- a/mysql-test/suite/sql_sequence/next.test
+++ b/mysql-test/suite/sql_sequence/next.test
@@ -329,4 +329,150 @@ 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;
+
+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;
diff --git a/mysql-test/suite/sql_sequence/replication.result b/mysql-test/suite/sql_sequence/replication.result
index 2cfc246f2bf..94b1c72b9e0 100644
--- a/mysql-test/suite/sql_sequence/replication.result
+++ b/mysql-test/suite/sql_sequence/replication.result
@@ -149,7 +149,7 @@ CREATE TABLE `s2` (
) ENGINE=myisam DEFAULT CHARSET=latin1 sequence=1;
show create sequence s2;
Table Create Table
-s2 CREATE SEQUENCE `s2` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+s2 CREATE SEQUENCE `s2` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
drop sequence s2;
###########################################
select sequence syntax test
@@ -188,7 +188,7 @@ alter table s2 rename to s2_1;
rename table s2_1 to s2_2;
show create sequence s2_2;
Table Create Table
-s2_2 CREATE SEQUENCE `s2_2` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
+s2_2 CREATE SEQUENCE `s2_2` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
select * from s2_2;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1 1 9223372036854775806 1 1 1000 0 0
diff --git a/mysql-test/suite/sql_sequence/setval.result b/mysql-test/suite/sql_sequence/setval.result
index 504d460fea5..598c7395423 100644
--- a/mysql-test/suite/sql_sequence/setval.result
+++ b/mysql-test/suite/sql_sequence/setval.result
@@ -269,3 +269,152 @@ SETVAL(s, 10)
10
DROP SEQUENCE s;
# End of 10.3 tests
+#
+# MDEV-28152 Features for sequence
+#
+create sequence s;
+select setval(s, 12345678901234567890);
+setval(s, 12345678901234567890)
+NULL
+select nextval(s);
+nextval(s)
+1
+drop sequence s;
+create sequence s increment -1;
+select setval(s, 12345678901234567890);
+setval(s, 12345678901234567890)
+NULL
+select nextval(s);
+nextval(s)
+-1
+drop sequence s;
+create sequence s as smallint;
+select setval(s, 55555);
+setval(s, 55555)
+NULL
+select setval(s, -55555);
+setval(s, -55555)
+NULL
+select nextval(s);
+nextval(s)
+1
+drop sequence s;
+create sequence s as smallint increment -1;
+select setval(s, 55555);
+setval(s, 55555)
+NULL
+select setval(s, -55555);
+setval(s, -55555)
+NULL
+select nextval(s);
+nextval(s)
+-1
+drop sequence s;
+create sequence s as bigint unsigned;
+select setval(s, -123);
+setval(s, -123)
+NULL
+select nextval(s);
+nextval(s)
+1
+drop sequence s;
+create sequence s as bigint unsigned increment -1;
+select setval(s, -123);
+setval(s, -123)
+NULL
+select nextval(s);
+nextval(s)
+18446744073709551614
+drop sequence s;
+create sequence s as bigint unsigned;
+select setval(s, -123);
+setval(s, -123)
+NULL
+select setval(s, 0);
+setval(s, 0)
+0
+select nextval(s);
+nextval(s)
+1
+select setval(s, 12345678901234567890);
+setval(s, 12345678901234567890)
+12345678901234567890
+select nextval(s);
+nextval(s)
+12345678901234567891
+select setval(s, 12345678901234567890);
+setval(s, 12345678901234567890)
+NULL
+select nextval(s);
+nextval(s)
+12345678901234567892
+select setval(s, 18446744073709551614, 0);
+setval(s, 18446744073709551614, 0)
+18446744073709551614
+select nextval(s);
+nextval(s)
+18446744073709551614
+select nextval(s);
+ERROR HY000: Sequence 'test.s' has run out
+select setval(s, 12345678901234567890, 0, 1);
+ERROR HY000: Sequence 'test.s' has run out
+alter sequence s cycle;
+select setval(s, 12345678901234567890, 0, 1);
+setval(s, 12345678901234567890, 0, 1)
+12345678901234567890
+select nextval(s);
+nextval(s)
+12345678901234567890
+drop sequence s;
+create sequence s as bigint unsigned;
+select setval(s, 18446744073709551616);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '18446744073709551616)' at line 1
+select setval(s, 18446744073709551615);
+setval(s, 18446744073709551615)
+18446744073709551615
+select nextval(s);
+ERROR HY000: Sequence 'test.s' has run out
+drop sequence s;
+create sequence s as bigint unsigned;
+select setval(s, 18446744073709551615, 0);
+setval(s, 18446744073709551615, 0)
+18446744073709551615
+select nextval(s);
+ERROR HY000: Sequence 'test.s' has run out
+drop sequence s;
+create sequence s as bigint unsigned cycle;
+select setval(s, 18446744073709551615);
+setval(s, 18446744073709551615)
+18446744073709551615
+select nextval(s);
+nextval(s)
+1
+drop sequence s;
+create sequence s as bigint unsigned cycle;
+select setval(s, 18446744073709551615, 0);
+setval(s, 18446744073709551615, 0)
+18446744073709551615
+select nextval(s);
+nextval(s)
+1
+drop sequence s;
+create sequence s as bigint unsigned minvalue 123 maxvalue 456;
+select setval(s, 100);
+setval(s, 100)
+NULL
+select nextval(s);
+nextval(s)
+123
+select setval(s, 500);
+setval(s, 500)
+500
+select nextval(s);
+ERROR HY000: Sequence 'test.s' has run out
+drop sequence s;
+create sequence s as smallint;
+select setval(s, 32767);
+setval(s, 32767)
+32767
+select nextval(s);
+ERROR HY000: Sequence 'test.s' has run out
+drop sequence s;
diff --git a/mysql-test/suite/sql_sequence/setval.test b/mysql-test/suite/sql_sequence/setval.test
index 1993bdbe077..b45533f63d1 100644
--- a/mysql-test/suite/sql_sequence/setval.test
+++ b/mysql-test/suite/sql_sequence/setval.test
@@ -154,3 +154,100 @@ 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;
diff --git a/mysql-test/suite/sql_sequence/slave_nextval.result b/mysql-test/suite/sql_sequence/slave_nextval.result
index 36efa85d920..bfbc472e117 100644
--- a/mysql-test/suite/sql_sequence/slave_nextval.result
+++ b/mysql-test/suite/sql_sequence/slave_nextval.result
@@ -4,7 +4,7 @@ CREATE SEQUENCE s;
INSERT INTO s VALUES (1,1,4,1,1,1,0,0);
show create sequence s;
Table Create Table
-s CREATE SEQUENCE `s` as bigint start with 1 minvalue 1 maxvalue 4 increment by 1 cache 1 nocycle ENGINE=MyISAM
+s CREATE SEQUENCE `s` start with 1 minvalue 1 maxvalue 4 increment by 1 cache 1 nocycle ENGINE=MyISAM
SELECT NEXTVAL(s);
NEXTVAL(s)
1
@@ -38,7 +38,7 @@ CREATE SEQUENCE s;
INSERT INTO s VALUES (1,1,3,1,1,1,1,0);
show create sequence s;
Table Create Table
-s CREATE SEQUENCE `s` as bigint start with 1 minvalue 1 maxvalue 3 increment by 1 cache 1 cycle ENGINE=MyISAM
+s CREATE SEQUENCE `s` start with 1 minvalue 1 maxvalue 3 increment by 1 cache 1 cycle ENGINE=MyISAM
SELECT NEXTVAL(s);
NEXTVAL(s)
1
diff --git a/sql/item_func.cc b/sql/item_func.cc
index a07595cbbd8..cca4d9e2536 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -7192,8 +7192,20 @@ longlong Item_func_setval::val_int()
DBUG_RETURN(0);
}
- value= nextval;
- error= table->s->sequence->set_value(table, nextval, round, is_used);
+ /*
+ Truncate nextval according to the value type of the sequence if
+ out of bounds. If truncation happens i.e. nextval is out of
+ bounds for the value type, return null immediately.
+ */
+ value= table->s->sequence->truncate_value(nextval);
+ if (value != nextval.value())
+ {
+ null_value= 1;
+ value= 0;
+ DBUG_RETURN(0);
+ }
+ unsigned_flag= table->s->sequence->is_unsigned;
+ error= table->s->sequence->set_value(table, value, round, is_used);
if (unlikely(error))
{
null_value= 1;
@@ -7241,7 +7253,10 @@ void Item_func_setval::print(String *str, enum_query_type query_type)
}
append_identifier(thd, str, &t_name);
str->append(',');
- str->append_longlong(nextval);
+ if (nextval.is_unsigned())
+ str->append_ulonglong(nextval.value());
+ else
+ str->append_longlong(nextval.value());
str->append(',');
str->append_longlong(is_used);
str->append(',');
diff --git a/sql/item_func.h b/sql/item_func.h
index 520dbdc90c7..9a17ebdb9ef 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -4136,7 +4136,8 @@ public:
}
bool fix_length_and_dec(THD *thd) override
{
- unsigned_flag= 0;
+ if (table_list->table)
+ unsigned_flag= table_list->table->s->sequence->is_unsigned;
max_length= MAX_BIGINT_WIDTH;
set_maybe_null(); /* In case of errors */
return FALSE;
@@ -4190,11 +4191,11 @@ public:
class Item_func_setval :public Item_func_nextval
{
- longlong nextval;
+ Longlong_hybrid nextval;
ulonglong round;
bool is_used;
public:
- Item_func_setval(THD *thd, TABLE_LIST *table_list_arg, longlong nextval_arg,
+ Item_func_setval(THD *thd, TABLE_LIST *table_list_arg, Longlong_hybrid nextval_arg,
ulonglong round_arg, bool is_used_arg)
: Item_func_nextval(thd, table_list_arg),
nextval(nextval_arg), round(round_arg), is_used(is_used_arg)
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index 65a7e613b72..79966ac9a05 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -10076,3 +10076,11 @@ ER_CM_OPTION_MISSING_REQUIREMENT
eng "CHANGE MASTER TO option '%s=%s' is missing requirement %s"
ER_SLAVE_STATEMENT_TIMEOUT 70100
eng "Slave log event execution was interrupted (slave_max_statement_time exceeded)"
+ER_SEQUENCE_TABLE_HAS_WRONG_NUMBER_OF_COLUMNS
+ eng "Wrong number of columns"
+ER_SEQUENCE_TABLE_CANNOT_HAVE_ANY_KEYS
+ eng "Sequence tables cannot have any keys"
+ER_SEQUENCE_TABLE_CANNOT_HAVE_ANY_CONSTRAINTS
+ eng "Sequence tables cannot have any constraints"
+ER_SEQUENCE_TABLE_ORDER_BY
+ eng "ORDER BY"
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index e3f486486d7..6645f8a0c77 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -8230,7 +8230,7 @@ Item *LEX::create_item_func_lastval(THD *thd,
Item *LEX::create_item_func_setval(THD *thd, Table_ident *table_ident,
- longlong nextval, ulonglong round,
+ Longlong_hybrid nextval, ulonglong round,
bool is_used)
{
TABLE_LIST *table;
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 95ed308103d..0d8dd837542 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -4093,8 +4093,9 @@ public:
/*
Create an item for "SETVAL(sequence_name, value [, is_used [, round]])
*/
- Item *create_item_func_setval(THD *thd, Table_ident *ident, longlong value,
- ulonglong round, bool is_used);
+ Item *create_item_func_setval(THD *thd, Table_ident *ident,
+ Longlong_hybrid value, ulonglong round,
+ bool is_used);
/*
Create an item for a name in LIMIT clause: LIMIT var
diff --git a/sql/sql_sequence.cc b/sql/sql_sequence.cc
index c5754dc9670..0dcb9980928 100644
--- a/sql/sql_sequence.cc
+++ b/sql/sql_sequence.cc
@@ -30,45 +30,56 @@
#include "wsrep_mysqld.h"
#endif
-/*
- Structure for all SEQUENCE tables
+#define MAX_AUTO_INCREMENT_VALUE 65535
- Note that the first field is named "next_val" to all us to have
- NEXTVAL a reserved word that will on access be changed to
- NEXTVAL(sequence_table). For this to work, the table can't have
- a column named NEXTVAL.
-*/
+/**
+ Structure for SEQUENCE tables of a certain value type
-#define MAX_AUTO_INCREMENT_VALUE 65535
+ @param in handler The handler of a sequence value type
+ @return The sequence table structure given the value type
+*/
Sequence_row_definition sequence_structure(const Type_handler* handler)
{
- // We don't really care about src because it is unused in max_display_length_for_field().
+ /*
+ We don't really care about src because it is unused in
+ max_display_length_for_field().
+ */
const Conv_source src(handler, 0, system_charset_info);
const uint32 len= handler->max_display_length_for_field(src) + 1;
const LEX_CSTRING empty= {STRING_WITH_LEN("")};
const uint flag_unsigned= handler->is_unsigned() ? UNSIGNED_FLAG : 0;
-#define FL (NOT_NULL_FLAG | NO_DEFAULT_VALUE_FLAG)
-#define FLV (NOT_NULL_FLAG | NO_DEFAULT_VALUE_FLAG | flag_unsigned)
- return {{{"next_not_cached_value", len, handler, empty, FLV},
- {"minimum_value", len, handler, empty, FLV},
- {"maximum_value", len, handler, empty, FLV},
+#define FNND (NOT_NULL_FLAG | NO_DEFAULT_VALUE_FLAG)
+#define FNNDFU (NOT_NULL_FLAG | NO_DEFAULT_VALUE_FLAG | flag_unsigned)
+ return {{{"next_not_cached_value", len, handler, empty, FNNDFU},
+ {"minimum_value", len, handler, empty, FNNDFU},
+ {"maximum_value", len, handler, empty, FNNDFU},
{"start_value", len, handler,
{STRING_WITH_LEN("start value when sequences is created or value "
- "if RESTART is used")}, FLV},
+ "if RESTART is used")}, FNNDFU},
{"increment", 21, &type_handler_slonglong,
- {STRING_WITH_LEN("increment value")}, FL},
+ {STRING_WITH_LEN("increment value")}, FNND},
{"cache_size", 21, &type_handler_ulonglong, empty,
- FL | UNSIGNED_FLAG},
+ FNND | UNSIGNED_FLAG},
{"cycle_option", 1, &type_handler_utiny,
- {STRING_WITH_LEN("0 if no cycles are allowed, 1 if the sequence " "should begin a new cycle when maximum_value is " "passed")}, FL | UNSIGNED_FLAG},
+ {STRING_WITH_LEN("0 if no cycles are allowed, 1 if the sequence "
+ "should begin a new cycle when maximum_value is "
+ "passed")}, FNND | UNSIGNED_FLAG},
{"cycle_count", 21, &type_handler_slonglong,
- {STRING_WITH_LEN("How many cycles have been done")}, FL},
+ {STRING_WITH_LEN("How many cycles have been done")}, FNND},
{NULL, 0, &type_handler_slonglong, {STRING_WITH_LEN("")}, 0}}};
-#undef FLV
-#undef FL
+#undef FNNDFU
+#undef FNND
}
+/**
+ Whether a type is allowed as a sequence value type.
+
+ @param in type The type to check
+
+ @retval true allowed
+ false not allowed
+*/
bool sequence_definition::is_allowed_value_type(enum_field_types type)
{
switch (type)
@@ -84,72 +95,101 @@ bool sequence_definition::is_allowed_value_type(enum_field_types type)
}
}
+/*
+ Get the type handler for the value type of a sequence.
+*/
Type_handler const *sequence_definition::value_type_handler()
{
- const Type_handler *handler= Type_handler::get_handler_by_field_type(value_type);
+ const Type_handler *handler=
+ Type_handler::get_handler_by_field_type(value_type);
return is_unsigned ? handler->type_handler_unsigned() : handler;
}
+/*
+ Get the upper bound for a sequence value type.
+*/
longlong sequence_definition::value_type_max()
{
- // value_type != MYSQL_TYPE_LONGLONG to avoid undefined behaviour
- // https://stackoverflow.com/questions/9429156/by-left-shifting-can-a-number-be-set-to-zero
+ /*
+ Use value_type != MYSQL_TYPE_LONGLONG to avoid undefined behaviour
+ https://stackoverflow.com/questions/9429156/by-left-shifting-can-a-number-be-set-to-zero
+ */
return is_unsigned && value_type != MYSQL_TYPE_LONGLONG ?
~(~0ULL << 8 * value_type_handler()->calc_pack_length(0)) :
~value_type_min();
}
+/*
+ Get the lower bound for a sequence value type.
+*/
longlong sequence_definition::value_type_min() {
return is_unsigned ? 0 :
~0ULL << (8 * value_type_handler()->calc_pack_length(0) - 1);
}
-/*
- Truncate `original` to `result`.
- If `original` is greater than value_type_max(), truncate down to value_type_max()
- If `original` is less than value_type_min(), truncate up to value_type_min()
+/**
+ Truncate a Longlong_hybrid.
+
+ If `original` is greater than value_type_max(), truncate down to
+ value_type_max()
+
+ If `original` is less than value_type_min(), truncate up to
+ value_type_min()
+
+ Whenever a truncation happens, the resulting value is just out of
+ bounds for sequence values because value_type_max() is the maximum
+ possible sequence value + 1, and the same applies to
+ value_type_min().
+
+ @param in original The value to truncate
+
+ @return The truncated value
*/
longlong sequence_definition::truncate_value(const Longlong_hybrid& original)
{
if (is_unsigned)
return original.to_ulonglong(value_type_max());
- else if (original.is_unsigned_outside_of_signed_range())
+ if (original.is_unsigned_outside_of_signed_range())
return value_type_max();
- else
- return original.value() > value_type_max() ? value_type_max()
- : original.value() < value_type_min() ? value_type_min()
- : original.value();
+ const longlong value= original.value();
+ return (value > value_type_max() ? value_type_max() :
+ value < value_type_min() ? value_type_min() : value);
}
-/*
+/**
Check whether sequence values are valid.
+
Sets default values for fields that are not used, according to Oracle spec.
- RETURN VALUES
- false valid
- true invalid
+ @param in thd The connection
+ @param in set_reserved_until Whether to set reserved_until to start
+
+ @retval false valid
+ true invalid
*/
-
-// from_parser: whether to check foo_from_parser or foo, where foo in
-// {min_value, max_value, ...}
bool sequence_definition::check_and_adjust(THD *thd, bool set_reserved_until)
{
- longlong max_increment;
DBUG_ENTER("sequence_definition::check_and_adjust");
+ /* Easy error to detect. */
+ if (!is_allowed_value_type(value_type) || cache < 0)
+ DBUG_RETURN(TRUE);
+
if (!(real_increment= increment))
real_increment= global_system_variables.auto_increment_increment;
/*
- If min_value is not set, set it to value_type_min()+1 or 1, depending on
- real_increment
+ If min_value is not set, in case of signed sequence, set it to
+ value_type_min()+1 or 1, depending on real_increment, and in case
+ of unsigned sequence, set it to value_type_min()+1
*/
if (!(used_fields & seq_field_specified_min_value))
- min_value= real_increment < 0 ? value_type_min()+1 : 1;
+ min_value= real_increment < 0 || is_unsigned ? value_type_min()+1 : 1;
else
{
min_value= truncate_value(min_value_from_parser);
- if ((is_unsigned && (ulonglong) min_value <= (ulonglong) value_type_min()) ||
+ if ((is_unsigned &&
+ (ulonglong) min_value <= (ulonglong) value_type_min()) ||
(!is_unsigned && min_value <= value_type_min()))
{
push_warning_printf(
@@ -160,15 +200,17 @@ bool sequence_definition::check_and_adjust(THD *thd, bool set_reserved_until)
}
/*
- If max_value is not set, set it to value_type_max()-1 or -1, depending on
- real_increment
+ If max_value is not set, in case of signed sequence set it to
+ value_type_max()-1 or -1, depending on real_increment, and in case
+ of unsigned sequence, set it to value_type_max()-1
*/
if (!(used_fields & seq_field_specified_max_value))
- max_value= real_increment < 0 ? -1 : value_type_max()-1;
+ max_value= real_increment > 0 || is_unsigned ? value_type_max()-1 : -1;
else
{
max_value= truncate_value(max_value_from_parser);
- if ((is_unsigned && (ulonglong) max_value >= (ulonglong) value_type_max()) ||
+ if ((is_unsigned &&
+ (ulonglong) max_value >= (ulonglong) value_type_max()) ||
(!is_unsigned && max_value >= value_type_max()))
{
push_warning_printf(
@@ -183,12 +225,14 @@ bool sequence_definition::check_and_adjust(THD *thd, bool set_reserved_until)
/* Use min_value or max_value for start depending on real_increment */
start= real_increment < 0 ? max_value : min_value;
} else
- // If the supplied start value is out of range for the value type,
- // instead of immediately reporting error, we truncate it to
- // value_type_min or value_type_max depending on which side it is
- // one. Whenever such truncation happens, the condition that
- // max_value >= start >= min_value will be violated, and the error
- // will be reported then.
+ /*
+ If the supplied start value is out of range for the value type,
+ instead of immediately reporting error, we truncate it to
+ value_type_min or value_type_max depending on which side it is
+ one. Whenever such truncation happens, the condition that
+ max_value >= start >= min_value will be violated, and the error
+ will be reported then.
+ */
start= truncate_value(start_from_parser);
if (set_reserved_until)
@@ -197,27 +241,31 @@ bool sequence_definition::check_and_adjust(THD *thd, bool set_reserved_until)
adjust_values(reserved_until);
/* To ensure that cache * real_increment will never overflow */
- max_increment= (real_increment ?
- llabs(real_increment) :
- MAX_AUTO_INCREMENT_VALUE);
+ const longlong max_increment= (real_increment ?
+ llabs(real_increment) :
+ MAX_AUTO_INCREMENT_VALUE);
- // Common case for error, signed or unsigned.
- if (!is_allowed_value_type(value_type) || cache < 0)
+ /*
+ To ensure that cache * real_increment will never overflow. See the
+ calculation of add_to below in SEQUENCE::next_value(). We need
+ this for unsigned too, because otherwise we will need to handle
+ add_to as an equivalent of Longlong_hybrid type in
+ SEQUENCE::increment_value().
+ */
+ if (cache >= (LONGLONG_MAX - max_increment) / max_increment)
DBUG_RETURN(TRUE);
-
- // TODO: check for cache < (ULONGLONG_MAX - max_increment) / max_increment
+
if (is_unsigned && (ulonglong) max_value >= (ulonglong) start &&
(ulonglong) max_value > (ulonglong) min_value &&
(ulonglong) start >= (ulonglong) min_value &&
- // Just like the case in signed, where a positive sequence
- // cannot have a negatvie increment, an unsigned sequence is
- // positive, so the increment has to be positive
- (real_increment > 0 && (ulonglong) reserved_until >= (ulonglong) min_value))
+ ((real_increment > 0 &&
+ (ulonglong) reserved_until >= (ulonglong) min_value) ||
+ (real_increment < 0 &&
+ (ulonglong) reserved_until <= (ulonglong) max_value)))
DBUG_RETURN(FALSE);
-
+
if (!is_unsigned && max_value >= start && max_value > min_value &&
start >= min_value &&
- cache < (LONGLONG_MAX - max_increment) / max_increment &&
((real_increment > 0 && reserved_until >= min_value) ||
(real_increment < 0 && reserved_until <= max_value)))
DBUG_RETURN(FALSE);
@@ -297,28 +345,28 @@ bool check_sequence_fields(LEX *lex, List<Create_field> *fields)
field_count= fields->elements;
if (!field_count)
{
- reason= "Wrong number of columns";
+ reason= my_get_err_msg(ER_SEQUENCE_TABLE_HAS_WRONG_NUMBER_OF_COLUMNS);
goto err;
}
row_structure= sequence_structure(fields->head()->type_handler());
if (field_count != array_elements(row_structure.fields)-1)
{
- reason= "Wrong number of columns";
+ reason= my_get_err_msg(ER_SEQUENCE_TABLE_HAS_WRONG_NUMBER_OF_COLUMNS);
goto err;
}
if (lex->alter_info.key_list.elements > 0)
{
- reason= "Sequence tables cannot have any keys";
+ reason= my_get_err_msg(ER_SEQUENCE_TABLE_CANNOT_HAVE_ANY_KEYS);
goto err;
}
if (lex->alter_info.check_constraint_list.elements > 0)
{
- reason= "Sequence tables cannot have any constraints";
+ reason= my_get_err_msg(ER_SEQUENCE_TABLE_CANNOT_HAVE_ANY_CONSTRAINTS);
goto err;
}
if (lex->alter_info.flags & ALTER_ORDER)
{
- reason= "ORDER BY";
+ reason= my_get_err_msg(ER_SEQUENCE_TABLE_ORDER_BY);
goto err;
}
@@ -353,10 +401,12 @@ err:
true Failure (out of memory)
*/
-bool sequence_definition::prepare_sequence_fields(List<Create_field> *fields, bool alter)
+bool sequence_definition::prepare_sequence_fields(List<Create_field> *fields,
+ bool alter)
{
DBUG_ENTER("prepare_sequence_fields");
- const Sequence_row_definition row_def= sequence_structure(value_type_handler());
+ const Sequence_row_definition row_def=
+ sequence_structure(value_type_handler());
for (const Sequence_field_definition *field_info= row_def.fields;
field_info->field_name; field_info++)
@@ -480,7 +530,7 @@ bool sequence_insert(THD *thd, LEX *lex, TABLE_LIST *org_table_list)
{
seq->value_type= (*table->s->field)->type();
seq->is_unsigned= (*table->s->field)->is_unsigned();
- // fixme: why do we need true here?
+ /* We set reserved_until when creating a new sequence. */
if (seq->check_and_adjust(thd, true))
DBUG_RETURN(TRUE);
}
@@ -701,15 +751,26 @@ void sequence_definition::adjust_values(longlong next_value)
/*
Check if add will make next_free_value bigger than max_value,
taken into account that next_free_value or max_value addition
- may overflow
+ may overflow.
+
+ 0 <= to_add <= auto_increment_increment <= 65535 so we do not
+ need to cast to_add.
*/
- if (next_free_value > max_value - to_add ||
- next_free_value + to_add > max_value)
+ if ((is_unsigned &&
+ (ulonglong) next_free_value > (ulonglong) max_value - to_add) ||
+ (is_unsigned &&
+ (ulonglong) next_free_value + to_add > (ulonglong) max_value) ||
+ (!is_unsigned && next_free_value > max_value - to_add) ||
+ (!is_unsigned && next_free_value + to_add > max_value))
next_free_value= max_value+1;
else
{
next_free_value+= to_add;
- DBUG_ASSERT(llabs(next_free_value % real_increment) == offset);
+ if (is_unsigned)
+ DBUG_ASSERT((ulonglong) next_free_value % real_increment ==
+ (ulonglong) offset);
+ else
+ DBUG_ASSERT(llabs(next_free_value % real_increment) == offset);
}
}
}
@@ -833,7 +894,8 @@ longlong SEQUENCE::next_value(TABLE *table, bool second_round, int *error)
res_value= next_free_value;
next_free_value= increment_value(next_free_value, real_increment);
- if (within_bounds(res_value, reserved_until, reserved_until, real_increment > 0))
+ if (within_bound(res_value, reserved_until, reserved_until,
+ real_increment > 0))
{
write_unlock(table);
DBUG_RETURN(res_value);
@@ -851,9 +913,9 @@ longlong SEQUENCE::next_value(TABLE *table, bool second_round, int *error)
*/
add_to= cache ? real_increment * cache : real_increment;
- // TODO: consider extracting this refactoring to a separate earlier commit.
reserved_until= increment_value(reserved_until, add_to);
- out_of_values= !within_bounds(res_value, max_value + 1, min_value - 1, add_to > 0);
+ out_of_values= !within_bound(res_value, max_value + 1, min_value - 1,
+ add_to > 0);
if (out_of_values)
{
if (!cycle || second_round)
@@ -948,9 +1010,8 @@ int SEQUENCE::set_value(TABLE *table, longlong next_val, ulonglong next_round,
goto end; // error = -1
if (round == next_round)
{
- if (real_increment > 0 ?
- next_val < next_free_value :
- next_val > next_free_value)
+ if (within_bound(next_val, next_free_value, next_free_value,
+ real_increment > 0))
goto end; // error = -1
if (next_val == next_free_value)
{
@@ -971,9 +1032,8 @@ int SEQUENCE::set_value(TABLE *table, longlong next_val, ulonglong next_round,
round= next_round;
adjust_values(next_val);
- if ((real_increment > 0 ?
- next_free_value > reserved_until :
- next_free_value < reserved_until) ||
+ if (within_bound(reserved_until, next_free_value, next_free_value,
+ real_increment > 0) ||
needs_to_be_stored)
{
reserved_until= next_free_value;
@@ -1032,10 +1092,8 @@ bool Sql_cmd_alter_sequence::execute(THD *thd)
if (new_seq->used_fields & seq_field_used_as)
{
- // This shouldn't happen as it should have been prevented during
- // parsing.
- if (new_seq->used_fields - seq_field_used_as)
- DBUG_RETURN(TRUE);
+ /* This should have been prevented during parsing. */
+ DBUG_ASSERT(!(new_seq->used_fields - seq_field_used_as));
first_table->lock_type= TL_READ_NO_INSERT;
first_table->mdl_request.set_type(MDL_SHARED_NO_WRITE);
@@ -1048,13 +1106,15 @@ bool Sql_cmd_alter_sequence::execute(THD *thd)
create_info.alter_info= &alter_info;
if (if_exists())
thd->push_internal_handler(&no_such_table_handler);
- error= mysql_alter_table(thd, &null_clex_str, &null_clex_str, &create_info, first_table, &alter_info, 0, (ORDER *) 0, 0, 0);
+ error= mysql_alter_table(thd, &null_clex_str, &null_clex_str,
+ &create_info, first_table, &alter_info, 0,
+ (ORDER *) 0, 0, 0);
if (if_exists())
{
trapped_errors= no_such_table_handler.safely_trapped_errors();
thd->pop_internal_handler();
}
- // Do we need to store the sequence value in table share, like below?
+ /* Do we need to store the sequence value in table share, like below? */
DBUG_RETURN(error);
}
@@ -1093,31 +1153,37 @@ bool Sql_cmd_alter_sequence::execute(THD *thd)
/* Copy from old sequence those fields that the user didn't specified */
if (!(new_seq->used_fields & seq_field_used_increment))
new_seq->increment= seq->increment;
+ /*
+ We need to assign to foo_from_parser so that things get handled
+ properly in check_and_adjust() later
+ */
if (!(new_seq->used_fields & seq_field_used_min_value))
- new_seq->min_value_from_parser= seq->min_value_from_parser;
+ new_seq->min_value_from_parser= Longlong_hybrid(seq->min_value, seq->is_unsigned);
if (!(new_seq->used_fields & seq_field_used_max_value))
- new_seq->max_value_from_parser= seq->max_value_from_parser;
+ new_seq->max_value_from_parser= Longlong_hybrid(seq->max_value, seq->is_unsigned);
if (!(new_seq->used_fields & seq_field_used_start))
- new_seq->start_from_parser= seq->start_from_parser;
+ new_seq->start_from_parser= Longlong_hybrid(seq->start, seq->is_unsigned);
if (!(new_seq->used_fields & seq_field_used_cache))
new_seq->cache= seq->cache;
if (!(new_seq->used_fields & seq_field_used_cycle))
new_seq->cycle= seq->cycle;
- if (!(new_seq->used_fields & seq_field_used_as))
- {
- new_seq->value_type= seq->value_type;
- new_seq->is_unsigned= seq->is_unsigned;
- }
+ /* This should have been prevented during parsing. */
+ DBUG_ASSERT(!(new_seq->used_fields & seq_field_used_as));
+ new_seq->value_type= seq->value_type;
+ new_seq->is_unsigned= seq->is_unsigned;
/* If we should restart from a new value */
if (new_seq->used_fields & seq_field_used_restart)
{
if (!(new_seq->used_fields & seq_field_used_restart_value))
new_seq->restart_from_parser= new_seq->start_from_parser;
- // Similar to start, we just need to truncate reserved_until and
- // the errors will be reported in check_and_adjust if truncation
- // happens on the wrong end.
- new_seq->reserved_until= new_seq->truncate_value(new_seq->restart_from_parser);
+ /*
+ Similar to start, we just need to truncate reserved_until and
+ the errors will be reported in check_and_adjust if truncation
+ happens on the wrong end.
+ */
+ new_seq->reserved_until=
+ new_seq->truncate_value(new_seq->restart_from_parser);
}
/* Let check_and_adjust think all fields are used */
diff --git a/sql/sql_sequence.h b/sql/sql_sequence.h
index 0de92a90639..4b3f102509b 100644
--- a/sql/sql_sequence.h
+++ b/sql/sql_sequence.h
@@ -64,10 +64,13 @@ public:
sequence_definition():
min_value_from_parser(1, false),
max_value_from_parser(LONGLONG_MAX-1, false), start_from_parser(1, false),
- increment(1), cache(1000), round(0), restart_from_parser(0, false), cycle(0), used_fields(0),
- // We use value type and is_unsigned instead of a handler because
- // Type_handler is incomplete, which we cannot initialise here
- // with &type_handler_slonglong.
+ increment(1), cache(1000), round(0), restart_from_parser(0, false),
+ cycle(0), used_fields(0),
+ /*
+ We use value type and is_unsigned instead of a handler because
+ Type_handler is incomplete, which we cannot initialise here with
+ &type_handler_slonglong.
+ */
value_type(MYSQL_TYPE_LONGLONG), is_unsigned(false)
{}
longlong reserved_until;
@@ -80,7 +83,6 @@ public:
longlong increment;
longlong cache;
ulonglong round;
- // TODO: allow unsigned in restart
longlong restart; // alter sequence restart value
Longlong_hybrid restart_from_parser;
bool cycle;
@@ -89,9 +91,9 @@ public:
bool is_unsigned;
Type_handler const *value_type_handler();
- // max value for the value type, e.g. 32767 for smallint.
+ /* max value for the value type, e.g. 32767 for smallint. */
longlong value_type_max();
- // min value for the value type, e.g. -32768 for smallint.
+ /* min value for the value type, e.g. -32768 for smallint. */
longlong value_type_min();
bool check_and_adjust(THD *thd, bool set_reserved_until);
void store_fields(TABLE *table);
@@ -151,7 +153,28 @@ public:
longlong next_value(TABLE *table, bool second_round, int *error);
int set_value(TABLE *table, longlong next_value, ulonglong round_arg,
bool is_used);
- bool within_bounds(const longlong value, const longlong upper, const longlong lower, bool increasing)
+
+ bool all_values_used;
+ seq_init initialized;
+
+private:
+ /**
+ Check that a value is within a relevant bound
+
+ If increasing sequence, check that the value is lower than an
+ upper bound, otherwise check that the value is higher than a lower
+ bound.
+
+ @param in value The value to check
+ @param in upper The upper bound
+ @param in lower The lower bound
+ @param in increasing Which bound to check
+
+ @retval true The value is within the bound.
+ false The value is out of the bound.
+ */
+ bool within_bound(const longlong value, const longlong upper,
+ const longlong lower, bool increasing)
{
return
(is_unsigned && increasing && (ulonglong) value < (ulonglong) upper) ||
@@ -160,24 +183,39 @@ public:
(!is_unsigned && !increasing && value > lower);
}
+ /**
+ Increment a value, subject to truncation
+
+ Truncating to the nearer value between max_value + 1 and min_value
+ - 1
+
+ @param in value The original value
+ @param in increment The increment to add to the value
+
+ @return The value after increment and possible truncation
+ */
longlong increment_value(longlong value, const longlong increment)
{
if (is_unsigned)
{
if (increment > 0)
{
- // in case value + increment overflows
- if ((ulonglong) value > (ulonglong) max_value - (ulonglong) increment ||
- // in case max_value - increment underflows
- (ulonglong) value + (ulonglong) increment > (ulonglong) max_value)
+ if (/* in case value + increment overflows */
+ (ulonglong) value >
+ (ulonglong) max_value - (ulonglong) increment ||
+ /* in case max_value - increment underflows */
+ (ulonglong) value + (ulonglong) increment >
+ (ulonglong) max_value)
value= max_value + 1;
else
value+= increment;
}
else
{
- if ((ulonglong) value - (ulonglong) (-increment) < (ulonglong) min_value ||
- (ulonglong) value < (ulonglong) min_value + (ulonglong) (- increment))
+ if ((ulonglong) value - (ulonglong) (-increment) <
+ (ulonglong) min_value ||
+ (ulonglong) value <
+ (ulonglong) min_value + (ulonglong) (-increment))
value= min_value - 1;
else
value+= increment;
@@ -185,27 +223,20 @@ public:
} else
if (increment > 0)
{
- if (value > max_value - increment ||
- value + increment > max_value)
+ if (value > max_value - increment || value + increment > max_value)
value= max_value + 1;
else
value+= increment;
}
else
{
- if (value + increment < min_value ||
- value < min_value - increment)
+ if (value + increment < min_value || value < min_value - increment)
value= min_value - 1;
else
value+= increment;
}
return value;
}
-
- bool all_values_used;
- seq_init initialized;
-
-private:
mysql_rwlock_t mutex;
};
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 12e4f655515..fae01faa468 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -2694,10 +2694,14 @@ static int show_create_sequence(THD *thd, TABLE_LIST *table_list,
packet->append(STRING_WITH_LEN("CREATE SEQUENCE "));
append_identifier(thd, packet, &alias);
- /* Do not show " as <type>" in oracle mode as it is not supported:
- https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/CREATE-SEQUENCE.html
+ /*
+ Do not show " as <type>" in oracle mode as it is not supported:
+ https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/CREATE-SEQUENCE.html
+ Also, do not show this if the type is the default type,
+ i.e. slonglong, for backward compatibility.
*/
- if (!(sql_mode & MODE_ORACLE))
+ if (!(sql_mode & MODE_ORACLE) &&
+ seq->value_type_handler() != &type_handler_slonglong)
{
packet->append(STRING_WITH_LEN(" as "));
packet->append(seq->value_type_handler()->name().lex_cstring());
@@ -5530,9 +5534,9 @@ int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond)
}
static int get_schema_sequence_record(THD *thd, TABLE_LIST *tables,
- TABLE *table, bool res,
- const LEX_CSTRING *db_name,
- const LEX_CSTRING *table_name)
+ TABLE *table, bool res,
+ const LEX_CSTRING *db_name,
+ const LEX_CSTRING *table_name)
{
DBUG_ENTER("get_sequence_record");
CHARSET_INFO *cs= system_charset_info;
@@ -9468,23 +9472,25 @@ ST_FIELD_INFO proc_fields_info[]=
ST_FIELD_INFO sequence_fields_info[]=
{
- Column("SEQUENCE_CATALOG", Catalog(), NOT_NULL, OPEN_FRM_ONLY),
- Column("SEQUENCE_SCHEMA", Name(), NOT_NULL, OPEN_FRM_ONLY),
- Column("SEQUENCE_NAME", Name(), NOT_NULL, "Table", OPEN_FRM_ONLY),
+ Column("SEQUENCE_CATALOG", Catalog(), NOT_NULL,
+ OPEN_FRM_ONLY),
+ Column("SEQUENCE_SCHEMA", Name(), NOT_NULL,
+ OPEN_FRM_ONLY),
+ Column("SEQUENCE_NAME", Name(), NOT_NULL, "Table",
+ OPEN_FRM_ONLY),
Column("DATA_TYPE", Name(), NOT_NULL),
Column("NUMERIC_PRECISION", SLong(21), NOT_NULL),
Column("NUMERIC_PRECISION_RADIX", SLong(21), NULLABLE),
Column("NUMERIC_SCALE", SLong(21), NULLABLE),
- // Decimal types for these values to incorporate possibly unsigned
- // longlongs.
+ /*
+ Decimal types for these values to incorporate possibly unsigned
+ longlongs.
+ */
Column("START_VALUE", Decimal(2100), NOT_NULL),
Column("MINIMUM_VALUE", Decimal(2100), NOT_NULL),
Column("MAXIMUM_VALUE", Decimal(2100), NOT_NULL),
Column("INCREMENT", SLonglong(21), NOT_NULL),
- Column("CYCLE_OPTION", SLonglong(21), NOT_NULL),
- Column("DECLARED_DATA_TYPE", SLong(21), NULLABLE),
- Column("DECLARED_NUMERIC_PRECISION", SLong(21), NULLABLE),
- Column("DECLARED_NUMERIC_SCALE", SLong(21), NULLABLE),
+ Column("CYCLE_OPTION", Yes_or_empty(), NOT_NULL),
CEnd()
};
diff --git a/sql/sql_type.cc b/sql/sql_type.cc
index 3759c0ba02f..1207ffd4fb8 100644
--- a/sql/sql_type.cc
+++ b/sql/sql_type.cc
@@ -43,7 +43,7 @@ Named_type_handler<Type_handler_short> type_handler_sshort("smallint");
Named_type_handler<Type_handler_long> type_handler_slong("int");
Named_type_handler<Type_handler_int24> type_handler_sint24("mediumint");
Named_type_handler<Type_handler_longlong> type_handler_slonglong("bigint");
-Named_type_handler<Type_handler_utiny> type_handler_utiny("tiny unsigned");
+Named_type_handler<Type_handler_utiny> type_handler_utiny("tinyint unsigned");
Named_type_handler<Type_handler_ushort> type_handler_ushort("smallint unsigned");
Named_type_handler<Type_handler_ulong> type_handler_ulong("int unsigned");
Named_type_handler<Type_handler_uint24> type_handler_uint24("mediumint unsigned");
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 27ce8bcdbfc..ae81c026b26 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -200,8 +200,10 @@ void _CONCAT_UNDERSCORED(turn_parser_debug_on,yyparse)()
ulonglong ulonglong_number;
longlong longlong_number;
uint sp_instr_addr;
- // Longlong_hybrid does not have a default constructor, hence the
- // default value below.
+ /*
+ Longlong_hybrid does not have a default constructor, hence the
+ default value below.
+ */
Longlong_hybrid longlong_hybrid_number= Longlong_hybrid(0, false);
/* structs */
@@ -2425,7 +2427,8 @@ create:
{
LEX *lex= thd->lex;
- if (unlikely(lex->create_info.seq_create_info->check_and_adjust(thd, 1)))
+ if (unlikely(lex->create_info.seq_create_info->
+ check_and_adjust(thd, 1)))
{
my_error(ER_SEQUENCE_INVALID_DATA, MYF(0),
lex->first_select_lex()->table_list.first->db.str,
@@ -2435,12 +2438,13 @@ create:
}
/* No fields specified, generate them */
- if (unlikely(lex->create_info.seq_create_info->prepare_sequence_fields(
- &lex->alter_info.create_list, false)))
+ if (unlikely(
+ lex->create_info.seq_create_info->prepare_sequence_fields(
+ &lex->alter_info.create_list, false)))
MYSQL_YYABORT;
/* CREATE SEQUENCE always creates a sequence */
- Lex->create_info.used_fields|= HA_CREATE_USED_SEQUENCE;
+ Lex->create_info.used_fields|= HA_CREATE_USED_SEQUENCE;
Lex->create_info.sequence= 1;
create_table_set_open_action_and_adjust_tables(lex);
@@ -2613,104 +2617,111 @@ sequence_defs:
sequence_def:
AS int_type field_options
{
- if (unlikely(Lex->create_info.seq_create_info->used_fields &
- seq_field_used_as))
+ sequence_definition *seq= Lex->create_info.seq_create_info;
+ if (unlikely(seq->used_fields & seq_field_used_as))
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "AS"));
if ($3 & ZEROFILL_FLAG)
- my_yyabort_error((ER_BAD_OPTION_VALUE, MYF(0), "ZEROFILL", "AS"));
- Lex->create_info.seq_create_info->value_type = $2->field_type();
- Lex->create_info.seq_create_info->is_unsigned = $3 & UNSIGNED_FLAG ? true : false;
- Lex->create_info.seq_create_info->used_fields|= seq_field_used_as;
+ my_yyabort_error((ER_BAD_OPTION_VALUE, MYF(0), "ZEROFILL",
+ "AS"));
+ seq->value_type = $2->field_type();
+ seq->is_unsigned= $3 & UNSIGNED_FLAG ? true : false;
+ seq->used_fields|= seq_field_used_as;
}
| MINVALUE_SYM opt_equal sequence_truncated_value_hybrid_num
{
- if (unlikely(Lex->create_info.seq_create_info->used_fields &
- seq_field_used_min_value))
+ sequence_definition *seq= Lex->create_info.seq_create_info;
+ if (unlikely(seq->used_fields & seq_field_used_min_value))
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MINVALUE"));
- Lex->create_info.seq_create_info->min_value_from_parser= $3;
- Lex->create_info.seq_create_info->used_fields|= seq_field_used_min_value;
- Lex->create_info.seq_create_info->used_fields|= seq_field_specified_min_value;
+ seq->min_value_from_parser= $3;
+ seq->used_fields|=
+ seq_field_used_min_value;
+ seq->used_fields|=
+ seq_field_specified_min_value;
}
| NO_SYM MINVALUE_SYM
{
- if (unlikely(Lex->create_info.seq_create_info->used_fields & seq_field_used_min_value))
+ sequence_definition *seq= Lex->create_info.seq_create_info;
+ if (unlikely(seq->used_fields & seq_field_used_min_value))
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MINVALUE"));
- Lex->create_info.seq_create_info->used_fields|= seq_field_used_min_value;
+ seq->used_fields|= seq_field_used_min_value;
}
| NOMINVALUE_SYM
{
- if (unlikely(Lex->create_info.seq_create_info->used_fields & seq_field_used_min_value))
+ sequence_definition *seq= Lex->create_info.seq_create_info;
+ if (unlikely(seq->used_fields & seq_field_used_min_value))
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MINVALUE"));
- Lex->create_info.seq_create_info->used_fields|= seq_field_used_min_value;
+ seq->used_fields|= seq_field_used_min_value;
}
| MAXVALUE_SYM opt_equal sequence_truncated_value_hybrid_num
{
- if (unlikely(Lex->create_info.seq_create_info->used_fields &
- seq_field_used_max_value))
+ sequence_definition *seq= Lex->create_info.seq_create_info;
+ if (unlikely(seq->used_fields & seq_field_used_max_value))
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MAXVALUE"));
- Lex->create_info.seq_create_info->max_value_from_parser= $3;
- Lex->create_info.seq_create_info->used_fields|= seq_field_used_max_value;
- Lex->create_info.seq_create_info->used_fields|= seq_field_specified_max_value;
+ seq->max_value_from_parser= $3;
+ seq->used_fields|= seq_field_used_max_value;
+ seq->used_fields|= seq_field_specified_max_value;
}
| NO_SYM MAXVALUE_SYM
{
- if (unlikely(Lex->create_info.seq_create_info->used_fields & seq_field_used_max_value))
+ sequence_definition *seq= Lex->create_info.seq_create_info;
+ if (unlikely(seq->used_fields & seq_field_used_max_value))
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MAXVALUE"));
- Lex->create_info.seq_create_info->used_fields|= seq_field_used_max_value;
+ seq->used_fields|= seq_field_used_max_value;
}
| NOMAXVALUE_SYM
{
- if (unlikely(Lex->create_info.seq_create_info->used_fields & seq_field_used_max_value))
+ sequence_definition *seq= Lex->create_info.seq_create_info;
+ if (unlikely(seq->used_fields & seq_field_used_max_value))
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MAXVALUE"));
- Lex->create_info.seq_create_info->used_fields|= seq_field_used_max_value;
+ seq->used_fields|= seq_field_used_max_value;
}
| START_SYM opt_with sequence_value_hybrid_num
{
- if (unlikely(Lex->create_info.seq_create_info->used_fields &
- seq_field_used_start))
+ sequence_definition *seq= Lex->create_info.seq_create_info;
+ if (unlikely(seq->used_fields & seq_field_used_start))
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "START"));
- Lex->create_info.seq_create_info->start_from_parser= $3;
- Lex->create_info.seq_create_info->used_fields|= seq_field_used_start;
+ seq->start_from_parser= $3;
+ seq->used_fields|= seq_field_used_start;
}
| INCREMENT_SYM opt_by sequence_value_num
{
- if (unlikely(Lex->create_info.seq_create_info->used_fields &
- seq_field_used_increment))
+ sequence_definition *seq= Lex->create_info.seq_create_info;
+ if (unlikely(seq->used_fields & seq_field_used_increment))
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "INCREMENT"));
- Lex->create_info.seq_create_info->increment= $3;
- Lex->create_info.seq_create_info->used_fields|= seq_field_used_increment;
+ seq->increment= $3;
+ seq->used_fields|= seq_field_used_increment;
}
| CACHE_SYM opt_equal sequence_value_num
{
- if (unlikely(Lex->create_info.seq_create_info->used_fields &
- seq_field_used_cache))
+ sequence_definition *seq= Lex->create_info.seq_create_info;
+ if (unlikely(seq->used_fields & seq_field_used_cache))
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "CACHE"));
- Lex->create_info.seq_create_info->cache= $3;
- Lex->create_info.seq_create_info->used_fields|= seq_field_used_cache;
+ seq->cache= $3;
+ seq->used_fields|= seq_field_used_cache;
}
| NOCACHE_SYM
{
- if (unlikely(Lex->create_info.seq_create_info->used_fields &
- seq_field_used_cache))
+ sequence_definition *seq= Lex->create_info.seq_create_info;
+ if (unlikely(seq->used_fields & seq_field_used_cache))
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "CACHE"));
- Lex->create_info.seq_create_info->cache= 0;
- Lex->create_info.seq_create_info->used_fields|= seq_field_used_cache;
+ seq->cache= 0;
+ seq->used_fields|= seq_field_used_cache;
}
| CYCLE_SYM
{
- if (unlikely(Lex->create_info.seq_create_info->used_fields &
- seq_field_used_cycle))
+ sequence_definition *seq= Lex->create_info.seq_create_info;
+ if (unlikely(seq->used_fields & seq_field_used_cycle))
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "CYCLE"));
- Lex->create_info.seq_create_info->cycle= 1;
- Lex->create_info.seq_create_info->used_fields|= seq_field_used_cycle;
+ seq->cycle= 1;
+ seq->used_fields|= seq_field_used_cycle;
}
| NOCYCLE_SYM
{
- if (unlikely(Lex->create_info.seq_create_info->used_fields &
- seq_field_used_cycle))
+ sequence_definition *seq= Lex->create_info.seq_create_info;
+ if (unlikely(seq->used_fields & seq_field_used_cycle))
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "CYCLE"));
- Lex->create_info.seq_create_info->cycle= 0;
- Lex->create_info.seq_create_info->used_fields|= seq_field_used_cycle;
+ seq->cycle= 0;
+ seq->used_fields|= seq_field_used_cycle;
}
| RESTART_SYM
{
@@ -2719,10 +2730,10 @@ sequence_def:
thd->parse_error(ER_SYNTAX_ERROR, "RESTART");
MYSQL_YYABORT;
}
- if (unlikely(Lex->create_info.seq_create_info->used_fields &
- seq_field_used_restart))
+ sequence_definition *seq= Lex->create_info.seq_create_info;
+ if (unlikely(seq->used_fields & seq_field_used_restart))
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "RESTART"));
- Lex->create_info.seq_create_info->used_fields|= seq_field_used_restart;
+ seq->used_fields|= seq_field_used_restart;
}
| RESTART_SYM opt_with sequence_value_hybrid_num
{
@@ -2731,11 +2742,12 @@ sequence_def:
thd->parse_error(ER_SYNTAX_ERROR, "RESTART");
MYSQL_YYABORT;
}
- if (unlikely(Lex->create_info.seq_create_info->used_fields &
- seq_field_used_restart))
+ sequence_definition *seq= Lex->create_info.seq_create_info;
+ if (unlikely(seq->used_fields & seq_field_used_restart))
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "RESTART"));
- Lex->create_info.seq_create_info->restart_from_parser= $3;
- Lex->create_info.seq_create_info->used_fields|= seq_field_used_restart | seq_field_used_restart_value;
+ seq->restart_from_parser= $3;
+ seq->used_fields|=
+ seq_field_used_restart | seq_field_used_restart_value;
}
;
@@ -7141,8 +7153,13 @@ alter:
{
/* Create a generic ALTER SEQUENCE statment. */
Lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_alter_sequence($3);
- if ((Lex->create_info.seq_create_info->used_fields & seq_field_used_as) && (Lex->create_info.seq_create_info->used_fields - seq_field_used_as))
- my_yyabort_error((ER_NOT_SUPPORTED_YET, MYF(0), "ALTER SEQUENCE with both AS <type> and something else."));
+ if ((Lex->create_info.seq_create_info->used_fields &
+ seq_field_used_as) &&
+ (Lex->create_info.seq_create_info->used_fields -
+ seq_field_used_as))
+ my_yyabort_error((ER_NOT_SUPPORTED_YET, MYF(0),
+ "ALTER SEQUENCE with both AS <type> and "
+ "something else."));
if (unlikely(Lex->m_sql_cmd == NULL))
MYSQL_YYABORT;
} stmt_end {}
@@ -9752,19 +9769,23 @@ column_default_non_parenthesized_expr:
if (unlikely(!($$= Lex->create_item_func_lastval(thd, $3))))
MYSQL_YYABORT;
}
- | SETVAL_SYM '(' table_ident ',' sequence_value_num ')'
+ | SETVAL_SYM '(' table_ident ',' sequence_value_hybrid_num ')'
{
- if (unlikely(!($$= Lex->create_item_func_setval(thd, $3, $5, 0, 1))))
+ if (unlikely(!($$= Lex->create_item_func_setval(thd, $3, $5, 0,
+ 1))))
MYSQL_YYABORT;
}
- | SETVAL_SYM '(' table_ident ',' sequence_value_num ',' bool ')'
+ | SETVAL_SYM '(' table_ident ',' sequence_value_hybrid_num ',' bool ')'
{
- if (unlikely(!($$= Lex->create_item_func_setval(thd, $3, $5, 0, $7))))
+ if (unlikely(!($$= Lex->create_item_func_setval(thd, $3, $5, 0,
+ $7))))
MYSQL_YYABORT;
}
- | SETVAL_SYM '(' table_ident ',' sequence_value_num ',' bool ',' ulonglong_num ')'
+ | SETVAL_SYM '(' table_ident ',' sequence_value_hybrid_num ',' bool ','
+ ulonglong_num ')'
{
- if (unlikely(!($$= Lex->create_item_func_setval(thd, $3, $5, $9, $7))))
+ if (unlikely(!($$= Lex->create_item_func_setval(thd, $3, $5, $9,
+ $7))))
MYSQL_YYABORT;
}
;
@@ -12584,89 +12605,124 @@ real_ulong_num:
| dec_num_error { MYSQL_YYABORT; }
;
-// For simple sequence metadata values that are signed and do not need truncation
+/*
+ For simple sequence metadata values that are signed and do not need
+ truncation
+*/
sequence_value_num:
- opt_plus NUM { int error; $$= (longlong) my_strtoll10($2.str, (char**) 0, &error); }
- | opt_plus LONG_NUM { int error; $$= (longlong) my_strtoll10($2.str, (char**) 0, &error); }
- | '-' NUM { int error; $$= -(longlong) my_strtoll10($2.str, (char**) 0, &error); }
- | '-' LONG_NUM { int error; $$= -(longlong) my_strtoll10($2.str, (char**) 0, &error); }
+ opt_plus NUM
+ {
+ int error;
+ $$= (longlong) my_strtoll10($2.str, (char**) 0, &error);
+ }
+ | opt_plus LONG_NUM
+ {
+ int error;
+ $$= (longlong) my_strtoll10($2.str, (char**) 0, &error);
+ }
+ | '-' NUM
+ {
+ int error;
+ $$= -(longlong) my_strtoll10($2.str, (char**) 0, &error);
+ }
+ | '-' LONG_NUM
+ {
+ int error;
+ $$= -(longlong) my_strtoll10($2.str, (char**) 0, &error);
+ }
| '-' ULONGLONG_NUM
{
- int error;
- const ulonglong abs= my_strtoll10($2.str, (char**) 0, &error);
- if (abs == 1 + (ulonglong) LONGLONG_MAX)
- $$= LONGLONG_MIN;
- else
- thd->parse_error(ER_DATA_OUT_OF_RANGE);
+ int error;
+ const ulonglong abs= my_strtoll10($2.str, (char**) 0, &error);
+ if (abs == 1 + (ulonglong) LONGLONG_MAX)
+ $$= LONGLONG_MIN;
+ else
+ thd->parse_error(ER_DATA_OUT_OF_RANGE);
}
;
-// For sequence metadata values that may be unsigned but do not need truncation (start, restart)
+/*
+ For sequence metadata values that may be unsigned but do not need
+ truncation (start, restart)
+*/
sequence_value_hybrid_num:
opt_plus NUM
- {
- int error;
- $$= Longlong_hybrid(my_strtoll10($2.str, (char**) 0, &error), false);
- }
+ {
+ int error;
+ $$= Longlong_hybrid(my_strtoll10($2.str, (char**) 0, &error),
+ false);
+ }
| opt_plus LONG_NUM
- {
- int error;
- $$= Longlong_hybrid(my_strtoll10($2.str, (char**) 0, &error), false);
- }
+ {
+ int error;
+ $$= Longlong_hybrid(my_strtoll10($2.str, (char**) 0, &error),
+ false);
+ }
| opt_plus ULONGLONG_NUM
- {
- int error;
- $$= Longlong_hybrid(my_strtoll10($2.str, (char**) 0, &error), true);
- }
+ {
+ int error;
+ $$= Longlong_hybrid(my_strtoll10($2.str, (char**) 0, &error),
+ true);
+ }
| '-' NUM
- {
- int error;
- $$= Longlong_hybrid(- my_strtoll10($2.str, (char**) 0, &error), false);
- }
+ {
+ int error;
+ $$= Longlong_hybrid(- my_strtoll10($2.str, (char**) 0, &error),
+ false);
+ }
| '-' LONG_NUM
- {
- int error;
- $$= Longlong_hybrid(- my_strtoll10($2.str, (char**) 0, &error), false);
- }
+ {
+ int error;
+ $$= Longlong_hybrid(- my_strtoll10($2.str, (char**) 0, &error),
+ false);
+ }
| '-' ULONGLONG_NUM
- {
- int error;
- const ulonglong abs= my_strtoll10($2.str, (char**) 0, &error);
- if (abs == 1 + (ulonglong) LONGLONG_MAX)
- $$= Longlong_hybrid(LONGLONG_MIN, false);
- else
- thd->parse_error(ER_DATA_OUT_OF_RANGE);
- }
+ {
+ int error;
+ const ulonglong abs= my_strtoll10($2.str, (char**) 0, &error);
+ if (abs == 1 + (ulonglong) LONGLONG_MAX)
+ $$= Longlong_hybrid(LONGLONG_MIN, false);
+ else
+ thd->parse_error(ER_DATA_OUT_OF_RANGE);
+ }
;
-// For sequence metadata values that may be unsigned and need truncation (maxvalue, minvalue)
+/*
+ For sequence metadata values that may be unsigned and need
+ truncation (maxvalue, minvalue)
+*/
sequence_truncated_value_hybrid_num:
opt_plus NUM
- {
- int error;
- $$= Longlong_hybrid(my_strtoll10($2.str, (char**) 0, &error), false);
- }
+ {
+ int error;
+ $$= Longlong_hybrid(my_strtoll10($2.str, (char**) 0, &error),
+ false);
+ }
| opt_plus LONG_NUM
- {
- int error;
- $$= Longlong_hybrid(my_strtoll10($2.str, (char**) 0, &error), false);
- }
+ {
+ int error;
+ $$= Longlong_hybrid(my_strtoll10($2.str, (char**) 0, &error),
+ false);
+ }
| opt_plus ULONGLONG_NUM
- {
- int error;
- $$= Longlong_hybrid(my_strtoll10($2.str, (char**) 0, &error), true);
- }
+ {
+ int error;
+ $$= Longlong_hybrid(my_strtoll10($2.str, (char**) 0, &error),
+ true);
+ }
| opt_plus DECIMAL_NUM { $$= Longlong_hybrid(ULONGLONG_MAX, true); }
| '-' NUM
- {
- int error;
- $$= Longlong_hybrid(- my_strtoll10($2.str, (char**) 0, &error), false);
- }
+ {
+ int error;
+ $$= Longlong_hybrid(- my_strtoll10($2.str, (char**) 0, &error),
+ false);
+ }
| '-' LONG_NUM
- {
- int error;
- $$= Longlong_hybrid(- my_strtoll10($2.str, (char**) 0, &error), false);
- }
+ {
+ int error;
+ $$= Longlong_hybrid(- my_strtoll10($2.str, (char**) 0, &error),
+ false);
+ }
| '-' ULONGLONG_NUM { $$= Longlong_hybrid(LONGLONG_MIN, false); }
| '-' DECIMAL_NUM { $$= Longlong_hybrid(LONGLONG_MIN, false); }
;