Skip to content

Remove redundant ix_FileTrash_repo_id index (covered by composite index in seafevents#606)#8680

Merged
r350178982 merged 5 commits intohaiwen:masterfrom
yaoge123:optimize-filetrash-remove-redundant-index
Feb 9, 2026
Merged

Remove redundant ix_FileTrash_repo_id index (covered by composite index in seafevents#606)#8680
r350178982 merged 5 commits intohaiwen:masterfrom
yaoge123:optimize-filetrash-remove-redundant-index

Conversation

@yaoge123
Copy link
Contributor

@yaoge123 yaoge123 commented Feb 8, 2026

Summary

Add a composite index (repo_id, delete_time) on the FileTrash table and remove the now-redundant single-column repo_id index.

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:

SELECT * FROM FileTrash
WHERE repo_id = ? AND delete_time > ?
ORDER BY delete_time DESC
LIMIT ...

The single-column repo_id index 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

  1. seahub/base/models.py - Remove db_index=True from FileTrash.repo_id (the single-column index is now redundant)
  2. sql/mysql.sql - Replace ix_FileTrash_repo_id (repo_id) with idx_filetrash_repo_delete_time (repo_id, delete_time) in the table definition
  3. scripts/upgrade/sql/13.0.0/mysql/seahub.sql - Add ALTER TABLE to create the composite index and DROP INDEX to remove the old one for existing installations

@r350178982 r350178982 force-pushed the optimize-filetrash-remove-redundant-index branch from 0ce179e to 387bd8b Compare February 9, 2026 08:07
@r350178982 r350178982 merged commit 1d5a457 into haiwen:master Feb 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants