我需要在多维数据集上运行以下MDX查询(我无法访问更改)。
此特定查询需要大约1.5分钟才能运行,这太长了。我一直在寻找加快速度的方法,但我没有一堆运气。
有人能看到改善此查询的方法吗?在过去的几天里,我一直在撕扯我的头发,所以非常感谢任何帮助!
public List<Models.eConnectModels.eConnStatus> CommitAsTransaction(List<SqlCommand> commands) {
SqlTransaction transaction = null;
SqlConnection connection = null;
List<eConnStatus> ErrorList = new List<eConnStatus>();
try {
connection = this.CreateSqlConnection();
connection.Open();
transaction = connection.BeginTransaction(IsolationLevel.ReadUncommitted, "TransactionID");
foreach (SqlCommand cmd in commands) {
eConnStatus curErr = new eConnStatus();
cmd.Transaction = transaction;
cmd.Connection = connection;
SqlParameter errorString = cmd.Parameters.Add("@oErrString", SqlDbType.VarChar);
errorString.Direction = ParameterDirection.Output;
errorString.Size = 8000;
SqlParameter errorStatus = cmd.Parameters.Add("@O_iErrorState", SqlDbType.Int);
errorStatus.Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
curErr.ErrorState = (int)cmd.Parameters["@O_iErrorState"].Value;
curErr.ErrorMessage = (string)cmd.Parameters["@oErrString"].Value;
ErrorList.Add(curErr);
}
transaction.Commit();
}
catch (Exception ex) {
transaction.Rollback();
connection.Close();
throw ex;
}
connection.Close();
return ErrorList;
}
答案 0 :(得分:1)
最后,逻辑占了上风,我能够让立方体所有者为立方体添加一个新的维度,这意味着我不再需要尝试让这只狗的早餐起作用。
答案 1 :(得分:0)
(只是为了好玩!)
您的第一项措施肯定可以通过以下方式得到改善。
Count(Filter
是一种你可以在大多数时间摆脱的模式。
Mosha在博客上发表了关于这种模式的文章,可以在这里进行改进:
http://sqlblog.com/blogs/mosha/archive/2007/11/22/optimizing-count-filter-expressions-in-mdx.aspx
我也试图改进第二次计算。如果这个条件为真[Measures].[Amount Lost] >= 1 AND [Measures].[Amount Lost] <= 99
,那么这必然意味着这是假IsEmpty([Measures]。[Amount Lost])所以这两个条件都可以由1条件覆盖。同时将0
替换为null
- 使用null
SSAS更快乐(更快):
WITH
MEMBER [Measures].[1-99_Count] AS
Sum
(
[Scam].[Scam Ref].ALLMEMBERS
,IIF
(
[Measures].[Amount Lost] >= 1 AND [Measures].[Amount Lost] <= 99
,1
,null
)
)
MEMBER [Measures].[1-99_Amount] AS
Sum
(
[Scam].[Scam Ref].ALLMEMBERS
,IIF
(
[Measures].[Amount Lost] >= 1 AND [Measures].[Amount Lost] <= 99
,[Measures].[Amount Lost]
,null
)
)
SELECT
{
[Measures].[1-99_Count]
,[Measures].[1-99_Amount]
} ON COLUMNS
,[First Resolved On Date].[Month].[Month] ON ROWS
FROM [Infocentre]
WHERE
(
[First Resolved On Date].[Date].[Date].&[20140101]
:
[First Resolved On Date].[Date].[Date].&[20150623]
,[Scam].[Scam Category Level1].&[{d9d6bc38-e73e-e411-9a82-0a713f2121f7}]
);