Fix for 1002448

This commit is contained in:
Brian Fraser fraserb@gmail.com
2012-05-27 23:18:50 -03:00
parent f6e265613c
commit 56d3d9a3b5
3 changed files with 33 additions and 2 deletions

View File

@@ -6296,7 +6296,7 @@ sub check_orig_table {
# Find a pk or unique index to use for the delete trigger. can_nibble() # 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, # above returns an index, but NibbleIterator will use non-unique indexes,
# so we have to do this again here. # 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}) ) { foreach my $index ( $tp->sort_indexes($orig_tbl->{tbl_struct}) ) {
if ( $index eq 'PRIMARY' || $indexes->{$index}->{is_unique} ) { if ( $index eq 'PRIMARY' || $indexes->{$index}->{is_unique} ) {
PTDEBUG && _d('Delete trigger index:', Dumper($index)); PTDEBUG && _d('Delete trigger index:', Dumper($index));

View File

@@ -29,7 +29,7 @@ elsif ( !$slave_dbh ) {
plan skip_all => 'Cannot connect to sandbox slave1'; plan skip_all => 'Cannot connect to sandbox slave1';
} }
else { else {
plan tests => 2; plan tests => 3;
} }
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic # 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" "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. # Done.
# ############################################################################# # #############################################################################

View File

@@ -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