Fix SET STATEMENT ... FOR bug 1635927 and bug 1392375. #1273
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug 1392375 is that repeated execution of SET STATEMENT ... FOR
crashes and bug 1635927 is a memory leak when using per-query variables with subquery temp tables. Both bugs share the root cause which is that SET STATEMENT query variables were set with a sql_set_variables call before main query execution. This function frees subselect joins, if any, at its end, which is premature as they are needed for main query execution. As the subselect lex object is marked as already freed, any subsequent free attempts will be no-ops, resulting in either a memory leak or a crash that the lex already has a join associated. Fix by not freeing subselect joins for SET STATEMENT variable setting part. At the same time add invariant asserts to st_select_lex_unit methods that the object is in cleaned state iff it has no associated joins. http://jenkins.percona.com/job/percona-server-5.6-param/1577/