MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:eugene Date:June 22 2005 2:00am
Subject:bk commit into 4.1 tree (evgen:1.2306) 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.2306 05/06/22 06:00:13 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.26 05/06/22 05:58:51 evgen@stripped +15 -0
    Test case for bug#9728 Decreased functionality in "on duplicate key update".

  mysql-test/t/insert_select.test
    1.19 05/06/22 05:58:00 evgen@stripped +14 -0
    Test case for bug#9728 Decreased functionality in "on duplicate key update".

  sql/sql_yacc.yy
    1.387 05/06/22 05:57:09 evgen@stripped +5 -0
    Fix bug#9728  decreased functionality in "on duplicate key update"

  sql/sql_parse.cc
    1.446 05/06/22 05:56:48 evgen@stripped +3 -6
    Fix bug#9728  decreased functionality in "on duplicate key update"

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

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

  sql/item.h
    1.183 05/06/22 05:55:39 evgen@stripped +11 -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-22 05:56:27 +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-22 05:55:39 +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-22 05:56:38 +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.445/sql/sql_parse.cc	2005-06-21 23:40:55 +04:00
+++ 1.446/sql/sql_parse.cc	2005-06-22 05:56:48 +04:00
@@ -2856,17 +2856,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)))
     {
@@ -2879,7 +2876,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.386/sql/sql_yacc.yy	2005-06-04 00:45:58 +04:00
+++ 1.387/sql/sql_yacc.yy	2005-06-22 05:57:09 +04:00
@@ -4239,9 +4239,14 @@
 	simple_ident equal expr_or_default
 	{
 	  LEX *lex= Lex;
+          uint8 tmp= MY_ITEM_PREFER_1ST_TABLE;
 	  if (lex->update_list.push_back($1) || 
 	      lex->value_list.push_back($3))
 	    YYABORT;
+          $1->walk(&Item::set_flags_processor,
+                  (byte *) &tmp);
+          $3->walk(&Item::set_flags_processor,
+                  (byte *) &tmp);
 	};
 
 opt_low_priority:

--- 1.25/mysql-test/r/insert_select.result	2005-06-21 22:16:33 +04:00
+++ 1.26/mysql-test/r/insert_select.result	2005-06-22 05:58:51 +04:00
@@ -634,3 +634,18 @@
 1	2
 2	1
 drop table t1, t2;
+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.18/mysql-test/t/insert_select.test	2005-06-21 22:16:26 +04:00
+++ 1.19/mysql-test/t/insert_select.test	2005-06-22 05:58:00 +04:00
@@ -175,3 +175,17 @@
 insert into t2(ff1) select f1 from t1 on duplicate key update ff2=ff2+1;
 select * from t2;
 drop table t1, t2;
+#
+# 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.2306) BUG#8147eugene21 Jun