??xml version="1.0" encoding="utf-8" standalone="yes"?>
CODE NAME B01 S01 B02 S02
1 张三 数学 80
1 张三 语文 75
2 王五 数学 70
2 王五
3 李四 数学 50
3 李四 语文 88
希望查询出如下结果:
CODE SUM_STR(NAME) B01 SUM_STR(S01) B02 SUM_STR(S02)
1 张三 数学 80 语文 75
2 王五 数学 70
3 李四 数学 50 语文 88
q个问题可以采用自定义的聚集函数来实玎ͼ
------------------------------------
-------------------
-------最后查询语句:
2 alias_p2.title, alias_p2.sendercn, alias_p2.operatedes, alias_p2.pendingstate,
3 alias_p2.parameter, alias_p2.createdate, alias_p2.deptname, alias_p2.completeddate ,
4 alias_p2.openstate , alias_p2.name, alias_p2.processinstanceid, alias_p2.asset
5 from ( select alias_p1.pendingid, alias_p1.workitemid, alias_p1.operationid,
6 alias_p1.operationkey, alias_p1.title, alias_p1.sendercn, alias_p1.operatedes,
7 alias_p1.pendingstate, alias_p1.parameter, alias_p1.createdate, alias_p1.deptname,
8 alias_p1.completeddate , alias_p1.openstate , alias_p1.name, alias_p1.processinstanceid ,
9 alias_p1.asset , rownum rn from(select alias_p.pendingid, alias_p.workitemid, alias_p.operationid,
10 alias_p.operationkey, alias_p.title, alias_p.sendercn, alias_p.operatedes, alias_p.pendingstate,
11 alias_p.parameter, alias_p.createdate, alias_p.deptname, alias_p.completeddate , alias_p.openstate ,
12 pd.name, w.processinstanceid , eam_db.concatassetname( alias_p.operationkey, alias_p.operationid )
13 asset from WF_Pending alias_p, WF_WorkItem w, WF_ProcessDefinition pd, WF_ProcessInstance pi
14 where alias_p.ownerid='qinxue' and alias_p.pendingstate in(0,3,5,7,9,10,11,12)
15 and (alias_p.deptname=' 审控部信息处 ' or alias_p.deptname='' or alias_p.deptname is null)
16 and w.workitemid = alias_p.workitemid and pi.processinstanceid = w.processinstanceid
17 and pi.completeddate is null and pd.processdefinitionid = w.processdefinitionid order by alias_p.createdate desc) alias_p1 where rownum <=10)
alias_p2 where rn>=1;
已选择 10 行?/span>
执行计划
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=10 Card=1 Bytes=2507
)
1 0 VIEW (Cost=10 Card=1 Bytes=2507)
2 1 COUNT (STOPKEY)
3 2 VIEW (Cost=10 Card=1 Bytes=2494)
4 3 SORT (ORDER BY STOPKEY) (Cost=10 Card=1 Bytes=167)
5 4 NESTED LOOPS (Cost=8 Card=1 Bytes=167)
6 5 NESTED LOOPS (Cost=7 Card=1 Bytes=162)
7 6 NESTED LOOPS (Cost=6 Card=1 Bytes=134)
8 7 TABLE ACCESS (FULL) OF 'WF_PENDING' (Cost=5
Card=1 Bytes=111)
9 7 TABLE ACCESS (BY INDEX ROWID) OF 'WF_WORKITE
M' (Cost=1 Card=3 Bytes=69)
10 9 INDEX (UNIQUE SCAN) OF 'SYS_C003694' (UNIQ
UE)
11 6 TABLE ACCESS (BY INDEX ROWID) OF 'WF_PROCESSDE
FINITION' (Cost=1 Card=1 Bytes=28)
12 11 INDEX (UNIQUE SCAN) OF 'SYS_C003684' (UNIQUE
)
13 5 TABLE ACCESS (BY INDEX ROWID) OF 'WF_PROCESSINST
ANCE' (Cost=1 Card=1 Bytes=5)
14 13 INDEX (UNIQUE SCAN) OF 'SYS_C003662' (UNIQUE)
l计信息
----------------------------------------------------------
314 recursive calls
0 db block gets
29433 consistent gets
0 physical reads
0 redo size
2153 bytes sent via SQL*Net to client
372 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
101 sorts (memory)
0 sorts (disk)
10 rows processed
其中一致读辑ֈq?万次Q关联调用出?14ơ。排序数g非常多,昄W一目标是把q两个数据降下来?br />通过q一步的分析。发现出现这些问题的主要原因是调?font size="3">eam_db.concatassetname( alias_p.operationkey, alias_p.operationid )q个包?br />开始考虑直接在sql外层做关联,不用function来实现。利用聚集函数来合ƈ数据?br />着手徏立:
聚集函数Q CREATE OR REPLACE FUNCTION F_ASSETLINK(P_STR VARCHAR2) RETURN VARCHAR2
AGGREGATE USING asset_link;
----------------------
创徏typeQCREATE OR REPLACE TYPE ASSET_LINK AS OBJECT (
STR VARCHAR2(30000),
STATIC FUNCTION ODCIAGGREGATEINITIALIZE(SCTX IN OUT ASSET_LINK) RETURN NUMBER,
MEMBER FUNCTION ODCIAGGREGATEITERATE(SELF IN OUT ASSET_LINK, VALUE IN VARCHAR2) RETURN NUMBER,
MEMBER FUNCTION ODCIAGGREGATETERMINATE(SELF IN ASSET_LINK, RETURNVALUE OUT VARCHAR2, FLAGS IN NUMBER) RETURN NUMBER,
MEMBER FUNCTION ODCIAGGREGATEMERGE(SELF IN OUT ASSET_LINK, CTX2 IN ASSET_LINK) RETURN NUMBER
)
------------------------------------------------------
创徏type bodyQCREATE OR REPLACE TYPE BODY ASSET_LINK IS
STATIC FUNCTION ODCIAGGREGATEINITIALIZE(SCTX IN OUT ASSET_LINK) RETURN NUMBER IS
BEGIN
SCTX := ASSET_LINK(NULL);
RETURN ODCICONST.SUCCESS;
END;
MEMBER FUNCTION ODCIAGGREGATEITERATE(SELF IN OUT ASSET_LINK, VALUE IN VARCHAR2) RETURN NUMBER IS
BEGIN
SELF.STR := SELF.STR ||','|| VALUE;
RETURN ODCICONST.SUCCESS;
END;
MEMBER FUNCTION ODCIAGGREGATETERMINATE(SELF IN ASSET_LINK, RETURNVALUE OUT VARCHAR2, FLAGS IN NUMBER) RETURN NUMBER IS
BEGIN
RETURNVALUE := SELF.STR;
RETURN ODCICONST.SUCCESS;
END;
MEMBER FUNCTION ODCIAGGREGATEMERGE(SELF IN OUT ASSET_LINK, CTX2 IN ASSET_LINK) RETURN NUMBER IS
BEGIN
NULL;
RETURN ODCICONST.SUCCESS;
END;
END;
调整sql如下Q?br />select alias_p.pendingid, alias_p.workitemid, alias_p.operationid,
alias_p.operationkey, alias_p.title, alias_p.sendercn, alias_p.operatedes, alias_p.pendingstate,
alias_p.parameter, alias_p.createdate, alias_p.deptname, alias_p.completeddate , alias_p.openstate ,
pd.name, w.processinstanceid
--,T.ASSETCLASS3 ASSET
,f_assetlink(d3.typename) ASSET
--,eam_db.concatassetname( alias_p.operationkey, alias_p.operationid ) asset
from WF_Pending alias_p, WF_WorkItem w,
WF_ProcessDefinition pd, WF_ProcessInstance pi
, tb_asset_dizhiyihao T,dic_app_wfconfig wfc,dic_app_assettype3 d3
where alias_p.ownerid='qinxue'
and alias_p.pendingstate in(0,3,5,7,9,10,11,12)
and (alias_p.deptname='审控部信息处' or alias_p.deptname='' or alias_p.deptname is null)
and w.workitemid = alias_p.workitemid
and pi.processinstanceid = w.processinstanceid
and pi.completeddate is null
and pd.processdefinitionid = w.processdefinitionid
AND t.pk_businessid = alias_p.operationid
and alias_p.operationkey = wfc.memo_1
and wfc.wfconfig_code = t.wfconfig_code
and t.assetclass3 = d3.assettype3_id
group by alias_p.pendingid, alias_p.workitemid, alias_p.operationid,
alias_p.operationkey, alias_p.title, alias_p.sendercn, alias_p.operatedes, alias_p.pendingstate,
alias_p.parameter, alias_p.createdate, alias_p.deptname, alias_p.completeddate , alias_p.openstate ,
pd.name, w.processinstanceid
order by alias_p.createdate desc
得到l计数据如下Q?br />C:\Documents and Settings\ibm>sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 9?10 19:27:33 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn jic/jic@name
已连接?br />SQL> set autotrace traceonly
SQL> select alias_p.pendingid, alias_p.workitemid, alias_p.operationid,
2 alias_p.operationkey, alias_p.title, alias_p.sendercn, alias_p.operatedes, alias_p.pendingstate,
3 alias_p.parameter, alias_p.createdate, alias_p.deptname, alias_p.completeddate , alias_p.openstate ,
4 pd.name, w.processinstanceid
5 --,T.ASSETCLASS3 ASSET
6 ,f_assetlink(d3.typename) ASSET
7 --,eam_db.concatassetname( alias_p.operationkey, alias_p.operationid ) asset
8 from WF_Pending alias_p, WF_WorkItem w,
9 WF_ProcessDefinition pd, WF_ProcessInstance pi
10 , tb_asset_dizhiyihao T,dic_app_wfconfig wfc,dic_app_assettype3 d3
11 where alias_p.ownerid='qinxue'
12 and alias_p.pendingstate in(0,3,5,7,9,10,11,12)
13 and (alias_p.deptname='审控部信息处' or alias_p.deptname='' or alias_p.deptname is null)
14 and w.workitemid = alias_p.workitemid
15 and pi.processinstanceid = w.processinstanceid
16 and pi.completeddate is null
17 and pd.processdefinitionid = w.processdefinitionid
18 AND t.pk_businessid = alias_p.operationid
19 and alias_p.operationkey = wfc.memo_1
20 and wfc.wfconfig_code = t.wfconfig_code
21 and t.assetclass3 = d3.assettype3_id
22 group by alias_p.pendingid, alias_p.workitemid, alias_p.operationid,
23 alias_p.operationkey, alias_p.title, alias_p.sendercn, alias_p.operatedes, alias_p.pendingstate,
24 alias_p.parameter, alias_p.createdate, alias_p.deptname, alias_p.completeddate , alias_p.openstate ,
25 pd.name, w.processinstanceid
26 order by alias_p.createdate desc;
已选择30行?/p>
执行计划
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=19 Card=1 Bytes=205)
1 0 SORT (GROUP BY) (Cost=19 Card=1 Bytes=205)
2 1 NESTED LOOPS (Cost=17 Card=1 Bytes=205)
3 2 HASH JOIN (Cost=16 Card=1 Bytes=191)
4 3 HASH JOIN (Cost=11 Card=1 Bytes=183)
5 4 NESTED LOOPS (Cost=8 Card=1 Bytes=167)
6 5 NESTED LOOPS (Cost=7 Card=1 Bytes=139)
7 6 NESTED LOOPS (Cost=6 Card=1 Bytes=134)
8 7 TABLE ACCESS (FULL) OF 'WF_PENDING' (Cost=5
Card=1 Bytes=111)
9 7 TABLE ACCESS (BY INDEX ROWID) OF 'WF_WORKITE
M' (Cost=1 Card=1 Bytes=23)
10 9 INDEX (UNIQUE SCAN) OF 'SYS_C004347' (UNIQ
UE)
11 6 TABLE ACCESS (BY INDEX ROWID) OF 'WF_PROCESSIN
STANCE' (Cost=1 Card=1 Bytes=5)
12 11 INDEX (UNIQUE SCAN) OF 'SYS_C004334' (UNIQUE
)
13 5 TABLE ACCESS (BY INDEX ROWID) OF 'WF_PROCESSDEFI
NITION' (Cost=1 Card=1 Bytes=28)
14 13 INDEX (UNIQUE SCAN) OF 'SYS_C004329' (UNIQUE)
15 4 TABLE ACCESS (FULL) OF 'DIC_APP_WFCONFIG' (Cost=2
Card=24 Bytes=384)
16 3 TABLE ACCESS (FULL) OF 'TB_ASSET_DIZHIYIHAO' (Cost=4
Card=310 Bytes=2480)
17 2 TABLE ACCESS (BY INDEX ROWID) OF 'DIC_APP_ASSETTYPE3'
(Cost=1 Card=1 Bytes=14)
18 17 INDEX (UNIQUE SCAN) OF 'PK_DIC_APP_ASSETTYPE3' (UNIQ
UE)
l计信息
----------------------------------------------------------
6 recursive calls
0 db block gets
847 consistent gets
0 physical reads
0 redo size
4102 bytes sent via SQL*Net to client
383 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
其中排序?01变ؓ1?br />一致读降ؓ847。下降非常客?br />兌调用仅有6ơ?br />此sql性能优化非常可观。至此优化结束:)
scgi.debug=3
status.status-url = "/server-status"
status.config-url = "/server-config"
-------------------------------------
## server.virtual-* options
server.document-root = "c:/depot/public"
记得q个需要设|到public目录,不然按默认的rails生成的文档一些东西访问不来的
-----------------------------------------------------------------------------------------------------
需要注意的是你开发的E序需要放在c盘下,不然找不到config/scgi.yamlq个文g
然后lighttpd必须装在c盘下(当前版本?.4.11)