Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tell mysql to ignore the sort index for search queries #29300

Closed
wants to merge 2 commits into from

Conversation

icewind1991
Copy link
Member

@icewind1991 icewind1991 commented Oct 18, 2021

Involves some creative query builder usage to sneak the index hint into the query

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>
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>
@icewind1991 icewind1991 added the 2. developing Work in progress label Oct 18, 2021
@icewind1991 icewind1991 marked this pull request as draft October 18, 2021 16:01
@icewind1991 icewind1991 marked this pull request as ready for review October 19, 2021 12:47
@icewind1991 icewind1991 added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Oct 19, 2021
@icewind1991 icewind1991 added this to the Nextcloud 23 milestone Oct 19, 2021
@icewind1991
Copy link
Member Author

/backport to stable22

@skjnldsv skjnldsv requested review from a team, CarlSchwan and come-nc and removed request for a team October 21, 2021 15:57
$this->add('join', [
$this->quoteAlias($name) => [
// horrible query builder crimes to sneak in raw sql after the "FROM oc_filecache $name"
'joinType' => $mysqlIndexHint . ' left',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would be a clean way ? is this something that could be added upstream ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would have to be added upstream (the design of the query builder doesn't really make it possible to overwrite internal parts of it) but upstream is (understandably) hesitant about adding features that only apply on one specific db backend.

While this is certainly not a nice way to do this, it is the best option I'm aware of and doesn't require waiting for upstream releases.

@skjnldsv skjnldsv added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Oct 22, 2021
This was referenced Oct 25, 2021
@blizzz blizzz mentioned this pull request Nov 3, 2021
18 tasks
@skjnldsv skjnldsv mentioned this pull request Nov 8, 2021
23 tasks
@blizzz blizzz modified the milestones: Nextcloud 23, Nextcloud 24 Nov 30, 2021
@skjnldsv
Copy link
Member

Bump? What is the status?

@skjnldsv skjnldsv mentioned this pull request Mar 24, 2022
@blizzz blizzz mentioned this pull request Mar 31, 2022
@icewind1991
Copy link
Member Author

replaced with #32074

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. developing Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants