Bug #31161 | Stored procedures should free prepared statements on exiting | ||
---|---|---|---|
Submitted: | 23 Sep 2007 18:54 | Modified: | 22 Feb 2008 18:22 |
Reporter: | Morgan Tocker | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Documentation | Severity: | S2 (Serious) |
Version: | OS: | Any | |
Assigned to: | Paul DuBois | CPU Architecture: | Any |
Tags: | bfsm_2007_10_18 |
[23 Sep 2007 18:54]
Morgan Tocker
[26 Sep 2007 8:40]
Sveta Smirnova
test case
Attachment: bug31161.test (application/octet-stream, text), 320 bytes.
[26 Sep 2007 8:45]
Sveta Smirnova
Thank you for the report. Verified as described. Even if this is expected, this should be documented in the user manual.
[27 Sep 2007 6:09]
MySQL Verification Team
i tried a test. if i disconnect the client connection, everything is freed. if you re-run the procedure twice in the same connection, it won't continue to use up more statements. this is visible in the Prepared_stmt_count status variable.
[27 Sep 2007 6:12]
MySQL Verification Team
in my tests, calling mysqli_change_user() also freed the statements. but, i found another bug in the status variables. noticed Com_stmt_close decreases sometimes!!! How can that happen?
[18 Oct 2007 10:34]
Konstantin Osipov
This is not a bug. Prepared statements are connection global just like user variables. One can free them after the stored procedure has finished using the same name as used in the stored procedure. In other words, statement names are not local to the stored procedure, they are local to the connection. Out of memory situations can just as well be reached by creating many prepared statements with different names outside stored procedures. The bug with statistics that Shane noticed needs to be reported and verified separately.
[18 Oct 2007 10:35]
Konstantin Osipov
Finally, to limit the possibility of the out of memory attack, there is max_stmt_count global limit.
[18 Oct 2007 10:43]
Konstantin Osipov
It has been suggested by Sveta that this behavior should be clarified in the documentation.
[22 Feb 2008 18:22]
Paul DuBois
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products. Added to SQLPS section: "A prepared statement is specific to the connection in which it was created. If you terminate a client session without deallocating a previously prepared statement, the server deallocates it automatically. A prepared statement is also global to the connection. If you create a prepared statement within a stored routine, it is not deallocated when the stored routine ends. To guard against too many prepared statements being created simultaneously, the max_prepared_stmt_count system variable can be set."