写SQL语句时应该避免在索引列上做计算,能移到另一方的都移动到另一方。
下面是测试的例子,索引列为D_DATE
1 SQL> select count(1) 2 2 from tywtx a 3 3 where a.d_date >= to_date('20100312', 'yyyymmdd') 4 4 and a.d_date < to_date('20100312', 'yyyymmdd') + 1 5 5 ; 6 7 COUNT(1) 8 ---------- 9 59 10 11 Executed in 0.032 seconds 12 13 SQL> alter system flush shared_pool; 14 15 System altered 16 17 Executed in 0.031 seconds 18 19 SQL> select count(1) from tywtx a where trunc(a.d_date) = to_date('20100312', 'yyyymmdd'); 20 21 COUNT(1) 22 ---------- 23 59 24 25 Executed in 0.078 seconds
同样的语句,性能相差近一倍。