diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index 2b7655b6..a2aa96f5 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -8959,6 +8959,9 @@ sub create_new_table{ my $sql = $ddl; $sql =~ s/\ACREATE TABLE .*?\($/CREATE TABLE $quoted (/m; $sql =~ s/^ CONSTRAINT `/ CONSTRAINT `_/gm; + if ( $o->get('default-engine') ) { + $sql =~ s/\s+ENGINE=\S+//; + } PTDEBUG && _d($sql); eval { $cxn->dbh()->do($sql); @@ -10160,6 +10163,17 @@ single value of Threads_running that is wrong for every server, but a default of 50 seems likely to be unacceptably high for most servers, indicating that the operation should be canceled immediately. +=item --default-engine + +Remove C from the new table. + +By default the new table is created with the same table options as +the original table, so if the original table uses InnoDB, then the new +table will use InnoDB. In certain cases involving replication, this may +cause unintended changes on replicas which use a different engine for +the same table. Specifying this option causes the new table to be +created with the system's default engine. + =item --defaults-file short form: -F; type: string diff --git a/t/pt-online-schema-change/basics.t b/t/pt-online-schema-change/basics.t index ac28fd60..b2826ee7 100644 --- a/t/pt-online-schema-change/basics.t +++ b/t/pt-online-schema-change/basics.t @@ -661,6 +661,31 @@ ok( "--statistics --execute" ); +# ############################################################################# +# --default-engine +# ############################################################################# + +SKIP: { + skip "--default-engine tests require < MySQL 5.5", 1 + if $sandbox_version ge '5.5'; + + # The alter doesn't actually change the engine (test_type), + # but the --default-engine does because the table uses InnoDB + # but MyISAM is the default engine before MySQL 5.5. + test_alter_table( + name => "--default-engine", + table => "pt_osc.t", + file => "default-engine.sql", + test_type => "new_engine", + new_engine => "MyISAM", + cmds => [ + '--default-engine', + '--execute', + '--alter', 'ADD INDEX (d)', + ], + ); +} + # ############################################################################# # Done. # ############################################################################# diff --git a/t/pt-online-schema-change/samples/default-engine.sql b/t/pt-online-schema-change/samples/default-engine.sql new file mode 100644 index 00000000..6c8dba22 --- /dev/null +++ b/t/pt-online-schema-change/samples/default-engine.sql @@ -0,0 +1,20 @@ +DROP DATABASE IF EXISTS pt_osc; +CREATE DATABASE pt_osc; +USE pt_osc; +CREATE TABLE t ( + id int auto_increment primary key, + c char(32), + d date, + unique index (c(32)) +) ENGINE=InnoDB; +INSERT INTO pt_osc.t VALUES + (null, 'a', now()), + (null, 'b', now()), + (null, 'c', now()), + (null, 'd', now()), + (null, 'e', now()), + (null, 'f', now()), + (null, 'g', now()), + (null, 'h', now()), + (null, 'i', now()), + (null, 'j', now()); -- 10