Oracle 10g中可以通過列方式指定HINT

來源:互聯網
上載者:User

看最佳化文檔的時候發現,指定索引的HINT還可以通過列方式。

在9i和以前的版本,索引提示的格式為/*+ index(table_alias) */或/*+ index(table_alias index_name) */,但是在10g中不僅可以通過索引名稱來確定HINT的索引,還可以通過指定列名的方式。

SQL> select * from v$version;

BANNER

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

Oracle Database10gEnterpriseEdition Release10.2.0.3.0 - 64bi

PL/SQL Release 10.2.0.3.0 - Production

CORE    10.2.0.3.0      Production

TNS for Linux: Version 10.2.0.3.0 - Production

NLSRTL Version 10.2.0.3.0 - Production

SQL> create table t

2  as select *

3  from dba_objects;

Table created.

SQL> create index ind_t_owner_type

2  on t (owner, object_type);

Index created.

SQL> exec dbms_stats.gather_table_stats(user, 'T', method_opt => 'for all indexed columns size 100')

PL/SQL procedure successfully completed.

SQL> set autot trace exp

SQL> select *

2  from t

3  where wner = 'SYS';

Execution Plan

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

Plan hash value: 1601196873

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

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

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

|   0 | SELECT STATEMENT  |      | 23299 |  2138K|   180   (1)| 00:00:03 |

|*  1 |  TABLE ACCESS FULL| T    | 23299 |  2138K|   180   (1)| 00:00:03 |

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

Predicate Information (identified by operation id):

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

1 - filter("OWNER"='SYS')

SQL> select /*+ index(t ind_t_owner_type) */ *

2  from t

3  where wner = 'SYS';

Execution Plan

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

Plan hash value: 393469706

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

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

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

|  0 | SELECT STATEMENT            |                  | 23299 |2138K|   721   (1)| 00:00:11 |

|  1 |  TABLE ACCESS BY INDEX ROWID| T                | 23299 |2138K|   721   (1)| 00:00:11 |

|* 2 |   INDEX RANGE SCAN          | IND_T_OWNER_TYPE | 23299 |     |    44   (0)| 00:00:01 |

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

Predicate Information (identified by operation id):

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

2 - access("OWNER"='SYS')

除了常規的索引名稱方式,還可以通過owner或owner、object_type列的方式指定:

聯繫我們

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