开发者

PHP/MySQL(i) use_result, store_result and MyISAM Table Locks

I've read variou开发者_StackOverflow中文版s sources (like this, this, or this one) about the difference between use_result() (unbuffered queries) and store_result() (buffered queries) and also know that MySQL keeps locks on data (in the case of MyISAM on the entire table) until all the results have been sent to the client.

What I don't understand is why with use_result() (unbuffered) queries MySQL keeps locks for a longer time than for store_result() (buffered) queries. Why is it so different to use store_result() than using use_result() and doing the buffering (into a PHP array) myself?


When using store_result() mysql driver (that is written on lower level than php) is transfers data from server to client and releasing the lock.

When using use_result() and buffering in array you need to make a php loop, and because php is an interpreter that loop is slower, so there is a delay between every row fetch.

In order to see this delay measure the time difference taken to execute

for (i = 0; i < 100000; i++) {} 

between php and c

In general, php code is slower then c code, and php extensions and internal functions are written in c code, so using extension or internal function is always faster than writing the algorithm for that same thing in php code

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜