Created
May 13, 2011 05:25
-
-
Save kazeburo/970015 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use DBIx::Sunny; | |
use Digest::MurmurHash qw/murmur_hash/; | |
use Text::ASCIITable; | |
use String::Random qw/random_regex/; | |
my $dbh = DBIx::Sunny->connect('dbi:mysql:test'); | |
$dbh->query(q{DROP TABLE IF EXISTS entries_int}); | |
$dbh->query(q{CREATE TABLE entries_int ( | |
id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, | |
fid INT UNSIGNED NOT NULL, | |
bid INT UNSIGNED NOT NULL, | |
filename VARCHAR(255) NOT NULL, | |
INDEX (fid, bid), | |
INDEX (bid) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin}); | |
$dbh->query(q{DROP TABLE IF EXISTS entries_char}); | |
$dbh->query(q{CREATE TABLE entries_char ( | |
id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, | |
filename VARCHAR(255) NOT NULL, | |
bid INT UNSIGNED NOT NULL, | |
UNIQUE INDEX (filename, bid), | |
INDEX (bid) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin}); | |
for ( 1..10000 ) { | |
my $filename = random_regex( sprintf "/[a-zA-Z0-9]{%d}", 32 ); | |
my $bid = int(rand(0xff)); | |
$dbh->query( | |
q{INSERT INTO entries_int (fid,bid,filename) VALUES (?,?,?)}, | |
murmur_hash($filename), | |
$bid, | |
$filename | |
); | |
$dbh->query( | |
q{INSERT INTO entries_char (filename,bid) VALUES (?,?)}, | |
$filename, | |
$bid | |
); | |
} | |
my $rows = $dbh->select_all(q{SELECT table_name,engine,row_format,table_rows,avg_row_length, | |
(data_length+index_length)/1024 as total_kb, | |
(data_length)/1024 as data_kb, | |
(index_length)/1024 as index_kb | |
from information_schema.tables | |
where table_name like 'entries%'}); | |
my @cols = qw/table_name total_kb data_kb index_kb/; | |
my $table = Text::ASCIITable->new; | |
$table->setCols(@cols); | |
for my $row ( @$rows ) { | |
$table->addRow( map{$row->{$_}} @cols ); | |
} | |
print $table; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment