mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-10-18 00:14:12 +00:00
Split --review and --history
This commit is contained in:
@@ -107,78 +107,6 @@ sub new {
|
||||
return bless $self, $class;
|
||||
}
|
||||
|
||||
# Tell QueryReview object to also prepare to save values in the review history
|
||||
# table.
|
||||
sub set_history_options {
|
||||
my ( $self, %args ) = @_;
|
||||
foreach my $arg ( qw(table tbl_struct col_pat) ) {
|
||||
die "I need a $arg argument" unless $args{$arg};
|
||||
}
|
||||
|
||||
# Pick out columns, attributes and metrics that need to be stored in the
|
||||
# table.
|
||||
my @cols;
|
||||
my @metrics;
|
||||
foreach my $col ( @{$args{tbl_struct}->{cols}} ) {
|
||||
my ( $attr, $metric ) = $col =~ m/$args{col_pat}/;
|
||||
next unless $attr && $metric;
|
||||
|
||||
# TableParser lowercases the column names so, e.g., Query_time
|
||||
# becomes query_time. We have to fix this so attribs in the event
|
||||
# match keys in $self->{history_metrics}...
|
||||
|
||||
# If the attrib name has at least one _ then it's a multi-word
|
||||
# attrib like Query_time or Lock_time, so the first letter should
|
||||
# be uppercase. Else, it's a one-word attrib like ts, checksum
|
||||
# or sample, so we leave it alone. Except Filesort which is yet
|
||||
# another exception.
|
||||
$attr = ucfirst $attr if $attr =~ m/_/;
|
||||
$attr = 'Filesort' if $attr eq 'filesort';
|
||||
|
||||
$attr =~ s/^Qc_hit/QC_Hit/; # Qc_hit is really QC_Hit
|
||||
$attr =~ s/^Innodb/InnoDB/g; # Innodb is really InnoDB
|
||||
$attr =~ s/_io_/_IO_/g; # io is really IO
|
||||
|
||||
push @cols, $col;
|
||||
push @metrics, [$attr, $metric];
|
||||
}
|
||||
|
||||
my $sql = "REPLACE INTO $args{table}("
|
||||
. join(', ',
|
||||
map { $self->{quoter}->quote($_) } ('checksum', 'sample', @cols))
|
||||
. ') VALUES (CONV(?, 16, 10), ?'
|
||||
. (@cols ? ', ' : '') # issue 1265
|
||||
. join(', ', map {
|
||||
# ts_min and ts_max might be part of the PK, in which case they must
|
||||
# not be NULL.
|
||||
$_ eq 'ts_min' || $_ eq 'ts_max'
|
||||
? "COALESCE(?, $self->{ts_default})"
|
||||
: '?'
|
||||
} @cols) . ')';
|
||||
PTDEBUG && _d($sql);
|
||||
|
||||
$self->{history_sth} = $self->{dbh}->prepare($sql);
|
||||
$self->{history_metrics} = \@metrics;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# Save review history for a class of queries. The incoming data is a bunch
|
||||
# of hashes. Each top-level key is an attribute name, and each second-level key
|
||||
# is a metric name. Look at the test for more examples.
|
||||
sub set_review_history {
|
||||
my ( $self, $id, $sample, %data ) = @_;
|
||||
# Need to transform ts->min/max into timestamps
|
||||
foreach my $thing ( qw(min max) ) {
|
||||
next unless defined $data{ts} && defined $data{ts}->{$thing};
|
||||
$data{ts}->{$thing} = parse_timestamp($data{ts}->{$thing});
|
||||
}
|
||||
$self->{history_sth}->execute(
|
||||
make_checksum($id),
|
||||
$sample,
|
||||
map { $data{$_->[0]}->{$_->[1]} } @{$self->{history_metrics}});
|
||||
}
|
||||
|
||||
# Fetch information from the database about a query that's been reviewed.
|
||||
sub get_review_info {
|
||||
my ( $self, $id ) = @_;
|
||||
|
Reference in New Issue
Block a user