 |
|
Oracle: Coalesce vs. deallocate unused space
Oracle Database Tips by Donald Burleson
|
Question: What is the
difference between coalesce and "deallocate unused space"?
Answer: Both the
coalesce and "deallocate unused space" commands serve to
free-up space, but they do it in different ways:
Deallocate unused space
Oracle notes that the "deallocate
unused space" clause is used to to explicitly deallocate unused
space at "the end" of a segment and makes that space available
for other segments within the tablespace.
alter table xxx
deallocate unused space;
alter index xxx deallocate unused space;
Internally, Oracle deallocates
unused space beginning from the end of the objects (allocated
space) and moving downwards toward the beginning of the object,
continuing down until it reaches the high water mark (HWM).
The high-water mark for the table determines the amount of data
that is stored in the table. For indexes, "deallocate unused space" coalesces all leaf blocks
within same branch of b-tree, and quickly frees up index leaf
blocks for use.
The coalesce statement
Unlike the "deallocate unused
space" syntax, which removes space above the high-water mark,
"coalesce" puts together discontiguous fragmented extents.
There are two type of space
fragmentation in Oracle. First is the honeycomb
fragmentation, when the free extents are side by side, and the
"Swiss Cheese" fragmentation, when the extents are separated by
live segments.
alter table xxx
coalesce;
alter index xxx coalesce;
The coalesce partition syntax
For partitioned tables, Oracle
provides the "Coalesce partition" syntax.
alter table xxx
modify partition yyy
coalesce subpartition;
alter table xxx
modify partition yyy
coalesce partition;
The
Oracle docs note that the
coalesce partition syntax behave differently, depending on the
type of partition:
"When a hash partition is coalesced, its
contents are redistributed into one or more remaining partitions determined
by the hash function.
The specific partition that is coalesced is
selected by the database, and is dropped after its contents have been
redistributed."