Commit 6d537f01 authored by unknown's avatar unknown
Browse files

Merge gkodinov@bk-internal.mysql.com:/home/bk/mysql-5.0-opt

into  rakia.gmz:/home/kgeorge/mysql/autopush/B25831-5.0-opt


sql/item.h:
  Auto merged
sql/sql_base.cc:
  Auto merged
sql/sql_insert.cc:
  Auto merged
sql/sql_prepare.cc:
  Auto merged
sql/sql_yacc.yy:
  Auto merged
parents d7992c88 a97fd193
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -219,3 +219,20 @@ SELECT * FROM t1;
a	b
45	2
DROP TABLE t1;
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
INSERT INTO t1 SELECT 1, j;
ERROR 42S22: Unknown column 'j' in 'field list'
DROP TABLE t1;
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
CREATE TABLE t2 (a INT, b INT);
CREATE TABLE t3 (a INT, c INT);
INSERT INTO t1 SELECT 1, a FROM t2 NATURAL JOIN t3 
ON DUPLICATE KEY UPDATE j= a;
DROP TABLE t1,t2,t3;
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
CREATE TABLE t2 (a INT);
INSERT INTO t1 VALUES (1, 1);
INSERT INTO t2 VALUES (1), (3);
INSERT INTO t1 SELECT 1, COUNT(*) FROM t2 ON DUPLICATE KEY UPDATE j= a;
ERROR 42S22: Unknown column 'a' in 'field list'
DROP TABLE t1,t2;
+23 −0
Original line number Diff line number Diff line
@@ -139,3 +139,26 @@ INSERT INTO t1 VALUES (45, 1) ON DUPLICATE KEY UPDATE b =
SELECT * FROM t1;

DROP TABLE t1;

#
# Bug#25831: Deficiencies in INSERT ... SELECT ... field name resolving.
#
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
--error ER_BAD_FIELD_ERROR
INSERT INTO t1 SELECT 1, j;
DROP TABLE t1;

CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
CREATE TABLE t2 (a INT, b INT);
CREATE TABLE t3 (a INT, c INT);
INSERT INTO t1 SELECT 1, a FROM t2 NATURAL JOIN t3 
  ON DUPLICATE KEY UPDATE j= a;
DROP TABLE t1,t2,t3;

CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
CREATE TABLE t2 (a INT);
INSERT INTO t1 VALUES (1, 1);
INSERT INTO t2 VALUES (1), (3);
--error ER_BAD_FIELD_ERROR
INSERT INTO t1 SELECT 1, COUNT(*) FROM t2 ON DUPLICATE KEY UPDATE j= a;
DROP TABLE t1,t2;
+6 −1
Original line number Diff line number Diff line
@@ -325,10 +325,10 @@ class Name_resolution_context_state
  TABLE_LIST *save_first_name_resolution_table;
  TABLE_LIST *save_next_name_resolution_table;
  bool        save_resolve_in_select_list;
  TABLE_LIST *save_next_local;

public:
  Name_resolution_context_state() {}          /* Remove gcc warning */
  TABLE_LIST *save_next_local;

public:
  /* Save the state of a name resolution context. */
@@ -350,6 +350,11 @@ class Name_resolution_context_state
    context->first_name_resolution_table=  save_first_name_resolution_table;
    context->resolve_in_select_list=       save_resolve_in_select_list;
  }

  TABLE_LIST *get_first_name_resolution_table()
  {
    return save_first_name_resolution_table;
  }
};

/*************************************************************************/
+2 −15
Original line number Diff line number Diff line
@@ -4527,21 +4527,8 @@ bool setup_tables(THD *thd, Name_resolution_context *context,
  uint tablenr= 0;
  DBUG_ENTER("setup_tables");

  /*
    Due to the various call paths that lead to setup_tables() it may happen
    that context->table_list and context->first_name_resolution_table can be
    NULL (this is typically done when creating TABLE_LISTs internally).
    TODO:
    Investigate all cases when this my happen, initialize the name resolution
    context correctly in all those places, and remove the context reset below.
  */
  if (!context->table_list || !context->first_name_resolution_table)
  {
    /* Test whether the context is in a consistent state. */
    DBUG_ASSERT(!context->first_name_resolution_table && !context->table_list);
    context->table_list= context->first_name_resolution_table= tables;
  }

  DBUG_ASSERT ((select_insert && !tables->next_name_resolution_table) || !tables || 
               (context->table_list && context->first_name_resolution_table));
  /*
    this is used for INSERT ... SELECT.
    For select we setup tables except first (and its underlying tables)
+2 −0
Original line number Diff line number Diff line
@@ -656,6 +656,8 @@ bool mysqld_help(THD *thd, const char *mask)
    Init tables and fields to be usable from items
    tables do not contain VIEWs => we can pass 0 as conds
  */
  thd->lex->select_lex.context.table_list= 
    thd->lex->select_lex.context.first_name_resolution_table= &tables[0];
  setup_tables(thd, &thd->lex->select_lex.context,
               &thd->lex->select_lex.top_join_list,
               tables, 0, &leaves, FALSE);
Loading