Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
Performance Tuning
»
how to Eliminate 'IN'
how to Eliminate 'IN'
Rate Topic
Display Mode
Topic Options
Author
Message
KcV
KcV
Posted Thursday, March 01, 2012 1:18 AM
Valued Member
Group: General Forum Members
Last Login: Friday, May 10, 2013 3:11 AM
Points: 56,
Visits: 150
Hi,
How can i eliminate IN from following query ?
select * from idata a where isnull(validationstatus,'Y')='Y'
and srno not in (select srno from IFDetails where eby =1 )
and edate between '20.02.2012' and '20.02.2012'
this query takes too long time due to both tables having more then 1.5 million rows.
thanks
Post #1259943
John Mitchell-245523
John Mitchell-245523
Posted Thursday, March 01, 2012 1:47 AM
SSCarpal Tunnel
Group: General Forum Members
Last Login: Yesterday @ 8:44 AM
Points: 4,434,
Visits: 7,218
You could use an OUTER JOIN instead, although I suspect that you may end up with the same execution plan. Have you considered indexes on the srno column in both tables? Also, the BETWEEN operator is not needed since the beginning and end of the range are identical. Use "=" instead.
John
Post #1259952
GilaMonster
GilaMonster
Posted Thursday, March 01, 2012 2:57 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 4:30 AM
Points: 37,742,
Visits: 30,021
Why do you want to eliminate IN? It's usually more efficient than an equivalent join.
If srno in IFDetails is nullable, you may want to use EXISTS instead. Also your first predicate is not SARGable, so that may result in the query being a little slower than it could be.
Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild
: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter
We stand on the bridge and no one may pass
Post #1259985
KcV
KcV
Posted Friday, March 02, 2012 12:54 AM
Valued Member
Group: General Forum Members
Last Login: Friday, May 10, 2013 3:11 AM
Points: 56,
Visits: 150
thanks for reply,
as far as I know that, Join is much faster then IN.
i am sorry but i can't understand what you mean by saying :
'Also your first predicate is not SARGable, so that may result in the query being a little slower than it could be.'
thanks for giving me time.
Post #1260650
John Mitchell-245523
John Mitchell-245523
Posted Friday, March 02, 2012 1:50 AM
SSCarpal Tunnel
Group: General Forum Members
Last Login: Yesterday @ 8:44 AM
Points: 4,434,
Visits: 7,218
There's plenty of information out there. Use your favourite search engine to search for "sargable predicates".
John
Post #1260669
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.