Documente Academic
Documente Profesional
Documente Cultură
Agenda
The Goal
Mythology and other interesting anti-facts and facts
Reorganizing Tables
Offline
Online
Entire table
Shrinking Space
Purging
Reorganizing Indexes
Offline
Online
Entire rebuild
Coalesce
Goal
The goal
The Goal is to not have to reorganize
Do not get into ground hog day mode
There are long term solutions for many of the
common issues
The trick is understanding why something happens,
so you can develop a corrective action
EG: we purge old data, this leaves table 30%
empty, we want to reclaim this space
Mythology
And other interesting anti-facts and facts
(found in that inter-web thingy)
Indexes
If this were true, all indexes would grow,
and grow and grow and grow.
Oracle index nodes are not physically deleted when table rows are deleted, nor are the entries
removed from the index. Rather, Oracle "logically" deletes the index entry and leaves "dead"
nodes in the index tree where that may be re-used if another adjacent entry is required.
However, when large numbers of adjacent rows are deleted, it is highly unlikely that Oracle will
have an opportunity to re-use the deleted leaf rows, and these represent wasted space in the
index. In addition to wasting space, large volumes of deleted leaf nodes will make index fastfull scans run for longer periods.
Myth1.sql
Indexes
If this were true, all indexes on sequence
populated columns and most on
dates/timestamps would be unbalanced.
Hence, an Oracle index may have four levels, but only in those areas of the index tree where
the massive inserts have occurred. Oracle indexes can support many millions of entries in
three levels, and any Oracle index that has four or more levels would benefit from rebuilding.
Note that Oracle indexes will spawn to a fourth level only in areas of the index where a
massive insert has occurred, such that 99% of the index has three levels, but the index is
reported as having four levels.
Indexes
Add to this the various node splitting algorithms Oracle uses for non-sequential inserts and updates and
you can easily see why clustering factor increases and can become out of sync with reality. An index
rebuild coalesces nodes and aligns them with the underlying table. Now, in many cases this reduces the
clustering factor,
Indexes
DEL_LF_ROWS is very unreliable as a
method to detect an index that needs to be
rebuilt.
The second rule of thumb is that the deleted leaf rows should be less than 20%
of the total
number of leaf
rows. An excessive
number
of deleted leaf
rows
Contrary
to popular
belief
deleted
rows
indicates that a high number of deletes or updates have occurred to the index
are in
fact tocleaned
out
column(s). The index should
be rebuilt
better balance
the tree. The
INDEX_STATS table can be queried to determine if there are excessive deleted
An index that is most in need of a rebuild
leaf rows in relation to the total number of leaf rows.
from time to time will not make itself known
using this technique.
An index that will be perfectly fine in a
couple of minutes will be flagged
erroneously
Myth3.sql
Indexes
If the indexed data arrives randomly
(last_name for example) this is utter nonsense. The index might end up 50% utilized
andthat
a rebuild
could
makeinsert,
it 90%
utilized
Indexes
undergo
frequent
update
and
for the next
of minutes!
delete operations
needcouple
to be rebuilt
regularly to
prevent fragmentation
Think sweeper index from prior slide.
They are candidates for period coalesce or
rebuilds.
Indexes
This is why atomic_refresh => false on a
materialized view might be relevant.
This is why you want to consider
partitioning
other physical
structures
Index
space is and
not reused
within a transaction.
if you
have two indexwill
segments,
and flipthe
Hence
DELETE+INSERT
tend to increase
flop
this wont be an issue.
size of
thepartitions,
index greatly
Knowing that this is true is the first step to
solving the problem. Or at least identifying
when you might want to coalesce/rebuild
fact1.sql
Indexes
If you leave a few stragglers behind
delete most but not all old entries then
the left hand side of the index might
Sweeper
indexes are
candidates for
periodic
rebuilds
order to either
become
brown.
Since
you
areininserting
monotonically values only the right hand
1. Reclaim space
gets
hit t order by id style queries
2. Improve the performanceside
of select
id from
You could rebuild or coalesce forever. Or
you could fix it with a reverse key index
(but only if the only goal was to reclaim
space! Range scan issue)
Indexes
index key
Indexes
corollary
This isfalse
in most all general cases. It is
true in one special case when you access
only the index and not the table and you do
so during a RANGE SCAN (not a fast full
scan)
Rebuild indexes that you range scan in a
tablespace
withIOs
a larger
than
default
Most logical
will blocksize
be against
thethe
table,
blocksize. This will
reduce
logical
IOs
by
50%.
not the index
And the detrimental side effects?
Increased contention. Special memory set
aside that cannot be used for other stuff.
More management for you. Myth4.sql
How To
For
Tables
Offline
Online EE only
Entire table
Shrinking Space
Purging
Mostly online
Materialized view trick, all editions
Redef.sql
DBMS_REDEFINITION
In the past
shrink.sql
How To
For
Indexes
Itll go better
Itll not change at all
Itll be much worse than it was before
Do an index rebuild
Come back tomorrow and verify you did more good then harm
Rebuilding can be good
Coalescing even better (online, without the overhead)
Most of the time, it is not even needed and can do more harm
then good
Does not mean Ive said you never have to rebuld an index
Bitmaps
Secondary indexes on IOTs
Text indexes for example
Offline
Online
Entire rebuild
Coalesce
swap.sql
Rebuild
Optionally online
Need approximately 2 times the storage
Use existing index to copy from
o Skip sort
o Less physical IO
Coalesce
Need only current storage
Online
Combines logically adjacent index blocks as much as
possible
compare.sql
Q&A