From a4789f52d8f7437fab1bf156f7e190b6e025122b Mon Sep 17 00:00:00 2001 From: Monty Date: Wed, 24 May 2017 18:57:47 +0300 Subject: [PATCH] More tests for SEQUENCE's - 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. --- .../suite/sql_sequence/mysqldump.result | 41 +++++++++++++++++++ mysql-test/suite/sql_sequence/mysqldump.test | 15 +++++++ mysql-test/suite/sql_sequence/other.result | 31 ++++++++++++++ mysql-test/suite/sql_sequence/other.test | 25 +++++++++++ sql/handler.cc | 8 +++- 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/sql_sequence/mysqldump.result create mode 100644 mysql-test/suite/sql_sequence/mysqldump.test diff --git a/mysql-test/suite/sql_sequence/mysqldump.result b/mysql-test/suite/sql_sequence/mysqldump.result new file mode 100644 index 00000000000..30f0719f16e --- /dev/null +++ b/mysql-test/suite/sql_sequence/mysqldump.result @@ -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; diff --git a/mysql-test/suite/sql_sequence/mysqldump.test b/mysql-test/suite/sql_sequence/mysqldump.test new file mode 100644 index 00000000000..8d5c2d0869d --- /dev/null +++ b/mysql-test/suite/sql_sequence/mysqldump.test @@ -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; diff --git a/mysql-test/suite/sql_sequence/other.result b/mysql-test/suite/sql_sequence/other.result index 1d86fa80e4f..e991a595e91 100644 --- a/mysql-test/suite/sql_sequence/other.result +++ b/mysql-test/suite/sql_sequence/other.result @@ -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; diff --git a/mysql-test/suite/sql_sequence/other.test b/mysql-test/suite/sql_sequence/other.test index 6860a91e217..3716b53311a 100644 --- a/mysql-test/suite/sql_sequence/other.test +++ b/mysql-test/suite/sql_sequence/other.test @@ -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; diff --git a/sql/handler.cc b/sql/handler.cc index a5832be30e1..9b66801b109 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -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;