MySQL Forums
Forum List  »  Optimizer & Parser

Re: Query Tuning for NOT EQUAL TO <> operator
Posted by: Rick James
Date: November 02, 2010 02:21PM

My bad. You are not doing a JOIN.

SELECT uid, ip FROM log_count WHERE ip = '1851220710' AND uid <> '4796596'
leads to log_count needing
INDEX(ip)
and so does log_count_arch:
SELECT uid, ip FROM log_count_arch WHERE ip = '1851220710' AND uid <> '4796596' GROUP BY uid;

For log_count_arch, it might be a little more optimal to have
INDEX(ip, uid)
This might help with the GROUP BY. (It will not help any for the 'uid<>...')

EXPLAIN's rows 2 & 3 have
type: ALL
This implies doing a table scan (costly). With the suggested indexes, this is likely to change, and be faster.

Back to the title... "<>" is essentially un-optimizable.

Options: ReplyQuote


Subject
Views
Written By
Posted
10760
October 22, 2010 07:42AM
Re: Query Tuning for NOT EQUAL TO <> operator
3630
November 02, 2010 02:21PM


Sorry, you can't reply to this topic. It has been closed.

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.