diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index 8462d259..f67d5d82 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -5415,7 +5415,11 @@ sub new { PTDEBUG && _d('Ascend params:', Dumper($asc)); my $from = "$tbl->{name} FORCE INDEX(`$index`)"; - my $order_by = join(', ', map {$q->quote($_)} @{$index_cols}); + my $order_by = join(', ', map { $tbl->{tbl_struct}->{type_for}->{$_} eq 'enum' + ? "CONCAT(".$q->quote($_).")" : $q->quote($_)} @{$index_cols}); + + my $order_by_dec = join(' DESC,', map { $tbl->{tbl_struct}->{type_for}->{$_} eq 'enum' + ? "CONCAT(".$q->quote($_).")" : $q->quote($_)} @{$index_cols}); my $first_lb_sql = "SELECT /*!40001 SQL_NO_CACHE */ " @@ -5447,7 +5451,7 @@ sub new { . " FROM $from" . ($where ? " WHERE $where" : '') . " ORDER BY " - . join(' DESC, ', map {$q->quote($_)} @{$index_cols}) . ' DESC' + . $order_by_dec . ' DESC' . " LIMIT 1" . " /*last upper boundary*/"; PTDEBUG && _d('Last upper boundary statement:', $last_ub_sql); diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index f70ea0ec..f2e877e4 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -6222,7 +6222,11 @@ sub new { PTDEBUG && _d('Ascend params:', Dumper($asc)); my $from = "$tbl->{name} FORCE INDEX(`$index`)"; - my $order_by = join(', ', map {$q->quote($_)} @{$index_cols}); + my $order_by = join(', ', map { $tbl->{tbl_struct}->{type_for}->{$_} eq 'enum' + ? "CONCAT(".$q->quote($_).")" : $q->quote($_)} @{$index_cols}); + + my $order_by_dec = join(' DESC,', map { $tbl->{tbl_struct}->{type_for}->{$_} eq 'enum' + ? "CONCAT(".$q->quote($_).")" : $q->quote($_)} @{$index_cols}); my $first_lb_sql = "SELECT /*!40001 SQL_NO_CACHE */ " @@ -6254,7 +6258,7 @@ sub new { . " FROM $from" . ($where ? " WHERE $where" : '') . " ORDER BY " - . join(' DESC, ', map {$q->quote($_)} @{$index_cols}) . ' DESC' + . $order_by_dec . ' DESC' . " LIMIT 1" . " /*last upper boundary*/"; PTDEBUG && _d('Last upper boundary statement:', $last_ub_sql); diff --git a/lib/NibbleIterator.pm b/lib/NibbleIterator.pm index ea5f08c5..b363abc4 100644 --- a/lib/NibbleIterator.pm +++ b/lib/NibbleIterator.pm @@ -138,7 +138,11 @@ sub new { # ORDER BY are the same for all statements. FORCE IDNEX and ORDER BY # are needed to ensure deterministic nibbling. my $from = "$tbl->{name} FORCE INDEX(`$index`)"; - my $order_by = join(', ', map {$q->quote($_)} @{$index_cols}); + my $order_by = join(', ', map { $tbl->{tbl_struct}->{type_for}->{$_} eq 'enum' + ? "CONCAT(".$q->quote($_).")" : $q->quote($_)} @{$index_cols}); + + my $order_by_dec = join(' DESC,', map { $tbl->{tbl_struct}->{type_for}->{$_} eq 'enum' + ? "CONCAT(".$q->quote($_).")" : $q->quote($_)} @{$index_cols}); # The real first row in the table. Usually we start nibbling from # this row. Called once in _get_bounds(). @@ -177,7 +181,7 @@ sub new { . " FROM $from" . ($where ? " WHERE $where" : '') . " ORDER BY " - . join(' DESC, ', map {$q->quote($_)} @{$index_cols}) . ' DESC' + . $order_by_dec . ' DESC' . " LIMIT 1" . " /*last upper boundary*/"; PTDEBUG && _d('Last upper boundary statement:', $last_ub_sql);