避免在WHERE條件中,在索引列上進行計算或使用函式,因為這將導致索引不被使用

LuiseDalian發表於2014-01-15

點選(此處)摺疊或開啟

  1. --在sal列上建立非唯一索引
  2. scott@TESTDB11>create index idx_emp1_sal on emp1(sal);

  3. Index created.

  4. --查詢年薪 > 20,000的員工的編號、姓名、薪水、年薪
  5. --不走索引
  6. select empno, ename, sal, sal * 12 from emp1 where sal * 12 > 20000;


點選(此處)摺疊或開啟

  1. --修改為等價的寫法,走索引
  2. select empno, ename, sal, sal * 12 from emp1 where sal > 20000 / 12;


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17013648/viewspace-1070753/,如需轉載,請註明出處,否則將追究法律責任。

相關文章