05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

484<br />

CHAPTER 11 ■ INDEXES<br />

12 /<br />

blocks on freelist = 0<br />

PL/SQL procedure successfully completed.<br />

ops$tkyte@ORA10GR1> select leaf_blocks from user_indexes<br />

2 where index_name = 'BIG_TABLE_PK';<br />

LEAF_BLOCKS<br />

-----------<br />

1043<br />

Before we perform this mass deletion, we have no blocks on the freelist <strong>and</strong> there are<br />

1,043 blocks in the “leafs” of the index, holding data. Now, we’ll perform the delete <strong>and</strong><br />

measure the space utilization again:<br />

ops$tkyte@ORA10GR1> delete from big_table where id commit;<br />

Commit complete.<br />

ops$tkyte@ORA10GR1> declare<br />

2 l_freelist_blocks number;<br />

3 begin<br />

4 dbms_space.free_blocks<br />

5 ( segment_owner => user,<br />

6 segment_name => 'BIG_TABLE_PK',<br />

7 segment_type => 'INDEX',<br />

8 freelist_group_id => 0,<br />

9 free_blks => l_freelist_blocks );<br />

10 dbms_output.put_line( 'blocks on freelist = ' || l_freelist_blocks );<br />

11 dbms_stats.gather_index_stats<br />

12 ( user, 'BIG_TABLE_PK' );<br />

13 end;<br />

14 /<br />

blocks on freelist = 520<br />

PL/SQL procedure successfully completed.<br />

ops$tkyte@ORA10GR1> select leaf_blocks from user_indexes<br />

2 where index_name = 'BIG_TABLE_PK';<br />

LEAF_BLOCKS<br />

-----------<br />

523<br />

As we can see, over half of the index is on the freelist now (520 blocks) <strong>and</strong> there are only<br />

523 leaf blocks. If we add 523 <strong>and</strong> 520, we get the original 1043. This means the blocks are<br />

totally empty <strong>and</strong> ready to be reused (blocks on the freelist for an index must be empty, unlike

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!