Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Optimizing for group by
Message
 
À
24/01/2011 18:47:35
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01497285
Message ID:
01497286
Vues:
54
This message has been marked as the solution to the initial question of the thread.
Isn't this:
CONVERT(char(8), Hit.AddDate, 112)
the same as your expression
CONVERT(CHAR(4),YEAR(Hit.AddDate))+REPLACE(STR(MONTH(Hit.AddDate),2),' ','0') + REPLACE(STR(DAY(Hit.AddDate),2),' ','0')
?


>How can I create an index which would optimize this query:
>
>
>SELECT CONVERT(CHAR(4),YEAR(Hit.AddDate))+REPLACE(STR(MONTH(Hit.AddDate),2),' ','0')+
> REPLACE(STR(DAY(Hit.AddDate),2),' ','0') AS lcChampNumero,
> COUNT(*) AS Compte,MIN(Hit.AddDate) AS AddDate
> FROM Hit
> WHERE Hit.NoServer=3
> GROUP BY CONVERT(CHAR(4),YEAR(Hit.AddDate))+REPLACE(STR(MONTH(Hit.AddDate),2),' ','0')+
> REPLACE(STR(DAY(Hit.AddDate),2),' ','0')
> ORDER BY 1 DESC 
>
>
>I added an index NoServerAddDate which includes the NoServer and AddDate fields. I see that this has changed the execution plan. It does show that it uses it. However, my query is not any faster.
>
>Is there a way to make it faster?
>
>This is one on a Hit table having about two million records and all I need is a repartition on a daily basis with the count. The result returns presently 28 records.
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform