91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Mysql索引類型創建錯誤導致SQL查詢緩慢

發布時間:2020-08-16 05:31:42 來源:ITPUB博客 閱讀:178 作者:shawnloong 欄目:MySQL數據庫
索引類型創建錯誤導致SQL查詢緩慢
通過pt-query-digest分析發現這條語句%95都需要15S以上
# Query 2: 0.00 QPS, 0.01x concurrency, ID 0xB0328811156CFA43 at byte 28152292
# This item is included in the report because it matches --limit.
# Scores: V/M = 1.67
# Time range: 2017-01-17 20:02:15 to 2017-03-02 14:48:20
# Attribute    pct   total     min     max     avg     95%  stddev  median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count          7    2669
# Exec time     22  24668s      3s     20s      9s     15s      4s      9s
# Lock time      2   655ms   117us     1ms   245us   348us    68us   224us
# Rows sent      0   2.61k       1       1       1       1       0       1
# Rows examine   9  40.04M   9.46k  20.30k  15.36k  19.40k   3.60k  15.96k
# Rows affecte   0       0       0       0       0       0       0       0
# Bytes sent     0 172.03k      66      66      66      66       0      66
# Query size     2 560.39k     215     215     215     215       0     215
# String:
# Databases    ebiz_kly
# Hosts        10.111.124.41
# Last errno   0
# Users        ebiz_kly
# Query_time distribution
#   1us
#  10us
# 100us
#   1ms
#  10ms
# 100ms
#    1s  ################################################################
#  10s+  ########################################################
# Tables
#    SHOW TABLE STATUS FROM `ebiz_kly` LIKE 'ORDER_INFO'\G
#    SHOW CREATE TABLE `ebiz_kly`.`ORDER_INFO`\G
#    SHOW TABLE STATUS FROM `ebiz_kly` LIKE 'ORDER_CHECK'\G
#    SHOW CREATE TABLE `ebiz_kly`.`ORDER_CHECK`\G
# EXPLAIN /*!50100 PARTITIONS*/
SELECT count(1) from (
                        SELECT a.* from ORDER_INFO a LEFT JOIN ORDER_CHECK b ON a.ORDER_NO=b.ORDER_NO


                 WHERE  a.DELETED = '0'
                GROUP BY a.id
                ORDER BY a.CREATE_TIME DESC, a.MODIFIED_TIME DESC


                ) as t\G

手動執行查看計劃
+----+-------------+------------+------+------------------+------+---------+------+----------+----------------------------------------------------+
| id | select_type | table      | type | possible_keys    | key  | key_len | ref  | rows     | Extra                                              |
+----+-------------+------------+------+------------------+------+---------+------+----------+----------------------------------------------------+
|  1 | PRIMARY     | | ALL  | NULL             | NULL | NULL    | NULL | 26682118 | NULL                                               |
|  2 | DERIVED     | b          | ALL  | ORDER_NO         | NULL | NULL    | NULL |     5182 | Using temporary; Using filesort                    |
|  2 | DERIVED     | a          | ALL  | PRIMARY,ORDER_NO | NULL | NULL    | NULL |     5149 | Using where; Using join buffer (Block Nested Loop) 


order_info 跟order_check join 竟然這么多返回行
兩張表的數據,每張表才5000多條
查看兩張表(ORDER_INFO,ORDER_CHECK)字段ORDER_NO竟然是full text index


修改索引類型發現只要0.3了.
system@localhost 17:45:  [ebiz_kly]> SELECT count(1) from (
    ->                         SELECT a.* from ORDER_INFO a LEFT JOIN ORDER_CHECK b ON a.ORDER_NO=b.ORDER_NO
    -> 
    ->                  WHERE  a.DELETED = '0'
    ->                 GROUP BY a.id
    ->                 ORDER BY a.CREATE_TIME DESC, a.MODIFIED_TIME DESC
    -> 
    ->                 ) as t\G
*************************** 1. row ***************************
count(1): 5205
1 row in set (0.28 sec)
查詢執行計劃
system@localhost 17:45:  [ebiz_kly]> explain SELECT count(1) from (
    ->                         SELECT a.* from ORDER_INFO a LEFT JOIN ORDER_CHECK b ON a.ORDER_NO=b.ORDER_NO
    -> 
    ->                  WHERE  a.DELETED = '0'
    ->                 GROUP BY a.id
    ->                 ORDER BY a.CREATE_TIME DESC, a.MODIFIED_TIME DESC
    -> 
    ->                 ) as t;
+----+-------------+------------+-------+-------------------+-----------+---------+---------------------+------+----------------------------------------------+
| id | select_type | table      | type  | possible_keys     | key       | key_len | ref                 | rows | Extra                                        |
+----+-------------+------------+-------+-------------------+-----------+---------+---------------------+------+----------------------------------------------+
|  1 | PRIMARY     | | ALL   | NULL              | NULL      | NULL    | NULL                | 5157 | NULL                                         |
|  2 | DERIVED     | a          | index | PRIMARY,idx_oi_on | PRIMARY   | 8       | NULL                | 5157 | Using where; Using temporary; Using filesort |
|  2 | DERIVED     | b          | ref   | idx_oc_on         | idx_oc_on | 768     | ebiz_kly.a.ORDER_NO |    1 | Using where                                  |
差距很明顯了


官方文檔相關解決
全文索引
InnoDB FULLTEXT Indexes


FULLTEXT indexes are created on text-based columns (CHAR, VARCHAR, or TEXT columns) to help speed up queries and DML operations on data contained within those columns,
 omitting any words that are defined as stopwords.
 InnoDB FULLTEXT indexes have an inverted index design. Inverted indexes store a list of words, and for each word, a list of documents that the word appears in. To support 
 proximity search, position information for each word is also stored, as a byte offset.
 全文索引創建基于文本的列(char,varchar,或文本列)來幫助加快對包含在這些列的數據查詢和DML操作,主要支持
 關于全文索引解釋,阿里月報相關資料
 http://mysql.taobao.org/monthly/2015/10/01/
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

大连市| 望都县| 潜江市| 平顺县| 吉安市| 崇明县| 霍州市| 临洮县| 昆明市| 修文县| 浏阳市| 常德市| 木兰县| 社旗县| 宁德市| 新密市| 卢氏县| 浦东新区| 温宿县| 安新县| 图片| 怀集县| 蒙自县| 梁平县| 临海市| 莒南县| 那曲县| 辉南县| 攀枝花市| 伊金霍洛旗| 蒲江县| 民丰县| 荥经县| 青铜峡市| 海兴县| 南部县| 岫岩| 扎鲁特旗| 德阳市| 凤山县| 香港|