mirror of
https://github.com/MariaDB/server.git
synced 2025-08-15 22:37:22 +00:00
Fixed bug in INSERT DELAYED when INSERT generated an error
Docs/manual.texi: Splitted INSERT syntax to different sub-sections mysql-test/r/delayed.result: Added new test that hanged INSERT DELAYED mysql-test/t/delayed.test: Added new test that hanged INSERT DELAYED scripts/mysqldumpslow.sh: Fix for new slow query log format sql/field_conv.cc: cleanup
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
#!@PERL@
|
||||
# mysqldumpslow - parse and summarize the MySQL slow query log
|
||||
|
||||
# Original version by Tim Bunce, sometime in 2000.
|
||||
# Further changes by Tim Bunce, 8th March 2001.
|
||||
|
||||
use strict;
|
||||
use Getopt::Long;
|
||||
|
||||
@ -8,69 +11,128 @@ use Getopt::Long;
|
||||
# at, al, and ar are the corresponding averages
|
||||
|
||||
my %opt = (
|
||||
s => 'at',
|
||||
h => '*',
|
||||
s => 'at',
|
||||
h => '*',
|
||||
);
|
||||
|
||||
GetOptions(\%opt,
|
||||
'v+', # verbose
|
||||
'd+', # debug
|
||||
's=s', # what to sort by (t, at, l, al, r, ar etc)
|
||||
'a!', # don't abstract all numbers to N and strings to 'S'
|
||||
'g=s', # grep: only consider stmts that include this string
|
||||
'h=s', # hostname of db server (can be wildcard)
|
||||
'v+', # verbose
|
||||
'd+', # debug
|
||||
's=s', # what to sort by (t, at, l, al, r, ar etc)
|
||||
'r!', # reverse the sort order (largest last instead of first)
|
||||
't=i', # just show the top n queries
|
||||
'a!', # don't abstract all numbers to N and strings to 'S'
|
||||
'n=i', # abstract numbers with at least n digits within names
|
||||
'g=s', # grep: only consider stmts that include this string
|
||||
'h=s', # hostname of db server for *-slow.log filename (can be wildcard)
|
||||
'i=s', # name of server instance (if using mysql.server startup script)
|
||||
'l!', # don't subtract lock time from total time
|
||||
) or die "Bad option";
|
||||
|
||||
|
||||
unless (@ARGV) {
|
||||
my $defaults = `my_print_defaults mysqld`;
|
||||
my $basedir = ($defaults =~ m/--basedir=(.*)/)[0]
|
||||
or die "Can't determine basedir from 'my_print_defaults mysqld' output: $defaults";
|
||||
warn "basedir=$basedir\n" if $opt{v};
|
||||
|
||||
my $datadir = ($defaults =~ m/--datadir=(.*)/)[0];
|
||||
if (!$datadir or $opt{i}) {
|
||||
# determine the datadir from the instances section of /etc/my.cnf, if any
|
||||
my $instances = `my_print_defaults instances`;
|
||||
die "Can't determine datadir from 'my_print_defaults mysqld' output: $defaults"
|
||||
unless $instances;
|
||||
my @instances = ($instances =~ m/^--(\w+)-/mg);
|
||||
die "No -i 'instance_name' specified to select among known instances: @instances.\n"
|
||||
unless $opt{i};
|
||||
die "Instance '$opt{i}' is unknown (known instances: @instances)\n"
|
||||
unless grep { $_ eq $opt{i} } @instances;
|
||||
$datadir = ($instances =~ m/--$opt{i}-datadir=(.*)/)[0]
|
||||
or die "Can't determine --$opt{i}-datadir from 'my_print_defaults instances' output: $instances";
|
||||
warn "datadir=$datadir\n" if $opt{v};
|
||||
}
|
||||
|
||||
@ARGV = <$datadir/$opt{h}-slow.log>;
|
||||
die "Can't find '$datadir/$opt{h}-slow.log'\n" unless @ARGV;
|
||||
}
|
||||
|
||||
warn "\nReading mysql slow query log from @ARGV\n";
|
||||
|
||||
my @pending;
|
||||
my %stmt;
|
||||
$/ = ";\n#"; # read entire statements using paragraph mode
|
||||
while ( defined($_ = shift @pending) or defined($_ = <>) ) {
|
||||
warn "[[$_]]\n" if $opt{d}; # show raw paragraph being read
|
||||
|
||||
my $datadir = "/var/lib/mysql"; # XXX should fetch dynamically
|
||||
@ARGV = <$datadir/$opt{h}-slow.log>;
|
||||
my @chunks = split /^\/.*Version.*started with[\000-\377]*?Time.*Id.*Command.*Argument.*\n/m;
|
||||
if (@chunks > 1) {
|
||||
unshift @pending, map { length($_) ? $_ : () } @chunks;
|
||||
warn "<<".join(">>\n<<",@chunks).">>" if $opt{d};
|
||||
next;
|
||||
}
|
||||
|
||||
$/ = "\n#"; # read entire statements using paragraph mode
|
||||
while (<>) {
|
||||
print "[$_]\n" if $opt{v};
|
||||
s/^#// unless %stmt;
|
||||
s/^#? Time: \d{6}\s+\d+:\d+:\d+.*\n//;
|
||||
my ($user,$host) = s/^#? User\@Host:\s+(\S+)\s+\@\s+(\S+).*\n// ? ($1,$2) : ('','');
|
||||
|
||||
s/\s*Time: (\d+) Lock_time: (\d+) Rows_sent: (\d+).*\n//;
|
||||
my ($t, $l, $r) = ($1, $2, $3);
|
||||
s/^# Time: (\d+) Lock_time: (\d+) Rows_sent: (\d+).*\n//;
|
||||
my ($t, $l, $r) = ($1, $2, $3);
|
||||
$t -= $l unless $opt{l};
|
||||
|
||||
s/^use \w+;\n//; # not consistently added
|
||||
s/^SET timestamp=\d+;\n//;
|
||||
# remove fluff that mysqld writes to log when it (re)starts:
|
||||
s!^/.*Version.*started with:.*\n!!mg;
|
||||
s!^Tcp port: \d+ Unix socket: \S+\n!!mg;
|
||||
s!^Time.*Id.*Command.*Argument.*\n!!mg;
|
||||
|
||||
s/^[ ]*\n//mg; # delete blank lines
|
||||
s/^[ ]*/ /mg; # normalize leading whitespace
|
||||
s/\s*;\s*(#\s*)?$//; # remove traing semicolon(+newline-hash)
|
||||
s/^use \w+;\n//; # not consistently added
|
||||
s/^SET timestamp=\d+;\n//;
|
||||
|
||||
next if $opt{g} and !m/$opt{g}/i;
|
||||
s/^[ ]*\n//mg; # delete blank lines
|
||||
s/^[ ]*/ /mg; # normalize leading whitespace
|
||||
s/\s*;\s*(#\s*)?$//; # remove trailing semicolon(+newline-hash)
|
||||
|
||||
unless ($opt{a}) {
|
||||
s/\b\d+\b/N/g;
|
||||
s/\b0x[0-9A-Fa-f]+\b/N/g;
|
||||
s/'.*?'/'S'/g;
|
||||
s/".*?"/"S"/g;
|
||||
}
|
||||
next if $opt{g} and !m/$opt{g}/io;
|
||||
|
||||
$stmt{$_}->{c} += 1;
|
||||
$stmt{$_}->{t} += $t;
|
||||
$stmt{$_}->{l} += $l;
|
||||
$stmt{$_}->{r} += $r;
|
||||
unless ($opt{a}) {
|
||||
s/\b\d+\b/N/g;
|
||||
s/\b0x[0-9A-Fa-f]+\b/N/g;
|
||||
s/'.*?'/'S'/g;
|
||||
s/".*?"/"S"/g;
|
||||
# -n=8: turn log_20001231 into log_NNNNNNNN
|
||||
s/([a-z_]+)(\d{$opt{n},})/$1.('N' x length($2))/ieg if $opt{n};
|
||||
# abbreviate massive "in (...)" statements and similar
|
||||
s!(([NS],){100,})!sprintf("$2,{repeated %d times}",length($1)/2)!eg;
|
||||
}
|
||||
|
||||
warn "[$_]" if $opt{d};
|
||||
my $s = $stmt{$_} ||= { users=>{}, hosts=>{} };
|
||||
$s->{c} += 1;
|
||||
$s->{t} += $t;
|
||||
$s->{l} += $l;
|
||||
$s->{r} += $r;
|
||||
$s->{users}->{$user}++ if $user;
|
||||
$s->{hosts}->{$host}++ if $host;
|
||||
|
||||
warn "{{$_}}\n\n" if $opt{d}; # show processed statement string
|
||||
}
|
||||
|
||||
foreach (keys %stmt) {
|
||||
my $v = $stmt{$_} || die;
|
||||
my ($c, $t, $l, $r) = @{ $v }{qw(c t l r)};
|
||||
$v->{at} = $t / $c;
|
||||
$v->{al} = $l / $c;
|
||||
$v->{ar} = $r / $c;
|
||||
my $v = $stmt{$_} || die;
|
||||
my ($c, $t, $l, $r) = @{ $v }{qw(c t l r)};
|
||||
$v->{at} = $t / $c;
|
||||
$v->{al} = $l / $c;
|
||||
$v->{ar} = $r / $c;
|
||||
}
|
||||
|
||||
my @sorted = sort { $stmt{$a}->{$opt{s}} <=> $stmt{$b}->{$opt{s}} } keys %stmt;
|
||||
my @sorted = sort { $stmt{$b}->{$opt{s}} <=> $stmt{$a}->{$opt{s}} } keys %stmt;
|
||||
@sorted = @sorted[0 .. $opt{t}-1] if $opt{t};
|
||||
@sorted = reverse @sorted if $opt{r};
|
||||
|
||||
foreach (@sorted) {
|
||||
my $v = $stmt{$_} || die;
|
||||
my ($c, $t,$at, $l,$al, $r,$ar) = @{ $v }{qw(c t at l al r ar)};
|
||||
printf "Count: %d Time: %.2f (%d) Lock_time: %.2f (%d) Rows_sent: %.1f (%d) \n%s\n\n",
|
||||
$c, $at,$t, $al,$l, $ar,$r, $_;
|
||||
my $v = $stmt{$_} || die;
|
||||
my ($c, $t,$at, $l,$al, $r,$ar) = @{ $v }{qw(c t at l al r ar)};
|
||||
my @users = keys %{$v->{users}};
|
||||
my $user = (@users==1) ? $users[0] : sprintf "%dusers",scalar @users;
|
||||
my @hosts = keys %{$v->{hosts}};
|
||||
my $host = (@hosts==1) ? $hosts[0] : sprintf "%dhosts",scalar @hosts;
|
||||
printf "Count: %d Time=%.2fs (%ds) Lock=%.2fs (%ds) Rows=%.1f (%d), $user\@$host\n%s\n\n",
|
||||
$c, $at,$t, $al,$l, $ar,$r, $_;
|
||||
}
|
||||
|
Reference in New Issue
Block a user