On Fri, May 23, 2008 at 11:20 PM, Velen <[EMAIL PROTECTED]> wrote: > Hi, > > I wanted to know when doing a select query how is it executed : > > > If there is 1000 records with price<10, 3000 records with flag='Y' and the > table contains 200,000 records. > > Select code, description, price, flag from products where flag='Y' and > price<10 > > Select code, description, price, flag from products where price<10 and > flag='Y' > > Which one of the query will be faster? In query 1, will mysql sort the list > for flag='Y' then from the list find price<'10'? > > Regards, > > Velen >
There should be no difference in quey execution. If there is an index on either column with good cardinality, then that index will probably be used to eliminate records first. If you are on mysql 5.0+ then multiple index may be used (merge index). After this happens each individual row will need to be examined, which will be expensive depending on the number or rows left after using the index. EXPLAIN and EXPLAIN EXTENDED are your friends for questions like this. At some point I need to dig into the mysql source to gain a better understanding of what is going on... -- Rob Wultsch [EMAIL PROTECTED] wultsch (aim) -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]