Hello,
I have a performance problem on my SQL 2012 SP1 enterprise edition database server. Basically we have a query that is reporting against a 600 million row table on which we have a clustered index and a non clustered covering index.The query runs extremly slow when it uses the non clustered index.The reason being the query incorectly assumes this index has only 1 row (estimated number of rows 1,actual number of rows around 2 million) while hash joining with a temp table and hashes this index into memory which spills to tempdb. Even though I have updated the statistics with FULLSCAN multiple times and flushed the query cache, the query continues to assume the same. If I drop the non clustered index the query runs fast as it uses the clustered index which it correctly diagnose the row count. The nonclustered index/statistics is created on int,Datetime column whereas the clustered index is on datetime,int columns. I cannot use query hint to force it to use clustered index for this query. Can someone suggest where might be the problem? Appreciate your help.
SELECT
Correlation.Domain as Domain,
ns.InterfaceID AS InterfaceID,
data.SourceIPSort AS IPSort, data.SourcePort AS Port, data.SourceAS as AsId,
data.*
FROM #Temptab ns
INNER JOIN Tab3 data WITH (NOLOCK) ON ns.InterfaceID = InterfaceIDRx
INNER JOIN View1 AS Correlation ON Correlation.IPAddressSort = SourceIPSort
WHERE (1=1)
AND ( StartTime >= '2013-11-15T00:00:00' AND StartTime < '2013-11-19T00:00:00' )AND(NodeID=998)
Sample of historam
Statistics for INDEX 'IX_NodeID_StartTime3'.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Name Updated
Rows Rows Sampled
Steps Density
Average Key Length String Index
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IX_NodeID_StartTime3 Nov 23 2013 3:13PM 639376094
639376094 200
5.374837E-06 8
NO
639376094
All Density Average Length Columns
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
0.004424779 4
NodeID
1.66179E-07 8
NodeID, StartTime
Histogram Steps
RANGE_HI_KEY RANGE_ROWS
EQ_ROWS DISTINCT_RANGE_ROWS AVG_RANGE_ROWS
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 0
94346 0
1
2 0
58573 0
1
3 0
100618 0
1
5 0
2533304 0
1
35 0
8889027 0
1
36 0
4214197 0
1
38 0
1.137143E+07 0
1
39 0
1.297758E+07 0
1
47 0
877041 0
1
49 0
7284844 0
1
64 0
4544215 0
1
65 0
1421458 0
1