Merge lp:~percona-toolkit-dev/percona-toolkit/fix-bug-821673 into lp:percona-toolkit/1.0

Proposed by Daniel Nichter
Status: Merged
Approved by: Daniel Nichter
Approved revision: 100
Merged at revision: 95
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-bug-821673
Merge into: lp:percona-toolkit/1.0
Diff against target: 391 lines (+187/-33)
10 files modified
bin/pt-table-checksum (+7/-8)
lib/TableChunker.pm (+9/-10)
t/lib/TableChunker.t (+72/-8)
t/pt-table-checksum/basics.t (+36/-1)
t/pt-table-checksum/chunk_index.t (+2/-6)
t/pt-table-checksum/samples/where01.out (+3/-0)
t/pt-table-checksum/samples/where01.sql (+26/-0)
t/pt-table-checksum/samples/where02.out (+4/-0)
t/pt-table-checksum/samples/where02.sql (+26/-0)
t/pt-table-checksum/throttle.t (+2/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-bug-821673
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+73144@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-table-checksum'
2--- bin/pt-table-checksum 2011-08-23 14:31:04 +0000
3+++ bin/pt-table-checksum 2011-08-27 18:33:24 +0000
4@@ -2863,7 +2863,7 @@
5
6 sub _chunk_char {
7 my ( $self, %args ) = @_;
8- my @required_args = qw(dbh db tbl tbl_struct chunk_col rows_in_range chunk_size);
9+ my @required_args = qw(dbh db tbl tbl_struct chunk_col min max rows_in_range chunk_size);
10 foreach my $arg ( @required_args ) {
11 die "I need a $arg argument" unless defined $args{$arg};
12 }
13@@ -2874,12 +2874,7 @@
14 my $row;
15 my $sql;
16
17- $sql = "SELECT MIN($chunk_col), MAX($chunk_col) FROM $db_tbl "
18- . "ORDER BY `$chunk_col`";
19- MKDEBUG && _d($dbh, $sql);
20- $row = $dbh->selectrow_arrayref($sql);
21- my ($min_col, $max_col) = ($row->[0], $row->[1]);
22-
23+ my ($min_col, $max_col) = @{args}{qw(min max)};
24 $sql = "SELECT ORD(?) AS min_col_ord, ORD(?) AS max_col_ord";
25 MKDEBUG && _d($dbh, $sql);
26 my $ord_sth = $dbh->prepare($sql); # avoid quoting issues
27@@ -2950,7 +2945,9 @@
28 MKDEBUG && _d("Base", $base, "chars:", @chars);
29
30
31- $sql = "SELECT MAX(LENGTH($chunk_col)) FROM $db_tbl ORDER BY `$chunk_col`";
32+ $sql = "SELECT MAX(LENGTH($chunk_col)) FROM $db_tbl "
33+ . ($args{where} ? "WHERE $args{where} " : "")
34+ . "ORDER BY `$chunk_col`";
35 MKDEBUG && _d($dbh, $sql);
36 $row = $dbh->selectrow_arrayref($sql);
37 my $max_col_len = $row->[0];
38@@ -5560,6 +5557,7 @@
39 tbl => $tbl,
40 chunk_col => $chunk_col,
41 tbl_struct => $struct,
42+ where => $final_o->get('where'),
43 );
44 if ( !grep { !defined $params{$_} } qw(min max rows_in_range) ) {
45 @chunks = $ch->calculate_chunks(
46@@ -5571,6 +5569,7 @@
47 chunk_size => $rows_per_chunk,
48 zero_chunk => $final_o->get('zero-chunk'),
49 chunk_range => $final_o->get('chunk-range'),
50+ where => $final_o->get('where'),
51 %params,
52 );
53 $maxval = $params{max};
54
55=== modified file 'lib/TableChunker.pm'
56--- lib/TableChunker.pm 2011-07-12 21:47:07 +0000
57+++ lib/TableChunker.pm 2011-08-27 18:33:24 +0000
58@@ -204,6 +204,7 @@
59 # exact - Use exact chunk_size? Use approximates is not.
60 # tries - Fetch up to this many rows to find a non-zero value
61 # chunk_range - Make chunk range open (default) or openclosed
62+# where - WHERE clause.
63 #
64 # Returns:
65 # Array of WHERE predicates like "`col` >= '10' AND `col` < '20'",
66@@ -510,6 +511,9 @@
67 # <TableChunker::get_range_statistics()>
68 # chunk_size - requested size of each chunk
69 #
70+# Optional Arguments:
71+# where - WHERE clause.
72+#
73 # Returns:
74 # Array of chunker info that <calculate_chunks()> uses to create
75 # chunks, like:
76@@ -522,7 +526,7 @@
77 # (end code)
78 sub _chunk_char {
79 my ( $self, %args ) = @_;
80- my @required_args = qw(dbh db tbl tbl_struct chunk_col rows_in_range chunk_size);
81+ my @required_args = qw(dbh db tbl tbl_struct chunk_col min max rows_in_range chunk_size);
82 foreach my $arg ( @required_args ) {
83 die "I need a $arg argument" unless defined $args{$arg};
84 }
85@@ -533,15 +537,8 @@
86 my $row;
87 my $sql;
88
89- # Get what MySQL says are the min and max column values.
90- # For example, is 'a' or 'A' the min according to MySQL?
91- $sql = "SELECT MIN($chunk_col), MAX($chunk_col) FROM $db_tbl "
92- . "ORDER BY `$chunk_col`";
93- MKDEBUG && _d($dbh, $sql);
94- $row = $dbh->selectrow_arrayref($sql);
95- my ($min_col, $max_col) = ($row->[0], $row->[1]);
96-
97 # Get the character codes between the min and max column values.
98+ my ($min_col, $max_col) = @{args}{qw(min max)};
99 $sql = "SELECT ORD(?) AS min_col_ord, ORD(?) AS max_col_ord";
100 MKDEBUG && _d($dbh, $sql);
101 my $ord_sth = $dbh->prepare($sql); # avoid quoting issues
102@@ -642,7 +639,9 @@
103 # [ant, apple, azur, boy]. We assume data is more evenly distributed
104 # than not so we use the minimum number of characters to express a chunk
105 # size.
106- $sql = "SELECT MAX(LENGTH($chunk_col)) FROM $db_tbl ORDER BY `$chunk_col`";
107+ $sql = "SELECT MAX(LENGTH($chunk_col)) FROM $db_tbl "
108+ . ($args{where} ? "WHERE $args{where} " : "")
109+ . "ORDER BY `$chunk_col`";
110 MKDEBUG && _d($dbh, $sql);
111 $row = $dbh->selectrow_arrayref($sql);
112 my $max_col_len = $row->[0];
113
114=== modified file 't/lib/TableChunker.t'
115--- t/lib/TableChunker.t 2011-07-12 21:47:07 +0000
116+++ t/lib/TableChunker.t 2011-08-27 18:33:24 +0000
117@@ -27,7 +27,7 @@
118 plan skip_all => 'Cannot connect to sandbox master';
119 }
120 else {
121- plan tests => 86;
122+ plan tests => 90;
123 }
124
125 $sb->create_dbs($dbh, ['test']);
126@@ -1174,21 +1174,27 @@
127
128 $sb->load_file('master', "t/lib/samples/char-chunking/world-city.sql", 'test');
129 $t = $p->parse( $du->get_create_table($dbh, $q, 'test', 'world_city') );
130+%params = $c->get_range_statistics(
131+ dbh => $dbh,
132+ db => 'test',
133+ tbl => 'world_city',
134+ chunk_col => 'name',
135+ tbl_struct => $t,
136+ chunk_size => '500',
137+);
138 @chunks = $c->calculate_chunks(
139+ dbh => $dbh,
140+ db => 'test',
141+ tbl => 'world_city',
142 tbl_struct => $t,
143 chunk_col => 'name',
144- min => 'A Coruña (La Coruña)',
145- max => '´s-Hertogenbosch',
146- rows_in_range => 4079,
147 chunk_size => 500,
148- dbh => $dbh,
149- db => 'test',
150- tbl => 'world_city',
151+ %params,
152 );
153 ok(
154 @chunks >= 9,
155 "At least 9 char chunks on test.world_city.name"
156-);
157+) or print STDERR Dumper(\@chunks);
158
159 my $n_rows = count_rows("test.world_city", "name", @chunks);
160 is(
161@@ -1231,6 +1237,64 @@
162 );
163 };
164
165+# ############################################################################
166+# Bug 821673: pt-table-checksum doesn't included --where in min max queries
167+# ############################################################################
168+$sb->load_file('master', "t/pt-table-checksum/samples/where01.sql");
169+$t = $p->parse( $du->get_create_table($dbh, $q, 'test', 'checksum_test') );
170+%params = $c->get_range_statistics(
171+ dbh => $dbh,
172+ db => 'test',
173+ tbl => 'checksum_test',
174+ chunk_col => 'id',
175+ tbl_struct => $t,
176+ where => "date = '2011-03-03'",
177+);
178+is(
179+ $params{min},
180+ 11,
181+ 'MIN int range stats with --where (bug 821673)'
182+);
183+is(
184+ $params{max},
185+ 15,
186+ 'MAX int range stats with --where (bug 821673)'
187+);
188+
189+# char chunking
190+$sb->load_file('master', "t/pt-table-checksum/samples/where02.sql");
191+$t = $p->parse( $du->get_create_table($dbh, $q, 'test', 'checksum_test') );
192+%params = $c->get_range_statistics(
193+ dbh => $dbh,
194+ db => 'test',
195+ tbl => 'checksum_test',
196+ chunk_col => 'id',
197+ tbl_struct => $t,
198+ where => "date = '2011-03-03'",
199+);
200+is(
201+ $params{min},
202+ 'Apple',
203+ 'MIN char range stats with --where (bug 821673)'
204+);
205+is(
206+ $params{max},
207+ 'raspberry',
208+ 'MAX char range stats with --where (bug 821673)'
209+);
210+
211+# It's difficult to construct a char chunk test where WHERE will matter.
212+#@chunks = $c->calculate_chunks(
213+# dbh => $dbh,
214+# db => 'test',
215+# tbl => 'checksum_test',
216+# tbl_struct => $t,
217+# chunk_col => 'id',
218+# chunk_size => 5,
219+# where => "date = '2011-03-03'",
220+# %params,
221+#);
222+
223 # #############################################################################
224 # Done.
225 # #############################################################################
226
227=== modified file 't/pt-table-checksum/basics.t'
228--- t/pt-table-checksum/basics.t 2011-07-12 22:56:55 +0000
229+++ t/pt-table-checksum/basics.t 2011-08-27 18:33:24 +0000
230@@ -24,7 +24,7 @@
231 plan skip_all => 'Cannot connect to sandbox master';
232 }
233 else {
234- plan tests => 12;
235+ plan tests => 14;
236 }
237
238 my ($output, $output2);
239@@ -120,6 +120,41 @@
240 "--sleep doesn't sleep unless table is chunked"
241 );
242
243+
244+# ############################################################################
245+# Bug 821673: pt-table-checksum doesn't included --where in min max queries
246+# ############################################################################
247+$sb->load_file('master', "t/pt-table-checksum/samples/where01.sql");
248+
249+ok(
250+ no_diff(
251+ sub { pt_table_checksum::main(@args,
252+ qw(--no-zero-chunk --chunk-size 5), '--where', "date = '2011-03-03'");
253+ },
254+ "t/pt-table-checksum/samples/where01.out",
255+ trf => "awk '{print \$1 \" \" \$2 \" \" \$3 \" \" \$6}'",
256+ ),
257+ "--where affects int range stats (bug 821673)"
258+);
259+
260+# Test it again with a varchar primary key. The resulting 5 rows are:
261+# | Apple | 2011-03-03 |
262+# | lemon | 2011-03-03 |
263+# | lime | 2011-03-03 |
264+# | pineapple | 2011-03-03 |
265+# | raspberry | 2011-03-03 |
266+$sb->load_file('master', "t/pt-table-checksum/samples/where02.sql");
267+ok(
268+ no_diff(
269+ sub { pt_table_checksum::main(@args,
270+ qw(--no-zero-chunk --chunk-size 5), '--where', "date = '2011-03-03'");
271+ },
272+ "t/pt-table-checksum/samples/where02.out",
273+ trf => "awk '{print \$1 \" \" \$2 \" \" \$3 \" \" \$6}'",
274+ ),
275+ "--where affects char range stats (bug 821673)"
276+);
277+
278 # #############################################################################
279 # Done.
280 # #############################################################################
281
282=== modified file 't/pt-table-checksum/chunk_index.t'
283--- t/pt-table-checksum/chunk_index.t 2011-07-12 22:56:55 +0000
284+++ t/pt-table-checksum/chunk_index.t 2011-08-27 18:33:24 +0000
285@@ -127,12 +127,8 @@
286
287 is(
288 $output,
289-"issue_519 t SELECT /*issue_519.t:1/5*/ 0 AS chunk_num, COUNT(*) AS cnt, COALESCE(LOWER(CONV(BIT_XOR(CAST(CRC32(CONCAT_WS('#', `i`, `y`, `t`, CONCAT(ISNULL(`t`)))) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `issue_519`.`t` FORCE INDEX (`y`) WHERE (`y` = 0) AND ((y > 2009))
290-issue_519 t `y` = 0
291-issue_519 t `y` > 0 AND `y` < '2003'
292-issue_519 t `y` >= '2003' AND `y` < '2006'
293-issue_519 t `y` >= '2006' AND `y` < '2009'
294-issue_519 t `y` >= '2009'
295+"issue_519 t SELECT /*issue_519.t:1/1*/ 0 AS chunk_num, COUNT(*) AS cnt, COALESCE(LOWER(CONV(BIT_XOR(CAST(CRC32(CONCAT_WS('#', `i`, `y`, `t`, CONCAT(ISNULL(`t`)))) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `issue_519`.`t` FORCE INDEX (`y`) WHERE (1=1) AND ((y > 2009))
296+issue_519 t 1=1
297 ",
298 "Auto-chosen --chunk-index for --where (issue 378)"
299 );
300
301=== added file 't/pt-table-checksum/samples/where01.out'
302--- t/pt-table-checksum/samples/where01.out 1970-01-01 00:00:00 +0000
303+++ t/pt-table-checksum/samples/where01.out 2011-08-27 18:33:24 +0000
304@@ -0,0 +1,3 @@
305+DATABASE TABLE CHUNK COUNT
306+test checksum_test 0 2
307+test checksum_test 1 3
308
309=== added file 't/pt-table-checksum/samples/where01.sql'
310--- t/pt-table-checksum/samples/where01.sql 1970-01-01 00:00:00 +0000
311+++ t/pt-table-checksum/samples/where01.sql 2011-08-27 18:33:24 +0000
312@@ -0,0 +1,26 @@
313+drop database if exists test;
314+create database test;
315+use test;
316+
317+CREATE TABLE `checksum_test` (
318+ `id` int(11) NOT NULL DEFAULT '0',
319+ `date` date DEFAULT NULL,
320+ PRIMARY KEY (`id`)
321+) ENGINE=InnoDB;
322+
323+INSERT INTO `checksum_test` VALUES
324+ (1, '2011-03-01'),
325+ (2, '2011-03-01'),
326+ (3, '2011-03-01'),
327+ (4, '2011-03-01'),
328+ (5, '2011-03-01'),
329+ (6, '2011-03-02'),
330+ (7, '2011-03-02'),
331+ (8, '2011-03-02'),
332+ (9, '2011-03-02'),
333+ (10, '2011-03-02'),
334+ (11, '2011-03-03'),
335+ (12, '2011-03-03'),
336+ (13, '2011-03-03'),
337+ (14, '2011-03-03'),
338+ (15, '2011-03-03');
339
340=== added file 't/pt-table-checksum/samples/where02.out'
341--- t/pt-table-checksum/samples/where02.out 1970-01-01 00:00:00 +0000
342+++ t/pt-table-checksum/samples/where02.out 2011-08-27 18:33:24 +0000
343@@ -0,0 +1,4 @@
344+DATABASE TABLE CHUNK COUNT
345+test checksum_test 0 1
346+test checksum_test 1 4
347+test checksum_test 2 0
348
349=== added file 't/pt-table-checksum/samples/where02.sql'
350--- t/pt-table-checksum/samples/where02.sql 1970-01-01 00:00:00 +0000
351+++ t/pt-table-checksum/samples/where02.sql 2011-08-27 18:33:24 +0000
352@@ -0,0 +1,26 @@
353+drop database if exists test;
354+create database test;
355+use test;
356+
357+CREATE TABLE `checksum_test` (
358+ `id` varchar(255) NOT NULL,
359+ `date` date DEFAULT NULL,
360+ PRIMARY KEY (`id`)
361+) ENGINE=InnoDB;
362+
363+INSERT INTO `checksum_test` VALUES
364+ ('Apple', '2011-03-03'),
365+ ('banana', '2011-03-01'),
366+ ('orange', '2011-03-01'),
367+ ('grape', '2011-03-01'),
368+ ('kiwi', '2011-03-01'),
369+ ('strawberry', '2011-03-02'),
370+ ('peach', '2011-03-02'),
371+ ('mango', '2011-03-02'),
372+ ('tomato', '2011-03-02'),
373+ ('nectarine', '2011-03-02'),
374+ ('pear', '2011-03-01'),
375+ ('lemon', '2011-03-03'),
376+ ('lime', '2011-03-03'),
377+ ('pineapple', '2011-03-03'),
378+ ('raspberry', '2011-03-03');
379
380=== modified file 't/pt-table-checksum/throttle.t'
381--- t/pt-table-checksum/throttle.t 2011-08-23 15:11:00 +0000
382+++ t/pt-table-checksum/throttle.t 2011-08-27 18:33:24 +0000
383@@ -281,6 +281,8 @@
384 # Done.
385 # #############################################################################
386 diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`);
387+diag(`/tmp/12346/stop >/dev/null`); # Start/stop clears SHOW SLAVE HOSTS.
388+diag(`/tmp/12346/start >/dev/null`);
389 $sb->wipe_clean($master_dbh);
390 diag(`$trunk/sandbox/test-env reset >/dev/null`);
391 exit;

Subscribers

People subscribed via source and target branches

to all changes: