Ruby on Rails: Model.all.each vs find_by_sql("SELECT * FROM model").each ?
Posted
by B_
on Stack Overflow
See other posts from Stack Overflow
or by B_
Published on 2010-03-30T02:23:27Z
Indexed on
2010/03/30
8:23 UTC
Read the original article
Hit count: 453
I'm fairly new to RoR. In my controller, I'm iterating over every tuple in the database. For every table, for every column I used to call
SomeOtherModel.find_by_sql("SELECT column FROM model").each {|x| #etc }
which worked fine enough. When I later changed this to
Model.all(:select => "column").each {|x| #etc }
the loop starts out at roughly the same speed but quickly slows down to something like 100 times slower than the the find_by_sql command. These calls should be identical so I really don't know what's happening.
I know these calls are not the most efficient but this is just an intermediate step and I will optimize it more once this works correctly.
Thanks!
© Stack Overflow or respective owner