WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 4 years ago

#42256 new defect (bug)

Skip SQL_CALC_FOUND_ROWS when using post__in whose count matches posts_per_page

Reported by: ethitter Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Query Keywords: reporter-feedback
Focuses: Cc:

Description

If a post__in array is passed to WP_Query whose length matches the posts_per_page value for the query, SQL_CALC_FOUND_ROWS is unnecessary.

Attachments (2)

42256.diff (786 bytes) - added by ethitter 4 years ago.
42256.2.diff (1.5 KB) - added by dlh 4 years ago.

Download all attachments as: .zip

Change History (5)

@ethitter
4 years ago

@dlh
4 years ago

#1 @dlh
4 years ago

42256.2.diff adds a test.

#2 @boonebgorges
4 years ago

What if the values in post__in point to non-existent posts? Or, perhaps more likely, what if the combination of post__in with some other param (say, a meta_query) makes it so that only a subset of the post__in items are grabbed?

It feels safer to let plugins decide whether they're passing query parameters that guarantee that all and only the items in post__in will end up in the results array. If the plugin knows this, it can pass no_found_rows explicitly.

#3 @dd32
4 years ago

  • Keywords reporter-feedback added

I'm inclined to agree with @boonebgorges here.

Perhaps including an example use-case and the impact it has upon performance will help sway it from "I don't see the need" to "That seems like a worthwhile shortcut to take".

Note: See TracTickets for help on using tickets.