Click here to Skip to main content
15,889,216 members
Home / Discussions / Database
   

Database

 
GeneralRe: Slow query when using @variable in Where clause Pin
Meysam Mahfouzi27-Jan-09 8:14
Meysam Mahfouzi27-Jan-09 8:14 
GeneralRe: Slow query when using @variable in Where clause Pin
Wendelius27-Jan-09 8:36
mentorWendelius27-Jan-09 8:36 
GeneralRe: Slow query when using @variable in Where clause Pin
Meysam Mahfouzi27-Jan-09 9:09
Meysam Mahfouzi27-Jan-09 9:09 
GeneralRe: Slow query when using @variable in Where clause Pin
Wendelius27-Jan-09 9:34
mentorWendelius27-Jan-09 9:34 
GeneralRe: Slow query when using @variable in Where clause [modified] Pin
Meysam Mahfouzi27-Jan-09 20:40
Meysam Mahfouzi27-Jan-09 20:40 
GeneralRe: Slow query when using @variable in Where clause Pin
Wendelius27-Jan-09 20:49
mentorWendelius27-Jan-09 20:49 
GeneralRe: Slow query when using @variable in Where clause Pin
Meysam Mahfouzi27-Jan-09 21:02
Meysam Mahfouzi27-Jan-09 21:02 
GeneralRe: Slow query when using @variable in Where clause Pin
Wendelius27-Jan-09 21:28
mentorWendelius27-Jan-09 21:28 
Okay, first you could add an index with two columns: Culture, Date DESC:
CREATE INDEX X_Test ON News (Culture, Date DESC);

After that, see what happens for the execution plan (and the performance).

After doing that, you could experiment a change to the query (I suspect that the above modification will not be enough, but if it is, the skip the rest):
SELECT TOP(@Count)
       id, title, description
FROM  News a
WHERE Culture = @c
AND   @Start <= (SELECT COUNT(*)
                 FROM  News b
                 WHERE b.Date < a.Date
                 AND   b.Culture = @c)
ORDER BY Date DESC

Again see execution plan and performance.

Also is the ID column defined as IDENTITY and are the records added to the table in date order. In other words what I'm after, if the identity is greater on one row is it always true that its a newer post based on date column?

If you could post the results for those two operations.

The need to optimize rises from a bad design.My articles[^]

GeneralRe: Slow query when using @variable in Where clause Pin
Meysam Mahfouzi27-Jan-09 22:41
Meysam Mahfouzi27-Jan-09 22:41 
GeneralRe: Slow query when using @variable in Where clause Pin
Wendelius27-Jan-09 22:59
mentorWendelius27-Jan-09 22:59 
GeneralRe: Slow query when using @variable in Where clause Pin
Meysam Mahfouzi27-Jan-09 23:11
Meysam Mahfouzi27-Jan-09 23:11 
GeneralRe: Slow query when using @variable in Where clause Pin
Wendelius27-Jan-09 23:23
mentorWendelius27-Jan-09 23:23 
GeneralRe: Slow query when using @variable in Where clause Pin
Meysam Mahfouzi27-Jan-09 23:59
Meysam Mahfouzi27-Jan-09 23:59 
GeneralRe: Slow query when using @variable in Where clause Pin
Wendelius28-Jan-09 0:21
mentorWendelius28-Jan-09 0:21 
GeneralRe: Slow query when using @variable in Where clause Pin
Meysam Mahfouzi28-Jan-09 1:07
Meysam Mahfouzi28-Jan-09 1:07 
GeneralRe: Slow query when using @variable in Where clause Pin
Wendelius28-Jan-09 1:19
mentorWendelius28-Jan-09 1:19 
GeneralRe: Slow query when using @variable in Where clause Pin
Meysam Mahfouzi28-Jan-09 1:53
Meysam Mahfouzi28-Jan-09 1:53 
GeneralRe: Slow query when using @variable in Where clause Pin
Wendelius28-Jan-09 2:13
mentorWendelius28-Jan-09 2:13 
GeneralRe: Slow query when using @variable in Where clause Pin
Meysam Mahfouzi28-Jan-09 2:56
Meysam Mahfouzi28-Jan-09 2:56 
GeneralRe: Slow query when using @variable in Where clause Pin
Wendelius28-Jan-09 3:12
mentorWendelius28-Jan-09 3:12 
GeneralRe: Slow query when using @variable in Where clause Pin
Meysam Mahfouzi28-Jan-09 3:31
Meysam Mahfouzi28-Jan-09 3:31 
GeneralRe: Slow query when using @variable in Where clause Pin
Wendelius28-Jan-09 4:16
mentorWendelius28-Jan-09 4:16 
GeneralRe: Slow query when using @variable in Where clause Pin
Meysam Mahfouzi28-Jan-09 4:38
Meysam Mahfouzi28-Jan-09 4:38 
GeneralRe: Slow query when using @variable in Where clause Pin
Wendelius28-Jan-09 4:51
mentorWendelius28-Jan-09 4:51 
GeneralRe: Slow query when using @variable in Where clause Pin
Meysam Mahfouzi24-Jun-09 20:46
Meysam Mahfouzi24-Jun-09 20:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.