Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Understanding indexing?
Message
De
24/08/2009 11:44:52
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
Understanding indexing?
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01420204
Message ID:
01420204
Vues:
122
I have a 2 queries. One takes 45 seconds and the other is instand. The only differences is that the first query has no order. The order by clause uses a primary key. I think that the DATEADD() function is causing the problem. If I don't use the dateadd fuction and hardcode the date, it's much faster as well.

declare @dateonly as datetime

select @dateonly = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))

-- query takes 45 seconds
select top 1 somedte, * from sqlservertable
where somedte> @dateonly

-- query is instant
select top 1 somedte, * from sqlservertable
where somedte > @dateonly
order by serialnum desc

Thanks,
Dan
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform