MySQL Forums
Forum List  »  Optimizer & Parser

Re: JOINS AND INDEX NOT USED
Posted by: Rick James
Date: August 07, 2009 10:45PM

Perhaps OR is the villain... See if this runs faster:
(
SELECT  server.mailhome
    FROM  emailaddress
    INNER JOIN  account
    LEFT JOIN  server ON account.server_current = server.id
    WHERE  emailaddress.domain = 'domain.com'
      AND  emailaddress.lhs = ''
    ORDER BY  emailaddress.lhs DESC
    LIMIT  1
)
UNION
(
SELECT  server.mailhome
    FROM  emailaddress
    INNER JOIN  account
    LEFT JOIN  server ON account.server_current = server.id
    WHERE  emailaddress.domain = 'domain.com'
      AND  emailaddress.lhs = 'emailuser'
    ORDER BY  emailaddress.lhs DESC
    LIMIT  1
)
    ORDER BY  emailaddress.lhs DESC
    LIMIT  1

What is the value of server_current when it ignores the index? Perhaps the cardinality is so poor that it decided that a table scan was faster than bothering to use the index.

Options: ReplyQuote


Subject
Views
Written By
Posted
3481
July 30, 2009 04:51PM
Re: JOINS AND INDEX NOT USED
1872
August 07, 2009 10:45PM


Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.