diff --git a/Docs/manual.texi b/Docs/manual.texi
index 76cad308d6af0466aa89bcbdfb9b94bcd30e816b..09d0fa6e6aaf433b80b8501081ac335d7c955088 100644
--- a/Docs/manual.texi
+++ b/Docs/manual.texi
@@ -27362,6 +27362,10 @@ MySQL will, by default, use sockets.)
 If you connect using TCP/IP from another computer over a 100M Ethernet,
 things will be 8-11 % slower.
 
+@item
+When running our benchmark with secure connections (all data encrypted
+with internal ssl support) things where 55 % slower.
+
 @item
 If you compile with @code{--with-debug=full}, then you will loose 20 %
 for most queries, but some queries may take substantially longer (The
diff --git a/configure.in b/configure.in
index 970336af518f4403793a6acdfb7cf986c076f205..08e8918b0dfce7813bbf1608a1028faa1e06c4d0 100644
--- a/configure.in
+++ b/configure.in
@@ -524,6 +524,13 @@ AC_ARG_WITH(mit-threads,
 if test "$with_mit_threads" = "yes"
 then
   enable_largefile="no"		# Will not work on Linux.
+  if test "$GXX" = "yes"
+  then
+    # Needed for gcc 3.0
+    CCLD=g++
+    export CCLD
+    AC_SUBST(CCLD)
+  fi
 fi
 
 # Set flags if we want to force to use pthreads
@@ -1596,13 +1603,17 @@ ac_save_CXXFLAGS="$CXXFLAGS"
 AC_CACHE_CHECK([style of gethost* routines], mysql_cv_gethost_style,
 AC_LANG_SAVE
 AC_LANG_CPLUSPLUS
-# Do not treat warnings as errors if we are linking agaist other libc
+
+# Do not treat warnings as errors if we are linking against other libc
 # this is to work around gcc not being permissive on non-system includes
 # with respect to ANSI C++
-if test "$ac_cv_prog_gxx" = "yes" -a "$with_other_libc" = "no" 
+# We also remove the -fbranch-probabilities option as this will give warnings
+# about not profiled code, which confuses configure
+if test "$ac_cv_prog_gxx" = "yes" -a "$with_other_libc" = "no"
 then
-  CXXFLAGS="$CXXFLAGS -Werror"
+  CXXFLAGS=`echo "$CXXFLAGS -Werror" | sed 's/-fbranch-probabilities//'`
 fi
+
 AC_TRY_COMPILE(
 [#undef inline
 #if !defined(SCO) && !defined(__osf__) && !defined(_REENTRANT)
diff --git a/include/my_semaphore.h b/include/my_semaphore.h
index 484423150f746dfe8a206b90d8cad8c28e61158f..36c4b1a47403b62c099b799af537faade547357d 100644
--- a/include/my_semaphore.h
+++ b/include/my_semaphore.h
@@ -31,21 +31,22 @@
 #ifndef _my_semaphore_h_
 #define _my_semaphore_h_
 
+C_MODE_START
+
 #ifndef __WIN__
 #include <semaphore.h>
 #else
 
-C_MODE_START
-
 typedef HANDLE sem_t;
-int sem_init (sem_t * sem, int pshared, unsigned int value);
-int sem_destroy (sem_t * sem);
-int sem_trywait (sem_t * sem);
-int sem_wait (sem_t * sem);
-int sem_post (sem_t * sem);
-int sem_post_multiple (sem_t * sem,int count);
-int sem_getvalue (sem_t * sem, int * sval);
+int sem_init(sem_t * sem, int pshared, unsigned int value);
+int sem_destroy(sem_t * sem);
+int sem_trywait(sem_t * sem);
+int sem_wait(sem_t * sem);
+int sem_post(sem_t * sem);
+int sem_post_multiple(sem_t * sem,int count);
+int sem_getvalue(sem_t * sem, int * sval);
 
-C_MODE_END
 #endif /* __WIN__ */
+
+C_MODE_END
 #endif /* !_my_semaphore_h_ */
diff --git a/mit-pthreads/Changes-mysql b/mit-pthreads/Changes-mysql
index da30f66fdec1dec061b216af99fa95321df4507d..06336abaecbef12d00629fc14d3a99c41a6b61bd 100644
--- a/mit-pthreads/Changes-mysql
+++ b/mit-pthreads/Changes-mysql
@@ -1,4 +1,8 @@
-Changes done to this distrubtion (pthreads-1_60_beta6) by Monty (monty@mysql.com)
+Changes done to this distrubtion (pthreads-1_60_beta6) by Monty
+(monty@mysql.com)
+
+02.06.20
+- Added support for semaphores.
 
 02.05.07
 - Hacked some files to get it to compile (not work) with glibc 2.2
diff --git a/mit-pthreads/include/Makefile.inc b/mit-pthreads/include/Makefile.inc
index b7fe59d5f0df15548f2a3674f9846eb195d489d2..72554b638d266ab32918e2b4b23b32839200a3f4 100644
--- a/mit-pthreads/include/Makefile.inc
+++ b/mit-pthreads/include/Makefile.inc
@@ -7,7 +7,7 @@
 
 
 FILES= cond.h copyright.h fd.h fd_pipe.h kernel.h mutex.h posix.h \
-	   pthread.h pthread_attr.h queue.h util.h 
+	   pthread.h pthread_attr.h queue.h util.h semaphore.h
 
 # Machine dependent header file
 MFILE= ${.CURDIR}/arch/${MACHINE}/machdep.h
diff --git a/mit-pthreads/include/pthread/ac-types.h b/mit-pthreads/include/pthread/ac-types.h
index 7fa4568817f755b79fa5417d64a2ae7e7ca54003..4dd20a6f7484a54cab589962cd05a42d21fe144e 100644
--- a/mit-pthreads/include/pthread/ac-types.h
+++ b/mit-pthreads/include/pthread/ac-types.h
@@ -6,5 +6,7 @@
 #define pthread_ssize_t int
 #define pthread_time_t long
 #define pthread_off_t long
-#define pthread_va_list void *
+#ifdef NOT_USED		/* Removed by monty becasue of conflicts on Linux */
+#define pthread_va_list char *
+#endif
 #endif
diff --git a/mit-pthreads/include/semaphore.h b/mit-pthreads/include/semaphore.h
new file mode 100644
index 0000000000000000000000000000000000000000..7a593287bc481df60ad8e0530698b03dadc3c075
--- /dev/null
+++ b/mit-pthreads/include/semaphore.h
@@ -0,0 +1,20 @@
+/*
+  This is written by Sergei Golubchik for MySQL AB and is in public domain.
+
+  Simple implementation of semaphores, needed to compile MySQL with
+  MIT-pthreads.
+*/
+
+typedef struct {
+  pthread_mutex_t mutex;
+  pthread_cond_t  cond;
+  uint            count;
+} sem_t;
+
+int sem_init(sem_t * sem, int pshared, uint value);
+int sem_destroy(sem_t * sem);
+int sem_wait(sem_t * sem);
+int sem_trywait(sem_t * sem);
+int sem_post (sem_t * sem);
+int sem_post_multiple(sem_t * sem, uint count);
+int sem_getvalue (sem_t * sem, uint *sval);
diff --git a/mit-pthreads/pthreads/GNUmakefile.inc b/mit-pthreads/pthreads/GNUmakefile.inc
index c8621495bacce7ba929d9b4ec3bf5bfc2e0279c4..b3019364a1d7260bfaf895c590d1233817f5578d 100644
--- a/mit-pthreads/pthreads/GNUmakefile.inc
+++ b/mit-pthreads/pthreads/GNUmakefile.inc
@@ -9,7 +9,7 @@ SRCS:= cleanup.c cond.c fd.c fd_kern.c fd_pipe.c fd_sysv.c file.c globals.c \
        specific.c process.c wait.c errno.c schedparam.c _exit.c prio_queue.c \
        pthread_init.c init.cc sig.c info.c mutexattr.c select.c wrapper.c \
        dump_state.c pthread_kill.c stat.c readv.c writev.c condattr.c \
-       pthread_cancel.c panic.c $(SRCS)
+       pthread_cancel.c panic.c semaphore.c $(SRCS)
 
 ifeq ($(HAVE_SYSCALL_TEMPLATE),yes)
 SYSCALL_FILTER_RULE=	for s in $(AVAILABLE_SYSCALLS) ; do \
diff --git a/mit-pthreads/pthreads/Makefile.inc b/mit-pthreads/pthreads/Makefile.inc
index 3939d57de6eb1e3d3d00adfeb4e74c5e7f403da5..68d970f17d83f593371e644d0e0b7470b57b65b4 100644
--- a/mit-pthreads/pthreads/Makefile.inc
+++ b/mit-pthreads/pthreads/Makefile.inc
@@ -8,7 +8,8 @@ SRCS+= cleanup.c cond.c fd.c fd_kern.c fd_pipe.c file.c globals.c malloc.c \
        pthread_join.c pthread_detach.c pthread_once.c sleep.c specific.c \
        process.c wait.c errno.c schedparam.c _exit.c prio_queue.c \
        pthread_init.c init.cc sig.c info.c mutexattr.c select.c wrapper.c \
-       dump_state.c pthread_kill.c condattr.c pthread_cancel.c panic.c
+       dump_state.c pthread_kill.c condattr.c pthread_cancel.c panic.c \
+       semaphore.c
 
 .if $(HAVE_SYSCALL_TEMPLATE) == yes
 OBJS+= syscalls.o
diff --git a/mit-pthreads/pthreads/semaphore.c b/mit-pthreads/pthreads/semaphore.c
new file mode 100644
index 0000000000000000000000000000000000000000..5516af1f4e3e87c8c0efc8e96d127781b8fa04ea
--- /dev/null
+++ b/mit-pthreads/pthreads/semaphore.c
@@ -0,0 +1,84 @@
+/*
+  This is written by Sergei Golubchik for MySQL AB and is in public domain.
+
+  Simple implementation of semaphores, needed to compile MySQL with
+  MIT-pthreads.
+*/
+
+#include <pthread.h>
+#include <errno.h>
+#include <semaphore.h>
+
+int sem_init(sem_t * sem, int pshared, uint value)
+{
+  sem->count=value;
+  pthread_cond_init(&sem->cond, 0);
+  pthread_mutex_init(&sem->mutex, 0);
+  return 0;
+}
+
+int sem_destroy(sem_t * sem)
+{
+  int err1,err2;
+  err1=pthread_cond_destroy(&sem->cond);
+  err2=pthread_mutex_destroy(&sem->mutex);
+  if (err1 || err2)
+  {
+    errno=err1 ? err1 : err2;
+    return -1;
+  }
+  return 0;
+}
+
+int sem_wait(sem_t * sem)
+{
+  while ((errno=pthread_mutex_lock(&sem->mutex)) || !sem->count)
+    pthread_cond_wait(&sem->cond, &sem->mutex);
+  if (errno)
+    return -1;
+  sem->count--; /* mutex is locked here */
+  pthread_mutex_unlock(&sem->mutex);
+  return 0;
+}
+
+int sem_trywait(sem_t * sem)
+{
+  if ((errno=pthread_mutex_lock(&sem->mutex)))
+    return -1;
+  if (sem->count)
+    sem->count--;
+  else
+    errno=EAGAIN;
+  pthread_mutex_unlock(&sem->mutex);
+  return errno ? -1 : 0;
+}
+
+
+int sem_post(sem_t * sem)
+{
+  if ((errno=pthread_mutex_lock(&sem->mutex)))
+    return -1;
+  sem->count++;
+  pthread_mutex_unlock(&sem->mutex);    /* does it really matter what to do */
+  pthread_cond_signal(&sem->cond);      /* first: x_unlock or x_signal ?    */
+  return 0;
+}
+
+int sem_post_multiple(sem_t * sem, uint count)
+{
+  if ((errno=pthread_mutex_lock(&sem->mutex)))
+    return -1;
+  sem->count+=count;
+  pthread_mutex_unlock(&sem->mutex);    /* does it really matter what to do */
+  pthread_cond_broadcast(&sem->cond);   /* first: x_unlock or x_broadcast ? */
+  return 0;
+}
+
+int sem_getvalue(sem_t * sem, uint *sval)
+{
+  if ((errno=pthread_mutex_lock(&sem->mutex)))
+    return -1;
+  *sval=sem->count;
+  pthread_mutex_unlock(&sem->mutex);
+  return 0;
+}
diff --git a/mit-pthreads/stdio/xprintf.c b/mit-pthreads/stdio/xprintf.c
index 668e8bc06050f5b4ced699b62cc66a1b23c82cec..d2cec36c835d913aeaad8ccff57c8ec7b02eef0f 100644
--- a/mit-pthreads/stdio/xprintf.c
+++ b/mit-pthreads/stdio/xprintf.c
@@ -217,7 +217,7 @@ static int vxprintf(func,arg,format,ap)
   void (*func)(char*,int,void*);
   void *arg;
   const char *format;
-  va_list ap;
+  pthread_va_list ap;
 {
   register const char *fmt; /* The format string. */
   register int c;           /* Next character in the format string */
@@ -673,7 +673,7 @@ int xprintf(
   const char *format,
   ...
 ){
-  va_list ap;
+  pthread_va_list ap;
   va_start(ap,format);
   return vxprintf(func,arg,format,ap);
 }
@@ -715,7 +715,7 @@ static void sout(txt,amt,arg)
 
 int sprintf(char *buf, const char *fmt, ...){
   int rc;
-  va_list ap;
+  pthread_va_list ap;
   struct s_strargument arg;
 
   va_start(ap,fmt);
@@ -725,7 +725,7 @@ int sprintf(char *buf, const char *fmt, ...){
   rc = vxprintf(sout,&arg,fmt,ap);
   va_end(ap);
 }
-int vsprintf(char *buf,const char *fmt,va_list ap){
+int vsprintf(char *buf,const char *fmt, pthread_va_list ap){
   struct s_strargument arg;
   arg.next = buf;
   arg.last = 0;
@@ -734,7 +734,7 @@ int vsprintf(char *buf,const char *fmt,va_list ap){
 }
 int snprintf(char *buf, size_t n, const char *fmt, ...){
   int rc;
-  va_list ap;
+  pthread_va_list ap;
   struct s_strargument arg;
 
   va_start(ap,fmt);
@@ -744,7 +744,7 @@ int snprintf(char *buf, size_t n, const char *fmt, ...){
   rc = vxprintf(sout,&arg,fmt,ap);
   va_end(ap);
 }  
-int vsnprintf(char *buf, size_t n, const char *fmt, va_list ap){
+int vsnprintf(char *buf, size_t n, const char *fmt, pthread_va_list ap){
   struct s_strargument arg;
   arg.next = buf;
   arg.last = &buf[n-1];
@@ -798,7 +798,7 @@ static void mout(zNewText,nNewChar,arg)
 ** routine naming conventions.
 */
 char *mprintf(const char *zFormat, ...){
-  va_list ap;
+  pthread_va_list ap;
   struct sgMprintf sMprintf;
   char *zNew;
   char zBuf[200];
@@ -825,7 +825,7 @@ char *mprintf(const char *zFormat, ...){
 ** The name is changed to TclVMPrintf() to conform with Tcl naming
 ** conventions.
 */
-char *vmprintf(const char *zFormat,va_list ap){
+char *vmprintf(const char *zFormat,pthread_va_list ap){
   struct sgMprintf sMprintf;
   char zBuf[200];
   sMprintf.nChar = 0;
@@ -858,7 +858,7 @@ static void fout(zNewText,nNewChar,arg)
 
 /* The public interface routines */
 int fprintf(FILE *pOut, const char *zFormat, ...){
-  va_list ap;
+  pthread_va_list ap;
   int retc;
 
   va_start(ap,zFormat);  
@@ -866,11 +866,11 @@ int fprintf(FILE *pOut, const char *zFormat, ...){
   va_end(ap);
   return retc;
 }
-int vfprintf(FILE *pOut, const char *zFormat, va_list ap){
+int vfprintf(FILE *pOut, const char *zFormat, pthread_va_list ap){
   return vxprintf(fout,pOut,zFormat,ap);
 }
 int printf(const char *zFormat, ...){
-  va_list ap;
+  pthread_va_list ap;
   int retc;
 
   va_start(ap,zFormat);
@@ -878,6 +878,6 @@ int printf(const char *zFormat, ...){
   va_end(ap);
   return retc;
 }
-int vprintf(const char *zFormat, va_list ap){
+int vprintf(const char *zFormat, pthread_va_list ap){
   return vxprintf(fout,stdout,zFormat,ap);
 }
diff --git a/mysql-test/r/rpl_alter.result b/mysql-test/r/rpl_alter.result
index 7883e725e3ac92c39b861f173568b45038745be7..2e42177c140ba415d35b7901c535159cbef39b52 100644
--- a/mysql-test/r/rpl_alter.result
+++ b/mysql-test/r/rpl_alter.result
@@ -1,4 +1,21 @@
+slave stop;
+reset master;
+reset slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+slave start;
+use test;
+drop database if exists d1;
+create database d1;
+create table d1.t1 ( n int);
+alter table d1.t1 add m int;
+insert into d1.t1 values (1,2);
+create table d1.t2 (n int);
+insert into d1.t2 values (45);
+rename table d1.t2 to d1.t3, d1.t1 to d1.t2;
+select * from d1.t2;
 n	m
 1	2
+select * from d1.t3;
 n
 45
+drop database d1;
diff --git a/sql/ha_isam.cc b/sql/ha_isam.cc
index b83dabd86b1795d3e820356cf3751035a789bfc3..55d24f5edb93b70a6275081680bc21ca2077fdb7 100644
--- a/sql/ha_isam.cc
+++ b/sql/ha_isam.cc
@@ -51,6 +51,8 @@ int ha_isam::open(const char *name, int mode, uint test_if_locked)
   info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
   if (!(test_if_locked & HA_OPEN_WAIT_IF_LOCKED))
     (void) nisam_extra(file,HA_EXTRA_WAIT_LOCK);
+  if (!table->db_record_offset)
+    int_table_flags|=HA_REC_NOT_IN_SEQ;
   return (0);
 }
 
diff --git a/sql/ha_isam.h b/sql/ha_isam.h
index 135424892f54fab1ecdf01224ce2b7a5bbc8ed9c..82a243ef5c0fce2e6fd1744147ea943bd1ae04be 100644
--- a/sql/ha_isam.h
+++ b/sql/ha_isam.h
@@ -26,20 +26,21 @@
 class ha_isam: public handler
 {
   N_INFO *file;
+  /* We need this as table_flags() may change after open() */
+  ulong int_table_flags;
 
  public:
-  ha_isam(TABLE *table): handler(table), file(0)
+  ha_isam(TABLE *table)
+    :handler(table), file(0),
+    int_table_flags(HA_READ_RND_SAME | HA_KEYPOS_TO_RNDPOS | HA_LASTKEY_ORDER |
+		    HA_KEY_READ_WRONG_STR | HA_DUPP_POS |
+		    HA_NOT_DELETE_WITH_CACHE)
   {}
   ~ha_isam() {}
   const char *table_type() const { return "ISAM"; }
   const char *index_type(uint key_number) { return "BTREE"; }
   const char **bas_ext() const;
-  ulong table_flags() const
-  {
-    return (HA_READ_RND_SAME | HA_KEYPOS_TO_RNDPOS | HA_LASTKEY_ORDER |
-	    HA_KEY_READ_WRONG_STR | HA_DUPP_POS | HA_NOT_DELETE_WITH_CACHE |
-	    ((table->db_record_offset) ? 0 : HA_REC_NOT_IN_SEQ));
-  }
+  ulong table_flags() const { return int_table_flags; }
   uint max_record_length() const { return HA_MAX_REC_LENGTH; }
   uint max_keys()          const { return N_MAXKEY; }
   uint max_key_parts()     const { return N_MAXKEY_SEG; }
diff --git a/sql/mini_client.cc b/sql/mini_client.cc
index 19e940542725572839c288ebf25aaf93bf7cbe11..f8c930a2154a5de0b8000aab8889f13deb22f277 100644
--- a/sql/mini_client.cc
+++ b/sql/mini_client.cc
@@ -27,13 +27,12 @@
 #define net_write_timeout net_write_timeout1
 #endif
 
-#if defined(__WIN__)
-#include <winsock.h>
-#include <odbcinst.h>		/* QQ: Is this really needed ? */
-#define DONT_USE_THR_ALARM
-#endif
-
 #include <my_global.h>
+/* my_pthread must be included early to be able to fix things */
+#if defined(THREAD)
+#include <my_pthread.h>				/* because of signal()	*/
+#endif
+#include <thr_alarm.h>
 #include <mysql_embed.h>
 #include <mysql_com.h>
 #include <violite.h>
@@ -75,10 +74,6 @@ extern "C" {					// Because of SCO 3.2V4.2
 #ifdef HAVE_SYS_UN_H
 #  include <sys/un.h>
 #endif
-#if defined(THREAD)
-#include <my_pthread.h>				/* because of signal()	*/
-#endif
-#include <thr_alarm.h>
 #ifndef INADDR_NONE
 #define INADDR_NONE	-1
 #endif