mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-12-16 02:01:41 +08:00
Merge pull request #64 from percona/pt-query-digest-and-pt-show-grants-5.7-compat
fixed 5.7 tests for pt-query-digest and pt-show-grants
This commit is contained in:
@@ -39,14 +39,21 @@ use Data::Dumper;
|
||||
# SqlModes object
|
||||
|
||||
sub new {
|
||||
my ( $class, $dbh ) = @_;
|
||||
my ( $class, $dbh, %args ) = @_;
|
||||
die "I need a database handle" unless $dbh;
|
||||
|
||||
my $global = $args{'global'} ? 'GLOBAL' : '';
|
||||
|
||||
my $self = {
|
||||
dbh => $dbh,
|
||||
global => $global,
|
||||
original_modes_string => '',
|
||||
};
|
||||
|
||||
return bless $self, $class;
|
||||
bless $self, $class;
|
||||
|
||||
$self->{original_modes_string} = $self->get_modes_string();
|
||||
return $self;
|
||||
}
|
||||
|
||||
# Sub: add
|
||||
@@ -71,7 +78,7 @@ sub add {
|
||||
|
||||
my $sql_mode_string = join ",", keys %$curr_modes;
|
||||
|
||||
$self->{dbh}->do("set sql_mode = '$sql_mode_string'") || return 0;
|
||||
$self->{dbh}->do("set $self->{global} sql_mode = '$sql_mode_string'") || return 0;
|
||||
|
||||
PTDEBUG && _d('sql_mode changed to: ', $sql_mode_string);
|
||||
return $curr_modes;
|
||||
@@ -99,7 +106,7 @@ sub del {
|
||||
|
||||
my $sql_mode_string = join ",", keys %$curr_modes;
|
||||
|
||||
$self->{dbh}->do("set sql_mode = '$sql_mode_string'") || return 0;
|
||||
$self->{dbh}->do("SET $self->{global} sql_mode = '$sql_mode_string'") || return 0;
|
||||
|
||||
PTDEBUG && _d('sql_mode changed to: ', $sql_mode_string);
|
||||
return $curr_modes || 1;
|
||||
@@ -149,6 +156,40 @@ sub get_modes {
|
||||
return \%modes;
|
||||
}
|
||||
|
||||
# Sub: get_modes_string
|
||||
# get current set of sql modes as string
|
||||
#
|
||||
# Required Arguments:
|
||||
# none
|
||||
#
|
||||
# Returns:
|
||||
# sql_modes as a string (coma separated values)
|
||||
sub get_modes_string {
|
||||
my ( $self ) = @_;
|
||||
|
||||
my (undef, $sql_mode_string) = $self->{dbh}->selectrow_array("show variables like 'sql_mode'");
|
||||
|
||||
return $sql_mode_string;
|
||||
}
|
||||
|
||||
# Sub: restore_original_modes
|
||||
# resets sql_mode to the state it was when object was created
|
||||
#
|
||||
# Required Arguments:
|
||||
# none
|
||||
#
|
||||
# Returns:
|
||||
# original sql_mode as a string
|
||||
sub restore_original_modes {
|
||||
my ( $self ) = @_;
|
||||
|
||||
$self->{dbh}->do("SET $self->{global} sql_mode = '$self->{original_modes_string}'");
|
||||
|
||||
return $self->{original_modes_string};
|
||||
}
|
||||
|
||||
|
||||
|
||||
sub _d {
|
||||
my ($package, undef, $line) = caller 0;
|
||||
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
|
||||
|
||||
Binary file not shown.
@@ -39,13 +39,13 @@ ok(
|
||||
no_diff(
|
||||
sub { pt_query_digest::main(@args,
|
||||
"$trunk/t/lib/samples/slowlogs/slow007.txt") },
|
||||
( $sandbox_version ge '5.5' ? "$sample/slow007_explain_1-55.txt"
|
||||
( $sandbox_version ge '5.7' ? "$sample/slow007_explain_1-57.txt"
|
||||
: $sandbox_version ge '5.5' ? "$sample/slow007_explain_1-55.txt"
|
||||
: $sandbox_version ge '5.1' ? "$sample/slow007_explain_1-51.txt"
|
||||
: "$sample/slow007_explain_1.txt")
|
||||
: "$sample/slow007_explain_1.txt"),
|
||||
),
|
||||
'Analysis for slow007 with --explain, no rows',
|
||||
);
|
||||
|
||||
# Normalish output from EXPLAIN.
|
||||
$dbh->do("insert into trees values ('apple'),('orange'),('banana')");
|
||||
|
||||
@@ -53,8 +53,9 @@ ok(
|
||||
no_diff(
|
||||
sub { pt_query_digest::main(@args,
|
||||
"$trunk/t/lib/samples/slowlogs/slow007.txt") },
|
||||
($sandbox_version ge '5.1' ? "$sample/slow007_explain_2-51.txt"
|
||||
: "$sample/slow007_explain_2.txt")
|
||||
( $sandbox_version ge '5.7' ? "$sample/slow007_explain_2-57.txt"
|
||||
: $sandbox_version ge '5.1' ? "$sample/slow007_explain_2-51.txt"
|
||||
: "$sample/slow007_explain_2.txt"),
|
||||
),
|
||||
'Analysis for slow007 with --explain',
|
||||
);
|
||||
@@ -98,11 +99,12 @@ ok(
|
||||
'--report-format', 'profile,query_report',
|
||||
"$trunk/t/pt-query-digest/samples/issue_1196.log",)
|
||||
},
|
||||
( $sandbox_version eq '5.6' ? "$sample/issue_1196-output-5.6.txt"
|
||||
( $sandbox_version ge '5.7' ? "$sample/issue_1196-output-5.7.txt"
|
||||
: $sandbox_version ge '5.6' ? "$sample/issue_1196-output-5.6.txt"
|
||||
: $sandbox_version ge '5.1' ? "$sample/issue_1196-output.txt"
|
||||
: "$sample/issue_1196-output-5.0.txt"),
|
||||
),
|
||||
"--explain sparkline uses event db and doesn't crash ea (issue 1196"
|
||||
"--explain sparkline uses event db and doesn't crash ea (issue 1196)"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
|
||||
@@ -13,6 +13,7 @@ use Test::More;
|
||||
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
use SqlModes;
|
||||
require "$trunk/bin/pt-query-digest";
|
||||
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
@@ -136,6 +137,14 @@ ok(
|
||||
|
||||
# Make sure that when we run with all-0 timestamps they don't show up in the
|
||||
# output because they are useless of course (issue 202).
|
||||
|
||||
# Since some sql_modes don't allow '0000-00-00' dates, to keep this test valid
|
||||
# we simply remove them for a moment and then restore.
|
||||
my $modes = new SqlModes($dbh);
|
||||
$modes->del(qw(STRICT_TRANS_TABLES STRICT_ALL_TABLES NO_ZERO_IN_DATE NO_ZERO_DATE));
|
||||
|
||||
my $currmodes = $modes->get_modes_string();
|
||||
|
||||
$dbh->do("update test.query_review set first_seen='0000-00-00 00:00:00', "
|
||||
. " last_seen='0000-00-00 00:00:00'");
|
||||
$output = run_with("slow022.txt",
|
||||
@@ -144,6 +153,8 @@ unlike($output, qr/last_seen/, 'no last_seen when 0000 timestamp');
|
||||
unlike($output, qr/first_seen/, 'no first_seen when 0000 timestamp');
|
||||
unlike($output, qr/0000-00-00 00:00:00/, 'no 0000-00-00 00:00:00 timestamp');
|
||||
|
||||
$modes->restore_original_modes();
|
||||
|
||||
# ##########################################################################
|
||||
# XXX The following tests will cause non-deterministic data, so run them
|
||||
# after anything that wants to check the contents of the --review table.
|
||||
|
||||
62
t/pt-query-digest/samples/issue_1196-output-5.7.txt
Normal file
62
t/pt-query-digest/samples/issue_1196-output-5.7.txt
Normal file
@@ -0,0 +1,62 @@
|
||||
|
||||
# Profile
|
||||
# Rank Query ID Response time Calls R/Call V/M Item
|
||||
# ==== ================== ============= ===== ====== ===== ========
|
||||
# 1 0xD4B6A5CD2F2F485C 0.2148 100.0% 1 0.2148 0.00 SELECT t
|
||||
|
||||
# Query 1: 0 QPS, 0x concurrency, ID 0xD4B6A5CD2F2F485C at byte 0 ________
|
||||
# This item is included in the report because it matches --limit.
|
||||
# Scores: V/M = 0.00
|
||||
# Time range: all events occurred at 2010-12-14 16:12:28
|
||||
# Attribute pct total min max avg 95% stddev median
|
||||
# ============ === ======= ======= ======= ======= ======= ======= =======
|
||||
# Count 100 1
|
||||
# Exec time 100 215ms 215ms 215ms 215ms 215ms 0 215ms
|
||||
# Lock time 99 162us 162us 162us 162us 162us 0 162us
|
||||
# Rows sent 100 10 10 10 10 10 0 10
|
||||
# Rows examine 100 1.96k 1.96k 1.96k 1.96k 1.96k 0 1.96k
|
||||
# Query size 100 82 82 82 82 82 0 82
|
||||
# String:
|
||||
# Databases issue_1196
|
||||
# Hosts localhost
|
||||
# Users root
|
||||
# Query_time distribution
|
||||
# 1us
|
||||
# 10us
|
||||
# 100us
|
||||
# 1ms
|
||||
# 10ms
|
||||
# 100ms ################################################################
|
||||
# 1s
|
||||
# 10s+
|
||||
# Tables
|
||||
# SHOW TABLE STATUS FROM `issue_1196` LIKE 't'\G
|
||||
# SHOW CREATE TABLE `issue_1196`.`t`\G
|
||||
# EXPLAIN /*!50100 PARTITIONS*/
|
||||
select t.a, count(*) from t join t t2 using(a) group by 1 order by 2 desc limit 10\G
|
||||
# *************************** 1. row ***************************
|
||||
# id: 1
|
||||
# select_type: SIMPLE
|
||||
# table: t
|
||||
# partitions: NULL
|
||||
# type: ALL
|
||||
# possible_keys: NULL
|
||||
# key: NULL
|
||||
# key_len: NULL
|
||||
# ref: NULL
|
||||
# rows: 14
|
||||
# filtered: 100.00
|
||||
# Extra: Using temporary; Using filesort
|
||||
# *************************** 2. row ***************************
|
||||
# id: 1
|
||||
# select_type: SIMPLE
|
||||
# table: t2
|
||||
# partitions: NULL
|
||||
# type: ALL
|
||||
# possible_keys: NULL
|
||||
# key: NULL
|
||||
# key_len: NULL
|
||||
# ref: NULL
|
||||
# rows: 14
|
||||
# filtered: 10.00
|
||||
# Extra: Using where; Using join buffer (Block Nested Loop)
|
||||
45
t/pt-query-digest/samples/slow007_explain_1-57.txt
Normal file
45
t/pt-query-digest/samples/slow007_explain_1-57.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
|
||||
# Query 1: 0 QPS, 0x concurrency, ID 0x8E306CDB7A800841 at byte 0 ________
|
||||
# This item is included in the report because it matches --limit.
|
||||
# Scores: V/M = 0.00
|
||||
# Time range: all events occurred at 2007-12-18 11:48:27
|
||||
# Attribute pct total min max avg 95% stddev median
|
||||
# ============ === ======= ======= ======= ======= ======= ======= =======
|
||||
# Count 100 1
|
||||
# Exec time 100 12us 12us 12us 12us 12us 0 12us
|
||||
# Lock time 0 0 0 0 0 0 0 0
|
||||
# Rows sent 0 0 0 0 0 0 0 0
|
||||
# Rows examine 0 0 0 0 0 0 0 0
|
||||
# Merge passes 0 0 0 0 0 0 0 0
|
||||
# Query size 100 23 23 23 23 23 0 23
|
||||
# String:
|
||||
# Databases food
|
||||
# Hosts
|
||||
# Users [SQL_SLAVE]
|
||||
# Query_time distribution
|
||||
# 1us
|
||||
# 10us ################################################################
|
||||
# 100us
|
||||
# 1ms
|
||||
# 10ms
|
||||
# 100ms
|
||||
# 1s
|
||||
# 10s+
|
||||
# Tables
|
||||
# SHOW TABLE STATUS FROM `food` LIKE 'trees'\G
|
||||
# SHOW CREATE TABLE `food`.`trees`\G
|
||||
# EXPLAIN /*!50100 PARTITIONS*/
|
||||
SELECT fruit FROM trees\G
|
||||
# *************************** 1. row ***************************
|
||||
# id: 1
|
||||
# select_type: SIMPLE
|
||||
# table: trees
|
||||
# partitions: NULL
|
||||
# type: index
|
||||
# possible_keys: NULL
|
||||
# key: fruit
|
||||
# key_len: 27
|
||||
# ref: NULL
|
||||
# rows: 1
|
||||
# filtered: 100.00
|
||||
# Extra: Using index
|
||||
45
t/pt-query-digest/samples/slow007_explain_2-57.txt
Normal file
45
t/pt-query-digest/samples/slow007_explain_2-57.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
|
||||
# Query 1: 0 QPS, 0x concurrency, ID 0x8E306CDB7A800841 at byte 0 ________
|
||||
# This item is included in the report because it matches --limit.
|
||||
# Scores: V/M = 0.00
|
||||
# Time range: all events occurred at 2007-12-18 11:48:27
|
||||
# Attribute pct total min max avg 95% stddev median
|
||||
# ============ === ======= ======= ======= ======= ======= ======= =======
|
||||
# Count 100 1
|
||||
# Exec time 100 12us 12us 12us 12us 12us 0 12us
|
||||
# Lock time 0 0 0 0 0 0 0 0
|
||||
# Rows sent 0 0 0 0 0 0 0 0
|
||||
# Rows examine 0 0 0 0 0 0 0 0
|
||||
# Merge passes 0 0 0 0 0 0 0 0
|
||||
# Query size 100 23 23 23 23 23 0 23
|
||||
# String:
|
||||
# Databases food
|
||||
# Hosts
|
||||
# Users [SQL_SLAVE]
|
||||
# Query_time distribution
|
||||
# 1us
|
||||
# 10us ################################################################
|
||||
# 100us
|
||||
# 1ms
|
||||
# 10ms
|
||||
# 100ms
|
||||
# 1s
|
||||
# 10s+
|
||||
# Tables
|
||||
# SHOW TABLE STATUS FROM `food` LIKE 'trees'\G
|
||||
# SHOW CREATE TABLE `food`.`trees`\G
|
||||
# EXPLAIN /*!50100 PARTITIONS*/
|
||||
SELECT fruit FROM trees\G
|
||||
# *************************** 1. row ***************************
|
||||
# id: 1
|
||||
# select_type: SIMPLE
|
||||
# table: trees
|
||||
# partitions: NULL
|
||||
# type: index
|
||||
# possible_keys: NULL
|
||||
# key: fruit
|
||||
# key_len: 27
|
||||
# ref: NULL
|
||||
# rows: 3
|
||||
# filtered: 100.00
|
||||
# Extra: Using index
|
||||
@@ -13,6 +13,8 @@ use Test::More;
|
||||
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
use SqlModes;
|
||||
|
||||
require "$trunk/bin/pt-show-grants";
|
||||
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
@@ -35,9 +37,14 @@ my $cnf = '/tmp/12345/my.sandbox.cnf';
|
||||
# Issue 551: mk-show-grants does not support listing all grants for a single
|
||||
# user (over multiple hosts)
|
||||
# #############################################################################
|
||||
|
||||
# to make creating users easier we remove NO_AUTO_CREATE_USER mode
|
||||
my $modes = new SqlModes($dbh, global=>1);
|
||||
$modes->del('NO_AUTO_CREATE_USER');
|
||||
diag(`/tmp/12345/use -u root -e "GRANT USAGE ON *.* TO 'bob'\@'%'"`);
|
||||
diag(`/tmp/12345/use -u root -e "GRANT USAGE ON *.* TO 'bob'\@'localhost'"`);
|
||||
diag(`/tmp/12345/use -u root -e "GRANT USAGE ON *.* TO 'bob'\@'192.168.1.1'"`);
|
||||
$modes->restore_original_modes;
|
||||
|
||||
$output = output(
|
||||
sub { pt_show_grants::main('-F', $cnf, qw(--only bob --no-header)); }
|
||||
|
||||
@@ -13,6 +13,7 @@ use Test::More;
|
||||
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
use SqlModes;
|
||||
require "$trunk/bin/pt-show-grants";
|
||||
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
@@ -90,15 +91,17 @@ like(
|
||||
qr/\d\d:\d\d:\d\d\n\z/,
|
||||
'No output when all users skipped'
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# pt-show-grant doesn't support column-level grants
|
||||
# https://bugs.launchpad.net/percona-toolkit/+bug/866075
|
||||
# #############################################################################
|
||||
$sb->load_file('master', 't/pt-show-grants/samples/column-grants.sql');
|
||||
# momentarily disable NO_AUTO_CREATE_USER
|
||||
my $modes = new SqlModes($dbh, global=>1);
|
||||
$modes->del('NO_AUTO_CREATE_USER');
|
||||
diag(`/tmp/12345/use -u root -e "GRANT SELECT(DateCreated, PckPrice, PaymentStat, SANumber) ON test.t TO 'sally'\@'%'"`);
|
||||
diag(`/tmp/12345/use -u root -e "GRANT SELECT(city_id), INSERT(city) ON sakila.city TO 'sally'\@'%'"`);
|
||||
|
||||
$modes->restore_original_modes();
|
||||
ok(
|
||||
no_diff(
|
||||
sub { pt_show_grants::main('-F', $cnf, qw(--only sally --no-header)) },
|
||||
@@ -141,6 +144,7 @@ ok(
|
||||
|
||||
diag(`/tmp/12345/use -u root -e "DROP USER 'sally'\@'%'"`);
|
||||
|
||||
DONE:
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
|
||||
@@ -13,6 +13,7 @@ use Test::More;
|
||||
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
use SqlModes;
|
||||
require "$trunk/bin/pt-show-grants";
|
||||
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
@@ -34,7 +35,13 @@ my $cnf = '/tmp/12345/my.sandbox.cnf';
|
||||
# #############################################################################
|
||||
# Issue 445: mk-show-grants --revoke crashes
|
||||
# #############################################################################
|
||||
|
||||
# allow auto create user for a moment
|
||||
my $modes = new SqlModes($dbh, global=>1);
|
||||
$modes->del('NO_AUTO_CREATE_USER');
|
||||
diag(`/tmp/12345/use -u root -e "GRANT USAGE ON *.* TO ''\@''"`);
|
||||
$modes->restore_original_modes();
|
||||
|
||||
$output = `/tmp/12345/use -e "SELECT user FROM mysql.user WHERE user = ''"`;
|
||||
like(
|
||||
$output,
|
||||
|
||||
@@ -6,7 +6,7 @@ CREATE TABLE t (
|
||||
`SOrNum` mediumint(9) unsigned NOT NULL auto_increment,
|
||||
`SPNum` mediumint(9) unsigned NOT NULL,
|
||||
`DateCreated` timestamp NOT NULL default CURRENT_TIMESTAMP,
|
||||
`DateRelease` timestamp NOT NULL default '0000-00-00 00:00:00',
|
||||
`DateRelease` timestamp NOT NULL default CURRENT_TIMESTAMP,
|
||||
`ActualReleasedDate` timestamp NULL default NULL,
|
||||
`PckPrice` decimal(10,2) NOT NULL default '0.00',
|
||||
`Status` varchar(20) NOT NULL,
|
||||
|
||||
Reference in New Issue
Block a user