From a28152aafcab34800652a8be014e7c6d6ddf7da4 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Tue, 15 Aug 2017 15:37:10 -0700 Subject: Fixed the bug mdev-13346. The bug was caused by a defect of the patch for the bug 11081. The patch was actually a port of the fix this bug from the mysql code line. Later a correction of this fix was added to the mysql code. Here's the comment this correction was provided with: Bug#16499751: Opening cursor on SELECT in stored procedure causes segfault This is a regression from the fix of bug#14740889. The fix started using another set of expressions as the source for the temporary table used for the materialized cursor. However, JOIN::make_tmp_tables_info() calls setup_copy_fields() which creates an Item_copy wrapper object on top of the function being selected. The Item_copy objects were not properly handled by create_tmp_table - they were simply ignored. This patch creates temporary table fields based on the underlying item of the Item_copy objects. The test case for the bug 13346 was taken from mdev-13380. --- sql/sql_select.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'sql/sql_select.cc') diff --git a/sql/sql_select.cc b/sql/sql_select.cc index ba3760dd948..ce487205218 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -16572,7 +16572,12 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List &fields, Field **tmp_from_field=from_field; while ((item=li++)) { - Item::Type type=item->type(); + Item::Type type= item->type(); + if (type == Item::COPY_STR_ITEM) + { + item= ((Item_copy *)item)->get_item(); + type= item->type(); + } if (not_all_columns) { if (item->with_sum_func && type != Item::SUM_FUNC_ITEM) -- cgit v1.2.1