Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Poor performance of parameterised NOT IN clause - SQL 2008


Poor performance of parameterised NOT IN clause - SQL 2008

Author
Message
Andrew Greig
Andrew Greig
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 63
I'm comparing the logical reads done by two slightly differently phrased parameterised SQL statements that return the same results from an SAP database table :
DECLARE @P1 varchar(3) = '400';
DECLARE @P2 varchar(2)= '30';
DECLARE @P3 varchar(2) ='60';

SELECT "COUNTER" AS c ,"REFCOUNTER" AS c ,"STATUS" AS c
FROM "CATSDB"
WHERE "MANDT" = @P1 AND NOT ("STATUS" = @P2 OR STATUS = @P3 )
ORDER BY "COUNTER"


In my case the query stats say:
Scan count 2, logical reads 22084

but when I run :
DECLARE @P1 varchar(3) = '400';
DECLARE @P2 varchar(2)= '30';
DECLARE @P3 varchar(2) ='60';

SELECT "COUNTER" AS c ,"REFCOUNTER" AS c ,"STATUS" AS c
FROM qe7."CATSDB"
WHERE "MANDT" = @P1 AND NOT "STATUS" IN (@P2, @P3)
ORDER BY "COUNTER"


the query stats say :
Scan count 2, logical reads 113454
The CATSDB table has an index consisting of MANDT, STATUS, REFCOUNTER.
Why do these two statements do such different numbers of logical reads and take such different times ?
Thanks.
SQLSACT
SQLSACT
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1456 Visits: 2931
So, in the second query, all you're doing is using the schema_name.table_name?

What do the execution plans say?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search