pt-table-sync and text columns with just whitespace
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Percona Toolkit moved to https://jira.percona.com/projects/PT |
Fix Released
|
Medium
|
Brian Fraser |
Bug Description
I was having trouble syncing some tables with text columns, some of which are just whitespace.
pt-table-sync recognised that rows in the two databases were different, but the UPDATE command it was generating was setting the text column to '' (the empty string) when it should have been ' ' or "\r\n" (crlf).
The problem appears to be in this section of code ...
if ( $self->{hex_blob}
&& $tbl_struct-
$col = "IF(`$col`='', '', CONCAT('0x', HEX(`$col`))) AS `$col`";
}
... where the IF condition is satisfied more often than I expected (note: MySQL really isn't my thing) ...
mysql> SHOW VARIABLES LIKE 'version%';
+------
| Variable_name | Value |
+------
| version | 5.0.77-log |
| version_bdb | Sleepycat Software: Berkeley DB 4.1.24: (January 29, 2009) |
| version_comment | Source distribution |
| version_
| version_compile_os | redhat-linux-gnu |
+------
5 rows in set (0.00 sec)
mysql> DESCRIBE the_table;
+------
| Field | Type | Null | Key | Default | Extra |
+------
| id | int(11) | NO | PRI | NULL | auto_increment |
: :
| message | text | NO | | NULL | |
: :
+------
11 rows in set (0.00 sec)
mysql> SELECT id,message,
+------
| id | message | LENGTH(message) | HEX(message) | IF(message=
+------
| 24169 | | 1 | 20 | empty |
+------
1 row in set (0.00 sec)
(note that this is a stock CentOS 5.7 box.)
This patch fixed things for me ...
- $col = "IF(`$col`='', '', CONCAT('0x', HEX(`$col`))) AS `$col`";
+ $col = "IF(LENGTH(
... but assumes that LENGTH() does something sensible for blob and binary columns (which it probably does, I just haven't tested it.)
Related branches
- Daniel Nichter: Approve
-
Diff: 62 lines (+8/-5)4 files modifiedbin/pt-table-sync (+1/-1)
bin/pt-upgrade (+1/-1)
lib/ChangeHandler.pm (+4/-1)
t/lib/ChangeHandler.t (+2/-2)
tags: | added: pt-table-sync |
tags: | added: whitespace |
Changed in percona-toolkit: | |
status: | New → Confirmed |
Changed in percona-toolkit: | |
assignee: | nobody → Brian Fraser (fraserbn) |
Changed in percona-toolkit: | |
milestone: | none → 2.1.4 |
Changed in percona-toolkit: | |
status: | Confirmed → In Progress |
Changed in percona-toolkit: | |
importance: | Undecided → Medium |
Changed in percona-toolkit: | |
status: | In Progress → Fix Committed |
Changed in percona-toolkit: | |
status: | Fix Committed → Fix Released |
Percona now uses JIRA for bug reports so this bug report is migrated to: https:/ /jira.percona. com/browse/ PT-471