mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
cef1d75249
Speed up column-completion in 'mysql' Don't use ISAM if HAVE_ISAM is not defined A lot of fixes for the embedded version. All libraries are now included in libmysqld.a Changed arguments to convert_dirname() to make it more general. Renamed files in the 'merge' directory to all use a common prefix. Don't compile both assembler and C functions on x86 BitKeeper/deleted/.del-mf_pack2.c~f07795bbcf57be7: Delete: mysys/mf_pack2.c Docs/manual.texi: Updated chapter about embedded version acinclude.m4: Fix for using BDB and InnoDB with embedded client/completion_hash.cc: Speed up memory allocation client/completion_hash.h: Speed up memory allocation client/mysql.cc: Speed up memory allocation client/mysqldump.c: Fix to use now convert_dirname client/mysqltest.c: Fixed memory allocation bugs. Added --basedir=#, --compress=#, --server-arg, --server-file. Fixes for embedded version Changed silent mode to -s instead of -q include/my_global.h: Update to use HAVE_ISAM include/my_sys.h: Cleanup of fn_format() include/mysql.h: Prepare FIELD struct for 4.1 include/mysql_embed.h: Don't use ISAM in embedded version innobase/include/srv0srv.h: Make InnoDB startup/shutdown silent in embedded version innobase/log/log0log.c: Make InnoDB startup/shutdown silent in embedded version innobase/srv/srv0srv.c: Make InnoDB startup/shutdown silent in embedded version innobase/srv/srv0start.c: Make InnoDB startup/shutdown silent in embedded version isam/isamlog.c: new convert_dirname libmysql/libmysql.c: Prepare for 4.1 libmysqld/Makefile.am: Changed to create one libmysqld.a file that includes all other libraries. libmysqld/examples/Makefile.am: Changed to use new libmysqld.a libmysqld/examples/test-run: Lot's of fixes to get new mysqltest with embedded MySQL to work. libmysqld/lib_sql.cc: Changed type of arguments for mysql_server_init() to make code more portable. libmysqld/libmysqld.c: Cleanup merge/Makefile.am: Rename to use common prefix. merge/mrg_close.c: Rename to use common prefix. merge/mrg_create.c: Rename to use common prefix. merge/mrg_def.h: Rename to use common prefix. merge/mrg_delete.c: Rename to use common prefix. merge/mrg_extra.c: Rename to use common prefix. merge/mrg_info.c: Rename to use common prefix. merge/mrg_locking.c: Rename to use common prefix. merge/mrg_open.c: Rename to use common prefix. merge/mrg_panic.c: Rename to use common prefix. merge/mrg_rrnd.c: Rename to use common prefix. merge/mrg_rsame.c: Rename to use common prefix. merge/mrg_static.c: Rename to use common prefix. merge/mrg_update.c: Rename to use common prefix. myisam/myisamlog.c: Use new convert_dirname myisammrg/Makefile.am: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_close.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_create.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_def.h: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_delete.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_extra.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_info.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_locking.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_open.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_panic.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_queue.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_rfirst.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_rkey.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_rlast.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_rnext.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_rprev.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_rrnd.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_rsame.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_static.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_update.c: Renamed mymrgdef.h -> myrg_def.h myisammrg/myrg_write.c: Renamed mymrgdef.h -> myrg_def.h mysql-test/include/master-slave.inc: Use short filenames for sockets (portability problem on Mac OS X) mysql-test/mysql-test-run.sh: cleanup mysql-test/r/auto_increment.result: Cleanup of tests for embedded version mysql-test/r/func_system.result: Cleanup of tests for embedded version mysql-test/r/isam.result: Cleanup of tests for embedded version mysql-test/r/lock.result: Cleanup of tests for embedded version mysql-test/r/show_check.result: Cleanup of tests for embedded version mysql-test/t/auto_increment.test: Cleanup of tests for embedded version mysql-test/t/backup.test: Cleanup of tests for embedded version mysql-test/t/count_distinct2-master.opt: Cleanup of tests for embedded version mysql-test/t/count_distinct2.test: Cleanup of tests for embedded version mysql-test/t/create.test: Cleanup of tests for embedded version mysql-test/t/flush.test: Cleanup of tests for embedded version mysql-test/t/func_system.test: Cleanup of tests for embedded version mysql-test/t/isam.test: Cleanup of tests for embedded version mysql-test/t/kill.test: Cleanup of tests for embedded version mysql-test/t/lock.test: Cleanup of tests for embedded version mysql-test/t/order_fill_sortbuf-master.opt: Cleanup of tests for embedded version mysql-test/t/rpl000015.test: Use short filenames for sockets (portability problem on Mac OS X) mysql-test/t/rpl000016.test: Use short filenames for sockets (portability problem on Mac OS X) mysql-test/t/rpl000017.test: Use short filenames for sockets (portability problem on Mac OS X) mysql-test/t/rpl000018.test: Use short filenames for sockets (portability problem on Mac OS X) mysql-test/t/show_check.test: Move ISAM specific tests to isam.test mysql-test/t/status.test: Cleanup of tests for embedded version mysql-test/t/tablelock.test: Cleanup mysys/Makefile.am: Removed not used mf_pack2.c mysys/charset.c: new convert_dirname mysys/default.c: new convert_dirname mysys/mf_dirname.c: Changed convert_dirname() to be more general mysys/mf_format.c: Changed bit flags to fn_format() to defines. Added handling of relative filenames BitKeeper/etc/ignore: Added libmysqld/examples/test-gdbinit scripts/mysql_explain_log to the ignore list mysys/mf_pack.c: new convert_dirname mysys/mf_tempfile.c: new convert_dirname scripts/Makefile.am: Adde mysql_explain_log scripts/mysql_config.sh: Added support of --libmysqld-libs sql/Makefile.am: Fix to use 'innodb_system_libs' sql/ha_innobase.cc: Make InnoDB startup/shutdown silent in embedded version sql/ha_isam.cc: Added handling of HAVE_ISAM sql/ha_isammrg.cc: Added handling of HAVE_ISAM sql/ha_myisam.cc: Handle relative paths; Needed to support BACKUP TABLE in embedded version sql/ha_myisammrg.cc: Rename of filenames sql/handler.cc: Added handling of HAVE_ISAM sql/item_func.cc: Fix for ecc (Intel Compiler) sql/mysql_priv.h: Added global variable 'mysql_embedded' sql/mysqld.cc: Use HAVE_ISAM sql/sql_parse.cc: Use new convert_dirname sql/sql_select.cc: Fix for ecc (Intel Compiler) sql/sql_table.cc: Added handling of relative filenames strings/Makefile.am: Don't compile both assembler and C functions on x86 strings/bchange.c: cleanup
383 lines
9.9 KiB
Bash
383 lines
9.9 KiB
Bash
#!@PERL@ -w
|
|
use strict;
|
|
use DBI;
|
|
|
|
use Getopt::Long;
|
|
$Getopt::Long::ignorecase=0;
|
|
|
|
print "explain_log provided by http://www.mobile.de\n";
|
|
print "=========== ================================\n";
|
|
|
|
my $Param={};
|
|
|
|
$Param->{host}='';
|
|
$Param->{user}='';
|
|
$Param->{password}='';
|
|
$Param->{PrintError}=0;
|
|
|
|
if (!GetOptions ('date|d:i' => \$Param->{ViewDate},
|
|
'host|h:s' => \$Param->{host},
|
|
'user|u:s' => \$Param->{user},
|
|
'password|p:s' => \$Param->{password},
|
|
'printerror|e:s' => \$Param->{PrintError},
|
|
)) {
|
|
ShowOptions();
|
|
}
|
|
else {
|
|
$Param->{UpdateCount} = 0;
|
|
$Param->{SelectCount} = 0;
|
|
$Param->{IdxUseCount} = 0;
|
|
$Param->{LineCount} = 0;
|
|
|
|
$Param->{Init} = 0;
|
|
$Param->{Field} = 0;
|
|
$Param->{Refresh} = 0;
|
|
$Param->{QueryCount} = 0;
|
|
$Param->{Statistics} =0;
|
|
|
|
$Param->{Query} = undef;
|
|
$Param->{ALL} = undef ;
|
|
$Param->{Comment} = undef ;
|
|
|
|
@{$Param->{Rows}} = (qw|possible_keys key type|);
|
|
|
|
if ($Param->{ViewDate}) {
|
|
$Param->{View} = 0;
|
|
}
|
|
else {
|
|
$Param->{View} = 1;
|
|
}
|
|
|
|
#print "Date=$Param->{ViewDate}, host=$Param->{host}, user=$Param->{user}, password=$Param->{password}\n";
|
|
|
|
$Param->{dbh}=DBI->connect("DBI:mysql:host=$Param->{host}",$Param->{user},$Param->{password},{PrintError=>0});
|
|
if (DBI::err()) {
|
|
print "Error: " . DBI::errstr() . "\n";
|
|
}
|
|
else {
|
|
$Param->{Start} = time;
|
|
while(<STDIN>) {
|
|
$Param->{LineCount} ++ ;
|
|
|
|
if ($Param->{ViewDate} ) {
|
|
if (m/^(\d{6})\s+\d{1,2}:\d\d:\d\d\s.*$/) { # get date
|
|
#print "# $1 #\n";
|
|
if ($1 == $Param->{ViewDate}) {
|
|
$Param->{View} = 1;
|
|
}
|
|
else {
|
|
$Param->{View} = 0;
|
|
}
|
|
}
|
|
}
|
|
if ($Param->{View} ) {
|
|
#print "->>>$_";
|
|
|
|
if (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Connect.+\s+on\s+(.*)$/i) { # get connection ID($2) and database($3)
|
|
#print "C-$1--$2--$3------\n";
|
|
RunQuery($Param);
|
|
if (defined $3) {
|
|
$Param->{CID}->{$2} = $3 ;
|
|
#print "DB:$Param->{CID}->{$2} .. $2 .. $3 \n";
|
|
}
|
|
}
|
|
|
|
elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Connect.+$/i) { # get connection ID($2) and database($3)
|
|
#print "\n <<<<<<<<<<<<<<<<<<----------------------------<<<<<<<<<<<<<<<< \n";
|
|
#print "Connect \n";
|
|
RunQuery($Param);
|
|
}
|
|
elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Change user .*\s+on\s+(.*)$/i) { # get connection ID($2) and database($3)
|
|
#print "C-$1--$2--$3------\n";
|
|
RunQuery($Param);
|
|
if (defined $3) {
|
|
$Param->{CID}->{$2} = $3 ;
|
|
#print "DB:$Param->{CID}->{$2} .. $2 .. $3 \n";
|
|
}
|
|
}
|
|
|
|
elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Quit\s+$/i) { # remove connection ID($2) and querystring
|
|
#print "Q-$1--$2--------\n";
|
|
RunQuery($Param);
|
|
delete $Param->{CID}->{$2} ;
|
|
}
|
|
|
|
elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Query\s+(select.+)$/i) { # get connection ID($2) and querystring
|
|
#print "S1-$1--$2--$3------\n";
|
|
RunQuery($Param);
|
|
unless ($Param->{CID}->{$2}) {
|
|
#print "Error: No Database for Handle: $2 found\n";
|
|
}
|
|
else {
|
|
$Param->{DB}=$Param->{CID}->{$2};
|
|
|
|
my $s = "$3";
|
|
$s =~ s/from\s/from $Param->{DB}./i;
|
|
$Param->{Query}="EXPLAIN $s";
|
|
|
|
#$s =~ m/from\s+(\w+[.]\w+)/i;
|
|
#$Param->{tab} =$1;
|
|
#print "-- $Param->{tab} -- $s --\n";
|
|
}
|
|
}
|
|
|
|
elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Query\s+(update.+)$/i) { # get connection ID($2) and querystring
|
|
#print "S2--$1--$2--$3------\n";
|
|
RunQuery($Param);
|
|
unless ($Param->{CID}->{$2}) {
|
|
#print "Error: No Database for Handle: $2 found\n";
|
|
}
|
|
else {
|
|
$Param->{DB}=$Param->{CID}->{$2};
|
|
|
|
my $ud = $3;
|
|
$ud =~ m/^update\s+(\w+).+(where.+)$/i;
|
|
$Param->{Query} ="EXPLAIN SELECT * FROM $1 $2";
|
|
$Param->{Query} =~ s/from\s/from $Param->{DB}./i;
|
|
|
|
#$Param->{Query} =~ m/from\s+(\w+[.]\w+)/i;
|
|
#$Param->{tab} =$1;
|
|
}
|
|
}
|
|
|
|
elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Statistics\s+(.*)$/i) { # get connection ID($2) and info?
|
|
$Param->{Statistics} ++;
|
|
#print "Statistics--$1--$2--$3------\n";
|
|
RunQuery($Param);
|
|
}
|
|
elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Query\s+(.+)$/i) { # get connection ID($2)
|
|
$Param->{QueryCount} ++;
|
|
#print "Query-NULL $3\n";
|
|
RunQuery($Param);
|
|
}
|
|
elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Refresh\s+(.+)$/i) { # get connection ID($2)
|
|
$Param->{Refresh} ++;
|
|
#print "Refresh\n";
|
|
RunQuery($Param);
|
|
}
|
|
elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Init\s+(.+)$/i) { # get connection ID($2)
|
|
$Param->{Init} ++;
|
|
#print "Init $3\n";
|
|
RunQuery($Param);
|
|
}
|
|
elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Field\s+(.+)$/i) { # get connection ID($2)
|
|
$Param->{Field} ++;
|
|
#print "Field $3\n";
|
|
RunQuery($Param);
|
|
}
|
|
|
|
elsif (m/^\s+(.+)$/ ) { # command could be some lines ...
|
|
#print "multi-lined ($1)\n";
|
|
my ($A)=$1;
|
|
chomp $A;
|
|
$Param->{Query} .= " $1";
|
|
#print "multi-lined ($1)<<$Param->{Query}>>\n";
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$Param->{dbh}->disconnect();
|
|
|
|
if (1 == 0) {
|
|
print "\nunclosed handles----------------------------------------\n";
|
|
my $count=0;
|
|
foreach (sort keys %{$Param->{CID}}) {
|
|
print "$count | $_ : $Param->{CID}->{$_} \n";
|
|
$count ++;
|
|
}
|
|
}
|
|
|
|
print "\nIndex usage ------------------------------------\n";
|
|
foreach my $t (sort keys %{$Param->{Data}}) {
|
|
print "\nTable\t$t: ---\n";
|
|
foreach my $k (sort keys %{$Param->{Data}->{$t}}) {
|
|
print " count\t$k:\n";
|
|
my %h = %{$Param->{Data}->{$t}->{$k}};
|
|
foreach (sort {$h{$a} <=> $h{$b}} keys %h) {
|
|
print " $Param->{Data}->{$t}->{$k}->{$_}\t$_\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
$Param->{AllCount}=0;
|
|
print "\nQueries causing table scans -------------------\n\n";
|
|
foreach (@{$Param->{ALL}}) {
|
|
$Param->{AllCount} ++;
|
|
print "$_\n";
|
|
}
|
|
print "Sum: $Param->{AllCount} table scans\n";
|
|
|
|
print "\nSummary ---------------------------------------\n\n";
|
|
print "Select: \t$Param->{SelectCount} queries\n";
|
|
print "Update: \t$Param->{UpdateCount} queries\n";
|
|
print "\n";
|
|
|
|
print "Init: \t$Param->{Init} times\n";
|
|
print "Field: \t$Param->{Field} times\n";
|
|
print "Refresh: \t$Param->{Refresh} times\n";
|
|
print "Query: \t$Param->{QueryCount} times\n";
|
|
print "Statistics:\t$Param->{Statistics} times\n";
|
|
print "\n";
|
|
|
|
print "Logfile: \t$Param->{LineCount} lines\n";
|
|
print "Started: \t".localtime($Param->{Start})."\n";
|
|
print "Finished: \t".localtime(time)."\n";
|
|
|
|
}
|
|
}
|
|
|
|
|
|
###########################################################################
|
|
#
|
|
#
|
|
#
|
|
sub RunQuery {
|
|
my $Param = shift ;
|
|
|
|
if (defined $Param->{Query}) {
|
|
if (defined $Param->{DB} ) {
|
|
|
|
$Param->{Query} =~ m/from\s+(\w+[.]\w+|\w+)/i;
|
|
$Param->{tab} =$1;
|
|
#print "||$Param->{tab} -- $Param->{Query}\n";
|
|
|
|
my $sth=$Param->{dbh}->prepare("USE $Param->{DB}");
|
|
if (DBI::err()) {
|
|
if ($Param->{PrintError}) {print "Error: ".DBI::errstr()."\n";}
|
|
}
|
|
else {
|
|
$sth->execute();
|
|
if (DBI::err()) {
|
|
if ($Param->{PrintError}) {print "Error: ".DBI::errstr()."\n";}
|
|
}
|
|
else {
|
|
$sth->finish();
|
|
|
|
$sth=$Param->{dbh}->prepare($Param->{Query});
|
|
if (DBI::err()) {
|
|
if ($Param->{PrintError}) {print "Error: ".DBI::errstr()."\n";}
|
|
}
|
|
else {
|
|
#print "$Param->{Query}\n";
|
|
$sth->execute();
|
|
if (DBI::err()) {
|
|
if ($Param->{PrintError}) {print "[$Param->{LineCount}]<<$Param->{Query}>>\n";}
|
|
if ($Param->{PrintError}) {print "Error: ".DBI::errstr()."\n";}
|
|
}
|
|
else {
|
|
my $row = undef;
|
|
while ($row = $sth->fetchrow_hashref()) {
|
|
$Param->{SelectCount} ++;
|
|
|
|
if (defined $row->{Comment}) {
|
|
push (@{$Param->{Comment}}, "$row->{Comment}; $_; $Param->{DB}; $Param->{Query}");
|
|
}
|
|
foreach (@{$Param->{Rows}}) {
|
|
if (defined $row->{$_}) {
|
|
#if (($_ eq 'type' ) and ($row->{$_} eq 'ALL')) {
|
|
if ($row->{type} eq 'ALL') {
|
|
push (@{$Param->{ALL}}, "$row->{$_} $_ $Param->{DB} $Param->{Query}");
|
|
#print ">> $row->{$_} $_ $Param->{DB} $Param->{Query}\n";
|
|
}
|
|
$Param->{IdxUseCount} ++;
|
|
$Param->{Data}->{$Param->{tab}}->{$_}->{$row->{$_}} ++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$sth->finish();
|
|
}
|
|
$Param->{Query} = undef ;
|
|
}
|
|
}
|
|
|
|
###########################################################################
|
|
#
|
|
#
|
|
#
|
|
sub ShowOptions {
|
|
print <<EOF;
|
|
Usage: $0 [OPTIONS] < LOGFILE
|
|
|
|
--date=YYMMDD select only entrys of date
|
|
-d=YYMMDD
|
|
--host=HOSTNAME db-host to ask
|
|
-h=HOSTNAME
|
|
--user=USERNAME db-user
|
|
-u=USERNAME
|
|
--password=PASSWORD password of db-user
|
|
-p=PASSWORD
|
|
|
|
Read logfile from STDIN an try to EXPLAIN all SELECT statements. All UPDATE statements are rewritten to an EXPLAIN SELECT statement. The results of the EXPLAIN statement are collected and counted. All results with type=ALL are collected in an separete list. Results are printed to STDOUT.
|
|
|
|
EOF
|
|
}
|
|
|
|
1;
|
|
|
|
__END__
|
|
|
|
=pod
|
|
|
|
=head1 NAME
|
|
|
|
explain_log.pl
|
|
|
|
Feed a mysqld general logfile (created with mysqld --log) back into mysql
|
|
and collect statistics about index usage with EXPLAIN.
|
|
|
|
=head1 DISCUSSION
|
|
|
|
To optimize your indices, you have to know which ones are actually
|
|
used and what kind of queries are causing table scans. Especially
|
|
if you are generating your queries dynamically and you have a huge
|
|
amount of queries going on, this isn't easy.
|
|
|
|
Use this tool to take a look at the effects of your real life queries.
|
|
Then add indices to avoid table scans and remove those which aren't used.
|
|
|
|
=head1 USAGE
|
|
|
|
explain_log.pl [--date=YYMMDD] --host=dbhost] [--user=dbuser] [--password=dbpw] < logfile
|
|
|
|
--date=YYMMDD select only entrys of date
|
|
|
|
-d=YYMMDD
|
|
|
|
--host=HOSTNAME db-host to ask
|
|
|
|
-h=HOSTNAME
|
|
|
|
--user=USERNAME db-user
|
|
|
|
-u=USERNAME
|
|
|
|
--password=PASSWORD password of db-user
|
|
|
|
-p=PASSWORD
|
|
|
|
=head1 EXAMPLE
|
|
|
|
explain_log.pl --host=localhost --user=foo --password=bar < /var/lib/mysql/mobile.log
|
|
|
|
=head1 AUTHOR
|
|
|
|
Stefan Nitz
|
|
Jan Willamowius <jan@mobile.de>, http://www.mobile.de
|
|
|
|
=head1 RECRUITING
|
|
|
|
If you are looking for a MySQL or Perl job, take a look at http://www.mobile.de
|
|
and send me an email with your resume (you must be speaking German!).
|
|
|
|
=head1 SEE ALSO
|
|
|
|
mysql documentation
|
|
|
|
=cut
|