Commit 956bcf8f authored by Monty's avatar Monty

Change mysqldump to use DO instead of 'SELECT' for storing sequences.

This avoids a lot of SETVAL() results when applying a mysqldump with
sequences.
parent fef32fd9
......@@ -2959,7 +2959,7 @@ static void get_sequence_structure(const char *seq, const char *db)
row= mysql_fetch_row(result);
if (row[0])
{
fprintf(sql_file, "SELECT SETVAL(%s, %s, 0);\n", result_seq, row[0]);
fprintf(sql_file, "DO SETVAL(%s, %s, 0);\n", result_seq, row[0]);
}
// Sequences will not use inserts, so no need for REPLACE and LOCKS
mysql_free_result(result);
......
......@@ -137,6 +137,10 @@ c int(11) YES NULL
drop table t1;
1
1
--------------
use
--------------
ERROR 1064 (42000) at line 3: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
ERROR at line 1: USE must be followed by a database name
1 +1
......@@ -166,6 +170,10 @@ count(*)
drop table t17583;
Test connect without db- or host-name => reconnect
Test connect with dbname only => new dbname, old hostname
--------------
connecttest
--------------
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'connecttest' at line 1
Test connect with _invalid_ dbname only => new invalid dbname, old hostname
ERROR 1049 (42000) at line 1: Unknown database 'invalid'
......
......@@ -6326,14 +6326,6 @@ Table Create Table
s4 CREATE SEQUENCE `s4` start with 400 minvalue 400 maxvalue 1400 increment by 40 cache 1000 cycle ENGINE=MyISAM
# Dump sequence without `--no-data`
# Restore from mysqldump
SETVAL(`s1`, 1101, 0)
1101
SETVAL(`s2`, 1201, 0)
1201
SETVAL(`s3`, 1301, 0)
1301
SETVAL(`s4`, 1401, 0)
1401
# Show create after restore
show create sequence d.s1;
Table Create Table
......@@ -6352,14 +6344,6 @@ NEXTVAL(d.s1) NEXTVAL(d.s2) NEXTVAL(d.s3) NEXTVAL(d.s4)
100 200 300 400
# Dump sequence with `--no-data`
# Restore from mysqldump
SETVAL(`s1`, 1101, 0)
1101
SETVAL(`s2`, 1201, 0)
1201
SETVAL(`s3`, 1301, 0)
1301
SETVAL(`s4`, 1401, 0)
1401
# Show create after restore `--no-data`
show create sequence d.s1;
Table Create Table
......@@ -6378,14 +6362,6 @@ NEXTVAL(d.s1) NEXTVAL(d.s2) NEXTVAL(d.s3) NEXTVAL(d.s4)
100 200 300 400
# Restore to different database than original
create database d2;
SETVAL(`s1`, 1101, 0)
1101
SETVAL(`s2`, 1201, 0)
1201
SETVAL(`s3`, 1301, 0)
1301
SETVAL(`s4`, 1401, 0)
1401
show create sequence d2.s1;
Table Create Table
s1 CREATE SEQUENCE `s1` start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
......@@ -6413,8 +6389,6 @@ j integer
INSERT INTO t VALUES (1,1),(2,2),(3,3),(4,4);
# Dump database 1
# Restore from database 1 to database 2
SETVAL(`seq_t_i`, 1, 0)
1
--------------
INSERT INTO `t` VALUES (1,1),(2,2),(3,3),(4,4)
--------------
......
......@@ -5,9 +5,9 @@ CREATE SEQUENCE x1 engine=innodb;
# dump whole database
/*!999999\- enable the sandbox mode */
CREATE SEQUENCE `a1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
SELECT SETVAL(`a1`, 1, 0);
DO SETVAL(`a1`, 1, 0);
CREATE SEQUENCE `x1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
SELECT SETVAL(`x1`, 1, 0);
DO SETVAL(`x1`, 1, 0);
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t1` (
......@@ -19,9 +19,9 @@ INSERT INTO `t1` VALUES (1),(2);
# dump by tables order 1
/*!999999\- enable the sandbox mode */
CREATE SEQUENCE `a1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
SELECT SETVAL(`a1`, 1, 0);
DO SETVAL(`a1`, 1, 0);
CREATE SEQUENCE `x1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
SELECT SETVAL(`x1`, 1, 0);
DO SETVAL(`x1`, 1, 0);
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t1` (
......@@ -33,9 +33,9 @@ INSERT INTO `t1` VALUES (1),(2);
# dump by tables order 2
/*!999999\- enable the sandbox mode */
CREATE SEQUENCE `a1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
SELECT SETVAL(`a1`, 1, 0);
DO SETVAL(`a1`, 1, 0);
CREATE SEQUENCE `x1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
SELECT SETVAL(`x1`, 1, 0);
DO SETVAL(`x1`, 1, 0);
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t1` (
......@@ -57,9 +57,9 @@ INSERT INTO `t1` VALUES (1),(2);
# dump by tables only sequences
/*!999999\- enable the sandbox mode */
CREATE SEQUENCE `a1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
SELECT SETVAL(`a1`, 1, 0);
DO SETVAL(`a1`, 1, 0);
CREATE SEQUENCE `x1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
SELECT SETVAL(`x1`, 1, 0);
DO SETVAL(`x1`, 1, 0);
# end of dumps
DROP TABLE a1,t1,x1;
set default_storage_engine=InnoDB;
......
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