In general, when you want to make a slow SELECT ...
WHERE
query faster, the first thing to check is
whether you can add an index. Indexes are especially important
for queries that reference different tables, using features
such as joins and foreign keys. You can use the
EXPLAIN
statement to determine
which indexes are used for a
SELECT
. See
Section 7.8.1, “Optimizing Queries with EXPLAIN
”, and
Section 7.3.1, “How MySQL Uses Indexes”.