首页 > 技术文章 > 避免在WHERE条件中,在索引列上进行计算或使用函数,因为这将导致索引不被使用

AmilyWilly 2016-05-13 11:21 原文

点击(此处)折叠或打开

  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;

推荐阅读