On Wed, 21 Aug 2002, Brian Moon wrote:

> If I have a query like:
> select field1 from table where field2=0 order by field3 desc limit 30;
> and I have keys:
> key field2 (field2)
> key field3 (field3)
>
> Will MySQL use one key to select and one to order?  Or do I need a:
>
> key field2_field3 (field2, field3)
>
> This is a big table and i don't want to have to alter it unless I need
> too.

Hi Brian,

In reading this:

  http://www.mysql.com/doc/en/ORDER_BY_optimisation.html

Two points stick out re: your situation:

  "The following queries will use the index to resolve the ORDER BY /
   GROUP BY part:

   ..
   ..
   SELECT * FROM t1 WHERE key_part1=constant ORDER BY key_part2
  "

and..

  "Some cases where MySQL can not use indexes to resolve the ORDER BY:
   (Note that MySQL will still use indexes to find the rows that matches
   the WHERE clause):

   ..
   The key used to fetch the rows are not the same one that is used to do
   the ORDER BY: SELECT * FROM t1 WHERE key2=constant ORDER BY key1
  "

Sorry -- no direct answer, but just in case you haven't read the above, I
hope it helps.  According to that second quote, your ORDER BY will not use
the key on field3 for a speedy order.

Regards,
Neil Mansilla
whatUseek.com


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to