SQL> set linesize 120
SQL> select num_rows from dba_tables where owner='ODSUSER' and table_name='T_POLICY_HEALTH_AGENT_INFO';
NUM_ROWS
----------
6659717
SQL> select owner,index_name from dba_indexes where owner='ODSUSER' and table_name='T_POLICY_HEALTH_AGENT_INFO';
no rows selected
SQL> set autot trace exp stat
SQL> SELECT * FROM odsuser.T_POLICY_HEALTH_AGENT_INFO T WHERE T.POLICY_ID =13006965 AND ROWNUM < 2;
Execution Plan
----------------------------------------------------------
Plan hash value: 77316705
---------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 65 | 17758 (1)| 00:03:34 |
|* 1 | COUNT STOPKEY | | | | | |
|* 2 | TABLE ACCESS STORAGE FULL| T_POLICY_HEALTH_AGENT_INFO | 1 | 65 | 17758 (1)| 00:03:34 |
---------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM<2)
2 - storage("T"."POLICY_ID"=13006965)
filter("T"."POLICY_ID"=13006965)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
1900 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> set autot off
SQL> create index odsuser.idx_t_policy_health_agent_info on odsuser.t_policy_health_agent_info (policy_id) parallel 4;
Index created.
SQL> alter index odsuser.idx_t_policy_health_agent_info noparallel;
Index altered.
SQL> set autot trace exp stat
SQL> SELECT * FROM odsuser.T_POLICY_HEALTH_AGENT_INFO T WHERE T.POLICY_ID =13006965 AND ROWNUM < 2;
Execution Plan
----------------------------------------------------------
Plan hash value: 1126906020
---------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 65 | 4 (0)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | TABLE ACCESS BY INDEX ROWID| T_POLICY_HEALTH_AGENT_INFO | 1 | 65 | 4 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | IDX_T_POLICY_HEALTH_AGENT_INFO | 1 | | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM<2)
3 - access("T"."POLICY_ID"=13006965)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
4 consistent gets
2 physical reads
148 redo size
1904 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
可以看到Exdata使用了SmartScan功能,两者的执行时间和consistent gets值差不多,那么是否可以认为在Exdata上有些索引可以不用创建了呢。
另外如果top 5 中出现了cell smart table scan的等待事件,此时还是应该检查sql语句,尽量创建需要的索引?