gpt4 book ai didi

mysql - Perl DBD::mysql 'mysql_use_result' 可以在插入到另一个表时使用吗?

转载 作者:行者123 更新时间:2023-11-29 00:53:23 27 4
gpt4 key购买 nike

我在 mysql 中进行大型连接,然后对生成的数据进行操作并将其写入另一个表。现在,我正在使用默认的 mysql_store_result,但是查询后的 $sth->execute() 需要大约 20 分钟才能运行。我想切换到 mysql_use_result,因为我一次只对一行进行操作。

但是,文档的这一部分让我很困扰:

This attribute forces the driver to use mysql_use_result rather than mysql_store_result. The former is faster and less memory consuming, but tends to block other processes. (That's why mysql_store_result is the default.)

我一次对一行进行操作,然后将结果存储在一个数组中。每 500 个条目,我将 INSERT 插入到一个单独的表中。在 mysql_use_result 循环中这样做可以吗?如果我为 INSERT 定义一个新的数据库处理程序,可以这样做吗?

最佳答案

您应该使用单独的数据库连接来执行插入操作。

但是,我相信您引用的警示说明是在谈论在服务器上阻止某些事情,而不仅仅是在您的特定客户端上。

mysql documentation更清楚一点:

you shouldn't use mysql_use_result() if you are doing a lot of processing for each row on the client side, or if the output is sent to a screen on which the user may type a ^S (stop scroll). This ties up the server and prevent other threads from updating any tables from which the data is being fetched.

(我认为这是夸大其词,当 mysql 更像是一个玩具 SQL 实现时,可能已经写回了。)

关于mysql - Perl DBD::mysql 'mysql_use_result' 可以在插入到另一个表时使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7275211/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com