使用+而不是Aggregate(Union)是否可以获得性能提升 [英] Is there a performance gain using + rather than Aggregate(Union
问题描述
我正在MSDN中查看此帖子: http://msdn.microsoft .com/en-us/library/ms145493.aspx
I was looking at this post in MSDN: http://msdn.microsoft.com/en-us/library/ms145493.aspx
它声明+和Union等同于 ...在下面不完全相同,因为如果我选择使用Union
,则需要应用Aggregate
.
It states that + and Union are equivalent ... not exactly in the following as Aggregate
needs to be applied if I choose to use Union
.
它更具可读性,但是在选择+
而不是Aggregate(Union
时,性能会有所提高吗?
It's more readable but is there any performance gain in choosing +
over Aggregate(Union
?
WITH
MEMBER [Employee].[Employee].[blah] AS
[Employee].[Employee].[Amy E. Alberts]
+
[Employee].[Employee].[Garrett R. Vargas]
MEMBER [Employee].[Employee].[blahblah] AS
Aggregate
(
Union
(
{[Employee].[Employee].[Amy E. Alberts]}
,{[Employee].[Employee].[Garrett R. Vargas]}
)
)
SELECT
[Measures].[Reseller Sales Amount] ON 0
,{
[Employee].[Employee].[Amy E. Alberts]
,[Employee].[Employee].[Garrett R. Vargas]
,[Employee].[Employee].[blah]
,[Employee].[Employee].[blahblah]
} ON 1
FROM [Adventure Works]
WHERE
[Date].[Calendar].[Month].&[2006]&[8];
推荐答案
问题在于+
在MDX中用于多种用途:作为数字加法,用于字符串连接以及用作联合运算符.并且,由于成员定义期望一个传递值的表达式,并且您在两个成员之间使用运算符,并且当前度量的值为数字,因此AS使用数字加法.
The issue is that +
is used for several purposes in MDX: as numerical addition, for string concatenation, and as union operator. And as the a member definition expects an expression that delivers a value and you use the operator between two members, and the value of the current measure is numerical, AS uses numerical addition.
如果将成员括在大括号中:
If you enclose the members in braces:
MEMBER [Employee].[Employee].[blah] AS
{[Employee].[Employee].[Amy E. Alberts]}
+
{[Employee].[Employee].[Garrett R. Vargas] }
您收到一个错误,提示AS希望+
运算符使用字符串或数字表达式.
you get an error that AS expects string or numeric expressions for the +
operator.
可能会有很小的性能提升,但是如果当前度量不由sum
聚合,结果可能会有所不同,在这种情况下,这等同于将两个成员值相加.
And there is probably a small performance gain, but the result may be different if the current measure is not aggregated by sum
, which would be equivalent to adding both member values in this case.
我个人不喜欢出于不同目的使用此运算符重载+
,*
等. +
和*
应该限制为数字,可以是整数,浮点数或小数.与Java,JavaScript和.net中的+
以及Microsoft SQL和MDX相比,我还希望使用其他字符串连接运算符.标准SQL使用||
,Perl使用.
,因此有些替代方法可以避免歧义,并且清楚地知道在编写'2' || 1
vs. '2' + 1
vs. 2 + '1'
vs.
I personally do not like this operator overloading of +
, *
etc. for different purposes. +
and *
should be restricted to numbers, be it integers, floats, or decimals. I also would also prefer another operator for string concatenation than +
in Java, JavaScript, and .net, as well as Microsoft SQL and MDX. Standard SQL uses ||
, Perl uses .
, so there are alternatives that clearly avoid ambiguities and you clearly know what to expect when you write '2' || 1
vs. '2' + 1
vs. vs. 2 + '1'
vs. 2 + 1
.
这篇关于使用+而不是Aggregate(Union)是否可以获得性能提升的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!