Opened 10 years ago
Closed 8 years ago
#29552 closed enhancement (worksforme)
Slight tweak to no_found_rows logic in WP_Query
Reported by: | dmchale | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 1.5 |
Component: | Query | Keywords: | reporter-feedback needs-testing has-patch |
Focuses: | performance | Cc: |
Description (last modified by )
It seems that edge cases could introduce times when a query WOULD have limits but NOT want them (when the query was passed nopaging=true or post_per_page=-1). When this happened, SQL_CALC_FOUND_ROWS would be invoked in the query and hinder performance of the query.
Code change still allows for a developer to override no_found_rows with their own value, but now checks the nopaging and post_per_page variables to possibly set no_found_rows to true anyway. By using one of those 2 variables to ask for EVERYTHING, we know the developer does not want/need pagination. This forces the issue so that by the time we get to the line...
if ( !$q['no_found_rows'] && !empty($limits) )
...we don't find ourselves WITH limits, and a False value for no_found_rows, in spite of the fact that the developer had asked for "all".
Attachments (2)
Change History (10)
#2
@
10 years ago
- Description modified (diff)
- Keywords needs-testing added
- Version changed from trunk to 1.5
This ticket was mentioned in Slack in #core by boone. View the logs.
8 years ago
#4
@
8 years ago
- Milestone changed from Awaiting Review to 4.6
- Owner set to boonebgorges
- Status changed from new to assigned
Assigning to myself to review the tests. If they are passing, I'll commit them and close the ticket as invalid, pending further details. If they're not passing, then maybe we have a bug on our hands.
Thanks for the patch, dmchale.
I can't reproduce this. Check out the last two tests in 29552.tests.patch. They declare
nopaging=true
andposts_per_page=-1
, and in each case, you can see that the request query does *not* containSQL_CALC_FOUND_ROWS
. When you haveLIMIT
clauses, WP_Query does not append the SQL_CALC_FOUND_ROWS keyword. See https://core.trac.wordpress.org/browser/tags/4.0/src/wp-includes/query.php?annotate=blame#L3376. See also https://core.trac.wordpress.org/browser/tags/4.0/src/wp-includes/query.php?annotate=blame#L3611 to see howfound_posts
is set in these cases.Can you say more about your "edge cases"?