Friday 12 August 2016

What is the difference between coalesce and "deallocate unused space"?

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:

I. 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.

SQL> alter table test_tab_01 deallocate unused space;
SQL> alter index test_tab_01 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.

II. 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.

SQL> alter table test_tab_01 coalesce;
SQL> alter index test_tab_01 coalesce;


Thanks & Comments Plz