4
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
5
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
6
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
10
use warnings FATAL => 'all';
11
use English qw(-no_match_vars);
17
# See 101_slowlog_analyses.t for why we shift.
18
shift @INC; # our unshift (above)
19
shift @INC; # MaatkitTest's unshift
22
require "$trunk/bin/pt-query-digest";
24
my $dp = new DSNParser(opts=>$dsn_opts);
25
my $vp = new VersionParser();
26
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
27
my $dbh = $sb->get_dbh_for('master');
30
plan skip_all => 'Cannot connect to sandbox master';
36
my $sample = "t/pt-query-digest/samples/";
38
$dbh->do('drop database if exists food');
39
$dbh->do('create database food');
41
$dbh->do('create table trees (fruit varchar(24), unique index (fruit))');
44
my @args = ('--explain', 'h=127.1,P=12345,u=msandbox,p=msandbox,D=food', qw(--report-format=query_report --limit 10));
46
# The table has no rows so EXPLAIN will return NULL for most values.
49
sub { mk_query_digest::main(@args,
50
"$trunk/t/lib/samples/slowlogs/slow007.txt") },
51
($sandbox_version ge '5.1' ? "$sample/slow007_explain_1-51.txt"
52
: "$sample/slow007_explain_1.txt")
54
'Analysis for slow007 with --explain, no rows',
57
# Normalish output from EXPLAIN.
58
$dbh->do('insert into trees values ("apple"),("orange"),("banana")');
62
sub { mk_query_digest::main(@args,
63
"$trunk/t/lib/samples/slowlogs/slow007.txt") },
64
($sandbox_version ge '5.1' ? "$sample/slow007_explain_2-51.txt"
65
: "$sample/slow007_explain_2.txt")
67
'Analysis for slow007 with --explain',
70
# #############################################################################
71
# Issue 1141: Add "spark charts" to mk-query-digest profile
72
# #############################################################################
75
sub { mk_query_digest::main(@args,
76
"$trunk/t/lib/samples/slowlogs/slow007.txt", qw(--report-format profile)) },
77
"$sample/slow007_explain_4.txt",
79
'EXPLAIN sparkline in profile'
82
# #############################################################################
84
# #############################################################################
85
$dbh->do('drop table trees');
89
sub { mk_query_digest::main(@args,
90
'--report-format', 'query_report,profile',
91
"$trunk/t/lib/samples/slowlogs/slow007.txt") },
92
"t/pt-query-digest/samples/slow007_explain_3.txt",
93
trf => "sed 's/at [a-zA-Z\/\-]\\+ line [0-9]\\+/at line ?/'",
95
'Analysis for slow007 with --explain, failed',
99
# #############################################################################
100
# Issue 1196: mk-query-digest --explain is broken
101
# #############################################################################
102
$sb->load_file('master', "t/pt-query-digest/samples/issue_1196.sql");
106
sub { mk_query_digest::main(@args,
107
'--report-format', 'profile,query_report',
108
"$trunk/t/pt-query-digest/samples/issue_1196.log",)
110
($sandbox_version ge '5.1'
111
? "t/pt-query-digest/samples/issue_1196-output.txt"
112
: "t/pt-query-digest/samples/issue_1196-output-5.0.txt"),
114
"--explain sparkline uses event db and doesn't crash ea (issue 1196"
117
# #############################################################################
119
# #############################################################################
120
$sb->wipe_clean($dbh);