oracle之数据字典屣履造门
oracle数据字典包括四部分,分别是RDBMS(X$),数据字典表、动态性能视图(v$)和数据字典视图。
1)RDBMS(X$)内部 表:
该部分内容是oracle最低层的表数据,这些表维持着oracle的整个视图,就像我们人体的血液在我们人体流动维持生命一样。
因此这些表只能查看、研究不建议修改。oracle对修改内部表产生的后果不负责技术支持工作。
在查看参数文件的时候我曾经提到x$ksppi和X$ksppcv这两个内部表。
研究内部表:
oracle@oracle:~> sqlplus "/as sysdba"
SQL*Plus: Release 11.1.0.6.0 - Production on 星期四 6月 20 20:38:47 2013
Copyright (c) 1982, 2007, Oracle. All rights reserved.
连接到:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SYS@orcl#select open_mode from v$database;
OPEN_MODE
--------------------
READ WRITE
SYS@orcl#grant select on x$ksppi to xiaohai;
grant select on x$ksppi to xiaohai
*
第 1 行出现错误:
ORA-02030: 只能从固定的表/视图查询
可以看出内部表不允许进行授权。
研究内部表方法如下:
SYS@orcl#set autotrace trace explain;
SYS@orcl#select * from v$parameter;
执行计划
----------------------------------------------------------
Plan hash value: 1128103955
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 4414 | 1 (100)| 00:00:01 |
|* 1 | HASH JOIN | | 1 | 4414 | 1 (100)| 00:00:01 |
|* 2 | FIXED TABLE FULL| X$KSPPI | 1 | 249 | 0 (0)| 00:00:01 |
| 3 | FIXED TABLE FULL| X$KSPPCV | 100 | 406K| 0 (0)| 00:00:01 |
------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("X"."INDX"="Y"."INDX")
filter(TRANSLATE("KSPPINM",'_','#') NOT LIKE '#%' OR
"KSPPSTDF"='FALSE' OR BITAND("KSPPSTVF",5)>0)
2 - filter("X"."INST_ID"=USERENV('INSTANCE') AND
TRANSLATE("KSPPINM",'_','#') NOT LIKE '##%')
SYS@orcl#
autotrace 语句研究:
该语句工具主要是研究统计sql语句的执行计划并生成报告,进而对dml语句进行检测和优化。
Generates a report on the execution path used by the SQL optimizer and the statement execution statistics. The report is useful to monitor and tune the performance of DML statements.
set autotrace off; 不产生报告和执行计划,默认设置。
set autotrace on explain; 生成执行计划并显示查询信息;
set autotrace on statistics;只生成语句的统计信息并显示查询信息。
set autotrace on ; 即生成语句报告有显示语句的执行统计信息和计划
set autotrace traceonly; 和on一样,区别就是不显示查询信息,查询的数据依然会fetch但是不会print,只显示统计信息和执行计划;
eg:
SYS@orcl#set autotrace on explain
SYS@orcl#select * from t2;
EMPNO ENAME
---------- --------------------
7521 WARD
执行计划
----------------------------------------------------------
Plan hash value: 1513984157
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 20 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| T2 | 1 | 20 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
SYS@orcl#set autotrace on statistices;
SP2-0735: 未知的 SET 选项开头 "statistice..."
SYS@orcl#set autotrace on statistics;
SYS@orcl#select * from t2;
EMPNO ENAME
---------- --------------------
7521 WARD
统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
600 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SYS@orcl#select * from t2;
EMPNO ENAME
---------- --------------------
7521 WARD
执行计划
----------------------------------------------------------
Plan hash value: 1513984157
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 20 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| T2 | 1 | 20 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads