List:Commits« Previous MessageNext Message »
From:kgeorge Date:October 17 2006 1:37pm
Subject:bk commit into 5.0 tree (gkodinov:1.2304)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of kgeorge. When kgeorge does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2006-10-17 16:36:44+03:00, gkodinov@stripped +7 -0
  Merge bk-internal:/home/bk/mysql-5.0-opt
  into  macbook.gmz:/Users/kgeorge/mysql/work/B21798-5.0-opt-merge
  MERGE: 1.2244.33.1

  mysql-test/r/subselect.result@stripped, 2006-10-17 16:36:36+03:00, gkodinov@stripped +26 -26
    merge fixes for bug 21798
    MERGE: 1.156.1.1

  mysql-test/t/subselect.test@stripped, 2006-10-17 16:36:37+03:00, gkodinov@stripped +26 -26
    merge fixes for bug 21798
    MERGE: 1.126.1.1

  sql/mysql_priv.h@stripped, 2006-10-17 16:27:09+03:00, gkodinov@stripped +0 -0
    Auto merged
    MERGE: 1.406.2.2

  sql/sql_delete.cc@stripped, 2006-10-17 16:27:09+03:00, gkodinov@stripped +0 -0
    Auto merged
    MERGE: 1.178.1.1

  sql/sql_select.cc@stripped, 2006-10-17 16:27:10+03:00, gkodinov@stripped +0 -0
    Auto merged
    MERGE: 1.447.4.1

  sql/sql_table.cc@stripped, 2006-10-17 16:27:11+03:00, gkodinov@stripped +0 -0
    Auto merged
    MERGE: 1.320.1.1

  sql/sql_update.cc@stripped, 2006-10-17 16:27:12+03:00, gkodinov@stripped +0 -0
    Auto merged
    MERGE: 1.196.1.1

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	gkodinov
# Host:	macbook.gmz
# Root:	/Users/kgeorge/mysql/work/B21798-5.0-opt-merge/RESYNC

--- 1.413/sql/mysql_priv.h	2006-10-17 16:37:01 +03:00
+++ 1.414/sql/mysql_priv.h	2006-10-17 16:37:01 +03:00
@@ -714,7 +714,8 @@ bool mysql_xa_recover(THD *thd);
 
 bool check_simple_select();
 
-SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length);
+SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length,
+                                  SORT_FIELD *sortorder);
 int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
 		List<Item> &fields, List <Item> &all_fields, ORDER *order);
 int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,

--- 1.179/sql/sql_delete.cc	2006-10-17 16:37:01 +03:00
+++ 1.180/sql/sql_delete.cc	2006-10-17 16:37:01 +03:00
@@ -167,7 +167,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *
                                                    MYF(MY_FAE | MY_ZEROFILL));
     
       if (!(sortorder= make_unireg_sortorder((ORDER*) order->first,
-                                             &length)) ||
+                                             &length, NULL)) ||
 	  (table->sort.found_records = filesort(thd, table, sortorder, length,
                                                 select, HA_POS_ERROR,
                                                 &examined_rows))

--- 1.460/sql/sql_select.cc	2006-10-17 16:37:01 +03:00
+++ 1.461/sql/sql_select.cc	2006-10-17 16:37:01 +03:00
@@ -1575,6 +1575,7 @@ JOIN::exec()
 	{
 	  DBUG_VOID_RETURN;
 	}
+        sortorder= curr_join->sortorder;
       }
       
       thd->proc_info="Copying to group table";
@@ -1784,6 +1785,7 @@ JOIN::exec()
 			    (select_options & OPTION_FOUND_ROWS ?
 			     HA_POS_ERROR : unit->select_limit_cnt)))
 	DBUG_VOID_RETURN;
+      sortorder= curr_join->sortorder;
     }
   }
   /* XXX: When can we have here thd->net.report_error not zero? */
@@ -4950,9 +4952,28 @@ make_simple_join(JOIN *join,TABLE *tmp_t
   JOIN_TAB *join_tab;
   DBUG_ENTER("make_simple_join");
 
-  if (!(tableptr=(TABLE**) join->thd->alloc(sizeof(TABLE*))) ||
-      !(join_tab=(JOIN_TAB*) join->thd->alloc(sizeof(JOIN_TAB))))
-    DBUG_RETURN(TRUE);
+  /*
+    Reuse TABLE * and JOIN_TAB if already allocated by a previous call
+    to this function through JOIN::exec (may happen for sub-queries).
+  */
+  if (!join->table_cache)
+  {
+    if (!(join->table_cache= (TABLE**) join->thd->alloc(sizeof(TABLE*))))
+      DBUG_RETURN(TRUE);                        /* purecov: inspected */
+    if (join->tmp_join)
+      join->tmp_join->table_cache= join->table_cache;
+  }
+  if (!join->join_tab_cache)
+  {
+    if (!(join->join_tab_cache=
+          (JOIN_TAB*) join->thd->alloc(sizeof(JOIN_TAB))))
+      DBUG_RETURN(TRUE);                        /* purecov: inspected */
+    if (join->tmp_join)
+      join->tmp_join->join_tab_cache= join->join_tab_cache;
+  }
+  tableptr= join->table_cache;
+  join_tab= join->join_tab_cache;
+
   join->join_tab=join_tab;
   join->table=tableptr; tableptr[0]=tmp_table;
   join->tables=1;
@@ -11982,7 +12003,6 @@ static int
 create_sort_index(THD *thd, JOIN *join, ORDER *order,
 		  ha_rows filesort_limit, ha_rows select_limit)
 {
-  SORT_FIELD *sortorder;
   uint length;
   ha_rows examined_rows;
   TABLE *table;
@@ -12004,7 +12024,8 @@ create_sort_index(THD *thd, JOIN *join, 
        !(join->select_options & SELECT_BIG_RESULT)) &&
       test_if_skip_sort_order(tab,order,select_limit,0))
     DBUG_RETURN(0);
-  if (!(sortorder=make_unireg_sortorder(order,&length)))
+  if (!(join->sortorder= 
+        make_unireg_sortorder(order,&length,join->sortorder)))
     goto err;				/* purecov: inspected */
 
   table->sort.io_cache=(IO_CACHE*) my_malloc(sizeof(IO_CACHE),
@@ -12051,7 +12072,7 @@ create_sort_index(THD *thd, JOIN *join, 
 
   if (table->s->tmp_table)
     table->file->info(HA_STATUS_VARIABLE);	// Get record count
-  table->sort.found_records=filesort(thd, table,sortorder, length,
+  table->sort.found_records=filesort(thd, table,join->sortorder, length,
                                      select, filesort_limit, &examined_rows);
   tab->records= table->sort.found_records;	// For SQL_CALC_ROWS
   if (select)
@@ -12398,7 +12419,8 @@ err:
 }
 
 
-SORT_FIELD *make_unireg_sortorder(ORDER *order, uint *length)
+SORT_FIELD *make_unireg_sortorder(ORDER *order, uint *length,
+                                  SORT_FIELD *sortorder)
 {
   uint count;
   SORT_FIELD *sort,*pos;
@@ -12407,7 +12429,9 @@ SORT_FIELD *make_unireg_sortorder(ORDER 
   count=0;
   for (ORDER *tmp = order; tmp; tmp=tmp->next)
     count++;
-  pos=sort=(SORT_FIELD*) sql_alloc(sizeof(SORT_FIELD)*(count+1));
+  if (!sortorder)
+    sortorder= (SORT_FIELD*) sql_alloc(sizeof(SORT_FIELD)*(count+1));
+  pos=sort=sortorder;
   if (!pos)
     return 0;
 

--- 1.322/sql/sql_table.cc	2006-10-17 16:37:01 +03:00
+++ 1.323/sql/sql_table.cc	2006-10-17 16:37:01 +03:00
@@ -4095,7 +4095,7 @@ copy_data_between_tables(TABLE *from,TAB
     if (thd->lex->select_lex.setup_ref_array(thd, order_num) ||
 	setup_order(thd, thd->lex->select_lex.ref_pointer_array,
 		    &tables, fields, all_fields, order) ||
-	!(sortorder=make_unireg_sortorder(order, &length)) ||
+	!(sortorder=make_unireg_sortorder(order, &length, NULL)) ||
 	(from->sort.found_records = filesort(thd, from, sortorder, length,
 					     (SQL_SELECT *) 0, HA_POS_ERROR,
 					     &examined_rows)) ==

--- 1.197/sql/sql_update.cc	2006-10-17 16:37:01 +03:00
+++ 1.198/sql/sql_update.cc	2006-10-17 16:37:01 +03:00
@@ -311,7 +311,7 @@ int mysql_update(THD *thd,
 
       table->sort.io_cache = (IO_CACHE *) my_malloc(sizeof(IO_CACHE),
 						    MYF(MY_FAE | MY_ZEROFILL));
-      if (!(sortorder=make_unireg_sortorder(order, &length)) ||
+      if (!(sortorder=make_unireg_sortorder(order, &length, NULL)) ||
           (table->sort.found_records = filesort(thd, table, sortorder, length,
 						select, limit,
 						&examined_rows))

--- 1.162/mysql-test/r/subselect.result	2006-10-17 16:37:02 +03:00
+++ 1.163/mysql-test/r/subselect.result	2006-10-17 16:37:02 +03:00
@@ -3458,6 +3458,32 @@ id	select_type	table	type	possible_keys	
 4	UNION	t12	system	NULL	NULL	NULL	NULL	0	const row not found
 NULL	UNION RESULT	<union2,4>	ALL	NULL	NULL	NULL	NULL	NULL	
 DROP TABLE t1;
+CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
+insert into t1 (a) values (FLOOR(rand() * 100));
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+SELECT a, 
+(SELECT REPEAT(' ',250) FROM t1 i1 
+WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a 
+FROM t1 ORDER BY a LIMIT 5;
+a	a
+0	NULL
+0	NULL
+0	NULL
+0	NULL
+0	NULL
+DROP TABLE t1;
 CREATE TABLE t1 (a INT, b INT);
 CREATE TABLE t2 (a INT);
 INSERT INTO t2 values (1);

--- 1.129/mysql-test/t/subselect.test	2006-10-17 16:37:02 +03:00
+++ 1.130/mysql-test/t/subselect.test	2006-10-17 16:37:02 +03:00
@@ -2371,6 +2371,32 @@ explain select * from t1 where not exist
 DROP TABLE t1;
 
 #
+# Bug#21798: memory leak during query execution with subquery in column 
+#             list using a function
+#
+CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
+insert into t1 (a) values (FLOOR(rand() * 100));
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+
+SELECT a, 
+       (SELECT REPEAT(' ',250) FROM t1 i1 
+        WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a 
+FROM t1 ORDER BY a LIMIT 5;
+DROP TABLE t1;
+
+#
 # Bug #21540: Subqueries with no from and aggregate functions return 
 #              wrong results
 CREATE TABLE t1 (a INT, b INT);
Thread
bk commit into 5.0 tree (gkodinov:1.2304)kgeorge17 Oct