oracle编程300例-性能优化(一)
1、在SELECT语句中避免使用“*”
2、尽可能减小记录行数
3、使用rowid高效删除重复记录
实例:
delete from stu s
where s.rowid>(select min(t.rowid)
from stu t
where t.stu=t.stu
/
4、使用truncate代替delete删除记录
5、高效统计记录行数
select tables_name,num_rows
from user_tables
where table_name='stu'
/
6、尽量多使用commit
7、避免使用having字句
select user_name,count(user_name)
from log_event
group by user_name
having user_name='sys'
/
select user_name,count(user_name)
from log_event
where user_name='sys'
group by user_name
/
8、用exists 替代in谓词
select sno 学号,sname 姓名,sage 年龄,
sgentle 性别,sbirth 出生年月,sdept 所在班级
from stu
where exists (select * from grade)
where sno=stu.sno and gname='计算机基础')
/
select sno 学号,sname 姓名,sage 年龄,
sgentle 性别,sbirth 出生年月,sdept 所在班级
from stu
where sno in(select sno from grade
where gname='计算机基础')