Jeff Pritchard wrote: > So is it generally the case that having the db hunt down the few records > we're after each time will execute substantially faster than returning > all of the records and doing the comparison "outside the database"? As > a novice db guy, the two approaches sound roughly similar, since both > cases involve doing essentially the same comparison on the same number > of records. Perhaps there is a lot of overhead involved in returning > records to the app.
Yes, the database is going to be faster at figuring out which records need to be returned, ASSUMING proper indexing, table structure, and generally sound approach to querying. If you don't use indexes, your data is not structured well, and you're querying on half the fields in the database, it may well be faster to just pull it all back into Rails and work through it. As to why this is so, two major things come to mind: marshaling the data from the db server to the application and object creation. Suppose you have your thousand users in your system, but only 20 of them have reminders to send. If the database finds them for you, it returns just twenty and your application creates just twenty objects (and you have no more decisions to make). If you pull all one thousand back first, the database has to send more data back to you and then you're going to create 1000 objects in your application. If you need related data for the decision making, you're going to be making more than 1000 objects, and possibly more database queries (unless you've used eager loading, which increases the amount of data sent back to the app). Whatever creates the data should be the fastest at ripping through it. The database engine is optimized for data storage and retrieval. When used properly, nothing is going to be faster than the db engine's native access to the data. Peace., -- 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 [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

