On Apr 18, 9:49 am, jey bal
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:> 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 run the above query?
> Is there any way to reduce the time? is it possible? please tell
> me.....................................
>
well the first step is to run explain against the query and see what
it says. Make sure you''ve added indexes when appropriate (at a minimum
this should include the columns being joined on. You should also index
columns used in the where clause that are sufficiently selective (I''d
guess that contacts_lists.list_id would be a good candidate). use
explain before and after to see the difference adding indexes makes to
the query plan
Fred> --
> Posted viahttp://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.