1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Fixed sequences based on comments from Peter Gulutzan and Andrii Nikitin

- Changed names of SEQUENCE table columns to be more close to ANSI
- Fixed error message for SHOW SEQUENCE non_existing_sequence
- Allow syntax CACHE +1
- Fixed ALTER TABLE for TEMPORARY sequences.
This commit is contained in:
Monty
2017-06-03 16:08:23 +03:00
parent 3356e42d01
commit 36ae8846ca
25 changed files with 763 additions and 696 deletions

View File

@ -23,27 +23,27 @@ create sequence s1;
show create table s1;
Table Create Table
s1 CREATE TABLE `s1` (
`next_value` bigint(21) NOT NULL COMMENT 'next not cached value',
`min_value` bigint(21) NOT NULL COMMENT 'min value',
`max_value` bigint(21) NOT NULL COMMENT 'max value',
`start` bigint(21) NOT NULL COMMENT 'start value',
`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` bigint(21) NOT NULL COMMENT 'cache size',
`cycle` tinyint(1) unsigned NOT NULL COMMENT 'cycle state',
`round` bigint(21) NOT NULL COMMENT 'How many cycles has been done'
`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
connection slave;
show create table s1;
Table Create Table
s1 CREATE TABLE `s1` (
`next_value` bigint(21) NOT NULL COMMENT 'next not cached value',
`min_value` bigint(21) NOT NULL COMMENT 'min value',
`max_value` bigint(21) NOT NULL COMMENT 'max value',
`start` bigint(21) NOT NULL COMMENT 'start value',
`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` bigint(21) NOT NULL COMMENT 'cache size',
`cycle` tinyint(1) unsigned NOT NULL COMMENT 'cycle state',
`round` bigint(21) NOT NULL COMMENT 'How many cycles has been done'
`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
connection master;
drop sequence s1;
@ -73,38 +73,37 @@ support create sequence
connection master;
create table t_1(id int);
show create sequence t_1;
ERROR HY000: 's_db.t_1' is not of type 'SEQUENCE'
ERROR 42S02: 's_db.t_1' is not a SEQUENCE
drop table t_1;
CREATE SEQUENCE `s2` (
`currval` bigint(21) NOT NULL COMMENT 'current value',
`nextval` bigint(21) NOT NULL COMMENT 'next value',
`minvalue` bigint(21) NOT NULL COMMENT 'min value',
`maxvalue` bigint(21) NOT NULL COMMENT 'max value',
`start` bigint(21) NOT NULL COMMENT 'start value',
`increment` bigint(21) NOT NULL COMMENT 'increment value',
`cache` bigint(21) NOT NULL COMMENT 'cache size',
`cycle` bigint(21) NOT NULL COMMENT 'cycle state',
`round` bigint(21) NOT NULL COMMENT 'already how many round'
`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,
`increment` bigint(21) NOT NULL,
`cache_size` bigint(21) unsigned NOT NULL,
`cycle_option` tinyint(1) unsigned NOT NULL,
`cycle_count` bigint(21) NOT NULL
) ENGINE=InnoDB sequence=1;
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 '(
`currval` bigint(21) NOT NULL COMMENT 'current value',
`nextval` bigint(21) NO' at line 1
`next_not_cached_value` bigint(21) NOT NULL,
`minimum_value` bigint(21) NOT NU' at line 1
CREATE TABLE `s2` (
`next_value` bigint(21) NOT NULL COMMENT 'next value',
`min_value` bigint(21) NOT NULL COMMENT 'min value',
`max_value` bigint(21) NOT NULL COMMENT 'max value',
`start` bigint(21) NOT NULL COMMENT 'start value',
`increment` bigint(21) NOT NULL COMMENT 'increment value',
`cache` bigint(21) NOT NULL COMMENT 'cache size',
`cycle` tinyint(1) unsigned NOT NULL COMMENT 'cycle state',
`round` bigint(21) NOT NULL COMMENT 'already how many round'
`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,
`increment` bigint(21) NOT NULL,
`cache_size` bigint(21) unsigned NOT NULL,
`cycle_option` tinyint(1) unsigned NOT NULL,
`cycle_count` bigint(21) NOT NULL
) ENGINE=InnoDB sequence=1;
insert into s2 values(1, 1, 10, 1, 2, 1, 1, 0);
commit;
select * for s2;
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 's2' at line 1
select * from s2;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1 1 10 1 2 1 1 0
select NEXT VALUE for s2;
NEXT VALUE for s2
@ -128,25 +127,25 @@ select NEXT VALUE for s2;
NEXT VALUE for s2
3
select * from s2;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
5 1 10 1 2 1 1 1
commit;
connection master;
connection slave;
select * from s2;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
5 1 10 1 2 1 1 1
connection master;
drop sequence s2;
CREATE TABLE `s2` (
`next_value` bigint(21) NOT NULL COMMENT 'next value',
`min_value` bigint(21) NOT NULL COMMENT 'min value',
`max_value` bigint(21) NOT NULL COMMENT 'max value',
`start` bigint(21) NOT NULL COMMENT 'start value',
`increment` bigint(21) NOT NULL COMMENT 'increment value',
`cache` bigint(21) NOT NULL COMMENT 'cache size',
`cycle` tinyint(1) unsigned NOT NULL COMMENT 'cycle state',
`round` bigint(21) NOT NULL COMMENT 'already how many round'
`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,
`increment` bigint(21) NOT NULL,
`cache_size` bigint(21) unsigned NOT NULL,
`cycle_option` tinyint(1) unsigned NOT NULL,
`cycle_count` bigint(21) NOT NULL
) ENGINE=myisam DEFAULT CHARSET=latin1 sequence=1;
show create sequence s2;
Table Create Table
@ -159,7 +158,7 @@ connection master;
create sequence s2;
create table t2 (id int);
select * from s2;
next_value min_value max_value start increment cache cycle round
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
select * from t2;
id
@ -171,7 +170,7 @@ NEXT VALUE for s2
select NEXT VALUE for t2;
ERROR 42S02: 's_db.t2' is not a SEQUENCE
select * from s2, t2;
next_value min_value max_value start increment cache cycle round id
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count id
1001 1 9223372036854775806 1 1 1000 0 0 1
select * for s2;
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 's2' at line 1
@ -191,7 +190,7 @@ show create sequence s2_2;
Table Create Table
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_value min_value max_value start increment cache cycle round
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
truncate table s2_2;
ERROR HY000: Storage engine SEQUENCE of the table `s_db`.`s2_2` doesn't have this option
@ -339,7 +338,7 @@ show global variables like 'read_only';
Variable_name Value
read_only OFF
select * from s_db.s1;
next_value min_value max_value start increment cache cycle round
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
connection master;
connection slave;
@ -360,7 +359,7 @@ connection master;
connection slave;
connection s_normal_3;
select * from s_t;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1 1 20 1 1 5 1 0
connection m_normal_1;
select next value for s_t;
@ -369,8 +368,8 @@ next value for s_t
connection master;
connection slave;
connection s_normal_3;
select next_value from s_t;
next_value
select next_not_cached_value from s_t;
next_not_cached_value
6
------------------------------------------
master ALTER SEQUENCE
@ -381,7 +380,7 @@ next value for s_t
2
alter sequence s_t restart= 11;
select * from s_t;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
11 1 20 1 1 5 1 0
connection master;
connection slave;
@ -390,7 +389,7 @@ show slave nextval;
------------------------------------------
connection s_normal_3;
select * from s_t;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
11 1 20 1 1 5 1 0
connection m_normal_1;
select next value for s_t;
@ -400,7 +399,7 @@ connection master;
connection slave;
connection s_normal_3;
select * from s_t;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
16 1 20 1 1 5 1 0
------------------------------------------
update into invalid sequence
@ -410,17 +409,17 @@ select next value for s_t;
next value for s_t
12
select * from s_t;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
16 1 20 1 1 5 1 0
alter sequence s_t minvalue=11 maxvalue=9;
ERROR HY000: Sequence 's_db.s_t' values are conflicting
select * from s_t;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
16 1 20 1 1 5 1 0
alter sequence s_t restart= 12 start=10 minvalue=11 maxvalue=20;
ERROR HY000: Sequence 's_db.s_t' values are conflicting
select * from s_t;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
16 1 20 1 1 5 1 0
------------------------------------------
delete sequence row
@ -457,7 +456,7 @@ id
2
2222
select * from s_1;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
6 1 9223372036854775806 1 1 5 0 0
connection master;
connection slave;
@ -505,7 +504,7 @@ id
2
2222
select * from s_1;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
11 1 9223372036854775806 1 1 5 0 0
select next value for s_1;
next value for s_1
@ -643,12 +642,12 @@ next value for s1
4
commit;
select * from s1;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
5 1 9223372036854775806 1 1 2 0 0
connection master;
connection slave;
select * from s1;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
5 1 9223372036854775806 1 1 2 0 0
------------------------------------------
close session binlog.
@ -669,23 +668,23 @@ next value for s1
8
set session sql_log_bin=on;
select * from s1;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
9 1 9223372036854775806 1 1 2 0 0
connection master;
connection slave;
select * from s1;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
5 1 9223372036854775806 1 1 2 0 0
connection master;
select next value for s1;
next value for s1
9
select * from s1;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
11 1 9223372036854775806 1 1 2 0 0
connection slave;
select * from s1;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
11 1 9223372036854775806 1 1 2 0 0
connection master;
drop sequence s1;
@ -711,7 +710,7 @@ next value for s1
connection master;
connection slave;
select * from s1;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
3 1 9223372036854775806 1 1 2 0 0
connection m_normal_1;
drop sequence s1;
@ -733,12 +732,12 @@ select next value for s1;
next value for s1
2
select * from s1;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
3 1 9223372036854775806 1 1 2 0 0
connection master;
connection slave;
select * from s1;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
3 1 9223372036854775806 1 1 2 0 0
connection m_normal_1;
drop sequence s1;
@ -784,7 +783,7 @@ connection m_normal_1;
create sequence s1 cache 2;
create table t as select * from s1;
select * from t;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1 1 9223372036854775806 1 1 2 0 0
drop table t;
create table t as select next value for s1;
@ -918,7 +917,7 @@ test value boundary
###########################################
connection m_normal_1;
------------------------------------------
round increment by round
cycle_count increment by cycle_count
------------------------------------------
create sequence s1 start with 5 minvalue 2 maxvalue 7 cache 1 cycle;
select next value for s1;
@ -950,39 +949,39 @@ next value for s1
select next value for s1;
ERROR HY000: Sequence 's_db.s1' has run out
select * from s1;
next_value min_value max_value start increment cache cycle round
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
8 2 7 5 1 10 0 0
drop sequence s1;
create sequence s1 start with 2 minvalue 1 maxvalue 3 increment by 3 nocache cycle;
select next value for s1;
next value for s1
2
select next_value,round from s1;
next_value round
select next_not_cached_value,cycle_count from s1;
next_not_cached_value cycle_count
4 0
select next value for s1;
next value for s1
1
select next_value,round from s1;
next_value round
select next_not_cached_value,cycle_count from s1;
next_not_cached_value cycle_count
4 1
select next value for s1;
next value for s1
1
select next_value,round from s1;
next_value round
select next_not_cached_value,cycle_count from s1;
next_not_cached_value cycle_count
4 2
select next value for s1;
next value for s1
1
select next_value,round from s1;
next_value round
select next_not_cached_value,cycle_count from s1;
next_not_cached_value cycle_count
4 3
select next value for s1;
next value for s1
1
select next_value,round from s1;
next_value round
select next_not_cached_value,cycle_count from s1;
next_not_cached_value cycle_count
4 4
drop sequence s1;
create sequence s1 start with 2 minvalue 1 maxvalue 3 increment by 3 cache 2 nocycle;
@ -996,67 +995,67 @@ drop sequence s1;
beyond ulonglong maxvalue
------------------------------------------
create sequence s1 start with 9223372036854775805 minvalue 9223372036854775804 maxvalue 9223372036854775806 cache 1 cycle;
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775805 0
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775806 0
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775804 0
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775805 1
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775806 1
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775804 1
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775805 2
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775806 2
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775804 2
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775805 3
drop sequence s1;
create sequence s1 start with 9223372036854775805 minvalue 9223372036854775804 maxvalue 9223372036854775806 cache 10 cycle;
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775805 0
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775806 0
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775804 0
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775805 1
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775806 1
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775804 1
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775805 2
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775806 2
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775804 2
select next value for s1, round from s1;
next value for s1 round
select next value for s1, cycle_count from s1;
next value for s1 cycle_count
9223372036854775805 3
drop sequence s1;
connection master;