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

Proposed by Jonathan Cua
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 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

Add create-table-like option

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/pt-online-schema-change'
--- bin/pt-online-schema-change 2013-04-19 23:26:48 +0000
+++ bin/pt-online-schema-change 2013-06-07 00:30:38 +0000
@@ -7750,6 +7750,10 @@
7750 $tbl = $dsn->{t}; 7750 $tbl = $dsn->{t};
7751 }7751 }
77527752
7753 if ( $o->get('create-table-like') ) {
7754 $o->set('alter-foreign-keys-method', 'none')
7755 }
7756
7753 my $alter_fk_method = $o->get('alter-foreign-keys-method') || '';7757 my $alter_fk_method = $o->get('alter-foreign-keys-method') || '';
7754 if ( $alter_fk_method eq 'drop_swap' ) {7758 if ( $alter_fk_method eq 'drop_swap' ) {
7755 $o->set('swap-tables', 0);7759 $o->set('swap-tables', 0);
@@ -9488,7 +9492,14 @@
9488 # or another table, we can still have a collision. But if there are9492 # or another table, we can still have a collision. But if there are
9489 # multiple FKs on this table, it's hard to know which one is causing the9493 # multiple FKs on this table, it's hard to know which one is causing the
9490 # trouble. Should we generate random/UUID FK names or something instead?9494 # trouble. Should we generate random/UUID FK names or something instead?
9491 my $sql = $ddl;9495 my $sql;
9496 if ( $o->get('create-table-like') ) {
9497 $sql = "CREATE TABLE $table_name LIKE " . $orig_tbl->{tbl} . "\n";
9498 }
9499 else {
9500 $sql = $ddl;
9501 }
9502
9492 $sql =~ s/\ACREATE TABLE .*?\($/CREATE TABLE $quoted (/m;9503 $sql =~ s/\ACREATE TABLE .*?\($/CREATE TABLE $quoted (/m;
9493 $sql =~ s/^ CONSTRAINT `/ CONSTRAINT `_/gm;9504 $sql =~ s/^ CONSTRAINT `/ CONSTRAINT `_/gm;
9494 if ( $o->get('default-engine') ) {9505 if ( $o->get('default-engine') ) {
@@ -10554,6 +10565,13 @@
1055410565
10555=over10566=over
1055610567
10568=item --create-table-like
10569
10570Use the create table like construct to preserve the index of the original table.
10571This will skip anything related to foreign keys.
10572
10573=over
10574
10557=item auto10575=item auto
1055810576
10559Automatically determine which method is best. The tool uses10577Automatically determine which method is best. The tool uses

Subscribers

People subscribed via source and target branches