PT-2114 Incorrect casting of bit columns by pt archiver (#587)

* PT-2114 Incorrect casting of BIT columns by pt-archiver

Added special handling of BIT columns, because by default Perl does not properly recognizes
this type and creates invalid query for MySQL.
Removed debugging comment from t/pt-table-checksum/pt-226.t
Added test case.

* PT-2114 Incorrect casting of BIT columns by pt-archiver

Removed debugging comments from t/pt-deadlock-logger/standard_options.t and t/pt-table-checksum/fnv_64.t

* PT-2114 Incorrect casting of BIT columns by pt-archiver

Added test for archiving BIT columns.

* PT-2114 Incorrect casting of BIT columns by pt-archiver

Added test for bulk operations

* PT-2114 Incorrect casting of BIT columns by pt-archiver

Added more tests for BIT columns

* PT-2114 Incorrect casting of BIT columns by pt-archiver

- Improved fix for PT-2123, so it works with 5.7
- Fixed tests for PT-2114, so they work with 5.7
This commit is contained in:
Sveta Smirnova
2023-02-22 18:59:05 +03:00
committed by GitHub
parent cd6eef7c28
commit 91ef89f904
7 changed files with 350 additions and 14 deletions

View File

@@ -6097,6 +6097,9 @@ $Data::Dumper::Quotekeys = 0;
use Percona::Toolkit;
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
# We need SQL types in order to properly handle BIT columns in WHERE clause
use DBI qw(:sql_types);
# Global variables; as few as possible.
my $oktorun = 1;
my $txn_cnt = 0;
@@ -6600,7 +6603,9 @@ sub main {
. ($o->get('replace') ? ' REPLACE' : '')
. ($o->get('ignore') ? ' IGNORE' : '')
. " INTO TABLE $dst->{db_tbl}"
. ($got_charset ? "CHARACTER SET $got_charset" : "")
. ($got_charset ? "CHARACTER SET $got_charset" :
( $src->{info}->{charset} && $src->{info}->{charset} =~ /utf/ ?
"CHARACTER SET utf8mb4" : "" ))
. "("
. join(",", map { $q->quote($_) } @{$ins_stmt->{cols}} )
. ")";
@@ -6864,7 +6869,15 @@ sub main {
}
if ( !$o->get('no-delete') ) {
my $success = do_with_retries($o, 'deleting', sub {
$del_row->execute(@{$row}[@del_slice]);
# We have to make exception for BIT column, see PT-2114
for my $i (0 .. $#del_slice) {
if ($src->{info}->{type_for}->{$del_stmt->{cols}[$del_slice[$i]]} eq 'bit') {
$del_row->bind_param($i + 1, oct('0b' . unpack('B*', @{$row}[$del_slice[$i]])), SQL_INTEGER);
} else {
$del_row->bind_param($i + 1, @{$row}[$del_slice[$i]]);
}
}
$del_row->execute();
PTDEBUG && _d('Deleted', $del_row->rows, 'rows');
$statistics{DELETE} += $del_row->rows;
});
@@ -6967,10 +6980,17 @@ sub main {
}
if ( !$o->get('no-delete') ) {
my $success = do_with_retries($o, 'bulk_deleting', sub {
$del_row->execute(
@{$first_row}[@bulkdel_slice],
@{$lastrow}[@bulkdel_slice],
);
# We have to make exception for BIT column, see PT-2114
for my $i (0 .. $#bulkdel_slice) {
if ($src->{info}->{type_for}->{$del_stmt->{cols}[$bulkdel_slice[$i]]} eq 'bit') {
$del_row->bind_param($i + 1, oct('0b' . unpack('B*', @{$first_row}[$bulkdel_slice[$i]])), SQL_INTEGER);
$del_row->bind_param($i + $#bulkdel_slice + 2, oct('0b' . unpack('B*', @{$lastrow}[$bulkdel_slice[$i]])), SQL_INTEGER);
} else {
$del_row->bind_param($i + 1, @{$first_row}[$bulkdel_slice[$i]]);
$del_row->bind_param($i + $#bulkdel_slice + 2, @{$lastrow}[$bulkdel_slice[$i]]);
}
}
$del_row->execute();
PTDEBUG && _d('Bulk deleted', $del_row->rows, 'rows');
$statistics{DELETE} += $del_row->rows;
});