If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > performance issue

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-15-04, 09:26
G_Andy G_Andy is offline
Registered User
 
Join Date: Apr 2004
Location: Toronto
Posts: 3
Question performance issue

Should I worry about the performance of a query like:
SELECT CustomerID FROM invoices WHERE InvoiceID NOT IN (SELECT TOP 50% InvoiceID FROM invoices)
What if the "invoices" is very big?
Reply With Quote
  #2 (permalink)  
Old 04-15-04, 09:57
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
i would not worry about performance until you can define what "very big" means

also, in the example you gave, you really should have an ORDER BY in the subquery, otherwise it doesn't make sense to pull 50% of all the invoices randomly
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 04-15-04, 10:52
G_Andy G_Andy is offline
Registered User
 
Join Date: Apr 2004
Location: Toronto
Posts: 3
absolutely right

The query I used for exemplification doesn't make much sense. My real query it's totaly different but I'm affraid that the inner SELECT will return too many records (hundreds of thousands maybe).
Reply With Quote
  #4 (permalink)  
Old 04-15-04, 11:15
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Since I can only see six invoices in your imaginary table, I really doubt that performance will be an issue for that syntax.

-PatP
Reply With Quote
  #5 (permalink)  
Old 04-15-04, 11:16
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
maybe the inner subquery will be optimized to a join, who knows without at least setting it up and running an EXPLAIN

but a few hundred thousand is typically a piffle
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 04-15-04, 11:17
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
been wantin' to use that word for ages

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On