Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email email@example.com
From: Rob Wultsch (wultschgmail.com)
Date: Sun May 25 2008 - 17:22:46 CDT
On Fri, May 23, 2008 at 11:20 PM, Velen <velenbiz-mu.com> wrote:
> 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'?
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...
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql