From 954d4b1a58d159a53436f5b78b7c5c0e75524b20 Mon Sep 17 00:00:00 2001
From: sunny <>
Date: Thu, 23 Aug 2007 03:40:42 +0000
Subject: [PATCH] We check whether the AUTOINC sub-system has been initialized
 (first) by holding the AUTOINC mutex and if initialization is required then
 we initialize using our normal procedure. This change is related to
 Bug#27950.

---
 handler/ha_innodb.cc | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/handler/ha_innodb.cc b/handler/ha_innodb.cc
index 9413a8d11fc..87d96d91997 100644
--- a/handler/ha_innodb.cc
+++ b/handler/ha_innodb.cc
@@ -3812,12 +3812,23 @@ ha_innobase::delete_row(
 	if (table->found_next_number_field && record == table->record[0]) {
 		ulonglong	dummy = 0;
 
-		error = innobase_get_auto_increment(&dummy);
+		/* First check whether the AUTOINC sub-system has been
+		initialized using the AUTOINC mutex. If not then we
+		do it the "proper" way, by acquiring the heavier locks. */
+		dict_table_autoinc_lock(prebuilt->table);
 
-		if (error == DB_SUCCESS) {
+		if (!prebuilt->table->autoinc_inited) {
+			dict_table_autoinc_unlock(prebuilt->table);
+
+			error = innobase_get_auto_increment(&dummy);
+
+			if (error == DB_SUCCESS) {
+				dict_table_autoinc_unlock(prebuilt->table);
+			} else {
+				goto error_exit;
+			}
+		} else  {
 			dict_table_autoinc_unlock(prebuilt->table);
-		} else {
-			goto error_exit;
 		}
 	}
 
-- 
2.30.9