<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優化 - 不要查詢不需要的列 - 不要在多表關聯返回全部的列 - 不要select * - 不要重復查詢,應當寫入緩存 - 盡量使用關聯查詢來替代子查詢。 - 盡量使用索引優化。如果不使用索引。mysql則使用臨時表或者文件排序。如果不關心結果集的順序,可以使用order by null 禁用文件排序。 - 優化分頁查詢,最簡單的就是利用覆蓋索引掃描。而不是查詢所有的列 - 應盡量避免在 where 子句中使用 !=或<> 操作符,否則將引擎放棄使用索引而進行全表掃描。 - 對查詢進行優化,應盡量避免全表掃描,首先應考慮在 where 及 order by 涉及的列上建立索引 - 應盡量避免在 where 子句中對字段進行 null 值判斷,否則將導致引擎放棄使用索引而進行全表掃描,如: ```sql select * from user where name is null ``` - 盡量不要使用前綴% ```sql select * from user where name like '%a' ``` - 應盡量避免在 where 子句中對字段進行表達式操作 - 應盡量避免在where子句中對字段進行函數操作,這將導致引擎放棄使用索引而進行全表掃描 - 很多時候用 exists 代替 in 是一個好的選擇: - ## btree索引 B-TREE索引適合全鍵值、鍵值范圍、前綴查找。 全值匹配,是匹配所有的列進行匹配、 匹配最左前綴。比如 a=1&b=2 那么會用到a的索引 匹配列前綴。 比如 abc abcd %abc 匹配范圍 比如 in(3,5) ### 限制 - 如果不是左前綴開始查找,無法使用索引 比如 %aa? - 不能跳過索引的列。 - 需要中,含有某個列的范圍查找,后面的所有字段都不會用到索引 ### 索引的優點 1、減少服務器掃描表的次數 2、避免排序和臨時表 3、將隨機io變成順序io ### 高性能索引策略 - 1、使用獨立的列,而不是計算的列 where num+1 =10 //bad where num = 9 //good - 2、使用前綴索引 - 3、多列索引,應該保證左序優先 - 4、覆蓋索引 - 5、選擇合適的索引順序 不考慮排序和分組的情況。在選擇性最高的列上,放索引, - 6、使用索引掃描來排序 mysql有兩種方式生成有序的結果,一種是排序操作,一種是按索引順序掃描,如果explain處理的type列的值是index。則說明mysql使用了索引 只有當索引的列順序和order by子句的順序一致的時候,并且所有的順序都一致的時候。mysql才能使用索引進行排序。 ### 不能使用索引的情況 - 1.查詢使用了兩種排序方向 ```sql select * from user where login_time > '2018-01-01' order by id des ,username asc # ``` - 2.order by中含有了一個沒有 索引的列 ```sql select * from user where name = '11' order by age desc; //age 沒有索引 ``` - 3.where 和 order by 無法形成最左前綴 - 索引列的第一列是范圍條件 - 在索引列上有多個等于條件,這也是一種范圍。不能使用索引 https://blog.csdn.net/samjustin1/article/details/52212421
                  <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>

                              哎呀哎呀视频在线观看