List:Commits« Previous MessageNext Message »
From:Sergey Glukhov Date:July 3 2009 8:35am
Subject:bzr commit into mysql-5.0-bugteam branch (Sergey.Glukhov:2792)
Bug#45806
View as plain text  
#At file:///home/gluh/MySQL/mysql-5.0-bugteam/ based on revid:bernt.johnsen@stripped

 2792 Sergey Glukhov	2009-07-03
      Bug#45806 crash when replacing into a view with a join!
      The crash happend because for views which are joins
      we have table_list->table == 0 and 
      table_list->table->'any method' call leads to crash.
      The fix is to perform table_list->table->file->extra()
      method for all tables belonging to view.
     @ mysql-test/r/view.result
        test result
     @ mysql-test/t/view.test
        test case
     @ sql/sql_insert.cc
        added prepare_for_positional_update() function
        which updates extra info about primary key for
        tables belonging to view.

    modified:
      mysql-test/r/view.result
      mysql-test/t/view.test
      sql/sql_insert.cc
=== modified file 'mysql-test/r/view.result'
--- a/mysql-test/r/view.result	2009-05-18 18:43:06 +0000
+++ b/mysql-test/r/view.result	2009-07-03 08:35:00 +0000
@@ -3723,6 +3723,117 @@ DROP TABLE t1;
 
 # -- End of test case for Bug#40825
 
+# 
+# Bug #45806 crash when replacing into a view with a join!
+# 
+CREATE TABLE t1(a INT UNIQUE);
+CREATE VIEW v1 AS SELECT t1.a FROM t1, t1 AS a;
+INSERT INTO t1 VALUES (1), (2);
+REPLACE INTO v1(a) SELECT 1 FROM t1,t1 AS c;
+SELECT * FROM v1;
+a
+1
+2
+1
+2
+REPLACE INTO v1(a) SELECT 3 FROM t1,t1 AS c;
+SELECT * FROM v1;
+a
+1
+2
+3
+1
+2
+3
+1
+2
+3
+DELETE FROM t1 WHERE a=3;
+INSERT INTO v1(a) SELECT 1 FROM t1,t1 AS c
+ON DUPLICATE KEY UPDATE `v1`.`a`= 1;
+SELECT * FROM v1;
+a
+1
+2
+1
+2
+CREATE VIEW v2 AS SELECT t1.a FROM t1, v1 AS a;
+REPLACE INTO v2(a) SELECT 1 FROM t1,t1 AS c;
+SELECT * FROM v2;
+a
+1
+2
+1
+2
+1
+2
+1
+2
+REPLACE INTO v2(a) SELECT 3 FROM t1,t1 AS c;
+SELECT * FROM v2;
+a
+1
+2
+3
+1
+2
+3
+1
+2
+3
+1
+2
+3
+1
+2
+3
+1
+2
+3
+1
+2
+3
+1
+2
+3
+1
+2
+3
+INSERT INTO v2(a) SELECT 1 FROM t1,t1 AS c
+ON DUPLICATE KEY UPDATE `v2`.`a`= 1;
+SELECT * FROM v2;
+a
+1
+2
+3
+1
+2
+3
+1
+2
+3
+1
+2
+3
+1
+2
+3
+1
+2
+3
+1
+2
+3
+1
+2
+3
+1
+2
+3
+DROP VIEW v1;
+DROP VIEW v2;
+DROP TABLE t1;
+# -- End of test case for Bug#45806
 # -----------------------------------------------------------------
 # -- End of 5.0 tests.
 # -----------------------------------------------------------------

=== modified file 'mysql-test/t/view.test'
--- a/mysql-test/t/view.test	2009-05-18 18:43:06 +0000
+++ b/mysql-test/t/view.test	2009-07-03 08:35:00 +0000
@@ -3703,6 +3703,38 @@ DROP TABLE t1;
 --echo # -- End of test case for Bug#40825
 --echo
 
+--echo # 
+--echo # Bug #45806 crash when replacing into a view with a join!
+--echo # 
+CREATE TABLE t1(a INT UNIQUE);
+CREATE VIEW v1 AS SELECT t1.a FROM t1, t1 AS a;
+INSERT INTO t1 VALUES (1), (2);
+
+REPLACE INTO v1(a) SELECT 1 FROM t1,t1 AS c;
+SELECT * FROM v1;
+REPLACE INTO v1(a) SELECT 3 FROM t1,t1 AS c;
+SELECT * FROM v1;
+DELETE FROM t1 WHERE a=3;
+INSERT INTO v1(a) SELECT 1 FROM t1,t1 AS c
+ON DUPLICATE KEY UPDATE `v1`.`a`= 1;
+SELECT * FROM v1;
+
+CREATE VIEW v2 AS SELECT t1.a FROM t1, v1 AS a;
+
+REPLACE INTO v2(a) SELECT 1 FROM t1,t1 AS c;
+SELECT * FROM v2;
+REPLACE INTO v2(a) SELECT 3 FROM t1,t1 AS c;
+SELECT * FROM v2;
+INSERT INTO v2(a) SELECT 1 FROM t1,t1 AS c
+ON DUPLICATE KEY UPDATE `v2`.`a`= 1;
+SELECT * FROM v2;
+
+DROP VIEW v1;
+DROP VIEW v2;
+DROP TABLE t1;
+
+--echo # -- End of test case for Bug#45806
+
 --echo # -----------------------------------------------------------------
 --echo # -- End of 5.0 tests.
 --echo # -----------------------------------------------------------------

=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc	2009-06-17 13:54:01 +0000
+++ b/sql/sql_insert.cc	2009-07-03 08:35:00 +0000
@@ -1149,6 +1149,33 @@ static bool mysql_prepare_insert_check_t
 
 
 /*
+  Get extra info for tables we insert into
+
+  @param table     table(TABLE object) we insert into,
+                   might be NULL in case of view
+  @param           table(TABLE_LIST object) or view we insert into
+*/
+
+static void prepare_for_positional_update(TABLE *table, TABLE_LIST *tables)
+{
+  if (table)
+  {
+    if(table->reginfo.lock_type != TL_WRITE_DELAYED)
+      table->file->extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY);
+    return;
+  }
+
+  DBUG_ASSERT(tables->view);
+  List_iterator<TABLE_LIST> it(*tables->view_tables);
+  TABLE_LIST *tbl;
+  while ((tbl= it++))
+    prepare_for_positional_update(tbl->table, tbl);
+
+  return;
+}
+
+
+/*
   Prepare items in INSERT statement
 
   SYNOPSIS
@@ -1298,9 +1325,8 @@ bool mysql_prepare_insert(THD *thd, TABL
     Only call extra() handler method if we are not performing a DELAYED
     operation. It will instead be executed by delayed insert thread.
   */
-  if ((duplic == DUP_UPDATE || duplic == DUP_REPLACE) &&
-      (table->reginfo.lock_type != TL_WRITE_DELAYED))
-    table->file->extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY);
+  if (duplic == DUP_UPDATE || duplic == DUP_REPLACE)
+    prepare_for_positional_update(table, table_list);
   DBUG_RETURN(FALSE);
 }
 


Attachment: [text/bzr-bundle] bzr/sergey.glukhov@sun.com-20090703083500-jq8vhw0tqr37j7te.bundle
Thread
bzr commit into mysql-5.0-bugteam branch (Sergey.Glukhov:2792)Bug#45806Sergey Glukhov3 Jul