Skip to content

Commit e89e8f6

Browse files
author
Bharathy Satish
committed
Bug #21462732 MYSQLPUMP --DEFER-TABLE-INDEXES MISHANDLES IN SPECIFIC CONDITION
With --defer-table-indexes option in mysqlpump, mysqlpump would parse the SHOW CREATE TABLE output and extract indexes and constraints so that they are applied on table after rows are dumped. This parsing of the table DDL had a problem because of which there was a syntax error during restore of dump file. This patch fixed this parsing issue.
1 parent aa233d2 commit e89e8f6

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

client/dump/table.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Table::Table(uint64 id, const std::string& name, const std::string& schema,
3333
{
3434
using Detail::Pattern_matcher;
3535
bool pk_present= false;
36+
bool constraint_present= false;
3637

3738
std::vector<std::string> definition_lines;
3839
boost::split(definition_lines, sql_formatted_definition,
@@ -57,12 +58,13 @@ Table::Table(uint64 id, const std::string& name, const std::string& schema,
5758
}
5859
else if (boost::starts_with(*it, "CONSTRAINT "))
5960
{
61+
constraint_present= true;
6062
*it= boost::algorithm::replace_last_copy(*it, ",", "");
6163
m_indexes_sql_definition.push_back(*it);
6264
}
6365
else
6466
{
65-
if (pk_present)
67+
if (pk_present || constraint_present)
6668
{
6769
if ((it+1) == definition_lines.end())
6870
{

mysql-test/r/mysqlpump_basic.result

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ PRIMARY KEY (p_id),
5353
KEY fk_t8 (c_id),
5454
CONSTRAINT t10_ibfk_1 FOREIGN KEY (c_id) REFERENCES t8 (c_id) ON UPDATE CASCADE
5555
);
56+
CREATE TABLE t11 (
57+
num int PRIMARY KEY,
58+
FOREIGN KEY (num) REFERENCES t9 (v_id)
59+
);
5660
ALTER TABLE t10 ADD COLUMN v_id INT NOT NULL AFTER c_id;
5761
ALTER TABLE t10 ADD FOREIGN KEY fk_t9(v_id) REFERENCES
5862
t9(v_id) ON DELETE NO ACTION ON UPDATE CASCADE;
@@ -100,6 +104,7 @@ WHERE TABLE_SCHEMA='db1_basic' AND TABLE_TYPE= 'BASE TABLE'
100104
TABLE_NAME
101105
t1
102106
t10
107+
t11
103108
t2
104109
t3
105110
t4
@@ -144,6 +149,7 @@ WHERE TABLE_SCHEMA='db1_basic' AND TABLE_TYPE= 'BASE TABLE'
144149
TABLE_NAME
145150
t1
146151
t10
152+
t11
147153
t2
148154
t3
149155
t4

mysql-test/t/mysqlpump_basic.test

+6
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ CREATE TABLE t10 (
6969
CONSTRAINT t10_ibfk_1 FOREIGN KEY (c_id) REFERENCES t8 (c_id) ON UPDATE CASCADE
7070
);
7171

72+
CREATE TABLE t11 (
73+
num int PRIMARY KEY,
74+
FOREIGN KEY (num) REFERENCES t9 (v_id)
75+
);
76+
7277
ALTER TABLE t10 ADD COLUMN v_id INT NOT NULL AFTER c_id;
7378
ALTER TABLE t10 ADD FOREIGN KEY fk_t9(v_id) REFERENCES
7479
t9(v_id) ON DELETE NO ACTION ON UPDATE CASCADE;
7580

81+
7682
INSERT INTO t4 (name) VALUES ('disk_temptable_create_cost');
7783
INSERT INTO t4 (name) VALUES ('disk_temptable_row_cost');
7884
INSERT INTO t4 (name) VALUES ('key_compare_cost');

0 commit comments

Comments
 (0)