Skip to content

Commit a2ccd43

Browse files
authored
Merge pull request #29551 from nextcloud/revert-29322-mysql-search-ignore-index-21
2 parents 07006f3 + 5b89d34 commit a2ccd43

File tree

3 files changed

+4
-40
lines changed

3 files changed

+4
-40
lines changed

lib/private/DB/QueryBuilder/QueryBuilder.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,21 +1301,4 @@ public function quoteAlias($alias) {
13011301

13021302
return $this->helper->quoteColumnName($alias);
13031303
}
1304-
1305-
/**
1306-
* Either appends to or replaces a single, generic query part.
1307-
*
1308-
* The available parts are: 'select', 'from', 'set', 'where',
1309-
* 'groupBy', 'having' and 'orderBy'.
1310-
*
1311-
* @param string $sqlPartName
1312-
* @param mixed $sqlPart
1313-
* @param bool $append
1314-
*
1315-
* @return $this This QueryBuilder instance.
1316-
*/
1317-
public function add(string $sqlPartName, $sqlPart, bool $append = false) {
1318-
$this->queryBuilder->add($sqlPartName, $sqlPart, $append);
1319-
return $this;
1320-
}
13211304
}

lib/private/Files/Cache/Cache.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -848,13 +848,7 @@ public function searchByMime($mimetype) {
848848
protected function buildSearchQuery(ISearchQuery $searchQuery): IQueryBuilder {
849849
$builder = $this->getQueryBuilder();
850850

851-
// mysql really likes to pick an index for sorting if it can't fully satisfy the where
852-
// filter with an index, since search queries pretty much never are fully filtered by index
853-
// mysql often picks an index for sorting instead of the *much* more useful index for filtering.
854-
//
855-
// To bypass this, we tell mysql explicitly not to use the mtime (the default order field) index,
856-
// so it will instead pick an index that is actually useful.
857-
$query = $builder->selectFileCache('file', 'ignore index for order by (fs_mtime)');
851+
$query = $builder->selectFileCache('file');
858852

859853
$query->whereStorageId();
860854

lib/private/Files/Cache/CacheQueryBuilder.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
namespace OC\Files\Cache;
2828

29-
use Doctrine\DBAL\Platforms\MySQLPlatform;
3029
use OC\DB\QueryBuilder\QueryBuilder;
3130
use OC\SystemConfig;
3231
use OCP\DB\QueryBuilder\IQueryBuilder;
@@ -46,24 +45,12 @@ public function __construct(IDBConnection $connection, SystemConfig $systemConfi
4645
$this->cache = $cache;
4746
}
4847

49-
public function selectFileCache(string $alias = null, string $mysqlIndexHint = '') {
48+
public function selectFileCache(string $alias = null) {
5049
$name = $alias ? $alias : 'filecache';
5150
$this->select("$name.fileid", 'storage', 'path', 'path_hash', "$name.parent", 'name', 'mimetype', 'mimepart', 'size', 'mtime',
5251
'storage_mtime', 'encrypted', 'etag', 'permissions', 'checksum', 'metadata_etag', 'creation_time', 'upload_time')
53-
->from('filecache', $name);
54-
if ($mysqlIndexHint !== '' && $this->getConnection()->getDatabasePlatform() instanceof MySQLPlatform) {
55-
$this->add('join', [
56-
$this->quoteAlias($name) => [
57-
// horrible query builder crimes to sneak in raw sql after the "FROM oc_filecache $name"
58-
'joinType' => $mysqlIndexHint . ' left',
59-
'joinTable' => $this->getTableName('filecache_extended'),
60-
'joinAlias' => $this->quoteAlias('fe'),
61-
'joinCondition' => $this->expr()->eq("$name.fileid", 'fe.fileid'),
62-
],
63-
], true);
64-
} else {
65-
$this->leftJoin($name, 'filecache_extended', 'fe', $this->expr()->eq("$name.fileid", 'fe.fileid'));
66-
}
52+
->from('filecache', $name)
53+
->leftJoin($name, 'filecache_extended', 'fe', $this->expr()->eq("$name.fileid", 'fe.fileid'));
6754

6855
$this->alias = $name;
6956

0 commit comments

Comments
 (0)