Commit cc5f13a1 authored by unknown's avatar unknown

Merge baker@bk-internal.mysql.com:/home/bk/mysql-5.1-new

into  zim.(none):/home/brian/mysql/dep-5.1
parents c305632e b0023a6f
SHOW CONTRIBUTORS;
Name Location Comment
Ronald Bradford Brisbane, Australia EFF contribution for UC2006 Auction
Sheeri Kritzer Boston, Mass. USA EFF contribution for UC2006 Auction
Mark Shuttleworth London, UK. EFF contribution for UC2006 Auction
......@@ -30,7 +30,6 @@ bin_SCRIPTS = @server_scripts@ \
mysql_find_rows \
mysqlhotcopy \
mysqldumpslow \
mysql_explain_log \
mysqld_multi \
mysql_create_system_tables
......@@ -55,7 +54,6 @@ EXTRA_SCRIPTS = make_binary_distribution.sh \
mysql_find_rows.sh \
mysqlhotcopy.sh \
mysqldumpslow.sh \
mysql_explain_log.sh \
mysqld_multi.sh \
mysqld_safe.sh \
mysql_create_system_tables.sh
......@@ -83,7 +81,6 @@ CLEANFILES = @server_scripts@ \
mysql_find_rows \
mysqlhotcopy \
mysqldumpslow \
mysql_explain_log \
mysql_tableinfo \
mysqld_multi \
make_win_src_distribution \
......
......@@ -148,7 +148,7 @@ BIN_FILES="extra/comp_err$BS extra/replace$BS extra/perror$BS \
if [ $BASE_SYSTEM = "netware" ] ; then
BIN_FILES="$BIN_FILES \
netware/mysqld_safe$BS netware/mysql_install_db$BS \
netware/init_db.sql netware/test_db.sql netware/mysql_explain_log$BS \
netware/init_db.sql netware/test_db.sql$BS \
netware/mysqlhotcopy$BS netware/libmysql$BS netware/init_secure_db.sql \
";
# For all other platforms:
......
#!@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;
$Param->{socket}='';
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},
'socket|s:s' => \$Param->{socket},
)) {
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->{socket}?";mysql_socket=$Param->{socket}":""),$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}}, "$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
--socket=SOCKET mysqld socket file to connect
-s=SOCKET
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] [--socket=/path/to/socket] < 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
--socket=SOCKET change path to the socket
-s=SOCKET
=head1 EXAMPLE
explain_log.pl --host=localhost --user=foo --password=bar < /var/lib/mysql/mobile.log
=head1 AUTHORS
Stefan Nitz
Jan Willamowius <jan@mobile.de>, http://www.mobile.de
Dennis Haney <davh@davh.dk> (Added socket support)
=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
/* Copyright (C) 2005 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* Structure of the name list */
struct show_table_contributors_st {
const char *name;
const char *location;
const char *comment;
};
/*
Output from "SHOW CONTRIBUTORS"
Get permission before editing.
IMPORTANT: Names should be left in historical order.
Names should be encoded using UTF-8.
*/
struct show_table_contributors_st show_table_contributors[]= {
{"Ronald Bradford", "Brisbane, Australia", "EFF contribution for UC2006 Auction"},
{"Sheeri Kritzer", "Boston, Mass. USA", "EFF contribution for UC2006 Auction"},
{"Mark Shuttleworth", "London, UK.", "EFF contribution for UC2006 Auction"},
{NULL, NULL, NULL}
};
......@@ -133,6 +133,7 @@ static SYMBOL symbols[] = {
{ "CONSTRAINT", SYM(CONSTRAINT)},
{ "CONTAINS", SYM(CONTAINS_SYM)},
{ "CONTINUE", SYM(CONTINUE_SYM)},
{ "CONTRIBUTORS", SYM(CONTRIBUTORS_SYM)},
{ "CONVERT", SYM(CONVERT_SYM)},
{ "CREATE", SYM(CREATE)},
{ "CROSS", SYM(CROSS)},
......
......@@ -999,6 +999,7 @@ int mysql_find_files(THD *thd,List<char> *files, const char *db,
const char *path, const char *wild, bool dir);
bool mysqld_show_storage_engines(THD *thd);
bool mysqld_show_authors(THD *thd);
bool mysqld_show_contributors(THD *thd);
bool mysqld_show_privileges(THD *thd);
bool mysqld_show_column_types(THD *thd);
bool mysqld_help (THD *thd, const char *text);
......
......@@ -202,6 +202,7 @@ sp_get_flags_for_command(LEX *lex)
case SQLCOM_SHOW_PROC_CODE:
case SQLCOM_SHOW_FUNC_CODE:
case SQLCOM_SHOW_AUTHORS:
case SQLCOM_SHOW_CONTRIBUTORS:
case SQLCOM_REPAIR:
case SQLCOM_BACKUP_TABLE:
case SQLCOM_RESTORE_TABLE:
......
......@@ -110,6 +110,7 @@ enum enum_sql_command {
SQLCOM_INSTALL_PLUGIN, SQLCOM_UNINSTALL_PLUGIN,
SQLCOM_SHOW_AUTHORS, SQLCOM_BINLOG_BASE64_EVENT,
SQLCOM_SHOW_PLUGINS,
SQLCOM_SHOW_CONTRIBUTORS,
SQLCOM_CREATE_EVENT, SQLCOM_ALTER_EVENT, SQLCOM_DROP_EVENT,
SQLCOM_SHOW_CREATE_EVENT, SQLCOM_SHOW_EVENTS,
SQLCOM_SHOW_SCHEDULER_STATUS,
......
......@@ -3531,6 +3531,9 @@ mysql_execute_command(THD *thd)
case SQLCOM_SHOW_AUTHORS:
res= mysqld_show_authors(thd);
break;
case SQLCOM_SHOW_CONTRIBUTORS:
res= mysqld_show_contributors(thd);
break;
case SQLCOM_SHOW_PRIVILEGES:
res= mysqld_show_privileges(thd);
break;
......
......@@ -25,6 +25,7 @@
#include "sp_head.h"
#include "sql_trigger.h"
#include "authors.h"
#include "contributors.h"
#include "event.h"
#include <my_dir.h>
......@@ -229,6 +230,41 @@ bool mysqld_show_authors(THD *thd)
DBUG_RETURN(FALSE);
}
/***************************************************************************
** List all Contributors.
** Please get permission before updating
***************************************************************************/
bool mysqld_show_contributors(THD *thd)
{
List<Item> field_list;
Protocol *protocol= thd->protocol;
DBUG_ENTER("mysqld_show_contributors");
field_list.push_back(new Item_empty_string("Name",40));
field_list.push_back(new Item_empty_string("Location",40));
field_list.push_back(new Item_empty_string("Comment",80));
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
DBUG_RETURN(TRUE);
show_table_contributors_st *contributors;
for (contributors= show_table_contributors; contributors->name; contributors++)
{
protocol->prepare_for_resend();
protocol->store(contributors->name, system_charset_info);
protocol->store(contributors->location, system_charset_info);
protocol->store(contributors->comment, system_charset_info);
if (protocol->write())
DBUG_RETURN(TRUE);
}
send_eof(thd);
DBUG_RETURN(FALSE);
}
/***************************************************************************
List all privileges supported
***************************************************************************/
......
......@@ -204,6 +204,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token CONSTRAINT
%token CONTAINS_SYM
%token CONTINUE_SYM
%token CONTRIBUTORS_SYM
%token CONVERT_SYM
%token CONVERT_TZ_SYM
%token COUNT_SYM
......@@ -8194,6 +8195,11 @@ show_param:
LEX *lex=Lex;
lex->sql_command= SQLCOM_SHOW_AUTHORS;
}
| CONTRIBUTORS_SYM
{
LEX *lex=Lex;
lex->sql_command= SQLCOM_SHOW_CONTRIBUTORS;
}
| PRIVILEGES
{
LEX *lex=Lex;
......
......@@ -554,7 +554,6 @@ fi
%attr(755, root, root) %{_bindir}/myisampack
%attr(755, root, root) %{_bindir}/mysql_convert_table_format
%attr(755, root, root) %{_bindir}/mysql_create_system_tables
%attr(755, root, root) %{_bindir}/mysql_explain_log
%attr(755, root, root) %{_bindir}/mysql_fix_extensions
%attr(755, root, root) %{_bindir}/mysql_fix_privilege_tables
%attr(755, root, root) %{_bindir}/mysql_install_db
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment