From 784445a4ef39d0a2d6be6f1cd67986af6dd3f667 Mon Sep 17 00:00:00 2001
From: "heikki@hundin.mysql.fi" <>
Date: Thu, 7 Oct 2004 16:08:15 +0300
Subject: [PATCH 1/4] ha_innodb.cc:   Merge manually the InnoDB mysqldump -l
 crash patch (crash with LOCK TABLES ... LOCAL) from 4.0 to 4.1; some code
 cleanup

---
 sql/ha_innodb.cc | 88 +++++++++++++++++++++++++++---------------------
 1 file changed, 49 insertions(+), 39 deletions(-)

diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index 8ddf00a7568..cb35c63357e 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -20,10 +20,6 @@ NOTE: You can only use noninlined InnoDB functions in this file, because we
 have disables the InnoDB inlining in this file. */
 
 /* TODO list for the InnoDB handler in 4.1:
-  - Check if the query_id is now right also in prepared and executed stats
-    in build_template()
-  - Add multi-language char set support to CREATE TABLE and the comparison
-    of strings
   - Find out what kind of problems the OS X case-insensitivity causes to
     table and database names; should we 'normalize' the names like we do
     in Windows?
@@ -2130,11 +2126,6 @@ build_template(
 		templ = prebuilt->mysql_template + n_requested_fields;
 		field = table->field[i];
 
-		/* TODO: Check if the query_id is now right also in prepared
-		and executed SQL statements. Previously, MySQL-4.1 failed to
-		update field->query_id so that the formula
-		thd->query_id == field->query_id did not work. */
-
 		if (templ_type == ROW_MYSQL_REC_FIELDS
 		    && !(fetch_all_in_key
 			 && dict_index_contains_col_or_prefix(index, i))
@@ -4727,23 +4718,41 @@ ha_innobase::start_stmt(
 	        prepared for an update of a row */
 	  
 	        prebuilt->select_lock_type = LOCK_X;
-        } else {
-                if (thd->lex->sql_command == SQLCOM_SELECT
-                                        && thd->lex->lock_option == TL_READ) {
- 
-                        /* For other than temporary tables, we obtain
-                        no lock for consistent read (plain SELECT) */
- 
-                        prebuilt->select_lock_type = LOCK_NONE;
-                } else {
-                        /* Not a consistent read: use LOCK_X as the
-                        select_lock_type value (TODO: how could we know
-                        whether it should be LOCK_S, LOCK_X, or LOCK_NONE?) */
-
-                        prebuilt->select_lock_type = LOCK_X;
-                }
-        }
+	} else {
+		if (trx->isolation_level != TRX_ISO_SERIALIZABLE
+		    && thd->lex->sql_command == SQLCOM_SELECT
+		    && thd->lex->lock_option == TL_READ) {
 	
+			/* For other than temporary tables, we obtain
+			no lock for consistent read (plain SELECT). */
+
+			prebuilt->select_lock_type = LOCK_NONE;
+		} else {
+			/* Not a consistent read: restore the
+			select_lock_type value. The value of
+			stored_select_lock_type was decided in:
+			1) ::store_lock(),
+			2) ::external_lock(), and
+			3) ::init_table_handle_for_HANDLER(). */
+
+			prebuilt->select_lock_type =
+				prebuilt->stored_select_lock_type;
+		}
+
+		if (prebuilt->stored_select_lock_type != LOCK_S
+		    && prebuilt->stored_select_lock_type != LOCK_X) {
+			fprintf(stderr,
+"InnoDB: Error: stored_select_lock_type is %lu inside ::start_stmt()!\n",
+			prebuilt->stored_select_lock_type);
+
+			/* Set the value to LOCK_X: this is just fault
+			tolerance, we do not know what the correct value
+			should be! */
+
+			prebuilt->select_lock_type = LOCK_X;
+		}
+	}
+
 	/* Set the MySQL flag to mark that there is an active transaction */
 	thd->transaction.all.innodb_active_trans = 1;
 
@@ -5258,14 +5267,14 @@ ha_innobase::get_auto_increment()
 }
 
 /***********************************************************************
-This function stores binlog offset and flushes logs */
+This function stores the binlog offset and flushes logs. */
 
 void 
 innobase_store_binlog_offset_and_flush_log(
-/*=============================*/
-    char *binlog_name,          /* in: binlog name */
-    longlong offset             /* in: binlog offset */
-) {
+/*=======================================*/
+    char 	*binlog_name,	/* in: binlog name */
+    longlong 	offset)		/* in: binlog offset */
+{
 	mtr_t mtr;
 	
 	assert(binlog_name != NULL);
@@ -5274,7 +5283,7 @@ innobase_store_binlog_offset_and_flush_log(
         mtr_start_noninline(&mtr); 
 
 	/* Update the latest MySQL binlog name and offset info
-           in trx sys header */
+        in trx sys header */
 
         trx_sys_update_mysql_binlog_offset(
             binlog_name,
@@ -5288,18 +5297,19 @@ innobase_store_binlog_offset_and_flush_log(
 	log_buffer_flush_to_disk();
 }
 
-char *ha_innobase::get_mysql_bin_log_name()
+char*
+ha_innobase::get_mysql_bin_log_name()
 {
-  return trx_sys_mysql_bin_log_name;
+	return(trx_sys_mysql_bin_log_name);
 }
 
-ulonglong ha_innobase::get_mysql_bin_log_pos()
+ulonglong
+ha_innobase::get_mysql_bin_log_pos()
 {
-  /*
-    trx... is ib_longlong, which is a typedef for a 64-bit integer (__int64 or
-    longlong) so it's ok to cast it to ulonglong.
-  */
-  return trx_sys_mysql_bin_log_pos;
+  	/* trx... is ib_longlong, which is a typedef for a 64-bit integer
+	(__int64 or longlong) so it's ok to cast it to ulonglong. */
+
+  	return(trx_sys_mysql_bin_log_pos);
 }
 
 extern "C" {

From 9035aab33cea3e3353f39a28550116e04aea07be Mon Sep 17 00:00:00 2001
From: "tomas@poseidon.ndb.mysql.com" <>
Date: Thu, 7 Oct 2004 16:01:41 +0000
Subject: [PATCH 2/4] fixed bug where scan is not closed as it should

---
 sql/ha_ndbcluster.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index 8faa0b33756..bb6ace75f1f 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -2170,6 +2170,9 @@ int ha_ndbcluster::index_read(byte *buf,
     break;
   }
   
+  if (m_active_cursor)
+    close_scan();
+    
   key_range start_key;
   start_key.key = key;
   start_key.length = key_len;

From 69f40808e2aa8309c49b09d0faf2491a4b32188b Mon Sep 17 00:00:00 2001
From: "tomas@poseidon.ndb.mysql.com" <>
Date: Thu, 7 Oct 2004 16:30:21 +0000
Subject: [PATCH 3/4] ndb_alter_table.result, ndb_alter_table.test:   ...

---
 mysql-test/r/ndb_alter_table.result | 2 ++
 mysql-test/t/ndb_alter_table.test   | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/mysql-test/r/ndb_alter_table.result b/mysql-test/r/ndb_alter_table.result
index 28a50504064..ee7c3b28fe2 100644
--- a/mysql-test/r/ndb_alter_table.result
+++ b/mysql-test/r/ndb_alter_table.result
@@ -116,7 +116,9 @@ select * from t1 order by a;
 a	b
 0	1
 17	18
+SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO;
 alter table  t1 modify column a int not null auto_increment;
+SET SQL_MODE='';
 select * from t1 order by a;
 a	b
 0	1
diff --git a/mysql-test/t/ndb_alter_table.test b/mysql-test/t/ndb_alter_table.test
index 1c1ef670af2..22b1a0e476d 100644
--- a/mysql-test/t/ndb_alter_table.test
+++ b/mysql-test/t/ndb_alter_table.test
@@ -95,7 +95,9 @@ CREATE TABLE t1 (
 
 INSERT INTO t1 VALUES (0,1),(17,18);
 select * from t1 order by a;
+SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO;
 alter table  t1 modify column a int not null auto_increment;
+SET SQL_MODE='';
 select * from t1 order by a;
 INSERT INTO t1 VALUES (0,19),(20,21);
 select * from t1 order by a;

From db93dd1e3c4b54c2d88ccc3bee6f88775cafa8a3 Mon Sep 17 00:00:00 2001
From: "tomas@poseidon.ndb.mysql.com" <>
Date: Thu, 7 Oct 2004 17:00:07 +0000
Subject: [PATCH 4/4] ha_ndbcluster.cc:   merge error

---
 sql/ha_ndbcluster.cc | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index 67d02bb9329..e501a2b118d 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -2197,9 +2197,6 @@ int ha_ndbcluster::index_read(byte *buf,
     break;
   }
   
-  if (m_active_cursor)
-    close_scan();
-    
   key_range start_key;
   start_key.key = key;
   start_key.length = key_len;