暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

LIKE 什么时候走索引

原创 章芋文 2012-05-28
458
SQL> set autotrace traceonly
SQL> select count(*) from awen.ob_bak where owner='AWEN';


执行计划
----------------------------------------------------------
Plan hash value: 3442547862

------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 1860 (4)| 00:00:03 |
| 1 | SORT AGGREGATE | | 1 | 6 | | |
|* 2 | INDEX RANGE SCAN| OB_INDEX | 774K| 4538K| 1860 (4)| 00:00:03 |
------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

2 - access("OWNER"='AWEN')


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

SQL> select count(*) from awen.ob_bak where owner like '%AWEN%';


执行计划
----------------------------------------------------------
Plan hash value: 961138420

-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 47284 (6)| 00:00:58 |
| 1 | SORT AGGREGATE | | 1 | 6 | | |
|* 2 | INDEX FULL SCAN| OB_INDEX | 968K| 5673K| 47284 (6)| 00:00:58 |
-----------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

2 - filter("OWNER" LIKE '%AWEN%')


统计信息
----------------------------------------------------------
1 recursive calls
0 db block gets
44622 consistent gets
44636 physical reads
0 redo size
409 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

SQL> select count(*) from awen.ob_bak where owner like '%AWE%';


执行计划
----------------------------------------------------------
Plan hash value: 961138420

-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 47284 (6)| 00:00:58 |
| 1 | SORT AGGREGATE | | 1 | 6 | | |
|* 2 | INDEX FULL SCAN| OB_INDEX | 968K| 5673K| 47284 (6)| 00:00:58 |
-----------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

2 - filter("OWNER" LIKE '%AWE%')


统计信息
----------------------------------------------------------
1 recursive calls
0 db block gets
44622 consistent gets
44614 physical reads
0 redo size
409 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

SQL> select count(*) from awen.ob_bak where owner like 'AWE%';


执行计划
----------------------------------------------------------
Plan hash value: 3442547862

------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 1860 (4)| 00:00:03 |
| 1 | SORT AGGREGATE | | 1 | 6 | | |
|* 2 | INDEX RANGE SCAN| OB_INDEX | 774K| 4538K| 1860 (4)| 00:00:03 |
------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

2 - access("OWNER" LIKE 'AWE%')
filter("OWNER" LIKE 'AWE%')


统计信息
----------------------------------------------------------
1 recursive calls
0 db block gets
8 consistent gets
0 physical reads
0 redo size
409 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

SQL> select count(*) from awen.ob_bak where owner like 'AWEN';


执行计划
----------------------------------------------------------
Plan hash value: 3442547862

------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 1860 (4)| 00:00:03 |
| 1 | SORT AGGREGATE | | 1 | 6 | | |
|* 2 | INDEX RANGE SCAN| OB_INDEX | 774K| 4538K| 1860 (4)| 00:00:03 |
------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

2 - access("OWNER" LIKE 'AWEN')


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


like 'AWEN' 走索引
like 'AWE%' 走索引
like '%AWE' 不走
like '%AWE%' 不走

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论