[Bug]: Files "Recent" view takes 13–21 s: `mtime OR upload_time` across two tables prevents index use

Ouverte
#66,921 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
30/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
mariadb, php, sql
Domaine
database

Piste de recherche

Start from the Recent query in the report: its mtime OR upload_time condition spans oc_filecache and oc_filecache_extended, which stops MariaDB using fs_mtime or fce_utime_idx. Run EXPLAIN on the query and on the UNION-of-candidate-IDs variant described in the issue, then compare. Done when the Recent query uses the indexes, returns the same rows, and finishes well under a second on a large filecache.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

35-feedback
⚠️ This issue respects the following points: ⚠️
  • This is not a troubleshooting question, general support matter, or webserver/proxy problem, but likely a bug (if unsure, ask the Community Help Forum).
  • This issue is not already reported on Github OR solved at the Community Help Forum (I've searched!).
  • I'm using a maintained major version of Nextcloud Server and tested against the latest patch level. (Supported major versions and current patch levels).
  • I agree to follow Nextcloud's Code of Conduct.
  • I've tried my best to provide clear reproduction steps that someone unfamiliar with this bug could use to reproduce it.
Bug description

Since upload_time was added to recent files (#58327), the query behind the Files "Recent" view combines file.mtime > X OR fe.upload_time > X. The two columns are in different tables (oc_filecache, oc_filecache_extended), so MariaDB cannot use fs_mtime or fce_utime_idx. It falls back to a range scan over all filecache rows of the user's storages.

On this instance, 142 rows match on mtime and 0 on upload_time, but every call examines ~770,000 rows and takes 13–21 s.

Query from the slow log (shortened select list):

SELECT `file`.`fileid`, ... FROM `oc_filecache` `file`
LEFT JOIN `oc_filecache_extended` `fe` ON `file`.`fileid` = `fe`.`fileid`
LEFT JOIN `oc_vcategory_to_object` `tagmap` ON `file`.`fileid` = `tagmap`.`objid`
LEFT JOIN `oc_files_metadata` `meta` ON `file`.`fileid` = `meta`.`file_id`
LEFT JOIN `oc_vcategory` `tag` ON (`tagmap`.`categoryid` = `tag`.`id`) AND (`tag`.`type` = 'files') AND (`tag`.`uid` = '<user>')
WHERE ((`mimetype` <> '2') OR (`size` = 0))
  AND ((`mtime` > 1794051606) OR (`upload_time` > 1794051606))
  AND (((`storage` = 3) AND ((`path` = 'files') OR (`path` LIKE 'files/%'))) OR (`storage` IN (12, 22)))
ORDER BY GREATEST(`file`.`mtime`, COALESCE(fe.upload_time, 0)) desc LIMIT 100;
# Query_time: 20.915799  Rows_sent: 69  Rows_examined: 769951
# explain: 1 SIMPLE file range fs_storage_mimepart ... rows 851837 r_rows 767816 ... Using index condition; Using where; Using temporary; Using filesort

Selecting the candidate IDs first through both indexes returns the same rows in 0.19 s:

SELECT ... FROM (
  SELECT fileid FROM oc_filecache WHERE mtime > 1794051606
  UNION
  SELECT fileid FROM oc_filecache_extended WHERE upload_time > 1794051606
) u
JOIN oc_filecache file ON file.fileid = u.fileid
LEFT JOIN oc_filecache_extended fe ON ...
WHERE <same storage/mimetype conditions>
ORDER BY ... LIMIT 100;

A WHERE file.fileid IN (... UNION ...) variant does not help: MariaDB turns it into a dependent subquery and scans again (30 s).

Steps to reproduce
  1. Have a user with large storages in the filecache (here: home + two local external storages, ~770k rows).
  2. Open Files → Recent.
Expected behavior

The query uses the mtime / upload_time indexes and returns in well under a second.

Actual behavior

Full range scan over all filecache rows of the user's storages, 13–21 s per call.

Nextcloud Server version

35

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.4

Web server

Apache (supported)

Database engine version

MariaDB

Is this bug present after an update or on a fresh install?

None

Are you using the Nextcloud Server Encryption module?

Encryption is Disabled

What user-backends are you using?
  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other
Configuration report

No response

List of activated Apps

No response

Nextcloud Signing status

No errors have been found.

Nextcloud Logs

No log entries; the query shows up only in the MariaDB slow query log (quoted above).

Additional info

Nextcloud 35.0.3, MariaDB 11.8.6, PHP 8.4.28, Debian 13 (aarch64). Validated and reproduced on a live Nextcloud instance; timings above are from that instance.


Assisted by ClaudeCode:claude-opus-5-5

Langage dominant
PHP
Étoiles
37.6k
Forks
5.4k
Merge moyen
1 j 13 h
PR mergées (30 j)
623

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de nextcloud/server

Toutes les issues de nextcloud/server

Issues similaires

Plus d'issues PHP

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.