Repository navigation
Conversation
Contributor
Author
|
If You can check it with: SHOW CREATE TABLE xf_resource_version; |
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.
getResourceUpdatesandgetResourceUpdatejoinxf_resource_updateandxf_resource_versiononresource_update_id.xf_resource_versionhas no index on that column, onlyPRIMARYandresource_id_release_date (resource_id, release_date).So MySQL reads the whole
xf_resource_versiontable for every request, even for a resource with a single update.With about 550k versions this takes between 30 and 300 ms of database time per request, on every page.
This PR adds
resource_idto the join condition, so MySQL can use the existing indexresource_id_release_date.getResourceUpdatesnow filters byrv.resource_idinstead ofr.resource_id.PDO sends the id as a string, and then MySQL does not carry the filter on
r.resource_idover torv.It would read all versions of the resource again for every update, about 900,000 rows on a late page of a resource with 1,000 updates.
Deliberate decisions:
Not covered on purpose:
XenForo always sets it like this, but imported or manually changed data could differ.
This query should return 0 (it reads both tables once):
SELECT COUNT(*) FROM xf_resource_version rv INNER JOIN xf_resource_update ru ON ru.resource_update_id = rv.resource_update_id WHERE ru.resource_id != rv.resource_id;limitparameter to paginated actions #109 changes the same line ingetResourceUpdates().Whichever is merged second needs
$this->_resource_update('AND rv.resource_id = :resource_id', $limit, $offset, $order, $direction).Benchmark
Measured locally with the tables and indexes of XenForo 1.5.24 and Resource Manager 1.1.2, MySQL 8.0.32, PHP 7.0.33 (PHP-FPM, nginx).
The database holds about as much data as SpigotMC has according to Spiget: ~92k resources, ~465k updates plus one description each, ~552k versions.
Database time and rows examined come from MySQL's performance_schema, every number is the median of three rounds.
getResourceUpdatefor 100 random updatesgetResourceUpdateswith 16 parallel clientsAlternative: an index on
resource_update_idInstead of changing the query, an index on
xf_resource_version.resource_update_idfixes the slow requests as well:I measured both ways with the same data, and they are about equally fast and return exactly the same results:
getResourceUpdateThe index does not depend on versions belonging to the same resource as their update, and the API code stays as it is.
But it changes the schema of a XenForo table. This PR works without any change to the database, so I chose it.
The index takes about 8.5 MB for 550,000 versions and can be added without locking the table on MySQL 8.
Both together do no harm, so the index is still an option if the query above finds versions that belong to another resource.