|
原帖由 askgyliu 于 2008-5-6 13:53 发表 ![]()
1) CUST_ID 应当是UNIQUE,不然的话出来的结果基本可以肯定是错误的。在CUST_ID上应该有UNIQUE INDEX或是PRIMARY KEY。
2) MSJOIN 应该是对的。除非CCP.CUST_BILLSUM_200802 a中符合“USEE8_TIME is null”的很少。也就是说,正常情况下TBSCAN在这个QUERY是对的。
3) OPTIMIZATION LEVEL越低考虑的因素就越少吧?
4) SORT时应该是这个的RESULTED ROW在做SORTING,SORTED BY CUST_ID,BUT THE WHOLE ROW WILL BE PLACED IN THE SORT HEAP。LZ的QUERY里有几十个COLUMNS。
5) 回到DESIGN问题。若是商业要求做WEEKLY REPORT,那怎么办?ROLLING REPORT呢?把几个TABLES UNION ALL成一个VIEW?觉得很成问题。
got questions, for your comment (2), why do you think MSJOIN is correct? i was thinking SORT may underestimated the cost because for a small SORTHEAP, 3 sorts in the plan may overflow to tempspace or even overflow to disk... (but didn't do manual calculation, just a brief idea)
i think you mean TBSCAN on CUST_BILLSUM_200 was correct, because most of the rows in the table are NOT NULL...
3) when optlvl<2 db2 uses greedy algorithm rather than dynamic programming, especially in opt=0, which will pickup index whenever possible, so that's a common way to test how's the runtime performance with using an index 
4) yeah you are right, the whole row will be placed in sortheap, unless the plan uses FETCH on top, TBSCAN+SORT on outter side and table name on inner side...
ex:
9) SORT : (Sort)
Cumulative Total Cost: 2.61297e+006
Cumulative CPU Cost: 1.72482e+010
Cumulative I/O Cost: 474282
Cumulative Re-Total Cost: 0
Cumulative Re-CPU Cost: 0
Cumulative Re-I/O Cost: 159922
Cumulative First Row Cost: 2.61297e+006
Cumulative Comm Cost: 0
Cumulative First Comm Cost: 0
Estimated Bufferpool Buffers: 547612
Arguments:
---------
DUPLWARN: (Duplicates Warning flag)
FALSE
NUMROWS : (Estimated number of rows)
1166257
PARTCOLS: (Table partitioning columns)
1: Q3."CUST_ID"
ROWWIDTH: (Estimated width of rows)
780
SORTKEY : (Sort Key column)
1: Q3."CUST_ID"(A)
SORTTYPE: (Intra-Partition parallelism sort type)
PARTITIONED
SPILLED : (Pages spilled to bufferpool or disk)
233252
TEMPSIZE: (Temporary Table Page Size)
4096
UNIQUE : (Uniqueness required flag)
FALSE
in this sort, please note that ROWWIDTH=780 and NUMROWS=1166257, so from calculation 780*1166257/1024/1024~=867MB.... that means at least 867MB of sortheap will be required for this particular sort.... and please note there are 3 sorts in the original plan.... |
|