1
0
mirror of https://github.com/MariaDB/server.git synced 2025-05-31 08:42:45 +03:00
Monty 6a779a6d28 Make SEQUENCE working with replication
- Old sequence code forced row based replication for any statements that
  refered to a sequence table. What is new is that row based replication
  is now sequence aware:
   - NEXT VALUE is now generating a short row based event with only
     next_value and round being replicated.
   - Short row based events are now on the slave updated as trough
     SET_VALUE(sequence_name)
   - Full row based events are on the slave updated with a full insert,
     which is practically same as ALTER SEQUENCE.
- INSERT on a SEQUENCE table does now a EXCLUSIVE LOCK to ensure that
  it is logged in binary log before any following NEXT VALUE calls.
- Enable all sequence tests and fixed found bugs
- ALTER SEQUENCE doesn't anymore allow changes that makes the next_value
  outside of allowed range
- SEQUENCE changes are done with TL_WRITE_ALLOW_WRITE. Because of this
  one can generate a statement for MyISAM with both
  TL_WRITE_CONCURRENT_INSERT and TL_WRITE_ALLOW_WRITE. To fix a warning
  I had to add an extra test in thr_lock.c for this.
- Removed UPDATE of SEQUENCE (no need to support this as we
  have ALTER SEQUENCE, which takes the EXCLUSIVE lock properly.
- Removed DBUG_ASSERT() in MDL_context::upgrade_shared_lock. This was
  removed upstream in MySQL 5.6 in 72f823de453.
- Simplified test in decided_logging_format() by using sql_command_flags()
- Fix that we log DROP SEQUENCE correctly.
- Fixed that Aria works with SEQUENCE
2017-05-23 21:12:27 +03:00

263 lines
6.3 KiB
Plaintext

--source include/have_sequence.inc
--source include/have_innodb.inc
#
# Test sequence generation
#
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 value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select NEXT VALUE for t1,seq from seq_1_to_20;
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 value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select next value for t1;
select next_value,round from t1;
select NEXT VALUE for t1,seq from seq_1_to_20;
drop sequence t1;
CREATE SEQUENCE t1 start with 8 minvalue 1 maxvalue 10 increment by 1 cache 2 nocycle;
select next value for t1;
select next value for t1;
select next value for t1;
select previous value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
select previous value for t1;
--error ER_SEQUENCE_RUN_OUT
select next value for t1;
drop sequence t1;
create sequence s1 start with 1 cache 2 maxvalue 5;
select next value for s1;
select next value for s1;
select next value for s1;
select next value for s1;
select next value for s1;
--error ER_SEQUENCE_RUN_OUT
select next value for s1;
drop sequence s1;
#
# Test that flush tables jumps to next next_value
#
CREATE SEQUENCE t1 start with 1 minvalue 1 maxvalue 100 increment by 1 cache 10;
select next value for t1;
select * from t1;
flush tables;
select next value for t1;
select nextval(t1);
drop sequence t1;
#
# Test currval/previous
#
CREATE SEQUENCE t9 start with 1 minvalue 1 maxvalue 10 increment by 1 cache 5 cycle;
select previous value for t9;
select next value for t9;
select previous value for t9, lastval(t9);
select next value for t9;
select previous value for t9, lastval(t9);
select seq, previous value for t9, NEXT VALUE for t9, previous value for t9 from seq_1_to_20;
select * from t9;
drop sequence t9;
#
# CACHE = 0 should be same as CACHE = 1
#
CREATE SEQUENCE s1 cache=0;
select * from s1;
select next value for s1;
select next_value from s1;
select next value for s1;
select next_value from s1;
DROP SEQUENCE s1;
CREATE SEQUENCE s1 cache=1;
select next_value from s1;
select next value for s1;
select next_value from s1;
select next value for s1;
select next_value from s1;
DROP SEQUENCE s1;
CREATE SEQUENCE s1 cache=2;
select next_value from s1;
select next value for s1;
select next_value from s1;
select next value for s1;
select next_value from s1;
DROP SEQUENCE s1;
#
# Negative increment for sequence
#
CREATE SEQUENCE s1;
select next value for s1;
select next value for s1;
select next value for s1;
select next value for s1;
alter sequence s1 increment -2;
select * from s1;
select next value for s1;
select next value for s1;
alter sequence s1 restart 6;
select next value for s1;
select next value for s1;
select next value for s1;
--error ER_SEQUENCE_RUN_OUT
select next value for s1;
DROP SEQUENCE s1;
#
# Check what happens when one refers to a sequence that has been closed/deleted
#
CREATE SEQUENCE t1 start with 1 minvalue 1 maxvalue 10 increment by 1 cache 5 cycle;
select next value for t1;
select previous value for t1;
flush tables;
select previous value for t1;
drop sequence t1;
--error ER_NO_SUCH_TABLE
select previous value for t1;
CREATE SEQUENCE t1 start with 5 minvalue 1 maxvalue 10 increment by 1 cache 5 cycle;
select previous value for t1;
select next value for t1;
select previous value for t1;
drop sequence t1;
# This failed in an early build
CREATE or replace SEQUENCE s1 MINVALUE 1 MAXVALUE 9999999999
INCREMENT BY 1 START WITH 3984356 CACHE 20 CYCLE engine=innodb;
show create table s1;
select * from s1;
select NEXT VALUE FOR s1;
select NEXT VALUE FOR s1;
select NEXT VALUE FOR s1;
select * from s1;
FLUSH TABLES;
select * from s1;
select NEXT VALUE FOR s1;
select * from s1;
drop sequence s1;
#
# Explain
#
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;
drop table t1;
#
# Using insert with NEXT VALUE
#
CREATE SEQUENCE s1;
CREATE TABLE t1 (a int);
insert into t1 values (next value for s1);
insert into t1 values (next value for s1);
select * from t1;
drop table t1,s1;
#
# Using update with NEXT VALUE
#
CREATE SEQUENCE s1;
CREATE TABLE t1 (a int primary key auto_increment, b int default 0) engine=myisam;
insert into t1 values (),(),(),(),(),(),();
update t1 set b= next value for s1 where a <= 3;
select * from t1;
drop table t1,s1;
#
# NO CACHE and InnoDB
#
CREATE OR REPLACE SEQUENCE s1 MINVALUE 1 MAXVALUE 9999999999 INCREMENT BY 1 START WITH 3984356 nocache CYCLE engine='innodb';
select * from s1;
select next value for s1;
explain extended select next value for s1;
explain extended select previous value for s1;
drop sequence s1;
#
# Some error testing
#
create table t1 (a int);
--error ER_NOT_SEQUENCE
select next value for t1;
drop table t1;
create sequence t1;
select next value for t1;
--error ER_BAD_FIELD_ERROR
select next value for t1, min_value;
drop sequence t1;
--echo #
--echo # MDEV-12854 Synchronize CREATE..SELECT data type and result set metadata data type for INT functions
--echo #
--enable_metadata
--disable_ps_protocol
CREATE SEQUENCE s1;
SELECT
NEXT VALUE FOR s1,
PREVIOUS VALUE FOR s1;
DROP SEQUENCE s1;
--enable_ps_protocol
--disable_metadata