請教:為什麼這二個語句速度不一樣?

[复制链接]
查看11 | 回复8 | 2014-2-18 16:42:02 | 显示全部楼层 |阅读模式
第二個查詢多一個rownum,速度就會快一點,其中kq_view是一個視圖,不知道是什麼原因,請指教,謝謝!
[php]
SQL> set timing on
SQL> set autotrace on
SQL> set linesize 999
SQL> select kq_view.*
2from kq_view
3 where 1 = 1
4 and oeb04 = 'GN90P150261B0123';
OEA02OEB01 OEB03 OEB04
OEB12 SUM006 SL B OEB16OEA04OEB15FLOSL V_SUM009 OEA03
---------- ---------- ---------- -------------------- ---------- ---------- ---------- - ---------- ---------- ---------- -- ---------- ---------- -----
2006/03/24 S7E-630223
4 GN90P150261B0123
200 75
0 N 2006/05/16 WE000562006/05/16 沒 17
0 ATP
目前歷時: 00:00:04.47
執行計畫
----------------------------------------------------------
0SELECT STATEMENT Optimizer=CHOOSE (Cost=318 Card=94 Bytes=19

270)
10 HASH JOIN (OUTER) (Cost=318 Card=94 Bytes=19270)
21 HASH JOIN (OUTER) (Cost=191 Card=1 Bytes=175)
32 HASH JOIN (OUTER) (Cost=118 Card=1 Bytes=130)
43 VIEW (Cost=5 Card=1 Bytes=86)
54 SORT (ORDER BY) (Cost=5 Card=1 Bytes=75)
65
NESTED LOOPS (Cost=3 Card=1 Bytes=75)
76
TABLE ACCESS (FULL) OF 'OEB_FILE' (Cost=2 Card

=1 Bytes=42)
86
TABLE ACCESS (BY INDEX ROWID) OF 'OEA_FILE' (C

ost=1 Card=1 Bytes=33)
98
INDEX (UNIQUE SCAN) OF 'OEA_01' (UNIQUE)
103 VIEW (Cost=113 Card=885 Bytes=38940)
11 10 SORT (GROUP BY) (Cost=113 Card=885 Bytes=46905)
12 11
TABLE ACCESS (FULL) OF 'TC_SAPA_FILE' (Cost=106

Card=885 Bytes=46905)
132 VIEW (Cost=72 Card=2373 Bytes=106785)
14 13 SORT (GROUP BY) (Cost=72 Card=2373 Bytes=111531)
15 14 TABLE ACCESS (FULL) OF 'TC_SAPC_FILE' (Cost=57 Car

d=2373 Bytes=111531)
161 VIEW (Cost=126 Card=4423 Bytes=132690)
17 16 SORT (GROUP BY) (Cost=126 Card=4423 Bytes=141536)
18 17 TABLE ACCESS (FULL) OF 'TC_SAPA_FILE' (Cost=106 Card

=4423 Bytes=141536)


統計值
----------------------------------------------------------

0recursive calls
56db block gets
4349consistent gets
5398physical reads

0redo size
1194bytes sent via SQL*Net to client
503bytes received via SQL*Net from client

2SQL*Net roundtrips to/from client

3sorts (memory)

1sorts (disk)

1rows processed
SQL> select rownum, kq_view.*
2from kq_view
3 where 1 = 1
4 and oeb04 = 'GN90P150261B0123';
ROWNUM OEA02OEB01 OEB03 OEB04
OEB12 SUM006 SL B OEB16OEA04OEB15FLOSL V_SUM0
---------- ---------- ---------- ---------- -------------------- ---------- ---------- ---------- - ---------- ---------- ---------- -- ---------- --------
1 2006/03/24 S7E-630223
4 GN90P150261B0123
200 75
0 N 2006/05/16 WE000562006/05/16 沒 17
目前歷時: 00:00:00.91
執行計畫
----------------------------------------------------------
0SELECT STATEMENT Optimizer=CHOOSE (Cost=278 Card=44 Bytes=90

20)
10 COUNT
21 MERGE JOIN (OUTER) (Cost=278 Card=44 Bytes=9020)
32 HASH JOIN (OUTER) (Cost=172 Card=1 Bytes=175)
43 NESTED LOOPS (OUTER) (Cost=112 Card=1 Bytes=130)
54 VIEW (Cost=5 Card=1 Bytes=86)
65
SORT (ORDER BY) (Cost=5 Card=1 Bytes=75)
76
NESTED LOOPS (Cost=3 Card=1 Bytes=75)
87
TABLE ACCESS (FULL) OF 'OEB_FILE' (Cost=2 Ca

rd=1 Bytes=42)
97
TABLE ACCESS (BY INDEX ROWID) OF 'OEA_FILE'

(Cost=1 Card=1 Bytes=33)
109
INDEX (UNIQUE SCAN) OF 'OEA_01' (UNIQUE)
114 VIEW (Cost=108 Card=1 Bytes=44)
12 11
SORT (GROUP BY) (Cost=108 Card=9 Bytes=477)
13 12
TABLE ACCESS (FULL) OF 'TC_SAPA_FILE' (Cost=10

6 Card=9 Bytes=477)
143 VIEW (Cost=59 Card=24 Bytes=1080)
15 14 SORT (GROUP BY) (Cost=59 Card=24 Bytes=1128)
16 15
TABLE ACCESS (FULL) OF 'TC_SAPC_FILE' (Cost=57 C

ard=24 Bytes=1128)
172 BUFFER (SORT) (Cost=278 Card=44 Bytes=1320)
18 17 VIEW (Cost=106 Card=44 Bytes=1320)
19 18 SORT (GROUP BY) (Cost=106 Card=44 Bytes=1408)
20 19
TABLE ACCESS (FULL) OF 'TC_SAPA_FILE' (Cost=106

Card=44 Bytes=1408)


統計值
----------------------------------------------------------

0recursive calls

0db block gets
4349consistent gets
4135physical reads

0redo size
1251bytes sent via SQL*Net to client
503bytes received via SQL*Net from client

2SQL*Net roundtrips to/from client

5sorts (memory)

0sorts (disk)

1rows processed
[/php]
回复

使用道具 举报

千问 | 2014-2-18 16:42:02 | 显示全部楼层
都多执行几次,看“統計值”有什么不同吧。
回复

使用道具 举报

千问 | 2014-2-18 16:42:02 | 显示全部楼层
select kq_view.*
from kq_view
where 1 = 1
and oeb04 = 'GN90P150261B0123';
shutdown immediate
startup
select rownum,kq_view.*
from kq_view
where 1 = 1
and oeb04 = 'GN90P150261B0123';
然后再比较一下两者的区别
回复

使用道具 举报

千问 | 2014-2-18 16:42:02 | 显示全部楼层
最初由 cjf107 发布
[B]都多执行几次,看“統計值”有什么不同吧。 [/B]

謝謝,執行幾次都差不多.
回复

使用道具 举报

千问 | 2014-2-18 16:42:02 | 显示全部楼层
最初由 hanson 发布
[B]select kq_view.*
from kq_view
where 1 = 1
and oeb04 = 'GN90P150261B0123';
shutdown immediate
startup
select rownum,kq_view.*
from kq_view
where 1 = 1
and oeb04 = 'GN90P150261B0123';
然后再比较一下两者的区别 [/B]

是關閉數據庫再重啟嗎?我這是生產用的數據庫!


回复

使用道具 举报

千问 | 2014-2-18 16:42:02 | 显示全部楼层
先把disk sort搞掉
回复

使用道具 举报

千问 | 2014-2-18 16:42:02 | 显示全部楼层
执行计划不一样
做个10053的event看看……
回复

使用道具 举报

千问 | 2014-2-18 16:42:02 | 显示全部楼层
加了rownum后,明显表TC_SAPA_FILE扫描的记录少了许多,我想这和你使用的视图有关系
回复

使用道具 举报

千问 | 2014-2-18 16:42:02 | 显示全部楼层
谢谢大家指点,我先去找找这些资料!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行