jdavidbakr / mail-tracker

Package for Laravel to inject tracking code into outgoing emails.
MIT License
577 stars 129 forks source link

"Out of sort memory" when viewing /email-manager #145

Closed ChrisHardie closed 3 years ago

ChrisHardie commented 3 years ago

Hi! Thanks for such a great, well-documented, useful package! Much appreciated.

I recently launched it on my app and everything worked fine for the first day or two, where emails sent and tracked was under 50. However, when we got up above that, my ability to access the admin /email-manager URI started yielding 500 server errors. I found that an exception was being thrown with this error:

SQLSTATE[HY001]: Memory allocation error: 1038 Out of sort memory, consider increasing server sort buffer size (SQL: select * from sent_emails order by created_at desc limit 30 offset 0)

This is on an app that regularly retrieves and sorts much larger result sets than a few hundred records, so I was surprised to see the error. This is just in accessing the index of messages, so I wonder if it's something about select * and including the message body for all of the messages (since it has to fetch them all before limiting to 30 after the sort), when maybe only some subset of the fields are needed? Or maybe it's a matter of a missing index?

Let me know if you have any guidance about troubleshooting this further.

Other environment info:

Thanks!

jdavidbakr commented 3 years ago

That's an interesting issue. I have some pretty large data sets of emails (in the thousands, much more than 50) and have never run into that. Are your emails very large? I wonder if changing the query builder to only select the columns needed for the report would solve it. It could be an index issue, you could try adding an index on the created_at column and see if that fixes it, but I would think it would take a lot more than 50 emails to run out of memory from a bad index. Try adding an index first and see if that solves it.

ChrisHardie commented 3 years ago

Following up to note that I've been successfully accessing the /email-manager view on a regular basis since I made this report, and have not received any more database errors, even as the number of emails available has grown substantially. So I'll chalk the original error up to some sort of transient weirdness. Closing.