Bug #86260 | Assert on KILL'ing a stored routine invocation | ||
---|---|---|---|
Submitted: | 10 May 2017 6:47 | Modified: | 17 Jan 2018 17:00 |
Reporter: | Laurynas Biveinis (OCA) | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Stored Routines | Severity: | S2 (Serious) |
Version: | 5.6.36 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | KILL, regression, stored routines |
[10 May 2017 6:47]
Laurynas Biveinis
[10 May 2017 6:48]
Laurynas Biveinis
This appears to be a regression introduced by commit d7b37d4d141a95f577916448650c429f0d6e193d Author: Sreeharsha Ramanavarapu <sreeharsha.ramanavarapu@oracle.com> Date: Wed Feb 22 11:02:07 2017 +0530 Bug #25053286: USE VIEW WITH CONDITION IN PROCEDURE CAUSES INCORRECT BEHAVIOR Issue: ------ This problem occurs when a stored procedure contains a query with a view. While resolving the columns in the WHERE condition, find_field_in_view insists on creating a Item_direct_view_ref object every time an execution happens. This object is not destroyed at the end of the execution. In the next execution, a new object is created and will be appended to the free_list. Hence the size of the free_list is growing and the cleanup phase at the end of each execute takes increasingly longer time. Solution: --------- This is a regression due to the fix for BUG#19897405. Ideally the Item_direct_view_ref object (which is related to the view's column in WHERE clause) should be created at the beginning of every execution and destroyed at the end. This doesn't happen because the check related to the status (STMT_INITIALIZED_FOR_SP / STMT_EXECUTED) had been removed. This check has been re-introduced. Scenario 1 in BUG#19897405: -------------------------- a) SP is executed--> The view fields are resolved/fixed. b) FLUSH TABLE <table-name>. c) SP is executed--> Triggers re-prepare--> Query arena state is not reset and remains as 'STMT_EXECUTED'. Previously created Item_direct_view_ref object is destroyed. The view fields are resolved/fixed using the execution mem_root. It creates a new Item_direct_view_ref object, this is destroyed at the end of the execution. d) SP is executed--> Server crashes while trying to access the resolved view columns allocated on the execution mem_root which was freed after execution(c). Solution to Scenario 1 in BUG#19897405: --------------------------------------- The root cause of the problem mentioned in BUG#19897405 is that when a re-prepare error is raised due to a FLUSH TABLE / DROP TABLE, the state of statement arena should be switched to STMT_INITIALIZED_FOR_SP. Without this, the statement is unaware that previously created Item_direct_view_ref have been destroyed after the table re-open. While it creates a new Item_direct_view_ref object, this is destroyed at the end of the execution. Hence the execution that follows will not have any Item_direct_view_ref to use. The fix here is to set the state to STMT_INITIALIZED_FOR_SP after the re-prepare error is raised. Problem 2 in BUG#19897405: -------------------------- a) SP is executed--> The view fields are resolved/fixed. b) SP is executed--> Gets re-prepare error. Destroys Item_direct_view_ref object. At the end "TABLE EXISTS" error is raised and state is set to EXECUTED c) DROP TABLE <table-created-in-sp> d) SP is executed--> Creates new item_direct_view_ref object. Destroys the object at the end of the statement. d) DROP TABLE <table-created-in-sp> e) SP is executed--> Server crashes while trying to access the resolved view columns allocated on the execution mem_root which was freed after execution. Solution to Scenario 2 in BUG#19897405: --------------------------------------- CREATE TABLE ... SELECT statement in an SP requires some special handling. The state is always set to STMT_INITIALIZED_FOR_SP in such a case.
[10 May 2017 7:11]
Roel Van de Paar
Also see bug 76912
[11 May 2017 5:55]
MySQL Verification Team
Hello Laurynas, Thank you for the report and feedback! Thanks, Umesh
[11 May 2017 5:55]
MySQL Verification Team
test results
Attachment: 86260_5.6.36.results (application/octet-stream, text), 164.25 KiB.
[25 May 2017 9:47]
Laurynas Biveinis
Bug 86260 fix for 5.6 (*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.
Contribution: bug86260-5.6.patch (application/octet-stream, text), 7.07 KiB.
[25 May 2017 9:48]
Laurynas Biveinis
Bug 86260 fix for 5.7 (*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.
Contribution: bug86260-5.7.patch (application/octet-stream, text), 7.09 KiB.
[25 May 2017 9:48]
Laurynas Biveinis
Bug 86260 regression testcase for 8.0.1 (*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.
Contribution: bug86260-8.0.1-testcase.patch (application/octet-stream, text), 2.39 KiB.
[25 May 2017 9:49]
Laurynas Biveinis
Submitted fixes for 5.6 and 5.7. The issue did not reproduce under 8.0.1, I haven't researched why, the 8.0.1 patch contains only the testcase.
[17 Jan 2018 17:00]
Paul DuBois
Posted by developer: Fixed in 5.6.40, 5.7.22, 8.0.5, 9.0.0. For debug builds, using KILL to terminate a stored routine could raise an assertion. Thanks to Laurynas Biveinis for the patch.