diff --git a/Build-tools/Do-all-build-steps b/Build-tools/Do-all-build-steps
index 2938edf2b01d21f6f848828dfbcf77297ba8fea7..d42db28fe2cb708b0dbe6fc290aa0659a8530e85 100755
--- a/Build-tools/Do-all-build-steps
+++ b/Build-tools/Do-all-build-steps
@@ -49,20 +49,12 @@ rm -f NEW-RPMS/*
 # Stop on error
 set -e
 
-# Make everything readable for user and group
-# chmod -R u+rw,g+rw .
-
 /bin/rm -f */.deps/*.P
 /bin/rm -f config.cache
 
-aclocal; autoheader; aclocal; automake; autoconf
-cd innobase
-aclocal; autoheader; aclocal; automake; autoconf
-cd ..
-
-# Since we have moved the configure.in stuff from readline to the
-# toplevel why do this? David 990630
-# (cd readline; aclocal; autoheader; aclocal; automake; autoconf)
+aclocal && autoheader && aclocal && automake && autoconf
+(cd innobase && aclocal && autoheader && aclocal && automake && autoconf)
+(cd bdb/dist && sh s_all)
 
 # A normal user starts here. We must use mit-threads. Otherwise it
 # does not end up in the distribution.
@@ -71,7 +63,7 @@ cd ..
  --with-low-memory \
  --with-mit-threads=yes $EXTRA_CONFIG \
  --enable-thread-safe-client \
- --without-berkeley-db \
+ --with-berkeley-db \
  --with-innobase-db
 
 gmake -j 2 
@@ -89,6 +81,7 @@ set -e
 log=$WD/Logs/Log-distcheck-`date +%y%m%d-%H%M`
 
 echo "Logging script $TMP_SCRIPT into $log"
+
 if test $to_host = "mysql-work"
 then
   # Try to get the right user for MySQL builds on work so that all
diff --git a/Docs/manual.texi b/Docs/manual.texi
index c394121c75b361bb5cd243548dbff58ea183e54f..d0c86182dca7bb4d75687d76cb291b1e75914c87 100644
--- a/Docs/manual.texi
+++ b/Docs/manual.texi
@@ -17884,6 +17884,7 @@ Returns the bitwise @code{AND} of all bits in @code{expr}. The calculation is
 performed with 64-bit (@code{BIGINT}) precision.
 @end table
 
+@cindex @code{GROUP BY}, extensions to ANSI SQL
 @strong{MySQL} has extended the use of @code{GROUP BY}. You can use columns or
 calculations in the @code{SELECT} expressions that don't appear in
 the @code{GROUP BY} part. This stands for @emph{any possible value for this
@@ -17902,8 +17903,9 @@ In ANSI SQL, you would have to add @code{customer.name} to the @code{GROUP
 BY} clause.  In @strong{MySQL}, the name is redundant if you don't run in
 ANSI mode.
 
-Don't use this feature if the columns you omit from the @code{GROUP BY} part
-aren't unique in the group!
+@strong{Don't use this feature} if the columns you omit from the
+@code{GROUP BY} part aren't unique in the group!  You will get
+unpredictable results.
 
 In some cases, you can use @code{MIN()} and @code{MAX()} to obtain a specific
 column value even if it isn't unique. The following gives the value of
@@ -19255,6 +19257,7 @@ to tell the optimizer that the result set will have many rows.  In this case,
 temporary table with a key on the @code{GROUP BY} elements.
 
 @item
+@cindex @code{GROUP BY}, extensions to ANSI SQL
 If you use @code{GROUP BY}, the output rows will be sorted according to the
 @code{GROUP BY} as if you would have had an @code{ORDER BY} over all the fields
 in the @code{GROUP BY}. @strong{MySQL} has extended the @code{GROUP BY} so that
@@ -19264,6 +19267,13 @@ you can also specify @code{ASC} and @code{DESC} to @code{GROUP BY}:
 SELECT a,COUNT(b) FROM test_table GROUP BY a DESC
 @end example
 
+@item
+@strong{MySQL} has extended the use of @code{GROUP BY} to allow you to
+select fields which are not mentioned in the @code{GROUP BY} clause.
+If you are not getting the results you expect from your query, please
+read the @code{GROUP BY} description.
+@xref{Group by functions}.
+
 @item
 @code{SQL_BUFFER_RESULT} will force the result to be put into a temporary
 table. This will help @strong{MySQL} free the table locks early and will help
diff --git a/acinclude.m4 b/acinclude.m4
index 1c01126385d04a5f1fde49b6f0773526f21893ae..633b2345a72b40f8a0b93041b0d7c0471abb5a61 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -608,8 +608,8 @@ AC_MSG_RESULT($ac_cv_conv_longlong_to_float)
 dnl ---------------------------------------------------------------------------
 dnl Macro: MYSQL_CHECK_BDB
 dnl Sets HAVE_BERKELEY_DB if inst library is found
-dnl Makes sure db version is >= 3.2.3
-dnl Looks in $srcdir for Berkeley distribution not told otherwise
+dnl Makes sure db version is correct.
+dnl Looks in $srcdir for Berkeley distribution if not told otherwise
 dnl ---------------------------------------------------------------------------
 
 AC_DEFUN([MYSQL_CHECK_BDB], [
@@ -618,7 +618,7 @@ AC_DEFUN([MYSQL_CHECK_BDB], [
   --with-berkeley-db[=DIR]
                           Use BerkeleyDB located in DIR],
               [bdb="$withval"],
-              [bdb=default])
+              [bdb=no])
 
   AC_ARG_WITH([berkeley-db-includes],
               [\
@@ -719,8 +719,6 @@ dnl echo "DBG3: [$mode] bdb='$bdb'; incl='$bdb_includes'; lib='$bdb_libs'"
       ;;
     compile )
       have_berkeley_db="$bdb"
-dnl Is added to @sql_server_dirs@ in configure.in
-      MYSQL_TOP_BUILDDIR([have_berkeley_db])
       AC_MSG_RESULT([Compiling Berekeley DB in '$have_berkeley_db'])
       ;;
     * )
@@ -791,9 +789,18 @@ AC_DEFUN([MYSQL_SEARCH_FOR_BDB], [
 dnl echo ["MYSQL_SEARCH_FOR_BDB"]
   bdb_dir_ok="no BerkeleyDB found"
 
-  for test_dir in bdb db-*.*.* ../db-*.*.* /usr/local/BerkeleyDB*; do
+  for test_dir in $srcdir/bdb $srcdir/db-*.*.* /usr/local/BerkeleyDB*; do
+dnl    echo "-----------> Looking at ($test_dir; `cd $test_dir && pwd`)"
     MYSQL_CHECK_BDB_DIR([$test_dir])
     if test X"$bdb_dir_ok" = Xsource || test X"$bdb_dir_ok" = Xinstalled; then
+dnl	echo "-----------> Found it ($bdb), ($srcdir)"
+dnl     This is needed so that 'make distcheck' works properly (VPATH build).
+dnl     VPATH build won't work if bdb is not under the source tree; but in
+dnl     that case, hopefully people will just make and install inside the
+dnl     tree, or install BDB first, and then use the installed version.
+	case "$bdb" in
+	"$srcdir/"* ) bdb=`echo "$bdb" | sed -e "s,^$srcdir/,,"` ;;
+	esac
         break
     fi
   done
@@ -834,9 +841,18 @@ AC_DEFUN([MYSQL_CHECK_BDB_VERSION], [
 ])
 
 AC_DEFUN([MYSQL_TOP_BUILDDIR], [
-  case $[$1] in
-    /* )        ;;      # already an absolute path
-    *  )        [$1]="'\$(top_builddir)/'$[$1]" ;;
+  case "$[$1]" in
+    /* ) ;;		# don't do anything with an absolute path
+    "$srcdir"/* )
+      # If BDB is under the source directory, we need to look under the
+      # build directory for bdb/build_unix.
+      # NOTE: I'm being lazy, and assuming the user did not specify
+      # something like --with-berkeley-db=bdb (it would be missing "./").
+      [$1]="\$(top_builddir)/"`echo "$[$1]" | sed -e "s,^$srcdir/,,"`
+      ;;
+    * )
+      AC_MSG_ERROR([The BDB directory must be directly under the MySQL source directory, or be specified using the full path. ('$srcdir'; '$[$1]')])
+      ;;
   esac
   if test X"$[$1]" != "/"
   then
diff --git a/bdb/Makefile.in b/bdb/Makefile.in
index 20140ac39c6b0c25ace9c036d30c1e0e79306154..b86eaefb5c1da16857dafb2f3e630a0f0067694a 100644
--- a/bdb/Makefile.in
+++ b/bdb/Makefile.in
@@ -37,7 +37,7 @@ all:
 	cd $(bdb_build) && $(MAKE) all
 
 # May want to fix this, and MYSQL/configure, to install things
-install:
+install dvi check installcheck:
 
 distdir:
 	for s in $(subdirs); do \
@@ -47,3 +47,4 @@ distdir:
 	  test -f $(distdir)/$$f || cp -p $(srcdir)/$$f $(distdir)/$$f; \
 	done
 	mkdir $(distdir)/$(bdb_build)
+	cp -p $(srcdir)/$(bdb_build)/.IGNORE_ME $(distdir)/$(bdb_build)
diff --git a/configure.in b/configure.in
index 1bac02c35911f67c9ffbc2a0be412268cf6cf088..1939f6191d10ef4c721178fe04ed9e082acaae9d 100644
--- a/configure.in
+++ b/configure.in
@@ -1877,9 +1877,31 @@ then
       then
         bdb_conf_flags="$bdb_conf_flags --enable-debug --enable-diagnostic"
       fi
-      (cd $bdb && cd build_unix && sh ../dist/configure $bdb_conf_flags) \
-      || AC_MSG_ERROR([could not configure Berkeley DB])
-
+      # NOTICE: if you're compiling BDB, it needs to be a SUBDIR
+      # of $srcdir (i.e., you can 'cd $srcdir/$bdb').  It won't
+      # work otherwise.
+      if test -d "$bdb"; then :
+      else
+	# This should only happen when doing a VPATH build
+	echo "NOTICE: I have to make the BDB directory: `pwd`:$bdb"
+	mkdir "$bdb" || exit 1
+      fi
+      if test -d "$bdb"/build_unix; then :
+      else
+	# This should only happen when doing a VPATH build
+	echo "NOTICE: I have to make the build_unix directory: `pwd`:$bdb/build_unix"
+	mkdir "$bdb/build_unix" || exit 1
+      fi
+      rel_srcdir=
+      case "$srcdir" in
+	/* ) rel_srcdir="$srcdir" ;;
+	* )  rel_srcdir="../../$srcdir" ;;
+      esac
+      (cd $bdb/build_unix && \
+       sh $rel_srcdir/$bdb/dist/configure $bdb_conf_flags) || \
+	AC_MSG_ERROR([could not configure Berkeley DB])
+
+dnl       echo "bdb = '$bdb'; inc = '$bdb_includes', lib = '$bdb_libs'"
       echo "END OF BERKELEY DB CONFIGURATION"
     fi