分享
 
 
 

一次分析的全过程

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

我们的程序员抱怨一段执行很慢的程序,我把代码执行分析执行计划,

后果如下:

这是最初的执行效果及执行计划

SQL SELECT "SP_TRANS"."TRANS_NO",

2 "SP_TRANS_SUB"."ITEM_CODE",

3 "SP_ITEM"."ITEM_NAME",

4 "SP_ITEM"."CHART_ID",

5 "SP_ITEM"."SPECIFICATION",

6 "SP_TRANS_SUB"."COUNTRY",

7 "SP_TRANS_SUB"."QTY",

8 "SP_TRANS_SUB"."PRICE",

9 "SP_TRANS"."VENDOR_CODE",

10 "SP_TRANS"."PAY_MODE",

11 NVL("SP_TRANS_SUB"."PAY_QTY",0),

12 0 as PAY_THIS

13 FROM "SP_ITEM",

14 "SP_TRANS_SUB",

15 "SP_TRANS"

16 WHERE ( "SP_TRANS_SUB"."TRANS_NO" = "SP_TRANS"."TRANS_NO" ) and

17 ( "SP_ITEM"."ITEM_CODE" = "SP_TRANS_SUB"."ITEM_CODE" ) and

18 ( ( "SP_TRANS"."VENDOR_CODE" = '20011021023') )

19 /

8 rows selected.

Elapsed: 00: 00: 00.51

Execution Plan

----------------------------------------------------------

0 SELECT STATEMENT Optimizer=CHOOSE

1 0 NESTED LOOPS

2 1 NESTED LOOPS

3 2 TABLE Access (FULL) OF 'SP_TRANS'

4 2 TABLE ACCESS (BY INDEX ROWID) OF 'SP_TRANS_SUB'

5 4 INDEX (RANGE SCAN) OF 'PK_SP_TRANS_SUB' (UNIQUE)

6 1 TABLE ACCESS (BY INDEX ROWID) OF 'SP_ITEM'

7 6 INDEX (UNIQUE SCAN) OF 'PK_SP_ITEM' (UNIQUE)

Statistics

----------------------------------------------------------

0 recursive calls

4 db block gets

323 consistent gets

0 physical reads

0 redo size

1809 bytes sent via SQL*Net to client

425 bytes received via SQL*Net from client

2 SQL*Net roundtrips to/from client

0 sorts (memory)

0 sorts (disk)

8 rows processed

此前这几个表都没有分析过。

然后我analyze相关表

SQL analyze table sp_trans_sub compute statistics;

Table analyzed.

Elapsed: 00: 00: 30.64

SQL SELECT "SP_TRANS"."TRANS_NO",

2 "SP_TRANS_SUB"."ITEM_CODE",

3 "SP_ITEM"."ITEM_NAME",

4 "SP_ITEM"."CHART_ID",

5 "SP_ITEM"."SPECIFICATION",

6 "SP_TRANS_SUB"."COUNTRY",

7 "SP_TRANS_SUB"."QTY",

8 "SP_TRANS_SUB"."PRICE",

9 "SP_TRANS"."VENDOR_CODE",

10 "SP_TRANS"."PAY_MODE",

11 NVL("SP_TRANS_SUB"."PAY_QTY",0),

12 0 as PAY_THIS

13 FROM "SP_ITEM",

14 "SP_TRANS_SUB",

15 "SP_TRANS"

16 WHERE ( "SP_TRANS_SUB"."TRANS_NO" = "SP_TRANS"."TRANS_NO" ) and

17 ( "SP_ITEM"."ITEM_CODE" = "SP_TRANS_SUB"."ITEM_CODE" ) and

18 ( ( "SP_TRANS"."VENDOR_CODE" = '20011021023') )

19 /

8 rows selected.

Elapsed: 00: 00: 06.49

Execution Plan

----------------------------------------------------------

0 SELECT STATEMENT Optimizer=CHOOSE (Cost=18577 Card=126726520

Bytes=30034185240)

1 0 MERGE JOIN (Cost=18577 Card=126726520 Bytes=30034185240)

2 1 SORT (JOIN) (Cost=14722 Card=310300 Bytes=20790100)

3 2 HASH JOIN (Cost=358 Card=310300 Bytes=20790100)

4 3 TABLE ACCESS (FULL) OF 'SP_TRANS' (Cost=43 Card=229

Bytes=8473)

5 3 TABLE ACCESS (FULL) OF 'SP_TRANS_SUB' (Cost=158 Card

=135502 Bytes=4065060)

6 1 SORT (JOIN) (Cost=3855 Card=40840 Bytes=6942800)

7 6 TABLE ACCESS (FULL) OF 'SP_ITEM' (Cost=77 Card=40840 B

ytes=6942800)

Statistics

----------------------------------------------------------

150 recursive calls

89 db block gets

1837 consistent gets

755 physical reads

60 redo size

1732 bytes sent via SQL*Net to client

425 bytes received via SQL*Net from client

2 SQL*Net roundtrips to/from client

4 sorts (memory)

1 sorts (disk)

8 rows processed

SQL

SQL analyze table sp_trans compute statistics;

Table analyzed.

Elapsed: 00: 00: 13.00

SQL

SQL SELECT "SP_TRANS"."TRANS_NO",

2 "SP_TRANS_SUB"."ITEM_CODE",

3 "SP_ITEM"."ITEM_NAME",

4 "SP_ITEM"."CHART_ID",

5 "SP_ITEM"."SPECIFICATION",

6 "SP_TRANS_SUB"."COUNTRY",

7 "SP_TRANS_SUB"."QTY",

8 "SP_TRANS_SUB"."PRICE",

9 "SP_TRANS"."VENDOR_CODE",

10 "SP_TRANS"."PAY_MODE",

11 NVL("SP_TRANS_SUB"."PAY_QTY",0),

12 0 as PAY_THIS

13 FROM "SP_ITEM",

14 "SP_TRANS_SUB",

15 "SP_TRANS"

16 WHERE ( "SP_TRANS_SUB"."TRANS_NO" = "SP_TRANS"."TRANS_NO" ) and

17 ( "SP_ITEM"."ITEM_CODE" = "SP_TRANS_SUB"."ITEM_CODE" ) and

18 ( ( "SP_TRANS"."VENDOR_CODE" = '20011021023') )

19 /

8 rows selected.

Elapsed: 00: 00: 01.62

Execution Plan

----------------------------------------------------------

0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1453 Card=447198 Byt

es=101066748)

1 0 NESTED LOOPS (Cost=1453 Card=447198 Bytes=101066748)

2 1 HASH JOIN (Cost=358 Card=1095 Bytes=61320)

3 2 TABLE ACCESS (FULL) OF 'SP_TRANS' (Cost=43 Card=273 By

tes=7098)

4 2 TABLE ACCESS (FULL) OF 'SP_TRANS_SUB' (Cost=158 Card=1

35502 Bytes=4065060)

5 1 TABLE ACCESS (BY INDEX ROWID) OF 'SP_ITEM' (Cost=1 Card=

40840 Bytes=6942800)

6 5 INDEX (UNIQUE SCAN) OF 'PK_SP_ITEM' (UNIQUE)

Statistics

----------------------------------------------------------

0 recursive calls

8 db block gets

1344 consistent gets

0 physical reads

0 redo size

1824 bytes sent via SQL*Net to client

425 bytes received via SQL*Net from client

2 SQL*Net roundtrips to/from client

3 sorts (memory)

0 sorts (disk)

8 rows processed

SQL

SQL analyze table sp_item compute statistics

2 /

Table analyzed.

Elapsed: 00: 00: 11.67

SQL SELECT "SP_TRANS"."TRANS_NO",

2 "SP_TRANS_SUB"."ITEM_CODE",

3 "SP_ITEM"."ITEM_NAME",

4 "SP_ITEM"."CHART_ID",

5 "SP_ITEM"."SPECIFICATION",

6 "SP_TRANS_SUB"."COUNTRY",

7 "SP_TRANS_SUB"."QTY",

8 "SP_TRANS_SUB"."PRICE",

9 "SP_TRANS"."VENDOR_CODE",

10 "SP_TRANS"."PAY_MODE",

11 NVL("SP_TRANS_SUB"."PAY_QTY",0),

12 0 as PAY_THIS

13 FROM "SP_ITEM",

14 "SP_TRANS_SUB",

15 "SP_TRANS"

16 WHERE ( "SP_TRANS_SUB"."TRANS_NO" = "SP_TRANS"."TRANS_NO" ) and

17 ( "SP_ITEM"."ITEM_CODE" = "SP_TRANS_SUB"."ITEM_CODE" ) and

18 ( ( "SP_TRANS"."VENDOR_CODE" = '20011021023') )

19 /

8 rows selected.

Elapsed: 00: 00: 01.43

Execution Plan

----------------------------------------------------------

0 SELECT STATEMENT Optimizer=CHOOSE (Cost=687 Card=1362 Bytes=

128028)

1 0 HASH JOIN (Cost=687 Card=1362 Bytes=128028)

2 1 HASH JOIN (Cost=358 Card=1362 Bytes=76272)

3 2 TABLE ACCESS (FULL) OF 'SP_TRANS' (Cost=43 Card=273 By

tes=7098)

4 2 TABLE ACCESS (FULL) OF 'SP_TRANS_SUB' (Cost=158 Card=1

35502 Bytes=4065060)

5 1 TABLE ACCESS (FULL) OF 'SP_ITEM' (Cost=77 Card=29547 Byt

es=1122786)

Statistics

----------------------------------------------------------

0 recursive calls

12 db block gets

1820 consistent gets

0 physical reads

0 redo size

1732 bytes sent via SQL*Net to client

425 bytes received via SQL*Net from client

2 SQL*Net roundtrips to/from client

3 sorts (memory)

right"(出处:清风软件下载学院)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有