select count(*)和select * 区别

explain plan for select * from F_AGT_BUSINESS_CONTRACT_H a where a.end_dt=date'2999-12-31';




select * from table(dbms_xplan.display());


Plan hash value: 3544262987
 
-----------------------------------------------------------------------------------------------
| Id  | Operation         | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |                           |   255K|   151M| 55276   (1)| 00:11:04 |
|*  1 |  TABLE ACCESS FULL| F_AGT_BUSINESS_CONTRACT_H |   255K|   151M| 55276   (1)| 00:11:04 |
-----------------------------------------------------------------------------------------------
 
Predicate Information (identified by operation id):
---------------------------------------------------
 
   1 - filter("A"."END_DT"=TO_DATE(' 2999-12-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))


###########################################################################################################


explain plan for select count(*) from F_AGT_BUSINESS_CONTRACT_H a where a.end_dt=date'2999-12-31';




select * from table(dbms_xplan.display());
Plan hash value: 2053193161
 
----------------------------------------------------------------------------------------------------
| Id  | Operation         | Name                           | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |                                |     1 |     8 |   681   (1)| 00:00:09 |
|   1 |  SORT AGGREGATE   |                                |     1 |     8 |            |          |
|*  2 |   INDEX RANGE SCAN| F_AGT_BUSINESS_CONTRACT_H_IDX3 |   255K|  1992K|   681   (1)| 00:00:09 |
----------------------------------------------------------------------------------------------------
 
Predicate Information (identified by operation id):
---------------------------------------------------
 
   2 - access("A"."END_DT"=TO_DATE(' 2999-12-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))


count(*)可以直接从索引返回数据,故可以走索引


select * 需要索引访问后回表,Oracle认为cost高于索引扫描,故选择全表扫描

你可能感兴趣的:(select count(*)和select * 区别)