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

Use index hints to specify index so Mysql does not select the less pe… #11825

Merged

Conversation

sjeng
Copy link
Contributor

@sjeng sjeng commented Aug 24, 2022

…rformant index.

Description

Mysql is using the wrong index in a subquery for structures table when there are a lot of records. The result is that the overall query gets super slow to complete. This is compounded by the fact that the subquery is used in multiple places in the control panel, and sometimes multiple times in a single request.

The recent entries widget is one place where the query is used and below is an example of load time:
6iiKw (1)

And here is the difference after applying index hint:
image

To be fair, the above example is an extreme one, but I'm seeing improvement in other problematic areas as well (edit pages of complex entries).

The proposed code change should not be very disruptive, and should be very specific to the exist subquery and also only when using MySQL db.

@sjeng sjeng requested a review from a team as a code owner August 24, 2022 15:43
@angrybrad
Copy link
Member

angrybrad commented Aug 24, 2022

@sjeng thanks for that... any chance you could send a database dump and the full SQL query in the screenshot over to [email protected] so we can do some local testing?

@sjeng
Copy link
Contributor Author

sjeng commented Aug 24, 2022

I can do that! I'll package up the db dump and send it over as soon as I'm able.

@sjeng
Copy link
Contributor Author

sjeng commented Aug 25, 2022

I've sent the code and query. Please let me know if you need anymore info.

@brandonkelly brandonkelly merged commit 43c9619 into craftcms:develop Aug 31, 2022
@brandonkelly
Copy link
Member

Merged for the next release!

@sjeng
Copy link
Contributor Author

sjeng commented Sep 1, 2022

That's great news, thank you!

@brandonkelly
Copy link
Member

Craft 4.2.4 is tagged with that change!

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

Successfully merging this pull request may close these issues.

3 participants