执行信息统计后没有使用索引

SQL> conn system/yang as sysdba
已连接。
SQL> create table t1 as  select *  from dba_objects
  2  where wner='SYS'
  3  and object_type not like '%BODY'
  4  and object_type not like '%JAVA%';
表已创建。
SQL> set timing on
SQL> create table t2 as select * from dba_segments where wner='SYS';
表已创建。
已用时间:  00: 00: 00.34
SQL> create table t3 as select * from dba_indexes where wner='SYS';
表已创建。
已用时间:  00: 00: 00.51
SQL> select count(*) from t2;
  COUNT(*)                                                                     
----------                                                                     
      2087                                                                     
已用时间:  00: 00: 00.06
SQL> select count(*) from t3;
  COUNT(*)                                                                     
----------                                                                     
      1060                                                                     
已用时间:  00: 00: 00.03
SQL> alter table t1 add constraint pk_t1 primary key (object_name);
alter table t1 add constraint pk_t1 primary key (object_name)
                              *
第 1 行出现错误:
ORA-02437: 无法验证 (SYS.PK_T1) - 违反主键
SQL> create index i_t1 on t1 t1(object_id);
索引已创建。
已用时间:  00: 00: 00.11
SQL> set autot on
SQL> select count (*) from t1;
  COUNT(*)                                                                     
----------                                                                     
      7909                                                                     
已用时间:  00: 00: 00.01
执行计划
----------------------------------------------------------                     
Plan hash value: 3724264953                                                    
                                                                               
-------------------------------------------------------------------            
| Id  | Operation          | Name | Rows  | Cost (%CPU)| Time     |            
-------------------------------------------------------------------            
|   0 | SELECT STATEMENT   |      |     1 |    29   (0)| 00:00:01 |            
|   1 |  SORT AGGREGATE    |      |     1 |            |          |            
|   2 |   TABLE ACCESS FULL| T1   |  8165 |    29   (0)| 00:00:01 |            
-------------------------------------------------------------------            
                                                                               
Note                                                                           
-----                                                                          
   - dynamic sampling used for this statement                                  
统计信息
----------------------------------------------------------                     
         28  recursive calls                                                   
          0  db block gets                                                     
        178  consistent gets                                                   
          0  physical reads                                                    
          0  redo size                                                         
        420  bytes sent via SQL*Net to client                                  
        416  bytes received via SQL*Net from client                            
          2  SQL*Net roundtrips to/from client                                 
          0  sorts (memory)                                                    
          0  sorts (disk)                                                      
          1  rows processed                                                    

SQL> analyze table t1 compute statistics;
表已分析。
已用时间:  00: 00: 00.20
SQL> select count (*) from t1;

  COUNT(*)                                                                     
----------                                                                     
      7909                                                                     
已用时间:  00: 00: 00.01
执行计划
----------------------------------------------------------                     
Plan hash value: 3724264953                                                    
                                                                               
-------------------------------------------------------------------            
| Id  | Operation          | Name | Rows  | Cost (%CPU)| Time     |            
-------------------------------------------------------------------            
|   0 | SELECT STATEMENT   |      |     1 |    29   (0)| 00:00:01 |            
|   1 |  SORT AGGREGATE    |      |     1 |            |          |            
|   2 |   TABLE ACCESS FULL| T1   |  7909 |    29   (0)| 00:00:01 |            
-------------------------------------------------------------------            
统计信息
----------------------------------------------------------                     
          1  recursive calls                                                   
          0  db block gets                                                     
        105  consistent gets                                                   
          0  physical reads                                                    
          0  redo size                                                         
        420  bytes sent via SQL*Net to client                                  
        416  bytes received via SQL*Net from client                            
          2  SQL*Net roundtrips to/from client                                 
          0  sorts (memory)                                                    
          0  sorts (disk)                                                      
          1  rows processed                                                    

SQL> ALTER SESSION SET optimizer_mode=first_rows;
会话已更改。
已用时间:  00: 00: 00.00
SQL> select count (*) from t1;
  COUNT(*)                                                                     
----------                                                                     
      7909                                                                     

已用时间:  00: 00: 00.00
执行计划
----------------------------------------------------------                     
Plan hash value: 3724264953                                                                                                                                  
-------------------------------------------------------------------            
| Id  | Operation          | Name | Rows  | Cost (%CPU)| Time     |            
-------------------------------------------------------------------            
|   0 | SELECT STATEMENT   |      |     1 |    29   (0)| 00:00:01 |            
|   1 |  SORT AGGREGATE    |      |     1 |            |          |            
|   2 |   TABLE ACCESS FULL| T1   |  7909 |    29   (0)| 00:00:01 |            
-------------------------------------------------------------------            


统计信息
----------------------------------------------------------                     
          1  recursive calls                                                   
          0  db block gets                                                     
        105  consistent gets                                                   
          0  physical reads                                                    
          0  redo size                                                         
        420  bytes sent via SQL*Net to client                                  
        416  bytes received via SQL*Net from client                            
          2  SQL*Net roundtrips to/from client                                 
          0  sorts (memory)                                                    
          0  sorts (disk)                                                      
          1  rows processed                                                    

SQL> ALTER SESSION SET optimizer_mode=choose;
会话已更改。
已用时间:  00: 00: 00.00
SQL> select count (*) from t1;
  COUNT(*)                                                                     
----------                                                                     
      7909                                                                     
已用时间:  00: 00: 00.00
执行计划
----------------------------------------------------------                     
Plan hash value: 3724264953                                                    
                                                                               
-------------------------------------------------------------------            
| Id  | Operation          | Name | Rows  | Cost (%CPU)| Time     |            
-------------------------------------------------------------------            
|   0 | SELECT STATEMENT   |      |     1 |    29   (0)| 00:00:01 |            
|   1 |  SORT AGGREGATE    |      |     1 |            |          |            
|   2 |   TABLE ACCESS FULL| T1   |  7909 |    29   (0)| 00:00:01 |            
-------------------------------------------------------------------            


统计信息
----------------------------------------------------------                     
          1  recursive calls                                                   
          0  db block gets                                                     
        105  consistent gets                                                   
          0  physical reads                                                    
          0  redo size                                                         
        420  bytes sent via SQL*Net to client                                  
        416  bytes received via SQL*Net from client                            
          2  SQL*Net roundtrips to/from client                                 
          0  sorts (memory)                                                    
          0  sorts (disk)                                                      
          1  rows processed                                                    

SQL> spool off

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22664653/viewspace-668546/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/22664653/viewspace-668546/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值