如何在oracle 10g中设置sort_area_size以及应该是什么尺寸,因为我在单个表中有超过2.2m的行。请告诉我SORT_AREA_RETAINED_SIZE的建议大小
因为我的查询太慢,所以需要1个多小时才能完成。 (大多) 请建议我如何优化我的查询和调整数据库oracle 10g
感谢
查询
SELECT A.TITLE,C.TOWN_VILL U_R,F.CODE TOWN_CODE,F.CITY_TOWN_MAKE,A.FRM,A.PRD_CODE,A.BR_CODE,A.SIZE_CODE ,B.PRICES,
A.PROJECT_YY,A.PROJECT_MM,d.province ,D.BR_CODE BRANCH_CODE,D.STRATUM,L.LSM_GRP LSM,
SUM(GET_FRAC_FACTOR_ALL_PR_NEW(A.FRM,A.PRD_CODE,A.BR_CODE,A.SIZE_CODE,A.PROJECT_YY,A.PROJECT_MM,A.FRAC_CODE ,B.PRICES,A.QTY_USED,A.VERIF_CODE, A.PACKING_CODE, J.TYPE ,'R') )
* MAX(D.UNIVERSE) / MAX(E.SAMPLE) /1000000 MARKET , D.UNIVERSE ,E.SAMPLE
FROM A2_FOR_CPMARKETS A,
BRAND J,
PRICES B,CP_SAMPLE_ALL_MONTHS C ,
CP_LSM L,
HOUSEHOLD_GL D,
SAMPLE_CP_ALL_MONTHS E ,
City_Town_ALL F
WHERE A.PRD_CODE = B.PRD_CODE
AND A.BR_CODE = B.BR_CODE
AND DECODE(A.SIZE_CODE,NULL,'L',A.SIZE_CODE) = B.SIZE_CODE -- for unbranded loose
AND DECODE(B.VAR_CODE,'X','X',A.VAR_CODE) = B.VAR_CODE
AND DECODE(B.COL_CODE,'X','X',A.COL_CODE) = B.COL_CODE
AND DECODE(B.PACK_CODE,'X','X',A.PACKING_CODE) = B.PACK_CODE
AND A.project_yy||A.project_MM BETWEEN B.START_DATE AND B.END_DATE
AND A.PRD_CODE=J.PRD_CODE
AND A.BR_CODE=J.BR_CODE
AND A.FRM = C.FRM
AND A.PROJECT_YY=L.YEAR
AND A.frm=L.FORM_NO
AND C.TOWN_VILL= D.U_R
AND C.CLASS = D.CLASS
AND D.TOWN=F.GRP
AND D.TOWN = E.TOWN_CODE
AND A.PROJECT_YY = E.PROJECT_YY
AND A.PROJECT_MM = E.PROJECT_MM
AND A.PROJECT_YY = C.PROJECT_YY
AND A.PROJECT_MM = C.PROJECT_MM
-- FOR HOUSEJOLD_GL
AND A.PROJECT_YY = D.YEAR
AND A.PROJECT_MM = D.MONTH
-- END HOUSEHOLD_GL
AND C.TOWN_VILL = E.TOWN_VILL
AND C.CLASS = E.CLASS
AND C.TOWN_VILL = F.TOWN_VILL
AND C.TOWN_CODE=F.CODE
AND (DECODE(e.PROJECT_YY,'1997','1','1998','1','1999','1','2000','1','2001','1','2002','1','2') = F.TYP )
GROUP BY A.TITLE,C.TOWN_VILL,F.CODE ,F.CITY_TOWN_MAKE,A.FRM,A.PRD_CODE,A.BR_CODE,A.SIZE_CODE ,B.PRICES,
A.PROJECT_YY,A.PROJECT_MM,d.province,D.BR_CODE ,D.STRATUM,L.LSM_GRP ,
UNIVERSE ,E.SAMPLE
![alt text] [1]
[1]:http://C:\ Documents and Settings \ Hussain \ My Documents \ My Pictures \ explain plan.jpg
答案 0 :(得分:1)
点击此处查看SORT_AREA_SIZE的Oracle文档。您可以使用alter session set sort_area_size=10000
命令为会话和alter system
系统修改此命令。对于SORT_AREA_RETAINED_SIZE,它的方式相同。
您是否在结果集中获取了整个表( 2.2 m行)?是否有某种排序操作?
查询执行不当可能还有其他一些原因。你能分享查询和解释计划吗?
答案 1 :(得分:1)
当您使用DBMS_Xplan.Display方法运行查询的执行计划时,oracle将估计(通常非常合理地)执行它所需的临时表空间存储大小。
顺便说一下,2.2百万行可能与排序大小无关。聚合操作(如MAX和SUM)所需的内存与结果集的大小相关,而不是与源数据的大小相关。
提供存储在您电脑上的jpg文件的链接并不算是提供了执行计划,顺便说一句。
答案 2 :(得分:1)
A.project_yy||A.project_MM BETWEEN B.START_DATE AND B.END_DATE
你知道我们在数据库中有DATE数据类型,对吗?使用不正确的数据类型使Oracle更难确定数据分布,谓词选择性和适当的查询计划