f. 应尽量避免在 where 子句中对字段进行表达式操作,这将导致引擎放弃使用索引而进行全表扫描。如:
select id from t where num/2=100 应改为: select id from t where num=100*2
g. 应尽量避免在where子句中对字段进行函数操作,这将导致引擎放弃使用索引而进行全表扫描。如: select
id from t where substring(name,1,3)= ‘ abc’ – name 以 abc 开头 的 id select id from t where
datediff(day,createdate,’2005-11-30′)=0–‘2005-11-30’生成的 id 应改为: select id from t where name
like ‘abc%’ select id from t where createdate>=’2005-11-30′ and createdate<’2005-12-1′ |
|