Merge lp:~linuxjedi/drizzle/trunk-bug-683940 into lp:drizzle/7.0

Proposed by Andrew Hutchings
Status: Merged
Approved by: Brian Aker
Approved revision: 1967
Merged at revision: 1970
Proposed branch: lp:~linuxjedi/drizzle/trunk-bug-683940
Merge into: lp:drizzle/7.0
Diff against target: 140 lines (+40/-81)
1 file modified
client/drizzledump_mysql.cc (+40/-81)
To merge this branch: bzr merge lp:~linuxjedi/drizzle/trunk-bug-683940
Reviewer Review Type Date Requested Status
Drizzle Developers Pending
Review via email: mp+42488@code.launchpad.net

Description of the change

In some cases foreign keys were not migrated in drizzledump, performance also sucked. An improved method still had poor performance and hits bugs in MySQL 5.5. Switching to regex of SHOW CREATE TABLE for fkeys during migration instead.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'client/drizzledump_mysql.cc'
2--- client/drizzledump_mysql.cc 2010-11-02 10:28:05 +0000
3+++ client/drizzledump_mysql.cc 2010-12-02 14:54:12 +0000
4@@ -306,96 +306,55 @@
5 if (verbose)
6 std::cerr << _("-- Retrieving foreign keys for ") << tableName << "..." << std::endl;
7
8- query= "SHOW TABLES FROM INFORMATION_SCHEMA LIKE 'REFERENTIAL_CONSTRAINTS'";
9-
10+ query= "SHOW CREATE TABLE `";
11+ query.append(database->databaseName);
12+ query.append("`.`");
13+ query.append(tableName);
14+ query.append("`");
15 result= dcon->query(query);
16
17 if (result == NULL)
18 return false;
19
20- uint64_t search_count = drizzle_result_row_count(result);
21-
22- dcon->freeResult(result);
23-
24- /* MySQL 5.0 will be 0 and MySQL 5.1 will be 1 */
25- if (search_count > 0)
26+ if ((row= drizzle_row_next(result)))
27 {
28- query= "select rc.constraint_name, rc.referenced_table_name, group_concat(distinct concat('`',kc.column_name,'`')), rc.update_rule, rc.delete_rule, rc.match_option, group_concat(distinct concat('`',kt.column_name,'`')) from information_schema.referential_constraints rc join information_schema.key_column_usage kt on (rc.constraint_schema = kt.constraint_schema and rc.constraint_name = kt.constraint_name) join information_schema.key_column_usage kc on (rc.constraint_schema = kc.constraint_schema and rc.referenced_table_name = kc.table_name and rc.unique_constraint_name = kc.constraint_name) where rc.constraint_schema='";
29- query.append(database->databaseName);
30- query.append("' and rc.table_name='");
31- query.append(tableName);
32- query.append("' group by rc.constraint_name");
33-
34- result= dcon->query(query);
35-
36- if (result == NULL)
37- return false;
38-
39- while ((row= drizzle_row_next(result)))
40+ boost::match_flag_type flags = boost::match_default;
41+ boost::regex constraint_regex("CONSTRAINT `(.*)` FOREIGN KEY \\((.*)\\) REFERENCES `(.*)` \\((.*)\\)( ON (UPDATE|DELETE) (CASCADE|RESTRICT|SET NULL))?( ON (UPDATE|DELETE) (CASCADE|RESTRICT|SET NULL))?");
42+
43+ boost::match_results<std::string::const_iterator> constraint_results;
44+
45+ std::string search_body(row[1]);
46+ std::string::const_iterator start, end;
47+ start= search_body.begin();
48+ end= search_body.end();
49+ while (regex_search(start, end, constraint_results, constraint_regex, flags))
50 {
51- fkey= new DrizzleDumpForeignKey(row[0], dcon);
52- fkey->parentColumns= row[6];
53- fkey->childTable= row[1];
54- fkey->childColumns= row[2];
55- fkey->updateRule= (strcmp(row[3], "RESTRICT") != 0) ? row[3] : "";
56- fkey->deleteRule= (strcmp(row[4], "RESTRICT") != 0) ? row[4] : "";
57- fkey->matchOption= (strcmp(row[5], "NONE") != 0) ? row[5] : "";
58+ fkey= new DrizzleDumpForeignKey(constraint_results[1], dcon);
59+ fkey->parentColumns= constraint_results[2];
60+ fkey->childTable= constraint_results[3];
61+ fkey->childColumns= constraint_results[4];
62+
63+ if (constraint_results[5].compare("") != 0)
64+ {
65+ if (constraint_results[6].compare("UPDATE") == 0)
66+ fkey->updateRule= constraint_results[7];
67+ else if (constraint_results[6].compare("DELETE") == 0)
68+ fkey->deleteRule= constraint_results[7];
69+ }
70+ if (constraint_results[8].compare("") != 0)
71+ {
72+ if (constraint_results[9].compare("UPDATE") == 0)
73+ fkey->updateRule= constraint_results[10];
74+ else if (constraint_results[9].compare("DELETE") == 0)
75+ fkey->deleteRule= constraint_results[10];
76+ }
77+ fkey->matchOption= "";
78
79 fkeys.push_back(fkey);
80- }
81- }
82- else
83- {
84- query= "SHOW CREATE TABLE `";
85- query.append(database->databaseName);
86- query.append("`.`");
87- query.append(tableName);
88- query.append("`");
89- result= dcon->query(query);
90-
91- if (result == NULL)
92- return false;
93-
94- if ((row= drizzle_row_next(result)))
95- {
96- boost::match_flag_type flags = boost::match_default;
97- boost::regex constraint_regex("CONSTRAINT `(.*)` FOREIGN KEY \\((.*)\\) REFERENCES `(.*)` \\((.*)\\)( ON (UPDATE|DELETE) (CASCADE|RESTRICT|SET NULL))?( ON (UPDATE|DELETE) (CASCADE|RESTRICT|SET NULL))?");
98-
99- boost::match_results<std::string::const_iterator> constraint_results;
100-
101- std::string search_body(row[1]);
102- std::string::const_iterator start, end;
103- start= search_body.begin();
104- end= search_body.end();
105- while (regex_search(start, end, constraint_results, constraint_regex, flags))
106- {
107- fkey= new DrizzleDumpForeignKey(constraint_results[1], dcon);
108- fkey->parentColumns= constraint_results[2];
109- fkey->childTable= constraint_results[3];
110- fkey->childColumns= constraint_results[4];
111-
112- if (constraint_results[5].compare("") != 0)
113- {
114- if (constraint_results[6].compare("UPDATE") == 0)
115- fkey->updateRule= constraint_results[7];
116- else if (constraint_results[6].compare("DELETE") == 0)
117- fkey->deleteRule= constraint_results[7];
118- }
119- if (constraint_results[8].compare("") != 0)
120- {
121- if (constraint_results[9].compare("UPDATE") == 0)
122- fkey->updateRule= constraint_results[10];
123- else if (constraint_results[9].compare("DELETE") == 0)
124- fkey->deleteRule= constraint_results[10];
125- }
126- fkey->matchOption= "";
127-
128- fkeys.push_back(fkey);
129-
130- start= constraint_results[0].second;
131- flags |= boost::match_prev_avail;
132- flags |= boost::match_not_bob;
133- }
134+
135+ start= constraint_results[0].second;
136+ flags |= boost::match_prev_avail;
137+ flags |= boost::match_not_bob;
138 }
139 }
140 dcon->freeResult(result);

Subscribers

People subscribed via source and target branches