Oracle執行計畫 講解(一)____Oracle

來源:互聯網
上載者:User

看懂Oracle執行計畫是最佳化的第一步,讓我們從下面的例子開始吧。

        下面為補充內容

1、建立測試表
[sql]  view plain  copy SQL> create table t as select 1 id,object_name from dba_objects;       Table created       SQL> update t set id=99 where rownum=1;       1 row updated       SQL> commit;       Commit complete       SQL> create index t_ind on t(id);       Index created  

        oracle最佳化器:RBO和CBO兩種, 從oracle10g開始最佳化器已經拋棄了RBO,下面的列子說明CBO大概是怎樣的

[sql]  view plain  copy SQL>  select /*+dynamic_sampling(t 0) */* from t where id=1;      50819 rows selected.         Execution Plan   ----------------------------------------------------------   Plan hash value: 1376202287      -------------------------------------------------------------------------------------   | Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |   -------------------------------------------------------------------------------------   |   0 | SELECT STATEMENT            |       |   195 | 15405 |    51   (0)| 00:00:01 |   |   1 |  TABLE ACCESS BY INDEX ROWID| T     |   195 | 15405 |    51   (0)| 00:00:01 |   |*  2 |   INDEX RANGE SCAN          | T_IND |    78 |       |    50   (0)| 00:00:01 |   -------------------------------------------------------------------------------------      Predicate Information (identified by operation id):   ---------------------------------------------------         2 - access("ID"=1)  

       現象t表還沒有被分析,提示/*+dynamic_sampling(t 0) */*的目的是讓CBO無法通過動態採樣擷取表中的實際資料情況,此時CBO只能根據T表中非常有限的資訊(比如表中的extents數量,資料區塊的數量)來猜測表中的資料。從結果中可以看到CBO猜出表中id=1的有195條,這個數值對於表的總數來說,是一個非常小的值,所以CBO選擇了索引而不是全表掃描。
      而實際情況如下所示:
[sql]  view plain  copy SQL> select * from  t where

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.