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 > Database Server Software > MySQL > performance difference of nested/not nested query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-08-10, 16:58
uhm uhm is offline
Registered User
 
Join Date: Mar 2010
Posts: 8
performance difference of nested/not nested query

hello

I don't understand why there's a difference in the execution time of two queries when run separately and together in the same query.

Query A
Code:
SELECT cat_bindings.merchantcategory FROM cat_bindings,categories WHERE cat_bindings.systemcategory = categories.id AND categories.slug = 'slughere';
Takes 0.000 sec. ( according to MySQL Workbench )
this returns a list of category names which are then passed as quoted values in the following query
Query B
Code:
SELECT id FROM products WHERE products.merchantcategory IN ('category name 1','category name 2') AND products.status = 1 ORDER BY RAND() LIMIT 8;
Takes 0.000 sec.

Query C ( same 2 queries run the one inside the other )
Code:
SELECT id FROM products WHERE products.merchantcategory IN (SELECT cat_bindings.merchantcategory FROM cat_bindings,categories WHERE cat_bindings.systemcategory = categories.id AND categories.slug = 'slughere') AND products.status = 1 ORDER BY RAND() LIMIT 8;
I would expect this query to be very fast, since the two queries it's composed by are reported to run in 0.000sec, but this takes 1.6 seconds. Can someone shed some light?
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