oracle spm使用1,oraclespm使用

來源:互聯網
上載者:User

oracle spm使用1,oraclespm使用
oracle11g new feature SPM
有助於保持sql的語句特性,只允許執行效能提高的執行計畫。
它不同於stored outlines, spm在於穩定sql效能,而store outlines在於凍結sql執行計畫


事列
1.啟用optimizer_cature_sql_plan_baselines 捕獲sql語句
SQL> alter session set optimizer_capture_sql_plan_baselines = true;
Session altered.
SQL> select * from objs where object_id = 2;
no rows selected
SQL> select * from objs where object_id = 2;
no rows selected
SQL> alter session set optimizer_capture_sql_plan_baselines = false;
Session altered.
2.查詢dba_sql_plan_baselines,確定sql的spm狀態
SQL> select plan_name, sql_handle, enabled, accepted, fixed,
  2             module, sql_text
  3  from dba_sql_plan_baselines;
PLAN_NAME                      SQL_HANDLE           ENABLED   ACCEPTED  FIXED     MODULE               SQL_TEXT
------------------------------ -------------------- --------- --------- --------- -------------------- --------------------------------------------------
SQL_PLAN_4pzq3z6xcqkpwd0984253 SQL_4afec3f9bacb4abc YES       YES       NO        SQL*Plus             select * from objs where object_id = 2
3.增加索引改變環境再運行sql
SQL> alter session set optimizer_capture_sql_plan_baselines = true;
Session altered.
SQL> select * from objs where object_id = 2;
no rows selected
SQL> select * from objs where object_id = 2;
no rows selected
SQL> alter session set optimizer_capture_sql_plan_baselines = false;
Session altered.
4.查詢dba_sql_plan_baselines
SQL> select plan_name, sql_handle, enabled, accepted, fixed, module, sql_text from dba_sql_plan_baselines;
PLAN_NAME                      SQL_HANDLE           ENABLED   ACCEPTED  FIXED     MODULE               SQL_TEXT
------------------------------ -------------------- --------- --------- --------- -------------------- --------------------------------------------------
SQL_PLAN_4pzq3z6xcqkpwbe4c314c SQL_4afec3f9bacb4abc YES       NO        NO        SQL*Plus             select * from objs where object_id = 2
SQL_PLAN_4pzq3z6xcqkpwd0984253 SQL_4afec3f9bacb4abc YES       YES       NO        SQL*Plus             select * from objs where object_id = 2
SQL>
5.測試
SQL>
SQL> set autotrace on
SQL> select * from objs where object_id = 2;
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 954894094


--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     1 |    98 |   247   (1)| 00:00:03 |
|*  1 |  TABLE ACCESS FULL| OBJS |     1 |    98 |   247   (1)| 00:00:03 |
--------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------


   1 - filter("OBJECT_ID"=2)


Note
-----
   - SQL plan baseline "SQL_PLAN_4pzq3z6xcqkpwd0984253" used for this statement




Statistics
----------------------------------------------------------
        255  recursive calls
          0  db block gets
       1044  consistent gets
        879  physical reads
          0  redo size
       1343  bytes sent via SQL*Net to client
        513  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
         28  sorts (memory)
          0  sorts (disk)
          0  rows processed


SQL> alter session set optimizer_use_sql_plan_baselines = false;
Session altered.
SQL> select * from objs where object_id = 2;
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 613004408


-----------------------------------------------------------------------------------------------
| Id  | Operation                   | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |                 |     1 |    98 |     2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| OBJS            |     1 |    98 |     2   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | IDX_OBJSID_OBJS |     1 |       |     1   (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------


   2 - access("OBJECT_ID"=2)




Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
          2  consistent gets
          4  physical reads
          0  redo size
       1343  bytes sent via SQL*Net to client
        513  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          0  rows processed




可以看到當啟動optimizer_user_sql_plan_baselines時走索引應該是最優的卻沒有使用
plan_name accecpt 為 no 影響了走索引計劃










oracle中 HAVING count(1) group by sex having count(*)>4; having是什?怎使用?

譬如如下資料
id value
1 2
1 3
2 3
3 5
3 6

可以寫個語句統計value的分組
select id,sum(value) from table group by id having sum(value)>=5
這樣的結果就是
1 5
3 11

其實這句的意思就是
select id,sum(value) from table where sum(value)>=5 group by id
但是oracle中,計算欄位沒法當作條件來用,所以就用having 來表示
你的例子是count(*)也是一個道理的,當然什麼avg,max,min之類的彙總函式也同樣
 
oracle 怎尋找哪一個包中使用了一個表(表我是知道哪一個的)

你想要找表就找關鍵字,如果說你不知道表名的關鍵字。那麼在表的上面操作也無非就那麼幾個,drop和create是不可能在包裡處理的。你就查select、 update 和 delete,之後跟的就是表名,
這個是查包裡用了多少個表,都是哪些表。

如果反過來查,一個表被多少個包,存貯過程等使用了,那就更簡單了,用Toad for Oracle,在編輯器裡打上表名後F4,點那個used by就OK了。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.