perf(folder): avoid on-disk temp table when sorting folders by group count#4736
Open
solracsf wants to merge 1 commit into
Open
perf(folder): avoid on-disk temp table when sorting folders by group count#4736solracsf wants to merge 1 commit into
solracsf wants to merge 1 commit into
Conversation
…count Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
54e3b4f to
8e8a70b
Compare
Member
|
It's probably best to just drop the ordering altogether |
Member
Author
|
Cc @provokateurin since this has been introduced by 38dfb30 |
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.
Summary
Found while working on nextcloud/server#60932
The admin list, when sorted by the Groups column, calls
FolderManager::getAllFoldersWithSize($offset, $limit, 'groups', $order). That code path ordered folders by their applicable-group count with aLEFT JOIN group_folders_groups + GROUP BY f.folder_id:The
GROUP BYforces the database to materialize an internal temporary table. BecauseselectWithFileCache()selects theoptionscolumn, aLONGTEXT, that temporary table cannot use the in-memoryMEMORYengine (it cannot hold TEXT/BLOB), so MariaDB/MySQL always spill it to an on-disk (Aria) temporary table, regardless oftmp_table_size, on every request that uses this sort.Validation (MariaDB 10.11, 3 group folders, 60k
oc_filecacherows)EXPLAIN, driving tablef:Using where; Using temporary; Using filesortUsing where; Using filesortSHOW STATUSaround the query (tmp_table_size = max_heap_table_size = 64M):Created_tmp_disk_tablesResult-equivalence: the returned folder order is identical for both
ASCandDESC, verified by building the query throughIQueryBuilderagainst the real database.Tests
Adds
FolderManagerTest::testGetAllFoldersWithSizeOrderedByGroups, which creates folders with 1/2/3 applicable groups and asserts the'groups'sort returns them ordered by group count (both ascending and descending).