Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Understanding indexing?
Message
De
25/08/2009 03:49:11
Metin Emre
Ozcom Bilgisayar Ltd.
Istanbul, Turquie
 
 
À
24/08/2009 11:44:52
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01420204
Message ID:
01420386
Vues:
78
Your first query has an order too because of "top" clause. Using "top" clause without "order by" causes adding an "auto order by" with first field of query by sql-server.

You have to create an index for "somedte" field for run your first query fast too...

>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform