MDX 查询优化 -- 插入 SQL Table
MDX Query Optimization -- Insert into SQL Table
全部,
我不是很熟悉 MDX 查询,如果您熟悉,那么这个问题很快就会变得显而易见。此查询是根据我复制的 tableau MDX 查询修改的。我将查询与链接的 SSMS 服务器一起使用,插入 table。这是必要的,因为我可以检索数据。生成的数据集包含许多 duplicate/null columns/rows 并且经常导致锁定冲突。这个查询可以改进吗?我知道这不是提取数据的理想方式,但这是我所能做的。
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'
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
是一个应该谨慎使用的函数,所以我只是认为尝试上面的方法会很有用,看看它是否是问题所在?
全部,
我不是很熟悉 MDX 查询,如果您熟悉,那么这个问题很快就会变得显而易见。此查询是根据我复制的 tableau MDX 查询修改的。我将查询与链接的 SSMS 服务器一起使用,插入 table。这是必要的,因为我可以检索数据。生成的数据集包含许多 duplicate/null columns/rows 并且经常导致锁定冲突。这个查询可以改进吗?我知道这不是提取数据的理想方式,但这是我所能做的。
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'
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
是一个应该谨慎使用的函数,所以我只是认为尝试上面的方法会很有用,看看它是否是问题所在?