Почему MAX () в 100 раз медленнее, чем ORDER BY… LIMIT 1?

У меня есть столfoo с (среди 20 других) столбцами,barbaz а такжеquux с индексами наbaz а такжеquux, В таблице ~ 500 тыс. Строк.

Почему следующие запросы так сильно отличаются по скорости? Запрос A занимает 0,3 с, а запрос B - 28 с.

Запрос А

select baz from foo
    where bar = :bar
    and quux = (select quux from foo where bar = :bar order by quux desc limit 1)

объяснять

id  select_type table   type    possible_keys   key     key_len ref     rows    Extra
1   PRIMARY     foo     ref     quuxIdx         quuxIdx 9       const   2       "Using where"
2   SUBQUERY    foo     index   NULL            quuxIdx 9       NULL    1       "Using where"

Запрос B

select baz from foo
    where bar = :bar
    and quux = (select MAX(quux) from foo where bar = :bar)

объяснять

id  select_type table   type    possible_keys   key     key_len ref     rows    Extra
1   PRIMARY     foo     ref     quuxIdx         quuxIdx 9       const   2       "Using where"
2   SUBQUERY    foo     ALL     NULL            NULL    NULL    NULL    448060  "Using where"

Я использую MySQL 5.1.34. '

Ответы на вопрос(1)

Ваш ответ на вопрос