user1642018
user1642018

Reputation:

mysql Does the change in where clause order of select query increases performace?

Is there any performance benefit if order of where clause criteria changes ?

what i mean is e.g.

i have a select query,

SELECT * from mytable WHERE enabled = '1' AND type = 'pictures' AND category = 'family' 

now in above query

  1. enabled comes first and in my table there are 95% rows are enabled .
  2. type comes second where my table contains 75% rows which are of type pictures
  3. category comes last where my table contains 20% rows which are in family category.

so my question is will i see any perfomance benefit if i order the where clause like this

SELECT * from mytable WHERE category = 'family' AND type = 'pictures' AND enabled = '1'

Thanks using : MYISAM as table engine. and all the columns in where clause has index .

Upvotes: 0

Views: 84

Answers (1)

Arth
Arth

Reputation: 13110

Nah, the optimizer is clever enough to use the best index in this simple SELECT.. use an EXPLAIN on each to double check if you like (they should come out the same).

You may get better performance if you add one INDEX on all three columns however.

Upvotes: 2

Related Questions