简体   繁体   English

IBM DB2 ver 09.09.006按组或不按组提取数据的最快方法(性能)

[英]IBM DB2 ver 09.09.006 fastest way to pull data group by or no group by (Performance)

I am looking for the fastest way to get a unique record set from 4 tables. 我正在寻找最快的方法来从4个表中获得唯一记录集。 They are joined together with performance joins using indexs. 使用索引将它们与性能联接连接在一起。 Also there are duplicates in the results after the select from the join. 从联接中选择后,结果中也有重复项。 Would it be faster to pull the records using the joins into a CTE (Common Table Expression/WITH Statement) and then select from the CTE with a group by or would it be faster to use the group by on the original data pull? 使用联接将记录提取到CTE(公用表表达式/ WITH语句)中,然后从CTE中选择分组依据是否更快,或者在原始数据提取中使用分组依据会更快吗?

ie

SELECT     
account 
,customer
,class
,CURRENT DATE
,contract_date
FROM ACCOUNT acct
INNER JOIN measure msr 
ON acct.CUST_ID = msr.CUST_ID 
INNER JOIN products prod 
ON msr.PROD_ID = prod.PROD_ID 
INNER JOIN customer x 
ON acct.CUST_ID = x.CUST_ID 
WITH UR

There are a bunch of dups in here so would it be faster to just group by the 5 columns in the select or add a distinct or put this in a CTE/WITH statement and then select with group from the CTE? 这里有很多重复,所以将它们按选择中的5列分组或添加一个不同的字符串或将其放入CTE / WITH语句然后从CTE中进行分组选择会更快吗?

It depends on your data pattern and size of data. 这取决于您的数据模式和数据大小。 There are no thumb rules. 没有经验法则。 I would say try with all possible option and check execution plan, should give you the best option. 我会说尝试所有可能的选项并检查执行计划,应该为您提供最佳选择。

~ Santosh 〜桑托什

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM