Question

I am having some issues getting an index to work for this query (generated by MicroStrategy):

SELECT     a11.method  method, sum(a11.call_count) CALLCOUNT
FROM    call_facts     a11
  JOIN    dimension a12 ON (a11.user_id = a12.user_id)
  JOIN service a13 ON (a11.service_id = a13.service_id)
WHERE   (a12.is_fraudulent = 0
  AND a12.is_test_account = 0
  AND a13.in_directory in ('yes')
  AND a11.date > '2011-10-01')
GROUP BY a11.method;  

I currently have indices on a12.is_fraudulent and a12.is_test_account. Explain shows an index merge using those two. a11 and a13 are both good with indices. What index could I create to speed this query up a bit?

For reference, a12 has about 8 M entries, 7.4 of them match the is_test_account = 0 and is_fraudulent = 0 cases.

Était-ce utile?

La solution

Compound indexes usually give better performance than multiple single-column indexes combined in an index-merge optimization.

It would be helpful if you would include the current EXPLAIN report for the query when you ask for help with a query.

It would also be helpful to post the full DDL (SHOW CREATE TABLE) for each table, because "a11 and a13 are both good with indices" is probably not true, and gives us no information about what indexes you have defined in these tables.

If I have to make some guess, I would try:

ALTER TABLE call_facts ADD INDEX (method, date, call_count);

ALTER TABLE dimension ADD INDEX (user_id, is_fraudulent, is_test_account);

ALTER TABLE service ADD INDEX (service_id, in_directory);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top