SELECT * FROM v $ version;
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production
PL/SQL Release 11.2.0.4.0 - Production
"CORE 11.2.0.4.0 Production"
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
有以下用例: -
--Create Table T1
create table t1 as select * from all_objects where 1=0;
--Create Table T2
create table t2 as select * from all_objects where 1=0;
--Gather stats on T1
exec dbms_stats.set_table_stats( user, 'T1', numrows=>10000000, numblks=> 1000000 );
--Gather stats on T1
exec dbms_stats.set_table_stats( user, 'T2', numrows=>10000000, numblks=> 1000000 );
--Enable autotrace
set autotrace traceonly explain
--Run SQL
with data
as
(select * from t2 where object_id between 1 and 100000 )
select *
from t2
where not exists (select 1 from data where data.object_id = t2.object_id)
/
Execution Plan
----------------------------------------------------------
Plan hash value: 2779716391
---------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost(%CPU)| Time |
---------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 9200K| 991M| 618K (2)| 00:48:59 |
| 1 | TEMP TABLE TRANSFORMATION | | | | | |
| 2 | LOAD AS SELECT | T2 | | | | |
|* 3 | TABLE ACCESS FULL | T2 | 25000| 2441K| 308K (2)| 00:24:28 |
|* 4 | HASH JOIN RIGHT ANTI | | 9200K| 991M| 309K (2)| 00:24:32 |
| 5 | VIEW | | 25000| 317K| 110 (4)| 00:00:01 |
| 6 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6620_1BF817E | 25000| 2441K| 110 (4)| 00:00:01 |
| 7 | TABLE ACCESS FULL | T2 | 10M| 953M| 309K (2)| 00:24:30 |
---------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter("OBJECT_ID">=1 AND "OBJECT_ID"<=100000)
4 - access("DATA"."OBJECT_ID"="T2"."OBJECT_ID")
--Disable autotrace
set autotrace off
我的问题是 - 我可以以某种方式让优化器在创建的TEMP表上使用索引扫描'SYS_TEMP_0FD9D6620_1BF817E'??
以上是用于说明目的的示例,以提出我的问题。在实际情况中,我遇到的情况是,我创建的SYS_ *表(确切地说是3个)具有巨大的数据集(~5 +百万),并且FULL表扫描耗费了我的查询响应时间。
有没有办法通过无证提示更改(例如??),我可以加快对从WITH suquery中创建的SYS_ *表的访问速度吗?
非常感谢回应。
蒂亚..
答案 0 :(得分:0)
要使用索引扫描,您必须先创建它。 如果您想加快查询速度,请在没有WITH数据AS的情况下重写它,因为WITH需要大量的Oracle资源。以下是:
select *
from t2
where not exists (select 1
from t2
where object_id between 1 and 100000
and object_id = t2.object_id);