Oracle 11g Invisible Indexes

773 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
773
On SlideShare
0
From Embeds
0
Number of Embeds
33
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Oracle 11g Invisible Indexes

  1. 1. Invisible Indexes Bu yazimda 11g ile gelen yeni ozellik “"invisible index" ler uzerinde dayanacagam. Eger biz Index I invisibleye chekdiyimzde optimizer o index yoxmush kimi davranacaqdir. Diger terefden gelen insertlerde index update olmaya devam edecekdir. Yeni indexsi yeniden visible etdiyimizde indexsi rebuild etmeye gerek qalmayacaqdir. Bunu istifade ede bilmemiz uchun COMPATIBLE parametresi en az 11.0.0.0.0 olmalidir. Bele olmasa o zmana ashagdaki xetani alacaqsiniz. ORA-00406: COMPATIBLE parametresi 11.0.0.0.0 ve ya daha boyuk olmalıdır Oracle 11g Databaselerde optimizer_use_invisible_indexes parametresi default olarak FALSE gelir.Bu parameteni TRUE etdiyimizde optimizer invisible indexleri istifade edmeyecekdir. SQL> show parameter optimizer_use_invisible_indexes NAME TYPE VALUE ------------------------------------ ----------optimizer_use_invisible_indexes boolean FALSE Misal uchun bir table ve index yaradaraq invisible index testi heyata kechirek. SQL> create table deneme as select * from dba_objects; Table created. SQL> CREATE INDEX indx_deneme_owner ON DENEME(OWNER); Index created. SQL> set autotrace traceonly SQL> select * from deneme where owner='ANAR'; Execution Plan --------------------------------------------------------| Id | Operation | Name | --------------------------------------------------------| 0 | SELECT STATEMENT | | | 1 | TABLE ACCESS BY INDEX ROWID| DENEME | |* 2 | INDEX RANGE SCAN | INDX_DENEME_OWNER | --------------------------------------------------------SQL> set autotrace off; Bu sorguda optimizer index istifade olundu. Indi indexsimizi invisibla chekerek tekrar execution plani inceleyek.
  2. 2. Optimizer indexi gormezden gelerek table access full scan getmesini gozleyirik. SQL> alter index indx_deneme_owner invisible; Index altered. SQL> set autotrace traceonly SQL> select * from deneme where owner='ANAR'; Execution Plan -----------------------------------| Id | Operation | Name | -----------------------------------| 0 | SELECT STATEMENT | | |* 1 | TABLE ACCESS FULL| DENEME | -----------------------------------SQL> set autotrace off Gorduyumuz kimi optimizer indexi gormedi ve DENEME tablesine full access getdi. Bu zaman bele bir sual ortaya chixir. Bir index invisible-dirsa update olunurmu? Gozel sual  Test uchun analiz tarixi ve setir sayisini inceleyek. SQL> select num_rows,last_analyzed from dba_indexes where index_name ='INDX_DENEME_OWNER'; NUM_ROWS LAST_ANAL ---------- --------79051 12.03.2012 10:39:27 Analiz tarixi indexsin yaradilma tarihi BU deqiqe indexsimiz invisibledir. Tablenin statistikasini alsqa bu zaman indexsimizin statistikasida toplanacaqdir. SQL> exec dbms_stats.gather_table_stats(ownname=>'SYS',tabname=>'DENEME',cascade= >true); PL/SQL procedure successfully completed. SQL> select num_rows,last_analyzed from dba_indexes where index_name ='INDX_DENEME_OWNER'; NUM_ROWS LAST_ANAL ---------- --------79051 12.03.2012 10:41:03
  3. 3. Yeniden analiz tarixine baxiriq ve bu anin tarixi oldugunu goruruk. Demeli index invisible olsada update olur. Birde tabeleye insert edek tekrar baxaq. SQL> insert into deneme select * from dba_objects; 79052 rows created. SQL> commit; Commit complete. SQL> exec dbms_stats.gather_index_stats('SYS','INDX_DENEME_OWNER'); PL/SQL procedure successfully completed. SQL> select num_rows,last_analyzed from dba_indexes where index_name ='INDX_DENEME_OWNER'; NUM_ROWS LAST_ANAL ---------- --------158103 12.03.2012 10:43:15 Burdan goruruk ki num_rows columumuzda artdi. Indi tekrar visableye chekek. SQL> alter index indx_deneme_owner visible; Index altered. Indi Indesimiz istifade edile bilir ve herhansi bir index rebuild ishlemine ehtiyac yoxdur. SQL> set autotrace traceonly SQL> select * from deneme where owner='ANAR'; Execution Plan --------------------------------------------------------| Id | Operation | Name | --------------------------------------------------------| 0 | SELECT STATEMENT | | | 1 | TABLE ACCESS BY INDEX ROWID| DENEME | |* 2 | INDEX RANGE SCAN | INDX_DENEME_OWNER | --------------------------------------------------------SQL> set autotrace off Birde optimizer_use_invisible_indexes parametresini test edek. Ilk once indexsi visibleye chekek ardindan parametreni true edek.
  4. 4. SQL> alter index indx_deneme_owner invisible; Index altered. SQL> set autotrace traceonly SQL> select * from deneme where owner='ANAR'; -----------------------------------| Id | Operation | Name | -----------------------------------| 0 | SELECT STATEMENT | | |* 1 | TABLE ACCESS FULL| DENEME | -----------------------------------Parametreni TRUEya chekdiyimizde artiq optimizer Invisible indexleri istifade etmeyecek. SQL> alter session set optimizer_use_invisible_indexes=TRUE; Session altered. SQL> select * from deneme where owner='ANAR'; Execution Plan --------------------------------------------------------| Id | Operation | Name | --------------------------------------------------------| 0 | SELECT STATEMENT | | | 1 | TABLE ACCESS BY INDEX ROWID| DENEME | |* 2 | INDEX RANGE SCAN | INDX_DENEME_OWNER | -------------------------

×