This project is archived and is in readonly mode.

#5933 ✓committed
alex (at alexrothenberg)

Allow adapters to specify a limit on number of ids to allow in a single expression

Reported by alex (at alexrothenberg) | November 8th, 2010 @ 09:46 PM | in 3.0.5

When active record preloads associated records it can generate a long list in the sql. This patch allows an adapter to specify its limit and AR will then issue multiple queries if necessary.

For example if there were 1500 posts

Post.include(:comments)

will generate something like

select * from posts
select * from comments where post_id IN (1,2,3,4...999)
select * from comments where post_id IN (1001...1500)

With out the patch some databases (oracle I mean you) will give errors when there are too many ids in the comments select (in oracle more than 1000 causes error ORA-01795 - see http://ora-01795.ora-code.com/).

The patch is attached below or can be see on github at https://github.com/alexrothenberg/rails/tree/maximum_ids_in_list_fo...

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages