From a1cba706ec83fafb1153d7bbf453107ff3fc8856 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Fri, 30 Mar 2012 10:37:16 -0600 Subject: [PATCH] Update TableChunker in pt-table-sync, pt-upgrade, and pt-online-schema-change. --- bin/pt-online-schema-change | 21 +++++++++++---------- bin/pt-table-sync | 21 +++++++++++---------- bin/pt-upgrade | 21 +++++++++++---------- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index 26fd4a76..48a4915a 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -2773,10 +2773,11 @@ sub _chunk_char { foreach my $arg ( @required_args ) { die "I need a $arg argument" unless defined $args{$arg}; } - my $q = $self->{Quoter}; - my $db_tbl = $q->quote($args{db}, $args{tbl}); - my $dbh = $args{dbh}; - my $chunk_col = $args{chunk_col}; + my $q = $self->{Quoter}; + my $db_tbl = $q->quote($args{db}, $args{tbl}); + my $dbh = $args{dbh}; + my $chunk_col = $args{chunk_col}; + my $qchunk_col = $q->quote($args{chunk_col}); my $row; my $sql; @@ -2834,9 +2835,9 @@ sub _chunk_char { $ins_char_sth->execute($char_code); } - $sql = "SELECT `$chunk_col` FROM $tmp_db_tbl " - . "WHERE `$chunk_col` BETWEEN ? AND ? " - . "ORDER BY `$chunk_col`"; + $sql = "SELECT $qchunk_col FROM $tmp_db_tbl " + . "WHERE $qchunk_col BETWEEN ? AND ? " + . "ORDER BY $qchunk_col"; PTDEBUG && _d($dbh, $sql); my $sel_char_sth = $dbh->prepare($sql); $sel_char_sth->execute($min_col, $max_col); @@ -2851,9 +2852,9 @@ sub _chunk_char { PTDEBUG && _d("Base", $base, "chars:", @chars); - $sql = "SELECT MAX(LENGTH($chunk_col)) FROM $db_tbl " + $sql = "SELECT MAX(LENGTH($qchunk_col)) FROM $db_tbl " . ($args{where} ? "WHERE $args{where} " : "") - . "ORDER BY `$chunk_col`"; + . "ORDER BY $qchunk_col"; PTDEBUG && _d($dbh, $sql); $row = $dbh->selectrow_arrayref($sql); my $max_col_len = $row->[0]; @@ -2887,7 +2888,7 @@ sub _chunk_char { }; return ( - col => $q->quote($chunk_col), + col => $qchunk_col, start_point => 0, end_point => $n_values, interval => $interval, diff --git a/bin/pt-table-sync b/bin/pt-table-sync index 1168c68b..667efd65 100755 --- a/bin/pt-table-sync +++ b/bin/pt-table-sync @@ -3231,10 +3231,11 @@ sub _chunk_char { foreach my $arg ( @required_args ) { die "I need a $arg argument" unless defined $args{$arg}; } - my $q = $self->{Quoter}; - my $db_tbl = $q->quote($args{db}, $args{tbl}); - my $dbh = $args{dbh}; - my $chunk_col = $args{chunk_col}; + my $q = $self->{Quoter}; + my $db_tbl = $q->quote($args{db}, $args{tbl}); + my $dbh = $args{dbh}; + my $chunk_col = $args{chunk_col}; + my $qchunk_col = $q->quote($args{chunk_col}); my $row; my $sql; @@ -3292,9 +3293,9 @@ sub _chunk_char { $ins_char_sth->execute($char_code); } - $sql = "SELECT `$chunk_col` FROM $tmp_db_tbl " - . "WHERE `$chunk_col` BETWEEN ? AND ? " - . "ORDER BY `$chunk_col`"; + $sql = "SELECT $qchunk_col FROM $tmp_db_tbl " + . "WHERE $qchunk_col BETWEEN ? AND ? " + . "ORDER BY $qchunk_col"; PTDEBUG && _d($dbh, $sql); my $sel_char_sth = $dbh->prepare($sql); $sel_char_sth->execute($min_col, $max_col); @@ -3309,9 +3310,9 @@ sub _chunk_char { PTDEBUG && _d("Base", $base, "chars:", @chars); - $sql = "SELECT MAX(LENGTH($chunk_col)) FROM $db_tbl " + $sql = "SELECT MAX(LENGTH($qchunk_col)) FROM $db_tbl " . ($args{where} ? "WHERE $args{where} " : "") - . "ORDER BY `$chunk_col`"; + . "ORDER BY $qchunk_col"; PTDEBUG && _d($dbh, $sql); $row = $dbh->selectrow_arrayref($sql); my $max_col_len = $row->[0]; @@ -3345,7 +3346,7 @@ sub _chunk_char { }; return ( - col => $q->quote($chunk_col), + col => $qchunk_col, start_point => 0, end_point => $n_values, interval => $interval, diff --git a/bin/pt-upgrade b/bin/pt-upgrade index d5e6e081..d415999f 100755 --- a/bin/pt-upgrade +++ b/bin/pt-upgrade @@ -5437,10 +5437,11 @@ sub _chunk_char { foreach my $arg ( @required_args ) { die "I need a $arg argument" unless defined $args{$arg}; } - my $q = $self->{Quoter}; - my $db_tbl = $q->quote($args{db}, $args{tbl}); - my $dbh = $args{dbh}; - my $chunk_col = $args{chunk_col}; + my $q = $self->{Quoter}; + my $db_tbl = $q->quote($args{db}, $args{tbl}); + my $dbh = $args{dbh}; + my $chunk_col = $args{chunk_col}; + my $qchunk_col = $q->quote($args{chunk_col}); my $row; my $sql; @@ -5498,9 +5499,9 @@ sub _chunk_char { $ins_char_sth->execute($char_code); } - $sql = "SELECT `$chunk_col` FROM $tmp_db_tbl " - . "WHERE `$chunk_col` BETWEEN ? AND ? " - . "ORDER BY `$chunk_col`"; + $sql = "SELECT $qchunk_col FROM $tmp_db_tbl " + . "WHERE $qchunk_col BETWEEN ? AND ? " + . "ORDER BY $qchunk_col"; PTDEBUG && _d($dbh, $sql); my $sel_char_sth = $dbh->prepare($sql); $sel_char_sth->execute($min_col, $max_col); @@ -5515,9 +5516,9 @@ sub _chunk_char { PTDEBUG && _d("Base", $base, "chars:", @chars); - $sql = "SELECT MAX(LENGTH($chunk_col)) FROM $db_tbl " + $sql = "SELECT MAX(LENGTH($qchunk_col)) FROM $db_tbl " . ($args{where} ? "WHERE $args{where} " : "") - . "ORDER BY `$chunk_col`"; + . "ORDER BY $qchunk_col"; PTDEBUG && _d($dbh, $sql); $row = $dbh->selectrow_arrayref($sql); my $max_col_len = $row->[0]; @@ -5551,7 +5552,7 @@ sub _chunk_char { }; return ( - col => $q->quote($chunk_col), + col => $qchunk_col, start_point => 0, end_point => $n_values, interval => $interval,