mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 13:11:32 +00:00
Add forked Maatkit tools in bin/ and their tests in t/.
This commit is contained in:
95
t/pt-table-usage/basics.t
Normal file
95
t/pt-table-usage/basics.t
Normal file
@@ -0,0 +1,95 @@
|
||||
#!/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 => 6;
|
||||
|
||||
use MaatkitTest;
|
||||
shift @INC; # our unshift (above)
|
||||
shift @INC; # MaatkitTest's unshift
|
||||
|
||||
require "$trunk/bin/pt-table-usage";
|
||||
|
||||
my @args = qw();
|
||||
my $in = "$trunk/t/pt-table-usage/samples/in/";
|
||||
my $out = "t/pt-table-usage/samples/out/";
|
||||
my $output = '';
|
||||
|
||||
# ############################################################################
|
||||
# Basic queries that parse without problems.
|
||||
# ############################################################################
|
||||
ok(
|
||||
no_diff(
|
||||
sub { mk_table_usage::main(@args, "$in/slow001.txt") },
|
||||
"$out/slow001.txt",
|
||||
),
|
||||
'Analysis for slow001.txt'
|
||||
);
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
sub { mk_table_usage::main(@args, "$in/slow002.txt") },
|
||||
"$out/slow002.txt",
|
||||
),
|
||||
'Analysis for slow002.txt (issue 1237)'
|
||||
);
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
sub { mk_table_usage::main(@args, '--query',
|
||||
'DROP TABLE IF EXISTS t') },
|
||||
"$out/drop-table-if-exists.txt",
|
||||
),
|
||||
'DROP TABLE IF EXISTS'
|
||||
);
|
||||
|
||||
# ############################################################################
|
||||
# --id-attribute
|
||||
# ############################################################################
|
||||
ok(
|
||||
no_diff(
|
||||
sub { mk_table_usage::main(@args, "$in/slow003.txt",
|
||||
qw(--id-attribute ts)) },
|
||||
"$out/slow003-003.txt",
|
||||
),
|
||||
'Analysis for slow003.txt with --id-attribute'
|
||||
);
|
||||
|
||||
# ############################################################################
|
||||
# --constant-data-value
|
||||
# ############################################################################
|
||||
$output = output(
|
||||
sub { mk_table_usage::main('--query', 'INSERT INTO t VALUES (42)',
|
||||
qw(--constant-data-value <const>)) },
|
||||
);
|
||||
like(
|
||||
$output,
|
||||
qr/SELECT <const>/,
|
||||
"--constant-data-value"
|
||||
);
|
||||
|
||||
# ############################################################################
|
||||
# Queries with tables that can't be resolved.
|
||||
# ############################################################################
|
||||
|
||||
# The tables in the WHERE can't be resolved so there's no WHERE access listed.
|
||||
ok(
|
||||
no_diff(
|
||||
sub { mk_table_usage::main(@args, "$in/slow003.txt") },
|
||||
"$out/slow003-001.txt",
|
||||
),
|
||||
'Analysis for slow003.txt'
|
||||
);
|
||||
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
exit;
|
44
t/pt-table-usage/create_table_definitions.t
Normal file
44
t/pt-table-usage/create_table_definitions.t
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/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 => 1;
|
||||
|
||||
use MaatkitTest;
|
||||
shift @INC; # our unshift (above)
|
||||
shift @INC; # MaatkitTest's unshift
|
||||
|
||||
require "$trunk/bin/pt-table-usage";
|
||||
|
||||
my @args = qw();
|
||||
my $in = "$trunk/t/pt-table-usage/samples/in/";
|
||||
my $out = "t/pt-table-usage/samples/out/";
|
||||
my $output = '';
|
||||
|
||||
# ############################################################################
|
||||
# Test --create-table-definitions
|
||||
# ############################################################################
|
||||
|
||||
# Without --create-table-definitions, the tables wouldn't be db-qualified.
|
||||
ok(
|
||||
no_diff(
|
||||
sub { mk_table_usage::main(@args,
|
||||
'--query', 'select city from city where city="New York"',
|
||||
'--create-table-definitions',
|
||||
"$trunk/t/lib/samples/mysqldump-no-data/all-dbs.txt") },
|
||||
"$out/create-table-defs-001.txt",
|
||||
),
|
||||
'--create-table-definitions'
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
exit;
|
58
t/pt-table-usage/explain_extended.t
Normal file
58
t/pt-table-usage/explain_extended.t
Normal file
@@ -0,0 +1,58 @@
|
||||
#!/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 MaatkitTest;
|
||||
use Sandbox;
|
||||
require "$trunk/bin/pt-table-usage";
|
||||
|
||||
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';
|
||||
}
|
||||
else {
|
||||
plan tests => 2;
|
||||
}
|
||||
|
||||
my $output;
|
||||
my $cnf = '/tmp/12345/my.sandbox.cnf';
|
||||
my @args = ('--explain-extended', "F=$cnf");
|
||||
|
||||
my $in = "$trunk/t/pt-table-usage/samples/in/";
|
||||
my $out = "t/pt-table-usage/samples/out/";
|
||||
|
||||
$output = output(
|
||||
sub { mk_table_usage::main(@args, "$in/slow003.txt") },
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/No database/,
|
||||
"--explain-extended doesn't work without a database"
|
||||
);
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
sub { mk_table_usage::main(@args, qw(-D sakila), "$in/slow003.txt") },
|
||||
"$out/slow003-002.txt",
|
||||
),
|
||||
'EXPLAIN EXTENDED slow003.txt'
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
exit;
|
24
t/pt-table-usage/samples/in/slow001.txt
Normal file
24
t/pt-table-usage/samples/in/slow001.txt
Normal file
@@ -0,0 +1,24 @@
|
||||
# Time: 071218 11:48:27
|
||||
# Thread_id: 10 Query_id: 1
|
||||
# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
|
||||
select * from t;
|
||||
# Time: 071218 11:48:27
|
||||
# Thread_id: 10 Query_id: 2
|
||||
# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
|
||||
select * from t1, t2 as x, t3 y, z;
|
||||
# Time: 071218 11:48:27
|
||||
# Thread_id: 10 Query_id: 3
|
||||
# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
|
||||
insert into t values (1, 2, 3);
|
||||
# Time: 071218 11:48:27
|
||||
# Thread_id: 10 Query_id: 4
|
||||
# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
|
||||
delete from t where id < 1000;
|
||||
# Time: 071218 11:48:27
|
||||
# Thread_id: 10 Query_id: 5
|
||||
# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
|
||||
select * from a as t1, b as t2 where t1.id=t2.id;
|
||||
# Time: 071218 11:48:27
|
||||
# Thread_id: 10 Query_id: 6
|
||||
# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
|
||||
replace into t set foo='bar';
|
20
t/pt-table-usage/samples/in/slow002.txt
Normal file
20
t/pt-table-usage/samples/in/slow002.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
# Time: 071218 11:48:27
|
||||
# Thread_id: 10 Query_id: 1
|
||||
# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
|
||||
UPDATE t1 AS a JOIN t2 AS b USING (id) SET a.foo="bar" WHERE b.foo IS NOT NULL;
|
||||
# Time: 071218 11:48:27
|
||||
# Thread_id: 10 Query_id: 2
|
||||
# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
|
||||
UPDATE t1 AS a JOIN t2 AS b USING (id) SET a.foo="bar", b.foo="bat" WHERE a.id=1;
|
||||
# Time: 071218 11:48:27
|
||||
# Thread_id: 10 Query_id: 3
|
||||
# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
|
||||
UPDATE t1 INNER JOIN t2 USING (id) SET t1.foo="bar" WHERE t2.id=1;
|
||||
# Time: 071218 11:48:27
|
||||
# Thread_id: 10 Query_id: 4
|
||||
# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
|
||||
insert into t1 (a, b, c) select x, y, z from t2 where x is not null;
|
||||
# Time: 071218 11:48:27
|
||||
# Thread_id: 10 Query_id: 5
|
||||
# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
|
||||
insert into t (a, b, c) select a.x, a.y, b.z from a, b where a.id=b.id;
|
3
t/pt-table-usage/samples/in/slow003.txt
Normal file
3
t/pt-table-usage/samples/in/slow003.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
# Time: 110422 11:28:00
|
||||
# Query_time: 0.000300 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 1
|
||||
select country.country, city.city from city join country using (country_id) where country = 'Brazil' and city like 'A%' limit 1;
|
4
t/pt-table-usage/samples/out/create-table-defs-001.txt
Normal file
4
t/pt-table-usage/samples/out/create-table-defs-001.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
Query_id: 0x1E0BF7001F0D58BB.1
|
||||
SELECT sakila.city
|
||||
WHERE sakila.city
|
||||
|
3
t/pt-table-usage/samples/out/drop-table-if-exists.txt
Normal file
3
t/pt-table-usage/samples/out/drop-table-if-exists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
Query_id: 0xAED187CD505CBD92.1
|
||||
DROP_TABLE t
|
||||
|
31
t/pt-table-usage/samples/out/slow001.txt
Normal file
31
t/pt-table-usage/samples/out/slow001.txt
Normal file
@@ -0,0 +1,31 @@
|
||||
Query_id: 0xF28708D8F2920792.1
|
||||
SELECT t
|
||||
|
||||
Query_id: 0x09CB59D3450EF6E8.1
|
||||
SELECT t1
|
||||
SELECT t2
|
||||
SELECT t3
|
||||
SELECT z
|
||||
TLIST t1
|
||||
TLIST t2
|
||||
TLIST t3
|
||||
TLIST z
|
||||
|
||||
Query_id: 0xCF687AF9F2D5E248.1
|
||||
INSERT t
|
||||
SELECT DUAL
|
||||
|
||||
Query_id: 0xF1FBC364588DC469.1
|
||||
DELETE t
|
||||
WHERE t
|
||||
|
||||
Query_id: 0x8745D03011B0E1CE.1
|
||||
SELECT a
|
||||
SELECT b
|
||||
JOIN a
|
||||
JOIN b
|
||||
|
||||
Query_id: 0xEB871CD2B5729EA1.1
|
||||
REPLACE t
|
||||
SELECT DUAL
|
||||
|
40
t/pt-table-usage/samples/out/slow002.txt
Normal file
40
t/pt-table-usage/samples/out/slow002.txt
Normal file
@@ -0,0 +1,40 @@
|
||||
Query_id: 0x6B1671EA6890F103.1
|
||||
UPDATE t1
|
||||
SELECT DUAL
|
||||
JOIN t1
|
||||
JOIN t2
|
||||
WHERE t2
|
||||
|
||||
Query_id: 0x1CD27577D202A339.1
|
||||
UPDATE t1
|
||||
SELECT DUAL
|
||||
JOIN t1
|
||||
JOIN t2
|
||||
WHERE t1
|
||||
|
||||
Query_id: 0x1CD27577D202A339.2
|
||||
UPDATE t2
|
||||
SELECT DUAL
|
||||
JOIN t1
|
||||
JOIN t2
|
||||
WHERE t1
|
||||
|
||||
Query_id: 0xF4BEDD52BF14F91B.1
|
||||
UPDATE t1
|
||||
SELECT DUAL
|
||||
JOIN t1
|
||||
JOIN t2
|
||||
WHERE t2
|
||||
|
||||
Query_id: 0x1E62B5AB0DD828BF.1
|
||||
INSERT t1
|
||||
SELECT t2
|
||||
WHERE t2
|
||||
|
||||
Query_id: 0xE25F88EDB02EA4A3.1
|
||||
INSERT t
|
||||
SELECT a
|
||||
SELECT b
|
||||
JOIN a
|
||||
JOIN b
|
||||
|
6
t/pt-table-usage/samples/out/slow003-001.txt
Normal file
6
t/pt-table-usage/samples/out/slow003-001.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
Query_id: 0x7C6C08E1FA6D7E73.1
|
||||
SELECT country
|
||||
SELECT city
|
||||
JOIN city
|
||||
JOIN country
|
||||
|
8
t/pt-table-usage/samples/out/slow003-002.txt
Normal file
8
t/pt-table-usage/samples/out/slow003-002.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
Query_id: 0x7C6C08E1FA6D7E73.1
|
||||
SELECT sakila.country
|
||||
SELECT sakila.city
|
||||
JOIN sakila.city
|
||||
JOIN sakila.country
|
||||
WHERE sakila.city
|
||||
WHERE sakila.country
|
||||
|
6
t/pt-table-usage/samples/out/slow003-003.txt
Normal file
6
t/pt-table-usage/samples/out/slow003-003.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
Query_id: 110422 11:28:00.1
|
||||
SELECT country
|
||||
SELECT city
|
||||
JOIN city
|
||||
JOIN country
|
||||
|
Reference in New Issue
Block a user