Files
percona-toolkit/t/pt-index-usage/save_results.t
Sveta Smirnova 25c969542b PT-2151 fix tests for pt-query-digest (#631)
* PT-2151 - Fix tests for pt-query-digest

Put fix for PT-1908 into the proper place

* PT-2151 - Fix tests for pt-query-digest

Put fix for PT-1554 into the proper place

* PT-2151 - Fix tests for pt-query-digest

Adjusted expected results for the default test t/pt-table-checksum/basics.t, so they do not depend on number of rows in the help tables

* PT-2151 - Fix tests for pt-query-digest

Added additional check for both replicas into t/pt-online-schema-change/preserve_triggers.t to avoid deadlock when ->ok() is doing CHECKSUM

* PT-2151 - Fix tests for pt-query-digest

Added delay to t/pt-table-sync/wait.t, so it waits for the child process to start lagging

* PT-2151 - Fix tests for pt-query-digest

Updated t/pt-query-digest/samples/issue_1196-output-8.0.txt, so it reflects changes in the latest 8.0

* PT-2151 - Fix tests for pt-query-digest

Updated queries against query history table, so they don't fail after e2cf183762

* PT-2151 - Fix tests for pt-query-digest

Fixed PT-813 by comparing query text. Since order itself does not matter, it is not essential to compare by the fingerprint or use any other function that changes the query.

* PT-2151 - Fix tests for pt-query-digest

Adjusted samples files which now should have consistent order after fix for PT-813

* PT-2151 - Fix tests for pt-query-digest

Fixed typo in the SELECT query in the QueryReview package

* PT-2151 - Fix tests for pt-query-digest

Fix for PT-981

* PT-2151 - Fix tests for pt-query-digest

Updated modules for pt-index-usage and fixed tests, because checksum is calculated differently after fix for PT-1554

* PT-2151 - Fix tests for pt-query-digest

Updated modules for pt-diskstats, pt-fk-error-logger, pt-heartbeat, pt-online-schema-change, pt-slave-delay, pt-slave-find, pt-table-checksum, pt-table-sync, pt-upgrade

* PT-2151 - Fix tests for pt-query-digest

Updated lib/IndexUsage.pm, so fix for pt-index-usage is in the correct place
2023-06-23 15:48:21 +03:00

369 lines
10 KiB
Perl

#!/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;
require "$trunk/bin/pt-index-usage";
use Sandbox;
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';
}
if ( !@{ $dbh->selectall_arrayref("show databases like 'sakila'") } ) {
plan skip_all => "Sakila database is not loaded";
}
else {
plan tests => 18;
}
my $cnf = '/tmp/12345/my.sandbox.cnf';
my @args = ('-F', $cnf, '--save-results-database', 'D=mk');
my $samples = "t/pt-index-usage/samples/";
my $output;
$sb->wipe_clean($dbh);
pt_index_usage::main(@args, "$trunk/t/lib/samples/empty",
qw(--empty-save-results --create-save-results-database --no-report),
'-t', 'sakila.actor,sakila.address');
$dbh->do("use mk");
my $rows = $dbh->selectcol_arrayref("show databases");
my $ok = grep { $_ eq "mk" } @$rows;
ok(
$ok,
"--create-save-results-databse"
);
$rows = $dbh->selectcol_arrayref("show tables from `mk`");
is_deeply(
$rows,
[qw(index_alternatives index_usage indexes queries tables)],
"Create tables"
);
$rows = $dbh->selectall_arrayref("select * from mk.tables order by db, tbl");
is_deeply(
$rows,
[
[qw( sakila actor 0 )],
[qw( sakila address 0 )],
],
"Populate tables table (filtered)"
);
$rows = $dbh->selectall_arrayref("select * from mk.indexes order by db, tbl");
is_deeply(
$rows,
[
[qw(sakila actor idx_actor_last_name 0)],
[qw(sakila actor PRIMARY 0)],
[qw(sakila address idx_fk_city_id 0)],
[qw(sakila address PRIMARY 0)],
],
"Populate indexes table (filtered)"
);
$rows = $dbh->selectall_arrayref("select * from mk.queries");
is_deeply(
$rows,
[],
"No queries yet"
);
$rows = $dbh->selectall_arrayref("select * from mk.index_usage");
is_deeply(
$rows,
[],
"No index usage counts yet"
);
$rows = $dbh->selectall_arrayref("select * from mk.index_alternatives");
is_deeply(
$rows,
[],
"No index alternatives yet"
);
# Now for the real test.
pt_index_usage::main(@args, "$trunk/t/pt-index-usage/samples/slow007.txt",
qw(--empty-save-results --no-report), '-t', 'sakila.actor,sakila.address');
$rows = $dbh->selectall_arrayref("select * from mk.tables order by db, tbl");
is_deeply(
$rows,
[
[qw( sakila actor 4 )],
[qw( sakila address 0 )],
],
"Table access counts"
);
$rows = $dbh->selectall_arrayref("select * from mk.indexes order by db, tbl");
# EXPLAIN results differ a little between 5.0 and 5.1, and sometimes 5.1 acts
# like 5.0. So here we detect which verison MySQL is acting like and future
# tests will select between 2 possibilities based on exp_plan. Note: both
# possibilities are correct; they're variants of the same result.
my $res;
my $exp_plan;
if ( $rows->[0]->[3] == 1 ) {
# Usually v5.1 and newer
$res = [
[qw(sakila actor idx_actor_last_name 1)],
[qw(sakila actor PRIMARY 3)],
[qw(sakila address idx_fk_city_id 0)],
[qw(sakila address PRIMARY 0)],
];
$exp_plan = '5.1'; # acting like 5.1
}
else {
# Usually v5.0 and older, but somtimes 5.1.
$res = [
[qw(sakila actor idx_actor_last_name 2)],
[qw(sakila actor PRIMARY 2)],
[qw(sakila address idx_fk_city_id 0)],
[qw(sakila address PRIMARY 0)],
];
$exp_plan = '5.0'; # acting like 5.0
}
is_deeply(
$rows,
$res,
"Index usage counts"
);
$rows = $dbh->selectall_arrayref("select * from mk.queries order by query_id");
is_deeply(
$rows,
[
[ "3608BDE3153F5A7544B298738912D1D3",
"select * from sakila.actor where last_name like ?",
"select * from sakila.actor where last_name like 'A%'",
],
[ "6305C691826EDFA28F6B31B3A67D952C",
"select * from sakila.actor where last_name like ? order by actor_id",
"select * from sakila.actor where last_name like 'A%' order by actor_id",
],
[ "CAF7BE5C0CBA7D07972773B5DA7295FA",
"select * from sakila.actor where actor_id>?",
"select * from sakila.actor where actor_id>10",
],
],
"Queries added"
);
$rows = $dbh->selectall_arrayref("select query_id, db, tbl, idx, sample, cnt from index_usage iu left join queries q using (query_id) order by db, tbl, idx");
$res = $exp_plan eq '5.1' ?
# v5.1 and newer
[
[
"3608BDE3153F5A7544B298738912D1D3",
qw(sakila actor idx_actor_last_name),
"select * from sakila.actor where last_name like 'A%'",
1,
],
[
"6305C691826EDFA28F6B31B3A67D952C",
qw(sakila actor PRIMARY),
"select * from sakila.actor where actor_id>10",
2,
],
[
"CAF7BE5C0CBA7D07972773B5DA7295FA",
qw(sakila actor PRIMARY),
"select * from sakila.actor where last_name like 'A%' order by actor_id",
1,
],
]
:
# v5.0 and older
[
[
"3608BDE3153F5A7544B298738912D1D3",
qw(sakila actor idx_actor_last_name),
"select * from sakila.actor where last_name like 'A%'",
1,
],
[
"6305C691826EDFA28F6B31B3A67D952C",
qw(sakila actor idx_actor_last_name),
"select * from sakila.actor where last_name like 'A%' order by actor_id",
1,
],
[
"CAF7BE5C0CBA7D07972773B5DA7295FA",
qw(sakila actor PRIMARY),
"select * from sakila.actor where actor_id>10",
2,
],
];
is_deeply(
$rows,
$res,
"Index usage",
);
$rows = $dbh->selectall_arrayref("select db,tbl,idx,alt_idx,sample from index_alternatives a left join queries q using (query_id)");
$res = $exp_plan eq '5.1' ?
[[qw(sakila actor PRIMARY idx_actor_last_name),
"select * from sakila.actor where last_name like 'A%' order by actor_id"]]
: [];
is_deeply(
$rows,
$res,
"Index alternatives"
);
# #############################################################################
# Run again to check that cnt vals are properly updated.
# #############################################################################
pt_index_usage::main(@args, "$trunk/t/pt-index-usage/samples/slow007.txt",
qw(--no-report), '-t', 'sakila.actor,sakila.address');
$rows = $dbh->selectall_arrayref("select * from mk.tables order by db, tbl");
is_deeply(
$rows,
[
[qw( sakila actor 8 )],
[qw( sakila address 0 )],
],
"Updated table access counts"
);
# EXPLAIN results differ a little between 5.0 and 5.1. 5.1 is smarter.
$res = $exp_plan eq '5.1' ?
# v5.1 and newer
[
[qw(sakila actor idx_actor_last_name 2)],
[qw(sakila actor PRIMARY 6)],
[qw(sakila address idx_fk_city_id 0)],
[qw(sakila address PRIMARY 0)],
]
: # v5.0 and older
[
[qw(sakila actor idx_actor_last_name 4)],
[qw(sakila actor PRIMARY 4)],
[qw(sakila address idx_fk_city_id 0)],
[qw(sakila address PRIMARY 0)],
];
$rows = $dbh->selectall_arrayref("select * from mk.indexes order by db, tbl");
is_deeply(
$rows,
$res,
"Updated index usage counts"
);
$rows = $dbh->selectall_arrayref("select * from mk.queries order by query_id");
is_deeply(
$rows,
[
[ "3608BDE3153F5A7544B298738912D1D3",
"select * from sakila.actor where last_name like ?",
"select * from sakila.actor where last_name like 'A%'",
],
[ "6305C691826EDFA28F6B31B3A67D952C",
"select * from sakila.actor where last_name like ? order by actor_id",
"select * from sakila.actor where last_name like 'A%' order by actor_id",
],
[
"CAF7BE5C0CBA7D07972773B5DA7295FA",
"select * from sakila.actor where actor_id>?",
"select * from sakila.actor where actor_id>10",
],
],
"Same queries added"
);
$rows = $dbh->selectall_arrayref("select query_id, db, tbl, idx, sample, cnt from index_usage iu left join queries q using (query_id) order by db, tbl, idx");
$res = $exp_plan eq '5.1' ?
# v5.1 and newer
[
[
"3608BDE3153F5A7544B298738912D1D3",
qw(sakila actor idx_actor_last_name),
"select * from sakila.actor where last_name like 'A%'",
2,
],
[
"6305C691826EDFA28F6B31B3A67D952C",
qw(sakila actor PRIMARY),
"select * from sakila.actor where actor_id>10",
4,
],
[
"CAF7BE5C0CBA7D07972773B5DA7295FA",
qw(sakila actor PRIMARY),
"select * from sakila.actor where last_name like 'A%' order by actor_id",
2,
],
]
:
# v5.0 and older
[
[
"3608BDE3153F5A7544B298738912D1D3",
qw(sakila actor idx_actor_last_name),
"select * from sakila.actor where last_name like 'A%'",
2,
],
[
"6305C691826EDFA28F6B31B3A67D952C",
qw(sakila actor idx_actor_last_name),
"select * from sakila.actor where last_name like 'A%' order by actor_id",
2,
],
[
"CAF7BE5C0CBA7D07972773B5DA7295FA",
qw(sakila actor PRIMARY),
"select * from sakila.actor where actor_id>10",
4,
],
];
is_deeply(
$rows,
$res,
"Same index usage",
);
$rows = $dbh->selectall_arrayref("select db,tbl,idx,alt_idx,sample from index_alternatives a left join queries q using (query_id)");
$res = $exp_plan eq '5.1' ?
[[qw(sakila actor PRIMARY idx_actor_last_name),
"select * from sakila.actor where last_name like 'A%' order by actor_id"]]
: [];
is_deeply(
$rows,
$res,
"Same index alternatives"
);
# #############################################################################
# Issue 1184: Make mk-index-usage create views for canned queries
# #############################################################################
SKIP: {
skip "MySQL sandbox version < 5.0", 1 unless $sandbox_version ge '5.0';
}
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
exit;