SQL> @ver
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
SQL> select index_name, null partition_name, num_rows, s.blocks, leaf_blocks, status
from dba_indexes i, dba_segments s where i.index_name = s.segment_name and table_name='MUSE' and partitioned = 'NO'
union select index_name, i.partition_name, num_rows, s.blocks, leaf_blocks, status
from dba_ind_partitions i, dba_segments s where i.partition_name = s.partition_name and index_name like 'MUSE%';
INDEX_NAME PARTITION_NAME NUM_ROWS BLOCKS LEAF_BLOCKS STATUS
------------------------------ ------------------------------ ---------- ---------- ----------- --------
MUSE_CODE_I CODE_P1 1500000 4224 4137 USABLE
MUSE_CODE_I CODE_P2 1500000 4352 4177 USABLE
MUSE_ID_I 3000000 9216 8633 VALID
SQL> select n.name, s.value from v$mystat s, v$statname n where s.statistic# = n.statistic# and (n.name = 'redo size' or n.name = 'db block gets') ;
NAME VALUE
-------------------- ----------
db block gets 3
redo size 776
SQL> select n.name, s.value from v$mystat s, v$statname n where s.statistic# = n.statistic# and (n.name = 'redo size' or n.name = 'db block gets') ;
NAME VALUE
-------------------- ----------
db block gets 71
redo size 14240
SQL> select index_name, null partition_name, num_rows, leaf_blocks, status
from dba_indexes i where table_name='MUSE' and partitioned = 'NO'
union select index_name, i.partition_name, num_rows, leaf_blocks, status
from dba_ind_partitions i where index_name like 'MUSE%';
INDEX_NAME PARTITION_NAME NUM_ROWS LEAF_BLOCKS STATUS
------------------------------ ------------------------------ ---------- ----------- --------
MUSE_CODE_I CODE_P1 1500000 4137 UNUSABLE
MUSE_CODE_I CODE_P2 1500000 4177 UNUSABLE
MUSE_ID_I 3000000 8633 UNUSABLE
SQL> select index_name, null partition_name, num_rows, s.blocks, leaf_blocks, status
from dba_indexes i, dba_segments s where i.index_name = s.segment_name and table_name='MUSE' and partitioned = 'NO'
union select index_name, i.partition_name, num_rows, s.blocks, leaf_blocks, status
from dba_ind_partitions i, dba_segments s where i.partition_name = s.partition_name and index_name like 'MUSE%';
INDEX_NAME PARTITION_NAME NUM_ROWS BLOCKS LEAF_BLOCKS STATUS
------------------------------ ------------------------------ ---------- ---------- ----------- --------
MUSE_CODE_I CODE_P1 1500000 4224 4137 USABLE
MUSE_CODE_I CODE_P2 1500000 4352 4177 USABLE
MUSE_ID_I 3000000 9216 8633 VALID
SQL> select n.name, s.value from v$mystat s, v$statname n where s.statistic# = n.statistic# and (n.name = 'redo size' or n.name = 'db block gets') ;
NAME VALUE
-------------------- ----------
db block gets 3
redo size 776
SQL> alter table muse drop partition muse1 update global indexes;
SQL> select n.name, s.value from v$mystat s, v$statname n where s.statistic# = n.statistic# and (n.name = 'redo size' or n.name = 'db block gets') ;
NAME VALUE
-------------------- ----------
db block gets 56376
redo size 44149272--可以发现产生的redo size很多。
SQL> select index_name, null partition_name, num_rows, s.blocks, leaf_blocks, status
from dba_indexes i, dba_segments s where i.index_name = s.segment_name and table_name='MUSE' and partitioned = 'NO'
union select index_name, i.partition_name, num_rows, s.blocks, leaf_blocks, status
from dba_ind_partitions i, dba_segments s where i.partition_name = s.partition_name and index_name like 'MUSE%';
INDEX_NAME PARTITION_NAME NUM_ROWS BLOCKS LEAF_BLOCKS STATUS
------------------------------ ------------------------------ ---------- ---------- ----------- --------
MUSE_CODE_I CODE_P1 1500000 4224 4137 USABLE
MUSE_CODE_I CODE_P2 1500000 4352 4177 USABLE
MUSE_ID_I 3000000 9216 8633 VALID
SQL> set autot traceonly ;
SQL> select min(id) from muse;
Execution Plan
----------------------------------------------------------
Plan hash value: 2104594370
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 6 | | |
| 2 | INDEX FULL SCAN (MIN/MAX)| MUSE_ID_I | 1 | 6 | 3 (0)| 00:00:01 |
----------------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
2787 consistent gets
0 physical reads
0 redo size
528 bytes sent via SQL*Net to client
520 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed--可以发现由于前面的空块没有重用,查询最小值,从left扫描,要读许多空块。
SQL> set autot traceonly ;
SQL> select min(id) from muse;
Execution Plan
----------------------------------------------------------
Plan hash value: 2104594370
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 6 | | |
| 2 | INDEX FULL SCAN (MIN/MAX)| MUSE_ID_I | 1 | 6 | 3 (0)| 00:00:01 |
----------------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
154 consistent gets
0 physical reads
0 redo size
528 bytes sent via SQL*Net to client
520 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-768592/ ,如需转载,请注明出处,否则将追究法律责任。