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

Aperta
#66,921 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
30/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
mariadb, php, sql
Ambito
database

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
PHP
Stelle
37.6k
Fork
5.4k
Merge medio
1g 13h
PR unite (30g)
623

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nextcloud/server

Tutte le issue di nextcloud/server

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.