File: clustered_keys.t

package info (click to toggle)
percona-toolkit 3.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 68,916 kB
  • sloc: perl: 241,287; sql: 22,868; sh: 19,746; javascript: 6,799; makefile: 353; awk: 38; python: 30; sed: 1
file content (102 lines) | stat: -rw-r--r-- 3,547 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env perl

BEGIN {
   die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
      unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
   unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};

use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More;

use PerconaTest;
use Sandbox;
require "$trunk/bin/pt-duplicate-key-checker";

my $dp  = new DSNParser(opts=>$dsn_opts);
my $sb  = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $dbh = $sb->get_dbh_for('master');

if ( !$dbh ) {
   plan skip_all => 'Cannot connect to sandbox master';
}

my $cnf    = "/tmp/12345/my.sandbox.cnf";
my $sample = "t/pt-duplicate-key-checker/samples/";
my @args   = ('-F', $cnf, qw(-h 127.1));

$sb->wipe_clean($dbh);
$sb->create_dbs($dbh, ['test']);

# #############################################################################
# Issue 295: Enhance rules for clustered keys in mk-duplicate-key-checker
# #############################################################################
$sb->load_file('master', 't/pt-duplicate-key-checker/samples/issue_295.sql', 'test');
ok(
   no_diff(
      sub { pt_duplicate_key_checker::main(@args, qw(-d issue_295)) },
      ($sandbox_version ge '5.1' ? "$sample/issue_295-51.txt"
                                 : "$sample/issue_295.txt")
   ),
   "Shorten, not remove, clustered dupes"
) or diag($test_diff);

# #############################################################################
# Error if InnoDB table has no PK or unique indexes
# https://bugs.launchpad.net/percona-toolkit/+bug/1036804
# #############################################################################
$sb->load_file('master', "t/pt-duplicate-key-checker/samples/idb-no-uniques-bug-894140.sql");

# PTDEBUG was auto-vivifying $clustered_key:
#
#    PTDEBUG && _d('clustered key:', $clustered_key->{name},
#       $clustered_key->{colnames});
#
#    if ( $clustered_key
#         && $args{clustered}
#         && $args{tbl_info}->{engine}
#         && $args{tbl_info}->{engine} =~ m/InnoDB/i )
#    {
#          push @dupes, $self->remove_clustered_duplicates($clustered_key...
#
#    sub remove_clustered_duplicates {
#       my ( $self, $ck, $keys, %args ) = @_;
#       die "I need a ck argument"   unless $ck;
#       die "I need a keys argument" unless $keys;
#       my $ck_cols = $ck->{colnames};
#       my @dupes;
#       KEY:
#       for my $i ( 0 .. @$keys - 1 ) {
#          my $key = $keys->[$i]->{colnames};
#          if ( $key =~ m/$ck_cols$/ ) {

my $output = `PTDEBUG=1 $trunk/bin/pt-duplicate-key-checker F=$cnf -d bug_1036804 2>&1`;

unlike(
   $output,
   qr/Use of uninitialized value/,
   'PTDEBUG doesn\'t auto-vivify cluster key hashref (bug 1036804)'
);

# #############################################################################
# 
# https://bugs.launchpad.net/percona-toolkit/+bug/1201443
# #############################################################################
$sb->load_file('master', "t/pt-duplicate-key-checker/samples/fk_chosen_index_bug_1201443.sql");

$output = `$trunk/bin/pt-duplicate-key-checker F=$cnf -d fk_chosen_index_bug_1201443 2>&1`;

unlike(
   $output,
   qr/Use of uninitialized value/,
   'fk_chosen_index_bug_1201443'
);

# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
done_testing;