I was just running a relative simple exists? query: Page.exists?(["id > ?",i]) which equates to SELECT COUNT(*) FROM `pages` WHERE (id > 1400000) LIMIT 1 You would think with a COUNT and a LIMIT 1, that things would be really fast, but its SUPER slow, its trying to count all the records greater than 1400000. This is N times faster: SELECT * FROM `pages` WHERE (id > 1400000) LIMIT 1 Do you guys think this needs to be changed, or not worth changing COUNT(*) to just * even though its a "LIMIT 1" ? -- Posted via http://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Aryk Grosz
2008-Oct-11 23:22 UTC
Re: huge performance issue with ActiveRecord::Base exists?
COMPLETELY IGNORE this "issue", this was caused by an old overwrite of the exists? function that I had from years ago. MY BAD! -- Posted via http://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Oct-11 23:26 UTC
Re: huge performance issue with ActiveRecord::Base exists?
On Oct 12, 12:19 am, Aryk Grosz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I was just running a relative simple exists? query: > > Page.exists?(["id > ?",i]) > > which equates to > > SELECT COUNT(*) FROM `pages` WHERE (id > 1400000) LIMIT 1 > > You would think with a COUNT and a LIMIT 1, that things would be really > fast, but its SUPER slow, its trying to count all the records greater > than 1400000. > > This is N times faster: > > SELECT * FROM `pages` WHERE (id > 1400000) LIMIT 1 > > Do you guys think this needs to be changed, or not worth changing > COUNT(*) to just * even though its a "LIMIT 1" ?Which version of rails are you running? I''ve looked at the source of edge, 2-1-stable and 2-0-stable and for all those versions exists does not appear to use count. Are you sure the query is coming from there? 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Aryk Grosz
2008-Oct-11 23:28 UTC
Re: huge performance issue with ActiveRecord::Base exists?
Fred, this was my mistake read, the post above yours. -- Posted via http://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---