开发者

Optimize the query

开发者 https://www.devze.com 2023-02-25 08:15 出处:网络
I have following query for find out the total no of counts. SELECT count(*) FROM contacts_lists JOIN plain_contacts

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
0

精彩评论

暂无评论...
验证码 换一张
取 消