Optimize the query
I have following query for find out the total no of counts.
SELECT count(*)
FROM contacts_lists
JOIN plain_contacts
ON contacts_lists.contact_id = plain_contacts.contact_id
JOIN contacts
ON contacts.id = plain_contacts.contact_id
WHERE plain_contacts.has_email
AND NOT contacts.email_bad
AND NOT contacts.email_unsub
AND contacts_lists.list_id = 45897
It takes 150ms to complete its task. Is there any another way to ru开发者_如何学Cn the above query? Is there any way to reduce the time? is it possible? please tell me.....................................
Did you create indices (add_index
in migrations) on your contact_id
columns? Also it might be better to use
JOIN contacts ON contacts.id = contacts_lists.contact_id
# instead of: JOIN contacts ON contacts.id = plain_contacts.contact_id
精彩评论