diff --git a/t/lib/NibbleIterator.t b/t/lib/NibbleIterator.t index bbbd260d..d97e4339 100644 --- a/t/lib/NibbleIterator.t +++ b/t/lib/NibbleIterator.t @@ -831,6 +831,26 @@ is_deeply( "Bug 995274: nibble iter works" ); + +# ############################################################################# +# pt-table-checksum doesn't use non-unique index with highest cardinality +# https://bugs.launchpad.net/percona-toolkit/+bug/1199591 +# ############################################################################# + +diag(`/tmp/12345/use < $trunk/t/lib/samples/cardinality.sql >/dev/null`); + +$ni = make_nibble_iter( + db => 'cardb', + tbl => 't', + argv => [qw(--databases cardb --chunk-size 2)], +); + +is( + $ni->{index}, + 'b', + "Use non-unique index with highest cardinality (bug 1199591)" +); + # ############################################################################# # Done. # ############################################################################# diff --git a/t/lib/samples/cardinality.sql b/t/lib/samples/cardinality.sql new file mode 100644 index 00000000..08b579e8 --- /dev/null +++ b/t/lib/samples/cardinality.sql @@ -0,0 +1,49 @@ +DROP DATABASE IF EXISTS cardb; +CREATE DATABASE cardb; +USE cardb; +CREATE TABLE t ( + high INT UNSIGNED NOT NULL, + low INT UNSIGNED NOT NULL, + INDEX a (low), + INDEX b (high), + INDEX c (low) +) ENGINE=InnoDB; +INSERT INTO t VALUES + (1, 1), + (2, 1), + (3, 1), + (4, 1), + (5, 1), + (6, 1), + (7, 1), + (8, 1), + (9, 1), + (10, 1), + (11, 1), + (12, 1), + (13, 1), + (14, 1), + (15, 1), + (16, 1), + (17, 1), + (18, 1), + (19, 1), + (20, 1), + (21, 2), + (22, 2), + (23, 2), + (24, 2), + (25, 2), + (26, 2), + (27, 2), + (28, 2), + (29, 2), + (30, 2), + (31, 2), + (32, 2), + (33, 2), + (34, 2), + (35, 2), + (36, 2), + (37, 2); +ANALYZE TABLE t;