allow specifying index hints for mysql search queries

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2021-10-18 17:58:04 +02:00
parent efaf112d67
commit 7f272dd98f
No known key found for this signature in database
GPG key ID: 42B69D8A64526EFB
2 changed files with 33 additions and 3 deletions

View file

@ -1301,4 +1301,21 @@ 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;
}
}

View file

@ -26,6 +26,7 @@ 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;
@ -45,12 +46,24 @@ class CacheQueryBuilder extends QueryBuilder {
$this->cache = $cache;
}
public function selectFileCache(string $alias = null) {
public function selectFileCache(string $alias = null, string $mysqlIndexHint = '') {
$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)
->leftJoin($name, 'filecache_extended', 'fe', $this->expr()->eq("$name.fileid", 'fe.fileid'));
->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'));
}
$this->alias = $name;