Hi, I am writing a small rails application that uses Ruby(1.8.5) with ActiveRecord (1.15.3) . I realized that if i use the find method with the optional parameter :select with only the required columns to look for records in a table with 50,000 records as opposed to a find method without the :select option, the query is a lot faster. It took me 31 secs in the former case as opposed to 12 in the latter. I am using MySQL and my application is running on windows. (And yes, the table that I am querying is indexed). Now my problem is that if i use :select the way it is mentioned in the rails documentation Item.find( :all, :select => [:column1, :column2, :column3] ) or Item.find( :all, :select => [''column1'', ''column2'', '':column3''] ) It throws an error because it executes a query like: select column1column2 column3 from items; when there is no column like column1column2column3 in the table items. However, If i modify my request and put a comma after each column name except on the last one Item.find( :all, :select => [''column1,'' , ''column2,'' , ''column3''] ) it works because this time it executes the query as noted below: select column1,column2,column3 from items; So I guess unless I am using some incompatible version, there could be a bug in ActiveRecord. Or am I missing something? Thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rick Olson
2007-Apr-14 23:01 UTC
Re: Possible Active Record bug using :select in find method
> Now my problem is that if i use :select the way it is mentioned in the > rails documentation > > Item.find( :all, :select => [:column1, :column2, :column3] ) or > Item.find( :all, :select => [''column1'', ''column2'', '':column3''] )Where is that in the docs? :select should be a string. :select => "col1, col2, tbl2.*" -- Rick Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.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 -~----------~----~----~----~------~----~------~--~---
wolleybook
2007-Apr-15 01:27 UTC
Re: Possible Active Record bug using :select in find method
My apologies. I should have checked in the official rails docs. I was referring to http://www.rubyonrailsblog.com/articles/2006/10/04/ruby-on-rails-cheat-sheet-collectors-edition. Thanks for clearing this up. On Apr 14, 7:01 pm, "Rick Olson" <technowee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Now my problem is that if i use :select the way it is mentioned in the > > rails documentation > > > Item.find( :all, :select => [:column1, :column2, :column3] ) or > > Item.find( :all, :select => [''column1'', ''column2'', '':column3''] ) > > Where is that in the docs? :select should be a string. :select => > "col1, col2, tbl2.*" > > -- > Rick Olsonhttp://lighthouseapp.comhttp://weblog.techno-weenie.nethttp://mephistoblog.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 -~----------~----~----~----~------~----~------~--~---