oracle hints簡介

來源:互聯網
上載者:User

hints翻譯成中文就是提示,暗示的意思,它在資料庫中作用就是更改SQL語句的執行方式,你可以使用hints強制sql按照你所設定的方式執行sql,一般用來做效能診斷和調優,不建議在開發中使用。

1.寫一條SQL,使它通過全表掃描方式的效率優於索引訪問,分別給出各自的執行計畫。

LEO1@LEO1> create table leo1 as select * from dba_objects;      建立leo1表

Table created.

LEO1@LEO1> create index idx_leo1 on leo1(object_id);            在這個object_id列上建立索引

Index created.

LEO1@LEO1> execute dbms_stats.gather_table_stats('LEO1','LEO1',cascade=>true);  分析表和索引

PL/SQL procedure successfully completed.

LEO1@LEO1> select count(*) from leo1;         表上有71958行記錄

COUNT(*)

---------------

71958

LEO1@LEO1> select /*+ full(leo1) */ * from leo1 where object_id>100;

71859 rows selected.

Execution Plan

----------------------------------------------------------

Plan hash value: 2716644435

--------------------------------------------------------------------------

| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |

--------------------------------------------------------------------------

|   0 | SELECT STATEMENT  |      | 71862 |  6807K|   287   (1)| 00:00:04 |

|*  1 |  TABLE ACCESS FULL| LEO1  | 71862 |  6807K|  287   (1)| 00:00:04 |

--------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

1 - filter("OBJECT_ID">100)

Statistics

----------------------------------------------------------

1  recursive calls

0  db block gets

5762  consistent gets                 5762次一致性讀

0  physical reads

0  redo size

3715777  bytes sent via SQL*Net to client

53214  bytes received via SQL*Net from client

4792  SQL*Net roundtrips to/from client

0  sorts (memory)

0  sorts (disk)

71859  rows processed

LEO1@LEO1> select /*+ index(leo1 idx_leo1) */ * from leo1 where object_id>100;

71859 rows selected.

Execution Plan

----------------------------------------------------------

Plan hash value: 1434365503

----------------------------------------------------------------------------------------

| Id  | Operation                   | Name     | Rows  | Bytes | Cost (%CPU)| Time     |

----------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT            |          | 71862 |  6807K|  1232   (1)| 00:00:15 |

|   1 |  TABLE ACCESS BY INDEX ROWID| LEO1     | 71862 |  6807K|  1232   (1)| 00:00:15 |

|*  2 |   INDEX RANGE SCAN         | IDX_LEO1 | 71862 |       |  160   (0)| 00:00:02 |

----------------------------------------------------------------------------------------

聯繫我們

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