Thread: How dangerous is index rebuild?


Permlink Replies: 17 - Pages: 2 [ 1 2 | Next ] - Last Post: Jan 30, 2008 10:08 PM Last Post By: Virag Sharma
Chen Shapira

Posts: 396
Registered: 04/09/07
How dangerous is index rebuild?
Posted: Jan 29, 2008 4:51 PM
Click to report abuse...   Click to reply to this thread Reply
I've heard that rebuilding an index can in some cases cause queries using this index to run slower and do more buffer gets (after the rebuild, not during). Is this true?

A test case showing this will be greatly appreciated.
Stellios

Posts: 804
Registered: 06/24/07
Re: How dangerous is index rebuild?
Posted: Jan 29, 2008 5:16 PM   in response to: Chen Shapira in response to: Chen Shapira
Click to report abuse...   Click to reply to this thread Reply
Looking at it from another angle I read the subject and thought dangerous if you don't perform a "rebuild online" and even then you may run into the many "rebuild online" bugs.
santhanam_oradba

Posts: 113
Registered: 12/02/07
Re: How dangerous is index rebuild?
Posted: Jan 29, 2008 5:34 PM   in response to: Stellios in response to: Stellios
Click to report abuse...   Click to reply to this thread Reply
actually u have to rebuild index on following conditions.

select height from index_stats ;

if height > 20

u have to rebuid the index.

select (del_lf_rows/lf_rows)*100 from index_stats ;

if (del_lf_rows/lf_rows)*100 > 20% the rebuild the index;

during index rebuild u can reclaim space and improve performance by eliminating fragmentation and reducing the blocks used.

anyone please check what i said is right or not.

yingkuan

Posts: 10,898
Registered: 10/08/98
Re: How dangerous is index rebuild?
Posted: Jan 29, 2008 6:16 PM   in response to: santhanam_oradba in response to: santhanam_oradba
Click to report abuse...   Click to reply to this thread Reply
INDEX_STATS will not populated unless you do ANALYZE INDEX .. VALIDATE STRUCTURE.

Do you really have any index that have height > 20 ?

What's your Oracle block size? How many index records per block do you have?

You can find the index height from DBA_INDEXES, without validate structure of each indexes.

height=BLEVEL+1
Justin Cave

Posts: 24,284
Registered: 10/11/99
Re: How dangerous is index rebuild?
Posted: Jan 29, 2008 6:19 PM   in response to: santhanam_oradba in response to: santhanam_oradba
Click to report abuse...   Click to reply to this thread Reply
I would strongly suggest spending some time reading Richard Foote's presentation on index internals "Rebuilding the Truth"

http://richardfoote.files.wordpress.com/2007/12/index-internals-rebuilding-the-truth.pdf

The metrics you've posted are not particularly accurate. There are very few cases where b-tree indexes need to be rebuilt, none of which are captured by these criteria.

As for the original poster, yes, rebuilding indexes can force Oracle to do additional work in the days after the rebuild as it does a variety of block splits in order to get back to the "steady state" configuration.

Justin
Chen Shapira

Posts: 396
Registered: 04/09/07
Re: How dangerous is index rebuild?
Posted: Jan 29, 2008 6:25 PM   in response to: Justin Cave in response to: Justin Cave
Click to report abuse...   Click to reply to this thread Reply
Thanks Justin, this was exactly the information I was looking for.
Stellios

Posts: 804
Registered: 06/24/07
Re: How dangerous is index rebuild?
Posted: Jan 29, 2008 6:44 PM   in response to: santhanam_oradba in response to: santhanam_oradba
Click to report abuse...   Click to reply to this thread Reply
I was merely pointing out a danger in running the "index rebuild" command especially when there are other users logged in and accessing the table and index eing rebuild. I am aware there are other conditions that constitute a rebuild.
Virag Sharma

Posts: 2,332
Registered: 10/15/99
Re: How dangerous is index rebuild?
Posted: Jan 29, 2008 6:59 PM   in response to: Chen Shapira in response to: Chen Shapira
Click to report abuse...   Click to reply to this thread Reply
I've heard that rebuilding an index can in some cases
cause queries using this index to run slower and do
more buffer gets (after the rebuild, not during). Is this true?

Not sure what version of oracle you using !!
Rebuild index online, it has less impact on query, so try to rebuild Index online on peak-off time

Check following blog , to know experience about rebuild indexes

Anecdote about Rebuilding Indexes
Chen Shapira

Posts: 396
Registered: 04/09/07
Re: How dangerous is index rebuild?
Posted: Jan 29, 2008 7:07 PM   in response to: Virag Sharma in response to: Virag Sharma
Click to report abuse...   Click to reply to this thread Reply
Hoisted by my own petard!

I'm the one who wrote the anecdote. Management is very happy with the results of the rebuild and wants me to rebuild indexes automatically on regular basis, to prevent the next such problem.

I'm a bit worried about the rebuild because I'm not sure we fully acknowledge the problems it may cause in the system. After all, the fact that something helps when there is a problem doesn't mean it can't cause problems in a healthy system. We don't take anti-headache medicine every day to prevent headaches.

Thank you, and I'll appreciate any opinions regarding regular index rebuilds.
Amardeep Sidhu

Posts: 1,296
Registered: 10/27/06
Re: How dangerous is index rebuild?
Posted: Jan 29, 2008 11:06 PM   in response to: Chen Shapira in response to: Chen Shapira
Click to report abuse...   Click to reply to this thread Reply
Hoisted by my own petard!

lol...after seeing the link..I quickly scrolled down to see whether you have replied or not :)
Virag Sharma

Posts: 2,332
Registered: 10/15/99
Re: How dangerous is index rebuild?
Posted: Jan 30, 2008 9:56 AM   in response to: Chen Shapira in response to: Chen Shapira
Click to report abuse...   Click to reply to this thread Reply
Hoisted by my own petard!

I'm the one who wrote the anecdote. Management is


Lesson learned , recognize people by there name not by there blog name :-)

very happy with the results of the rebuild and wants
me to rebuild indexes automatically on regular basis,
to prevent the next such problem.

1) If nothing is broken don't fix it , but be proactive i.e don't wait till things break
2) Test case work on Ideal Scenario, but not always work on production

As per manufacturer/car expert, my car suppose to give mileage of 16 Km/Liter , but it gives only 10-12 km/liter, because it depend on Road condition , Traffic condition and of course driver.

We use to rebuild index regular basis on criteria of, deleted entries represent 30 % or depth go above 4. There are only few indexes, which have depth of 4 , all others indexes are below that. To get this information, we need to run ANALYZE ... VALIDATE STRUCTURE , that look too recourse consuming. So, we run ANALYZE ... VALIDATE STRUCTURE command on test environment immediate after refreshing from production and before running data masking script. After ANALYZE , we get list of Indexes which are candidate for index rebuild. Mostly we get very few indexes and those indexes are on tables which are heart and soul of application :-) .

We rebuild indexes online on off-peak time For example Saturday 7-8:00 PM PST, with no logging. After rebuild we collect stats on tables(for which we rebuild indexes) with cascade=true and make indexes logging.

I wonder, We collect stats same way regularly, if index rebuild is myth and above criteria not work well, then why execution plan changed after few weeks and after index rebuild, why good execution plan come into picture.

Not sure , how many Database with very high volume of DML exists that never need index rebuild !!!!!!
Jonathan Lewis

Posts: 1,911
Registered: 01/23/07
Re: How dangerous is index rebuild?
Posted: Jan 30, 2008 11:37 AM   in response to: Chen Shapira in response to: Chen Shapira
Click to report abuse...   Click to reply to this thread Reply
As far as rebuilding lots of indexes on autopilot is concerned, you might want to read the following note:

http://jonathanlewis.wordpress.com/2007/09/16/index-rebuild/

The more you rebuild, the greater your chances of hitting Oracle error ORA-01410 at random intervals.

In answer to your original question, though - any index rebuild may change the blevel and leaf-block count of the index, which changes the arithmetic controlling whether or not the optimizer will use it. Any such change could cause a change of execution path - which may, or may not, be an improvement.

Note that an index rebuild often reduces the size of an index, temporarily - but may increase the size of an index.

Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk
Jonathan Lewis

Posts: 1,911
Registered: 01/23/07
Re: How dangerous is index rebuild?
Posted: Jan 30, 2008 11:40 AM   in response to: santhanam_oradba in response to: santhanam_oradba
Click to report abuse...   Click to reply to this thread Reply
actually u have to rebuild index on following
conditions.

select height from index_stats ;

if height > 20

u have to rebuid the index.


If you have an index with a height greater than 20, you certainly might want to rebuild it once - but you would certainly want to make sure that this was necessary before you did so, and you would probably want to find out why it had got to such a state.

For an indication on how indexes can degenerate, you might like to read this (not entirely serious) note on my website:

http://www.jlcomp.demon.co.uk/22_how_high.html

Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk
Chen Shapira

Posts: 396
Registered: 04/09/07
Re: How dangerous is index rebuild?
Posted: Jan 30, 2008 11:45 AM   in response to: Virag Sharma in response to: Virag Sharma
Click to report abuse...   Click to reply to this thread Reply
We noticed no change of the execution plan after rebuild. The plan was exactly the same, but an index scan that required lots of block reads and was very costly, now takes significantly less. Which is exactly what we needed!
Chen Shapira

Posts: 396
Registered: 04/09/07
Re: How dangerous is index rebuild?
Posted: Jan 30, 2008 11:50 AM   in response to: Jonathan Lewis in response to: Jonathan Lewis
Click to report abuse...   Click to reply to this thread Reply
Thank you Jonathan!

ORA-01410 is indeed a risk we did not think of at all.

We did take into account the fact that the index will actually take more space eventually. Now that I think of it - taking more space may mean that range scans will read more blocks and therefore take more time than before... In addition to the fact that having different execution plans for key queries every month will not be fun at all.

Thanks again for the useful information.
Legend
Guru Guru : 2500 - 1000000 pts
Expert Expert : 1000 - 2499 pts
Pro Pro : 500 - 999 pts
Journeyman Journeyman : 200 - 499 pts
Newbie Newbie : 0 - 199 pts
Oracle ACE Director
Oracle ACE Member
Oracle Employee ACE
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums