2016-01-21 47 views
0

在這裏,我處於同一個泥潭,也許你們中的很多人都是。 Teradata 14.1的對象使用功能已啓用。
此專欄是1 env。結果是零脯氨酸,因爲我們升級了一段時間,但在另一個(QA /測試)env。它有價值。

DBC.DBQLRuleTbl | TimeCreated


sel TimeCreated from DBC.DBQLRuleTbl where DBQLRuleTbl.UserID in (sel OU.DatabaseId from DBC.ObjectUsage OU)

在1個ENV沒有行。 我想要做的是找出未使用的統計數據。我們只在過去的幾個月纔得到OU。 所以,當我使用這個查詢來找出UNUSED統計信息時,我得到最後一個col -1,因爲RuleTbl沒有任何與OU表相匹配的東西。新的Teradata統計功能。困惑了幾件事

 SELECT DBC.DBase.DatabaseName AS DatabaseName 
      ,DBC.TVM.TVMName  AS TableName 
      ,COALESCE(DBC.StatsTbl.StatsName 
        ,DBC.StatsTbl.ExpressionList 
        ,'SUMMARY') AS StatName 
      ,CURRENT_DATE - CAST(DBC.StatsTbl.CreateTimeStamp AS DATE) AS StatAge 
      ,CASE 
      WHEN DatabaseName = 'DBC' 
      THEN -2 -- Logging Not Applicable 
      WHEN DBC.StatsTbl.StatsType IN ('B', 'M') 
      THEN -2 -- Logging Not Applicable on Temp tables (base and materialized) 
      WHEN DBC.DBQLRuleTbl.TimeCreated IS NULL 
      THEN -1 -- Logging Not Enabled 
      WHEN DBC.DBQLRuleTbl.TimeCreated > DBC.StatsTbl.CreateTimeStamp 
      THEN CURRENT_DATE - CAST(DBC.DBQLRuleTbl.TimeCreated AS DATE) 
      ELSE CURRENT_DATE - CAST(DBC.StatsTbl.CreateTimeStamp AS DATE) 
    END AS DaysStatLogged 
    FROM DBC.StatsTbl LEFT JOIN DBC.DBQLRuleTbl 
       ON DBC.StatsTbl.DatabaseId = DBC.DBQLRuleTbl.UserID 
       AND DBQLRuleTbl.ExtraField5 = 'T' 

      ,DBC.Dbase 
      ,DBC.TVM  
    WHERE DBC.StatsTbl.DatabaseId = DBC.DBASE.DatabaseId 
     AND DBC.StatsTbl.ObjectId = DBC.TVM.TVMId 
     AND NOT EXISTS (SELECT '1' FROM DBC.ObjectUsage OU 
         WHERE OU.UsageType = 'STA' 
         AND OU.DatabaseId = DBC.StatsTbl.DatabaseId 
         AND OU.ObjectId = DBC.StatsTbl.ObjectId 
         AND OU.FieldId = DBC.StatsTbl.StatsId 
         AND CURRENT_DATE - CAST(OU.LastAccessTimeStamp AS DATE) < N 
        ) 
     --AND DaysStatLogged > N 

    /* I had to mute this criteria because otherwise there will be no o/p for reasons mentioned above */ 

     AND DBC.StatsTbl.StatsId <> 0 
-- Do not qualify table-level SUMMARY statistics as unused 
-- May get implicitly used but not recorded as used 
and StatAge < N 

/* StatAge < N .I am not sure if this filter should be there- I added it to catch those stats that are as old OU. We dunno if stats older than OU ever got used before OU started */ 
            and databasename in (sel child from dbc.children where parent ='FINDB' group by  1) 
    ORDER BY 1, 2, 3; 

我想獲取FINDB級聯而不是系統範圍統計信息。 鑑於我的規則表搞砸了 - 不上面的查詢最接近適應該法案
「查找我的統計信息FINDB下的所有數據庫沒有被使用,因爲OU被打開」

回答