【问题标题】:perl with mysql, terribly slow, how to fix itperl 与 mysql,非常慢,如何解决它
【发布时间】:2012-03-20 23:00:06
【问题描述】:

我有一个非常小的 perl 脚本,它从原始表中提取一列以形成一个新表,并顺便生成关系表

$sqr->$conn->prepare("select id, authors from paper");
$sqr->execute();
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
  }
}

我有 80,000 篇论文,大约 240,000 位作者,而这个脚本运行速度非常慢,谁能告诉我原因并给我一些建议?

paper
id authors title

author
id name

author_paper
id author_id paper_id

【问题讨论】:

  • 你试过批量插入吗?
  • 你有索引吗?几乎不可能在不查看架构的情况下诊断数据库问题。

标签: mysql perl performance


【解决方案1】:

这可能完全可以在 MySQL 中通过运行查询来解决

INSERT INTO
  newTable(field1,field2,...)
SELECT 
   field1, field2
FROM
   oldTable;

【讨论】:

  • 答案不是我想要的。我想要
  • 非常感谢。但答案不是我想要的。我已经解决了这个问题。
猜你喜欢
  • 2012-03-21
  • 1970-01-01
  • 1970-01-01
  • 2017-05-07
  • 2014-07-16
  • 2012-02-04
  • 2012-09-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多