From 36827564d3d8d6f18e13d79bebed75572c21f769 Mon Sep 17 00:00:00 2001
From: unknown <monty@hundin.mysql.fi>
Date: Sat, 17 Aug 2002 18:02:56 +0300
Subject: [PATCH] Portability fixes for 4.0.3 build. Don't update MyISAM index
 file on UPDATE if index is not changed

Build-tools/Do-compile:
  Remove log files as early as possible
Docs/manual.texi:
  Changelog
BitKeeper/etc/ignore:
  Added myisam/test2.MYD myisam/test2.MYI to the ignore list
include/my_semaphore.h:
  Portability fix for SCO and BSDI
innobase/configure.in:
  Don't use inline with openbsd as this cases linker problems.
myisam/mi_update.c:
  Don't update index file on UPDATE if index is not changed
mysys/my_pthread.c:
  Portability fix for hpux
sql/item_cmpfunc.cc:
  Don't convert bigint to bigint
---
 .bzrignore             |  2 ++
 Build-tools/Do-compile | 32 ++++++++++++++++++++------------
 Docs/manual.texi       |  4 +++-
 include/my_semaphore.h |  2 +-
 innobase/configure.in  |  2 ++
 myisam/mi_update.c     | 23 ++++++++++++++++++-----
 mysys/my_pthread.c     |  7 +++----
 sql/item_cmpfunc.cc    |  8 +++++++-
 8 files changed, 56 insertions(+), 24 deletions(-)

diff --git a/.bzrignore b/.bzrignore
index 6234f16cad0..6a62ded71b2 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -491,3 +491,5 @@ sql-bench/innotest1b
 sql-bench/innotest2
 sql-bench/innotest2a
 sql-bench/innotest2b
+myisam/test2.MYD
+myisam/test2.MYI
diff --git a/Build-tools/Do-compile b/Build-tools/Do-compile
index 53a79017f1a..58bd2e49a38 100755
--- a/Build-tools/Do-compile
+++ b/Build-tools/Do-compile
@@ -75,6 +75,19 @@ $ENV{"PERL5LIB"}="$pwd/$host/perl5:$pwd/$host/perl5/site_perl";
 $slave_port=$mysql_tcp_port+16;
 $manager_port=$mysql_tcp_port+1;
 
+if ($opt_stage == 0)
+{
+  system("mkdir Logs") if (! -d "Logs");
+  system("mv $log ${log}-old") if (-f $log);
+  unlink($log);
+}
+
+open(LOG,">>$log") || abort("Can't open log file, error $?");
+select LOG;
+$|=1;
+select STDOUT;
+$|=1;
+
 if (-x "$host/bin/mysqladmin")
 {
   log_system("$host/bin/mysqladmin --no-defaults -u root -S $mysql_unix_port -s shutdown");
@@ -97,17 +110,8 @@ if ($opt_stage == 0)
   }
   rm_all("$host/test");
   system("mkdir $host/test") if (! -d "$host/test");
-  system("mkdir Logs") if (! -d "Logs");
-  system("mv $log ${log}-old") if (-f $log);
-  unlink($log);
 }
 
-open(LOG,">>$log") || abort("Can't open log file, error $?");
-select LOG;
-$|=1;
-select STDOUT;
-$|=1;
-
 safe_cd($host);
 if ($opt_stage == 0 && ! $opt_use_old_distribution)
 {
@@ -553,13 +557,17 @@ sub rm_all
 sub kill_all
 {
   my ($pattern) = @_;
-  my ($USER,$BSD,$LINUX,$pscmd, $user, $pid);
+  my ($USER,$BSD,$LINUX, $pscmd, $user, $pid);
   $user=$ENV{'USER'};
-  $BSD = -f '/vmunix' || $ENV{"OS"} eq "SunOS4";
+  $BSD = -f '/vmunix' || $ENV{"OS"} eq "SunOS4" || $^O eq 'darwin';
   $LINUX = $^O eq 'linux';
   $pscmd = $BSD ? "/bin/ps -auxww" : $LINUX ? "/bin/ps axuw" : "/bin/ps -ef";
 
-  open(PS, "$pscmd|") || die "can't run $pscmd: $!";
+  if (!open(PS, "$pscmd|"))
+  {
+    print "Warning: Can't run $pscmd: $!\n";
+    exit;
+  }
 
   # Catch any errors with eval.  A bad pattern, for instance.
  process:
diff --git a/Docs/manual.texi b/Docs/manual.texi
index ce72ffa6eb0..d4859ac279a 100644
--- a/Docs/manual.texi
+++ b/Docs/manual.texi
@@ -8828,7 +8828,7 @@ To get a core dump on Linux if @code{mysqld} dies with a @code{SIGSEGV} signal,
 you can start @code{mysqld} with the @code{--core-file} option.  Note
 that you also probably need to raise the @code{core file size} by adding
 @code{ulimit -c 1000000} to @code{safe_mysqld} or starting
-@code{safe_mysqld} with @code{--core-file-sizes=1000000}.
+@code{safe_mysqld} with @code{--core-file-size=1000000}.
 @xref{safe_mysqld, , @code{safe_mysqld}}.
 
 If you are linking your own MySQL client and get the error:
@@ -50261,6 +50261,8 @@ each individual 4.0.x release.
 
 @itemize @bullet
 @item
+Don't update MyISAM index file on update if not strictly necessary.
+@item
 Fixed bug in @code{SELECT DISTINCT ... FROM many_tables ORDER BY
 not-used-column}.
 @item
diff --git a/include/my_semaphore.h b/include/my_semaphore.h
index 0deac1a60d1..3431212ec82 100644
--- a/include/my_semaphore.h
+++ b/include/my_semaphore.h
@@ -34,7 +34,7 @@
 C_MODE_START
 #ifdef HAVE_SEMAPHORE_H
 #include <semaphore.h>
-#elif defined(__bsdi__)
+#elif !defined(__bsdi__)
 #ifdef __WIN__
 typedef HANDLE sem_t;
 #else
diff --git a/innobase/configure.in b/innobase/configure.in
index 100692e06ab..ea518ef1dfd 100644
--- a/innobase/configure.in
+++ b/innobase/configure.in
@@ -97,6 +97,8 @@ case "$target_os" in
        sysv5uw7*)
 	 # Problem when linking on SCO
 	 CFLAGS="$CFLAGS -DUNIV_MUST_NOT_INLINE";;
+	*-openbsd*)
+	 CFLAGS="$CFLAGS -DUNIV_MUST_NOT_INLINE";;
 esac
 
 case "$target" in
diff --git a/myisam/mi_update.c b/myisam/mi_update.c
index 2c6bc42bbdb..c52989f493e 100644
--- a/myisam/mi_update.c
+++ b/myisam/mi_update.c
@@ -83,8 +83,6 @@ int mi_update(register MI_INFO *info, const byte *oldrec, byte *newrec)
   /* Check which keys changed from the original row */
 
   new_key=info->lastkey2;
-  key_changed=HA_STATE_KEY_CHANGED;	/* We changed current database */
-					/* Remove key that didn't change */
   changed=0;
   for (i=0 ; i < share->base.keys ; i++)
   {
@@ -93,7 +91,7 @@ int mi_update(register MI_INFO *info, const byte *oldrec, byte *newrec)
       /* The following code block is for text searching by SerG */
       if (share->keyinfo[i].flag & HA_FULLTEXT )
       {
-	if(_mi_ft_cmp(info,i,oldrec, newrec))
+	if (_mi_ft_cmp(info,i,oldrec, newrec))
 	{
 	  if ((int) i == info->lastinx)
 	    key_changed|=HA_STATE_WRITTEN;
@@ -121,11 +119,24 @@ int mi_update(register MI_INFO *info, const byte *oldrec, byte *newrec)
       }
     }
   }
+  if (changed)
+    key_changed|= HA_STATE_KEY_CHANGED;
 
   if (share->calc_checksum)
+  {
     info->checksum=(*share->calc_checksum)(info,newrec);
-  if ((*share->update_record)(info,pos,newrec))
-    goto err;
+    key_changed|= HA_STATE_KEY_CHANGED;		/* Must update index file */
+  }
+  {
+    /* Don't update index file if data file is not extended */
+    MI_STATUS_INFO state;
+    memcpy((char*) &state, (char*) info->state, sizeof(state));
+    if ((*share->update_record)(info,pos,newrec))
+      goto err;
+    if (!key_changed &&
+	memcmp((char*) &state, (char*) info->state, sizeof(state)))
+      key_changed|= HA_STATE_KEY_CHANGED;	/* Must update index file */  
+  }
   if (auto_key_changed)
     update_auto_increment(info,newrec);
   if (share->calc_checksum)
@@ -147,6 +158,8 @@ int mi_update(register MI_INFO *info, const byte *oldrec, byte *newrec)
 err:
   DBUG_PRINT("error",("key: %d  errno: %d",i,my_errno));
   save_errno=my_errno;
+  if (changed)
+    key_changed|= HA_STATE_KEY_CHANGED;
   if (my_errno == HA_ERR_FOUND_DUPP_KEY || my_errno == HA_ERR_RECORD_FILE_FULL)
   {
     info->errkey= (int) i;
diff --git a/mysys/my_pthread.c b/mysys/my_pthread.c
index 9abe5d22c92..54a5c71c695 100644
--- a/mysys/my_pthread.c
+++ b/mysys/my_pthread.c
@@ -387,14 +387,13 @@ int pthread_signal(int sig, void (*func)())
 #undef pthread_mutex_destroy
 #undef pthread_mutex_wait
 #undef pthread_mutex_timedwait
-#undef pthread_mutex_t
-#undef pthread_cond_wait
-#undef pthread_cond_timedwait
 #undef pthread_mutex_trylock
 #undef pthread_mutex_t
+#undef pthread_cond_init
+#undef pthread_cond_wait
+#undef pthread_cond_timedwait
 #undef pthread_cond_t
 
-
 /*****************************************************************************
 ** Patches for AIX and DEC OSF/1 3.2
 *****************************************************************************/
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index e5544bc7bc2..923bbccde24 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -37,10 +37,16 @@ longlong Item_func_not::val_int()
   return !null_value && value == 0 ? 1 : 0;
 }
 
+/*
+  Convert a constant expression or string to an integer.
+  This is done when comparing DATE's of different formats and
+  also when comparing bigint to strings (in which case the string
+  is converted once to a bigint).
+*/
 
 static bool convert_constant_item(Field *field, Item **item)
 {
-  if ((*item)->const_item())
+  if ((*item)->const_item() && (*item)->type() != Item::INT_ITEM)
   {
     if (!(*item)->save_in_field(field) &&
 	!((*item)->null_value))