Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Index become non optimized after a while
Message
De
18/07/2010 11:46:25
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Maintenance bases de données
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01471721
Message ID:
01472857
Vues:
23
The where exists approach you gave resolves the issue.
DECLARE @NoMember Integer

SET @NoMember=1

SELECT Thread.Numero,Thread.Title,Thread.Url,Thread.AddDate
 FROM Thread (NOLOCK)
 WHERE EXISTS
 (SELECT 1 FROM (SELECT TOP 10 Reply.NoThread FROM Reply (NOLOCK)
 WHERE Reply.NoMember=@NoMember ORDER BY 1 DESC) Temp
 WHERE Temp.NoThread=Thread.Numero) 
Duration: 0.0000 Count: 10

It is even faster than the initial query after an index.

Now, I would like to understand why using WHERE EXISTS is optimized and the other not. This is a mystery.

Basically, I didn't even reindex. I simply ran both queries one after the other and found out that yours was the key. I also ran this:
SELECT TOP 10 Reply.NoThread FROM Reply (NOLOCK) WHERE Reply.NoMember=@NoMember ORDER BY 1 DESC
And, that one was optimized as well. So, basically, the problem was with the corelation with the Thread table. In my test, I ran the following pattern:

1. Ran the initial query (took 1.7 seconds)
2. Ran the query just above in the Reply table only just to see that the query in its table run as is was optimized
3. Executed point #1 (same)
4. Executed point #2 (same)
5. Executed your query (took 0.00 second)
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform