Skip to content

Commit 89fc40e

Browse files
committed
Bug#26116415 TABLESPACE CLAUSE CONFUSES MYSQLPUMP
Before this fix, mysqlpump failed to export tables using a tablespace. The root cause is that mysqlpump parses the result of SHOW CREATE TABLE, and is not expecting the TABLESPACE clause. In the following statement: CREATE TABLE `t1` ( `a` int(11) DEFAULT NULL ) /*!50100 TABLESPACE `mytbsp` */ ENGINE=InnoDB DEFAULT CHARSET=latin1 MYSQLPUMP was looking for ") ENGINE=" ..., and failed to detect this line. The fix is to relax parsing of SHOW CREATE TABLE, so that the line: ) /*!50100 TABLESPACE `mytbsp` */ ENGINE=... is also detected as the table options clause.
1 parent 06fa146 commit 89fc40e

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

client/dump/table.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2015, 2017 Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -39,10 +39,14 @@ Table::Table(uint64 id, const std::string& name, const std::string& schema,
3939
for (std::vector<std::string>::iterator it= definition_lines.begin();
4040
it != definition_lines.end(); ++it)
4141
{
42+
/*
43+
MAINTAINER: This code parses the output of SHOW CREATE TABLE.
44+
@TODO: Instead, look up INFORMATION_SCHEMA and get the table details.
45+
*/
46+
4247
boost::trim_left(*it);
4348
if (!engine_line_read)
4449
boost::trim_if(*it, boost::is_any_of(","));
45-
// TODO: Look up INFORMATION_SCHEMA and get the table details.
4650
if (boost::starts_with(*it, "KEY ")
4751
|| boost::starts_with(*it, "INDEX ")
4852
|| boost::starts_with(*it, "UNIQUE KEY ")
@@ -57,7 +61,12 @@ Table::Table(uint64 id, const std::string& name, const std::string& schema,
5761
}
5862
else
5963
{
60-
if (boost::starts_with(*it, ") ENGINE="))
64+
/*
65+
Make sure we detect the table options clauses,
66+
even with different syntaxes (with or without TABLESPACE)
67+
*/
68+
if (boost::starts_with(*it, ")") &&
69+
boost::contains(*it, "ENGINE="))
6170
{
6271
engine_line_read= true;
6372
std::string &sql_def = m_sql_definition_without_indexes;

mysql-test/r/mysqlpump_basic.result

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,3 +718,21 @@ INSERT INTO t VALUES (9), (0);
718718
DROP DATABASE bug26694675;
719719
check for warnings
720720
Pattern "mysqlpump: \[WARNING\]" not found
721+
#
722+
# Bug#26116415 TABLESPACE CLAUSE CONFUSES MYSQLPUMP
723+
#
724+
CREATE TABLESPACE `mytbsp` ADD DATAFILE 'mytbsp.ibd' ENGINE INNODB;
725+
CREATE TABLE `test`.`t1` (a integer) TABLESPACE `mytbsp`;
726+
SHOW CREATE TABLE test.t1;
727+
Table Create Table
728+
t1 CREATE TABLE `t1` (
729+
`a` int(11) DEFAULT NULL
730+
) /*!50100 TABLESPACE `mytbsp` */ ENGINE=InnoDB DEFAULT CHARSET=latin1
731+
DROP TABLE `test`.`t1`;
732+
SHOW CREATE TABLE test.t1;
733+
Table Create Table
734+
t1 CREATE TABLE `t1` (
735+
`a` int(11) DEFAULT NULL
736+
) /*!50100 TABLESPACE `mytbsp` */ ENGINE=InnoDB DEFAULT CHARSET=latin1
737+
DROP TABLE `test`.`t1`;
738+
DROP TABLESPACE `mytbsp`;

mysql-test/t/mysqlpump_basic.test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,3 +643,27 @@ let SEARCH_PATTERN= mysqlpump: \[WARNING\];
643643
# cleanup
644644
--remove_file $MYSQLTEST_VARDIR/log/err.log
645645
--remove_file $MYSQLTEST_VARDIR/tmp/bug26694675.sql
646+
647+
-- echo #
648+
-- echo # Bug#26116415 TABLESPACE CLAUSE CONFUSES MYSQLPUMP
649+
-- echo #
650+
651+
CREATE TABLESPACE `mytbsp` ADD DATAFILE 'mytbsp.ibd' ENGINE INNODB;
652+
653+
CREATE TABLE `test`.`t1` (a integer) TABLESPACE `mytbsp`;
654+
655+
SHOW CREATE TABLE test.t1;
656+
657+
--let $program= $MYSQL_PUMP --include-databases=test --include-tables=t1
658+
659+
--exec $PROGRAM >> $MYSQL_TMP_DIR/mysqlpump.sql
660+
661+
DROP TABLE `test`.`t1`;
662+
663+
--exec $MYSQL < $MYSQL_TMP_DIR/mysqlpump.sql
664+
665+
SHOW CREATE TABLE test.t1;
666+
667+
DROP TABLE `test`.`t1`;
668+
DROP TABLESPACE `mytbsp`;
669+

0 commit comments

Comments
 (0)