1 Oracle 调优:
1 在数据量比较大的表上建立相关索引 ----create index abc_b_index on abc ( b ) ;
2 sql 语句的调优:
1 > where 语句查询数据的时候将数据量大的条件放在 where 最后 oracle 查询自上向下 where name='john' and sal>1000 交换后就会影响效率
2 > select 语句避免使用 *
3> 减少访问数据库的次数
select ename ,job, sal from emp where empno=34; select ename ,job,sal from emp where=35;
->select ename,job,sal from emp where empno=34 or empno=35;
4> 采用 decode 函数 :decode( 条件 , 值 1, 翻译值 1, 值 2, 翻译值 2……, 缺省值 )
if( 条件 = 值 1){
return 翻译值 1;}else if( 条件 = 值 2){
return 值 2}else{
return 缺省值 }
Select count(*),sum(sal) from emp where ename='smith' and deptno=20;
Select count(*),sum(sal) from emp where ename='smith' and deptno=10;
->select count(decode(deptno,10,'x',null)) d10_count,
count(decode(deptno,20,'x',null)) d20_count,
sum(decode(deptno,10,sal,null)) d10_sum,
sum(decode(deptno,20,sal,null)) d20_sum,
from emp where ename='smith'
5> 删除重复记录
oracle 中在查询的结果集中没条数据都有一个 rowid 是唯一的,及时所有数据字段内容都相同 rowid 也不会相同只要找到最大的 rowid 就能删除全
部重复数据
方法一 -> 创建一个相同备份表 create table table_test_temp as select * from tbl_test;
-> 在原有表中加记录 insert into tbl_test select * from tbl_test;
-> 查询重复记录信息 select id,name,pid ,count(*) from tbl_test group by id,name ,pid having count(*)>1
-> 删除重复记录 delete from tbl_test_temp x where x.rowid <(select max(rowid) from tbl_test_temp e
where x.id=e.id)
方法二 -> 临时表保存不重复数据 create table temp as select distinct * from tbl_test_temp
-> 丢弃原来的表 drop table tbl_test_temp;
-> 创建原来的表 create table tbl_test_temp as select * from temp;
-> 丢弃临时表 drop table temp
6> truncate 代替 Delete
当用 delete 删除记录的时候,如果没有执行 commit 提交事务,回滚段( rollback segments )可以保存 delete 的数据
oracle 可以恢复到 delete 之前的状态,运用 truncate 时,回滚段不再放任何可以被恢复的数据 当执行命令是立即彻底
删除,占很少的资源
7> 尽量多用 commit
commit 可以释放资源 包括贵滚段恢复数据的空间 ;被程序语句获得的锁; redo log buffer 中的空间
8> count(*) 要比 count(1) 快
9> where 子句代替 having 子句 能减少 having 的开销 having 是在 groupby 的基础上进行查询的
10> 在子查询语句中尽量减少对表的查询
select * from emp where deptno in(select deptno form dept where loc like 'new york' ) or deptno in (select deptno
from dept where dname like 'sales')
select * from emp where deptno in (select deptno from dept where loc like 'newyork' or dname like 'sales')
11> Exist 和 in(not exist 和 not in)
in 是把外表和那表作 hash join ,而 exists 是对外表作 loop ,每次 loop 再对那表进行查询。这样的话, in 适合内外表都很大的情况, exists 适合外表结果集很小的情况。 in 是把外表和那表作 hash join ,而 exists 是对外表作 loop ,每次 loop 再对那表进行查询。
如: select * from emp where deptno in (select deptno from dept)
(或者) select * from emp where exists(select 'x' from dept where dept.deptno=emp.deptno)
分析如下:
Select * from T1 where x in ( select y from T2 )
执行的过程相当于 :
select * from t1, ( select distinct y from t2 ) t2
where t1.x = t2.y;
select * from t1 where exists ( select null from t2 where y = x )
执行的过程相当于 :
for x in ( select * from t1 )
loop
if ( exists ( select null from t2 where y = x.x )
then
OUTPUT THE RECORD
end if
end loop
表 T1 不可避免的要被完全扫描一遍
分享到:
相关推荐
oracle调优工具,包含oracle调优讲解和调优工具的安装文件。
Oracle调优总结Oracle调优总结Oracle调优总结Oracle调优总结Oracle调优总结Oracle调优总结
ORACLE调优技术的一些文档总结,包含了目前网上比较主流的ORACLE调优技术
oracle 调优 文档,武汉支点,大唐集团,甲骨文中国,2012年11月9日, oracle调优知识分享。武汉光谷乐华商务大厦。 英文pdf文档。
Linux内核参数调整及ORACLE调优参数
开Oracle调优鹰眼,深入理解AWR性能报告1.part3
开Oracle调优鹰眼,深入理解AWR性能报告2.part1
Oracle调优实战 Oracle调优实战
RHEL官方Oracle调优手册
oracle调优
文档为oracle调优的STA无脑命令,直接安装命令贴到sqlplus里面就好,sql_id号从awr报告里面获得,想调优的语句找到sql_id,替换到文档里面的sql_id位置,最后无脑贴进去就可以使用STA调优助手了。
DBA 应遵循的 Oracle 调优原则 Oracle 调优是一个复杂的主题。关于调优可以写整整一本书,不过,为了改善 Oracle 数据库的性能,有一些基本的概念是每个 Oracle DBA 都应该遵从的。 在这篇简介中,我们将简要地介绍...
Oracle调优总结收藏.docx
《Oracle 调优简要手册》,简洁实用,30页,WORD
Oracle调优工具使用研究.pdf
DBA 应遵循的 Oracle 调优原则
Oracle调优(入门及提高篇)...........Oracle
Oracle 调优指南 Oracle 调优指南