Remove redundant ix_FileTrash_repo_id index (covered by composite index in seafevents#606)#8680
Merged
r350178982 merged 5 commits intohaiwen:masterfrom Feb 9, 2026
Conversation
0ce179e to
387bd8b
Compare
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
Add a composite index
(repo_id, delete_time)on theFileTrashtable and remove the now-redundant single-columnrepo_idindex.This is the companion PR to haiwen/seafevents#606, which adds the same composite index in the SQLAlchemy model.
Problem
When listing a repository's trash, the query pattern is:
The single-column
repo_idindex is not optimal for this query. A composite index(repo_id, delete_time)allows the query to locate the target repository's records and walk the index in sorted order, avoiding scanning unnecessary rows and extra sorting.Tested on a production instance, query time improved from hundreds of milliseconds to under 1 ms.
Changes
seahub/base/models.py- Removedb_index=TruefromFileTrash.repo_id(the single-column index is now redundant)sql/mysql.sql- Replaceix_FileTrash_repo_id (repo_id)withidx_filetrash_repo_delete_time (repo_id, delete_time)in the table definitionscripts/upgrade/sql/13.0.0/mysql/seahub.sql- AddALTER TABLEto create the composite index andDROP INDEXto remove the old one for existing installations