diff --git a/innobase/dict/dict0dict.c b/innobase/dict/dict0dict.c
index 2fc05b1923fa82d5e6285af2cb04069ce4d968fd..b1d7b5f762e931dab2a2c2ee42f02e176c13cb31 100644
--- a/innobase/dict/dict0dict.c
+++ b/innobase/dict/dict0dict.c
@@ -494,6 +494,46 @@ dict_index_get_nth_col_pos(
 	return(ULINT_UNDEFINED);
 }
 
+/************************************************************************
+Returns TRUE if the index contains a column or a prefix of that column. */
+
+ibool
+dict_index_contains_col_or_prefix(
+/*==============================*/
+				/* out: TRUE if contains the column or its
+				prefix */
+	dict_index_t*	index,	/* in: index */
+	ulint		n)	/* in: column number */
+{
+	dict_field_t*	field;
+	dict_col_t*	col;
+	ulint		pos;
+	ulint		n_fields;
+	
+	ut_ad(index);
+	ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
+
+	if (index->type & DICT_CLUSTERED) {
+
+		return(TRUE);
+	}
+
+	col = dict_table_get_nth_col(index->table, n);
+
+	n_fields = dict_index_get_n_fields(index);
+	
+	for (pos = 0; pos < n_fields; pos++) {
+		field = dict_index_get_nth_field(index, pos);
+
+		if (col == field->col) {
+
+			return(TRUE);
+		}
+	}
+
+	return(FALSE);
+}
+
 /************************************************************************
 Looks for a matching field in an index. The column and the prefix len have
 to be the same. */
diff --git a/innobase/include/dict0dict.h b/innobase/include/dict0dict.h
index e88c6a52bcb2b504ada6805604caa280347432a1..b5ec5381db28c230c9508b00b95e812aefa425c6 100644
--- a/innobase/include/dict0dict.h
+++ b/innobase/include/dict0dict.h
@@ -569,6 +569,16 @@ dict_index_get_nth_col_pos(
 	dict_index_t*	index,	/* in: index */
 	ulint		n);	/* in: column number */
 /************************************************************************
+Returns TRUE if the index contains a column or a prefix of that column. */
+
+ibool
+dict_index_contains_col_or_prefix(
+/*==============================*/
+				/* out: TRUE if contains the column or its
+				prefix */
+	dict_index_t*	index,	/* in: index */
+	ulint		n);	/* in: column number */
+/************************************************************************
 Looks for a matching field in an index. The column and the prefix len has
 to be the same. */
 
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index 795cffc0776deaa504b479dc41a139ab180f6546..a6528209b3ea974ce03a5c649d31b37639bb812b 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -1863,7 +1863,11 @@ build_template(
 
 		if (prebuilt->read_just_key) {
 			/* MySQL has instructed us that it is enough to
-			fetch the columns in the key */
+			fetch the columns in the key; looks like MySQL
+			can set this flag also when there is only a
+			prefix of the column in the key: in that case we
+			retrieve the whole column from the clustered
+			index */
 
 			fetch_all_in_key = TRUE;
 		} else {
@@ -1924,9 +1928,8 @@ build_template(
 		field = table->field[i];
 
 		if (templ_type == ROW_MYSQL_REC_FIELDS
-			&& !(fetch_all_in_key &&
-				ULINT_UNDEFINED != dict_index_get_nth_col_pos(
-								index, i))
+			&& !(fetch_all_in_key
+			     && dict_index_contains_col_or_prefix(index, i))
 			&& thd->query_id != field->query_id
 			&& thd->query_id != (field->query_id ^ MAX_ULONG_BIT)
 			&& thd->query_id !=