MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:eugene Date:June 18 2005 1:03am
Subject:bk commit into 4.1 tree (evgen:1.2300) BUG#8147
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of evgen. When evgen 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
  1.2300 05/06/18 05:03:43 evgen@stripped +7 -0
  Fix bug #9728 decreased functionality in "on duplicate key update"
  
  Remove changes made by bug fix #8147. They strips list of insert_table_list to
  only insert table, which results in error reported in bug #9728.
  Added flag to Item to resolve ambigous fields reported in bug #8147.

  mysql-test/r/insert_select.result
    1.25 05/06/18 05:01:45 evgen@stripped +15 -0
    Test case for bug#9728 Decreased functionality in "on duplicate key update".

  mysql-test/t/insert_select.test
    1.18 05/06/18 05:01:00 evgen@stripped +15 -0
    Test case for bug#9728 Decreased functionality in "on duplicate key update".

  sql/sql_parse.cc
    1.444 05/06/18 05:00:39 evgen@stripped +3 -6
    Fix bug#9728  decreased functionality in "on duplicate key update"

  sql/sql_base.cc
    1.252 05/06/18 04:58:20 evgen@stripped +5 -2
    Fix bug#9728  decreased functionality in "on duplicate key update"

  sql/item.cc
    1.209 05/06/18 04:57:31 evgen@stripped +3 -1
    Fix bug#9728  decreased functionality in "on duplicate key update".

  sql/item.h
    1.183 05/06/18 04:56:59 evgen@stripped +11 -0
    Fix bug#9728  decreased functionality in "on duplicate key update".

  sql/sql_insert.cc
    1.167 05/06/18 04:56:29 evgen@stripped +22 -0
    Fix bug#9728  decreased functionality in "on duplicate key update"

# 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:	evgen
# Host:	moonbone.local
# Root:	/work/mysql-4.1-bug-8147

--- 1.208/sql/item.cc	2005-06-05 21:38:39 +04:00
+++ 1.209/sql/item.cc	2005-06-18 04:57:31 +04:00
@@ -65,6 +65,7 @@
 	place == IN_HAVING)
       thd->lex->current_select->select_n_having_items++;
   }
+  item_flags= 0;
 }
 
 /*
@@ -83,7 +84,8 @@
   unsigned_flag(item->unsigned_flag),
   with_sum_func(item->with_sum_func),
   fixed(item->fixed),
-  collation(item->collation)
+  collation(item->collation),
+  item_flags(item->item_flags)
 {
   next= thd->free_list;				// Put in free list
   thd->free_list= this;

--- 1.182/sql/item.h	2005-06-07 13:58:26 +04:00
+++ 1.183/sql/item.h	2005-06-18 04:56:59 +04:00
@@ -107,6 +107,11 @@
 
 typedef bool (Item::*Item_processor)(byte *arg);
 
+/* 
+  See comments for sql_insert.cc:mysql_prepare_insert()
+*/
+#define MY_ITEM_PREFER_1ST_TABLE 1
+
 class Item {
   Item(const Item &);			/* Prevent use of these */
   void operator=(Item &);
@@ -136,6 +141,7 @@
   Item *next;
   uint32 max_length;
   uint8 marker,decimals;
+  uint8 item_flags;		/* Flags on how item should be processed */
   my_bool maybe_null;			/* If item may be null */
   my_bool null_value;			/* if item is null */
   my_bool unsigned_flag;
@@ -326,6 +332,11 @@
   {
     cleanup();
     delete this;
+  }
+  virtual bool set_flags_processor(byte *args)
+  {
+    this->item_flags|= *((uint8*)args);
+    return true;
   }
 };
 

--- 1.251/sql/sql_base.cc	2005-06-04 09:23:30 +04:00
+++ 1.252/sql/sql_base.cc	2005-06-18 04:58:20 +04:00
@@ -2086,7 +2086,8 @@
     return (Field*) 0;
   }
   bool allow_rowid= tables && !tables->next;	// Only one table
-  for (; tables ; tables=tables->next)
+  uint table_idx= 0;
+  for (; tables ; tables=tables->next, table_idx++)
   {
     if (!tables->table)
     {
@@ -2114,7 +2115,9 @@
 			name,thd->where);
 	return (Field*) 0;
       }
-      found=field;
+      found= field;
+      if (table_idx == 0 && item->item_flags & MY_ITEM_PREFER_1ST_TABLE) 
+        break;
     }
   }
   if (found)

--- 1.166/sql/sql_insert.cc	2005-06-04 09:23:30 +04:00
+++ 1.167/sql/sql_insert.cc	2005-06-18 04:56:29 +04:00
@@ -523,6 +523,28 @@
     if (!table->insert_values)
       DBUG_RETURN(-1);
   }
+  /* 
+    INSERT INTO a1(a) SELECT b1.a FROM b1 ON DUPLICATE KEY UPDATE a= a + b1.b
+    
+    Set MY_ITEM_PREFER_1ST_TABLE flag on all items in update_fields 
+    and update_values to prevent find_field_in_tables() item searching 
+    if it finds item occurence in first table in insert_table_list. 
+    It allows to avoid ambiguity in resolving 'a' field and in example above.
+  */
+  if (duplic == DUP_UPDATE)
+  {
+    List_iterator<Item> itv(update_values);
+    List_iterator<Item> itf(update_fields);
+    reg2 Item *item;
+    uint8 tmp= MY_ITEM_PREFER_1ST_TABLE;
+
+    while((item= itf++))
+        item->walk(&Item::set_flags_processor,
+		   (byte *) &tmp);
+    while((item= itv++))
+        item->walk(&Item::set_flags_processor,
+		   (byte *) &tmp);
+  }
   if ((values && check_insert_fields(thd, table, fields, *values)) ||
       setup_tables(insert_table_list) ||
       (values && setup_fields(thd, 0, insert_table_list, *values, 0, 0, 0)) ||

--- 1.443/sql/sql_parse.cc	2005-06-17 00:11:40 +04:00
+++ 1.444/sql/sql_parse.cc	2005-06-18 05:00:39 +04:00
@@ -2854,17 +2854,14 @@
     if ((res= open_and_lock_tables(thd, tables)))
       break;
       
-    TABLE *table= tables->table;
     /* Skip first table, which is the table we are inserting in */
     select_lex->table_list.first= (byte*) first_local_table->next;
-    tables= (TABLE_LIST *) select_lex->table_list.first;
-    first_local_table->next= 0;
     
     if (!(res= mysql_prepare_insert(thd, tables, first_local_table, 
-				    table, lex->field_list, 0,
+				    tables->table, lex->field_list, 0,
 				    lex->update_list, lex->value_list,
 				    lex->duplicates)) &&
-        (result= new select_insert(table, &lex->field_list,
+        (result= new select_insert(tables->table, &lex->field_list,
 				   &lex->update_list, &lex->value_list,
                                    lex->duplicates, lex->ignore)))
     {
@@ -2877,7 +2874,7 @@
       /* revert changes for SP */
       lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE;
       delete result;
-      table->insert_values= 0;
+      tables->table->insert_values= 0;
       if (thd->net.report_error)
         res= -1;
     }

--- 1.24/mysql-test/r/insert_select.result	2005-03-31 05:32:40 +04:00
+++ 1.25/mysql-test/r/insert_select.result	2005-06-18 05:01:45 +04:00
@@ -625,3 +625,18 @@
 ID	NO	SEQ
 1	1	1
 drop table t1;
+create table t1 (a int unique);
+create table t2 (a int, b int);
+insert into t1 values (1),(2);
+insert into t2 values (1,2);
+select * from t1;
+a
+1
+2
+insert into t1 select t2.a from t2 on duplicate key update a= a + t2.b;
+select * from t1;
+a
+2
+3
+drop table t1;
+drop table t2;

--- 1.17/mysql-test/t/insert_select.test	2005-03-31 05:32:41 +04:00
+++ 1.18/mysql-test/t/insert_select.test	2005-06-18 05:01:00 +04:00
@@ -166,3 +166,18 @@
 select SQL_BUFFER_RESULT * from t1 WHERE (SEQ = 1);
 drop table t1;
 
+#
+# BUGS #9728 - 'Decreased functionality in "on duplicate key update"' 
+#      #8147 - 'a column proclaimed ambigous in INSERT ... SELECT .. ON
+#      DUPLICATE'
+#
+create table t1 (a int unique);
+create table t2 (a int, b int);
+insert into t1 values (1),(2);
+insert into t2 values (1,2);
+select * from t1;
+insert into t1 select t2.a from t2 on duplicate key update a= a + t2.b;
+select * from t1;
+drop table t1;
+drop table t2;
+
Thread
bk commit into 4.1 tree (evgen:1.2300) BUG#8147eugene17 Jun