select * from table(dbms_xplan.display_cursor('f4jwtn3360ppk',0,'advanced'));
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID f4jwtn3360ppk, child number 0
-------------------------------------
select count(value) from tab_acs where id=1
Plan hash value: 3684903434
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 11 (100)| |
| 1 | SORT AGGREGATE | | 1 | 7 | | |
|* 2 |
TABLE ACCESS FULL| TAB_ACS | 20000 | 136K| 11 (0)| 00:00:01 |
------------------------------------------------------------------------------
select count(value) from tab_acs where id=2;
COUNT(VALUE)
------------
10
SQL> select sql_text,sql_id,version_count,executions from v$sqlarea where sql_text like 'select count(value)%';
SQL_TEXT SQL_ID VERSION_COUNT EXECUTIONS
------------------------------------------------------------ ------------- ------------- ----------
select count(value) from tab_acs where id=1 f4jwtn3360ppk 1 1
select count(value) from tab_acs where id=2
9vx4syymyzkb7 1 1
select * from table(dbms_xplan.display_cursor('9vx4syymyzkb7',0,'advanced'));
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID 9vx4syymyzkb7, child number 0
-------------------------------------
select count(value) from tab_acs where id=2
Plan hash value: 3029888215
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 2 (100)| |
| 1 | SORT AGGREGATE | | 1 | 7 | | |
| 2 | TABLE ACCESS BY INDEX ROWID| TAB_ACS | 10 | 70 | 2 (0)| 00:00:01 |
|* 3 |
INDEX RANGE SCAN | IDX_TAB_ACS | 10 | | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------
可以看到谓词条件为1时走全表扫描,谓词条件为2的情况下走索引范围扫描。
下面看一下使用绑定变量的执行计划: