Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: ACTUAL INDEX SIZE
SQL: Script to determine INDEX storage requirement
Last Updated on 28-JUL-97
The following formula and associated sample demonstrate a method of
determining index storage size requirements on a fully populated table.
A commonly used formula that I've seen used and that generally errors on the conservative side is detailed below. This formula returns the index size in DB blocks. Also, this formula is only valid if the CREATE INDEX is issued on a fully populated table. Precreating the index on an empty table and subsequently populating the table will require storage requirements greater than these calulations.
Forumla:
floor ( (( db_block_size - 113 - ( initrans * 23 )) * (1 - (percent_free / 100 ))) / (( 10 + uniqueness ) + number_col_index + ( total_col_length )) )
Legend:
db_block_size => Actual number of bytes available in the block
Value: select to_number(value) from v$parameter where name = 'db_block_size'
initrans => Bytes used for each initrans Value: The default for indexes is 2 (see INITRANS parameter of CREATE INDEX) Note: In 7.2 and higher may be better to multiply this value by 24 rather than 23
percent_free => Percent free specified for the index
Value: The default for indexes is 10 (see PCTFREE parameter of CREATE INDEX)
uniqueness => If the index is unique or not (1 for unique, 0 for not unique)
Value: Self-explanatory, will you having repeating values or not
number_col_index => Number of columns in the index
Value: Self-explanatory, how many columns will be in the index key
total_col_length => Estimated length of the index columns Value: select avg(nvl(vsize(col_name1),0))+avg(nvl(vsize(col_name2),0)) from tab_name
Sample:
set serveroutput on
declare
row_count number;
db_block_size number;
initrans number := 2; -- Assuming default INITRANS percent_free number := 10; -- Assuming default PCTFREE uniqueness number := 1; -- Assuming that the index will be UNIQUE number_col_index number := 2; -- Assuming index is based on EMPNO and ENAMEtotal_col_length number;
(( row_count / (( floor ( (( db_block_size - 113 - ( initrans * 23 )) * (1 - (percent_free / 100 ))) / (( 10 + uniqueness ) + number_col_index + ( total_col_length )) ) )) ) * 2 )
into size_in_blocks
from dual;
dbms_output.put_line('Size in blocks: '||round(size_in_blocks));
end;
/
Paul in VT Received on Tue Oct 12 1999 - 14:06:27 CDT