您好,欢迎访问一九零五行业门户网

oracle hints的那点事

引言:hints翻译成中文就是提示,暗示的意思,它在数据库中作用就是更改sql语句的执行方式,你可以使用hints强制sql按照你所设置的方式执行sql,一般用来做性能
引言: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 |
----------------------------------------------------------------------------------------
predicate information (identified by operation id):
---------------------------------------------------
   2 - access(object_id>100)
statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
      10735  consistent gets                        10735次一致性读
          0  physical reads
          0  redo size
    8241805  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
其它类似信息

推荐信息