Commit 517967de authored by unknown's avatar unknown

WL#2779 ndb_size.pl

fix some small bugs, slightly improve output, add --help


ndb/tools/ndb_size.pl:
  Provide --help and --usage.
  
  Fix some bugs related to quoting table names.
ndb/tools/ndb_size.tmpl:
  A NAME and A HREF to tables from the main list
parent 19809fab
...@@ -26,24 +26,33 @@ use HTML::Template; ...@@ -26,24 +26,33 @@ use HTML::Template;
# BUGS # BUGS
# ---- # ----
# - enum/set is 0 byte storage! Woah - efficient! # - enum/set is 0 byte storage! Woah - efficient!
# - DECIMAL is 0 byte storage. A bit too efficient.
# - some float stores come out weird (when there's a comma e.g. 'float(4,1)') # - some float stores come out weird (when there's a comma e.g. 'float(4,1)')
# - no disk data values # - no disk data values
# - computes the storage requirements of views (and probably MERGE) # - computes the storage requirements of views (and probably MERGE)
# - ignores character sets. # - ignores character sets.
my $template = HTML::Template->new(filename => 'ndb_size.tmpl', my $template = HTML::Template->new(filename => 'ndb_size.tmpl',
die_on_bad_params => 0); die_on_bad_params => 0)
or die "Could not open ndb_size.tmpl.";
my $dbh; my $dbh;
if(@ARGV < 3 || $ARGV[0] eq '--usage' || $ARGV[0] eq '--help')
{
print STDERR "Usage:\n";
print STDERR "\tndb_size.pl database hostname user password\n\n";
print STDERR "If you need to specify a port number, use host:port\n\n";
exit(1);
}
{ {
my $database= $ARGV[0]; my $database= $ARGV[0];
my $hostname= $ARGV[1]; my $hostname= $ARGV[1];
my $port= $ARGV[2]; my $user= $ARGV[2];
my $user= $ARGV[3]; my $password= $ARGV[3];
my $password= $ARGV[4]; my $dsn = "DBI:mysql:database=$database;host=$hostname";
my $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; $dbh= DBI->connect($dsn, $user, $password) or exit(1);
$dbh= DBI->connect($dsn, $user, $password);
$template->param(db => $database); $template->param(db => $database);
$template->param(dsn => $dsn); $template->param(dsn => $dsn);
} }
...@@ -68,9 +77,8 @@ foreach(@{$tables}) ...@@ -68,9 +77,8 @@ foreach(@{$tables})
{ {
my $table= @{$_}[0]; my $table= @{$_}[0];
my @columns; my @columns;
my $info= $dbh->selectall_hashref("describe ".$dbh->quote($table),"Field"); my $info= $dbh->selectall_hashref('describe `'.$table.'`',"Field");
my @count = $dbh->selectrow_array("select count(*) from " my @count = $dbh->selectrow_array('select count(*) from `'.$table.'`');
.$dbh->quote($table));
my %columnsize; # used for index calculations my %columnsize; # used for index calculations
# We now work out the DataMemory usage # We now work out the DataMemory usage
...@@ -132,7 +140,7 @@ foreach(@{$tables}) ...@@ -132,7 +140,7 @@ foreach(@{$tables})
my $fixed= 1+$size; my $fixed= 1+$size;
my @dynamic=$dbh->selectrow_array("select avg(length(" my @dynamic=$dbh->selectrow_array("select avg(length("
.$dbh->quote($name) .$dbh->quote($name)
.")) from ".$dbh->quote($table)); .")) from `".$table.'`');
$dynamic[0]=0 if !$dynamic[0]; $dynamic[0]=0 if !$dynamic[0];
@realsize= ($fixed,$fixed,ceil($dynamic[0])); @realsize= ($fixed,$fixed,ceil($dynamic[0]));
} }
...@@ -166,7 +174,7 @@ foreach(@{$tables}) ...@@ -166,7 +174,7 @@ foreach(@{$tables})
# we can still connect to pre-5.0 mysqlds. # we can still connect to pre-5.0 mysqlds.
my %indexes; my %indexes;
{ {
my $sth= $dbh->prepare("show index from "$dbh->quote($table)); my $sth= $dbh->prepare("show index from `".$table.'`');
$sth->execute; $sth->execute;
while(my $i = $sth->fetchrow_hashref) while(my $i = $sth->fetchrow_hashref)
{ {
......
...@@ -13,18 +13,18 @@ td,th { border: 1px solid black } ...@@ -13,18 +13,18 @@ td,th { border: 1px solid black }
<h1>MySQL Cluster analysis for <TMPL_VAR NAME="db" escape="html"></h1> <h1>MySQL Cluster analysis for <TMPL_VAR NAME="db" escape="html"></h1>
<p>This is an automated analysis of the <TMPL_VAR NAME="DSN" escape="html"> database for migration into <a href="http://www.mysql.com/">MySQL</a> Cluster. No warranty is made to the accuracy of the information.</p> <p>This is an automated analysis of the <TMPL_VAR NAME="DSN" escape="html"> database for migration into <a href="http://www.mysql.com/">MySQL</a> Cluster. No warranty is made to the accuracy of the information.</p>
<p>This information should be valid for MySQL 4.1</p> <p>This information should be valid for MySQL 4.1 and 5.0. Since 5.1 is not a final release yet, the numbers should be used as a guide only.</p>
<ul> <ul>
<TMPL_LOOP NAME="tables"> <TMPL_LOOP NAME="tables">
<li><TMPL_VAR NAME="table"></li> <li><a href="#<TMPL_VAR NAME="table">"><TMPL_VAR NAME="table"></a></li>
</TMPL_LOOP> </TMPL_LOOP>
</ul> </ul>
<hr/> <hr/>
<TMPL_LOOP NAME="tables"> <TMPL_LOOP NAME="tables">
<h2><TMPL_VAR NAME="table"></h2> <h2><a name="<TMPL_VAR NAME="table">"><TMPL_VAR NAME="table"></a></h2>
<table> <table>
<tr> <tr>
<th>Column</th> <th>Column</th>
......
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