MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:antony Date:August 5 2005 3:36pm
Subject:bk commit into 4.1 tree (acurtis:1.2371) BUG#10109
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of antony. When antony 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.2371 05/08/05 16:29:40 acurtis@stripped +5 -0
  Bug#10109
    "INSERT .. SELECT ... ON DUPLICATE KEY UPDATE fails"
    Fix by ensureing check_insert_fields() is only called once

  sql/sql_parse.cc
    1.456 05/08/05 16:29:29 acurtis@stripped +2 -1
    constructor has extra args

  sql/sql_insert.cc
    1.171 05/08/05 16:29:29 acurtis@stripped +20 -8
    When doing INSERT..SELECT, we perform column checks inside
    select_insert::prepare instead of mysql_prepare_insert
    avoid calling check_insert_fields() twice!

  sql/sql_class.h
    1.281 05/08/05 16:29:29 acurtis@stripped +11 -3
    Relocated checks require more state data for INSERT..SELECT

  mysql-test/t/insert_update.test
    1.16 05/08/05 16:29:29 acurtis@stripped +14 -0
    Test for bug 10109

  mysql-test/r/insert_update.result
    1.15 05/08/05 16:29:29 acurtis@stripped +6 -0
    Test for bug 10109

# 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: acurtis
# Host: ltantony.
# Root: /usr/home/antony/work2/p2-bug10109.2

--- 1.280/sql/sql_class.h       2005-07-29 03:04:44 +01:00
+++ 1.281/sql/sql_class.h       2005-08-05 16:29:29 +01:00
@@ -1236,19 +1236,27 @@
   List<Item> *fields;
   ulonglong last_insert_id;
   COPY_INFO info;
+  TABLE_LIST *insert_table_list;
+  TABLE_LIST *dup_table_list;

   select_insert(TABLE *table_par, List<Item> *fields_par,
                enum_duplicates duplic, bool ignore)
-    :table(table_par), fields(fields_par), last_insert_id(0)
+    :table(table_par), fields(fields_par), last_insert_id(0),
+     insert_table_list(0), dup_table_list(0)
   {
     bzero((char*) &info,sizeof(info));
     info.ignore= ignore;
     info.handle_duplicates=duplic;
   }
-  select_insert(TABLE *table_par, List<Item> *fields_par,
+  select_insert(TABLE *table_par,
+               TABLE_LIST *insert_table_list_par,
+               TABLE_LIST *dup_table_list_par,
+               List<Item> *fields_par,
                List<Item> *update_fields, List<Item> *update_values,
                enum_duplicates duplic, bool ignore)
-    :table(table_par), fields(fields_par), last_insert_id(0)
+    :table(table_par), fields(fields_par), last_insert_id(0),
+     insert_table_list(insert_table_list_par),
+     dup_table_list(dup_table_list_par)
   {
     bzero((char*) &info,sizeof(info));
     info.ignore= ignore;

--- 1.170/sql/sql_insert.cc     2005-06-28 13:06:12 +01:00
+++ 1.171/sql/sql_insert.cc     2005-08-05 16:29:29 +01:00
@@ -543,13 +543,16 @@
     if (!table->insert_values)
       DBUG_RETURN(-1);
   }
-  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)) ||
-      (duplic == DUP_UPDATE &&
-       (check_update_fields(thd, table, insert_table_list, update_fields) ||
-        setup_fields(thd, 0, dup_table_list, update_values, 1, 0, 0))))
-    DBUG_RETURN(-1);
+  if (values)
+  {
+    if (check_insert_fields(thd, table, fields, *values) ||
+        setup_tables(insert_table_list) ||
+        setup_fields(thd, 0, insert_table_list, *values, 0, 0, 0) ||
+        (duplic == DUP_UPDATE &&
+         (check_update_fields(thd, table, insert_table_list, update_fields) ||
+          setup_fields(thd, 0, dup_table_list, update_values, 1, 0, 0))))
+      DBUG_RETURN(-1);
+  }
   if (values && find_real_table_in_list(table_list->next, table_list->db,
                                         table_list->real_name))
   {
@@ -1601,6 +1604,7 @@
   int res;
   LEX *lex= thd->lex;
   SELECT_LEX *lex_current_select_save= lex->current_select;
+  bool lex_select_no_error= lex->select_lex.no_error;
   DBUG_ENTER("select_insert::prepare");

   unit= u;
@@ -1610,8 +1614,16 @@
     we are fixing fields from insert list.
   */
   lex->current_select= &lex->select_lex;
-  res= check_insert_fields(thd, table, *fields, values);
+  lex->select_lex.no_error= 0;
+  res=
+    check_insert_fields(thd, table, *fields, values) ||
+    setup_tables(insert_table_list) ||
+    setup_fields(thd, 0, insert_table_list, values, 0, 0, 0) ||
+    (info.handle_duplicates == DUP_UPDATE &&
+     (check_update_fields(thd, table, insert_table_list, *info.update_fields) ||
+      setup_fields(thd, 0, dup_table_list, *info.update_values, 1, 0, 0)));
   lex->current_select= lex_current_select_save;
+  lex->select_lex.no_error= lex_select_no_error;
   if (res)
     DBUG_RETURN(1);


--- 1.455/sql/sql_parse.cc      2005-08-02 01:12:27 +01:00
+++ 1.456/sql/sql_parse.cc      2005-08-05 16:29:29 +01:00
@@ -2877,7 +2877,8 @@
                                     lex->field_list, 0,
                                    lex->update_list, lex->value_list,
                                    lex->duplicates)) &&
-        (result= new select_insert(insert_table, &lex->field_list,
+        (result= new select_insert(insert_table, first_local_table,
+                                  &dup_tables, &lex->field_list,
                                   &lex->update_list, &lex->value_list,
                                    lex->duplicates, lex->ignore)))
     {

--- 1.14/mysql-test/r/insert_update.result      2005-06-27 14:46:33 +01:00
+++ 1.15/mysql-test/r/insert_update.result      2005-08-05 16:29:29 +01:00
@@ -191,3 +191,9 @@
 insert ignore into t1 select a from t1 on duplicate key update a=t1.a+1 ;
 ERROR 23000: Column 't1.a' in field list is ambiguous
 drop table t1;
+CREATE TABLE t1 (
+a BIGINT(20) NOT NULL DEFAULT 0,
+PRIMARY KEY  (a)
+) ENGINE=MyISAM;
+INSERT I               TABLE_LIST *insert_table_list_par,
+               TABLE_LIST *dup_table_list_par,
+               List<Item> *fields_par,
                List<Item> *update_fields, List<Item> *update_values,
                enum_duplicates duplic, bool ignore)
-    :table(table_par), fields(fields_par), last_insert_id(0)
+    :table(table_par), fields(fields_par), last_insert_id(0),
+     insert_table_list(insert_table_list_par),
+     dup_table_list(dup_table_list_par)
   {
     bzero((char*) &info,sizeof(info));
     info.ignore= ignore;

--- 1.170/sql/sql_insert.cc     2005-06-28 13:06:12 +01:00
+++ 1.171/sql/sql_insert.cc     2005-08-05 16:29:29 +01:00
@@ -543,13 +543,16 @@
     if (!table->insert_values)
       DBUG_RETURN(-1);
   }
-  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)) ||
-      (duplic == DUP_UPDATE &&
-       (check_update_fields(thd, table, insert_table_list, update_fields) ||
-        setup_fields(thd, 0, dup_table_list, update_values, 1, 0, 0))))
-    DBUG_RETURN(-1);
+  if (values)
+  {
+    if (check_insert_fields(thd, table, fields, *values) ||
+        setup_tables(insert_table_list) ||
+        setup_fields(thd, 0, insert_table_list, *values, 0, 0, 0) ||
+        (duplic == DUP_UPDATE &&
+         (check_update_fields(thd, table, insert_table_list, update_fields) ||
+          setup_fields(thd, 0, dup_table_list, update_values, 1, 0, 0))))
+      DBUG_RETURN(-1);
+  }
   if (values && find_real_table_in_list(table_list->next, table_list->db,
                                         table_list->real_name))
   {
@@ -1601,6 +1604,7 @@
   int res;
   LEX *lex= thd->lex;
   SELECT_LEX *lex_current_select_save= lex->current_select;
+  bool lex_select_no_error= lex->select_lex.no_error;
   DBUG_ENTER("select_insert::prepare");

   unit= u;
@@ -1610,8 +1614,16 @@
     we are fixing fields from insert list.
   */
   lex->current_select= &lex->select_lex;
-  res= check_insert_fields(thd, table, *fields, values);
+  lex->select_lex.no_error= 0;
+  res=
+    check_insert_fields(thd, table, *fields, values) ||
+    setup_tables(insert_table_list) ||
+    setup_fields(thd, 0, insert_table_list, values, 0, 0, 0) ||
+    (info.handle_duplicates == DUP_UPDATE &&
+     (check_update_fields(thd, table, insert_table_list, *info.update_fields) ||
+      setup_fields(thd, 0, dup_table_list, *info.update_values, 1, 0, 0)));
   lex->current_select= lex_current_select_save;
+  lex->select_lex.no_error= lex_select_no_error;
   if (res)
     DBUG_RETURN(1);


--- 1.455/sql/sql_parse.cc      2005-08-02 01:12:27 +01:00
+++ 1.456/sql/sql_parse.cc      2005-08-05 16:29:29 +01:00
@@ -2877,7 +2877,8 @@
                                     lex->field_list, 0,
                                    lex->update_list, lex->value_list,
                                    lex->duplicates)) &&
-        (result= new select_insert(insert_table, &lex->field_list,
+        (result= new select_insert(insert_table, first_local_table,
+                                  &dup_tables, &lex->field_list,
                                   &lex->update_list, &lex->value_list,
                                    lex->duplicates, lex->ignore)))
     {

--- 1.14/mysql-test/r/insert_update.result      2005-06-27 14:46:33 +01:00
+++ 1.15/mysql-test/r/insert_update.result      2005-08-05 16:29:29 +01:00
@@ -191,3 +191,9 @@
 insert ignore into t1 select a from t1 on duplicate key update a=t1.a+1 ;
 ERROR 23000: Column 't1.a' in field list is ambiguous
 drop table t1;
+CREATE TABLE t1 (
+a BIGINT(20) NOT NULL DEFAULT 0,
+PRIMARY KEY  (a)
+) ENGINE=MyISAM;
+INSERT INTO t1 ( a ) SELECT 0 ON DUPLICATE KEY UPDATE a = a + VALUES (a) ;
+DROP TABLE t1;

--- 1.15/mysql-test/t/insert_update.test        2005-07-28 01:21:43 +01:00
+++ 1.16/mysql-test/t/insert_update.test        2005-08-05 16:29:29 +01:00
@@ -101,4 +101,18 @@
 insert ignore into t1 select a from t1 on duplicate key update a=t1.a+1 ;
 drop table t1;

+#
+# Bug#10109 - INSERT .. SELECT ... ON DUPLICATE KEY UPDATE fails
+# Bogus "Duplicate columns" error message
+#
+
+CREATE TABLE t1 (
+  a BIGINT(20) NOT NULL DEFAULT 0,
+  PRIMARY KEY  (a)
+) ENGINE=MyISAM;
+
+INSERT INTO t1 ( a ) SELECT 0 ON DUPLICATE KEY UPDATE a = a + VALUES (a) ;
+
+DROP TABLE t1;
+
 # End of 4.1 tests
Thread
bk commit into 4.1 tree (acurtis:1.2371) BUG#10109antony5 Aug