Pacific-Design.com

    
Home Index

1. MariaDB

2. Permutation Hex

MariaDB / Permutation Hex /

#!/usr/bin/perl
#------------------------------------------------------------------------------#
use strict;
use warnings;
use BerkeleyDB;
use DBI;
use Time::HiRes qw( gettimeofday tv_interval );
$| = 1;
use vars qw( $dbh $FileHandle $file $total );

#------------------------------------------------------------------------------#
$dbh = DBI->connect('DBI:mysql:mysql_socket=/var/run/mysqld/mysqld.sock',
                    'user', 'password', {RaiseError => 1, AutoCommit => 0})
  || die "Database connection not made: $DBI::errstr";

#------------------------------------------------------------------------------#
open($FileHandle, ">>/data2/flat_file.dat");

for my $a ('0' .. '9', 'a' .. 'f')
{
    for my $b ('0' .. '9', 'a' .. 'f')
    {
        for my $c ('0' .. '9', 'a' .. 'f')
        {
            my $table = $a . $b . $c;
            &execute_sql('engine27', $table);
        }
    }
}

close($FileHandle);
#------------------------------------------------------------------------------#
sub execute_sql
{
    my ($database, $table) = @_;

    my $sql = qq/SELECT url FROM $database.part_$table;/;
    print "----------------- [ " . $sql . " ] -----------------\n";

    my $sth = $dbh->prepare($sql);
    $sth->execute();

    my $url;

    $sth->bind_col(1, \$url);
    my $t0 = [gettimeofday];
    my $c  = 0;

    while ($sth->fetch())
    {
        $total++;
        $c++;
        print $total . "=" . $url . "\n" if (($total % 5000) == 0);
        print $FileHandle $url . "\n";
    }

    my $elapsed = tv_interval($t0, [gettimeofday]);
    my $rps = int($c / $elapsed);
    print "RPS=" . $rps . " Elapsed=" . $elapsed . "\n";

    $sth->finish();
}

#------------------------------------------------------------------------------#
__END__