mirror of
https://github.com/nextcloud/server.git
synced 2025-03-13 07:53:51 +00:00
Merge pull request #32074 from nextcloud/mysql-search-ignore-index-2
tell mysql to ignore the sort index for search queries
This commit is contained in:
commit
f7413b9afc
3 changed files with 13 additions and 2 deletions
lib
private
public/DB/QueryBuilder
|
@ -1113,7 +1113,7 @@ class QueryBuilder implements IQueryBuilder {
|
|||
/**
|
||||
* Adds an ordering to the query results.
|
||||
*
|
||||
* @param string $sort The ordering expression.
|
||||
* @param string|ILiteral|IParameter|IQueryFunction $sort The ordering expression.
|
||||
* @param string $order The ordering direction.
|
||||
*
|
||||
* @return $this This QueryBuilder instance.
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -834,7 +834,7 @@ interface IQueryBuilder {
|
|||
/**
|
||||
* Adds an ordering to the query results.
|
||||
*
|
||||
* @param string $sort The ordering expression.
|
||||
* @param string|ILiteral|IParameter|IQueryFunction $sort The ordering expression.
|
||||
* @param string $order The ordering direction.
|
||||
*
|
||||
* @return $this This QueryBuilder instance.
|
||||
|
|
Loading…
Reference in a new issue