简体   繁体   中英

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 eg

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM