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

オープン
#66,921 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
30/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
mariadb, php, sql
領域
database

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
PHP
スター
37.6k
フォーク
5.4k
平均マージ
1日 13時間
マージ済み PR(30日)
623

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nextcloud/server のほかの issue

nextcloud/server の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。