|
资料库sga1.7g
现在有一个表的数据有32000笔资料
语句如下
表mic_news上substr(classcode,0,8),hit列上已加过索引,主键在id上
select id,
title,
addtime,
hit,
CONTENT,
classcode,
typeid
from (select *
from mic_news
where substr(classcode, 0, 8) = 00140019
order by hit desc)
where rownum <= 10
执行时间为10秒左右
下面是explain plan
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=FIRST_ROWS (Cost=113 Card=10 Byte
s=275400)
1 0 COUNT (STOPKEY)
2 1 VIEW (Cost=113 Card=100 Bytes=275400)
3 2 SORT (ORDER BY STOPKEY) (Cost=3665 Card=3255 Bytes=524
055)
4 3 TABLE ACCESS (FULL) OF 'MIC_NEWS' (Cost=3585 Card=32
55 Bytes=524055)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
58731 consistent gets
4 physical reads
0 redo size
8674 bytes sent via SQL*Net to client
3433 bytes received via SQL*Net from client
32 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
10 rows processed
强制使用索引语句如下
select id,
title,
addtime,
hit,
CONTENT,
classcode,
typeid
from (select /*+index(m) */ *
from mic_news m
where substr(classcode, 0, 8) = 00140019
order by hit desc)
where rownum <= 10
这个时候使用的索引为主键上的索引,执行时间超过20秒,强制使用index(mic_news,idx_hit)以及index(mic_news,idx_substr(classcode,0,8))没有任何效果
explain plan 如下
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=FIRST_ROWS (Cost=8440 Card=10 Byt
es=275400)
1 0 COUNT (STOPKEY)
2 1 VIEW (Cost=8440 Card=100 Bytes=275400)
3 2 SORT (ORDER BY STOPKEY) (Cost=274711 Card=3255 Bytes=5
24055)
4 3 TABLE ACCESS (BY INDEX ROWID) OF 'MIC_NEWS' (Cost=27
4631 Card=3255 Bytes=524055)
5 4 INDEX (FULL SCAN) OF 'PK_MIC_NEWS' (UNIQUE) (Cost=
681 Card=325506)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
274658 consistent gets
4 physical reads
0 redo size
8679 bytes sent via SQL*Net to client
3433 bytes received via SQL*Net from client
32 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
10 rows processed
从explain plan里面能发现consistent gets很高
各位大侠,是语句有问题吗? |
|