MDX查询优化 - 插入SQL表

时间:2017-07-13 12:34:17

标签: mdx cube

所有

我对MDX查询不是很熟悉,如果你这样做,那么这个问题会很快显现出来。此查询是根据我复制的tableau MDX查询修改的。我将查询与链接的SSMS服务器一起使用,插入到表中。这是必要的,因为我可以检索数据的方式。生成的数据集包含许多重复/空列/行,并且通常会导致锁定冲突。这个查询可以改进吗?我知道这不是拉取数据的理想方式,但这是我所能做的。

set @SQL = 'SELECT * INTO db_rpt.dbo.temptable1 from (select * from 
openquery(server,''
WITH MEMBER [Measures].[LEVEL INSTANCE none:Date:qk - lev00] 
AS ''''CASE WHEN IsEmpty([Dim Date].[Date].CurrentMember.MemberValue) OR [Dim Date].[Date].CurrentMember.MemberValue = null 
THEN null 
ELSE CDate([Dim Date].[Date].CurrentMember.MemberValue) 
END''''
,SOLVE_ORDER = 127

SELECT 
{[Measures].[METRIC1]
,[Measures].[METRIC2]
,[Measures].[METRIC3]
,[Measures].[METRIC4]
,[Measures].[METRIC5]
,[Measures].[METRIC6]
} 

DIMENSION PROPERTIES HIERARCHY_UNIQUE_NAME ON COLUMNS , 
NON EMPTY (Hierarchize({DrilldownLevel({[Dim Employee].[GROUP1].[All]},,,INCLUDE_CALC_MEMBERS)})
,Hierarchize({DrilldownLevel({[Dim Employee].[Unique Emp Name].[All]},,,INCLUDE_CALC_MEMBERS)})
,Hierarchize({DrilldownLevel({[Dim Employee].[GROUP2].[All]},,,INCLUDE_CALC_MEMBERS)})
,Hierarchize({DrilldownLevel({[Dim Employee].[GROUP3].[All]},,,INCLUDE_CALC_MEMBERS)})
,Hierarchize({DrilldownLevel({[Dim Employee].[GROUP4].[All]},,,INCLUDE_CALC_MEMBERS)})
,Hierarchize({DrilldownLevel({[Dim Employee].[GROUP5].[All]},,,INCLUDE_CALC_MEMBERS)}))    ON ROWS 

 FROM [Cube] 
 WHERE (StripCalculatedMembers(Filter(  [Dim Date].[Date].[Date].AllMembers
 ,(([Measures].[LEVEL INSTANCE none:Date:qk - lev00] >= cdate(''''' + @date1 + ''''')) 
 AND ([Measures].[LEVEL INSTANCE none:Date:qk - lev00] <= cdate(''''' + @date2 + ''''')))))
 ,[Dim QA Form Section].[System - Form].[Form].&[Group]&[Form1])'')) t1' 

1 个答案:

答案 0 :(得分:1)

CASE可能比IIF慢,所以可能会重写:

CASE WHEN IsEmpty([Dim Date].[Date].CurrentMember.MemberValue) OR [Dim Date].[Date].CurrentMember.MemberValue = null 
THEN null 
ELSE CDate([Dim Date].[Date].CurrentMember.MemberValue) 
END

我认为这是等效的:

IIF(
  IsEmpty([Dim Date].[Date].CurrentMember.MemberValue) 
  OR [Dim Date].[Date].CurrentMember.MemberValue = null 
 ,NULL
 ,CDate([Dim Date].[Date].CurrentMember.MemberValue) 
)

可以进一步简化为:

IIF(
  IsEmpty([Dim Date].[Date].CurrentMember) 
 ,NULL
 ,CDate([Dim Date].[Date].CurrentMember.MemberValue) 
)

诊断

如果替换此块:

WHERE (StripCalculatedMembers(Filter(  [Dim Date].[Date].[Date].AllMembers
 ,(([Measures].[LEVEL INSTANCE none:Date:qk - lev00] >= cdate(''''' + @date1 + ''''')) 
 AND ([Measures].[LEVEL INSTANCE none:Date:qk - lev00] <= cdate(''''' + @date2 + ''''')))))
 ,[Dim QA Form Section].[System - Form].[Form].&[Group]&[Form1])

有了这个:

WHERE ([Dim QA Form Section].[System - Form].[Form].&[Group]&[Form1])

它现在运行得更快吗? Filter是一个应该谨慎使用的功能,所以我只是认为尝试上述功能是否有用是非常有用的?