点击(此处)折叠或打开
-
sys@TESTDB12>@$ORACLE_HOME/sqlplus/admin/plustrce.sql
-
sys@TESTDB12>drop role plustrace;
-
drop role plustrace
-
*
-
ERROR at line 1:
-
ORA-01919: role 'PLUSTRACE' does not exist
-
sys@TESTDB12>create role plustrace;
-
Role created.
-
sys@TESTDB12>
-
sys@TESTDB12>grant select on v_$sesstat to plustrace;
-
Grant succeeded.
-
sys@TESTDB12>grant select on v_$statname to plustrace;
-
Grant succeeded.
-
sys@TESTDB12>grant select on v_$mystat to plustrace;
-
Grant succeeded.
-
sys@TESTDB12>grant plustrace to dba with admin option;
-
Grant succeeded.
-
sys@TESTDB12>
- sys@TESTDB12>set echo off
-
sys@TESTDB12>grant plustrace to scott;
Grant succeeded.
点击(此处)折叠或打开
-
SQL> create table t as select 1 id,object_name from dba_objects;
-
Table created.
-
SQL> select count(*) from t;
-
COUNT(*)
-
----------
-
77262
-
SQL> update t set id=99 where rownum=1;
-
1 row updated.
-
SQL> commit;
-
Commit complete.
-
SQL> select id,count(*) from t group by id;
-
ID COUNT(*)
-
---------- ----------
-
1 77261
-
99 1
-
SQL> create index i_t_id on t(id);
- Index created.
点击(此处)折叠或打开
-
SQL> set autot traceonly
-
SQL> select * from t where id=99;
-
-
Execution Plan
-
----------------------------------------------------------
-
Plan hash value: 4153437776
-
-----------------------------------------------------------------------------------
-
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time|
-
-
------------------------------------------------------------------------------------
-
-
| 0 | SELECT STATEMENT | | 1 | 79 | 2 (0)| 00:00:0
-
-
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 79 | 2 (0)| 00:00:01
-
-
|* 2 | INDEX RANGE SCAN | I_T_ID | 1 | | 1 (0)| 00:00:01
-
-
------------------------------------------------------------------------------------
-
Predicate Information (identified by operation id):
-
---------------------------------------------------
-
2 - access("ID"=99)
-
Note
-
----- - dynamic sampling used for this statement (level=2)
-
-
Statistics
-
----------------------------------------------------------
-
10 recursive calls
-
0 db block gets
-
67 consistent gets
-
1 physical reads
-
0 redo size
-
491 bytes sent via SQL*Net to client
-
420 bytes received via SQL*Net from client
-
2 SQL*Net roundtrips to/from client
-
0 sorts (memory)
-
0 sorts (disk)
- 1 rows processed
-
SQL> exec dbms_stats.gather_table_stats('HR','T',CASCADE=>TRUE);
-
PL/SQL procedure successfully completed.
-
-
SQL> select * from t where id=99;
-
-
Execution Plan
-
----------------------------------------------------------
-
Plan hash value: 4153437776
-
--------------------------------------------------------------------------------------
-
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time|
-
-
--------------------------------------------------------------------------------------
-
-
| 0 | SELECT STATEMENT | | 14 | 378 | 2 (0)| 00:00:01 |
-
-
| 1 | TABLE ACCESS BY INDEX ROWID| T | 14 | 378 | 2 (0)| 00:00:01 |
-
-
|* 2 | INDEX RANGE SCAN | I_T_ID | 14 | | 1 (0)| 00:00:01 |
-
-
--------------------------------------------------------------------------------------
-
Predicate Information (identified by operation id):
-
---------------------------------------------------
-
2 - access("ID"=99)
-
-
Statistics
-
----------------------------------------------------------
-
0 recursive calls
-
0 db block gets
-
3 consistent gets
-
0 physical reads
-
0 redo size
-
491 bytes sent via SQL*Net to client
-
420 bytes received via SQL*Net from client
-
2 SQL*Net roundtrips to/from client
-
0 sorts (memory)
-
0 sorts (disk)
- 1 rows processed
点击(此处)折叠或打开
-
SQL> set autot off
-
SQL> update t set id=99 where id=1;
-
77261 rows updated.
-
-
SQL> update t set id=1 where rownum=1;
-
1 row updated.
-
-
SQL> commit;
-
Commit complete.
-
-
SQL> select id,count(*) from t group by id;
-
-
ID COUNT(*)
-
---------- ----------
-
1 1
-
99 77261
-
-
SQL> set autot traceonly
-
SQL> select * from t where id=99;
-
77261 rows selected.
-
-
Execution Plan
-
----------------------------------------------------------
-
Plan hash value: 4153437776
-
--------------------------------------------------------------------------------------
-
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time|
-
-
------------------------------------------------------------------------------------
-
-
| 0 | SELECT STATEMENT | | 14 | 378 | 2 (0)| 00:00:01
-
| 1 | TABLE ACCESS BY INDEX ROWID| T | 14 | 378 | 2 (0)| 00:00:01
-
-
|* 2 | INDEX RANGE SCAN | I_T_ID | 14 | | 1 (0)| 00:00:01
-
-
-----------------------------------------------------------------------------------
-
Predicate Information (identified by operation id):
-
---------------------------------------------------
-
2 - access("ID"=99)
-
-
Statistics
-
----------------------------------------------------------
-
0 recursive calls
-
0 db block gets
-
11017 consistent gets
-
0 physical reads
-
13840 redo size
-
3170997 bytes sent via SQL*Net to client
-
57070 bytes received via SQL*Net from client
-
5152 SQL*Net roundtrips to/from client
-
0 sorts (memory)
-
0 sorts (disk)
-
77261 rows processed
-
-
-
SQL> select /*+ full(t) */ * from t where id=99;
-
77261 rows selected.
-
-
Execution Plan
-
----------------------------------------------------------
-
Plan hash value: 1601196873
-
--------------------------------------------------------------------------
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-
--------------------------------------------------------------------------
-
| 0 | SELECT STATEMENT | | 14 | 378 | 101 (1)| 00:00:02 |
-
|* 1 | TABLE ACCESS FULL| T | 14 | 378 | 101 (1)| 00:00:02 |
-
--------------------------------------------------------------------------
-
Predicate Information (identified by operation id):
-
---------------------------------------------------
-
1 - filter("ID"=99)
-
-
Statistics
-
----------------------------------------------------------
-
1 recursive calls
-
0 db block gets
-
5477 consistent gets
-
0 physical reads
-
0 redo size
-
2357600 bytes sent via SQL*Net to client
-
57070 bytes received via SQL*Net from client
-
5152 SQL*Net roundtrips to/from client
-
0 sorts (memory)
-
0 sorts (disk)
-
77261 rows processed
-
-
SQL> exec dbms_stats.gather_table_stats('HEROSTART_CN','T',CASCADE=>TRUE);
-
PL/SQL procedure successfully completed.
-
-
SQL> select * from t where id=99;
-
77261 rows selected.
-
-
Execution Plan
-
----------------------------------------------------------
-
Plan hash value: 1601196873
-
--------------------------------------------------------------------------
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-
--------------------------------------------------------------------------
-
| 0 | SELECT STATEMENT | | 77241 | 2036K| 101 (1)| 00:00:02 |
-
|* 1 | TABLE ACCESS FULL| T | 77241 | 2036K| 101 (1)| 00:00:02 |
-
--------------------------------------------------------------------------
-
Predicate Information (identified by operation id):
-
---------------------------------------------------
-
1 - filter("ID"=99)
-
-
Statistics
-
----------------------------------------------------------
-
0 recursive calls
-
0 db block gets
-
10845 consistent gets
-
0 physical reads
-
0 redo size
-
3170997 bytes sent via SQL*Net to client
-
57070 bytes received via SQL*Net from client
-
5152 SQL*Net roundtrips to/from client
-
0 sorts (memory)
-
0 sorts (disk)
- 77261 rows processed
点击(此处)折叠或打开
-
SQL> explain plan for select * from t where id=1;
-
Explained.
-
-
SQL> select * from table(dbms_xplan.display);
-
-
PLAN_TABLE_OUTPUT
-
--------------------------------------------------------------------------------
-
Plan hash value: 4153437776
-
--------------------------------------------------------------------------------------
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-
--------------------------------------------------------------------------------------
-
-
| 0 | SELECT STATEMENT | | 14 | 378 | 2 (0)| 00:00:01 |
-
-
| 1 | TABLE ACCESS BY INDEX ROWID| T | 14 | 378 | 2 (0)| 00:00:01 |
-
-
|* 2 | INDEX RANGE SCAN | I_T_ID | 14 | | 1 (0)| 00:00:01 |
-
-
--------------------------------------------------------------------------------------
-
Predicate Information (identified by operation id):
-
---------------------------------------------------
-
2 - access("ID"=1)
-
- 14 rows selected.
点击(此处)折叠或打开
-
SQL> create table t1 as select 1 id,object_name from dba_objects;
-
Table created.
-
-
SQL> update t1 set id=99 where rownum=1;
-
1 row updated.
-
-
SQL> commit;
-
Commit complete.
-
-
SQL> create index i_t1_id on t1(id);
-
Index created.
-
-
SQL> select table_name,column_name,endpoint_number,endpoint_value from user_hist
-
ograms where table_name='T1';
-
no rows selected
-
-
SQL> exec dbms_stats.gather_table_stats('HEROSTART_CN','T1',CASCADE=>TRUE);
-
PL/SQL procedure successfully completed.
-
-
SQL> select table_name,column_name,endpoint_number,endpoint_value from user_hist
-
ograms where table_name='T1';
-
-
TABLE_NAME COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE
-
-------------------- -------------------- --------------- --------------
-
T1 ID 0 1
-
T1 OBJECT_NAME 0 2.4504E+35
-
T1 ID 1 99
-
T1 OBJECT_NAME 1 6.2963E+35
-
-
SQL> select count(*),id from t1 group by id;
-
-
COUNT(*) ID
-
---------- ----------
-
77267 1
-
1 99
-
-
SQL> set autot traceonly
-
SQL> select * from t1 where id=99;
-
-
Execution Plan
-
----------------------------------------------------------
-
Plan hash value: 1111474805
-
-
---------------------------------------------------------------------------------------
-
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-
-
------------------------------------------------------------------------------------
-
-
| 0 | SELECT STATEMENT | | 14 | 378 | 2 (0)| 00:00:01 |
-
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 14 | 378 | 2 (0)| 00:00:01 |
-
|* 2 | INDEX RANGE SCAN |I_T1_ID | 14 | | 1 (0)| 00:00:01 |
-
-
------------------------------------------------------------------------------------
-
Predicate Information (identified by operation id):
-
---------------------------------------------------
-
2 - access("ID"=99)
-
-
Statistics
-
----------------------------------------------------------
-
0 recursive calls
-
0 db block gets
-
351 consistent gets
-
0 physical reads
-
0 redo size
-
487 bytes sent via SQL*Net to client
-
420 bytes received via SQL*Net from client
-
2 SQL*Net roundtrips to/from client
-
0 sorts (memory)
-
0 sorts (disk)
-
1 rows processed
-
-
-
SQL> select * from t1 where id=1;
-
77267 rows selected.
-
-
Execution Plan
-
---------------------------------------------------------
-
Plan hash value: 3617692013
-
--------------------------------------------------------------------------
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-
--------------------------------------------------------------------------
-
| 0 | SELECT STATEMENT | | 77254 | 2036K| 101 (1)| 00:00:02 |
-
|* 1 | TABLE ACCESS FULL| T1 | 77254 | 2036K| 101 (1)| 00:00:02 |
-
--------------------------------------------------------------------------
-
Predicate Information (identified by operation id):
-
---------------------------------------------------
-
1 - filter("ID"=1)
-
-
Statistics
-
----------------------------------------------------------
-
8 recursive calls
-
0 db block gets
-
5489 consistent gets
-
0 physical reads
-
0 redo size
-
2357825 bytes sent via SQL*Net to client
-
57081 bytes received via SQL*Net from client
-
5153 SQL*Net roundtrips to/from client
-
3 sorts (memory)
-
0 sorts (disk)
-
77267 rows processed
-
-
SQL> set autot off
-
SQL> exec dbms_stats.delete_column_stats('HR','T1','ID');
-
-
PL/SQL procedure successfully completed.
-
-
SQL> select table_name,column_name,endpoint_number,endpoint_value from user_hist
-
ograms where table_name='T1';
-
-
TABLE_NAME COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE
-
-------------------- -------------------- --------------- --------------
-
T1 OBJECT_NAME 0 2.4504E+35
-
T1 OBJECT_NAME 1 6.2963E+35
-
-
SQL> set autot traceonly
-
SQL> select * from t1 where id=99;
-
-
Execution Plan
-
----------------------------------------------------------
-
Plan hash value: 1111474805
-
------------------------------------------------------------------------------------
-
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-
------------------------------------------------------------------------------------
-
-
| 0 | SELECT STATEMENT | | 773 | 20871 | 77 (0)| 00:00:01 |
-
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 773 | 20871 | 77 (0)| 00:00:01 |
-
-
|* 2 | INDEX RANGE SCAN | I_T1_ID | 309 | | 75 (0)| 00:00:01 |
-
------------------------------------------------------------------------------------
-
Predicate Information (identified by operation id):
-
---------------------------------------------------
-
2 - access("ID"=99)
-
-
Statistics
-
----------------------------------------------------------
-
0 recursive calls
-
0 db block gets
-
351 consistent gets
-
0 physical reads
-
0 redo size
-
487 bytes sent via SQL*Net to client
-
420 bytes received via SQL*Net from client
-
2 SQL*Net roundtrips to/from client
-
0 sorts (memory)
-
0 sorts (disk)
-
1 rows processed
-
-
SQL> select * from t1 where id=1;
-
77267 rows selected.
-
-
-
Execution Plan
-
----------------------------------------------------------
-
Plan hash value: 1111474805
-
---------------------------------------------------------------------------------------
-
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-
-
---------------------------------------------------------------------------------------
-
-
| 0 | SELECT STATEMENT | | 773 | 20871 | 77 (0)| 00:00:01 |
-
-
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 773 | 20871 | 77 (0)| 00:00:01 |
-
-
|* 2 | INDEX RANGE SCAN | I_T1_ID | 309 | | 75 (0)| 00:00:01 |
-
-
---------------------------------------------------------------------------------------
-
Predicate Information (identified by operation id):
-
---------------------------------------------------
-
2 - access("ID"=1)
-
-
Statistics
-
----------------------------------------------------------
-
1 recursive calls
-
0 db block gets
-
10781 consistent gets
-
0 physical reads
-
0 redo size
-
3171208 bytes sent via SQL*Net to client
-
57081 bytes received via SQL*Net from client
-
5153 SQL*Net roundtrips to/from client
-
0 sorts (memory)
-
0 sorts (disk)
-
77267 rows processed
-
-
SQL> exec dbms_stats.gather_table_stats('HR','T1',CASCADE=>TRUE);
-
PL/SQL procedure successfully completed.
-
-
SQL> set autot off
-
SQL> select table_name,column_name,endpoint_number,endpoint_value from user_hist
-
ograms where table_name='T1';
-
-
TABLE_NAME COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE
-
-------------------- -------------------- --------------- --------------
-
T1 ID 5527 99
-
T1 ID 5526 1
-
T1 OBJECT_NAME 0 2.4504E+35
- T1 OBJECT_NAME 1 6.2963E+35
点击(此处)折叠或打开
-
SQL> set autot traceonly
-
SQL> select * from t2 where object_id > 30;
-
77236 rows selected.
-
-
Execution Plan
-
----------------------------------------------------------
-
Plan hash value: 1513984157
-
--------------------------------------------------------------------------
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-
--------------------------------------------------------------------------
-
| 0 | SELECT STATEMENT | | 58208 | 4490K| 105 (0)| 00:00:02 |
-
|* 1 | TABLE ACCESS FULL| T2 | 58208 | 4490K| 105 (0)| 00:00:02 |
-
--------------------------------------------------------------------------
-
Predicate Information (identified by operation id):
-
---------------------------------------------------
-
1 - filter("OBJECT_ID">30)
-
Note
-
-----
-
- dynamic sampling used for this statement (level=2)
-
-
Statistics
-
----------------------------------------------------------
-
24 recursive calls
-
0 db block gets
-
5586 consistent gets
-
6 physical reads
-
0 redo size
-
3005346 bytes sent via SQL*Net to client
-
57059 bytes received via SQL*Net from client
-
5151 SQL*Net roundtrips to/from client
-
6 sorts (memory)
-
0 sorts (disk)
- 77236 rows processed
点击(此处)折叠或打开
-
SQL> select /*+ dynamic_sampling(t2 0) */ * from t2 where object_id > 30;
-
77236 rows selected.
-
-
Execution Plan
-
----------------------------------------------------------
-
Plan hash value: 3661687773
-
---------------------------------------------------------------------------------------
-
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-
-
---------------------------------------------------------------------------------------
-
-
| 0 | SELECT STATEMENT | | 1556 | 120K| 8 (0)| 00:00:01 |
-
-
| 1 | TABLE ACCESS BY INDEX ROWID| T2 | 1556 | 120K| 8 (0)| 00:00:01 |
-
-
|* 2 | INDEX RANGE SCAN | I_T2_ID | 280 | | 3 (0)| 00:00:01 |
-
-
---------------------------------------------------------------------------------------
-
Predicate Information (identified by operation id):
-
---------------------------------------------------
-
2 - access("OBJECT_ID">30)
-
-
Statistics
-
----------------------------------------------------------
-
1 recursive calls
-
0 db block gets
-
10897 consistent gets
-
165 physical reads
-
0 redo size
-
3314234 bytes sent via SQL*Net to client
-
57059 bytes received via SQL*Net from client
-
5151 SQL*Net roundtrips to/from client
-
0 sorts (memory)
-
0 sorts (disk)
- 77236 rows processed
点击(此处)折叠或打开
-
SQL> set autot off
-
SQL> exec dbms_stats.gather_table_stats('HR','T2',CASCADE=>TRUE);
-
PL/SQL procedure successfully completed.
-
-
SQL> select num_rows,avg_row_len,blocks,last_analyzed from user_tables where tab
-
le_name='T2';
-
-
NUM_ROWS AVG_ROW_LEN BLOCKS LAST_ANALYZED
-
---------- ----------- ---------- -------------------
-
77266 29 381 2012-06-07:14:05:52
-
-
SQL> select blevel,leaf_blocks,distinct_keys,num_rows,last_analyzed from user_in
-
dexes where table_name='T2';
-
-
BLEVEL LEAF_BLOCKS DISTINCT_KEYS NUM_ROWS LAST_ANALYZED
-
---------- ----------- ------------- ---------- -------------------
-
1 171 77265 77265 2012-06-07:14:05:52
-
-
SQL> set autot traceonly
-
SQL> select /*+ dynamic_sampling(t2 0) */ * from t2 where object_id > 30;
-
77236 rows selected.
-
-
Execution Plan
-
----------------------------------------------------------
-
Plan hash value: 1513984157
-
-
--------------------------------------------------------------------------
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-
--------------------------------------------------------------------------
-
| 0 | SELECT STATEMENT | | 77242 | 2187K| 106 (1)| 00:00:02 |
-
|* 1 | TABLE ACCESS FULL| T2 | 77242 | 2187K| 106 (1)| 00:00:02 |
-
--------------------------------------------------------------------------
-
-
Predicate Information (identified by operation id):
-
---------------------------------------------------
-
1 - filter("OBJECT_ID">30)
-
-
Statistics
-
----------------------------------------------------------
-
12 recursive calls
-
0 db block gets
-
5516 consistent gets
-
0 physical reads
-
0 redo size
-
3005346 bytes sent via SQL*Net to client
-
57059 bytes received via SQL*Net from client
-
5151 SQL*Net roundtrips to/from client
-
5 sorts (memory)
-
0 sorts (disk)
- 77236 rows processed