Commit 36ae8846 authored by Monty's avatar Monty

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.
parent 3356e42d
......@@ -6,7 +6,7 @@ Note 1051 Unknown table 'test.t1'
#
CREATE SEQUENCE t1 nocache engine=myisam;
select * from t1;
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 0 0 0
select next value for t1;
next value for t1
......@@ -16,7 +16,7 @@ show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 50 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
select * from t1;
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
2 1 9223372036854775806 50 1 0 0 0
select next value for t1;
next value for t1
......@@ -26,7 +26,7 @@ show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 50 minvalue -100 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
select * from t1;
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 -100 9223372036854775806 50 1 0 0 0
alter sequence t1 minvalue=100 start=100;
ERROR HY000: Sequence 'test.t1' values are conflicting
......@@ -35,14 +35,14 @@ show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 100 minvalue 100 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
select * from t1;
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
100 100 9223372036854775806 100 1 0 0 0
alter sequence t1 maxvalue=500;
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 100 minvalue 100 maxvalue 500 increment by 1 nocache nocycle ENGINE=MyISAM
select * from t1;
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
100 100 500 100 1 0 0 0
drop sequence t1;
CREATE SEQUENCE t1 engine=myisam;
......@@ -64,7 +64,7 @@ show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
select * from t1;
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 0 0 0
select next value for t1;
next value for t1
......@@ -75,8 +75,8 @@ next value for t1
select next value for t1;
next value for t1
3
select next_value, round from t1;
next_value round
select next_not_cached_value, cycle_count from t1;
next_not_cached_value cycle_count
4 0
drop sequence t1;
CREATE SEQUENCE t1 maxvalue=100 engine=myisam;
......@@ -85,7 +85,7 @@ show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
select * from t1;
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
alter sequence t1 cycle;
show create sequence t1;
......@@ -97,7 +97,7 @@ show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 15 minvalue 10 maxvalue 20 increment by 1 cache 1000 cycle ENGINE=MyISAM
select * from t1;
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
15 10 20 15 1 1000 1 0
select NEXT VALUE for t1 from seq_1_to_10;
NEXT VALUE for t1
......@@ -131,7 +131,7 @@ show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 50 minvalue -100 maxvalue 100 increment by -2 cache 1000 nocycle ENGINE=MyISAM
select * from t1;
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 -100 100 50 -2 1000 0 0
select NEXT VALUE for t1 from seq_1_to_10;
NEXT VALUE for t1
......@@ -151,7 +151,7 @@ drop sequence t1;
CREATE SEQUENCE t1 cache 10 engine=innodb;
select * from t1;
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 10 0 0
select next value for t1;
next value for t1
......@@ -161,7 +161,7 @@ show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 100 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 10 nocycle ENGINE=InnoDB
select * from t1;
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 100 1 10 0 0
select next value for t1;
next value for t1
......@@ -195,7 +195,7 @@ show create sequence t1;
Table Create Table
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_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
3001 1 9223372036854775806 1 1 1000 0 0
drop sequence t1;
CREATE SEQUENCE t1 engine=myisam;
......@@ -227,7 +227,7 @@ next value for t1
select next value for t1;
ERROR HY000: Sequence 'test.t1' has run out
select * from t1;
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
0 1 100 50 -2 1000 0 0
alter sequence t1 restart;
select next value for t1;
......
......@@ -43,7 +43,7 @@ select * from t1;
select next value for t1;
select next value for t1;
select next value for t1;
select next_value, round from t1;
select next_not_cached_value, cycle_count from t1;
drop sequence t1;
CREATE SEQUENCE t1 maxvalue=100 engine=myisam;
......
......@@ -26,7 +26,7 @@ NEXT VALUE for t1 seq
19 19
20 20
select * from t1;
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
21 1 9223372036854775806 1 1 10 0 0
drop sequence t1;
create sequence s1;
......
create or replace sequence s1 cache 3;
select next value for s1, min_value from s1 where max_value> 1;
next value for s1 min_value
select next value for s1, minimum_value from s1 where maximum_value> 1;
next value for s1 minimum_value
1 1
select next value for s1, min_value from s1 where max_value> 2;
next value for s1 min_value
select next value for s1, minimum_value from s1 where maximum_value> 2;
next value for s1 minimum_value
2 1
select next value for s1, min_value from s1 where max_value> 3;
next value for s1 min_value
select next value for s1, minimum_value from s1 where maximum_value> 3;
next value for s1 minimum_value
3 1
select next value for s1, min_value from s1 where max_value> 4;
next value for s1 min_value
select next value for s1, minimum_value from s1 where maximum_value> 4;
next value for s1 minimum_value
4 1
alter sequence s1 maxvalue 1000;
drop sequence s1;
......@@ -18,12 +18,12 @@ Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Gtid # # GTID #-#-#
master-bin.000001 # Query # # use `test`; create or replace sequence s1 cache 3
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
master-bin.000001 # Annotate_rows # # select next value for s1, min_value from s1 where max_value> 1
master-bin.000001 # Annotate_rows # # select next value for s1, minimum_value from s1 where maximum_value> 1
master-bin.000001 # Table_map # # table_id: # (test.s1)
master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
master-bin.000001 # Annotate_rows # # select next value for s1, min_value from s1 where max_value> 4
master-bin.000001 # Annotate_rows # # select next value for s1, minimum_value from s1 where maximum_value> 4
master-bin.000001 # Table_map # # table_id: # (test.s1)
master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
master-bin.000001 # Query # # COMMIT
......
......@@ -11,10 +11,10 @@ reset master; # get rid of previous tests binlog
--enable_query_log
create or replace sequence s1 cache 3;
select next value for s1, min_value from s1 where max_value> 1;
select next value for s1, min_value from s1 where max_value> 2;
select next value for s1, min_value from s1 where max_value> 3;
select next value for s1, min_value from s1 where max_value> 4;
select next value for s1, minimum_value from s1 where maximum_value> 1;
select next value for s1, minimum_value from s1 where maximum_value> 2;
select next value for s1, minimum_value from s1 where maximum_value> 3;
select next value for s1, minimum_value from s1 where maximum_value> 4;
#
# Alter sequence
......
This diff is collapsed.
......@@ -92,7 +92,7 @@ drop sequence t1;
#
create table t1 (a int);
--error ER_WRONG_OBJECT
--error ER_NOT_SEQUENCE
show create sequence t1;
--error ER_NOT_SEQUENCE2
drop sequence t1;
......@@ -149,6 +149,7 @@ show create sequence t1;
show create table t1;
create or replace sequence t1 start=1 increment= 2;
create or replace sequence t1 start 1 increment 2;
create or replace sequence t1 cache +1;
drop sequence t1;
#
......@@ -156,14 +157,14 @@ drop sequence t1;
#
CREATE TABLE t1 (
`next_value` bigint(21) NOT NULL,
`min_value` bigint(21) NOT NULL,
`max_value` bigint(21) NOT NULL,
`start` bigint(21) NOT NULL,
`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` bigint(21) NOT NULL,
`cycle` tinyint(1) unsigned NOT NULL,
`round` bigint(21) NOT NULL
`cache_size` bigint(21) unsigned NOT NULL,
`cycle_option` tinyint(1) unsigned NOT NULL,
`cycle_count` bigint(21) NOT NULL
) sequence=1;
show create sequence t1;
......@@ -174,40 +175,40 @@ drop sequence t1;
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
CREATE OR REPLACE TABLE t1 (
`next_val` bigint(21) NOT NULL,
`min_value` bigint(21) NOT NULL,
`max_value` bigint(21) NOT NULL,
`start` bigint(21) NOT NULL,
`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` bigint(21) NOT NULL,
`cycle` tinyint(1) unsigned NOT NULL,
`round` bigint(21) NOT NULL
`cache_size` bigint(21) unsigned NOT NULL,
`cycle_option` tinyint(1) unsigned NOT NULL,
`cycle_count_not_exists` bigint(21) NOT NULL
) sequence=1;
# Wrong type
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
CREATE OR REPLACE TABLE t1 (
`next_value` int(21) NOT NULL,
`min_value` bigint(21) NOT NULL,
`max_value` bigint(21) NOT NULL,
`start` bigint(21) NOT NULL,
`next_not_cached_value` int(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` bigint(21) NOT NULL,
`cycle` tinyint(1) unsigned NOT NULL,
`round` bigint(21) NOT NULL
`cache_size` bigint(21) unsigned NOT NULL,
`cycle_option` tinyint(1) unsigned NOT NULL,
`cycle_count` bigint(21) NOT NULL
) sequence=1;
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
CREATE OR REPLACE TABLE t1 (
`next_val` bigint(21) NOT NULL,
`min_value` bigint(21) NOT NULL,
`max_value` bigint(21) NOT NULL,
`start` bigint(21) NOT NULL,
`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` bigint(21) NOT NULL,
`cache_size` bigint(21) unsigned NOT NULL,
`cycle` bigint(21) unsigned NOT NULL, /* error */
`round` bigint(21) NOT NULL
`cycle_count` bigint(21) NOT NULL
) sequence=1;
......@@ -215,28 +216,28 @@ CREATE OR REPLACE TABLE t1 (
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
CREATE OR REPLACE TABLE t1 (
`next_value` bigint(21),
`min_value` bigint(21) NOT NULL,
`max_value` bigint(21) NOT NULL,
`start` bigint(21) NOT NULL,
`next_not_cached_value` bigint(21), /* error */
`minimum_value` bigint(21) NOT NULL,
`maximum_value` bigint(21) NOT NULL,
`start_value` bigint(21) NOT NULL,
`increment` bigint(21) NOT NULL,
`cache` bigint(21) NOT NULL,
`cycle` tinyint(1) unsigned NOT NULL,
`round` bigint(21) NOT NULL
`cache_size` bigint(21) unsigned NOT NULL,
`cycle_option` tinyint(1) unsigned NOT NULL,
`cycle_count` bigint(21) NOT NULL
) sequence=1;
# Extra field
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
CREATE OR REPLACE TABLE t1 (
`next_value` bigint(21) NOT NULL,
`min_value` bigint(21) NOT NULL,
`max_value` bigint(21) NOT NULL,
`start` bigint(21) NOT NULL,
`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` bigint(21) NOT NULL,
`cycle` tinyint(1) unsigned NOT NULL,
`round` bigint(21) NOT NULL,
`cache_size` bigint(21) unsigned NOT NULL,
`cycle_option` tinyint(1) unsigned NOT NULL,
`cycle_count` bigint(21) NOT NULL,
extra_field bigint(21)
) sequence=1;
......@@ -244,29 +245,29 @@ CREATE OR REPLACE TABLE t1 (
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
CREATE OR REPLACE TABLE t1 (
`min_value` bigint(21) NOT NULL,
`max_value` bigint(21) NOT NULL,
`next_value` bigint(21) NOT NULL,
`start` bigint(21) NOT NULL,
`minimum_value` bigint(21) NOT NULL,
`next_not_cached_value` bigint(21) NOT NULL,
`maximum_value` bigint(21) NOT NULL,
`start_value` bigint(21) NOT NULL,
`increment` bigint(21) NOT NULL,
`cache` bigint(21) NOT NULL,
`cycle` tinyint(1) unsigned NOT NULL,
`round` bigint(21) NOT NULL
`cache_size` bigint(21) unsigned NOT NULL,
`cycle_option` tinyint(1) unsigned NOT NULL,
`cycle_count` bigint(21) NOT NULL
) sequence=1;
# key
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
CREATE OR REPLACE TABLE t1 (
`next_value` bigint(21) NOT NULL,
`min_value` bigint(21) NOT NULL,
`max_value` bigint(21) NOT NULL,
`start` bigint(21) NOT NULL,
`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` bigint(21) NOT NULL,
`cycle` tinyint(1) unsigned NOT NULL,
`round` bigint(21) NOT NULL,
key key1 (next_value)
`cache_size` bigint(21) unsigned NOT NULL,
`cycle_option` tinyint(1) unsigned NOT NULL,
`cycle_count` bigint(21) NOT NULL,
key key1 (next_not_cached_value)
) sequence=1;
drop sequence if exists t1;
......
......@@ -24,28 +24,28 @@ 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;
use s_db;
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;
use s_db;
......@@ -161,13 +161,13 @@ priv test
connection m_normal_1;
create sequence s_db.s1;
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
select next value for s_db.s1;
next value for s_db.s1
1
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
1001 1 9223372036854775806 1 1 1000 0 0
create sequence s_db.s2;
drop sequence s_db.s2;
......@@ -250,20 +250,20 @@ connection slave;
connection s_normal_3;
use s_db;
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;
next value for s_t
1
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
6 1 20 1 1 5 1 0
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
6 1 20 1 1 5 1 0
------------------------------------------
master update nextval;
......@@ -272,12 +272,12 @@ connection m_normal_1;
select next value for s_t;
next value for s_t
2
update s_t set next_value= 11;
update s_t set next_not_cached_value= 11;
ERROR HY000: Storage engine SEQUENCE of the table `s_db`.`s_t` doesn't have this option
alter sequence s_t restart=11;
commit;
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;
......@@ -286,29 +286,29 @@ 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;
next value for s_t
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
16 1 20 1 1 5 1 0
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
------------------------------------------
connection m_normal_1;
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 s_t set next_value= 11,start=10, min_value=11;
update s_t set next_not_cached_value= 11,start_value=10, minimum_value=11;
ERROR HY000: Storage engine SEQUENCE of the table `s_db`.`s_t` doesn't have this option
ALTER SEQUENCE s_t restart with 11 start=10 minvalue=11;
ERROR HY000: Sequence 's_db.s_t' values are conflicting
......@@ -549,14 +549,14 @@ 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;
connection slave;
use s_db;
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.
......@@ -577,14 +577,14 @@ 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;
connection slave;
use s_db;
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 m_normal_1;
use s_db;
......@@ -609,13 +609,13 @@ select next value for s1;
next value for s1
1
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;
use s_db;
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;
use s_db;
......@@ -788,7 +788,7 @@ select * from t1;
a
1
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
1001 1 9223372036854775806 1 1 1000 0 0
select previous value for s1;
previous value for s1
......@@ -810,7 +810,7 @@ a (next value for s1)
2 3
do setval(s1,10000,0);
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
10000 1 9223372036854775806 1 1 1000 0 0
connection m_normal_2;
drop table t1;
......
......@@ -263,7 +263,7 @@ select * from s_t;
connection m_normal_1;
select next value for s_t;
--error ER_ILLEGAL_HA
update s_t set next_value= 11;
update s_t set next_not_cached_value= 11;
alter sequence s_t restart=11;
commit;
......@@ -295,7 +295,7 @@ select * from s_t;
connection m_normal_1;
select * from s_t;
--error ER_ILLEGAL_HA
update s_t set next_value= 11,start=10, min_value=11;
update s_t set next_not_cached_value= 11,start_value=10, minimum_value=11;
--error ER_SEQUENCE_INVALID_DATA
ALTER SEQUENCE s_t restart with 11 start=10 minvalue=11;
commit;
......
......@@ -5,14 +5,14 @@ CREATE SEQUENCE x1 engine=innodb;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `a1` (
`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=Aria SEQUENCE=1;
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO `a1` VALUES (1,1,9223372036854775806,1,1,1000,0,0);
......@@ -27,14 +27,14 @@ INSERT INTO `t1` VALUES (1),(2);
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `x1` (
`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=InnoDB SEQUENCE=1;
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO `x1` VALUES (1,1,9223372036854775806,1,1,1000,0,0);
......
This diff is collapsed.
......@@ -8,27 +8,27 @@
CREATE SEQUENCE t1 start with 1 minvalue 1 maxvalue 10 increment by 1 cache 2 cycle;
show create table t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select NEXT VALUE for t1,seq from seq_1_to_20;
......@@ -36,27 +36,27 @@ drop sequence t1;
CREATE SEQUENCE t1 minvalue 1 maxvalue 10 increment by -1 cache 2 cycle engine=aria;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select NEXT VALUE for t1,seq from seq_1_to_20;
......@@ -85,7 +85,7 @@ select next value for s1;
drop sequence s1;
#
# Test that flush tables jumps to next next_value
# Test that flush tables jumps to next next_not_cached_value
#
CREATE SEQUENCE t1 start with 1 minvalue 1 maxvalue 100 increment by 1 cache 10;
......@@ -116,23 +116,23 @@ drop sequence t9;
CREATE SEQUENCE s1 cache=0;
select * from s1;
select next value for s1;
select next_value from s1;
select next_not_cached_value from s1;
select next value for s1;
select next_value from s1;
select next_not_cached_value from s1;
DROP SEQUENCE s1;
CREATE SEQUENCE s1 cache=1;
select next_value from s1;
select next_not_cached_value from s1;
select next value for s1;
select next_value from s1;
select next_not_cached_value from s1;
select next value for s1;
select next_value from s1;
select next_not_cached_value from s1;
DROP SEQUENCE s1;
CREATE SEQUENCE s1 cache=2;
select next_value from s1;
select next_not_cached_value from s1;
select next value for s1;
select next_value from s1;
select next_not_cached_value from s1;
select next value for s1;
select next_value from s1;
select next_not_cached_value from s1;
DROP SEQUENCE s1;
#
......@@ -196,7 +196,7 @@ drop sequence s1;
CREATE SEQUENCE t1 start with 5 minvalue 1 maxvalue 10 increment by 1 cache 5 cycle;
explain select next value for t1;
explain select next value for t1, min_value from t1;
explain select next value for t1, minimum_value from t1;
drop table t1;
#
......@@ -244,7 +244,7 @@ drop table t1;
create sequence t1;
select next value for t1;
--error ER_BAD_FIELD_ERROR
select next value for t1, min_value;
select next value for t1, minimum_value;
drop sequence t1;
--echo #
......
......@@ -37,16 +37,16 @@ select next value for s1;
next value for s1
1001
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
2001 1 9223372036854775806 1 1 1000 0 0
drop sequence s1;
#
# NSERT
# INSERT
#
create sequence s1;
create sequence s2;
insert into s1 (next_value, min_value) values (100,1000);
ERROR HY000: Field 'max_value' doesn't have a default value
insert into s1 (next_not_cached_value, minimum_value) values (100,1000);
ERROR HY000: Field 'maximum_value' doesn't have a default value
insert into s1 values (next value for s1, 1,9223372036854775806,1,1,1000,0,0);
ERROR HY000: Table 's1' is specified twice, both as a target for 'INSERT' and as a separate source for data
insert into s1 values (next value for s2, 1,9223372036854775806,1,1,1000,0,0);
......@@ -58,17 +58,17 @@ ERROR HY000: Sequence 'test.s1' values are conflicting
insert into s1 values(0,9223372036854775806,1,1,1,1000,0,0);
ERROR HY000: Sequence 'test.s1' values are conflicting
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
1 1 9223372036854775806 1 1 1000 0 0
insert into s1 values(1000,1,9223372036854775806,1,1,1000,0,0);
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
1000 1 9223372036854775806 1 1 1000 0 0
select next value for s1;
next value for s1
1000
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
2000 1 9223372036854775806 1 1 1000 0 0
insert into s2 values(0, 1, 10, 1, 2, 1, 1, 0);
ERROR HY000: Sequence 'test.s2' values are conflicting
......@@ -77,9 +77,9 @@ drop sequence s1,s2;
# UPDATE and DELETE
#
create sequence s1;
update s1 set next_value=100;
update s1 set next_not_cached_value=100;
ERROR HY000: Storage engine SEQUENCE of the table `test`.`s1` doesn't have this option
delete from s1 where next_value > 0;
delete from s1 where next_not_cached_value > 0;
ERROR HY000: Storage engine SEQUENCE of the table `test`.`s1` doesn't have this option
drop sequence s1;
#
......@@ -106,7 +106,7 @@ drop view v1;
create sequence s1 engine=innodb;
LOCK TABLES s1 READ;
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
1 1 9223372036854775806 1 1 1000 0 0
UNLOCK TABLES;
LOCK TABLES s1 WRITE;
......@@ -123,7 +123,7 @@ count(nextval(s1))
2000
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
2001 1 9223372036854775806 1 1 1000 0 0
drop sequence s1;
create sequence s1 cache=1000 engine=innodb;
......@@ -138,13 +138,13 @@ select count(nextval(s1)) from seq_1_to_2000;
count(nextval(s1))
2000
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
4001 1 9223372036854775806 1 1 1000 0 0
commit;
disconnect addconroot;
connection default;
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
4001 1 9223372036854775806 1 1 1000 0 0
commit;
drop sequence s1;
......@@ -29,13 +29,13 @@ select * from s1;
drop sequence s1;
--echo #
--echo # NSERT
--echo # INSERT
--echo #
create sequence s1;
create sequence s2;
--error ER_NO_DEFAULT_FOR_FIELD
insert into s1 (next_value, min_value) values (100,1000);
insert into s1 (next_not_cached_value, minimum_value) values (100,1000);
--error ER_UPDATE_TABLE_USED
insert into s1 values (next value for s1, 1,9223372036854775806,1,1,1000,0,0);
--error ER_WRONG_INSERT_INTO_SEQUENCE
......@@ -61,9 +61,9 @@ drop sequence s1,s2;
create sequence s1;
--error ER_ILLEGAL_HA
update s1 set next_value=100;
update s1 set next_not_cached_value=100;
--error ER_ILLEGAL_HA
delete from s1 where next_value > 0;
delete from s1 where next_not_cached_value > 0;
drop sequence s1;
--echo #
......@@ -117,3 +117,17 @@ connection default;
select * from s1;
commit;
drop sequence s1;
--echo #
--echo # Flush tables with read lock
--echo #
create sequence s1;
select next value for s1;
flush tables with read lock;
--error 1223
create sequence s2;
--error 1223
select next value for s1;
unlock tables;
drop sequence s1;
......@@ -79,33 +79,32 @@ drop sequence s2;
connection master;
create table t_1(id int);
--error ER_WRONG_OBJECT
--error ER_NOT_SEQUENCE
show create sequence t_1;
drop table t_1;
--error ER_PARSE_ERROR
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;
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);
......@@ -131,14 +130,14 @@ 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;
......@@ -355,7 +354,7 @@ connection master;
--sync_slave_with_master
connection s_normal_3;
select next_value from s_t;
select next_not_cached_value from s_t;
--echo ------------------------------------------
--echo master ALTER SEQUENCE
......@@ -785,7 +784,7 @@ drop sequence s1;
connection m_normal_1;
--echo ------------------------------------------
--echo round increment by round
--echo cycle_count increment by cycle_count
--echo ------------------------------------------
create sequence s1 start with 5 minvalue 2 maxvalue 7 cache 1 cycle;
select next value for s1;
......@@ -806,15 +805,15 @@ drop sequence s1;
create sequence s1 start with 2 minvalue 1 maxvalue 3 increment by 3 nocache cycle;
select next value for s1;
select next_value,round from s1;
select next_not_cached_value,cycle_count from s1;
select next value for s1;
select next_value,round from s1;
select next_not_cached_value,cycle_count from s1;
select next value for s1;
select next_value,round from s1;
select next_not_cached_value,cycle_count from s1;
select next value for s1;
select next_value,round from s1;
select next_not_cached_value,cycle_count from s1;
select next value for s1;
select next_value,round from s1;
select next_not_cached_value,cycle_count from s1;
drop sequence s1;
create sequence s1 start with 2 minvalue 1 maxvalue 3 increment by 3 cache 2 nocycle;
......@@ -827,29 +826,29 @@ drop sequence s1;
--echo beyond ulonglong maxvalue
--echo ------------------------------------------
create sequence s1 start with 9223372036854775805 minvalue 9223372036854775804 maxvalue 9223372036854775806 cache 1 cycle;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
drop sequence s1;
create sequence s1 start with 9223372036854775805 minvalue 9223372036854775804 maxvalue 9223372036854775806 cache 10 cycle;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, round from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
select next value for s1, cycle_count from s1;
drop sequence s1;
connection master;
......
......@@ -5,26 +5,26 @@ Note 1051 Unknown table 'test.t1'
# Test setval function
#
CREATE SEQUENCE t1 cache 10 engine=myisam;
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
1 0
do setval(t1,10);
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
11 0
select next value for t1;
next value for t1
11
do setval(t1,12,1);
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
21 0
select next value for t1;
next value for t1
13
do setval(t1,15,0);
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
21 0
select next value for t1;
next value for t1
......@@ -39,15 +39,15 @@ do setval(t1,1000,0);
select next value for t1;
next value for t1
1000
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
1010 0
do setval(t1,2000,0);
select next value for t1;
next value for t1
2000
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
2010 0
select setval(t1,1000,0);
setval(t1,1000,0)
......@@ -61,8 +61,8 @@ NULL
select next value for t1;
next value for t1
2002
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
2010 0
select setval(t1,2002,0);
setval(t1,2002,0)
......@@ -76,40 +76,40 @@ setval(t1,2010,0)
select next value for t1;
next value for t1
2010
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
2020 0
drop sequence t1;
#
# Testing with cycle
#
CREATE SEQUENCE t1 cache=10 maxvalue=100 cycle engine=innodb;
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
1 0
select setval(t1,100,0);
setval(t1,100,0)
100
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
100 0
select next value for t1;
next value for t1
100
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
101 0
select setval(t1,100,0);
setval(t1,100,0)
NULL
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
101 0
select next value for t1;
next value for t1
1
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
11 1
select next value for t1;
next value for t1
......@@ -117,8 +117,8 @@ next value for t1
select setval(t1,100,0,1);
setval(t1,100,0,1)
100
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
100 1
select next value for t1;
next value for t1
......@@ -126,8 +126,8 @@ next value for t1
select setval(t1,100,1,2);
setval(t1,100,1,2)
100
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
101 2
select next value for t1;
next value for t1
......@@ -135,8 +135,8 @@ next value for t1
select setval(t1,100,0,3);
setval(t1,100,0,3)
100
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
100 3
select next value for t1;
next value for t1
......@@ -146,27 +146,27 @@ drop sequence t1;
# Testing extreme values
#
CREATE SEQUENCE t1 cache=10 maxvalue=100 engine=innodb;
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
1 0
select setval(t1,200);
setval(t1,200)
200
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
101 0
select next value for t1;
ERROR HY000: Sequence 'test.t1' has run out
drop sequence t1;
CREATE SEQUENCE t1 cache=10 maxvalue=100 cycle engine=innodb;
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
1 0
select setval(t1,200);
setval(t1,200)
200
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
101 0
select next value for t1;
next value for t1
......@@ -176,8 +176,8 @@ CREATE SEQUENCE t1 cache=10 maxvalue=0 increment=-10;
select setval(t1,-10);
setval(t1,-10)
-10
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
-20 0
select next value for t1;
next value for t1
......@@ -185,8 +185,8 @@ next value for t1
select setval(t1,-15);
setval(t1,-15)
NULL
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
-120 0
select next value for t1;
next value for t1
......@@ -214,8 +214,8 @@ CREATE SEQUENCE t1 cache=10 maxvalue=0 increment=-10;
select setval(t1,-10,0);
setval(t1,-10,0)
-10
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
-10 0
select next value for t1;
next value for t1
......@@ -231,8 +231,8 @@ setval(t1,10,0) setval(t1,15,1) setval(t1,5,1)
select next value for t1;
next value for t1
16
select next_value,round from t1;
next_value round
select next_not_cached_value,cycle_count from t1;
next_not_cached_value cycle_count
1016 0
explain extended select setval(t1,100),setval(t1,100,TRUE),setval(t1,100,FALSE,50);
id select_type table type possible_keys key key_len ref rows filtered Extra
......
......@@ -8,35 +8,35 @@ drop table if exists t1;
--echo #
CREATE SEQUENCE t1 cache 10 engine=myisam;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
do setval(t1,10);
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
do setval(t1,12,1);
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
do setval(t1,15,0);
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select setval(t1,16,0);
select next value for t1;
do setval(t1,1000,0);
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
do setval(t1,2000,0);
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
# Set smaller value
select setval(t1,1000,0);
select next value for t1;
select setval(t1,1000,TRUE);
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select setval(t1,2002,0);
select next value for t1;
select setval(t1,2010,0);
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
drop sequence t1;
--echo #
......@@ -44,24 +44,24 @@ drop sequence t1;
--echo #
CREATE SEQUENCE t1 cache=10 maxvalue=100 cycle engine=innodb;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select setval(t1,100,0);
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select setval(t1,100,0);
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select setval(t1,100,0,1);
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select setval(t1,100,1,2);
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select setval(t1,100,0,3);
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
drop sequence t1;
......@@ -70,26 +70,26 @@ drop sequence t1;
--echo #
CREATE SEQUENCE t1 cache=10 maxvalue=100 engine=innodb;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select setval(t1,200);
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
drop sequence t1;
CREATE SEQUENCE t1 cache=10 maxvalue=100 cycle engine=innodb;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select setval(t1,200);
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
drop sequence t1;
CREATE SEQUENCE t1 cache=10 maxvalue=0 increment=-10;
select setval(t1,-10);
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select setval(t1,-15);
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
select setval(t1,-500,FALSE);
select next value for t1;
......@@ -101,7 +101,7 @@ drop sequence t1;
CREATE SEQUENCE t1 cache=10 maxvalue=0 increment=-10;
select setval(t1,-10,0);
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
select next value for t1;
drop sequence t1;
......@@ -112,7 +112,7 @@ drop sequence t1;
CREATE SEQUENCE t1;
select setval(t1,10,0),setval(t1,15,1),setval(t1,5,1);
select next value for t1;
select next_value,round from t1;
select next_not_cached_value,cycle_count from t1;
explain extended select setval(t1,100),setval(t1,100,TRUE),setval(t1,100,FALSE,50);
drop sequence t1;
......
#
# Create
#
create temporary sequence s1 engine=innodb;
alter table s1 engine myisam;
select nextval(s1);
nextval(s1)
1
select * from s1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1001 1 9223372036854775806 1 1 1000 0 0
drop temporary sequence s1;
--source include/have_sequence.inc
--source include/have_innodb.inc
#
# Test temporary sequences
#
--echo #
--echo # Create
--echo #
create temporary sequence s1 engine=innodb;
alter table s1 engine myisam;
select nextval(s1);
select * from s1;
drop temporary sequence s1;
......@@ -198,6 +198,18 @@ int ha_sequence::write_row(uchar *buf)
/* This calls is from ha_open() as part of create table */
DBUG_RETURN(file->write_row(buf));
}
if (unlikely(sequence->initialized == SEQUENCE::SEQ_IN_ALTER))
{
int error= 0;
/* This is called from alter table */
tmp_seq.read_fields(table);
if (tmp_seq.check_and_adjust(0))
DBUG_RETURN(HA_ERR_SEQUENCE_INVALID_DATA);
sequence->copy(&tmp_seq);
if (!(error= file->write_row(buf)))
sequence->initialized= SEQUENCE::SEQ_READY_TO_USE;
DBUG_RETURN(error);
}
if (unlikely(sequence->initialized != SEQUENCE::SEQ_READY_TO_USE))
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
......@@ -280,7 +292,7 @@ int ha_sequence::extra(enum ha_extra_function operation)
if (operation == HA_EXTRA_PREPARE_FOR_ALTER_TABLE)
{
/* In case of ALTER TABLE allow ::write_row() to copy rows */
sequence->initialized= SEQUENCE::SEQ_IN_PREPARE;
sequence->initialized= SEQUENCE::SEQ_IN_ALTER;
}
return file->extra(operation);
}
......
......@@ -47,18 +47,19 @@ struct Field_definition
static Field_definition sequence_structure[]=
{
{"next_value", 21, &type_handler_longlong, {STRING_WITH_LEN("next not cached value")},
FL},
{"min_value", 21, &type_handler_longlong, {STRING_WITH_LEN("min value")}, FL},
{"max_value", 21, &type_handler_longlong, {STRING_WITH_LEN("max value")}, FL},
{"start", 21, &type_handler_longlong, {STRING_WITH_LEN("start value")}, FL},
{"next_not_cached_value", 21, &type_handler_longlong,
{STRING_WITH_LEN("")}, FL},
{"minimum_value", 21, &type_handler_longlong, STRING_WITH_LEN(""), FL},
{"maximum_value", 21, &type_handler_longlong, STRING_WITH_LEN(""), FL},
{"start_value", 21, &type_handler_longlong, {STRING_WITH_LEN("start value when sequences is created or value if RESTART is used")}, FL},
{"increment", 21, &type_handler_longlong,
{C_STRING_WITH_LEN("increment value")}, FL},
{"cache", 21, &type_handler_longlong, {STRING_WITH_LEN("cache size")}, FL},
{"cycle", 1, &type_handler_tiny, {STRING_WITH_LEN("cycle state")},
{"cache_size", 21, &type_handler_longlong, STRING_WITH_LEN(""),
FL | UNSIGNED_FLAG},
{"cycle_option", 1, &type_handler_tiny, {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 },
{"round", 21, &type_handler_longlong,
{STRING_WITH_LEN("How many cycles has been done")}, FL},
{"cycle_count", 21, &type_handler_longlong,
{STRING_WITH_LEN("How many cycles have been done")}, FL},
{NULL, 0, &type_handler_longlong, {STRING_WITH_LEN("")}, 0}
};
......@@ -458,9 +459,12 @@ int SEQUENCE::read_initial_values(TABLE *table_arg)
DBUG_RETURN(error);
}
/*
Read data from sequence table and update values
Done when table is opened
Do the actiual reading of data from sequence table and
update values in the sequence object.
Called once from when table is opened
*/
int SEQUENCE::read_stored_values()
......
......@@ -88,7 +88,8 @@ class sequence_definition :public Sql_alloc
class SEQUENCE :public sequence_definition
{
public:
enum seq_init { SEQ_UNINTIALIZED, SEQ_IN_PREPARE, SEQ_READY_TO_USE };
enum seq_init { SEQ_UNINTIALIZED, SEQ_IN_PREPARE, SEQ_IN_ALTER,
SEQ_READY_TO_USE };
SEQUENCE();
~SEQUENCE();
int read_initial_values(TABLE *table);
......@@ -101,6 +102,7 @@ class SEQUENCE :public sequence_definition
{
sequence_definition::operator= (*seq);
adjust_values(reserved_until);
all_values_used= 0;
}
longlong next_value(TABLE *table, bool second_round, int *error);
bool set_value(TABLE *table, longlong next_value, ulonglong round_arg,
......
......@@ -1181,8 +1181,8 @@ mysqld_show_create_get_fields(THD *thd, TABLE_LIST *table_list,
else if (thd->lex->table_type == TABLE_TYPE_SEQUENCE &&
table_list->table->s->table_type != TABLE_TYPE_SEQUENCE)
{
my_error(ER_WRONG_OBJECT, MYF(0),
table_list->db, table_list->table_name, "SEQUENCE");
my_error(ER_NOT_SEQUENCE, MYF(0),
table_list->db, table_list->table_name);
goto exit;
}
......@@ -4372,7 +4372,8 @@ fill_schema_table_by_open(THD *thd, bool is_show_fields_or_keys,
*/
if (!is_show_fields_or_keys && result &&
(thd->get_stmt_da()->sql_errno() == ER_NO_SUCH_TABLE ||
thd->get_stmt_da()->sql_errno() == ER_WRONG_OBJECT))
thd->get_stmt_da()->sql_errno() == ER_WRONG_OBJECT ||
thd->get_stmt_da()->sql_errno() == ER_NOT_SEQUENCE))
{
/*
Hide error for a non-existing table.
......@@ -4699,7 +4700,8 @@ static int fill_schema_table_from_frm(THD *thd, TABLE *table,
if (!share)
{
if (thd->get_stmt_da()->sql_errno() == ER_NO_SUCH_TABLE ||
thd->get_stmt_da()->sql_errno() == ER_WRONG_OBJECT)
thd->get_stmt_da()->sql_errno() == ER_WRONG_OBJECT ||
thd->get_stmt_da()->sql_errno() == ER_NOT_SEQUENCE)
{
res= 0;
}
......
......@@ -11969,17 +11969,22 @@ delete_limit_clause:
| LIMIT limit_option ROWS_SYM EXAMINED_SYM { thd->parse_error(); MYSQL_YYABORT; }
;
opt_plus:
/* empty */
| '+'
;
int_num:
NUM { int error; $$= (int) my_strtoll10($1.str, (char**) 0, &error); }
opt_plus NUM { int error; $$= (int) my_strtoll10($2.str, (char**) 0, &error); }
| '-' NUM { int error; $$= -(int) my_strtoll10($2.str, (char**) 0, &error); }
ulong_num:
NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
opt_plus NUM { int error; $$= (ulong) my_strtoll10($2.str, (char**) 0, &error); }
| HEX_NUM { $$= (ulong) strtol($1.str, (char**) 0, 16); }
| LONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
| ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
| DECIMAL_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
| FLOAT_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
| opt_plus LONG_NUM { int error; $$= (ulong) my_strtoll10($2.str, (char**) 0, &error); }
| opt_plus ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($2.str, (char**) 0, &error); }
| opt_plus DECIMAL_NUM { int error; $$= (ulong) my_strtoll10($2.str, (char**) 0, &error); }
| opt_plus FLOAT_NUM { int error; $$= (ulong) my_strtoll10($2.str, (char**) 0, &error); }
;
real_ulong_num:
......@@ -11991,18 +11996,18 @@ real_ulong_num:
;
longlong_num:
NUM { int error; $$= (longlong) my_strtoll10($1.str, (char**) 0, &error); }
opt_plus NUM { int error; $$= (longlong) my_strtoll10($2.str, (char**) 0, &error); }
| LONG_NUM { int error; $$= (longlong) my_strtoll10($1.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:
NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
| ULONGLONG_NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
| LONG_NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
| DECIMAL_NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
| FLOAT_NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
opt_plus NUM { int error; $$= (ulonglong) my_strtoll10($2.str, (char**) 0, &error); }
| opt_plus ULONGLONG_NUM { int error; $$= (ulonglong) my_strtoll10($2.str, (char**) 0, &error); }
| opt_plus LONG_NUM { int error; $$= (ulonglong) my_strtoll10($2.str, (char**) 0, &error); }
| opt_plus DECIMAL_NUM { int error; $$= (ulonglong) my_strtoll10($2.str, (char**) 0, &error); }
| opt_plus FLOAT_NUM { int error; $$= (ulonglong) my_strtoll10($2.str, (char**) 0, &error); }
;
real_ulonglong_num:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment