From aa1a89b9108d655d977b0d8193e146cf7654351f Mon Sep 17 00:00:00 2001
From: marko <Unknown>
Date: Mon, 28 Sep 2009 12:03:58 +0000
Subject: [PATCH] branches/zip: Remove an assertion failure when the InnoDB
 data dictionary is inconsistent with the MySQL .frm file.

ha_innobase::index_read(): When the index cannot be found,
return an error.

ha_innobase::change_active_index(): When prebuilt->index == NULL,
set also prebuilt->index_usable = FALSE.  This is not needed for
correctness, because prebuilt->index_usable is only checked by
row_search_for_mysql(), which requires prebuilt->index != NULL.

This addresses Issue #349.  Approved by Heikki Tuuri over IM.
---
 ChangeLog            | 7 +++++++
 handler/ha_innodb.cc | 6 ++++++
 2 files changed, 13 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 2538ff6ce1..2a13ae24b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-09-28	The InnoDB Team
+
+	* handler/ha_innodb.cc:
+	When a secondary index exists in the MySQL .frm file but not in
+	the InnoDB data dictionary, return an error instead of letting an
+	assertion fail in index_read.
+
 2009-09-28	The InnoDB Team
 
 	* btr/btr0btr.c, buf/buf0buf.c,
diff --git a/handler/ha_innodb.cc b/handler/ha_innodb.cc
index f6184a1f5b..00c0984eaa 100644
--- a/handler/ha_innodb.cc
+++ b/handler/ha_innodb.cc
@@ -5060,6 +5060,11 @@ ha_innobase::index_read(
 
 	index = prebuilt->index;
 
+	if (UNIV_UNLIKELY(index == NULL)) {
+		prebuilt->index_usable = FALSE;
+		DBUG_RETURN(HA_ERR_CRASHED);
+	}
+
 	/* Note that if the index for which the search template is built is not
 	necessarily prebuilt->index, but can also be the clustered index */
 
@@ -5219,6 +5224,7 @@ ha_innobase::change_active_index(
 	if (UNIV_UNLIKELY(!prebuilt->index)) {
 		sql_print_warning("InnoDB: change_active_index(%u) failed",
 				  keynr);
+		prebuilt->index_usable = FALSE;
 		DBUG_RETURN(1);
 	}
 
-- 
2.30.9