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:
parent
d0911e115e
commit
22bc19fd19
|
@ -24,7 +24,7 @@ my $ca = Simba::CA->new({
|
||||||
|
|
||||||
my $dbh = $ca->{dbh};
|
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{
|
$dbh->do(q{
|
||||||
create table versions2 (
|
create table versions2 (
|
||||||
|
@ -60,7 +60,15 @@ $dbh->do(q{
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
) 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(
|
my @version2_fields = qw(
|
||||||
file_type
|
file_type
|
||||||
|
@ -96,24 +104,31 @@ my $sth_ins_instances
|
||||||
session,
|
session,
|
||||||
version
|
version
|
||||||
)
|
)
|
||||||
values(?, ?, ?, ?, ?, ?)
|
values(?, ?, ?, ?, ?, ?, ?)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$sth_select->execute();
|
|
||||||
my %versions2;
|
my %versions2;
|
||||||
while(my $r = $sth_select->fetchrow_hashref) {
|
for (my $version_id = 0; $version_id <= $max_version_id; $version_id += $chunk_size) {
|
||||||
my $key = join($;, map((defined $_ ? $_ : ''),
|
print time - $^T, " ", $version_id, " ", scalar keys %versions2, "\n";
|
||||||
@{$r}{@version2_fields}
|
$sth_select->execute($version_id, $version_id + $chunk_size);
|
||||||
)
|
while(my $r = $sth_select->fetchrow_hashref) {
|
||||||
);
|
my $key = join($;, map((defined $_ ? $_ : ''),
|
||||||
my $version2_id;
|
@{$r}{@version2_fields}
|
||||||
if ($versions2{$key}) {
|
)
|
||||||
$version2_id = $versions2{$key};
|
);
|
||||||
} else {
|
my $version2_id;
|
||||||
$sth_ins_versions2->execute(@{$r}{@version2_fields});
|
if ($versions2{$key}) {
|
||||||
$version2_id = $sth_ins_versions2->{mysql_insertid};
|
$version2_id = $versions2{$key};
|
||||||
$versions2{$key} = $version2_id;
|
} else {
|
||||||
|
$sth_ins_versions2->execute(@{$r}{@version2_fields});
|
||||||
|
$version2_id = $sth_ins_versions2->{mysql_insertid};
|
||||||
|
$versions2{$key} = $version2_id;
|
||||||
|
}
|
||||||
|
$sth_ins_instances->execute(@{$r}{qw(id file file_id date online session)}, $version2_id);
|
||||||
}
|
}
|
||||||
$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
|
||||||
|
|
Loading…
Reference in New Issue