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>2021-10-18 19:05:48 +0300
committerRobin Appelman <robin@icewind.nl>2021-10-18 19:05:48 +0300
commit5002bf9cc1c9c25f0b7d180ac8400640513df913 (patch)
treec998d71cf7bf2f1152aa9658a463057396655e9e
parent7f272dd98f75fec5db6dd732a52aa328e898a1e8 (diff)
tell mysql to ignore the sort index for search queries
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. To bypass this, we tell mysql explicitly not to use the mtime (the default order field) index, so it will instead pick an index that is actually useful. Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--lib/private/Files/Cache/Cache.php8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php
index ae707fb5b54..99be91f5d6b 100644
--- a/lib/private/Files/Cache/Cache.php
+++ b/lib/private/Files/Cache/Cache.php
@@ -840,7 +840,13 @@ class Cache implements ICache {
protected function buildSearchQuery(ISearchQuery $searchQuery): IQueryBuilder {
$builder = $this->getQueryBuilder();
- $query = $builder->selectFileCache('file');
+ // 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.
+ //
+ // To bypass this, we tell mysql explicitly not to use the mtime (the default order field) index,
+ // so it will instead pick an index that is actually useful.
+ $query = $builder->selectFileCache('file', 'ignore index for order by (fs_mtime)');
$query->whereStorageId();