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 > where statment

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-24-10, 02:59
bchanan bchanan is offline
Registered User
 
Join Date: Dec 2009
Posts: 27
where statment

Hello All,

Question: notice the change on the where statement, will the change impact performace if id field on table_a is indexed ? where id is unique value on table_a

select *
from table_a a,
table_b b,
table_c c
where a.id = b.id
and b.another_id = c.another_id
and a.id = 100;

OR

select *
from table_a a,
table_b b,
table_c c
where a.id = 100
and a.id = b.id
and b.another_id = c.another_id
Reply With Quote
  #2 (permalink)  
Old 11-24-10, 04:29
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
I dunno why don't.....

you set up some tables,
populate them with some data
and run some tests for yourself?

who knows how the query optimiser will translate/parse your SQL. My expectation is that it will near identical,if not identical. but once you have built your tables, generated your test data and run your tests, you could follow up with an EXPLAIN to try to understand what is happening.

using an index on a column should, theoretically, make a query more efficient
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 11-24-10, 05:26
bchanan bchanan is offline
Registered User
 
Join Date: Dec 2009
Posts: 27
i wonder if the optimizer will first look on the a.id (which is unique index) and loop only once checking a.id = b.id and b.o_id = c.o_id)
OR
it will loop all posible a.id = b.id and b.o_id = c.o_id and then test it against a.id = 100;

performace is a lot diffrent (multiple cartezian tables tests against 1 value) or (1 value test against multiple cartezia although smaller)

thanks
Chanan
Reply With Quote
  #4 (permalink)  
Old 11-24-10, 10:20
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
the access path SHOULD be the same on both queries. Order of the predicates should not matter.
Dave
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