From 031cc1751c1470798bc689203e047155f65f257d Mon Sep 17 00:00:00 2001 From: "Brian Fraser fraserb@gmail.com" <> Date: Mon, 27 Aug 2012 15:04:51 -0300 Subject: [PATCH] ChangeHandler: Don't hexify text columns. As far as I understand, it doesn't make any sense to hexify text columns; they break in many ways (you can't roundtrip the UTFs, quote_val gets the hex quoting wrong, etc) and in any case, the maatkit bugs about the feature are all about blob/binary columns. And, while a perilous excercise of genetic programming, removing it didn't break any pt-table-sync tests, so this commit does exactly that. --- bin/pt-table-sync | 2 +- lib/ChangeHandler.pm | 2 +- t/lib/ChangeHandler.t | 29 ++++++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/bin/pt-table-sync b/bin/pt-table-sync index 5ddfc8c9..7b9d939b 100755 --- a/bin/pt-table-sync +++ b/bin/pt-table-sync @@ -3572,7 +3572,7 @@ sub make_fetch_back_query { map { my $col = $_; if ( $self->{hex_blob} - && $tbl_struct->{type_for}->{$col} =~ m/blob|text|binary/ ) { + && $tbl_struct->{type_for}->{$col} =~ m/b(?:lob|inary)/ ) { $col = "IF(BINARY(`$col`)='', '', CONCAT('0x', HEX(`$col`))) AS `$col`"; } else { diff --git a/lib/ChangeHandler.pm b/lib/ChangeHandler.pm index 9314f362..1507b6ed 100644 --- a/lib/ChangeHandler.pm +++ b/lib/ChangeHandler.pm @@ -496,7 +496,7 @@ sub make_fetch_back_query { map { my $col = $_; if ( $self->{hex_blob} - && $tbl_struct->{type_for}->{$col} =~ m/blob|text|binary/ ) { + && $tbl_struct->{type_for}->{$col} =~ m/b(?:lob|inary)/ ) { # Here we cast to binary, as otherwise, since text columns are # space padded, MySQL would compare ' ' and '' to be the same. # See https://bugs.launchpad.net/percona-toolkit/+bug/930693 diff --git a/t/lib/ChangeHandler.t b/t/lib/ChangeHandler.t index 1659b18e..e5711181 100644 --- a/t/lib/ChangeHandler.t +++ b/t/lib/ChangeHandler.t @@ -386,7 +386,7 @@ is( # ############################################################################# $tbl_struct = { cols => [qw(t)], - type_for => {t=>'text'}, + type_for => {t=>'blob'}, }; $ch = new ChangeHandler( Quoter => $q, @@ -406,6 +406,33 @@ is( "Don't prepend 0x to blank blob/text column value (issue 1052)" ); +# ############################################################################# +# An update to the above bug; It should only hexify for blob and binary, not +# for text columns; The latter not only breaks for UTF-8 data, but also +# breaks now that hex-looking columns aren't automatically left unquoted. +# ############################################################################# +$tbl_struct = { + cols => [qw(t)], + type_for => {t=>'text'}, +}; +$ch = new ChangeHandler( + Quoter => $q, + left_db => 'test', + left_tbl => 't', + right_db => 'test', + right_tbl => 't', + actions => [ sub {} ], + replace => 0, + queue => 0, + tbl_struct => $tbl_struct, +); + +is( + $ch->make_fetch_back_query('1=1'), + "SELECT `t` FROM `test`.`t` WHERE 1=1 LIMIT 1", + "Don't prepend 0x to blank blob/text column value (issue 1052)" +); + # ############################################################################# SKIP: {