What SQL was running, and what was the query plan?<p>ActiveRecord is notorious for generating terrible, terrible SQL.<p>Edit: What I would expect to see would be index scan on device id, then sort + limit.  So the important factor would be rows per device, not total rows.