Skip to Main Content
  • Questions
  • finding the size in bytes of an index

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Lalita .

Asked: May 02, 2000 - 1:21 pm UTC

Last updated: May 26, 2004 - 11:36 am UTC

Version:

Viewed 1000+ times

You Asked

How can we find the exact size (number of bytes)
of an index segment




and Tom said...



well -- you need to be a little more specific. We can find the allocated space (how much space has been carved out to be used only by this index segment) and we can find the amount of space within that space that is/has been actually used (the 'high water mark').

Consider -- I have an index T_IDX:

ops$tkyte@8i> select bytes, blocks, extents from user_segments where segment_name = 'T_IDX';

BYTES BLOCKS EXTENTS
---------- ---------- ----------
1048576 128 2

There is the amount of space dedicated to this segment. 128 blocks.


If I analyze the index (estimate on a big one)

ops$tkyte@8i> analyze index t_idx compute statistics;
Index analyzed.

ops$tkyte@8i> select blevel, leaf_blocks, num_rows from user_indexes where index_name = 'T_IDX';

BLEVEL LEAF_BLOCKS NUM_ROWS
---------- ----------- ----------
1 89 20252


I find that there really are about 89 blocks in use. These stats will remain in the data dictonary until i re-analyze or delete the stats.

Further, if I "validate" the index, I can get a little more data:

ops$tkyte@8i> analyze index t_idx validate structure;
Index analyzed.

ops$tkyte@8i> select height, blocks, lf_blks, br_blks, btree_space, used_space from index_stats where name = 'T_IDX';

HEIGHT BLOCKS LF_BLKS BR_BLKS BTREE_SPACE USED_SPACE
---------- ---------- ---------- ---------- ----------- ----------
2 128 89 1 719672 634258

That shows that of the allocated and used space -- I have about 700k, The space ACTUALLY in use in that allocated and used space is about 630k. This is exactly what I expected as this is a brand new index I just created and the pctfree was set to 10% so 10% of each block has been reserved for furture inserts into these blocks --700k - 10% is 630k. Note that the index stats view "empties" itself after you disconnect -- you would have to save this data into another table if you wanted to analyze it further.



Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Comparing index_stats with show_space output

A reader, May 25, 2004 - 5:59 pm UTC

Hi Tom, 

I used your show_space procedure to get the space used by an index. The used space numbers don't match with what's in index_stats. Why is that? Which number is right? Does it even make sense to compare the two outputs?

SQL> exec show_space('PK_DEVICE',user,'index');
Unformatted Blocks .....................               0
FS1 Blocks (0-25)  .....................               0
FS2 Blocks (25-50) .....................               1
FS3 Blocks (50-75) .....................               0
FS4 Blocks (75-100).....................               0
Full Blocks        .....................               0
Total Blocks............................             640
Total Bytes.............................       5,242,880
Total MBytes............................               5
Unused Blocks...........................             627
Unused Bytes............................       5,136,384
Last Used Ext FileId....................              12
Last Used Ext BlockId...................          21,128
Last Used Block.........................              13


SQL> analyze index pk_device validate structure;

Index analyzed.

SQL> select BTREE_SPACE,used_space from index_stats;

BTREE_SPACE USED_SPACE
----------- ----------
       8000       2256

According to show_space, used space is 5,242,880 - 5,136,384 = 106416 bytes whereas according to index_stats its 2256 bytes?

Thanks.

 

Tom Kyte
May 25, 2004 - 6:54 pm UTC

you are using ASSM, ASSM takes it's own bite of a tablespace to manage the space (bitmap blocks).


index stats -- shows you the space used by the index data.
show space -- shows you the space used by the index segment.

Table Size

Yogesh, May 26, 2004 - 8:57 am UTC

Can we even find the size of the table in same manner ?

Tom Kyte
May 26, 2004 - 11:36 am UTC

analyze the table, you'll see info in user_tables for it. like num_rows, avg_space, avg_row_len, etc.