Orace查询性能优化
来源:互联网 发布:超级列表框读取数据库 编辑:程序博客网 时间:2024/06/05 19:58
Orace查询性能优化
1、避免全表扫描,在涉及到where和order by 的字段上添加索引。
2、会导致放弃索引、变成全表扫描。
(1)在where子句中进行null判断。
解决办法:在num类型的数据设置为0。
(2)在where子句中使用!=、<>操作符
(3)在where子句中使用or。
解决办法:
select id from t where num=10 or num=20
可以这样查询:
select id from t where num=10
union all
select id from t where num=20
这样写就避免了全表扫描。
(4)in 和 not in 也要慎用
解决办法:
select id from t where num in(1,2,3)
对于连续的数值,能用 between 就不要用 in 了:
select id from t where num between 1 and 3
(解决办法用between代替in)
(5)在where子句中对字段进行表达式操作
解决办法:
select id from t where num/2=100
应改为:
select id from t where num=100*2
(6)在where子句中对字段进行函数操作
解决办法
select id from t where substring(name,1,3)=’abc’ // oracle总有的是substr函数。
select id from t where datediff(day,createdate,’2005-11-30’)=0 //查过了确实没有datediff函数。
应改为:
select id from t where name like ‘abc%’
select id from t where createdate>=’2005-11-30’ and createdate<’2005-12-1’ //
oracle 中时间应该把char 转换成 date 如: createdate >= to_date(‘2005-11-30’,’yyyy-mm-dd’)
(7).很多时候用 exists 代替 in 是一个好的选择:
select num from a where num in(select num from b)
用下面的语句替换:
select num from a where exists(select 1 from b where num=a.num)
- Orace查询性能优化
- Orace WDP 授权培训查询
- hibernate查询性能优化
- 数据库查询性能优化
- 数据库查询性能优化
- oracle查询性能优化
- 查询性能优化
- hibernate查询性能优化
- mysql查询性能优化
- sqlserver2008查询性能优化
- mysql性能优化(查询)
- oracle 查询性能优化
- 子查询性能优化
- SQL查询性能优化
- 数据库查询性能优化
- Oracle查询性能优化
- MySQL查询性能优化
- Oracle查询性能优化
- I2C协议
- SAP ABAP解析XML方法
- lua QUICK-COCOS2D-X
- 并发队列ConcurrentLinkedQueue和阻塞队列LinkedBlockingQueue用法
- python操作csv
- Orace查询性能优化
- RSS
- c++ primer 入门练习题 1.4.1节
- 物联网体系系统学习笔记
- BZOJ2632: [neerc2011]Gcd guessing game
- 值乎与分答:一场关于知识付费的“有声”暗战
- 每日一得--hadoop学习笔记
- Behavioral Patterns Part 3/11: Interpreter Pattern
- 174、请简述以下两个for循环的优缺点(5分)