From 3c6edf6d71f2397eae7cf1f8056cd2921614b590 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Sat, 27 Aug 2011 11:26:00 -0600 Subject: [PATCH] Update TableChunker in pt-table-checksum. Include COUNT in test samples. --- bin/pt-table-checksum | 13 +++++-------- t/pt-table-checksum/basics.t | 4 ++-- t/pt-table-checksum/samples/where01.out | 6 +++--- t/pt-table-checksum/samples/where02.out | 4 ++++ 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index 72cbc371..3c01380b 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -2863,7 +2863,7 @@ sub _chunk_numeric { sub _chunk_char { my ( $self, %args ) = @_; - my @required_args = qw(dbh db tbl tbl_struct chunk_col rows_in_range chunk_size); + my @required_args = qw(dbh db tbl tbl_struct chunk_col min max rows_in_range chunk_size); foreach my $arg ( @required_args ) { die "I need a $arg argument" unless defined $args{$arg}; } @@ -2874,12 +2874,7 @@ sub _chunk_char { my $row; my $sql; - $sql = "SELECT MIN($chunk_col), MAX($chunk_col) FROM $db_tbl " - . "ORDER BY `$chunk_col`"; - MKDEBUG && _d($dbh, $sql); - $row = $dbh->selectrow_arrayref($sql); - my ($min_col, $max_col) = ($row->[0], $row->[1]); - + my ($min_col, $max_col) = @{args}{qw(min max)}; $sql = "SELECT ORD(?) AS min_col_ord, ORD(?) AS max_col_ord"; MKDEBUG && _d($dbh, $sql); my $ord_sth = $dbh->prepare($sql); # avoid quoting issues @@ -2950,7 +2945,9 @@ sub _chunk_char { MKDEBUG && _d("Base", $base, "chars:", @chars); - $sql = "SELECT MAX(LENGTH($chunk_col)) FROM $db_tbl ORDER BY `$chunk_col`"; + $sql = "SELECT MAX(LENGTH($chunk_col)) FROM $db_tbl " + . ($args{where} ? "WHERE $args{where} " : "") + . "ORDER BY `$chunk_col`"; MKDEBUG && _d($dbh, $sql); $row = $dbh->selectrow_arrayref($sql); my $max_col_len = $row->[0]; diff --git a/t/pt-table-checksum/basics.t b/t/pt-table-checksum/basics.t index 9b598ef8..749f75b3 100644 --- a/t/pt-table-checksum/basics.t +++ b/t/pt-table-checksum/basics.t @@ -132,7 +132,7 @@ ok( qw(--no-zero-chunk --chunk-size 5), '--where', "date = '2011-03-03'"); }, "t/pt-table-checksum/samples/where01.out", - trf => "awk '{print \$1 \" \" \$2 \" \" \$3}'", + trf => "awk '{print \$1 \" \" \$2 \" \" \$3 \" \" \$6}'", ), "--where affects int range stats (bug 821673)" ); @@ -150,7 +150,7 @@ ok( qw(--no-zero-chunk --chunk-size 5), '--where', "date = '2011-03-03'"); }, "t/pt-table-checksum/samples/where02.out", - trf => "awk '{print \$1 \" \" \$2 \" \" \$3}'", + trf => "awk '{print \$1 \" \" \$2 \" \" \$3 \" \" \$6}'", ), "--where affects char range stats (bug 821673)" ); diff --git a/t/pt-table-checksum/samples/where01.out b/t/pt-table-checksum/samples/where01.out index af2869aa..8709fa8a 100644 --- a/t/pt-table-checksum/samples/where01.out +++ b/t/pt-table-checksum/samples/where01.out @@ -1,3 +1,3 @@ -DATABASE TABLE CHUNK -test checksum_test 0 -test checksum_test 1 +DATABASE TABLE CHUNK COUNT +test checksum_test 0 2 +test checksum_test 1 3 diff --git a/t/pt-table-checksum/samples/where02.out b/t/pt-table-checksum/samples/where02.out index e69de29b..e621908f 100644 --- a/t/pt-table-checksum/samples/where02.out +++ b/t/pt-table-checksum/samples/where02.out @@ -0,0 +1,4 @@ +DATABASE TABLE CHUNK COUNT +test checksum_test 0 1 +test checksum_test 1 4 +test checksum_test 2 0