Take the 2-minute tour ×

I have a very tiny perl script which extract one column from original table to form a new table, and generate the relation table by the way

$sqr->$conn->prepare("select id, authors from paper");
while(@row = $sqr->fetchrow_array()) {
  paper_id = $row[0];
  @author_arr = someExtractFunc($row[1]);
  for (@author_arr) {
    author_id = insertAuthor($_);
    insertAuthorPaper(author_id, paper_id); # this is the relation_table between author and paper

I have 80,000papers, about 240,000 authors, and this script runs terribly slow, can any one tell me why and give me some advice?

id authors title

id name

id author_id paper_id
share|improve this question
have you tried batch inserting? –  Karoly Horvath Mar 2 '12 at 12:44
Do you have any indexes? It's almost impossible to diagnose database problems without seeing the schema. –  mpeters Mar 2 '12 at 16:13
add comment

1 Answer

This can probably be solved entirely in MySQL by running query like

   field1, field2
share|improve this answer
the ans is not what i wanted.I want to –  lhdgriver Mar 3 '12 at 13:53
Thank you very much.But the ans is not what I wanted. I've cleared the question. –  lhdgriver Mar 3 '12 at 14:03
add comment

Your Answer


