wie die Struktur eines index für group by in Sql Server

Die folgende einfache Abfrage dauert sehr lange (mehrere Minuten) zu führen.

Habe ich einen index:

create index IX on [fctWMAUA] (SourceSystemKey, AsAtDateKey)
SELECT MAX([t0].[AsAtDateKey]) AS [Date], [t0].[SourceSystemKey] AS [SourceSystem]
FROM [fctWMAUA] (NOLOCK) AS [t0]
WHERE SourceSystemKey in (1,2,3,4,5,6,7,8,9)
GROUP BY [t0].[SourceSystemKey]

Die Statistiken sind wie folgt:

  • logische Lesevorgänge 1827978
  • physische Lesevorgänge 1113
  • read-aheads 1806459

Nehmen, dass genau die gleiche Abfrage und Formatierung wie folgt gibt mir diese Statistik:

  • logische Lesevorgänge 36
  • physische Lesevorgänge 0
  • read-aheads 0

Es dauert 31ms zu führen.

SELECT MAX([t0].[AsAtDateKey]) AS [Date], [t0].[SourceSystemKey] AS [SourceSystem]
 FROM [fctWMAUA] (NOLOCK) AS [t0]
 WHERE SourceSystemKey = 1
 GROUP BY [t0].[SourceSystemKey]
UNION
 SELECT MAX([t0].[AsAtDateKey]) AS [Date], [t0].[SourceSystemKey] AS [SourceSystem]
 FROM [fctWMAUA] (NOLOCK) AS [t0]
 WHERE SourceSystemKey = 2
 GROUP BY [t0].[SourceSystemKey]
UNION
 SELECT MAX([t0].[AsAtDateKey]) AS [Date], [t0].[SourceSystemKey] AS [SourceSystem]
 FROM [fctWMAUA] (NOLOCK) AS [t0]
 WHERE SourceSystemKey = 3
 GROUP BY [t0].[SourceSystemKey]
/* AND SO ON TO 9 */

Wie mache ich einen index hat, der die Gruppe durch schnell?

  • Hast du einen index auf SourceSystemKey ? Wenn nicht, ich denke, Sie werden möglicherweise induziert einen full table scan.
  • Was bedeutet die showplan-show? und welche Werte können SourceSystemKey nehmen?
InformationsquelleAutor Craig | 2009-11-04
Schreibe einen Kommentar