Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Only join includes referenced in conditions for count

#1528

When issuing ActiveRecord.count queries, include options are now turned into joins indiscriminately. This patch copies the strategy from associations.rb construct_finder_sql_for_association_limiting by only adding include joins to the query if they are referenced by the condition string.

Some may say, well just don't put the includes in the options but that's a lot of things to think about.

This saves me from my stupidity since I use a hack of the "paginating_find" plugin, which does a count of a limited query before firing the actual query.

No new tests included in the patch. All the (previously passing) tests still pass.

Reported by John Devine · December 8th, 2008 @ 05:38 AM

State: stale
Milestone: 3.x
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Pratik
    Pratik
    • Assigned user set to Pratik
    • Tag changed from activerecord, calculations to activerecord, calculations, patch
    • State changed from new to incomplete
    • Title changed from [PATCH] only join includes referenced in conditions for count to Only join includes referenced in conditions for count

    Patch should still have a test displaying the behaviour that's broken at the moment.

    Thanks !

    March 7th, 2009 @ 03:44 PM

  2. Pawel
  3. Jónas Tryggvi
  4. John Devine
    John Devine

    I'll see if I can come up with some tests this weekend -- but I've never done a test for a specific SQL statement. Since nothing's actually broken (in terms of results) now, I don't know what the test would look like. Any suggestions welcome.

    March 19th, 2009 @ 10:37 PM

  5. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  6. Santiago Pastorino
    Santiago Pastorino
    • State changed from incomplete to open
    • Importance changed from to

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 05:04 PM

  7. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 05:04 PM