mirror of
				https://github.com/MariaDB/server.git
				synced 2025-11-04 12:56:14 +01:00 
			
		
		
		
	Two new error codes ER_SEQUENCE_TABLE_HAS_TOO_FEW_ROWS and ER_SEQUENCE_TABLE_HAS_TOO_MANY_ROWS were introduced in MDEV-36032 in both 10.11 and, as part of MDEV-22491, 12.0. Here we remove them from 10.11, but they should remain in 12.0.
		
			
				
	
	
		
			378 lines
		
	
	
	
		
			9.8 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			378 lines
		
	
	
	
		
			9.8 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
--source include/have_sequence.inc
 | 
						|
--source include/have_innodb.inc
 | 
						|
 | 
						|
drop table if exists t1;
 | 
						|
 | 
						|
--echo #
 | 
						|
--echo # Test alter sequence
 | 
						|
--echo #
 | 
						|
 | 
						|
--disable_ps2_protocol
 | 
						|
CREATE SEQUENCE t1 nocache engine=myisam;
 | 
						|
select * from t1;
 | 
						|
select next value for t1;
 | 
						|
alter sequence t1 start=50;
 | 
						|
show create sequence t1;
 | 
						|
select * from t1;
 | 
						|
select next value for t1;
 | 
						|
 | 
						|
alter sequence t1 minvalue=-100;
 | 
						|
show create sequence t1;
 | 
						|
select * from t1;
 | 
						|
--error ER_SEQUENCE_INVALID_DATA
 | 
						|
alter sequence t1 minvalue=100 start=100;
 | 
						|
alter sequence t1 minvalue=100 start=100 restart=100;
 | 
						|
show create sequence t1;
 | 
						|
select * from t1;
 | 
						|
 | 
						|
alter sequence t1 maxvalue=500;
 | 
						|
show create sequence t1;
 | 
						|
select * from t1;
 | 
						|
drop sequence t1;
 | 
						|
 | 
						|
CREATE SEQUENCE t1 engine=myisam;
 | 
						|
alter sequence t1 nocache;
 | 
						|
show create sequence t1;
 | 
						|
alter sequence t1 cache=100;
 | 
						|
flush tables;
 | 
						|
show create sequence t1;
 | 
						|
alter sequence t1 nocache;
 | 
						|
show create sequence t1;
 | 
						|
flush tables;
 | 
						|
show create sequence t1;
 | 
						|
select * from t1;
 | 
						|
select next value for t1;
 | 
						|
select next value for t1;
 | 
						|
select next value for t1;
 | 
						|
select next_not_cached_value, cycle_count from t1;
 | 
						|
drop sequence t1;
 | 
						|
 | 
						|
CREATE SEQUENCE t1 maxvalue=100 engine=myisam;
 | 
						|
alter sequence t1 no maxvalue;
 | 
						|
show create sequence t1;
 | 
						|
select * from t1;
 | 
						|
alter sequence t1 cycle;
 | 
						|
show create sequence t1;
 | 
						|
alter sequence t1 nocycle;
 | 
						|
alter sequence t1 start=15 restart minvalue=10 maxvalue=20 cycle;
 | 
						|
show create sequence t1;
 | 
						|
select * from t1;
 | 
						|
select NEXT VALUE for t1 from seq_1_to_10;
 | 
						|
alter sequence t1 restart with 17 minvalue=10 maxvalue=20 cycle;
 | 
						|
select NEXT VALUE for t1 from seq_1_to_10;
 | 
						|
drop sequence t1;
 | 
						|
 | 
						|
CREATE SEQUENCE t1 maxvalue=100;
 | 
						|
alter sequence t1 increment=-2 start with 50 minvalue=-100;
 | 
						|
show create sequence t1;
 | 
						|
select * from t1;
 | 
						|
select NEXT VALUE for t1 from seq_1_to_10;
 | 
						|
drop sequence t1;
 | 
						|
 | 
						|
--echo #
 | 
						|
--echo # InnoDB (some things work different with InnoDB)
 | 
						|
--echo
 | 
						|
 | 
						|
CREATE SEQUENCE t1 cache 10 engine=innodb;
 | 
						|
select * from t1;
 | 
						|
select next value for t1;
 | 
						|
alter sequence t1 start=100;
 | 
						|
show create sequence t1;
 | 
						|
select * from t1;
 | 
						|
select next value for t1;
 | 
						|
let $check_innodb_flags =
 | 
						|
select flag & 12288 is_sequence from information_schema.innodb_sys_tables
 | 
						|
where name='test/t1';
 | 
						|
evalp $check_innodb_flags;
 | 
						|
alter table t1 sequence=0;
 | 
						|
begin;
 | 
						|
delete from t1;
 | 
						|
rollback;
 | 
						|
evalp $check_innodb_flags;
 | 
						|
alter table t1 sequence=1;
 | 
						|
evalp $check_innodb_flags;
 | 
						|
alter table t1 sequence=0, algorithm=copy;
 | 
						|
evalp $check_innodb_flags;
 | 
						|
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
 | 
						|
alter table t1 sequence=1, algorithm=inplace;
 | 
						|
alter table t1 sequence=1, algorithm=copy;
 | 
						|
evalp $check_innodb_flags;
 | 
						|
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
 | 
						|
alter table t1 sequence=0, algorithm=inplace;
 | 
						|
drop sequence t1;
 | 
						|
 | 
						|
--echo #
 | 
						|
--echo # ALTER TABLE
 | 
						|
--echo #
 | 
						|
 | 
						|
CREATE SEQUENCE t1 engine=innodb;
 | 
						|
select next value for t1;
 | 
						|
alter table t1 rename t2;
 | 
						|
select next value for t2;
 | 
						|
rename table t2 to t1;
 | 
						|
select next value for t1;
 | 
						|
alter table t1 comment="foo";
 | 
						|
show create sequence t1;
 | 
						|
alter table t1 engine=myisam;
 | 
						|
show create sequence t1;
 | 
						|
alter table t1 engine=innodb;
 | 
						|
show create sequence t1;
 | 
						|
select * from t1;
 | 
						|
drop sequence t1;
 | 
						|
 | 
						|
#
 | 
						|
# Some error testing
 | 
						|
#
 | 
						|
 | 
						|
CREATE SEQUENCE t1 engine=myisam;
 | 
						|
--error ER_SEQUENCE_INVALID_DATA
 | 
						|
alter sequence t1 minvalue=100;
 | 
						|
drop sequence t1;
 | 
						|
 | 
						|
CREATE SEQUENCE t1 engine=myisam;
 | 
						|
--error ER_SEQUENCE_INVALID_DATA
 | 
						|
alter sequence t1 minvalue=25 maxvalue=20;
 | 
						|
drop sequence t1;
 | 
						|
 | 
						|
create table t1 (a int);
 | 
						|
--error ER_NOT_SEQUENCE
 | 
						|
alter sequence t1 minvalue=100;
 | 
						|
drop table t1;
 | 
						|
 | 
						|
--echo #
 | 
						|
--echo # MDEV-32795: ALTER SEQUENCE IF NOT EXISTS non_existing_seq Errors rather than note
 | 
						|
--echo #
 | 
						|
 | 
						|
alter sequence if exists t1 minvalue=100;
 | 
						|
 | 
						|
--error ER_UNKNOWN_SEQUENCES
 | 
						|
alter sequence t1 minvalue=100;
 | 
						|
 | 
						|
create sequence t1;
 | 
						|
--error ER_PARSE_ERROR
 | 
						|
alter sequence t1;
 | 
						|
drop sequence t1;
 | 
						|
 | 
						|
CREATE SEQUENCE t1 maxvalue=100;
 | 
						|
alter sequence t1 increment=-2 start with 50;
 | 
						|
select next value for t1;
 | 
						|
--error ER_SEQUENCE_RUN_OUT
 | 
						|
select next value for t1;
 | 
						|
select * from t1;
 | 
						|
alter sequence t1 restart;
 | 
						|
select next value for t1;
 | 
						|
alter sequence t1 restart with 90;
 | 
						|
select next value for t1;
 | 
						|
drop sequence t1;
 | 
						|
 | 
						|
#
 | 
						|
# MDEV-19977 Assertion `(0xFUL & mode) == LOCK_S || (0xFUL & mode) == LOCK_X'
 | 
						|
# failed in lock_rec_lock
 | 
						|
#
 | 
						|
 | 
						|
CREATE SEQUENCE t1 engine=innodb;
 | 
						|
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
 | 
						|
ALTER IGNORE TABLE t1 ADD CHECK (start_value < minimum_value);
 | 
						|
DROP SEQUENCE t1;
 | 
						|
 | 
						|
#
 | 
						|
# MDEV-19320 Sequence gets corrupted and produces ER_KEY_NOT_FOUND (Can't
 | 
						|
# find record) after ALTER .. ORDER BY
 | 
						|
#
 | 
						|
 | 
						|
CREATE SEQUENCE s;
 | 
						|
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
 | 
						|
ALTER TABLE s ORDER BY cache_size;
 | 
						|
SELECT NEXTVAL(s);
 | 
						|
DROP SEQUENCE s;
 | 
						|
 | 
						|
--echo #
 | 
						|
--echo # MDEV-33169 Alter sequence 2nd ps fails while alter sequence 2nd time (no ps) succeeds
 | 
						|
--echo #
 | 
						|
create sequence s;
 | 
						|
show create sequence s;
 | 
						|
alter sequence s maxvalue 123;
 | 
						|
show create sequence s;
 | 
						|
alter sequence s maxvalue 123;
 | 
						|
show create sequence s;
 | 
						|
drop sequence s;
 | 
						|
 | 
						|
create sequence s;
 | 
						|
show create sequence s;
 | 
						|
prepare stmt from 'alter sequence s maxvalue 123';
 | 
						|
execute stmt;
 | 
						|
show create sequence s;
 | 
						|
execute stmt;
 | 
						|
show create sequence s;
 | 
						|
deallocate prepare stmt;
 | 
						|
drop sequence s;
 | 
						|
 | 
						|
create sequence s;
 | 
						|
show create sequence s;
 | 
						|
create procedure p() alter sequence s maxvalue 123;
 | 
						|
call p;
 | 
						|
show create sequence s;
 | 
						|
call p;
 | 
						|
show create sequence s;
 | 
						|
drop procedure p;
 | 
						|
drop sequence s;
 | 
						|
 | 
						|
--echo #
 | 
						|
--echo # End of 10.4 tests
 | 
						|
--echo #
 | 
						|
 | 
						|
--echo #
 | 
						|
--echo # MDEV-32350 Can't selectively restore sequences using innodb tables from
 | 
						|
--echo # backup
 | 
						|
--echo #
 | 
						|
 | 
						|
--disable_ps_protocol
 | 
						|
 | 
						|
create sequence s2 engine=innodb;
 | 
						|
alter table s2 discard tablespace;
 | 
						|
--error ER_GET_ERRNO
 | 
						|
SELECT NEXTVAL(s2);
 | 
						|
create sequence s1 engine=innodb;
 | 
						|
select * from s1;
 | 
						|
flush tables s1 for export;
 | 
						|
--let $MYSQLD_DATADIR= `select @@datadir`
 | 
						|
--move_file $MYSQLD_DATADIR/test/s1.cfg $MYSQLD_DATADIR/test/s2.cfg
 | 
						|
--copy_file $MYSQLD_DATADIR/test/s1.ibd $MYSQLD_DATADIR/test/s2.ibd
 | 
						|
unlock tables;
 | 
						|
--error ER_GET_ERRNO
 | 
						|
select * from s2;
 | 
						|
--error ER_GET_ERRNO
 | 
						|
SELECT NEXTVAL(s2);
 | 
						|
--error ER_GET_ERRNO
 | 
						|
alter sequence s2 restart;
 | 
						|
alter table s2 import tablespace;
 | 
						|
select * from s2;
 | 
						|
SELECT NEXTVAL(s2);
 | 
						|
select NEXTVAL(s1);
 | 
						|
flush table s1,s2;
 | 
						|
select * from s1;
 | 
						|
select * from s2;
 | 
						|
drop sequence s1,s2;
 | 
						|
 | 
						|
--enable_ps_protocol
 | 
						|
 | 
						|
--echo #
 | 
						|
--echo # MDEV-35144 CREATE TABLE ... LIKE uses current innodb_compression_default instead of the create value
 | 
						|
--echo #
 | 
						|
 | 
						|
set @@innodb_compression_default= off;
 | 
						|
create or replace sequence s engine=innodb;
 | 
						|
set @@innodb_compression_default= on;
 | 
						|
create or replace table s_import like s;
 | 
						|
 | 
						|
show create table s;
 | 
						|
show create table s_import;
 | 
						|
 | 
						|
alter table s_import discard tablespace;
 | 
						|
flush table s for export;
 | 
						|
--copy_file $MYSQLD_DATADIR/test/s.ibd $MYSQLD_DATADIR/test/s_import.ibd
 | 
						|
--copy_file $MYSQLD_DATADIR/test/s.cfg $MYSQLD_DATADIR/test/s_import.cfg
 | 
						|
UNLOCK TABLES;
 | 
						|
alter table s_import import tablespace;
 | 
						|
drop table s,s_import;
 | 
						|
 | 
						|
--echo # End of 10.5 tests
 | 
						|
 | 
						|
--echo #
 | 
						|
--echo # MDEV-31607 ER_DUP_KEY in mysql.table_stats upon REANME on sequence
 | 
						|
--echo #
 | 
						|
 | 
						|
CREATE SEQUENCE s1 ENGINE=InnoDB;
 | 
						|
CREATE SEQUENCE s2 ENGINE=InnoDB;
 | 
						|
SHOW CREATE SEQUENCE s1;
 | 
						|
SHOW CREATE SEQUENCE s2;
 | 
						|
DROP SEQUENCE s2;
 | 
						|
RENAME TABLE s1 TO s2;
 | 
						|
DROP SEQUENCE s2;
 | 
						|
 | 
						|
--enable_ps2_protocol
 | 
						|
 | 
						|
--echo #
 | 
						|
--echo # End of 10.6 tests
 | 
						|
--echo #
 | 
						|
 | 
						|
--echo #
 | 
						|
--echo # MDEV-36032 Check when doing ALTER TABLE table_name sequence=1 that table can be a sequence
 | 
						|
--echo #
 | 
						|
 | 
						|
## Too many rows
 | 
						|
create sequence s;
 | 
						|
alter table s sequence=0;
 | 
						|
insert into s values (3,1,9223372036854775806,1,1,1000,0,0);
 | 
						|
--error ER_INTERNAL_ERROR
 | 
						|
alter table s sequence=1;
 | 
						|
drop table s;
 | 
						|
 | 
						|
## Insert a wrong row (min > max)
 | 
						|
create sequence s;
 | 
						|
alter table s sequence=0;
 | 
						|
delete from s;
 | 
						|
insert into s values (2,500,200,1,1,1000,0,0);
 | 
						|
select * from s;
 | 
						|
--error ER_SEQUENCE_INVALID_DATA
 | 
						|
alter table s sequence=1;
 | 
						|
check table s;
 | 
						|
select * from s;
 | 
						|
check table s;
 | 
						|
drop table s;
 | 
						|
 | 
						|
## Invalid table structure (already implemented before MDEV-36032)
 | 
						|
CREATE TABLE `s` (
 | 
						|
  # `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=innodb;
 | 
						|
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
 | 
						|
alter table s sequence=1;
 | 
						|
drop table s;
 | 
						|
 | 
						|
## Altering a sequence table to a wrong structure is detected (already
 | 
						|
## implemented before MDEV-36032)
 | 
						|
create sequence s;
 | 
						|
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
 | 
						|
alter table s drop column next_not_cached_value;
 | 
						|
drop sequence s;
 | 
						|
 | 
						|
## Create a normal table then alter to sequence
 | 
						|
CREATE TABLE `s1` (
 | 
						|
`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=innodb;
 | 
						|
 | 
						|
--error ER_INTERNAL_ERROR
 | 
						|
alter table s1 sequence=1;
 | 
						|
# (for coverage) alter a non sequence table with sequence=0
 | 
						|
alter table s1 sequence=0;
 | 
						|
insert into s1 values (1,1,9223372036854775806,1,1,1000,0,0);
 | 
						|
alter table s1 sequence=1;
 | 
						|
 | 
						|
alter table s1 sequence=0;
 | 
						|
insert into s1 values (2,1,9223372036854775806,1,1,1000,0,0);
 | 
						|
--error ER_INTERNAL_ERROR
 | 
						|
alter table s1 sequence=1;
 | 
						|
 | 
						|
# (for coverage) alter a non sequence table with sequence=0
 | 
						|
alter table s1 sequence=0;
 | 
						|
insert into s1 values (3,1,9223372036854775806,1,1,1000,0,0);
 | 
						|
--error ER_INTERNAL_ERROR
 | 
						|
alter table s1 sequence=1;
 | 
						|
 | 
						|
drop table s1;
 | 
						|
 | 
						|
--echo # End of 10.11 tests
 |