Ok, when you turn on autotrace in sqlplus you can see these stats.
Lets run a query:
ops$tkyte@ORA817.US.ORACLE.COM> set autotrace traceonly statistics
ops$tkyte@ORA817.US.ORACLE.COM>
ops$tkyte@ORA817.US.ORACLE.COM> select * from emp;
14 rows selected.
Statistics
----------------------------------------------------------
0 recursive calls
4 db block gets
2 consistent gets
0 physical reads
0 redo size
1979 bytes sent via SQL*Net to client
430 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
14 rows processed
Here we had 4 db block gets. Those were blocks read in CURRENT MODE. The blocks that were read are actually the blocks that tell us how to FULL SCAN the dept table (data dictionary type of information). We need to get that in CURRENT MODE (as of RIGHT NOW) to get an accurate picture of what the table looks like.
We also had 2 consistent gets -- these are blocks we read in "consistent read" mode -- also known as query mode. This means we were reading them as of the POINT IN TIME the query began. See
</code>
http://docs.oracle.com/cd/A81042_01/DOC/server.816/a76965/c23cnsis.htm#17882 <code>
for a great discussion of this.
Now, if we do a delete:
ops$tkyte@ORA817.US.ORACLE.COM> delete from emp;
14 rows deleted.
Statistics
----------------------------------------------------------
0 recursive calls
20 db block gets
1 consistent gets
0 physical reads
4220 redo size
1009 bytes sent via SQL*Net to client
796 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
14 rows processed
we do lots more db block gets -- why? because in order to delete the data we need to get the block in CURRENT MODE, as it exists right then.
why did we do a consistent get? because the "read" part of the delete uses the consistent read mechanism -- we only delete data that existed in the table as of the point in time the delete began. Consider if DEPT was a 1,000,000 row table instead. It'll take a while to delete all of those rows. As you are deleting however, other sessions are inserting and committing data. This consistent read mechanism makes it so that we only delete the rows that existed WHEN WE BEGAN the delete. We will not delete this new data being inserted.
followup to comment one belowThink of the delete being processed like this:
for x in ( select rowid from emp ) --- CONSISTENT GETS
loop
delete from emp where rowid = x.rowid; --- CURRENT MODE GETS
end loop;
that is in effect what is happening. the READ portion of the delete, the portion of the delete that finds rows to actually remove reads the table in consistent read mode. For each row that it finds that it wants to delete, it does a CURRENT MODE get on that block to get the row as it exists now (so as to modify that row).
Consider what happens when we delete 1, 5, 10, and all rows from emp:
scott@ORA817.US.ORACLE.COM> set autotrace traceonly statistics;
scott@ORA817.US.ORACLE.COM> select * from emp;
14 rows selected.
Statistics
----------------------------------------------------------
0 recursive calls
4 db block gets
2 consistent gets
0 physical reads
0 redo size
1979 bytes sent via SQL*Net to client
430 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
14 rows processed
scott@ORA817.US.ORACLE.COM>
scott@ORA817.US.ORACLE.COM> delete from emp where rownum <=1;
1 row deleted.
Statistics
----------------------------------------------------------
0 recursive calls
7 db block gets
1 consistent gets
0 physical reads
516 redo size
850 bytes sent via SQL*Net to client
564 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1 rows processed
scott@ORA817.US.ORACLE.COM> rollback;
Rollback complete.
scott@ORA817.US.ORACLE.COM> delete from emp where rownum <=5;
5 rows deleted.
Statistics
----------------------------------------------------------
0 recursive calls
11 db block gets
1 consistent gets
0 physical reads
1660 redo size
850 bytes sent via SQL*Net to client
564 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
5 rows processed
scott@ORA817.US.ORACLE.COM> rollback;
Rollback complete.
scott@ORA817.US.ORACLE.COM> delete from emp where rownum <=10;
10 rows deleted.
Statistics
----------------------------------------------------------
0 recursive calls
16 db block gets
1 consistent gets
0 physical reads
3080 redo size
850 bytes sent via SQL*Net to client
565 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
10 rows processed
scott@ORA817.US.ORACLE.COM> rollback;
Rollback complete.
scott@ORA817.US.ORACLE.COM> delete from emp where rownum <=15;
14 rows deleted.
Statistics
----------------------------------------------------------
0 recursive calls
22 db block gets
1 consistent gets
0 physical reads
4272 redo size
850 bytes sent via SQL*Net to client
565 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
14 rows processed
scott@ORA817.US.ORACLE.COM> rollback;
Rollback complete.
Each one reads blocks in current mode with a cardinality that relates to the number of rows deleted.