nextcloud / nextcloud/server

Possibly sub-ideal index design for filecache.storage column

Open
#51,459 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

0. Needs triage enhancement feature: database feature: filesystem performance 🚀
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

How to use GitHub
  • Please use the 👍 reaction to show that you are interested into the same feature.
  • Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

Is your feature request related to a problem? Please describe.

As a admin/DBA of Nextcloud I monitor queries and notice a relatively simple query that is slow:

SELECT COUNT(*) FROM oc_filecache WHERE storage = ?

ANALYZE shows that the index fs_storage_mimetype is used and it takes the query around 27 seconds when scanning ~7M entries. The index has storage as first column, followed by mimetype.

create index fs_storage_mimetype
    on nextclouddev.oc_filecache (storage, mimetype);

Describe the solution you'd like

Consider an index on just storage. From simple tests, such index can retrieve the same result in around 13s. That is roughly twice as fast.

Describe alternatives you've considered

No ideas at this point.

Additional context

N/a

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file or test is named. Start by locating the schema or migration that defines oc_filecache and the fs_storage_mimetype index, then inspect how database-specific indexes are handled. Compare the storage-only index with the existing query across supported databases; done means the index choice is implemented safely with appropriate validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, sql
Domain
backend, databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.