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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
#!/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 tests => 5;
use PerconaTest;
require "$trunk/bin/pt-visual-explain";
my $p = new ExplainParser;
is_deeply(
$p->parse( load_file("t/pt-visual-explain/samples/full_scan_sakila_film.sql") ),
[ { id => 1,
select_type => 'SIMPLE',
table => 'film',
type => 'ALL',
possible_keys => undef,
key => undef,
key_len => undef,
'ref' => undef,
rows => 935,
Extra => undef,
}
],
'One line horizontal',
);
is_deeply(
$p->parse( load_file("t/pt-visual-explain/samples/actor_join_film_ref.sql") ),
[ { id => 1,
select_type => 'SIMPLE',
table => 'film',
type => 'ALL',
possible_keys => 'PRIMARY',
key => undef,
key_len => undef,
'ref' => undef,
rows => 952,
Extra => undef,
},
{ id => 1,
select_type => 'SIMPLE',
table => 'film_actor',
type => 'ref',
possible_keys => 'idx_fk_film_id',
key => 'idx_fk_film_id',
key_len => 2,
'ref' => 'sakila.film.film_id',
rows => 2,
Extra => undef,
},
],
'Simple join',
);
is_deeply(
$p->parse( load_file("t/pt-visual-explain/samples/rental_index_merge_intersect.sql") ),
[ { id => 1,
select_type => 'SIMPLE',
table => 'rental',
type => 'index_merge',
possible_keys => 'idx_fk_inventory_id,idx_fk_customer_id',
key => 'idx_fk_inventory_id,idx_fk_customer_id',
key_len => '3,2',
'ref' => undef,
rows => 1,
Extra =>
'Using intersect(idx_fk_inventory_id,idx_fk_customer_id); Using where',
}
],
'Vertical output',
);
is_deeply(
$p->parse( load_file("t/pt-visual-explain/samples/index_merge_union_intersect.sql") ),
[ { id => 1,
select_type => 'SIMPLE',
table => 't1',
type => 'index_merge',
possible_keys => 'key1,key2,key3,key4',
key => 'key1,key2,key3,key4',
key_len => '5,5,5,5',
'ref' => undef,
rows => 154,
Extra =>
'Using union(intersect(key1,key2),intersect(key3,key4)); Using where',
}
],
'Tab-separated output',
);
is_deeply(
$p->parse( load_file("t/pt-visual-explain/samples/simple_union.sql") ),
[ { id => 1,
select_type => 'PRIMARY',
table => 'actor_1',
type => 'index',
possible_keys => undef,
key => 'PRIMARY',
key_len => 2,
'ref' => undef,
rows => 200,
Extra => 'Using index',
},
{ id => 2,
select_type => 'UNION',
table => 'actor_2',
type => 'index',
possible_keys => undef,
key => 'PRIMARY',
key_len => 2,
'ref' => undef,
rows => 200,
Extra => 'Using index',
},
{ id => undef,
select_type => 'UNION RESULT',
table => '<union1,2>',
type => 'ALL',
possible_keys => undef,
key => undef,
key_len => undef,
'ref' => undef,
rows => undef,
Extra => undef,
},
],
'Tabular format with an empty cell',
);
# #############################################################################
# Done.
# #############################################################################
exit;
|