well, the blocks in dba_tables is the number of blocks below the HWM "as of the last analyze". It is not 100% accurate -- since it is current as of the last analyze. Here is an example with comments embedded:
ops$tkyte@8i> create table emp as select * from scott.emp;
Table created.
ops$tkyte@8i> select blocks, empty_blocks from dba_tables where owner = USER;
BLOCKS EMPTY_BLOCKS
---------- ------------
Initally, blocks is NULL, we have to analyze to fill it in.. We can see the number of allocated blocks with:
ops$tkyte@8i> select blocks, bytes from dba_extents where owner = USER;
BLOCKS BYTES
---------- ----------
64 524288
ops$tkyte@8i> analyze table emp compute statistics;
Table analyzed.
ops$tkyte@8i> select blocks, empty_blocks from dba_tables where owner = USER;
BLOCKS EMPTY_BLOCKS
---------- ------------
1 62
Now, we can see that 1 block has data and 62 are emtpy (the last block is an extent map -- there are 64 blocks allocated, 1 with data, 1 with a map and 62 empty ones).
ops$tkyte@8i> insert into emp select * from emp;
14 rows created.
ops$tkyte@8i> insert into emp select * from emp;
28 rows created.
ops$tkyte@8i> insert into emp select * from emp;
56 rows created.
ops$tkyte@8i> insert into emp select * from emp;
112 rows created.
So, now we've made the table larger -- lets see what happens:
ops$tkyte@8i> select blocks, empty_blocks from dba_tables where owner = USER;
BLOCKS EMPTY_BLOCKS
---------- ------------
1 62
ops$tkyte@8i> select blocks, bytes from dba_extents where owner = USER;
BLOCKS BYTES
---------- ----------
64 524288
that data did not change -- still looks like 1 block under the HWM but really:
ops$tkyte@8i> analyze table emp compute statistics;
Table analyzed.
ops$tkyte@8i> select blocks, empty_blocks from dba_tables where owner = USER;
BLOCKS EMPTY_BLOCKS
---------- ------------
3 60
There are 3. A full scan would hit 3 blocks now, not 1.
--
Thanks,
Thomas Kyte asktom_us@oracle.com
Oracle Service Industries
Oracle tips and papers </code>
https://asktom.oracle.com/magazine-archive.htm <code>