2016-11-11 230 views
0

我在下面有一個MDX查詢。此查詢有效,問題是速度慢,即使數據集不是很大,也需要15秒才能返回結果。我相信查詢應該在2秒內執行(它也用於登錄頁面,等待時間很麻煩)。 [度量]。[星級]由於所有IF THEN ELSE邏輯而導致速度減慢。它的所有操作都基於[平均分],它根據查找表中的範圍從查找表中找到[星級]。 例如如果[平均分數] < 86,[星級] = 1 如果[平均分]> = 86和< = 90,[星級] = 2SSAS根據另一個計算的度量計算度量值

的[平均分]是一個簡單的總和/數計算。 它可以根據用作參數的日期範圍進行更改。 您可以推薦在下面的現有查詢中進行優化,還是推薦一種替代方法來計算[星級]?

MDX查詢低於:

WITH 
     MEMBER [Measures].[MeanScore] AS ([Measures].[Standard Point Assignment - Sum]/[Measures].[Episode Of Care HCAHPS Count]) 
     MEMBER [Measures].[StarRating] AS 
     CASE 
     WHEN [HCAHPS Star Rating].[HCAHPS Star Rating ID].CurrentMember IS [HCAHPS Star Rating].[HCAHPS Star Rating ID].[All] 
      THEN 
     CASE 
      WHEN [Measures].[HSR-HCHCAHPS Domain ID] = TAIL([HCAHPS Star Rating].[HCAHPS Star Rating ID].[HCAHPS Star Rating ID]).Item(0).Item(0).Properties('HCHCAHPS Domain ID') 
        THEN 
       (
       [Measures].[Rating], 
       Tail([HCAHPS Star Rating].[HCAHPS Star Rating ID].[HCAHPS Star Rating ID]).Item(0).Item(0) 
       ) 
      ELSE 
       (
       [Measures].[StarRating], 
       Tail([HCAHPS Star Rating].[HCAHPS Star Rating ID].[HCAHPS Star Rating ID]).Item(0).Item(0).PrevMember 
       ) 
     END 
     ELSE 
     CASE 
      WHEN [Measures].[MeanScore] > [HCAHPS Star Rating].[HCAHPS Star Rating ID].CurrentMember.Properties('Start', typed) 
      AND [Measures].[HC-HCAHPS Domain ID] = [HCAHPS Star Rating].[HCAHPS Star Rating ID].CurrentMember.Properties('HCHCAHPS Domain ID', typed) 
        THEN 
       (
       [Measures].[Rating], 
       [HCAHPS Star Rating].[HCAHPS Star Rating ID].CurrentMember 
       ) 
      ELSE 
       (
       [Measures].[StarRating], 
       [HCAHPS Star Rating].[HCAHPS Star Rating ID].CurrentMember.PrevMember 
       ) 
     END 
    END 
SELECT 
    { 
     [Measures].[Episode Of Care HCAHPS Count] 
     ,[Measures].[Is Top Box] 
     ,[Measures].[CompositeScore] 
     ,[Measures].[PromoterCount] 
     ,[Measures].[PromoterPercent] 
     ,[Measures].[PassiveCount] 
     ,[Measures].[PassivePercent] 
     ,[Measures].[DetractorCount]  
     ,[Measures].[DetractorPercent] 
     ,[Measures].[StarRating] 
     ,[Measures].[MeanScore] 
    } ON COLUMNS, 
    NONEMPTYCROSSJOIN 
    (
     {NONEMPTY([HCAHPS Domain].[HCAHPS Survey Methodology ID].[HCAHPS Survey Methodology ID])} 
     ,DESCENDANTS(StrToSet('[Org Hierarchy].[Parent Key].&[118418]')) 
     ,{[HCHCAHPS Domain].[HC Domain Group].[HC Domain Group]} 
     ,{[HCHCAHPS Domain].[HCAHPS Domain Name].[HCAHPS Domain Name]} 
     ,{[HCAHPS Question Answer].[Question Number].AllMembers} 
    ) ON ROWS 
    FROM [CAHPS] 
    WHERE 
    (
     StrToMember("[Date].[Date].&[" + FORMAT(NOW()-365,"yyyy-MM-ddT00:00:00") + "]",CONSTRAINED):StrToMember("[Date].[Date].&[" + FORMAT(NOW(),"yyyy-MM-ddT00:00:00") + "]",CONSTRAINED) 
    ) 
+0

沒有愛的3.2.1節這個...任何人? – SQLSeeker

回答

0

一般情況下,分析服務MDX內IIF和CASE語句可能會看到一些性能下降。儘管大多數IIF語句相對便宜,且嵌套條件複雜(包含大量的IIF語句),但這會導致Analysis Services公式引擎最終會逐個單元地運行查詢。

對於高性能查詢,目標是使查詢以子空間模式(或塊計算)而不是逐個單元模式運行。如果在IIF聲明中,請在上下文中執行此操作,請嘗試使用SCOPE聲明。將IIF聲明轉換爲SCOPE的一個很好的參考是Mosha Pasumansky的博文是Performance of IIF function in MDX

順便說一句,子空間上計算的詳細信息(對細胞的細胞),請參閱Analysis Services Performance Guide