Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

[SQL Server 2008]
I have a table(DATALOG_4) with 10 Millions records. It contains 18 columns. The column DATE_TIME is a primary key column. We have created Non-Clustered Index on DATE_Time because we are using this column in WHERE Clause.

The issue is, It takes more than 20 seconds for even after I created Non-Clustered index.

We are using the following Query:

SQL
SELECT DATE_TIME, [794] AS CT, [61] AS BID,
         ROW_NUMBER() OVER (PARTITION BY [61] ORDER BY  DATE_TIME DESC) AS Row_No
   FROM DATALOG_4 (NOLOCK)
   WHERE
        DATE_TIME >= '2012-11-01 12:00:00' and DATE_TIME <= '2012-12-31 11:59:59'



Please anyone suggest me, How to make the select Query fast?
Posted
Comments
Sandeep Mewara 4-Jan-13 0:10am    
is DATE_TIME a 'DateTime' type column or 'varchar' type? If 'varchar' it will be slow compared to datetime datatype.
willington.d 4-Jan-13 1:41am    
its a DATETIME datatype.
jayantbramhankar 4-Jan-13 0:22am    
try adding non-clustered index on column DATE_TIME
Sandeep Mewara 4-Jan-13 0:49am    
He mentioned that he already did this!

I've not used it myself before, but have you tried removing the 'Over / Partition by' logic to see how the query preforms then?

My understanding is that it should only calculate the rownumber on each row selected - but it could be this that is degrading your performance.
 
Share this answer
 
Comments
willington.d 4-Jan-13 1:44am    
It is little faster than before after removed "Over / Partition by" logic. But I need that logic for calculation.
Add an index (non-clusterd, non-unique) for column [61].
 
Share this answer
 
Always store dates as a datetime, not as a string. That will make it faster. 20 seconds for 10 million records seems reasonable to me, however. How fast do you need it to be ?
 
Share this answer
 
Comments
willington.d 4-Jan-13 1:47am    
Its already a DATETIME datatype. 20 sec is reasonable but we have three more SQL statements in the same block and the total execution takes 60 sec to 90 sec.
Christian Graus 4-Jan-13 3:04am    
Then this is not the slowest one, right ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900