- 最后登录
- 2013-5-21
- 在线时间
- 3 小时
- 威望
- 0
- 金钱
- 16
- 注册时间
- 2012-7-13
- 阅读权限
- 10
- 帖子
- 7
- 精华
- 0
- 积分
- 0
- UID
- 610
|
1#
发表于 2012-12-11 14:58:19
|
查看: 5315 |
回复: 10
本帖最后由 dbman 于 2012-12-11 16:10 编辑
刘大,帮忙优化一下这条语句,我试了一些方法基本都没有效果,谢谢!
sql语句:
SELECT *
FROM (SELECT INFO.*, ROWNUM RNUM
FROM (SELECT distinct INF.STCO_ID AS STCO_ID,
AOU.SSG_SSI_STUDENT_ID,
INF.SSI_STUDENT_NAME,
INF.SSI_CARD_NUM,
INF.SSI_COMPANY_NAME,
BCS.SCO_NAME AS SCO_NAME,
CTY.CTCE_NAME AS CTCE_NAME,
SUT.STCO_NAME
FROM SAC_STUDENT_GRADE AOU
LEFT JOIN SAC_STUDENT_INFO INF
ON INF.SSI_STUDENT_ID = AOU.SSG_SSI_STUDENT_ID
LEFT JOIN sex_code BCS
ON INF.SCO_ID = BCS.SCO_ID
LEFT JOIN certificates_type_code CTY
ON CTY.CTCE_ID = INF.CTCE_ID
LEFT JOIN SAC_COURSE_INFO SCI
ON SCI.SCI_COURSE_ID = AOU.SSG_EXAM_COURSE_CODE
LEFT JOIN student_type_code SUT
ON SUT.STCO_ID = INF.STCO_ID
WHERE 1 = 1
AND inf.stco_id = '01'
ORDER BY SSI_CARD_NUM desc) INFO
WHERE ROWNUM < = 10)
WHERE RNUM > = 1
执行计划:
????: 00: 00: 22.73
----------------------------------------------------------
Plan hash value: 3536158082
---------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 2220 | | 142K (1)| 00:28:30 |
|* 1 | VIEW | | 10 | 2220 | | 142K (1)| 00:28:30 |
|* 2 | COUNT STOPKEY | | | | | | |
| 3 | VIEW | | 1576K| 314M| | 142K (1)| 00:28:30 |
|* 4 | SORT ORDER BY STOPKEY | | 1576K| 132M| 144M| 142K (1)| 00:28:30 |
| 5 | HASH UNIQUE | | 1576K| 132M| 144M| 110K (1)| 00:22:07 |
| 6 | MERGE JOIN OUTER | | 1576K| 132M| | 78615 (1)| 00:15:44 |
| 7 | MERGE JOIN OUTER | | 1576K| 118M| | 78613 (1)| 00:15:44 |
| 8 | SORT JOIN | | 1576K| 105M| | 78609 (1)| 00:15:44 |
| 9 | MERGE JOIN OUTER | | 1576K| 105M| | 78609 (1)| 00:15:44 |
| 10 | SORT JOIN | | 1576K| 94M| | 78604 (1)| 00:15:44 |
|* 11 | HASH JOIN | | 1576K| 94M| 24M| 78604 (1)| 00:15:44 |
|* 12 | TABLE ACCESS FULL | SAC_STUDENT_INFO | 405K| 20M| | 22698 (1)| 00:04:33 |
| 13 | TABLE ACCESS FULL | SAC_STUDENT_GRADE | 11M| 119M| | 42130 (1)| 00:08:26 |
|* 14 | SORT JOIN | | 3 | 21 | | 5 (20)| 00:00:01 |
| 15 | TABLE ACCESS FULL | SEX_CODE | 3 | 21 | | 4 (0)| 00:00:01 |
|* 16 | SORT JOIN | | 3 | 27 | | 4 (25)| 00:00:01 |
| 17 | TABLE ACCESS FULL | CERTIFICATES_TYPE_CODE | 3 | 27 | | 3 (0)| 00:00:01 |
|* 18 | SORT JOIN | | 1 | 9 | | 2 (50)| 00:00:01 |
| 19 | TABLE ACCESS BY INDEX ROWID| STUDENT_TYPE_CODE | 1 | 9 | | 1 (0)| 00:00:01 |
|* 20 | INDEX UNIQUE SCAN | PK_STUDENT_TYPE_CODE | 1 | | | 0 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("RNUM">=1)
2 - filter(ROWNUM<=10)
4 - filter(ROWNUM<=10)
11 - access("INF"."SSI_STUDENT_ID"="AOU"."SSG_SSI_STUDENT_ID")
12 - filter("INF"."STCO_ID"='01')
14 - access("INF"."SCO_ID"="BCS"."SCO_ID"(+))
filter("INF"."SCO_ID"="BCS"."SCO_ID"(+))
16 - access("CTY"."CTCE_ID"(+)="INF"."CTCE_ID")
filter("CTY"."CTCE_ID"(+)="INF"."CTCE_ID")
18 - access("SUT"."STCO_ID"(+)="INF"."STCO_ID")
filter("SUT"."STCO_ID"(+)="INF"."STCO_ID")
20 - access("SUT"."STCO_ID"(+)='01')
????
----------------------------------------------------------
420 recursive calls
13 db block gets
238112 consistent gets
53751 physical reads
0 redo size
1686 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
4 sorts (memory)
2 sorts (disk)
10 rows processed
数据量:
SAC_STUDENT_INFO 300W
SAC_STUDENT_GRADE 1100W
其他表数据为几条,十几条
distinct SAC_STUDENT_INFO.SSI_STUDENT_ID 290W
distinct SAC_STUDENT_GRADE.SSG_SSI_STUDENT_ID 300W
distinct SAC_STUDENT_INFO.STCO_ID 7条
sqlhc_sac_sac1_11.2.0.3.0_gz9u3dz8xnu4w_20121211154208.html
(41.94 KB, 下载次数: 752)
1.txt
(47.36 KB, 下载次数: 1046)
|
|