sql最佳化,sql最佳化的幾種方法

來源:互聯網
上載者:User

sql最佳化,sql最佳化的幾種方法

1. 常用的資料建視圖,盡量減少group by,order by,update等查法;

2. 建立合理的索引;

3. 先做選擇和投影,最後再串連操作(投影就是從所給的表中,選出需要的列;選擇就是選出所需的行);

4. in換成exists,in是把外表和內表作hash串連,而exists是對外表作loop迴圈,每次loop迴圈再對內表進行查詢,也就是子查詢表大的用exists,子查詢表小的用in,外表就是where前面的,子查詢就是where後面的,另外,無論哪個表大,用not exists都比not in要快;

5. 使用hints指定oracle最佳化器,最佳化器根據這些hints來選擇一個執行方案(Oracle Hints是一種機制,用來告訴最佳化器按照我們的告訴它的方式產生執行計畫)。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.