Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2022-04-22 14:31:34 +0300
committerRobin Appelman <robin@icewind.nl>2022-04-22 14:42:33 +0300
commita4e120c2034bc1739d7428245660670b09aa7a75 (patch)
tree0b0f3b35e7303e3e0e426c2e5908a445663369ac /lib/private/Files/Cache
parent9a76f06ecadf05ef1d26bd735df1bea0dfb15d59 (diff)
tell mysql to ignore the sort index for search queriesmysql-search-ignore-index-2
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Files/Cache')
-rw-r--r--lib/private/Files/Cache/SearchBuilder.php11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/private/Files/Cache/SearchBuilder.php b/lib/private/Files/Cache/SearchBuilder.php
index 003d3ac15e7..c8c442bcb8c 100644
--- a/lib/private/Files/Cache/SearchBuilder.php
+++ b/lib/private/Files/Cache/SearchBuilder.php
@@ -232,6 +232,17 @@ class SearchBuilder {
if ($field === 'fileid') {
$field = 'file.fileid';
}
+
+ // Mysql really likes to pick an index for sorting if it can't fully satisfy the where
+ // filter with an index, since search queries pretty much never are fully filtered by index
+ // mysql often picks an index for sorting instead of the much more useful index for filtering.
+ //
+ // By changing the order by to an expression, mysql isn't smart enough to see that it could still
+ // use the index, so it instead picks an index for the filtering
+ if ($field === 'mtime') {
+ $field = $query->func()->add($field, $query->createNamedParameter(0));
+ }
+
$query->addOrderBy($field, $order->getDirection());
}
}