WEB开发网
开发学院数据库Oracle Oracle数据库11g新特性:自适应游标与SQL计划管理... 阅读

Oracle数据库11g新特性:自适应游标与SQL计划管理

 2008-12-16 13:03:23 来源:WEB开发网   
核心提示: SQL> c/NY/CT1* select * from customers where state_code = 'CT' and times_purchased > 3SQL> /Execution Plan--Plan hash value: 487

SQL> c/NY/CT
 1* select * from customers where state_code = 'CT' and times_purchased > 3
SQL> /
Execution Plan
----------------------------------------------------------
Plan hash value: 4876992
---------------------------------------------------------------------------------------------
| Id | Operation          | Name     | Rows | Bytes | Cost (%CPU)| Time   |
---------------------------------------------------------------------------------------------
|  0 | SELECT STATEMENT      |        | 4589 |  138K|  56  (2)| 00:00:01 |
|* 1 | TABLE ACCESS BY INDEX ROWID| CUSTOMERS   | 4589 |  138K|  56  (2)| 00:00:01 |
|* 2 |  INDEX RANGE SCAN     | IN_CUST_STATE | 5099 |    |  12  (0)| 00:00:01 |
---------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
  1 - filter("TIMES_PURCHASED">3)
  2 - access("STATE_CODE"='CT')

它使用了索引。同样,这也是正确的操作。含有 CT 的行数仅占总行数的 5%,因此进行索引扫描是有利的。

让我们看一看使用绑定变量时的行为。以下是 Oracle 数据库 10g 中的演示行为。

SQL> var state_code varchar2(2)
SQL> exec :state_code := 'CT'
PL/SQL procedure successfully completed.
SQL> select max(times_purchased) from customers where state_code = :state_code
 2 /
Execution Plan
----------------------------------------------------------
Plan hash value: 296924608
--------------------------------------------------------------------------------
| Id | Operation     | Name   | Rows | Bytes | Cost (%CPU)| Time   |
--------------------------------------------------------------------------------
|  0 | SELECT STATEMENT  |      |   1 |   6 | 1511  (8)| 00:00:19 |
|  1 | SORT AGGREGATE  |      |   1 |   6 |      |     |
|* 2 |  TABLE ACCESS FULL| CUSTOMERS |  500K| 2929K| 1511  (8)| 00:00:19 |
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
  2 - filter("STATE_CODE"=:STATE_CODE)

上一页  1 2 3 4 5 6 7 8  下一页

Tags:Oracle 数据库 特性

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接