I have the following query:
SELECT DISTINCT DATEADD(ms,DATEDIFF(ms,0,[Time]),DATEADD(dd,0,DATEDIFF(dd,0,[DATE]))),
[DATE],
DATEPART(YY,[DATE]),
DATEPART(MM,[DATE]),
DATENAME(MONTH,[DATE]),
DATEPART(DD,[DATE]),
[Time],
DATEPART(HH,[Time]),
DATEPART(MI,[Time]),
DATEPART(SS,[Time])
FROM [SourceTable]
WHERE ([DATE] BETWEEN '2012-01-08' AND '2012-01-08') AND
DATEADD(ms,DATEDIFF(ms,0,[Time]),DATEADD(dd,0,DATEDIFF(dd,0,[DATE]))) NOT IN
(SELECT [DateTime]
FROM [DIM].[DateTime]
WHERE [Date] BETWEEN '2012-01-08' AND '2012-01-08')
ORDER BY [DATE], [Time]
OPTION (MAXDOP 6)
When I use this specific date I had to cancel the query after 14hours running time, any other date the same query takes normally 21 seconds. I did check the query execution plan independent on what date I use it is the same, the amount of rows impacted by the query is for each day nearly the same (around 500'000 Rows). I checked the indexes and the statistics are up to date. How is such a behaviour explainable and how to fix this ?
The Hardware of the machine is sufficient (8 Cores, 192 GB RAM)
sys.dm_os_waiting_tasksto see if it is blocked waiting on something. – Martin Smith Jan 12 '12 at 10:16TIMEandDATEfield, he is either using adatedatatype (notice he is using 2008r2) or these are string fields – JNK♦ Jan 12 '12 at 15:38