a)在 where 子句中,避免对字段进行表达式操作或函数操作,避免使用 like 进行模
糊查询,避免使用 OR 或 IN 连接条件,避免使用!=或<>操作符,避免使用 is null 或
is not null 操作来判断字段是否为空。如果使用需要使用 F5 查看执行计划。必要的是要
需要强制使用相应的索引。
b)尽量注意比较值与索引列数据类型的一致性。例如对于 char 型的 emp_type 字段:
where emp_type=123 应改为 where emp_type=’123’
c) 查询列、排序列要与索引列的顺序保持一致。
i. 例 A:复合索引(deptNo,job) 正确:order by deptNo,job,错误 order by job
deptNo
ii. 例 B:复合索引(empNo,job)正确:select empNo,job from emp where
empno<100 and job=’manager’, 错 误 : select empNo,job from emp where
job=’manager’ and empNo<100
4. sql 语句的优化:
a)检查 sql 语句是否符合第二步中的优化规则。
b)检查 sql 语句是否否和第三步索引使用规则。
c) 分析关键的表:
analyze table aqm.qm_mat_pinvoice_lines delete statistics;
analyze table aqm.qm_mat_pinvoice_lines compute statistics for all
indexes;
analyze table aqm.qm_mat_pinvoice_lines compute statistics for all
相关文档
评论