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
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,' ,
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?