- 论坛徽章:
- 0
|
SQL> select * from zhb where a='111';
未选定行
执行计划
----------------------------------------------------------
Plan hash value: 427883430
--------------------------------------------------------------------------------
-----
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
-----
| 0 | SELECT STATEMENT | | 1 | 24 | 1 (0)| 00:00
:01 |
|* 1 | TABLE ACCESS BY INDEX ROWID| ZHB | 1 | 24 | 1 (0)| 00:00
:01 |
|* 2 | INDEX RANGE SCAN | ZHB01 | 1 | | 1 (0)| 00:00
:01 |
--------------------------------------------------------------------------------
-----
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("A"='111')
2 - access(SUBSTR("A",1,1)='1')
Note
-----
- dynamic sampling used for this statement
统计信息
----------------------------------------------------------
4 recursive calls
0 db block gets
5 consistent gets
0 physical reads
0 redo size
318 bytes sent via SQL*Net to client
374 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
从以上可以看到这个查询走了索引,按照理论上面来说这个查询不应该走索引,而应该是全表扫描所以造成了结果错误
修复这个错误就是改变这个执行计划,不走索引
我们使用
analyze table zhb compute statistic
select * from zhb where a='111'
A B
---------- ----------
111 222
结果正确,查看执行计划为
SQL> select * from zhb where a='111';
执行计划
----------------------------------------------------------
Plan hash value: 2382782857
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 20 | 2 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| ZHB | 1 | 20 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("A"='111' AND SUBSTR("ZHB"."A",1,1)='1')
统计信息
----------------------------------------------------------
1 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
471 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed |
|