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-25 12:05:48-07:00, mtaylor@qualinost.(none) +1 -0
BUG#28683 - ndb_size.pl should support more than one database
Added the ability to run ndb_size.pl on mulitple databases and also to exclude lists of
databases and tables from analysis.
---
Added schema name information to index table calculations as well.
---
Made database an optional parameter, the exclusion of which causes all databases to be
examined.
If selecting from information_schema fails, attempt to fall back to show tables from
---
Added support for setting an optional "real_table_name" for a table to deal with unique
indexe size calcs.
---
Fixed report title for the case where we are using operating on more than one database.
storage/ndb/tools/ndb_size.pl@stripped, 2007-05-25 12:05:45-07:00, mtaylor@qualinost.(none)
+91 -24
Added the ability to run ndb_size.pl on mulitple databases and also to exclude lists
of databases and tables from analysis.
---
Added schema name information to index table calculations as well.
---
Made database an optional parameter, the exclusion of which causes all databases to be
examined.
If selecting from information_schema fails, attempt to fall back to show tables from
---
Added support for setting an optional "real_table_name" for a table to deal with
unique indexe size calcs.
---
Fixed report title for the case where we are using operating on more than one
database.
# 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-25 12:05:56 -07:00
+++ 1.9/storage/ndb/tools/ndb_size.pl 2007-05-25 12:05:56 -07:00
@@ -169,7 +169,9 @@
vdm_versions
ddm_versions ) ],
scalar => [ qw( name
- rows ) ],
+ rows
+ schema
+ real_table_name) ],
hash => [ qw( columns
indexes
indexed_columns
@@ -198,6 +200,16 @@
scalar => [ { -default=> 4 },'align'],
];
+sub table_name
+{
+ my ($self) = @_;
+ if ($self->real_table_name) {
+ return $self->real_table_name;
+ }else {
+ return $self->name;
+ }
+}
+
sub compute_row_size
{
my ($self, $releases) = @_;
@@ -391,7 +403,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 +411,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,
@@ -406,30 +420,56 @@
my $report= new MySQL::NDB::Size::Report;
-if($help || !$database)
+if($help)
{
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);
}
+
$hostname= 'localhost' unless $hostname;
my %queries; # used for loadqueries/savequeries
+my $withdb="";
+
+$excludedbs||="";
+$excludetables||="";
+
+if ($database) {
+ 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) {
+ if ($withdb) {
+ $report->database("databases: $withdb");
+ } else {
+ $report->database("database: $database");
+ }
+ $dsn = "DBI:mysql:database=$database;host=$hostname";
+ } else {
+ $dsn = "DBI:mysql:host=$hostname";
+ $report->database("host: $hostname");
+ }
$dbh= DBI->connect($dsn, $user, $password) or exit(1);
- $report->database($database);
$report->dsn($dsn);
}
else
@@ -446,7 +486,7 @@
$report->versions('4.1','5.0','5.1');
-my $tables;
+my $tables;
if($loadqueries)
{
@@ -454,7 +494,24 @@
}
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");
+ if (!$tables) {
+ print "WARNING: problem with selecing from INFORMATION SCHEMA\n";
+ if ($database) {
+ print "\t attempting to fallback to show tables from $database";
+ $tables= $dbh->selectall_arrayref("show tables from $database\n");
+ } else {
+ print "All Databases not supported in 4.1. Please specify --database=\n";
+ }
+ }
$queries{"show tables"}= $tables;
}
@@ -545,7 +602,7 @@
{
my $sql= "select avg(length(`"
.$colname
- ."`)) from `".$t->name().'`';
+ ."`)) from `".$t->schema().'`.`'.$t->table_name().'`';
my @dynamic;
if($loadqueries)
{
@@ -575,7 +632,7 @@
my $sql= "select SUM(CEILING(".
"length(`$colname`)/$blobhunk))"
- ."from `".$t->name."`";
+ ."from `".$t->schema().'`.`'.$t->table_name()."`";
my @blobsize;
if($loadqueries)
{
@@ -589,11 +646,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 +690,9 @@
$col->size($size);
$t->columns_set( $colname => $col );
}
- $report->tables_set( $t->name => $t );
+ #print "setting tables: ",$t->schema(), $t->table_name(), $t->name,
$t->real_table_name || "" , "\n";
+ # Use $t->name here instead of $t->table_name() to avoid namespace conflicts
+ $report->tables_set( $t->schema().".".$t->name() => $t );
# And now... the IndexMemory usage.
#
@@ -727,14 +787,16 @@
# Is a supporting table, add it to the lists:
my $idxname= $t->name().'_'.join('_',@{$indexes{$index}{columns}}).
"\$unique";
- $report->supporting_tables_set($idxname => 1);
- $t->supporting_tables_push($idxname);
+ $report->supporting_tables_set($t->schema().".".$idxname => 1);
+ $t->supporting_tables_push($t->schema().".".$idxname);
$t->indexed_columns_set($_ => 1)
foreach @{$indexes{$index}{columns}};
my $st= new MySQL::NDB::Size::Table(name => $idxname,
+ real_table_name => $t->table_name(),
rows => $count[0],
+ schema => $t->schema(),
row_dm_overhead =>
{ '4.1' => 12,
'5.0' => 12,
@@ -745,7 +807,10 @@
row_ddm_overhead =>
{ '5.1' => 8 },
);
-
+# FIXME - There is a bug here where if we set the table name in the created
+# table to the index name, it won't be able to select the column info out,
+# but if we set it to the table, then it will set the table into the report
+# on the same key as the parent table.
do_table($st,
\%idxcols,
{
@@ -766,9 +831,10 @@
foreach(@{$tables})
{
my $table= @{$_}[0];
+ my $schema = @{$_}[1] || $database;
my $info;
{
- my $sql= 'describe `'.$table.'`';
+ my $sql= 'describe `'.$schema.'`.`'.$table.'`';
if($loadqueries)
{
$info= $queries{$sql};
@@ -781,7 +847,7 @@
}
my @count;
{
- my $sql= 'select count(*) from `'.$table.'`';
+ my $sql= 'select count(*) from `'.$schema.'`.`'.$table.'`';
if($loadqueries)
{
@count= @{$queries{$sql}};
@@ -797,7 +863,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 +892,7 @@
}
}
my $t= new MySQL::NDB::Size::Table(name => $table,
+ schema => $schema,
rows => $count[0],
row_dm_overhead =>
{ '4.1' => 12,
@@ -1008,7 +1075,7 @@
my $self= shift;
my $r= $self->{report};
- print $self->ul("ndb_size.pl report for database ". $r->database().
+ print $self->ul("ndb_size.pl report for ". $r->database().
" (".(($r->tables_count()||0)-($r->supporting_tables_count()||0)).
" tables)");
@@ -1188,8 +1255,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 +1646,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) BUG#28683 | Monty Taylor | 25 May |