oracle 效能最佳化操作五:盡量去掉 "<>",oracle效能最佳化

來源:互聯網
上載者:User

oracle 效能最佳化操作五:盡量去掉 "<>",oracle效能最佳化

oracle 效能最佳化操作五:盡量去掉 "<>"

盡量去掉 "<>",避免全表掃描,如果資料是枚舉值,且取值範圍固定,則修改為"OR"方式。

例:

<span style="font-size:18px;">UPDATE SERVICEINFO SET STATE=0 WHERE STATE<>0;</span>

以上語句由於其中包含了"<>",執行計畫中用了全表掃描(TABLE ACCESS FULL),沒有用到state欄位上的索引。

實際應用中,由於商務邏輯的限制,欄位state為枚舉值,只能等於0,1或2,而且,值等於=1,2的很少。

因此可以去掉"<>",利用索引來提高效率。

修改為:

<span style="font-size:18px;">UPDATE SERVICEINFO SET STATE=0  WHERE STATE = 1 OR STATE = 2 ;</span>

進一步的修改可以參考“oracle 效能最佳化操作四”。

相關文章

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.