diff --git a/.bzrignore b/.bzrignore
index 9eae1ed2545000274bc329b8c0e415a73a6629e9..e9e207dc35c147480dddaf298a0f41b9315a2d87 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -197,3 +197,4 @@ bdb/build_win32/db.h
 bdb/dist/configure
 bdb/dist/tags
 bdb/build_unix/*
+sql/.gdbinit
diff --git a/Docs/manual.texi b/Docs/manual.texi
index 4d9eb645c5224bbfbefaa82dd10d19647d1615c4..11e7908e2328dee98aea7792c3f9f24967009991 100644
--- a/Docs/manual.texi
+++ b/Docs/manual.texi
@@ -5679,7 +5679,7 @@ To install the HP-UX tar.gz distribution, you must have a copy of GNU
 
 
 @cindex installing, source distribution
-@cindex source distribtuion, installing
+@cindex source distribution, installing
 @cindex installation overview
 @node Installing source, Installing source tree, Installing binary, Installing
 @section Installing a MySQL Source Distribution
@@ -40246,6 +40246,12 @@ If a test fails totally, you should check the logs file in the
 @item
 If you have compiled @strong{MySQL} with debugging you can try to debug this
 with the @code{--gdb} and @code{--debug} options to @code{mysql-test-run}.
+@xref{Making trace files}.
+
+If you have not compiled @strong{MySQL} for debugging you should probably
+do that.  Just specify the @code{--with-debug} options to @code{configure}!
+@xref{Installing source}.
+
 @end itemize
 
 @page
@@ -42125,6 +42131,8 @@ Fixed bug in bi-directonal replication.
 Fixed bug in @code{BDB} tables when using index on multi-part key where a
 key part may be @code{NULL}.
 @item
+Fixed @code{MAX()} optimization on sub-key for @code{BDB} tables.
+@item
 Fixed problem with 'garbage results' when using @code{BDB} tables and
 @code{BLOB} or @code{TEXT} fields when joining many tables.
 @item
@@ -47038,6 +47046,12 @@ in some cases the @code{PROCEDURE} will not transform the columns.
 @item
 Creation of a table of type @code{MERGE} doesn't check if the underlying
 tables are of compatible types.
+@item
+@strong{MySQL} can't yet handle @code{NaN}, @code{-Inf} and @code{Inf}
+values in double. Using these will cause problems when trying to export
+and import data. We should as a intermediate solution change @code{NaN} to
+@code{NULL} (if possible) and @code{-Inf} and @code{Inf} to the
+Minimum respective maximum possible @code{double} value.
 @end itemize
 
 The following are known bugs in earlier versions of @strong{MySQL}:
@@ -47669,7 +47683,7 @@ send mail to @email{mysql@@lists.mysql.com} and ask for help.  Please use the
 If you can cause the @code{mysqld} server to crash quickly, you can try to
 create a trace file of this:
 
-Start the @code{mysqld} server with a trace log in @file{/tmp/mysql.trace}.
+Start the @code{mysqld} server with a trace log in @file{/tmp/mysqld.trace}.
 The log file will get very @emph{BIG}.
 
 @code{mysqld --debug --log}
diff --git a/mysql-test/README b/mysql-test/README
index 6ad59ea6a8bdf7354eefb73a445b6373fa112bf3..c5dc3e219dea2eabd212f4fcb1c59dce054f24ab 100644
--- a/mysql-test/README
+++ b/mysql-test/README
@@ -6,7 +6,10 @@ actually have a co-existing MySQL installation - the tests will not
 conflict with it.
 
 All tests must pass. If one or more of them fail on your system, please
-report the details to bugs@lists.mysql.com
+read the following manual section of how to report the problem:
+
+http://www.mysql.com/doc/M/y/MySQL_test_suite.html
+
 
 You can create your own test cases. To create a test case:
 
diff --git a/mysql-test/r/bdb.result b/mysql-test/r/bdb.result
index 42d14e1c34f1423170ddca70888b434cc4918984..2e760ae5b75723dccc6b5a6cf2f27e6fbe80e777 100644
--- a/mysql-test/r/bdb.result
+++ b/mysql-test/r/bdb.result
@@ -490,3 +490,5 @@ a	2
 a	b
 a	1
 a	2
+MIN(B)	MAX(b)
+1	1
diff --git a/mysql-test/r/innobase.result b/mysql-test/r/innobase.result
index 577bfcbf5b2460d07c128b1c50b99cd01b6fcd70..6c45bfd810d03a4a22887570e06f6688fb2de163 100644
--- a/mysql-test/r/innobase.result
+++ b/mysql-test/r/innobase.result
@@ -443,3 +443,5 @@ i	j
 1	2
 i	j
 1	2
+MIN(B)	MAX(b)
+1	1
diff --git a/mysql-test/t/bdb.test b/mysql-test/t/bdb.test
index 900260217d5c63b78500514251e16cbff1814810..564491fc520a7c9384091532e1c3cb99292d029b 100644
--- a/mysql-test/t/bdb.test
+++ b/mysql-test/t/bdb.test
@@ -664,3 +664,17 @@ SELECT * FROM t1 WHERE a='a' AND b=2;
 SELECT * FROM t1 WHERE a='a' AND b in (2);
 SELECT * FROM t1 WHERE a='a' AND b in (1,2);
 drop table t1;
+
+#
+# Test min-max optimization
+#
+
+CREATE TABLE t1 (
+  a int3 unsigned NOT NULL,
+  b int1 unsigned NOT NULL,
+  UNIQUE (a, b)
+) TYPE = BDB;
+ 
+INSERT INTO t1 VALUES (1, 1);
+SELECT MIN(B),MAX(b) FROM t1 WHERE t1.a = 1;
+drop table t1;
diff --git a/mysql-test/t/innobase.test b/mysql-test/t/innobase.test
index bca10751c13993d83ce1bec87f511d3e627ac418..4fa8d07bd521cb2c6b58bccc36add7741c214f38 100644
--- a/mysql-test/t/innobase.test
+++ b/mysql-test/t/innobase.test
@@ -394,3 +394,17 @@ select * from t1 where i=1 and j=2;
 create index ax1 on t1 (i,j);
 select * from t1 where i=1 and j=2;
 drop table t1;
+
+#
+# Test min-max optimization
+#
+
+CREATE TABLE t1 (
+  a int3 unsigned NOT NULL,
+  b int1 unsigned NOT NULL,
+  UNIQUE (a, b)
+) TYPE = innobase;
+ 
+INSERT INTO t1 VALUES (1, 1);
+SELECT MIN(B),MAX(b) FROM t1 WHERE t1.a = 1;
+drop table t1;
diff --git a/sql-bench/server-cfg.sh b/sql-bench/server-cfg.sh
index 8ede6022cfc8db37a053e27f84a548ab1e3bdc93..bfd9d7ce7581ec2200571905f62fd0ac436726e7 100644
--- a/sql-bench/server-cfg.sh
+++ b/sql-bench/server-cfg.sh
@@ -194,6 +194,11 @@ sub new
   {
     $limits{'working_blobs'}	= 0; # HEAP tables can't handle BLOB's
   }
+  if (defined($main::opt_create_options) &&
+      $main::opt_create_options =~ /type=innobase/i)
+  {
+    $limits{'max_text_size'}	= 8000; # Limit in Innobase
+  }
 
   return $self;
 }
diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc
index 3f6b2629e16dcb28474baabaeeb5588a082e7da1..10ff4dcc260428abb3612683628f5f3ebec6c661 100644
--- a/sql/ha_berkeley.cc
+++ b/sql/ha_berkeley.cc
@@ -1429,7 +1429,12 @@ int ha_berkeley::index_read(byte * buf, const byte * key,
     pack_key(&last_key, active_index, key_buff, key, key_len);
     /* Store for compare */
     memcpy(key_buff2, key_buff, (key_len=last_key.size));
-    key_info->handler.bdb_return_if_eq= -1;
+    /*
+      If HA_READ_AFTER_KEY is set, return next key, else return first
+      matching key.
+    */
+    key_info->handler.bdb_return_if_eq= (find_flag == HA_READ_AFTER_KEY ?
+					 1 : -1);
     error=read_row(cursor->c_get(cursor, &last_key, &row, DB_SET_RANGE),
 		   (char*) buf, active_index, &row, (DBT*) 0, 0);
     key_info->handler.bdb_return_if_eq= 0;
diff --git a/sql/ha_innobase.h b/sql/ha_innobase.h
index 73991be208d38e7f301c29ee9880f2f8c929c5b7..7ce22e70dcb75edc41e1d459d124dcc919104b0a 100644
--- a/sql/ha_innobase.h
+++ b/sql/ha_innobase.h
@@ -72,16 +72,18 @@ class ha_innobase: public handler
 	/* Init values for the class: */
  public:
   	ha_innobase(TABLE *table): handler(table),
-    		int_option_flag(HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER |
-		    HA_REC_NOT_IN_SEQ |
-		    HA_KEYPOS_TO_RNDPOS | HA_LASTKEY_ORDER |
-		    HA_HAVE_KEY_READ_ONLY | HA_READ_NOT_EXACT_KEY |
-		    HA_LONGLONG_KEYS | HA_NULL_KEY |
-		    HA_NOT_EXACT_COUNT |
-		    HA_NO_WRITE_DELAYED |
-		    HA_PRIMARY_KEY_IN_READ_INDEX | HA_DROP_BEFORE_CREATE),
-    		last_dup_key((uint) -1),
-    		start_of_scan(0)
+	  int_option_flag(HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER |
+			  HA_REC_NOT_IN_SEQ |
+			  HA_KEYPOS_TO_RNDPOS | HA_LASTKEY_ORDER |
+			  HA_HAVE_KEY_READ_ONLY | HA_READ_NOT_EXACT_KEY |
+			  HA_LONGLONG_KEYS | HA_NULL_KEY |
+			  HA_NOT_EXACT_COUNT |
+			  HA_NO_WRITE_DELAYED |
+			  HA_PRIMARY_KEY_IN_READ_INDEX |
+			  HA_DROP_BEFORE_CREATE |
+			  HA_NOT_READ_AFTER_KEY),
+	  last_dup_key((uint) -1),
+	  start_of_scan(0)
   	{
   	}
   	~ha_innobase() {}
diff --git a/sql/handler.h b/sql/handler.h
index 8cecd1fe17158bdf5c2188e736558dffca8fde4a..25c5d834be91995d59706c7f4c3f62e06cd4f78c 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -70,6 +70,7 @@
 #define HA_NO_WRITE_DELAYED	(HA_NOT_EXACT_COUNT*2)
 #define HA_PRIMARY_KEY_IN_READ_INDEX (HA_NO_WRITE_DELAYED*2)
 #define HA_DROP_BEFORE_CREATE	(HA_PRIMARY_KEY_IN_READ_INDEX*2)
+#define HA_NOT_READ_AFTER_KEY	(HA_DROP_BEFORE_CREATE*2)
 
 	/* Parameters for open() (in register form->filestat) */
 	/* HA_GET_INFO does a implicit HA_ABORT_IF_LOCKED */
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc
index d56bf68db62e7fec1c19fe7a67e910d77c8d40d3..df49d52d54a77dce88587bf17a96ba630fe02c62 100644
--- a/sql/opt_sum.cc
+++ b/sql/opt_sum.cc
@@ -141,6 +141,11 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
 	    break;
 	  }
 	  TABLE *table=((Item_field*) expr)->field->table;
+	  if ((table->file->option_flag() & HA_NOT_READ_AFTER_KEY))
+	  {
+	    const_result=0;
+	    break;
+	  }
 	  bool error=table->file->index_init((uint) ref.key);
 
 	  if (!ref.key_length)