<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # mysql優化過程 # 了解desc 可用于分析表結構和sql語句, 用于分析sql語句最常見 ## 分析表結構 ```sql mysql> explain hd_parter; +------------+-----------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+-----------------------+------+-----+---------+----------------+ | id | mediumint(8) unsigned | NO | PRI | NULL | auto_increment | | parter | varchar(16) | NO | UNI | | | | key | varchar(32) | NO | | | | | name | varchar(100) | NO | | NULL | | | siteurl | varchar(200) | NO | | NULL | | | status | tinyint(1) | NO | | 0 | | | start_time | int(10) unsigned | NO | | 0 | | | end_time | int(10) unsigned | NO | | 0 | | +------------+-----------------------+------+-----+---------+----------------+ 8 rows in set (0.02 sec) ``` ## 分析語句 ```sql mysql> desc select * from hd_order order by id desc limit 10; +----+-------------+----------+-------+---------------+---------+---------+------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+----------+-------+---------------+---------+---------+------+------+-------+ | 1 | SIMPLE | hd_order | index | NULL | PRIMARY | 4 | NULL | 10 | | +----+-------------+----------+-------+---------------+---------+---------+------+------+-------+ 1 row in set (0.00 sec) ``` ### select_type - SIMPLE 簡單表, 不實用子查詢或者連接 - PRIMARY 主查詢 - SUBQUERY 子查詢中的第一個SELECT - UNION ### table 對應的表名, 如果取了別名則顯示別名 ### type 性能是越往下越差 - system?表中只有一行,即常量表 - const 單表中最多有一個匹配行,如primary key或unique index - eq_ref 對于前面的每一行,在此表中只查詢一條記錄,也就是多表連接中使用primary key或unique index - ref 與eq_ref類似,區別在于不是使用primary key或unique index,而是使用普通索引 - ref_or_null 與ref類型,區別在于條件中包含對null的查詢 - index_merge 索引合并優化 - unique_subquery in的后面是一個查詢主鍵字段的子查詢 - index_subquery 與unique_subquery類似,區別在于in的后面是查詢非唯一索引字段的子查詢 - range 單表中的范圍查詢 - index 對于前面的每一行,都通過查詢索引來得到數據 - all 對于前面的每一行,都通過掃描全表來得到數據 ### possible_keys 查詢時可能用到的索引 ### key 查詢時實際使用到的索引 ### key_len 索引字段的長度 ### ref key 列所選擇的索引的查找方式 ### rows ?掃描行的數量, 越少越好 ### Extra 執行情況的說明和描述 **Using index** 通過索引就能返回結果 **Using where** **Using temporary** 使用了臨時表 **Using filesort **查詢所需的排序與使用的索引的排序不一致, 重新排序 ### # 前置理論知識 ## sql語句執行過程 http://www.2cto.com/database/201512/453280.html 這是從網上找來的例子 ```sql SELECT DISTINCT < select_list > FROM < left_table > < join_type > JOIN < right_table > ON < join_condition > WHERE < where_condition > GROUP BY < group_by_list > HAVING < having_condition > ORDER BY < order_by_condition > LIMIT < limit_number > ``` 執行順序是 ```sql FROM <left_table> ON <join_condition> <join_type> JOIN <right_table> WHERE <where_condition> GROUP BY <group_by_list> HAVING <having_condition> SELECT DISTINCT <select_list> ORDER BY <order_by_condition> LIMIT <limit_number> ``` 大概就是 從張表獲取數據->根據條件過濾->選擇需要的字段->排序->從什么位置取多少條數據 ## 連表join http://coolshell.cn/articles/3463.html ## desc分析的參數 # 分析sql語句 desc ```sql ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看