]> source.dussan.org Git - nextcloud-server.git/commitdiff
Revert "[21] tell mysql to ignore the sort index for search queries" 29551/head
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>
Thu, 4 Nov 2021 10:10:46 +0000 (11:10 +0100)
committerGitHub <noreply@github.com>
Thu, 4 Nov 2021 10:10:46 +0000 (11:10 +0100)
lib/private/DB/QueryBuilder/QueryBuilder.php
lib/private/Files/Cache/Cache.php
lib/private/Files/Cache/CacheQueryBuilder.php

index 82add039cf55149cf38010cc4a947dd878e7db11..352829a56ae796fe6b2db55d5bf523658968e5de 100644 (file)
@@ -1301,21 +1301,4 @@ class QueryBuilder implements IQueryBuilder {
 
                return $this->helper->quoteColumnName($alias);
        }
-
-       /**
-        * Either appends to or replaces a single, generic query part.
-        *
-        * The available parts are: 'select', 'from', 'set', 'where',
-        * 'groupBy', 'having' and 'orderBy'.
-        *
-        * @param string $sqlPartName
-        * @param mixed  $sqlPart
-        * @param bool   $append
-        *
-        * @return $this This QueryBuilder instance.
-        */
-       public function add(string $sqlPartName, $sqlPart, bool $append = false) {
-               $this->queryBuilder->add($sqlPartName, $sqlPart, $append);
-               return $this;
-       }
 }
index 4e5edc0e0a6bf8df5ce6c0047de4459f6998009a..34ed6d33a2d8c34d9627a6e1c8e07a1c559c1334 100644 (file)
@@ -848,13 +848,7 @@ class Cache implements ICache {
        protected function buildSearchQuery(ISearchQuery $searchQuery): IQueryBuilder {
                $builder = $this->getQueryBuilder();
 
-               // 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 = $builder->selectFileCache('file');
 
                $query->whereStorageId();
 
index 9847375495e30cb9c4e744a69893b750d137b4d6..2215cef9a15a050a0ec00612a85295ff373d0cb6 100644 (file)
@@ -26,7 +26,6 @@ declare(strict_types=1);
 
 namespace OC\Files\Cache;
 
-use Doctrine\DBAL\Platforms\MySQLPlatform;
 use OC\DB\QueryBuilder\QueryBuilder;
 use OC\SystemConfig;
 use OCP\DB\QueryBuilder\IQueryBuilder;
@@ -46,24 +45,12 @@ class CacheQueryBuilder extends QueryBuilder {
                $this->cache = $cache;
        }
 
-       public function selectFileCache(string $alias = null, string $mysqlIndexHint = '') {
+       public function selectFileCache(string $alias = null) {
                $name = $alias ? $alias : 'filecache';
                $this->select("$name.fileid", 'storage', 'path', 'path_hash', "$name.parent", 'name', 'mimetype', 'mimepart', 'size', 'mtime',
                        'storage_mtime', 'encrypted', 'etag', 'permissions', 'checksum', 'metadata_etag', 'creation_time', 'upload_time')
-                       ->from('filecache', $name);
-               if ($mysqlIndexHint !== '' && $this->getConnection()->getDatabasePlatform() instanceof MySQLPlatform) {
-                       $this->add('join', [
-                               $this->quoteAlias($name) => [
-                                       // horrible query builder crimes to sneak in raw sql after the "FROM oc_filecache $name"
-                                       'joinType' => $mysqlIndexHint . ' left',
-                                       'joinTable' => $this->getTableName('filecache_extended'),
-                                       'joinAlias' => $this->quoteAlias('fe'),
-                                       'joinCondition' => $this->expr()->eq("$name.fileid", 'fe.fileid'),
-                               ],
-                       ], true);
-               } else {
-                       $this->leftJoin($name, 'filecache_extended', 'fe', $this->expr()->eq("$name.fileid", 'fe.fileid'));
-               }
+                       ->from('filecache', $name)
+                       ->leftJoin($name, 'filecache_extended', 'fe', $this->expr()->eq("$name.fileid", 'fe.fileid'));
 
                $this->alias = $name;