Merge lp:~percona-toolkit-dev/percona-toolkit/fix-ptc-pk-bug-978432 into lp:percona-toolkit/2.1

Proposed by Daniel Nichter
Status: Merged
Merged at revision: 248
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-ptc-pk-bug-978432
Merge into: lp:percona-toolkit/2.1
Diff against target: 151 lines (+78/-6)
5 files modified
bin/pt-table-checksum (+7/-4)
lib/NibbleIterator.pm (+14/-1)
t/pt-table-checksum/chunk_index.t (+17/-1)
t/pt-table-checksum/samples/not-using-pk-bug.out (+20/-0)
t/pt-table-checksum/samples/not-using-pk-bug.sql (+20/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-ptc-pk-bug-978432
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+105110@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 2012-05-04 16:17:01 +0000
3+++ bin/pt-table-checksum 2012-05-08 18:46:21 +0000
4@@ -3858,12 +3858,18 @@
5 }
6 my ($cxn, $tbl, $chunk_size, $o) = @args{@required_args};
7
8+ my $where = $o->has('where') ? $o->get('where') : '';
9+
10 my ($row_est, $mysql_index) = get_row_estimate(
11 Cxn => $cxn,
12 tbl => $tbl,
13- where => $o->has('where') ? $o->get('where') : '',
14+ where => $where,
15 );
16
17+ if ( !$where ) {
18+ $mysql_index = undef;
19+ }
20+
21 my $one_nibble = !defined $args{one_nibble} || $args{one_nibble}
22 ? $row_est <= $chunk_size * $o->get('chunk-size-limit')
23 : 0;
24@@ -6387,9 +6393,6 @@
25 my $chunk_size_limit = $o->get('chunk-size-limit');
26 my @too_large;
27 foreach my $slave ( @$slaves ) {
28- # get_row_estimate() returns (row_est, index), but
29- # we only need the row_est. Maybe in the future we'll
30- # care what index MySQL will use on a slave.
31 my ($n_rows) = NibbleIterator::get_row_estimate(
32 Cxn => $slave,
33 tbl => $tbl,
34
35=== modified file 'lib/NibbleIterator.pm'
36--- lib/NibbleIterator.pm 2012-04-03 15:33:10 +0000
37+++ lib/NibbleIterator.pm 2012-05-08 18:46:21 +0000
38@@ -428,13 +428,26 @@
39 }
40 my ($cxn, $tbl, $chunk_size, $o) = @args{@required_args};
41
42+ my $where = $o->has('where') ? $o->get('where') : '';
43+
44 # About how many rows are there?
45 my ($row_est, $mysql_index) = get_row_estimate(
46 Cxn => $cxn,
47 tbl => $tbl,
48- where => $o->has('where') ? $o->get('where') : '',
49+ where => $where,
50 );
51
52+ # MySQL's chosen index is only something we should prefer
53+ # if --where is used. Else, we can chose our own index
54+ # and disregard the MySQL index from the row estimate.
55+ # If there's a --where, however, then MySQL's chosen index
56+ # is used because it tells us how MySQL plans to optimize
57+ # for the --where.
58+ # https://bugs.launchpad.net/percona-toolkit/+bug/978432
59+ if ( !$where ) {
60+ $mysql_index = undef;
61+ }
62+
63 # Can all those rows be nibbled in one chunk? If one_nibble is defined,
64 # then do as it says; else, look at the chunk size limit.
65 my $one_nibble = !defined $args{one_nibble} || $args{one_nibble}
66
67=== modified file 't/pt-table-checksum/chunk_index.t'
68--- t/pt-table-checksum/chunk_index.t 2012-02-03 18:38:20 +0000
69+++ t/pt-table-checksum/chunk_index.t 2012-05-08 18:46:21 +0000
70@@ -25,7 +25,7 @@
71 plan skip_all => 'Cannot connect to sandbox master';
72 }
73 else {
74- plan tests => 10;
75+ plan tests => 11;
76 }
77
78 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
79@@ -142,6 +142,22 @@
80 );
81
82 # #############################################################################
83+# Bug 978432: PK is ignored
84+# #############################################################################
85+$sb->load_file('master', "t/pt-table-checksum/samples/not-using-pk-bug.sql");
86+PerconaTest::wait_for_table($dbh, "test.multi_resource_apt", "apt_id=4 AND res_id=4");
87+
88+ok(
89+ no_diff(
90+ sub { pt_table_checksum::main(@args,
91+ qw(-t test.multi_resource_apt --chunk-size 2 --explain --explain))
92+ },
93+ "t/pt-table-checksum/samples/not-using-pk-bug.out",
94+ ),
95+ "Smarter chunk index selection (bug 978432)"
96+);
97+
98+# #############################################################################
99 # Done.
100 # #############################################################################
101 $sb->wipe_clean($dbh);
102
103=== added file 't/pt-table-checksum/samples/not-using-pk-bug.out'
104--- t/pt-table-checksum/samples/not-using-pk-bug.out 1970-01-01 00:00:00 +0000
105+++ t/pt-table-checksum/samples/not-using-pk-bug.out 2012-05-08 18:46:21 +0000
106@@ -0,0 +1,20 @@
107+--
108+-- test.multi_resource_apt
109+--
110+
111+REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*) AS cnt, COALESCE(LOWER(CONV(BIT_XOR(CAST(CRC32(CONCAT_WS('#', `apt_id`, `res_id`)) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `test`.`multi_resource_apt` FORCE INDEX(`PRIMARY`) WHERE ((`apt_id` > ?) OR (`apt_id` = ? AND `res_id` >= ?)) AND ((`apt_id` < ?) OR (`apt_id` = ? AND `res_id` <= ?)) /*checksum chunk*/
112+
113+REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*), '0' FROM `test`.`multi_resource_apt` FORCE INDEX(`PRIMARY`) WHERE ((`apt_id` < ?) OR (`apt_id` = ? AND `res_id` < ?)) ORDER BY `apt_id`, `res_id` /*past lower chunk*/
114+
115+REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*), '0' FROM `test`.`multi_resource_apt` FORCE INDEX(`PRIMARY`) WHERE ((`apt_id` > ?) OR (`apt_id` = ? AND `res_id` > ?)) ORDER BY `apt_id`, `res_id` /*past upper chunk*/
116+
117+SELECT /*!40001 SQL_NO_CACHE */ `apt_id`, `apt_id`, `res_id` FROM `test`.`multi_resource_apt` FORCE INDEX(`PRIMARY`) WHERE ((`apt_id` > ?) OR (`apt_id` = ? AND `res_id` >= ?)) ORDER BY `apt_id`, `res_id` LIMIT ?, 2 /*next chunk boundary*/
118+
119+1 1,1,1 2,2,1
120+2 2,2,2 3,3,1
121+3 3,3,2 3,3,3
122+4 4,4,1 4,4,2
123+5 4,4,3 4,4,4
124+6 1,1,1
125+7 4,4,4
126+
127
128=== added file 't/pt-table-checksum/samples/not-using-pk-bug.sql'
129--- t/pt-table-checksum/samples/not-using-pk-bug.sql 1970-01-01 00:00:00 +0000
130+++ t/pt-table-checksum/samples/not-using-pk-bug.sql 2012-05-08 18:46:21 +0000
131@@ -0,0 +1,20 @@
132+DROP DATABASE IF EXISTS test;
133+CREATE DATABASE test;
134+USE test;
135+CREATE TABLE `multi_resource_apt` (
136+ `apt_id` int(10) unsigned NOT NULL DEFAULT '0',
137+ `res_id` int(10) unsigned NOT NULL DEFAULT '0',
138+ PRIMARY KEY (`apt_id`,`res_id`),
139+ KEY `resid` (`res_id`)
140+) ENGINE=InnoDB;
141+INSERT INTO multi_resource_apt VALUES
142+ (1, 1),
143+ (2, 1),
144+ (2, 2),
145+ (3, 1),
146+ (3, 2),
147+ (3, 3),
148+ (4, 1),
149+ (4, 2),
150+ (4, 3),
151+ (4, 4);

Subscribers

People subscribed via source and target branches