PHP/MySQL(i) use_result、store_result 和 MyISAM 表锁
我阅读了各种来源(例如 this、这个,或 这个一)关于< code>use_result()(无缓冲查询)和store_result()
(缓冲查询),并且还知道 MySQL 会保持对数据的锁定(在 MyISAM 的情况下是整个表),直到所有数据都处于锁定状态。结果已发送给客户。
我不明白的是为什么使用 use_result()
(无缓冲)查询 MySQL 保持锁定的时间比 store_result()
(缓冲)查询更长。为什么使用 store_result()
与使用 use_result()
并自己进行缓冲(到 PHP 数组中)有如此不同?
I've read various 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当使用store_result()时,mysql驱动程序(编写在比php更低的级别上)将数据从服务器传输到客户端并释放锁。
当使用 use_result() 并在数组中缓冲时,您需要创建一个 php 循环,并且由于 php 是一个解释器,因此循环速度较慢,因此每行获取之间存在延迟。
为了看到这个延迟,测量
php
和c
之间执行的时间差一般来说,php 代码比 c 代码慢,并且编写了 php 扩展和内部函数在 c 代码中,因此使用扩展或内部函数总是比在 php 代码中编写同一事物的算法更快
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
between
php
andc
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