-
-
Notifications
You must be signed in to change notification settings - Fork 625
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
Prepared statements via .execute() being cached indefinitely #393
Comments
I'm completely in favour about adding more documentation about prepared statement lifecycle on server and client The reason I have not yet added auto-closing of unused statements is that often people misuse them in a Another complexity is that statement I think it would be good to have LRU instead of letting them live until connection is closed, with expiration based on LRU size, not max idle time (e.i if limit is 100 when stmt 101 is prepared the first one from cache is closed). Note that due to the way commands are queued in the connection the state of the queue would look like "prepare stmt 101, execute stmt 101, close stmt 1" after |
As of today we don't, we've now changed all those queries over to using An LRU sounds like a good plan. That would at least save others from making the same mistake we did. |
Executing and unpreparing is probably slower than doing
if permission allow you can do something like this:
|
@ChiperSoft LRU cache for statements landed in master and going to be published as 1.1.0 soon |
Awesome, thanks! |
We ran into a problem this morning where we suddenly started getting a whole lot of
Can't create more than max_prepared_stmt_count statements
errors from our service. After some digging we came to discover that mysql2's .execute() function doesn't ever close the statements that it prepares. They get stored on the open connection's statement cache and never get purged unless the connection closes.We have been running all queries through .execute(), including those with dynamic ranges of arguments, so we hit our DB's max max_prepared_stmt_count limit fairly quickly.
We're now making changes to our code to limit when we use .execute(), but it would be nice to have a setting to expire cached queries after a set amount of time.
Additionally, the documentation could be clearer about the implications of using .execute() vs preparing the statements yourself.
The text was updated successfully, but these errors were encountered: