List:Internals« Previous MessageNext Message »
From:ingo Date:December 7 2005 6:52pm
Subject:bk commit into 4.1 tree (ingo:1.2485) BUG#5390
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of mydev. When mydev 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.2485 05/12/07 19:52:26 ingo@stripped +9 -0
  BUG#5390 - problems with merge tables
  Problem #1: INSERT...SELECT, Version for 4.1.
  INSERT ... SELECT with the same table on both sides (hidden
  below a MERGE table) does now work by buffering the select result.
  The duplicate detection works now after open_and_lock_tables() 
  on the locks.
  I did not find a test case that failed without the change in
  sql_update.cc. I made the change anyway as it should in theory
  fix a possible MERGE table problem with multi-table update.

  sql/sql_update.cc
    1.149 05/12/07 19:52:19 ingo@stripped +1 -2
    BUG#5390 - problems with merge tables
    Problem #1: INSERT...SELECT, Version for 4.1.
    Changed the duplicate tables detection for UPDATE
    to use the new function, which does also work for MERGE tables.

  sql/sql_parse.cc
    1.473 05/12/07 19:52:18 ingo@stripped +6 -5
    BUG#5390 - problems with merge tables
    Problem #1: INSERT...SELECT, Version for 4.1.
    Changed the duplicate tables detection for INSERT ... SELECT
    to use the new function, which does also work for MERGE tables.

  sql/mysql_priv.h
    1.372 05/12/07 19:52:18 ingo@stripped +1 -0
    BUG#5390 - problems with merge tables
    Problem #1: INSERT...SELECT, Version for 4.1.
    Added a declaration for the new function.

  sql/lock.cc
    1.62 05/12/07 19:52:18 ingo@stripped +86 -3
    BUG#5390 - problems with merge tables
    Problem #1: INSERT...SELECT, Version for 4.1.
    Added a new function to find a duplicate lock in a list of tables.

  mysql-test/t/merge.test
    1.37 05/12/07 19:52:18 ingo@stripped +26 -0
    BUG#5390 - problems with merge tables
    Problem #1: INSERT...SELECT, Version for 4.1.
    Added tests.

  mysql-test/t/create.test
    1.63 05/12/07 19:52:18 ingo@stripped +0 -7
    BUG#5390 - problems with merge tables
    Removed a duplicate test.

  mysql-test/r/merge.result
    1.39 05/12/07 19:52:18 ingo@stripped +49 -0
    BUG#5390 - problems with merge tables
    Problem #1: INSERT...SELECT, Version for 4.1.
    Added test results.

  mysql-test/r/create.result
    1.89 05/12/07 19:52:18 ingo@stripped +0 -15
    BUG#5390 - problems with merge tables
    Removed a duplicate test.

  libmysqld/ha_blackhole.cc
    1.2 05/12/07 19:52:18 ingo@stripped +0 -0
    BUG#5390 - problems with merge tables
    No idea, how the symlink change made it into my patch.

# 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:	ingo
# Host:	chilla.local
# Root:	/home/mydev/mysql-4.1-bug5390

--- 1.61/sql/lock.cc	2005-07-27 12:21:36 +02:00
+++ 1.62/sql/lock.cc	2005-12-07 19:52:18 +01:00
@@ -394,6 +394,88 @@
 }
 
 
+/*
+  Find duplicate lock in tables.
+
+  SYNOPSIS
+    mysql_lock_have_duplicate()
+    thd                         The current thread.
+    table                       The table to check for duplicate lock.
+    tables                      The list of tables to search for the dup lock.
+
+  NOTE
+    This is mainly meant for MERGE tables in INSERT ... SELECT
+    situations. The 'real', underlying tables can be found only after
+    the table is opened. The easier way is to check this after the
+    tables are locked.
+
+  RETURN
+    1           A table from 'tables' matches a lock on 'table'.
+    0           No duplicate lock is present.
+    -1          Error.
+*/
+
+int mysql_lock_have_duplicate(THD *thd, TABLE *table, TABLE_LIST *tables)
+{
+  uint                  count;
+  MYSQL_LOCK            *sql_lock1;
+  MYSQL_LOCK            *sql_lock2;
+  TABLE                 **tables1= &table;
+  TABLE                 **tables2;
+  TABLE                 **table_ptr;
+  TABLE_LIST            *tablist2;
+  TABLE                 *write_lock_used;
+  THR_LOCK_DATA         **lock_data1;
+  THR_LOCK_DATA         **end_data1;
+  THR_LOCK_DATA         **lock_data2;
+  THR_LOCK_DATA         **end_data2;
+  THR_LOCK              *lock1;
+  DBUG_ENTER("mysql_lock_have_duplicate");
+
+  if (! (sql_lock1= get_lock_data(thd, tables1, 1, 1, &write_lock_used)))
+    goto err0;
+
+  count=0;
+  for (tablist2 = tables; tablist2; tablist2= tablist2->next)
+    count++;
+  if (! (tables2= (TABLE**) sql_alloc(sizeof(TABLE*) * count)))
+    goto err1;
+  table_ptr= tables2;
+  for (tablist2 = tables; tablist2; tablist2= tablist2->next)
+    *(table_ptr++)= tablist2->table;
+  if (! (sql_lock2= get_lock_data(thd, tables2, count, 1, &write_lock_used)))
+    goto err1;
+
+  count= 1;
+  for (lock_data1= sql_lock1->locks,
+         end_data1= lock_data1 + sql_lock1->lock_count;
+       lock_data1 < end_data1;
+       lock_data1++)
+  {
+    lock1= (*lock_data1)->lock;
+    for (lock_data2= sql_lock2->locks,
+           end_data2= lock_data2 + sql_lock2->lock_count;
+         lock_data2 < end_data2;
+         lock_data2++)
+    {
+      if ((*lock_data2)->lock == lock1)
+        goto end;
+    }
+  }
+  count= 0;
+
+ end:
+  my_free((gptr) sql_lock2, MYF(0));
+  my_free((gptr) sql_lock1, MYF(0));
+  DBUG_RETURN(count);
+
+ err1:
+  my_free((gptr) sql_lock1, MYF(0));
+ err0:
+  DBUG_RETURN(-1);
+}
+
+
 	/* unlock a set of external */
 
 static int unlock_external(THD *thd, TABLE **table,uint count)
@@ -430,6 +512,7 @@
   MYSQL_LOCK *sql_lock;
   THR_LOCK_DATA **locks;
   TABLE **to;
+  DBUG_ENTER("get_lock_data");
 
   *write_lock_used=0;
   for (i=tables=lock_count=0 ; i < count ; i++)
@@ -445,7 +528,7 @@
 	my_malloc(sizeof(*sql_lock)+
 		  sizeof(THR_LOCK_DATA*)*tables+sizeof(table_ptr)*lock_count,
 		  MYF(0))))
-    return 0;
+    DBUG_RETURN(0);
   locks=sql_lock->locks=(THR_LOCK_DATA**) (sql_lock+1);
   to=sql_lock->table=(TABLE**) (locks+tables);
   sql_lock->table_count=lock_count;
@@ -465,7 +548,7 @@
       {
 	my_error(ER_OPEN_AS_READONLY,MYF(0),table->table_name);
 	my_free((gptr) sql_lock,MYF(0));
-	return 0;
+	DBUG_RETURN(0);
       }
     }
     THR_LOCK_DATA **org_locks = locks;
@@ -475,7 +558,7 @@
       for ( ; org_locks != locks ; org_locks++)
 	(*org_locks)->debug_print_param= (void *) table;
   }
-  return sql_lock;
+  DBUG_RETURN(sql_lock);
 }
 
 

--- 1.371/sql/mysql_priv.h	2005-12-04 14:32:55 +01:00
+++ 1.372/sql/mysql_priv.h	2005-12-07 19:52:18 +01:00
@@ -1022,6 +1022,7 @@
 void mysql_lock_abort(THD *thd, TABLE *table);
 bool mysql_lock_abort_for_thread(THD *thd, TABLE *table);
 MYSQL_LOCK *mysql_lock_merge(MYSQL_LOCK *a,MYSQL_LOCK *b);
+int mysql_lock_have_duplicate(THD *thd, TABLE *table, TABLE_LIST *tables);
 bool lock_global_read_lock(THD *thd);
 void unlock_global_read_lock(THD *thd);
 bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh, bool is_not_commit);

--- 1.472/sql/sql_parse.cc	2005-12-04 14:34:43 +01:00
+++ 1.473/sql/sql_parse.cc	2005-12-07 19:52:18 +01:00
@@ -2897,16 +2897,17 @@
     if (unit->select_limit_cnt < select_lex->select_limit)
       unit->select_limit_cnt= HA_POS_ERROR;		// No limit
 
-    if (find_real_table_in_list(tables->next, tables->db, tables->real_name))
+    if ((res= open_and_lock_tables(thd, tables)))
+      break;
+
+    insert_table= tables->table;
+    /* MERGE sub-tables can only be detected after open. */
+    if (mysql_lock_have_duplicate(thd, insert_table, tables->next))
     {
       /* Using same table for INSERT and SELECT */
       select_lex->options |= OPTION_BUFFER_RESULT;
     }
 
-    if ((res= open_and_lock_tables(thd, tables)))
-      break;
-      
-    insert_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;

--- 1.148/sql/sql_update.cc	2005-12-01 21:19:06 +01:00
+++ 1.149/sql/sql_update.cc	2005-12-07 19:52:19 +01:00
@@ -854,8 +854,7 @@
   {
     TABLE *table=table_ref->table;
     if (!(tables_to_update & table->map) && 
-	find_real_table_in_list(update_tables, table_ref->db,
-				table_ref->real_name))
+	mysql_lock_have_duplicate(thd, table, update_tables))
       table->no_cache= 1;			// Disable row cache
   }
   DBUG_RETURN(thd->is_fatal_error != 0);

--- 1.1/libmysqld/ha_blackhole.cc	2005-12-07 19:52:32 +01:00
+++ 1.2/libmysqld/ha_blackhole.cc	2005-12-07 19:52:32 +01:00
@@ -1 +1 @@
-SYMLINK -> ./../sql/ha_blackhole.cc
+SYMLINK -> ../sql/ha_blackhole.cc

--- 1.88/mysql-test/r/create.result	2005-11-09 07:34:41 +01:00
+++ 1.89/mysql-test/r/create.result	2005-12-07 19:52:18 +01:00
@@ -247,21 +247,6 @@
 0	1	2
 0	0	1
 drop table t1;
-create table t1 select 1,2,3;
-create table if not exists t1 select 1,2;
-Warnings:
-Note	1050	Table 't1' already exists
-create table if not exists t1 select 1,2,3,4;
-ERROR 21S01: Column count doesn't match value count at row 1
-create table if not exists t1 select 1;
-Warnings:
-Note	1050	Table 't1' already exists
-select * from t1;
-1	2	3
-1	2	3
-0	1	2
-0	0	1
-drop table t1;
 create table t1 (a int not null, b int, primary key (a));
 insert into t1 values (1,1);
 create table if not exists t1 select 2;

--- 1.38/mysql-test/r/merge.result	2005-09-29 13:44:12 +02:00
+++ 1.39/mysql-test/r/merge.result	2005-12-07 19:52:18 +01:00
@@ -717,3 +717,52 @@
 b
 3
 DROP TABLE t1, t2;
+create table t1(a int);
+create table t2(a int);
+insert into t1 values (1);
+insert into t2 values (2);
+create table t3 (a int) engine=merge union=(t1, t2) insert_method=first;
+select * from t3;
+a
+1
+2
+insert t2 select * from t2;
+select * from t2;
+a
+2
+2
+insert t3 select * from t1;
+select * from t3;
+a
+1
+1
+2
+2
+insert t1 select * from t3;
+select * from t1;
+a
+1
+1
+1
+1
+2
+2
+select * from t2;
+a
+2
+2
+select * from t3;
+a
+1
+1
+1
+1
+2
+2
+2
+2
+check table t1, t2;
+Table	Op	Msg_type	Msg_text
+test.t1	check	status	OK
+test.t2	check	status	OK
+drop table t1, t2, t3;

--- 1.62/mysql-test/t/create.test	2005-11-09 07:34:41 +01:00
+++ 1.63/mysql-test/t/create.test	2005-12-07 19:52:18 +01:00
@@ -207,13 +207,6 @@
 create table if not exists t1 select 1;
 select * from t1;
 drop table t1;
-create table t1 select 1,2,3;
-create table if not exists t1 select 1,2;
---error 1136
-create table if not exists t1 select 1,2,3,4;
-create table if not exists t1 select 1;
-select * from t1;
-drop table t1;
 
 #
 # Test create table if not exists with duplicate key error

--- 1.36/mysql-test/t/merge.test	2005-09-29 13:43:26 +02:00
+++ 1.37/mysql-test/t/merge.test	2005-12-07 19:52:18 +01:00
@@ -350,4 +350,30 @@
 SELECT b FROM t2;
 DROP TABLE t1, t2;
 
+
+#
+# BUG#5390 - problems with merge tables
+# Problem #1: INSERT...SELECT
+#
+#drop table if exists t1, t2, t3;
+create table t1(a int);
+create table t2(a int);
+insert into t1 values (1);
+insert into t2 values (2);
+create table t3 (a int) engine=merge union=(t1, t2) insert_method=first;
+select * from t3;
+#
+insert t2 select * from t2;
+select * from t2;
+#
+insert t3 select * from t1;
+select * from t3;
+#
+insert t1 select * from t3;
+select * from t1;
+select * from t2;
+select * from t3;
+check table t1, t2;
+drop table t1, t2, t3;
+
 # End of 4.1 tests
Thread
bk commit into 4.1 tree (ingo:1.2485) BUG#5390ingo7 Dec