1

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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

The last line just makes me wonder even more. I'm not writing to the same table as I'm reading.
You aren't, but is anyone? In any case, there's stuff on that mysql page that makes it really clear you need a separate connection to do other stuff.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.