unit
id fir_name sec_name
author
id name unit_id
author_paper
id author_id paper_id
著者を統一したい[同じ著者は名前が同じであり、そのユニットのfir_namesが同じであることを意味する]、author_paperテーブルを同じ時間。ここでPerlがmysqlを使っている、ひどく遅い、加速する方法
は私が何をすべきかです:
$conn->do('create index author_name on author (name)');
my $sqr = $conn->prepare("select name from author group by name having count(*) > 1");
$sqr->execute();
while(my @row = $sqr->fetchrow_array()) {
my $dup_name = $row[0];
$dup_name = formatHtml($dup_name);
my $sqr2 = $conn->prepare("select id, unit_id from author where name = '$dup_name'");
$sqr2->execute();
my %fir_name_hash =();
while(my @row2 = $sqr2->fetchrow_array()) {
my $author_id = $row2[0];
my $unit_id = $row2[1];
my $fir_name = getFirNameInUnit($conn, $unit_id);
if (not exists $fir_name_hash{$fir_name}) {
$fir_name_hash{$fir_name} = []; #anonymous arr reference
}
$x = $fir_name_hash{$fir_name};
push @$x, $author_id;
}
while(my ($fir_name, $author_id_arr) = each(%fir_name_hash)) {
my $count = scalar @$author_id_arr;
if ($count == 1) {next;}
my $author_id = $author_id_arr->[0];
for ($i = 1; $i < $count; $i++) {
#print "$author_id_arr->[$i] => $author_id\n";
unifyAuthorAndAuthorPaperTable($conn, $author_id, $author_id_arr->[$i]); #just delete in author table, and update in author_paper table
}
}
}
SELECT COUNT(*)の著者から。 #240,000 著者からの選択回数(distinct(name))。 #7,7000 それはとても遅いです!私は5時間走りました、それはちょうど約4,0000ダップの名前を削除しました。 あなたのアドバイスを熱望しています
空でないテーブルにインデックスを作成するには、しばらく時間がかかることがあります。 240k行は大きなテーブルではありません。 – Kamil
[perl with mysql、恐ろしく遅い、それを修正する方法](http://stackoverflow.com/questions/9533333/perl-with-mysql-terribly-slow-how-to-fix-it) – Toto