- 1、本文档共33页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Sql 优化核心是什么?
create table test1(id,object_name,owner) as select object_id as
id,object_name,owner from dba_objects;
create table test2(id,object_type,status) as select object_id as id,status,temporary
from dba_objects;
select count(*) from test1 t1,test2 t2 where t1.id=t2.id and t1.owner=SCOTT;
create index idx_test1 on test1(id,owner);
create index idx_test2 on test2(id);
exec
dbms_stats.gather_table_stats(user,test1,cascade=true,estimate_percent=100);
exec
dbms_stats.gather_table_stats(user,test2,cascade=true,estimate_percent=100);
CREATE INDEX IDX_TEST1 ON TEST1(OWNER,ID);
适用于在单独查询返回记录很多,而组合查询之后返回记录很少的情况
选择过滤条件作为引导列
尽量把join 列放在组合索引的最后面,即使join 选择性很高
引导列的选择性越高越好
仅等值查询时,组合索引的顺序是不影响性能的
在数据库优化过程中,索引的重要性是不言而喻的,但是在我们进行性能调整过程中,
一个索引是否能够被使用到,在索引创建之前是无法确定的,而创建索引又是一个代价
很高的操作,尤其是数据量很大的情况下,这时候我
们就可以考虑使用虚拟索引
特点:
无法执行alter index
不能创建和虚拟索引同名的实际索引
数据字典中查不到
create table test as select * from dba_objects;
-- 创建虚拟索引,首先要将
_use_nosegment_indexes 的隐含参数设置为true
alter session set
_use_nosegment_indexes=true;
create index ix_test on test(object_id)
nosegment;
explain plan for select * from test where
object_id=1;
set linesize 1000
select * from table(dbms_xplan.display());
set autotrace traceonly
select * from test where object_id=1;
-- 以下看的是真实执行计划,显
然是用不到索引。
alter session set
statistics_level=all;
select * from test where
object_id=1;
select * from
table(dbms_xplan.display_cur
sor(null,null,allstats last));
create table test1 ( a int, b varchar2(80) );
create table test2
begin
as
for i in 1 .. 100000
select a,b
loop from test1
insert into test1(a,b) order by b;
values (i, rpad(dbms_random.random,75,*) ); alter table test2 add constrain
文档评论(0)