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

Extreme performance issues with large wp_oses_attachments and wp_oses_email_attachments #33

Open
dr-yd opened this issue Nov 24, 2021 · 1 comment

Comments

@dr-yd
Copy link

dr-yd commented Nov 24, 2021

I just opened a new merge request. We had an issue today that caused Offload SES to bring down our database server for almost an hour. Upon investigation, it turned out to be this query:

UPDATE wp_oses_attachments attachments
LEFT JOIN wp_oses_email_attachments email_attachments ON email_attachments.attachment_id = attachments.id
SET attachments.gc = 1
WHERE email_attachments.attachment_id IS NULL;

There are about 42k rows in wp_oses_attachments and about 130k in wp_oses_email_attachments. The slowlog stated Rows_examined: 5719954827.

As the only purpose of this query is to find attachments that are not referenced in wp_oses_email_attachments any more, it can be rewritten as such:

UPDATE wp_oses_attachments attachments
LEFT JOIN (SELECT * FROM wp_oses_email_attachments GROUP BY attachment_id) email_attachments
ON email_attachments.attachment_id = attachments.id
SET attachments.gc = 1
WHERE email_attachments.attachment_id IS NULL

This reduced the runtime of the query to 700ms with no noticeable performance impact.

@dr-yd
Copy link
Author

dr-yd commented Nov 24, 2021

Link to merge request: #32

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

No branches or pull requests

1 participant