[Commits] a1785bc: Fixed the bug mdev-13346.

IgorBabaev igor at mariadb.com
Wed Aug 16 01:37:10 EEST 2017


revision-id: a1785bc447cf9d267444e1ed0296f603551a7186 (mariadb-10.2.6-92-ga1785bc)
parent(s): 9f0c1c0cf6a24a8613b3327c6f52a7d954e0e18b
author: Igor Babaev
committer: Igor Babaev
timestamp: 2017-08-15 15:37:10 -0700
message:

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.

---
 mysql-test/r/sp.result | 17 +++++++++++++++++
 mysql-test/t/sp.test   | 22 ++++++++++++++++++++++
 sql/sql_select.cc      |  7 ++++++-
 3 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result
index 47adafa..08d69e1 100644
--- a/mysql-test/r/sp.result
+++ b/mysql-test/r/sp.result
@@ -8127,3 +8127,20 @@ v_name	v_total
 c	1
 DROP PROCEDURE p1;
 DROP TABLE t1;
+#
+# MDEV-13346: CURSOR a query with GROUP BY using derived table
+#
+CREATE PROCEDURE p1()
+BEGIN
+DECLARE c CURSOR FOR
+SELECT
+IFNULL(NULL,1) AS col
+FROM
+( select 1 as id ) AS t
+GROUP BY t.id
+;
+OPEN c;
+END
+|
+CALL p1();
+DROP PROCEDURE p1;
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index 3ca210d..eacc8cb 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -9588,3 +9588,25 @@ DELIMITER ;|
 CALL p1();
 DROP PROCEDURE p1;
 DROP TABLE t1;
+
+--echo #
+--echo # MDEV-13346: CURSOR a query with GROUP BY using derived table
+--echo #
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+  DECLARE c CURSOR FOR
+    SELECT
+      IFNULL(NULL,1) AS col
+    FROM
+      ( select 1 as id ) AS t
+    GROUP BY t.id
+  ;
+  OPEN c;
+END
+|
+DELIMITER ;|
+CALL p1();
+DROP PROCEDURE p1;
+
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 6c56f01..711cb7b 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -16497,7 +16497,12 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &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)


More information about the commits mailing list