diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index c78e813b..becc7a9f 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -6296,7 +6296,7 @@ sub check_orig_table { # Find a pk or unique index to use for the delete trigger. can_nibble() # above returns an index, but NibbleIterator will use non-unique indexes, # so we have to do this again here. - my $indexes = $orig_tbl->{tbl_struct}->{indexes}; # brevity + my $indexes = $orig_tbl->{tbl_struct}->{keys}; # brevity foreach my $index ( $tp->sort_indexes($orig_tbl->{tbl_struct}) ) { if ( $index eq 'PRIMARY' || $indexes->{$index}->{is_unique} ) { PTDEBUG && _d('Delete trigger index:', Dumper($index)); diff --git a/t/pt-online-schema-change/bugs.t b/t/pt-online-schema-change/bugs.t index ee6c9191..c483b90b 100644 --- a/t/pt-online-schema-change/bugs.t +++ b/t/pt-online-schema-change/bugs.t @@ -29,7 +29,7 @@ elsif ( !$slave_dbh ) { plan skip_all => 'Cannot connect to sandbox slave1'; } else { - plan tests => 2; + plan tests => 3; } # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic @@ -66,6 +66,23 @@ unlike( "Bug 994002: doesn't choose non-PK" ); +# ############################################################################ +# https://bugs.launchpad.net/percona-toolkit/+bug/1002448 +# ############################################################################ +$sb->load_file('master', "$sample/bug-1002448.sql"); + +$output = output( + sub { pt_online_schema_change::main(@args, + "$master_dsn,D=test1002448,t=table_name", + "--alter", "add column (foo int)", + qw(--chunk-size 2 --dry-run --print)) }, +); + + +unlike $output, + qr/\QThe original table `test1002448`.`table_name` does not have a PRIMARY KEY or a unique index which is required for the DELETE trigger/, + "Bug 1002448: mistakenly uses indexes instead of keys"; + # ############################################################################# # Done. # ############################################################################# diff --git a/t/pt-online-schema-change/samples/bug-1002448.sql b/t/pt-online-schema-change/samples/bug-1002448.sql new file mode 100644 index 00000000..f7f012c5 --- /dev/null +++ b/t/pt-online-schema-change/samples/bug-1002448.sql @@ -0,0 +1,14 @@ +drop database if exists test1002448; +create database test1002448; +use test1002448; + +CREATE TABLE `table_name` ( + `site` varchar(20) NOT NULL DEFAULT '', + `update_name` varchar(32) NOT NULL DEFAULT '', + `user` varchar(64) NOT NULL DEFAULT '', + `time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `value` varchar(64) NOT NULL DEFAULT '', + UNIQUE KEY `site` (`site`,`update_name`,`user`,`value`), + KEY `user` (`user`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +