AR incorrectly quotes ids inside an IN clause. This happens when using include and limit clauses over a has_many relationship. An example and patch follows.
The ids using in the IN clause shouldn't be quoted as they are integers and not quoting them should improve the performance (by coping better with indexes).
Banner Load Including Associations (0.006802) SELECT (...) FROM banners LEFT OUTER JOIN blocks ON blocks.banner_id = banners.id WHERE (banner_id = banners.id and blocks.status = 0 and blocks.percentage_sold < 100) AND banners.id IN ('15', '13', '11') ORDER BY created_at DESC
After the patch to the select_limited_ids_list function this no longer occurs.
Banner Load Including Associations (0.004319) SELECT (...) FROM banners LEFT OUTER JOIN blocks ON blocks.banner_id = banners.id WHERE (banner_id = banners.id and blocks.status = 0 and blocks.percentage_sold < 100) AND banners.id IN (15, 13, 11) ORDER BY created_at DESC