Below is the list of changes that have just been committed into a local
5.1 repository of mtaylor. When mtaylor does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2007-05-24 14:53:12-07:00, mtaylor@qualinost.(none) +1 -0
Added the ability to run ndb_size.pl on mulitple databases and also to exclude lists of databases and tables from analysis.
storage/ndb/tools/ndb_size.pl@stripped, 2007-05-24 14:53:08-07:00, mtaylor@qualinost.(none) +53 -19
Added the ability to run ndb_size.pl on mulitple databases and also to exclude lists of databases and tables from analysis.
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: mtaylor
# Host: qualinost.(none)
# Root: /home/mtaylor/src/mysql/mysql-5.1-new-maint
--- 1.8/storage/ndb/tools/ndb_size.pl 2007-05-24 14:53:22 -07:00
+++ 1.9/storage/ndb/tools/ndb_size.pl 2007-05-24 14:53:22 -07:00
@@ -169,7 +169,8 @@
vdm_versions
ddm_versions ) ],
scalar => [ qw( name
- rows ) ],
+ rows
+ schema) ],
hash => [ qw( columns
indexes
indexed_columns
@@ -391,7 +392,7 @@
package main;
-my ($dbh,$database,$hostname,$user,$password,$help,$savequeries,$loadqueries,$debug,$format);
+my ($dbh,$database,$hostname,$user,$password,$help,$savequeries,$loadqueries,$debug,$format,$excludetables,$excludedbs);
GetOptions('database|d=s'=>\$database,
'hostname=s'=>\$hostname,
@@ -399,6 +400,8 @@
'password|p=s'=>\$password,
'savequeries|s=s'=>\$savequeries,
'loadqueries|l=s'=>\$loadqueries,
+ 'excludetables=s'=>\$excludetables,
+ 'excludedbs=s'=>\$excludedbs,
'help|usage|h!'=>\$help,
'debug'=>\$debug,
'format|f=s'=>\$format,
@@ -409,13 +412,17 @@
if($help || !$database)
{
print STDERR "Usage:\n";
- print STDERR "\tndb_size.pl --database=<db name> [--hostname=<host>]"
+ print STDERR "\tndb_size.pl --database=<db name>|ALL [--hostname=<host>]"
."[--user=<user>] [--password=<password>] [--help|-h] [--format=(html|text)] [--loadqueries=<file>] [--savequeries=<file>]\n\n";
+ print STDERR "\t--database=<db name> ALL may be specified to examine all "
+ ."databases\n";
print STDERR "\t--hostname=<host>:<port> can be used to designate a "
."specific port\n";
print STDERR "\t--hostname defaults to localhost\n";
print STDERR "\t--user and --password default to empty string\n";
print STDERR "\t--format=(html|text) Output format\n";
+ print STDERR "\t--excludetables Comma separated list of table names to skip\n";
+ print STDERR "\t--excludedbs Comma separated list of database names to skip\n";
print STDERR "\t--savequeries=<file> saves all queries to the DB into <file>\n";
print STDERR "\t--loadqueries=<file> loads query results from <file>. Doesn't connect to DB.\n";
exit(1);
@@ -425,9 +432,25 @@
my %queries; # used for loadqueries/savequeries
+my $withdb="";
+$excludedbs||="";
+$excludetables||="";
+
+if ($database ne "ALL") {
+ my @dbs = split(',',$database);
+ $database=$dbs[0];
+ $withdb = join("','",@dbs);
+ $withdb = " and t.TABLE_SCHEMA in ('$withdb') ";
+}
+
if(!$loadqueries)
{
- my $dsn = "DBI:mysql:database=$database;host=$hostname";
+ my $dsn;
+ if ($database eq "ALL") {
+ $dsn = "DBI:mysql:host=$hostname";
+ } else {
+ $dsn = "DBI:mysql:database=$database;host=$hostname";
+ }
$dbh= DBI->connect($dsn, $user, $password) or exit(1);
$report->database($database);
$report->dsn($dsn);
@@ -446,7 +469,7 @@
$report->versions('4.1','5.0','5.1');
-my $tables;
+my $tables;
if($loadqueries)
{
@@ -454,7 +477,15 @@
}
else
{
- $tables= $dbh->selectall_arrayref("show tables");
+ if ($excludedbs) {
+ $excludedbs = join("','",split(',',$excludedbs));
+ $excludedbs=" and t.TABLE_SCHEMA not in ('$excludedbs') ";
+ }
+ if ($excludetables) {
+ $excludetables = join("','",split(',',$excludetables));
+ $excludetables=" and t.TABLE_NAME not in ('$excludetables') ";
+ }
+ $tables= $dbh->selectall_arrayref("select t.TABLE_NAME,t.TABLE_SCHEMA from information_schema.TABLES t where t.TABLE_SCHEMA!='mysql' and t.TABLE_SCHEMA!='information_schema' $excludedbs $excludetables $withdb");
$queries{"show tables"}= $tables;
}
@@ -545,7 +576,7 @@
{
my $sql= "select avg(length(`"
.$colname
- ."`)) from `".$t->name().'`';
+ ."`)) from `".$t->schema().'`.`'.$t->name().'`';
my @dynamic;
if($loadqueries)
{
@@ -575,7 +606,7 @@
my $sql= "select SUM(CEILING(".
"length(`$colname`)/$blobhunk))"
- ."from `".$t->name."`";
+ ."from `".$t->schema().'`.`'.$t->name()."`";
my @blobsize;
if($loadqueries)
{
@@ -589,11 +620,12 @@
$blobsize[0]=0 if !defined($blobsize[0]);
# Is a supporting table, add it to the lists:
- $report->supporting_tables_set($t->name()."\$BLOB_$colname" => 1);
- $t->supporting_tables_push($t->name()."\$BLOB_$colname");
+ $report->supporting_tables_set($t->schema().".".$t->name()."\$BLOB_$colname" => 1);
+ $t->supporting_tables_push($t->schema().".".$t->name()."\$BLOB_$colname");
my $st= new MySQL::NDB::Size::Table(name =>
$t->name()."\$BLOB_$colname",
+ schema => $t->schema(),
rows => $blobsize[0],
row_dm_overhead =>
{ '4.1' => 12,
@@ -632,7 +664,7 @@
$col->size($size);
$t->columns_set( $colname => $col );
}
- $report->tables_set( $t->name => $t );
+ $report->tables_set( $t->schema().".".$t->name() => $t );
# And now... the IndexMemory usage.
#
@@ -725,7 +757,7 @@
$idxcols{$_} = $t->columns->{$_}
}
# Is a supporting table, add it to the lists:
- my $idxname= $t->name().'_'.join('_',@{$indexes{$index}{columns}}).
+ my $idxname= $t->schema().".".$t->name().'_'.join('_',@{$indexes{$index}{columns}}).
"\$unique";
$report->supporting_tables_set($idxname => 1);
$t->supporting_tables_push($idxname);
@@ -766,9 +798,10 @@
foreach(@{$tables})
{
my $table= @{$_}[0];
+ my $schema = @{$_}[1];
my $info;
{
- my $sql= 'describe `'.$table.'`';
+ my $sql= 'describe `'.$schema.'`.`'.$table.'`';
if($loadqueries)
{
$info= $queries{$sql};
@@ -781,7 +814,7 @@
}
my @count;
{
- my $sql= 'select count(*) from `'.$table.'`';
+ my $sql= 'select count(*) from `'.$schema.'`.`'.$table.'`';
if($loadqueries)
{
@count= @{$queries{$sql}};
@@ -797,7 +830,7 @@
{
my @show_indexes;
{
- my $sql= "show index from `".$table.'`';
+ my $sql= "show index from `".$schema.'`.`'.$table.'`';
if($loadqueries)
{
@show_indexes= @{$queries{$sql}};
@@ -826,6 +859,7 @@
}
}
my $t= new MySQL::NDB::Size::Table(name => $table,
+ schema => $schema,
rows => $count[0],
row_dm_overhead =>
{ '4.1' => 12,
@@ -1188,8 +1222,8 @@
my $st= $r->tables->{$_};
foreach(@{$st->indexes_keys()})
{
- printf $f, $st->name() if $_ eq 'PRIMARY';
- printf $f, $st->name().$_ if $_ ne 'PRIMARY';
+ printf $f, $st->schema().".".$st->name() if $_ eq 'PRIMARY';
+ printf $f, $st->schema().".".$st->name().$_ if $_ ne 'PRIMARY';
my $sti= $st->indexes->{$_};
printf $v, ($sti->ver_im_exists($_))
?$sti->ver_im->{$_}
@@ -1579,8 +1613,8 @@
foreach(@{$st->indexes_keys()})
{
my @r;
- push @r, $st->name() if $_ eq 'PRIMARY';
- push @r, $st->name().$_ if $_ ne 'PRIMARY';
+ push @r, $st->schema().".".$st->name() if $_ eq 'PRIMARY';
+ push @r, $st->schema().".".$st->name().$_ if $_ ne 'PRIMARY';
my $sti= $st->indexes->{$_};
push @r, ($sti->ver_im_exists($_))
?$sti->ver_im->{$_}
| Thread |
|---|
| • bk commit into 5.1 tree (mtaylor:1.2504) | Monty Taylor | 24 May |