开发者

Perl DBD::mysql 'mysql_use_result' OK to use while inserting to another table?

开发者 https://www.devze.com 2023-04-01 03:48 出处:网络
I\'m doing a large join in mysql, and then acting on the resulting data and writing it to another table.Right now, I\'m using the default mysql_store_result, but the $sth->execute() after the query ta

I'm doing a large join in mysql, and then acting on the resulting data and writing it to another table. Right now, I'm using the default mysql_store_result, but the $sth->execute() after the query takes about 20 minutes to run. I'm wanting to switch over to mysql_use_result since I'm only acting on one row at a time.

But, this part of the documentation bothers me:

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.)

开发者_如何学编程I'm acting on one row at a time, and then storing the result in an array. Every 500 entries, I do an INSERT into a separate table. Would this be OK to do from within the mysql_use_result loop? Would it be OK to do if I define a new DB handler for the INSERTs?


You should use a separate DB connection to do the inserts.

However, I believe the cautionary note you quote is talking about blocking things on the server, not just on your particular client.

The mysql documentation is a little clearer:

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.

(I believe that's an overstatement, and may have been written back when mysql was much more of a toy SQL implementation.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号