orcle优化

来源:互联网 发布:部分背包问题 贪心算法 编辑:程序博客网 时间:2024/04/28 09:46

sql语句优化
1.select子句中避免使用"*"
2.尽量多用commit语句
3.用exists代替in
4.尽量使用共享池已有的sql语句(如通过视图查看select sql_test from v$sqlarea);
优化器
rule(基于规则),cost(基于成本),choose(选择性)。参数:

all_rows,first_rows_n,first_rows,choose,rule
select parameter optimizer_mode;
alter session set optimizer_moder=first_rows_100;
i/o操作作优化
调整sga
1.字典的高速缓存
select sum(gets),sum(getmisses),1-(sum(getmisses)/sum(gets)) 'dictionary hit ratio' from

v$rowcache;

2.数据高数缓存
select name,value from v$sysstat where name in('consistent gets','db block gets','physical

reads');

使用索引
1.创建单列索引 create index employ_name on.scott.emp(empname);
2.重建索引 alter index employee_noname rebulid online;
使用数据簇
create cluster position (id number(1))
size 100
hash is id
hashkeys 10000;

create table depost2(
postno char(3) not null,
postname varchar(30) unique null,
ifvoid number(1) defualt 0 check (ifviod between 0 and 1)
)
cluster position(ifvoid)
防止访问冲突
加锁 lock table 表名|视图 in 锁类型 mode [nowait]
lock table scott.emp in exclusive mode ;

合理设计事务
set transaction read only;

分散文件
create tablespace tabdata
datafile 'e:/oracldata/tabdata01.dbf'
online;

create tablespace inddata
datafile 'e:/oracldata/inddata.dbf'
online;

create table department(
departno char(3) not null,
departname varchar2(30) not null,
telephone varchar2(2) not null
)

create tablespace depart_pk
on departno
tablespace inddata;