Skip to content

Commit 956bcf8

Browse files
committed
Change mysqldump to use DO instead of 'SELECT' for storing sequences.
This avoids a lot of SETVAL() results when applying a mysqldump with sequences.
1 parent fef32fd commit 956bcf8

File tree

4 files changed

+17
-35
lines changed

4 files changed

+17
-35
lines changed

client/mysqldump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2959,7 +2959,7 @@ static void get_sequence_structure(const char *seq, const char *db)
29592959
row= mysql_fetch_row(result);
29602960
if (row[0])
29612961
{
2962-
fprintf(sql_file, "SELECT SETVAL(%s, %s, 0);\n", result_seq, row[0]);
2962+
fprintf(sql_file, "DO SETVAL(%s, %s, 0);\n", result_seq, row[0]);
29632963
}
29642964
// Sequences will not use inserts, so no need for REPLACE and LOCKS
29652965
mysql_free_result(result);

mysql-test/main/mysql.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ c int(11) YES NULL
137137
drop table t1;
138138
1
139139
1
140+
--------------
141+
use
142+
--------------
143+
140144
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
141145
ERROR at line 1: USE must be followed by a database name
142146
1 +1
@@ -166,6 +170,10 @@ count(*)
166170
drop table t17583;
167171
Test connect without db- or host-name => reconnect
168172
Test connect with dbname only => new dbname, old hostname
173+
--------------
174+
connecttest
175+
--------------
176+
169177
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
170178
Test connect with _invalid_ dbname only => new invalid dbname, old hostname
171179
ERROR 1049 (42000) at line 1: Unknown database 'invalid'

mysql-test/main/mysqldump.result

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6326,14 +6326,6 @@ Table Create Table
63266326
s4 CREATE SEQUENCE `s4` start with 400 minvalue 400 maxvalue 1400 increment by 40 cache 1000 cycle ENGINE=MyISAM
63276327
# Dump sequence without `--no-data`
63286328
# Restore from mysqldump
6329-
SETVAL(`s1`, 1101, 0)
6330-
1101
6331-
SETVAL(`s2`, 1201, 0)
6332-
1201
6333-
SETVAL(`s3`, 1301, 0)
6334-
1301
6335-
SETVAL(`s4`, 1401, 0)
6336-
1401
63376329
# Show create after restore
63386330
show create sequence d.s1;
63396331
Table Create Table
@@ -6352,14 +6344,6 @@ NEXTVAL(d.s1) NEXTVAL(d.s2) NEXTVAL(d.s3) NEXTVAL(d.s4)
63526344
100 200 300 400
63536345
# Dump sequence with `--no-data`
63546346
# Restore from mysqldump
6355-
SETVAL(`s1`, 1101, 0)
6356-
1101
6357-
SETVAL(`s2`, 1201, 0)
6358-
1201
6359-
SETVAL(`s3`, 1301, 0)
6360-
1301
6361-
SETVAL(`s4`, 1401, 0)
6362-
1401
63636347
# Show create after restore `--no-data`
63646348
show create sequence d.s1;
63656349
Table Create Table
@@ -6378,14 +6362,6 @@ NEXTVAL(d.s1) NEXTVAL(d.s2) NEXTVAL(d.s3) NEXTVAL(d.s4)
63786362
100 200 300 400
63796363
# Restore to different database than original
63806364
create database d2;
6381-
SETVAL(`s1`, 1101, 0)
6382-
1101
6383-
SETVAL(`s2`, 1201, 0)
6384-
1201
6385-
SETVAL(`s3`, 1301, 0)
6386-
1301
6387-
SETVAL(`s4`, 1401, 0)
6388-
1401
63896365
show create sequence d2.s1;
63906366
Table Create Table
63916367
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
64136389
INSERT INTO t VALUES (1,1),(2,2),(3,3),(4,4);
64146390
# Dump database 1
64156391
# Restore from database 1 to database 2
6416-
SETVAL(`seq_t_i`, 1, 0)
6417-
1
64186392
--------------
64196393
INSERT INTO `t` VALUES (1,1),(2,2),(3,3),(4,4)
64206394
--------------

mysql-test/suite/sql_sequence/mysqldump.result

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ CREATE SEQUENCE x1 engine=innodb;
55
# dump whole database
66
/*!999999\- enable the sandbox mode */
77
CREATE SEQUENCE `a1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
8-
SELECT SETVAL(`a1`, 1, 0);
8+
DO SETVAL(`a1`, 1, 0);
99
CREATE SEQUENCE `x1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
10-
SELECT SETVAL(`x1`, 1, 0);
10+
DO SETVAL(`x1`, 1, 0);
1111
/*!40101 SET @saved_cs_client = @@character_set_client */;
1212
/*!40101 SET character_set_client = utf8 */;
1313
CREATE TABLE `t1` (
@@ -19,9 +19,9 @@ INSERT INTO `t1` VALUES (1),(2);
1919
# dump by tables order 1
2020
/*!999999\- enable the sandbox mode */
2121
CREATE SEQUENCE `a1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
22-
SELECT SETVAL(`a1`, 1, 0);
22+
DO SETVAL(`a1`, 1, 0);
2323
CREATE SEQUENCE `x1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
24-
SELECT SETVAL(`x1`, 1, 0);
24+
DO SETVAL(`x1`, 1, 0);
2525
/*!40101 SET @saved_cs_client = @@character_set_client */;
2626
/*!40101 SET character_set_client = utf8 */;
2727
CREATE TABLE `t1` (
@@ -33,9 +33,9 @@ INSERT INTO `t1` VALUES (1),(2);
3333
# dump by tables order 2
3434
/*!999999\- enable the sandbox mode */
3535
CREATE SEQUENCE `a1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
36-
SELECT SETVAL(`a1`, 1, 0);
36+
DO SETVAL(`a1`, 1, 0);
3737
CREATE SEQUENCE `x1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
38-
SELECT SETVAL(`x1`, 1, 0);
38+
DO SETVAL(`x1`, 1, 0);
3939
/*!40101 SET @saved_cs_client = @@character_set_client */;
4040
/*!40101 SET character_set_client = utf8 */;
4141
CREATE TABLE `t1` (
@@ -57,9 +57,9 @@ INSERT INTO `t1` VALUES (1),(2);
5757
# dump by tables only sequences
5858
/*!999999\- enable the sandbox mode */
5959
CREATE SEQUENCE `a1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
60-
SELECT SETVAL(`a1`, 1, 0);
60+
DO SETVAL(`a1`, 1, 0);
6161
CREATE SEQUENCE `x1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
62-
SELECT SETVAL(`x1`, 1, 0);
62+
DO SETVAL(`x1`, 1, 0);
6363
# end of dumps
6464
DROP TABLE a1,t1,x1;
6565
set default_storage_engine=InnoDB;

0 commit comments

Comments
 (0)