我通过命令行
PHP脚本(在MysqLnd驱动程序上使用PDO准备的查询)运行MySQL查询.这是一个简单的查询,具有单个左连接,每行返回100行和7个小列.
原文链接:https://www.f2er.com/php/139572.html当我在MysqL CLI(在运行相关PHP脚本的同一台计算机上)运行此查询时,需要0.10秒 – 即使抛出sql_NO_CACHE标志.
当我运行这个查询,准备通过PDO,它需要超过9秒.这只是执行() – 不包括获取调用所需的时间.
我的查询示例:
SELECT HEX(al.uuid) hexUUID,al.created_on,IFNULL(al.state,'ON') actionType,pp.publishers_id publisher_id,pp.products_id product_id,al.action_id,al.last_updated FROM ActionAPI.actionLists al LEFT JOIN ActionAPI.publishers_products pp ON al.publisher_product_id = pp.id WHERE (al.test IS NULL OR al.test = 0) AND (al.created_on >= :since OR al.last_updated >= :since) ORDER BY created_on ASC LIMIT :skip,100;
我不认为查询是错误的,考虑到我尝试过的每一个本地MysqL客户端已经运行在几乎瞬间,但是这里是EXPLAIN for kicks:
+----+-------------+-------+--------+-------------------------+------------+---------+-----------------------------------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+--------+-------------------------+------------+---------+-----------------------------------+------+-------------+ | 1 | SIMPLE | al | index | created_on,last_updated | created_on | 8 | NULL | 100 | Using where | | 1 | SIMPLE | pp | eq_ref | PRIMARY | PRIMARY | 4 | ActionAPI.al.publisher_product_id | 1 | | +----+-------------+-------+--------+-------------------------+------------+---------+-----------------------------------+------+-------------+ 2 rows in set (0.00 sec)
PDO在做什么在世界上花了8.9秒?
编辑:正如注释中所述,我已经编写了一个这样的MysqL_query版本,并且性能相同.然而,删除WHERE子句的一部分使其运行速度与MysqL客户端一样快.继续阅读令人难以置信的细节.