Skip to content

Commit

Permalink
More tests for SEQUENCE's
Browse files Browse the repository at this point in the history
- Test with LOCK TABLES
- Test mysqldump
- Don't update rows for sequence tables if values doesn't change. This is
  needed as InnoDB gives an error for updates where values doesn't change.
  • Loading branch information
montywi committed May 24, 2017
1 parent 8acf4d6 commit a4789f5
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 1 deletion.
41 changes: 41 additions & 0 deletions mysql-test/suite/sql_sequence/mysqldump.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
CREATE SEQUENCE a1 engine=aria;
CREATE TABLE t1(a INT, KEY (a)) KEY_BLOCK_SIZE=1024;
insert into t1 values (1),(2);
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',
`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'
) ENGINE=Aria SEQUENCE=1;
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO `a1` VALUES (1,1,9223372036854775806,1,1,1000,0,0);
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
KEY `a` (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 KEY_BLOCK_SIZE=1024;
/*!40101 SET character_set_client = @saved_cs_client */;
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',
`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'
) ENGINE=InnoDB SEQUENCE=1;
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO `x1` VALUES (1,1,9223372036854775806,1,1,1000,0,0);
DROP TABLE a1,t1,x1;
15 changes: 15 additions & 0 deletions mysql-test/suite/sql_sequence/mysqldump.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Testing mysqldump of sequences
#

# Embedded server doesn't support external clients
--source include/not_embedded.inc
--source include/have_aria.inc
--source include/have_innodb.inc

CREATE SEQUENCE a1 engine=aria;
CREATE TABLE t1(a INT, KEY (a)) KEY_BLOCK_SIZE=1024;
insert into t1 values (1),(2);
CREATE SEQUENCE x1 engine=innodb;
--exec $MYSQL_DUMP --compact test
DROP TABLE a1,t1,x1;
31 changes: 31 additions & 0 deletions mysql-test/suite/sql_sequence/other.result
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,34 @@ ERROR HY000: Storage engine SEQUENCE of the table `test`.`s1` doesn't have this
delete from s1 where next_value > 0;
ERROR HY000: Storage engine SEQUENCE of the table `test`.`s1` doesn't have this option
drop sequence s1;
#
# SHOW TABLES
#
create sequence s1;
create table t1 (a int);
create view v1 as select * from s1;
show full tables;
Tables_in_test Table_type
s1 SEQUENCE
t1 BASE TABLE
v1 VIEW
SELECT TABLE_TYPE,ENGINE FROM INFORMATION_SCHEMA.TABLES where table_schema="test";
TABLE_TYPE ENGINE
SEQUENCE MyISAM
BASE TABLE MyISAM
VIEW NULL
drop table t1,s1;
drop view v1;
#
# LOCK TABLES (as in mysqldump)
#
create sequence s1 engine=innodb;
LOCK TABLES s1 READ;
SELECT * from s1;
next_value min_value max_value start increment cache cycle round
1 1 9223372036854775806 1 1 1000 0 0
UNLOCK TABLES;
LOCK TABLES s1 WRITE;
insert into s1 values (1,1,9223372036854775806, 1, 1, 1000, 0, 0);
UNLOCK TABLES;
drop table s1;
25 changes: 25 additions & 0 deletions mysql-test/suite/sql_sequence/other.test
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,28 @@ update s1 set next_value=100;
--error ER_ILLEGAL_HA
delete from s1 where next_value > 0;
drop sequence s1;

--echo #
--echo # SHOW TABLES
--echo #

create sequence s1;
create table t1 (a int);
create view v1 as select * from s1;
show full tables;
SELECT TABLE_TYPE,ENGINE FROM INFORMATION_SCHEMA.TABLES where table_schema="test";
drop table t1,s1;
drop view v1;

--echo #
--echo # LOCK TABLES (as in mysqldump)
--echo #

create sequence s1 engine=innodb;
LOCK TABLES s1 READ;
SELECT * from s1;
UNLOCK TABLES;
LOCK TABLES s1 WRITE;
insert into s1 values (1,1,9223372036854775806, 1, 1, 1000, 0, 0);
UNLOCK TABLES;
drop table s1;
8 changes: 7 additions & 1 deletion sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6041,7 +6041,13 @@ int handler::update_first_row(uchar *new_data)
{
int end_error;
if (!(error= ha_rnd_next(table->record[1])))
error= update_row(table->record[1], new_data);
{
/*
We have to do the memcmp as otherwise we may get error 169 from InnoDB
*/
if (memcmp(table->record[0], table->record[1], table->s->reclength))
error= update_row(table->record[1], new_data);
}
end_error= ha_rnd_end();
if (!error)
error= end_error;
Expand Down

0 comments on commit a4789f5

Please sign in to comment.