Right.  The simple example listed at the bottom of this message works great
under version 4.  Version 3 gave the right answer, but it was very slow.
That made me upgrade to version 4.

However, even with version 4, I run into the same problem as soon as I add a
join.  MySQL always wants to find an index to match the join conditions.  If
there isn't an appropriate index, it actually sorts the data to match join
conditions!  This is probably right in the general case, but it makes my
query run very slowly.  How can I make this run faster?

SELECT *
FROM huge_table,small_table
WHERE huge_table.field2 = small_table.field2
ORDER BY huge_table.field1 DESC
LIMIT 5;

I want MySQL to use the index on huge_table.field1, just like it does when
there is no join.

----- Original Message -----
From: "Gerald Clark" <[EMAIL PROTECTED]>
To: "Philip Smolen" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Tuesday, September 17, 2002 12:55 PM
Subject: Re: Forcing a sort order in a join


> Using DESC on an index only works with V 4.
>
> Philip Smolen wrote:
>
> >I'm trying to make a query faster.  It seems simple, but I can't make it
> >work.
> >
> >This is a common case for me:
> >SELECT *
> >FROM very_large_table
> >WHERE (simple_condition)
> >ORDER BY an_indexed_field DESC
> >LIMIT 5;
> >For simple queries this works as expected.  MySQL starts at the end of
the
> >
>
>


---------------------------------------------------------------------
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