On Wed, Oct 19, 2011 at 05:09:13PM +1100, Wayne W wrote:
> I asked this question over on stackoverflow - basically I have a query
> and when using EXPLAIN I see that around 2400 rows are still being
> scanned. I'd added various indexes but it cannot make it perform any
> I would appreciate if anyone has any further ideas?
Create index on (importance, company_id) (or (company_id,importance), should
not matter). When that index is present, the query should use ref access on it
using both key parts (if by some crazy reason it doesn't, use FORCE INDEX to
make it to). This way, you will be scanning as few rows as possible.
Also, check if the EXPLAIN has "Using index". If it doesn't, add `id` to the
index, i.e. use
INDEX (importance, company_id, id)
That way, the query will be only using index, which will give the best possible
Sergei Petrunia, Software Developer
Monty Program AB, http://askmonty.org