mysql doesn't support nested commands,

so we need to read a chunk of data from versions,
insert it into versions2 and instances,
then read the next chunk ...
This commit is contained in:
hjp 2008-04-17 21:34:08 +00:00
parent d0911e115e
commit 22bc19fd19
1 changed files with 32 additions and 17 deletions

View File

@ -24,7 +24,7 @@ my $ca = Simba::CA->new({
my $dbh = $ca->{dbh};
$dbh->{mysql_use_result} = 1; # fetch row by row, not all at once
# $dbh->{mysql_use_result} = 1; # fetch row by row, not all at once
$dbh->do(q{
create table versions2 (
@ -60,7 +60,15 @@ $dbh->do(q{
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
});
my $sth_select = $dbh->prepare("select * from versions");
# mysql doesn't support nested commands,
# so we need to read a chunk of data from versions,
# insert it into versions2 and instances,
# then read the next chunk ...
my $chunk_size = 1_000_000;
my $max_version_id = $dbh->selectrow_array("select max(id) from versions");
my $sth_select = $dbh->prepare("select * from versions where id >= ? and id < ?");
my @version2_fields = qw(
file_type
@ -96,12 +104,14 @@ my $sth_ins_instances
session,
version
)
values(?, ?, ?, ?, ?, ?)
values(?, ?, ?, ?, ?, ?, ?)
}
);
$sth_select->execute();
my %versions2;
for (my $version_id = 0; $version_id <= $max_version_id; $version_id += $chunk_size) {
print time - $^T, " ", $version_id, " ", scalar keys %versions2, "\n";
$sth_select->execute($version_id, $version_id + $chunk_size);
while(my $r = $sth_select->fetchrow_hashref) {
my $key = join($;, map((defined $_ ? $_ : ''),
@{$r}{@version2_fields}
@ -117,3 +127,8 @@ while(my $r = $sth_select->fetchrow_hashref) {
}
$sth_ins_instances->execute(@{$r}{qw(id file file_id date online session)}, $version2_id);
}
}
print time - $^T, " ", $max_version_id, " ", scalar keys %versions2, "\n";
# vim: tw=132 expandtab sw=4 ts=8