Profilo di haiOracle & StarcraftBlogElenchi Strumenti Guida
25 settembre

autotrace,explain plan与绑定变量

create table fenbu as select 1 id,'Y' flag from dba_objects where rownum<100001;

insert into fenbu values(1,'N');
commit;

create index IDX_FENBU_FLAG on fenbu(flag);

analyze table fenbu compute statistics for table for all columns for all indexes;

var a varchar2(32);
exec :a:='N';

SQL 10G>set autotrace trace exp;

SQL 10G>alter session set events'10046 trace name context forever,level 12';  

Session altered.

SQL 10G>select * from fenbu    where   flag=:a;


Execution Plan
----------------------------------------------------------

----------------------------------------------------------------
| Id  | Operation         | Name  | Rows  | Bytes | Cost (%CPU)|
----------------------------------------------------------------
|   0 | SELECT STATEMENT  |       | 50001 |   244K|   202  (80)|
|*  1 |  TABLE ACCESS FULL| FENBU | 50001 |   244K|   202  (80)|
----------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("FLAG"=:A)

Note
-----
   - 'PLAN_TABLE' is old version

 


SQL 10G>alter session set events'10046 trace name context off';

Session altered.

 

很显然可以看到set autotrace的执行计划是错的,这是因为set auotrace,explain plan等操作
并不会发生bind peeking,它并不会把绑定变量的值反映到执行计划里面,不会去看直方图的
数据分布,所以它生成的计划并不可信,我们可以来看一下10046的真实计划。


select *
from
 fenbu    where   flag=:a


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        2      0.00       0.00          0          4          0           1
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        4      0.00       0.00          0          4          0           1

Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 55 

Rows     Row Source Operation
-------  ---------------------------------------------------
      1  TABLE ACCESS BY INDEX ROWID FENBU (cr=4 pr=0 pw=0 time=102 us)
      1   INDEX RANGE SCAN IDX_FENBU_FLAG (cr=3 pr=0 pw=0 time=78 us)(object id 83455)

Commenti (10)

Attendere...
Il commento immesso è troppo lungo. Immetti un commento più breve.
Immissione non effettuata. Riprova.
Impossibile aggiungere il commento al momento. Riprova più tardi.
Per aggiungere un commento è necessaria l'autorizzazione di un genitore. Chiedi autorizzazione
I tuoi genitori hanno disattivato i commenti.
Impossibile eliminare il commento al momento. Riprova più tardi.
Hai raggiunto il numero massimo di commenti pubblicabili giornalmente. Riprova tra 24 ore.
Impossibile lasciare commenti. La funzionalità è stata disattivata perché i sistemi hanno rilevato una possibile attività di spamming dal tuo account. Se ritieni che il tuo account è stato disattivato per errore, contatta il supporto tecnico di Windows Live.
Esegui il seguente controllo di protezione per completare la pubblicazione del commento.
I caratteri digitati nel controllo di protezione devono corrispondere ai caratteri dell'immagine o della riproduzione audio.

Per aggiungere un commento, accedi con il tuo Windows Live ID (se utilizzi Hotmail, Messenger o Xbox LIVE possiedi già un Windows Live ID). Accedi


Non hai ancora un Windows Live ID? Registrati

28 Ago.
Senza nomeha scritto:
Be wow gold cheapest wow power leveling under the best single-site!
17 Set.
Senza nomeha scritto:

Amberdigital Branch,Southern Stars Enterprises Co is specializing in the development and manufacturing of screen advertisings, digital sign, digital signages and LCDs. Established in 1996, we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers.

amberdigital Contact Us
Southern Stars Enterprises Co (Hong Kong Office)
Add:3 Fl, No.2, Lane 2, Kam Tsin Tsuen, Sheung Shui, Hong Kong
Tel:+852 2681 4099
Fax:+852 2681 4586

Southern Stars Enterprises Co (Shenzhen Office)
Add:DE, 16/F, Building 2, Nanguo Tower, Sungang Road, Shenzhen, China
Tel:+86 755 2592 9100
Fax:+86 755 2592 7171

E-mail:sstar@netvigator.com
website:www.amberdigital.com.hk
alibaba:amberdigital.en.alibaba.com[cidh

28 Ago.
9 Ago.
30 Lug.
26 Mar.
jh chenha scritto:
吼吼,打
16 Ott.
hai wangha scritto:
blue_prince没学好,该打屁股,哈
28 Set.
Roby Xueha scritto:
今天刚好看到这篇文章,peeking的话对同一条语句(绑定变量)来说只会对第一个变量值生效,接下无论变量值怎么变化,只要语句没被抛出共享池,还是走第一个值的执行计划。原来我还以为peeking会对不同变量值生效,想想如果这样,那样就都是硬解析了,绑定变量也就没有意义了,呵呵。
27 Set.
banky1 wang1ha scritto:
还有这么神奇的事情?
26 Set.

Riferimenti

L'URL di riferimento per questo intervento è:
http://wzwanghai.spaces.live.com/blog/cns!56626E237AFBD116!340.trak
Blog che fanno riferimento a questo intervento
  • Nessuno