If you're used to using raw SQL to find database records, then you will generally find that there are better ways to carry out the same operations in Rails.
To retrieve objects from the database, Active Record provides several finder methods.
Each finder method allows you to pass arguments into it to perform certain queries on your database without writing raw SQL.
The methods are: in a single pass, build a model object per row, and then keep the entire array of model objects in memory.
Indeed, if we have a large number of records, the entire collection may exceed the amount of memory available.
Rails provides two methods that address this problem by dividing records into memory-friendly batches for processing.