You are on page 1of 6

Sachin Arora's Blog: When should I rebuild my indexes?

http://oracle-online-help.blogspot.in/2007/01/when-should-i-rebuild-my-...

0

More

Next Blog»

Create Blog

Sign In

Sachin Arora's Blog

Google Ads

► SQL Server

► Indexes

► SQL DBA

► Query SQL

Top Posts Nested loops, Hash join and Sort Merge joins – difference? Optimizer_mode – ALL_ROWS or FIRST_ROWS? Star Vs Snowflake schema

T UESDA Y , J A NUA RY 2, 2007

1 Cr Term Cover @ Rs. 543
www.policybazaar.… Cheapest Term Insurance in India Compare 46 Insurers in 60 Secs.

When should I rebuild my indexes?
Need is necessary for any change. I hope all agree to this. So why many DBA’s (not all) rebuilds indexes on periodical basis without knowing the impact of it? Let’s revisit the facts stated by many Oracle experts:

Index Skip Scan - B Tree indexes can never be unbalanced - The distance of any leaf block (which contains the index value) from the root block is always same. - B Tree performance is good for both small and large tables and does not degrade with the growth of table Index usage with LIKE operator When will rebuild help? The Clustering factor SESSION_CACHED_CURSORS Vs CURSOR_SPACE_FOR_TIME - which, when and why?

Gmail -- Google ईमेल
Mail.Google.com Google आपक गोपनीयता को सु र रखेगा ! त

• When the data in index is sparse (lots of holes in index, due to deletes or updates) and your query is usually range based. Labels If your SQL’s use “=” predicate, rebuilding of index may not help you at all unless the DML’s (updates/deletes) on the table are cause of increasing the height of index. Due to heavy updates/deletes on a table, the space in the index can be left unused (unless it is reused) due to which block splits and if the splitting goes beyond the level of accomodation, the height of index increases by 1. In simpler terms, unless you reduce the height (BLEVEL) of index, the time taken to reach the leaf block from root block will not change. As explained above, the height of index can be decreased by rebuild of an index(only if height was increased to updates/deletes). Only in case of range scan, rebuild (consider coalesce option also) may help. Tuning (15) Tips (8) CBO (5) General (3) Index Rebuild (3) Oracle 11g new features (3) OLAP (2) Oracle Arch (2) Space management (2) materialized view (2) Execution Plan (1) Export/Import (1) Select * from emp where empno between 1000 and 2000; In above case there could be lot of deleted/updated data which will also be read while reading between 1000 to 2000. Rebuilding will reclaim any unused space and hence the select could be faster. • Index fast full scan/ Index full scan. (rare case) If your SQL’s are designed in a way that mostly data is selected from index (it doesn’t goes to table). In this case the whole index is read for data not for redirecting to table. Ex: Select count(empno) from emp; -- you have an index in empno Select empno from emp -- you have an index in empno Both the above SELECTs will fetch the data from Index only. Since the whole index is getting read, the space used by deleted rows is also read at the time of SELECT operation Posted by Sachin at Tuesday, January 02, 2007 Labels: Index Rebuild Nested table (1) Blog Archive ► 2009 (1) ► 2008 (10) ▼ 2007 (14) ► March (3) ► February (3) ▼ January (8) Running shell script from Oracle Index skip Scan – how? External Tables - 10g SESSION_CACHED_CURSORS Vs CURSOR_SPACE_FOR_TIME ... Should I rebuild or coalesce my indexes ? How to find indexes which are candidate for rebuil... When should I rebuild my indexes?

► Oracle SQL Tool ► Oracle ► Oracle 11G Upgrade

10 comments:
Tapiwanashe said...

Print to PDF without this message by purchasing novaPDF (http://www.novapdf.com/) 1 of 6

4/18/2013 5:44 AM

January 5.com/) 2 of 6 4/18/2013 5:44 AM . for your comments. Firstly. you cannot specify PCTUSED in CREATE INDEX. But in case of index. Beautifully explianed use of How B tree index works . This comment has been removed by a blog administrator. Update means delete + insert operation for index. Analyze helps in getting the statistics which helps in giving more information to optimizer while selecting the data. Oracle will first delete 10 and insert 20 (may or may be not within a single block) because reference to 20 may be done by a different branch block (or also values close to 20 are in different leaf block of the same branch block).novapdf..2007 ► 2006 (18) ► Oracle Database Support ► Oracle DBA Course ► Oracle Driver JDBC Print to PDF without this message by purchasing novaPDF (http://www.in/2007/01/when-should-i-rebuild-my-. Will be more helpful if can further add how to quick check for rebuild require & possible ways in 9i & 10g January 4. 2007 at 1:01:00 PM GMT+05:30 Harvinder said. Hello Tapiwanashe. When I say similar. 2007 at 1:35:00 PM GMT+05:30 Tracking Sachin said.. Assume a leaf index block holds index entries for 20 rows and you delete 10 rows.. Update works similar to delete in case of index.. If the BTree index is affected by things like updates and deletes.. my new post How to find indexes which are candidate for rebuild? is focssing that. January 5. it means index entries which can be referred by the branch block (of that leaf block) can be inserted.Sachin Arora's Blog: When should I rebuild my indexes? http://oracle-online-help. January 4. Thanks Harvinder. I am not a DBA but I have stupid question.blogspot.. Yes. 2007 at 1:01:00 PM GMT+05:30 Sachin said.. Let me take an example. 2007 at 12:52:00 PM GMT+05:30 Sachin said. Is it also necessary to re-analyze after loading many records and why? I mean if the table grows why can't the index grow too? January 3. Answer to your second part of question (if table grows.. But if all 20 rows are deleted. and they leaves hole but these holes can be used for future insert.. The hole for 10 rows can be used for newer insert when you insert similar kind of data... so block returns to freelist only when it is empty. This comment has been removed by the author. why index can’t grow) is: Both table. A table block goes to freelist. I think these can leave holes within the index.. Happy New Year . 2007 at 8:56:00 PM GMT+05:30 Harvinder said. If you update a value 10 to 20. the full block goes free and this block can go into freelist and can be used anywhere (irrespective of being similar or not). if post update/delete the block usage goes below the PCTUSED level. and index grows but their growth pattern is different. Let me know if I’m not able to explain clearly. B tree are affected by updates/deletes. Kindly give your feedback on that. Thanks for your comment.

992 : 'Question about how index space is reused'.Assume a leaf index block holds index entries for 20 rows and you delete 10 rows.. 48533 rows deleted. Regards. But if the rows are added as a seperate transaction then the index entries will get reused.blogspot. -.check this testcase: SQL> create table test as select * from dba_objects. Sachin January 5. i. 2007 at 1:37:00 PM GMT+05:30 vaibhav said.novapdf. it means index entries which can be referred by the branch block (of that leaf block) can be inserted. Table created.com/) 3 of 6 4/18/2013 5:44 AM . The hole for 10 rows can be used for newer insert when you insert similar kind of data. Hi Vaibhav. Index created.. -----------The index space will not get reused when similar data is inserted during the same transaction. When I say similar.Sachin Arora's Blog: When should I rebuild my indexes? http://oracle-online-help.in/2007/01/when-should-i-rebuild-my-.. SQL> analyze index test_in validate structure.DELETE AND Print to PDF without this message by purchasing novaPDF (http://www. Let me take an example. BTW ... I searched the document you refered but with no success I appreciate if you can give me the link. SQL> insert into test select * from dba_objects. Please refer to the Metalink Thread 619078.e.. SQL> select index_name. Index analyzed. if we delete 10 rows and insert the same rows in the same transaction then the index entries will not get reused. 2007 at 2:14:00 AM GMT+05:30 Sachin said. INDEX_NAME LEAF_BLOCKS -----------------------------. Vaibhav January 9. B tree are affected by updates/deletes. and they leaves hole but these holes can be used for future insert.----------TEST_IN 107 SQL> delete from test. Regarding following comment ------------Yes. SQL> create index test_in on test(object_id).leaf_blocks from user_indexes where index_name='TEST_IN'. Hi Sachin.

SQL> select leaf_blocks from user_indexes where index_name='INDX_MYTB'..com/) 4 of 6 4/18/2013 5:44 AM . SQL> commit.. Index created.992. SQL> select index_name. Commit complete. 2007 at 11:54:00 AM GMT+05:30 vaibhav said. Table created. SQL> commit. SQL> select leaf_blocks from user_indexes where index_name='INDX_MYTB'. SQL> analyze index test_in validate structure.delete and insert are performed in a single transaction SQL> create table mytb as select * from all_objects. 5/ PL/SQL procedure successfully completed. ( and not VALIDATE STRUCTURE ) Testcase 1 -. you are not computing the statistics on the index. INSERT within a single transaction 48534 rows created.Sachin Arora's Blog: When should I rebuild my indexes? http://oracle-online-help. 4 end.novapdf. In your testcase..blogspot. INDEX_NAME LEAF_BLOCKS -----------------------------.----------TEST_IN 107 January 9. SQL> analyze index indx_mytb validate structure. LEAF_BLOCKS ----------41 SQL> analyze index indx_mytb compute statistics. Index analyzed.leaf_blocks from user_indexes where index_name='TEST_IN'. LEAF_BLOCKS ----------84 Print to PDF without this message by purchasing novaPDF (http://www.. On Metalink in 'Advanced Search' check for document id 619078. Use : analyze index index_name compute statistics. SQL> create index indx_mytb on mytb(object_name). SQL> select leaf_blocks from user_indexes where index_name='INDX_MYTB'. 3 insert into mytb select * from all_objects. LEAF_BLOCKS ----------41 SQL> begin 2 delete from mytb. Hi Sachin. Commit complete. Index analyzed.in/2007/01/when-should-i-rebuild-my-. Index analyzed.

But definately other transactions can use it. LEAF_BLOCKS ----------41 SQL> begin 2 delete from mytb. " Oracle doesnot resuse the free space emptied by delete/update within a transaction" assuming that user can anytime rollback. Point seems correct.in/2007/01/when-should-i-rebuild-my-. 2007 at 12:21:00 AM GMT+05:30 Sachin said. Thanks Vaibhav. SQL> select leaf_blocks from user_indexes where index_name='INDX_MYTB'. LEAF_BLOCKS ----------41 Regards. 5 end. Index analyzed. LEAF_BLOCKS ----------41 SQL> analyze index indx_mytb compute statistics. SQL> select leaf_blocks from user_indexes where index_name='INDX_MYTB'.. ============================= Testcase 2 -. Table created. SQL> commit.novapdf. Sachin Sachin January 10. 3 commit.blogspot. And if rollback happens. emptied blocks doesnot go to freelist within a transaction. To put a logical reaosn for viewers.com/) 5 of 6 4/18/2013 5:44 AM . Commit complete. SQL> select leaf_blocks from user_indexes where index_name='INDX_MYTB'. But the point remains that the space can be reused (outside the trsansaction which is responsible for delete). 4 insert into mytb select * from all_objects. SQL> create table mytb as select * from all_objects. it will need that space. SQL> create index indx_mytb on mytb(object_name). 2007 at 6:58:00 AM GMT+05:30 Print to PDF without this message by purchasing novaPDF (http://www. Index created....Sachin Arora's Blog: When should I rebuild my indexes? http://oracle-online-help. 6/ PL/SQL procedure successfully completed. Vaibhav January 10. Table dropped. Thanks.delete and insert are performed in a differenr transactions SQL> drop table mytb. so assuming a rollback.

novapdf..com/) 6 of 6 4/18/2013 5:44 AM .blogspot.in/2007/01/when-should-i-rebuild-my-.Sachin Arora's Blog: When should I rebuild my indexes? http://oracle-online-help.. Post a Comment Newer Post Subscribe to: Post Comments (Atom) Home Older Post design by : amdg Print to PDF without this message by purchasing novaPDF (http://www.