oracle 效能最佳化操作一:避免對列的操作,oracle效能最佳化

來源:互聯網
上載者:User

oracle 效能最佳化操作一:避免對列的操作,oracle效能最佳化

任何對列的操作都可能導致全表掃描,這裡所謂的操作包括資料庫函數、計算運算式等等,查詢時要儘可能將操作移至等式的右邊,
甚至去掉函數。  

例1:下列SQL條件陳述式中的列都建有恰當的索引,但30萬行資料情況下執行速度卻非常慢:  

select * from record where  substrb(CardNo,1,4)='5378'(13秒)  select * from record where  amount/30< 1000(11秒)  select * from record where  to_char(ActionTime,'yyyymmdd')='19991201'(10秒)  

 

由於where子句中對列的任何操作結果都是在SQL運行時逐行計算得到的,因此它不得不進行表掃描,而沒有使用該列上面的索引;
如果這些結果在查詢編譯時間就能得到,那麼就可以被SQL最佳化器最佳化,使用索引,避免表掃描,因此將SQL重寫如下:

select * from record where CardNo like  '5378%'(< 1秒)select * from record where amount  < 1000*30(< 1秒)select * from record where ActionTime= to_date ('19991201' ,'yyyymmdd')(< 1秒)

相關文章

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.