久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <bdo id='5NZ4I'></bdo><ul id='5NZ4I'></ul>
<i id='5NZ4I'><tr id='5NZ4I'><dt id='5NZ4I'><q id='5NZ4I'><span id='5NZ4I'><b id='5NZ4I'><form id='5NZ4I'><ins id='5NZ4I'></ins><ul id='5NZ4I'></ul><sub id='5NZ4I'></sub></form><legend id='5NZ4I'></legend><bdo id='5NZ4I'><pre id='5NZ4I'><center id='5NZ4I'></center></pre></bdo></b><th id='5NZ4I'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='5NZ4I'><tfoot id='5NZ4I'></tfoot><dl id='5NZ4I'><fieldset id='5NZ4I'></fieldset></dl></div>

<small id='5NZ4I'></small><noframes id='5NZ4I'>

<legend id='5NZ4I'><style id='5NZ4I'><dir id='5NZ4I'><q id='5NZ4I'></q></dir></style></legend>
  • <tfoot id='5NZ4I'></tfoot>

        PHP 運行查詢所需的時間是 MySQL 客戶端的 90 倍

        PHP takes 90x longer to run query than MySQL client(PHP 運行查詢所需的時間是 MySQL 客戶端的 90 倍)
        1. <small id='73gfD'></small><noframes id='73gfD'>

            <bdo id='73gfD'></bdo><ul id='73gfD'></ul>
            • <legend id='73gfD'><style id='73gfD'><dir id='73gfD'><q id='73gfD'></q></dir></style></legend>
              <i id='73gfD'><tr id='73gfD'><dt id='73gfD'><q id='73gfD'><span id='73gfD'><b id='73gfD'><form id='73gfD'><ins id='73gfD'></ins><ul id='73gfD'></ul><sub id='73gfD'></sub></form><legend id='73gfD'></legend><bdo id='73gfD'><pre id='73gfD'><center id='73gfD'></center></pre></bdo></b><th id='73gfD'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='73gfD'><tfoot id='73gfD'></tfoot><dl id='73gfD'><fieldset id='73gfD'></fieldset></dl></div>

                <tbody id='73gfD'></tbody>

                  <tfoot id='73gfD'></tfoot>
                  本文介紹了PHP 運行查詢所需的時間是 MySQL 客戶端的 90 倍的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在通過命令行 PHP 腳本運行 MySQL 查詢(在 mysqlnd 驅動程序上使用 PDO 準備查詢).這是一個帶有單個左連接的簡單查詢,返回 100 行和每行 7 個小列.

                  I'm running a MySQL query via a command-line PHP script (prepared query using PDO on the mysqlnd driver). It's a simple query with a single left-join, returning 100 rows and 7 small columns per row.

                  當我在 MySQL CLI 中(在運行相關 PHP 腳本的同一臺機器上)運行這個查詢時,它需要 0.10 秒——即使拋出了 SQL_NO_CACHE 標志.

                  When I run this query in the MySQL CLI (on the same machine running the PHP script in question), it takes 0.10 seconds -- even with the SQL_NO_CACHE flag thrown in.

                  當我通過 PDO 運行這個準備好的查詢時,它需要超過 9 秒.這是 execute() only -- 不包括獲取調(diào)用所需的時間.

                  When I run this query, prepared, through PDO, it takes over 9 seconds. This is execute() only -- not including the time it takes for the fetch call.

                  我的查詢示例:

                  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 客戶端都幾乎立即運行它,但這里是踢球的解釋:

                  I don't believe the query is at fault, considering every native MySQL client I've tried has run it near-instantly, but here's the 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 秒?

                  What in the world is PDO doing that is taking 8.9 seconds?

                  正如評論中所述,我也編寫了一個 mysql_query 版本,它的性能同樣很差.然而,刪除 WHERE 子句的一部分,使其運行速度與 MySQL 客戶端一樣快.繼續(xù)閱讀令人難以置信的細節(jié).

                  As stated in the comments, I've written a mysql_query version of this as well, and it has the same poor performance. Removing part of the WHERE clause, however, makes it run as fast as the MySQL client. Read on for mind-boggling details.

                  推薦答案

                  就這個問題提供一個遲來的更新:

                  Giving a very belated update on this question:

                  我還沒有找到原因,但事實證明,PHP 中的 EXPLAIN 與 CLI 中的 EXPLAIN 不同.我不確定連接的任何方面是否會導致 MySQL 選擇為索引使用不同的字段,因為據(jù)我所知,這些東西不應該相關;但遺憾的是,PHP 的 EXPLAIN 顯示沒有使用正確的索引,而 CLI 使用了.

                  I've not found the cause, but it turns out the EXPLAIN was different in PHP versus on the CLI. I'm not sure if any aspect of the connection would cause MySQL to choose to use a different field for the index, because as far as I know those things shouldn't be related; but alas, PHP's EXPLAIN showed that the proper index was not being used, while the CLI's did.

                  在這種(令人困惑的)情況下的解決方案是使用 index暗示.從我的示例中查看此修改后的查詢中的FROM"行:

                  The solution in this (baffling) case is to use index hinting. See the 'FROM' line in this modified query from my example:

                  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 USE INDEX (created_on)
                  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;
                  

                  希望這對某人有所幫助!

                  Hope this helps someone!

                  這篇關于PHP 運行查詢所需的時間是 MySQL 客戶端的 90 倍的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                    <tbody id='DBDxi'></tbody>
                  1. <small id='DBDxi'></small><noframes id='DBDxi'>

                    <legend id='DBDxi'><style id='DBDxi'><dir id='DBDxi'><q id='DBDxi'></q></dir></style></legend>
                            <bdo id='DBDxi'></bdo><ul id='DBDxi'></ul>
                          • <i id='DBDxi'><tr id='DBDxi'><dt id='DBDxi'><q id='DBDxi'><span id='DBDxi'><b id='DBDxi'><form id='DBDxi'><ins id='DBDxi'></ins><ul id='DBDxi'></ul><sub id='DBDxi'></sub></form><legend id='DBDxi'></legend><bdo id='DBDxi'><pre id='DBDxi'><center id='DBDxi'></center></pre></bdo></b><th id='DBDxi'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='DBDxi'><tfoot id='DBDxi'></tfoot><dl id='DBDxi'><fieldset id='DBDxi'></fieldset></dl></div>

                            <tfoot id='DBDxi'></tfoot>
                            主站蜘蛛池模板: 别c我啊嗯国产av一毛片 | 久久久久久久久蜜桃 | 久久国产电影 | 久久在线看 | 国产成人精品一区二区三区视频 | 国产成人精品a视频一区www | 久久久国产精品一区 | 日韩一区二区三区视频 | 中文字幕在线观看一区 | 国产91在线播放 | 犬夜叉在线观看 | 成人精品久久 | 日韩电影免费观看中文字幕 | 孕妇一级毛片 | 91在线视频| 日韩精品在线看 | www日本在线播放 | 蜜桃黄网| 午夜一级做a爰片久久毛片 精品综合 | 91精品国产综合久久香蕉麻豆 | 精品日韩一区 | 日韩在线观看中文字幕 | 中文字幕在线播放第一页 | 亚洲品质自拍视频网站 | 成人网视频| 欧美久久一区 | 亚洲欧美日韩一区 | 国产区高清 | 欧美日韩中文字幕在线 | 国产精品久久久久久久久久久久冷 | 日韩一区二区三区在线 | 久久久久久91香蕉国产 | 久久久青草婷婷精品综合日韩 | 亚洲精品一级 | 亚洲国产精品久久 | 婷婷中文字幕 | 国产一区二区在线视频 | 中文字幕不卡视频在线观看 | 日韩欧美视频 | 天天艹逼网 | 丁香婷婷久久久综合精品国产 |