Merge lp:~jonathan-cua/percona-toolkit/percona-toolkit into lp:percona-toolkit/2.2

Proposed by Jonathan Cua on 2013-06-07
Status: Needs review
Proposed branch: lp:~jonathan-cua/percona-toolkit/percona-toolkit
Merge into: lp:percona-toolkit/2.2
Diff against target: 44 lines (+19/-1)
1 file modified
bin/pt-online-schema-change (+19/-1)
To merge this branch: bzr merge lp:~jonathan-cua/percona-toolkit/percona-toolkit
Reviewer Review Type Date Requested Status
Percona Toolkit developers 2013-06-07 Pending
Review via email: mp+167880@code.launchpad.net

Description of the change

This adds an option to use "CREATE TABLE LIKE" construct to preserve the index. One use case of this is this scenario: slave database has more index than the master. With this option, it will allow the slave to retain its old indexes. There is danger to this in that if the slave already has the index, and this option was used, then it will break replication.

To post a comment you must log in.

Unmerged revisions

582. By Jonathan Cua on 2013-06-06

Add create-table-like option

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-online-schema-change'
2--- bin/pt-online-schema-change 2013-04-19 23:26:48 +0000
3+++ bin/pt-online-schema-change 2013-06-07 00:30:38 +0000
4@@ -7750,6 +7750,10 @@
5 $tbl = $dsn->{t};
6 }
7
8+ if ( $o->get('create-table-like') ) {
9+ $o->set('alter-foreign-keys-method', 'none')
10+ }
11+
12 my $alter_fk_method = $o->get('alter-foreign-keys-method') || '';
13 if ( $alter_fk_method eq 'drop_swap' ) {
14 $o->set('swap-tables', 0);
15@@ -9488,7 +9492,14 @@
16 # or another table, we can still have a collision. But if there are
17 # multiple FKs on this table, it's hard to know which one is causing the
18 # trouble. Should we generate random/UUID FK names or something instead?
19- my $sql = $ddl;
20+ my $sql;
21+ if ( $o->get('create-table-like') ) {
22+ $sql = "CREATE TABLE $table_name LIKE " . $orig_tbl->{tbl} . "\n";
23+ }
24+ else {
25+ $sql = $ddl;
26+ }
27+
28 $sql =~ s/\ACREATE TABLE .*?\($/CREATE TABLE $quoted (/m;
29 $sql =~ s/^ CONSTRAINT `/ CONSTRAINT `_/gm;
30 if ( $o->get('default-engine') ) {
31@@ -10554,6 +10565,13 @@
32
33 =over
34
35+=item --create-table-like
36+
37+Use the create table like construct to preserve the index of the original table.
38+This will skip anything related to foreign keys.
39+
40+=over
41+
42 =item auto
43
44 Automatically determine which method is best. The tool uses

Subscribers

People subscribed via source and target branches