From: Alexander Nozdrin Date: May 6 2011 11:41am Subject: bzr commit into mysql-5.5 branch (alexander.nozdrin:3497) Bug#11848763 List-Archive: http://lists.mysql.com/commits/136822 X-Bug: 11848763 Message-Id: <201105061141.p46BfTeN013715@acsmt356.oracle.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2320692378161704023==" --===============2320692378161704023== MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline #At file:///home/alik/MySQL/bzr/00/bug60025/mysql-5.5-bug60025/ based on revid:alexander.nozdrin@stripped 3497 Alexander Nozdrin 2011-05-06 Patch for Bug#11848763 / 60025 (SUBSTRING inside a stored function works too slow). The user-visible problem was that the server started to consume memory if a stored-routine of some sort is executed subsequently. The memory was freed only after the corresponding connection was closed. Technically, the problem was that the memory needed for temporary string conversions was allocated on the connection ("persistent") memory root, instead of statement one. The root cause of this problem was the incorrect patch for Bug 55744. That patch wrongly fixed a crash in prepared-statement-mode introduced by another patch. The patch for Bug 55744 used wrong condition to check if prepared statement mode is active (or whether the connection-scoped or statement-scoped memory root should be used). The thing is that for prepared statements such conversions should be done in the connection memory root, so that that the transformations of item-tree were correctly remembered in the PREPARE-phase. The fix is to use proper condition to detect prepared-statement-mode and use proper memory root. modified: sql/item.cc === modified file 'sql/item.cc' --- a/sql/item.cc 2011-05-06 11:39:40 +0000 +++ b/sql/item.cc 2011-05-06 11:41:24 +0000 @@ -1781,14 +1781,17 @@ bool agg_item_set_converter(DTCollation } THD *thd= current_thd; - Query_arena *arena, backup; bool res= FALSE; uint i; + /* In case we're in statement prepare, create conversion item in its memory: it will be reused on each execute. */ - arena= thd->activate_stmt_arena_if_needed(&backup); + Query_arena backup; + Query_arena *arena= thd->stmt_arena->is_stmt_prepare() ? + thd->activate_stmt_arena_if_needed(&backup) : + NULL; for (i= 0, arg= args; i < nargs; i++, arg+= item_sep) { --===============2320692378161704023== MIME-Version: 1.0 Content-Type: text/bzr-bundle; charset="us-ascii"; name="bzr/alexander.nozdrin@stripped" Content-Transfer-Encoding: 7bit Content-Disposition: inline # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: alexander.nozdrin@stripped\ # 6mok97aefu631kpr # target_branch: file:///home/alik/MySQL/bzr/00/bug60025/mysql-5.5-\ # bug60025/ # testament_sha1: 3213d56a231db77924c6dd4d5a0700d1d3d28a88 # timestamp: 2011-05-06 15:41:28 +0400 # source_branch: file:///home/alik/MySQL/bzr/00/bug60025/mysql-5.5/ # base_revision_id: alexander.nozdrin@stripped\ # vi12q2mulw2cr768 # # Begin bundle IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWQAYFEUAAgn/gAAQEABZd/// 8qV+AL/v//BQBeZjyA3dL172drLZ07dteGmpGmTVPJin6SHiagGmgAek9R6jT0nqaBKIE0xABMjU FNMNNAg8kZGGpkEqehCJqbI1MEm9IgaaDRiNBtQyAEihT0Gk0ap+qb1NNR6nonqeoGTEDExGIYSR CCYmQNKe1Q9o1T0mZIaaGgNADNIBNZDUrDYPngr0cjYa5QpVMmYpuIsKXkCSjRA62yKGjXfTLQq5 dQAaA2K+Kiy+gkgM+E2wxl5DzBHSxecdLWRWbrlxhoxN0tmuPHam2RLVzTxuqMo4MWO1EW2Ulb94 o7u0Kh2Irm/ueCmi968t2eKpTVKRA6xcoiYqgmvu65vrk1cK2VvkMrUl7qJAc6ilKQksB1ezBrqf VHTdHL3N7OvnV0vxGqHepsziy39Gnm+0N/xGFDTA0EPubCVcL6eVfApz8YNfRqT6HMN3cjsujRtV r5JUiFJIhiWVSjtkBypB+86yEbBjeIZxjsYRC1IneESbVQhyKobUZlBiZsPCJ6mJxF2BTlIQ9Yju eVgrpr5SkE2h0KcI0R9p22aNuzMkTvr79v4GllK7KNJib0cayEMmt2oJiuuK12l7wpf5gxPIHhvd YraGPk8TnAcY0WIcWjDcgN58m5wWUa5iK1oMegZmkcB0asORePJ60aPIsz6hRsumFBCp6/9nOOQ0 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