#47280 - Remove SQL_CALC_FOUND_ROWS and lazy load found_rows#2119
Closed
johnbillion wants to merge 82 commits into
Closed
#47280 - Remove SQL_CALC_FOUND_ROWS and lazy load found_rows#2119johnbillion wants to merge 82 commits into
SQL_CALC_FOUND_ROWS and lazy load found_rows#2119johnbillion wants to merge 82 commits into
Conversation
Signed-off-by: Morgan Tocker <tocker@gmail.com>
# Conflicts: # src/wp-includes/class-wp-query.php # tests/phpunit/tests/query/noFoundRows.php
…ies don't trigger additional queries.
…nd_rows` is true.
This comment was marked as off-topic.
This comment was marked as off-topic.
…es with an `OR` relationship is accurate.
23 tasks
Member
Author
|
Closing this in favour of #3863 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Trac ticket: https://core.trac.wordpress.org/ticket/47280
This continues the work of @morgo on #330.
High level changes:
SQL_CALC_FOUND_ROWSandSELECT FOUND_ROWS()with an unboundedCOUNTof the query, which is the method recommended by MySQLSELECT FOUND_ROWS()only as a fallback if the query is filtered and aSQL_CALC_FOUND_ROWSmodifier insertedfound_postsandmax_num_pagesproperty values, thus avoiding the need to run the count query at all if it's not neededDetails and todos:
found_postsandmax_num_pagesinto private properties and then expose them via__get()which lazily populates (and caches) their valuesno_found_rowsWP_Queryobject -- the newly private properties still need to be includedfound_posts_queryfilter: https://wpdirectory.net/search/01G2JTDXB9WQ0H1Y4P0VQSFBE3SELECT FOUND_ROWS()posts_requestfilter (the only filter that runs between the query being constructed and executed) https://wpdirectory.net/search/01G695ZX9RZ03PCDN3C0HFV6A1SQL_CALC_FOUND_ROWS, need to retain the use of an immediate call toSELECT FOUND_ROWS()._deprecated_argument()posts_requestto add a DISTINCT clauseDISTINCTclause can be removed from the count queryDISTINCTis not used by core but could be used by plugins via the various clause filtersGROUP BYcan be triggered by core, eg via a meta query with two or more clauses, anORrelation, and resulting posts that match more than one meta clause -- tests have been added to cover thisDISTINCTclause in theCOUNT()query should remainswitch_to_blog()andrestore_current_blog()being called between the query and the countfound_postsandmax_num_pagesto be set via__set()found_postsormax_num_pagesare unnecessarily accessedPlugin authors:
If you're the maintainer of a plugin which makes changes to the way WordPress queries for posts or counts results, uses the
found_posts_queryfilter, or makes unusual use of thefound_postsandmax_num_pagesproperties, please test your plugin with this change in place.Other query classes
Once
WP_Queryis complete, the process can be repeated for all query classes that can perform count queries:WP_Network_QueryWP_Site_QueryWP_Comment_QueryWP_User_Query