We're seeing a lot of sloooow queries due to the recommendations app. So many it actually brought the server to a halt.
They all have a similar pattern but differ in lenght.
Here's one example from mysqldumpslow. As you can see the query is taking ~ 25 min. on average.
Count: 33 Time=1602.62s (52886s) Lock=0.01s (0s) Rows_sent=7.0 (231), Rows_examined=7505485.0 (247681005),
query from mysqldump slow
SELECT`file`.`fileid`, `storage`, `path`, `path_hash`, `file`.`parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`, `encrypted`, `etag`, `permissions`, `checksum`, `metadata_etag`, `creation_time`, `upload_time`FROM`oc_filecache``file`LEFT JOIN`oc_filecache_extended``fe`ON`file`.`fileid`=`fe`.`fileid`WHERE ((`mimetype`<> N) OR (`size`= N))
AND (
(
(`storage`= N) AND ((`path`='S') OR (`path`LIKE'S'))
) OR (
((`storage`= N) AND ((`path_hash`='S') OR (`path`LIKE'S')))
AND ((`path_hash`='S') OR (`path`LIKE'S'))
)
OR (
...
)
)
ORDER BY`mtime`+'S'descLIMIT N
The actual values for the order and limit query are:
ORDER BY`mtime`+'0'descLIMIT7
This looks very much like the call to getRecent in
| */ |
| publicfunctiongetMostRecentRecommendation(IUser$user, int$max): array { |
| /** @var IRootFolder $rootFolder */ |
| $rootFolder = $this->serverContainer->get(IRootFolder::class); |
| $userFolder = $rootFolder->getUserFolder($user->getUID()); |
| |
| returnarray_filter(array_map(function (Node$node) use ($userFolder): ?RecommendedFile { |
| try { |
| $parentPath = dirname($node->getPath()); |
| if ($parentPath === '' || $parentPath === '.' || $parentPath === '/') { |
| $parentPath = $node->getParent()->getPath(); |
| } |
| returnnewRecommendedFile( |
| $userFolder->getRelativePath($parentPath), |
| $node, |
| $node->getMTime(), |
| $this->l10n->t("Recently edited") |
| ); |
| } catch (StorageNotAvailableException$e) { |
| returnnull; |
| } |
| }, $userFolder->getRecent($max)), function (?RecommendedFile$entry): bool { |
| return$entry !== null; |
| }); |
| } |
Given that $max is 7 by default.
SHOW PROCESSLIST shows them as Creating sort index most of the time.
So maybe all we are missing is an index on mtime + '0'. Or maybe we should do away with the + '0'.
We're seeing a lot of sloooow queries due to the recommendations app. So many it actually brought the server to a halt.
They all have a similar pattern but differ in lenght.
Here's one example from
mysqldumpslow. As you can see the query is taking ~ 25 min. on average.query from mysqldump slow
The actual values for the order and limit query are:
This looks very much like the call to
getRecentinrecommendations/lib/Service/RecentlyEditedFilesSource.php
Lines 47 to 71 in 0342f4c
Given that
$maxis 7 by default.SHOW PROCESSLISTshows them asCreating sort indexmost of the time.So maybe all we are missing is an index on
mtime + '0'. Or maybe we should do away with the+ '0'.