- 最后登录
- 2019-7-8
- 在线时间
- 133 小时
- 威望
- 131
- 金钱
- 1368
- 注册时间
- 2011-10-14
- 阅读权限
- 50
- 帖子
- 126
- 精华
- 1
- 积分
- 131
- UID
- 31
|
1#
发表于 2012-4-17 16:37:36
|
查看: 5030 |
回复: 3
- SQL> drop table t2 purge;
- Table dropped.
- SQL> create table t2 as select * from all_objects
- 2 ;
- Table created.
- SQL> create index idn_t2 on t2(status);
- Index created.
- SQL> exec dbms_stats.gather_table_stats(ownname=>'CLM',tabname=>'T2',cascade=>true,estimate_percent=>100,method_opt=>'for all columns size 1');
- PL/SQL procedure successfully completed.
- SQL> select status,count(1) from t2 group by t2;
- select status,count(1) from t2 group by t2
- *
- ERROR at line 1:
- ORA-00904: "T2": invalid identifier
- SQL> select status,count(1) from t2 group by status;
- STATUS COUNT(1)
- ------- ----------
- VALID 71038
- INVALID 2
- SQL> set autotrace on
- SQL> select object_id ,status from t2 where status='INVALID';
- OBJECT_ID STATUS
- ---------- -------
- 73871 INVALID
- 73846 INVALID
- Execution Plan
- ----------------------------------------------------------
- Plan hash value: 1513984157
- --------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
- --------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 35520 | 416K| 284 (1)| 00:00:04 |
- |* 1 | TABLE ACCESS FULL| T2 | 35520 | 416K| 284 (1)| 00:00:04 |
- --------------------------------------------------------------------------
- Predicate Information (identified by operation id):
- ---------------------------------------------------
- 1 - filter("STATUS"='INVALID')
- Statistics
- ----------------------------------------------------------
- 1 recursive calls
- 0 db block gets
- 1018 consistent gets
- 0 physical reads
- 0 redo size
- 669 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)
- 2 rows processed
- SQL>
复制代码
为什么走的是全表扫描?这个invalid只有2个值应该有索引才对啊,忘刘总解答 |
|