Oracle --- PLAN_TABLE$和PLAN_TABLE區別
註釋
PLAN_TABLE is the default table for results of the EXPLAIN PLAN statement. It is created by utlxplan.sql, and it contains one row for each step in the execution plan.
---> session1:commit,session2:可檢視資料
PLAN_TABLE$ is a global temporary table accessible from any schema .It is created by catplan.sql ,It also creates the plan_id sequence number.
---> 臨時表 session1:commit,session2:不可檢視資料
測試【PLAN_TABLE普通表/基於PLAN_TABLE$基表的同義詞】 資料保留情況
1)PLAN_TABLE 表...SESSION1 :
SQL> show user
User is "fescotest_prod"
SQL>
-->檢視錶型別【是table 還是synonym】
SQL> SELECT t.OBJECT_NAME,t.OBJECT_TYPE FROM User_Objects T WHERE T.OBJECT_NAME='PLAN_TABLE';
OBJECT_NAME OBJECT_TYPE
-------------------------------------------------------------------------------- -------------------
PLAN_TABLE TABLE
SQL> explain plan for select 1 from dual; ---> 生成執行計劃
Explained
SQL> select * from table(dbms_xplan.display()); ---> 檢視執行計劃
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 1388734953
-----------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-----------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 (0)| 00:00:01 |
| 1 | FAST DUAL | | 1 | 2 (0)| 00:00:01 |
-----------------------------------------------------------------
8 rows selected
SQL> commit; ---> 提交事物
Commit complete
|
---> PLAN_TABLE 表...SESSION2 :
檢視資料:
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.3.0
Connected as sinotest@192.168.0.59/testdb
SQL> show user
User is "fescotest_prod"
SQL> select * from table(dbms_xplan.display()); ---> 檢視執行計劃
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 1388734953
-----------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-----------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 (0)| 00:00:01 |
| 1 | FAST DUAL | | 1 | 2 (0)| 00:00:01 |
-----------------------------------------------------------------
8 rows selected
SQL> select count(1) from plan_table;
COUNT(1)
----------
2
SQL>
-->sesion2 可以看到提交的資料 ...可以存放特定SQL的執行計劃,,避免去V$SQL_PLAN 查詢...利於偶爾最佳化SQL..看個人想法理解優缺點...
|
2)基於PLAN_TABLE$ 建立的同義詞...SESSION1 :
SQL> drop table plan_table; ---> 刪除表
Table dropped
SQL> SELECT owner,object_name,object_type,object_id FROM DBA_OBJECTS T WHERE T.OBJECT_NAME LIKE 'PLAN_TABLE%'; ---> 檢視物件
OWNER OBJECT_NAME OBJECT_TYPE OBJECT_ID ------------------------------ ------------------------------ ------------------- ---------- SYS PLAN_TABLE$ TABLE 59898 PUBLIC PLAN_TABLE SYNONYM 8709 SQL>
SQL> SELECT T.OWNER,T.TABLE_NAME,T.TEMPORARY FROM DBA_TABLES T WHERE T.TABLE_NAME='PLAN_TABLE$'; ---> 檢視錶型別
OWNER TABLE_NAME TEMPORARY
------------------------------ ------------------------------ ---------
SYS PLAN_TABLE$ Y --臨時表(session/事物級別)該表是[on commit preserve rows]session級,而不是[on commit delete rows]事物級
SQL>
SQL> explain plan for select 1 from dual join (select 1 from dual ) on 1=1; ---> 生成執行計劃
Explained
SQL> select * from table(dbms_xplan.display()); ---> 檢視執行計劃
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 3033775561
-----------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-----------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 4 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | 1 | 4 (0)| 00:00:01 |
| 2 | FAST DUAL | | 1 | 2 (0)| 00:00:01 |
| 3 | FAST DUAL | | 1 | 2 (0)| 00:00:01 |
-----------------------------------------------------------------
10 rows selected
SQL>
SQL> commit; ---> 提交
Commit complete
SQL>
|
---> 基於PLAN_TABLE$ 建立的同義詞...SESSION2 :
SQL> SELECT COUNT(1) FROM plan_table; ---> 檢視錶資料
COUNT(1)
----------
0
SQL>
|
總結:
【plan_table、基於PLAN_TABLE$基表建立同義詞】都可以理解是檢視執行計劃用的表,如庫中沒有該物件(或沒該物件的許可權),那估算的執行計劃都是不可以用的;包括【explain plan for /SET AUTOT[RACE]...等】
PLAN_TABLE普通表提交其他會話可以看資料【session1:commit,session2可查看資料】、同義詞PLAN_TABLE session級臨時表【session1:commit,session2不可檢視資料】
若想再瞭解下 請檢視部落格 http://blog.itpub.net/28602568/viewspace-1097288/
祝好~
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8494287/viewspace-1349432/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle -- 深入體會PLAN_TABLE、PLAN_TABLE$Oracle
- 【筆記】使用 plan_table筆記
- ORACLE SQL調優之'PLAN_TABLE' is old versionOracleSQL
- 解決 'PLAN_TABLE' is old version
- 資料庫升級後‘PLAN_TABLE資料庫
- 【原創】Oracle9i和10g中plan_table表的差異Oracle
- Error: cannot fetch last explain plan from PLAN_TABLEErrorASTAI
- 【Explain Plan】10g中的PLAN_TABLE$臨時表AI
- Oracle - @和@@、&與&& 的區別Oracle
- MySQL和Oracle的區別MySqlOracle
- Oracle和MySQL的區別OracleMySql
- 【原創】ORA-00054問題的解決(plan_table在autotrace過程中會被鎖定)
- Oracle 和 SQL Server 個別小區別OracleSQLServer
- Oracle User 和 Schema 的區別Oracle
- Oracle Purge和drop的區別Oracle
- oracle中in和exists的區別Oracle
- ORACLE_BASE和ORACLE_HOME的區別Oracle
- Oracle DBA 和Oracle EBS DBA 的最大區別Oracle
- Oracle dba角色和sysdba的區別Oracle
- Oracle 和 mysql的9點區別OracleMySql
- oracle中distinct和group by的區別Oracle
- oracle中 DG和GG的區別Oracle
- Oracle中truncate和delete的區別Oracledelete
- (轉)ORACLE 中IN和EXISTS的區別Oracle
- Oracle的redo 和undo的區別Oracle
- Oracle中latch和lock的區別Oracle
- 【轉】oracle_base 和 oracle_home 的區別Oracle
- Oracle中Date和Timestamp的區別Oracle
- oracle中rownum和rowid的區別Oracle
- Oracle rman中recover和restore的區別:OracleREST
- Oracle RAC 和OPS 區別 - Cache FusionOracle
- Oracle中User和Schema的區別和聯絡Oracle
- NULL在oracle和mysql索引上的區別NullOracleMySql索引
- oracle之group by,having和where的區別Oracle
- Oracle中sys和system的區別小結Oracle
- 在Oracle中session和process的區別(轉)OracleSession
- Oracle中truncate和delete的區別(例項)Oracledelete
- Oracle RESETLOGS 和 NORESETLOGS 區別說明Oracle