diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index c83b209d..e13a29e3 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -7860,10 +7860,15 @@ sub main { # Although triggers were introduced in 5.0.2, "Prior to MySQL 5.0.10, # triggers cannot contain direct references to tables by name." # ######################################################################## - if ( VersionParser->new($cxn->dbh()) < '5.0.10' ) { + my $server_version = VersionParser->new($cxn->dbh()); + if ( $server_version < '5.0.10' ) { die "This tool requires MySQL 5.0.10 or newer.\n"; } + # Use LOCK IN SHARE mode unless MySQL 5.0 because there's a bug like + # http://bugs.mysql.com/bug.php?id=45694 + my $lock_in_share_mode = $server_version < '5.1' ? 0 : 1; + # ######################################################################## # Setup lag and load monitors. # ######################################################################## @@ -8698,7 +8703,7 @@ sub main { dml => $dml, select => $select, callbacks => $callbacks, - lock_in_share_mode => 1, + lock_in_share_mode => $lock_in_share_mode, OptionParser => $o, Quoter => $q, TableParser => $tp, diff --git a/t/pt-online-schema-change/bugs.t b/t/pt-online-schema-change/bugs.t index 7d0e7822..58b1b567 100644 --- a/t/pt-online-schema-change/bugs.t +++ b/t/pt-online-schema-change/bugs.t @@ -235,6 +235,35 @@ $sb->load_file('master', "$sample/del-trg-bug-1062324.sql"); ); } +# ############################################################################# +# Something like http://bugs.mysql.com/bug.php?id=45694 means we should not +# use LOCK IN SHARE MODE with MySQL 5.0. +# ############################################################################# +$sb->load_file('master', "$sample/basic_no_fks_innodb.sql"); + +($output, $exit_status) = full_output( + sub { pt_online_schema_change::main(@args, + "$master_dsn,D=pt_osc,t=t", + "--alter", "add column (foo int)", + qw(--execute --print)) + }, +); + +if ( $sandbox_version eq '5.0' ) { + unlike( + $output, + qr/LOCK IN SHARE MODE/, + "No LOCK IN SHARE MODE for MySQL $sandbox_version" + ); +} +else { + like( + $output, + qr/LOCK IN SHARE MODE/, + "LOCK IN SHARE MODE for MySQL $sandbox_version", + ); +} + # ############################################################################# # Done. # #############################################################################