--- ./sql/item_func.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/item_func.cc	Wed May 30 11:33:27 2007
@@ -1159,8 +1159,8 @@
 */
 void Item_func_additive_op::result_precision()
 {
-  decimals= max(args[0]->decimals, args[1]->decimals);
-  int max_int_part= max(args[0]->decimal_precision() - args[0]->decimals,
+  decimals= MAX(args[0]->decimals, args[1]->decimals);
+  int max_int_part= MAX(args[0]->decimal_precision() - args[0]->decimals,
                         args[1]->decimal_precision() - args[1]->decimals);
   int precision= MIN(max_int_part + 1 + decimals, DECIMAL_MAX_PRECISION);
 
@@ -1340,7 +1340,7 @@
   switch(hybrid_type) {
   case REAL_RESULT:
   {
-    decimals=max(args[0]->decimals,args[1]->decimals)+prec_increment;
+    decimals=MAX(args[0]->decimals,args[1]->decimals)+prec_increment;
     set_if_smaller(decimals, NOT_FIXED_DEC);
     max_length=args[0]->max_length - args[0]->decimals + decimals;
     uint tmp=float_length(decimals);
@@ -1458,8 +1458,8 @@
 
 void Item_func_mod::result_precision()
 {
-  decimals= max(args[0]->decimals, args[1]->decimals);
-  max_length= max(args[0]->max_length, args[1]->max_length);
+  decimals= MAX(args[0]->decimals, args[1]->decimals);
+  max_length= MAX(args[0]->max_length, args[1]->max_length);
 }
 
 
--- ./sql/thr_malloc.cc.orig	Fri Apr 27 08:47:48 2007
+++ ./sql/thr_malloc.cc	Wed May 30 11:33:06 2007
@@ -103,7 +103,7 @@
   if ((from_cs == &my_charset_bin) || (to_cs == &my_charset_bin))
   {
     // Safety if to_cs->mbmaxlen > 0
-    new_length= min(arg_length, max_res_length);
+    new_length= MIN(arg_length, max_res_length);
     memcpy(pos, str, new_length);
   }
   else
--- ./sql/log_event.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/log_event.cc	Wed May 30 11:33:27 2007
@@ -4116,7 +4116,7 @@
   char buf[UV_NAME_LEN_SIZE];
   char buf1[UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE + 
 	    UV_CHARSET_NUMBER_SIZE + UV_VAL_LEN_SIZE];
-  char buf2[max(8, DECIMAL_MAX_FIELD_SIZE + 2)], *pos= buf2;
+  char buf2[MAX(8, DECIMAL_MAX_FIELD_SIZE + 2)], *pos= buf2;
   uint buf1_length;
   ulong event_length;
 
--- ./sql/sql_connect.cc.orig	Wed May  9 14:45:12 2007
+++ ./sql/sql_connect.cc	Wed May 30 11:33:06 2007
@@ -680,7 +680,7 @@
       if (thd->main_security_ctx.host)
       {
         if (thd->main_security_ctx.host != my_localhost)
-          thd->main_security_ctx.host[min(strlen(thd->main_security_ctx.host),
+          thd->main_security_ctx.host[MIN(strlen(thd->main_security_ctx.host),
                                           HOSTNAME_LENGTH)]= 0;
         thd->main_security_ctx.host_or_ip= thd->main_security_ctx.host;
       }
--- ./sql/sql_prepare.cc.orig	Mon May 21 11:20:37 2007
+++ ./sql/sql_prepare.cc	Wed May 30 11:33:06 2007
@@ -238,7 +238,7 @@
   int2store(buff+5, columns);
   int2store(buff+7, stmt->param_count);
   buff[9]= 0;                                   // Guard against a 4.1 client
-  tmp= min(stmt->thd->total_warn_count, 65535);
+  tmp= MIN(stmt->thd->total_warn_count, 65535);
   int2store(buff+10, tmp);
 
   /*
--- ./sql/item_sum.cc.orig	Mon May 21 11:20:37 2007
+++ ./sql/item_sum.cc	Wed May 30 11:33:06 2007
@@ -1071,7 +1071,7 @@
     AVG() will divide val by count. We need to reserve digits
     after decimal point as the result can be fractional.
   */
-  decimals= min(decimals + prec_increment, NOT_FIXED_DEC);
+  decimals= MIN(decimals + prec_increment, NOT_FIXED_DEC);
 }
 
 
@@ -1134,15 +1134,15 @@
   if (hybrid_type == DECIMAL_RESULT)
   {
     int precision= args[0]->decimal_precision() + prec_increment;
-    decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
+    decimals= MIN(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
     max_length= my_decimal_precision_to_length(precision, decimals,
                                                unsigned_flag);
-    f_precision= min(precision+DECIMAL_LONGLONG_DIGITS, DECIMAL_MAX_PRECISION);
+    f_precision= MIN(precision+DECIMAL_LONGLONG_DIGITS, DECIMAL_MAX_PRECISION);
     f_scale=  args[0]->decimals;
     dec_bin_size= my_decimal_get_binary_size(f_precision, f_scale);
   }
   else {
-    decimals= min(args[0]->decimals + prec_increment, NOT_FIXED_DEC);
+    decimals= MIN(args[0]->decimals + prec_increment, NOT_FIXED_DEC);
     max_length= args[0]->max_length + prec_increment;
   }
 }
@@ -1326,13 +1326,13 @@
   switch (args[0]->result_type()) {
   case REAL_RESULT:
   case STRING_RESULT:
-    decimals= min(args[0]->decimals + 4, NOT_FIXED_DEC);
+    decimals= MIN(args[0]->decimals + 4, NOT_FIXED_DEC);
     break;
   case INT_RESULT:
   case DECIMAL_RESULT:
   {
     int precision= args[0]->decimal_precision()*2 + prec_increment;
-    decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
+    decimals= MIN(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
     max_length= my_decimal_precision_to_length(precision, decimals,
                                                unsigned_flag);
 
@@ -3334,7 +3334,7 @@
       duplicate values (according to the syntax of this function). If there
       is no DISTINCT or ORDER BY clauses, we don't create this tree.
     */
-    init_tree(tree, (uint) min(thd->variables.max_heap_table_size,
+    init_tree(tree, (uint) MIN(thd->variables.max_heap_table_size,
                                thd->variables.sortbuff_size/16), 0,
               tree_key_length, compare_key, 0, NULL, (void*) this);
   }
--- ./sql/filesort.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/filesort.cc	Wed May 30 11:33:27 2007
@@ -202,7 +202,7 @@
     goto err;
 
   memavl= thd->variables.sortbuff_size;
-  min_sort_memory= max(MIN_SORT_MEMORY, param.sort_length*MERGEBUFF2);
+  min_sort_memory= MAX(MIN_SORT_MEMORY, param.sort_length*MERGEBUFF2);
   while (memavl >= min_sort_memory)
   {
     ulong old_memavl;
--- ./sql/stacktrace.c.orig	Thu Mar 29 23:58:47 2007
+++ ./sql/stacktrace.c	Wed May 30 11:33:06 2007
@@ -131,7 +131,7 @@
 
   if (!stack_bottom || (gptr) stack_bottom > (gptr) &fp)
   {
-    ulong tmp= min(0x10000,thread_stack);
+    ulong tmp= MIN(0x10000,thread_stack);
     /* Assume that the stack starts at the previous even 65K */
     stack_bottom= (gptr) (((ulong) &fp + tmp) &
 			  ~(ulong) 0xFFFF);
--- ./sql/sql_class.cc.orig	Wed May  9 14:45:12 2007
+++ ./sql/sql_class.cc	Wed May 30 11:33:06 2007
@@ -278,7 +278,7 @@
     if (max_query_len < 1)
       len= thd->query_length;
     else
-      len= min(thd->query_length, max_query_len);
+      len= MIN(thd->query_length, max_query_len);
     str.append('\n');
     str.append(thd->query, len);
   }
@@ -1477,7 +1477,7 @@
     else
     {
       if (fixed_row_size)
-	used_length=min(res->length(),item->max_length);
+	used_length=MIN(res->length(),item->max_length);
       else
 	used_length=res->length();
       if (result_type == STRING_RESULT && escape_char != -1)
--- ./sql/opt_range.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/opt_range.cc	Wed May 30 11:33:27 2007
@@ -7253,7 +7253,7 @@
   char *tmp_min_key, *tmp_max_key;
   uint8 save_first_null_comp= param->first_null_comp;
 
-  param->max_key_part=max(param->max_key_part,key_tree->part);
+  param->max_key_part=MAX(param->max_key_part,key_tree->part);
   if (key_tree->left != &null_element)
   {
     /*
@@ -9244,7 +9244,7 @@
         cur_group_prefix_len+= cur_part->store_length;
         cur_used_key_parts.set_bit(key_part_nr);
         ++cur_group_key_parts;
-        max_key_part= max(max_key_part,key_part_nr);
+        max_key_part= MAX(max_key_part,key_part_nr);
       }
       /*
         Check that used key parts forms a prefix of the index.
--- ./sql/sql_analyse.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/sql_analyse.cc	Wed May 30 11:33:27 2007
@@ -280,16 +280,16 @@
   {
     if (((longlong) info->ullval) < 0)
       return 0; // Impossible to store as a negative number
-    ev_info->llval =  -(longlong) max((ulonglong) -ev_info->llval, 
+    ev_info->llval =  -(longlong) MAX((ulonglong) -ev_info->llval, 
 				      info->ullval);
-    ev_info->min_dval = (double) -max(-ev_info->min_dval, info->dval);
+    ev_info->min_dval = (double) -MAX(-ev_info->min_dval, info->dval);
   }
   else		// ulonglong is as big as bigint in MySQL
   {
     if ((check_ulonglong(num, info->integers) == DECIMAL_NUM))
       return 0;
-    ev_info->ullval = (ulonglong) max(ev_info->ullval, info->ullval);
-    ev_info->max_dval =  (double) max(ev_info->max_dval, info->dval);
+    ev_info->ullval = (ulonglong) MAX(ev_info->ullval, info->ullval);
+    ev_info->max_dval =  (double) MAX(ev_info->max_dval, info->dval);
   }
   return 1;
 } // get_ev_num_info
@@ -1185,7 +1185,7 @@
   func_items[8] = new Item_proc_string("Std", 255);
   func_items[8]->maybe_null = 1;
   func_items[9] = new Item_proc_string("Optimal_fieldtype",
-				       max(64, output_str_length));
+				       MAX(64, output_str_length));
 
   for (uint i = 0; i < array_elements(func_items); i++)
     field_list.push_back(func_items[i]);
--- ./sql/ha_ndbcluster.cc.orig	Thu May 24 09:45:11 2007
+++ ./sql/ha_ndbcluster.cc	Wed May 30 11:33:06 2007
@@ -786,7 +786,7 @@
 
       DBUG_PRINT("value", ("set blob ptr: 0x%lx  len: %u",
                            (long) blob_ptr, blob_len));
-      DBUG_DUMP("value", (char*)blob_ptr, min(blob_len, 26));
+      DBUG_DUMP("value", (char*)blob_ptr, MIN(blob_len, 26));
 
       if (set_blob_value)
         *set_blob_value= TRUE;
--- ./sql/unireg.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/unireg.cc	Wed May 30 11:33:27 2007
@@ -652,7 +652,7 @@
     DBUG_RETURN(1);
   }
   /* Hack to avoid bugs with small static rows in MySQL */
-  reclength=max(file->min_record_length(table_options),reclength);
+  reclength=MAX(file->min_record_length(table_options),reclength);
   if (info_length+(ulong) create_fields.elements*FCOMP+288+
       n_length+int_length+com_length > 65535L || int_count > 255)
   {
--- ./sql/sql_acl.cc.orig	Wed Mar 28 21:05:05 2007
+++ ./sql/sql_acl.cc	Wed May 30 11:33:06 2007
@@ -808,7 +808,7 @@
         chars= 128;                             // Marker that chars existed
       }
     }
-    sort= (sort << 8) + (wild_pos ? min(wild_pos, 127) : chars);
+    sort= (sort << 8) + (wild_pos ? MIN(wild_pos, 127) : chars);
   }
   va_end(args);
   return sort;
--- ./sql/spatial.h.orig	Wed May 30 11:33:06 2007
+++ ./sql/spatial.h	Wed May 30 11:33:27 2007
@@ -180,7 +180,7 @@
     if (d != mbr->dimension() || d <= 0 || contains(mbr) || within(mbr))
       return 0;
 
-    MBR intersection(max(xmin, mbr->xmin), max(ymin, mbr->ymin),
+    MBR intersection(MAX(xmin, mbr->xmin), MAX(ymin, mbr->ymin),
                      MIN(xmax, mbr->xmax), MIN(ymax, mbr->ymax));
 
     return (d == intersection.dimension());
--- ./sql/rpl_utility.cc.orig	Thu Mar 22 09:49:02 2007
+++ ./sql/rpl_utility.cc	Wed May 30 11:33:06 2007
@@ -114,7 +114,7 @@
   /*
     We only check the initial columns for the tables.
   */
-  uint const cols_to_check= min(table->s->fields, size());
+  uint const cols_to_check= MIN(table->s->fields, size());
   int error= 0;
   RELAY_LOG_INFO const *rli= const_cast<RELAY_LOG_INFO*>(rli_arg);
 
--- ./sql/field.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/field.cc	Wed May 30 11:33:28 2007
@@ -2764,7 +2764,7 @@
   ASSERT_COLUMN_MARKED_FOR_READ;
   CHARSET_INFO *cs= &my_charset_bin;
   uint length;
-  uint mlength=max(field_length+1,5*cs->mbmaxlen);
+  uint mlength=MAX(field_length+1,5*cs->mbmaxlen);
   val_buffer->alloc(mlength);
   char *to=(char*) val_buffer->ptr();
 
@@ -2976,7 +2976,7 @@
   ASSERT_COLUMN_MARKED_FOR_READ;
   CHARSET_INFO *cs= &my_charset_bin;
   uint length;
-  uint mlength=max(field_length+1,7*cs->mbmaxlen);
+  uint mlength=MAX(field_length+1,7*cs->mbmaxlen);
   val_buffer->alloc(mlength);
   char *to=(char*) val_buffer->ptr();
   short j;
@@ -3193,7 +3193,7 @@
   ASSERT_COLUMN_MARKED_FOR_READ;
   CHARSET_INFO *cs= &my_charset_bin;
   uint length;
-  uint mlength=max(field_length+1,10*cs->mbmaxlen);
+  uint mlength=MAX(field_length+1,10*cs->mbmaxlen);
   val_buffer->alloc(mlength);
   char *to=(char*) val_buffer->ptr();
   long j= unsigned_flag ? (long) uint3korr(ptr) : sint3korr(ptr);
@@ -3412,7 +3412,7 @@
   ASSERT_COLUMN_MARKED_FOR_READ;
   CHARSET_INFO *cs= &my_charset_bin;
   uint length;
-  uint mlength=max(field_length+1,12*cs->mbmaxlen);
+  uint mlength=MAX(field_length+1,12*cs->mbmaxlen);
   val_buffer->alloc(mlength);
   char *to=(char*) val_buffer->ptr();
   int32 j;
@@ -3653,7 +3653,7 @@
 {
   CHARSET_INFO *cs= &my_charset_bin;
   uint length;
-  uint mlength=max(field_length+1,22*cs->mbmaxlen);
+  uint mlength=MAX(field_length+1,22*cs->mbmaxlen);
   val_buffer->alloc(mlength);
   char *to=(char*) val_buffer->ptr();
   longlong j;
@@ -3882,7 +3882,7 @@
 #endif
     memcpy_fixed((byte*) &nr,ptr,sizeof(nr));
 
-  uint to_length=max(field_length,70);
+  uint to_length=MAX(field_length,70);
   val_buffer->alloc(to_length);
   char *to=(char*) val_buffer->ptr();
 
@@ -4208,7 +4208,7 @@
 #endif
     doubleget(nr,ptr);
 
-  uint to_length=max(field_length, DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
+  uint to_length=MAX(field_length, DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
   val_buffer->alloc(to_length);
   char *to=(char*) val_buffer->ptr();
 
@@ -6071,13 +6071,13 @@
   double anr= fabs(nr);
   int neg= (nr < 0.0) ? 1 : 0;
   if (local_char_length > 4 && local_char_length < 32 &&
-      (anr < 1.0 ? anr > 1/(log_10[max(0,(int) local_char_length-neg-2)]) /* -2 for "0." */
+      (anr < 1.0 ? anr > 1/(log_10[MAX(0,(int) local_char_length-neg-2)]) /* -2 for "0." */
        : anr < log_10[local_char_length-neg]-1))
     use_scientific_notation= FALSE;
 
   length= (uint) my_sprintf(buff, (buff, "%-.*g",
                                    (use_scientific_notation ?
-                                    max(0, (int)local_char_length-neg-5) :
+                                    MAX(0, (int)local_char_length-neg-5) :
                                     local_char_length),
                                    nr));
   /*
--- ./sql/item_buff.cc.orig	Fri Apr 27 08:47:53 2007
+++ ./sql/item_buff.cc	Wed May 30 11:33:06 2007
@@ -51,7 +51,7 @@
 */
 
 Cached_item_str::Cached_item_str(THD *thd, Item *arg)
-  :item(arg), value(min(arg->max_length, thd->variables.max_sort_length))
+  :item(arg), value(MIN(arg->max_length, thd->variables.max_sort_length))
 {}
 
 bool Cached_item_str::cmp(void)
@@ -60,7 +60,7 @@
   bool tmp;
 
   if ((res=item->val_str(&tmp_value)))
-    res->length(min(res->length(), value.alloced_length()));
+    res->length(MIN(res->length(), value.alloced_length()));
   if (null_value != item->null_value)
   {
     if ((null_value= item->null_value))
--- ./sql/slave.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/slave.cc	Wed May 30 11:33:27 2007
@@ -1354,13 +1354,13 @@
         slave is 2. At SHOW SLAVE STATUS time, assume that the difference
         between timestamp of slave and rli->last_master_timestamp is 0
         (i.e. they are in the same second), then we get 0-(2-1)=-1 as a result.
-        This confuses users, so we don't go below 0: hence the max().
+        This confuses users, so we don't go below 0: hence the MAX().
 
         last_master_timestamp == 0 (an "impossible" timestamp 1970) is a
         special marker to say "consider we have caught up".
       */
       protocol->store((longlong)(mi->rli.last_master_timestamp ?
-                                 max(0, time_diff) : 0));
+                                 MAX(0, time_diff) : 0));
     }
     else
     {
@@ -3325,7 +3325,7 @@
     relay_log_pos       Current log pos
     pending             Number of bytes already processed from the event
   */
-  rli->event_relay_log_pos= max(rli->event_relay_log_pos, BIN_LOG_HEADER_SIZE);
+  rli->event_relay_log_pos= MAX(rli->event_relay_log_pos, BIN_LOG_HEADER_SIZE);
   my_b_seek(cur_log,rli->event_relay_log_pos);
   DBUG_RETURN(cur_log);
 }
--- ./sql/key.cc.orig	Wed May  9 14:45:11 2007
+++ ./sql/key.cc	Wed May 30 11:33:06 2007
@@ -143,13 +143,13 @@
         key_part->key_part_flag & HA_VAR_LENGTH_PART)
     {
       key_length-= HA_KEY_BLOB_LENGTH;
-      length= min(key_length, key_part->length);
+      length= MIN(key_length, key_part->length);
       key_part->field->get_key_image((char*) to_key, length, Field::itRAW);
       to_key+= HA_KEY_BLOB_LENGTH;
     }
     else
     {
-      length= min(key_length, key_part->length);
+      length= MIN(key_length, key_part->length);
       Field *field= key_part->field;
       CHARSET_INFO *cs= field->charset();
       uint bytes= field->get_key_image((char*) to_key, length, Field::itRAW);
@@ -236,7 +236,7 @@
       my_ptrdiff_t ptrdiff= to_record - field->table->record[0];
       field->move_field_offset(ptrdiff);
       key_length-= HA_KEY_BLOB_LENGTH;
-      length= min(key_length, key_part->length);
+      length= MIN(key_length, key_part->length);
       old_map= dbug_tmp_use_all_columns(field->table, field->table->write_set);
       field->set_key_image((char *) from_key, length);
       dbug_tmp_restore_column_map(field->table->write_set, old_map);
@@ -245,7 +245,7 @@
     }
     else
     {
-      length= min(key_length, key_part->length);
+      length= MIN(key_length, key_part->length);
       memcpy(to_record + key_part->offset, from_key, (size_t) length);
     }
     from_key+= length;
@@ -305,7 +305,7 @@
 	return 1;
       continue;
     }
-    length= min((uint) (key_end-key), store_length);
+    length= MIN((uint) (key_end-key), store_length);
     if (!(key_part->key_type & (FIELDFLAG_NUMBER+FIELDFLAG_BINARY+
                                 FIELDFLAG_PACK)))
     {
@@ -371,7 +371,7 @@
     {
       field->val_str(&tmp);
       if (key_part->length < field->pack_length())
-	tmp.length(min(tmp.length(),key_part->length));
+	tmp.length(MIN(tmp.length(),key_part->length));
       to->append(tmp);
     }
     else
--- ./sql/tztime.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/tztime.cc	Wed May 30 11:33:27 2007
@@ -167,7 +167,7 @@
       char buf[sizeof(struct tzhead) + sizeof(my_time_t) * TZ_MAX_TIMES +
                TZ_MAX_TIMES + sizeof(TRAN_TYPE_INFO) * TZ_MAX_TYPES +
 #ifdef ABBR_ARE_USED
-               max(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1))) +
+               MAX(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1))) +
 #endif
                sizeof(LS_INFO) * TZ_MAX_LEAPS];
     } u;
@@ -1827,7 +1827,7 @@
   uchar types[TZ_MAX_TIMES];
   TRAN_TYPE_INFO ttis[TZ_MAX_TYPES];
 #ifdef ABBR_ARE_USED
-  char chars[max(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1)))];
+  char chars[MAX(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1)))];
 #endif
   DBUG_ENTER("tz_load_from_open_tables");
 
--- ./sql/log.cc.orig	Thu May 24 09:45:11 2007
+++ ./sql/log.cc	Wed May 30 11:33:06 2007
@@ -579,11 +579,11 @@
     t.neg= 0;
 
     /* fill in query_time field */
-    calc_time_from_sec(&t, (long) min(query_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
+    calc_time_from_sec(&t, (long) MIN(query_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
     if (table->field[2]->store_time(&t, MYSQL_TIMESTAMP_TIME))
       goto err;
     /* lock_time */
-    calc_time_from_sec(&t, (long) min(lock_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
+    calc_time_from_sec(&t, (long) MIN(lock_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
     if (table->field[3]->store_time(&t, MYSQL_TIMESTAMP_TIME))
       goto err;
     /* rows_sent */
@@ -2308,7 +2308,7 @@
   {
     char *p= fn_ext(log_name);
     uint length= (uint) (p - log_name);
-    strmake(buff, log_name, min(length, FN_REFLEN));
+    strmake(buff, log_name, MIN(length, FN_REFLEN));
     return (const char*)buff;
   }
   return log_name;
@@ -4301,7 +4301,7 @@
   DBUG_ENTER("print_buffer_to_nt_eventlog");
 
   /* Add ending CR/LF's to string, overwrite last chars if necessary */
-  strmov(buffptr+min(length, buffLen-5), "\r\n\r\n");
+  strmov(buffptr+MIN(length, buffLen-5), "\r\n\r\n");
 
   setup_windows_event_source();
   if ((event= RegisterEventSource(NULL,"MySQL")))
--- ./sql/item_cmpfunc.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/item_cmpfunc.cc	Wed May 30 11:33:27 2007
@@ -560,7 +560,7 @@
   {
     if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
     {
-      precision= 5 * log_01[max((*a)->decimals, (*b)->decimals)];
+      precision= 5 * log_01[MAX((*a)->decimals, (*b)->decimals)];
       if (func == &Arg_comparator::compare_real)
         func= &Arg_comparator::compare_real_fixed;
       else if (func == &Arg_comparator::compare_e_real)
@@ -1936,11 +1936,11 @@
 {
   agg_result_type(&hybrid_type, args, 2);
   maybe_null=args[1]->maybe_null;
-  decimals= max(args[0]->decimals, args[1]->decimals);
+  decimals= MAX(args[0]->decimals, args[1]->decimals);
   max_length= (hybrid_type == DECIMAL_RESULT || hybrid_type == INT_RESULT) ?
-    (max(args[0]->max_length - args[0]->decimals,
+    (MAX(args[0]->max_length - args[0]->decimals,
          args[1]->max_length - args[1]->decimals) + decimals) :
-    max(args[0]->max_length, args[1]->max_length);
+    MAX(args[0]->max_length, args[1]->max_length);
 
   switch (hybrid_type) {
   case STRING_RESULT:
@@ -1964,7 +1964,7 @@
 
 uint Item_func_ifnull::decimal_precision() const
 {
-  int max_int_part=max(args[0]->decimal_int_part(),args[1]->decimal_int_part());
+  int max_int_part=MAX(args[0]->decimal_int_part(),args[1]->decimal_int_part());
   return MIN(max_int_part + decimals, DECIMAL_MAX_PRECISION);
 }
 
@@ -2094,7 +2094,7 @@
 Item_func_if::fix_length_and_dec()
 {
   maybe_null=args[1]->maybe_null || args[2]->maybe_null;
-  decimals= max(args[1]->decimals, args[2]->decimals);
+  decimals= MAX(args[1]->decimals, args[2]->decimals);
   unsigned_flag=args[1]->unsigned_flag && args[2]->unsigned_flag;
 
   enum Item_result arg1_type=args[1]->result_type();
@@ -2135,16 +2135,16 @@
     int len2= args[2]->max_length - args[2]->decimals
       - (args[2]->unsigned_flag ? 0 : 1);
 
-    max_length=max(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
+    max_length=MAX(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
   }
   else
-    max_length= max(args[1]->max_length, args[2]->max_length);
+    max_length= MAX(args[1]->max_length, args[2]->max_length);
 }
 
 
 uint Item_func_if::decimal_precision() const
 {
-  int precision=(max(args[1]->decimal_int_part(),args[2]->decimal_int_part())+
+  int precision=(MAX(args[1]->decimal_int_part(),args[2]->decimal_int_part())+
                  decimals);
   return MIN(precision, DECIMAL_MAX_PRECISION);
 }
@@ -4505,14 +4505,14 @@
       register const int v = plm1 - i;
       turboShift = u - v;
       bcShift    = bmBc[(uint) (uchar) text[i + j]] - plm1 + i;
-      shift      = max(turboShift, bcShift);
-      shift      = max(shift, bmGs[i]);
+      shift      = MAX(turboShift, bcShift);
+      shift      = MAX(shift, bmGs[i]);
       if (shift == bmGs[i])
 	u = MIN(pattern_len - shift, v);
       else
       {
 	if (turboShift < bcShift)
-	  shift = max(shift, u + 1);
+	  shift = MAX(shift, u + 1);
 	u = 0;
       }
       j+= shift;
@@ -4536,14 +4536,14 @@
       register const int v = plm1 - i;
       turboShift = u - v;
       bcShift    = bmBc[(uint) likeconv(cs, text[i + j])] - plm1 + i;
-      shift      = max(turboShift, bcShift);
-      shift      = max(shift, bmGs[i]);
+      shift      = MAX(turboShift, bcShift);
+      shift      = MAX(shift, bmGs[i]);
       if (shift == bmGs[i])
 	u = MIN(pattern_len - shift, v);
       else
       {
 	if (turboShift < bcShift)
-	  shift = max(shift, u + 1);
+	  shift = MAX(shift, u + 1);
 	u = 0;
       }
       j+= shift;
--- ./sql/set_var.cc.orig	Mon May 21 11:20:37 2007
+++ ./sql/set_var.cc	Wed May 30 11:33:06 2007
@@ -1403,7 +1403,7 @@
 					    &not_used));
     if (error_len)
     {
-      strmake(buff, error, min(sizeof(buff), error_len));
+      strmake(buff, error, MIN(sizeof(buff), error_len));
       goto err;
     }
   }
--- ./sql/sql_cache.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/sql_cache.cc	Wed May 30 11:33:27 2007
@@ -725,7 +725,7 @@
     Query_cache_query *header= query_block->query();
     Query_cache_block *last_result_block= header->result()->prev;
     ulong allign_size= ALIGN_SIZE(last_result_block->used);
-    ulong len= max(query_cache.min_allocation_unit, allign_size);
+    ulong len= MAX(query_cache.min_allocation_unit, allign_size);
     if (last_result_block->length >= query_cache.min_allocation_unit + len)
       query_cache.split_block(last_result_block,len);
 
@@ -2039,7 +2039,7 @@
   DBUG_ENTER("Query_cache::write_block_data");
   DBUG_PRINT("qcache", ("data: %ld, header: %ld, all header: %ld",
 		      data_len, header_len, all_headers_len));
-  Query_cache_block *block = allocate_block(max(align_len, 
+  Query_cache_block *block = allocate_block(MAX(align_len, 
 						min_allocation_unit),
 					    1, 0, under_guard);
   if (block != 0)
@@ -2104,7 +2104,7 @@
   ulong append_min = get_min_append_result_data_size();
   if (last_block_free_space < data_len &&
       append_next_free_block(last_block,
-			     max(tail, append_min)))
+			     MAX(tail, append_min)))
     last_block_free_space = last_block->length - last_block->used;
   // If no space in last block (even after join) allocate new block
   if (last_block_free_space < data_len)
@@ -2226,7 +2226,7 @@
     return min_result_data_size;
   ulong avg_result = (query_cache_size - free_memory) / queries_in_cache;
   avg_result = MIN(avg_result, query_cache_limit);
-  return max(min_result_data_size, avg_result);
+  return MAX(min_result_data_size, avg_result);
 }
 
 inline ulong Query_cache::get_min_append_result_data_size()
@@ -2258,7 +2258,7 @@
     ulong len= data_len + all_headers_len;
     ulong align_len= ALIGN_SIZE(len);
 
-    if (!(new_block= allocate_block(max(min_size, align_len),
+    if (!(new_block= allocate_block(MAX(min_size, align_len),
 				    min_result_data_size == 0,
 				    all_headers_len + min_result_data_size,
 				    1)))
--- ./sql/sql_plugin.cc.orig	Fri May 11 16:44:06 2007
+++ ./sql/sql_plugin.cc	Wed May 30 11:33:06 2007
@@ -463,7 +463,7 @@
     for (i=0;
          (old=(struct st_mysql_plugin *)(ptr+i*sizeof_st_plugin))->info;
          i++)
-      memcpy(cur+i, old, min(sizeof(cur[i]), sizeof_st_plugin));
+      memcpy(cur+i, old, MIN(sizeof(cur[i]), sizeof_st_plugin));
 
     sym= cur;
   }
@@ -1959,7 +1959,7 @@
                      &error, &error_len, &not_used);
     if (error_len)
     {
-      strmake(buff, error, min(sizeof(buff), error_len));
+      strmake(buff, error, MIN(sizeof(buff), error_len));
       strvalue= buff;
       goto err;
     }
--- ./sql/item_timefunc.cc.orig	Thu May  3 10:16:44 2007
+++ ./sql/item_timefunc.cc	Wed May 30 11:33:06 2007
@@ -306,14 +306,14 @@
       switch (*++ptr) {
 	/* Year */
       case 'Y':
-	tmp= (char*) val + min(4, val_len);
+	tmp= (char*) val + MIN(4, val_len);
 	l_time->year= (int) my_strtoll10(val, &tmp, &error);
         if ((int) (tmp-val) <= 2)
           l_time->year= year_2000_handling(l_time->year);
 	val= tmp;
 	break;
       case 'y':
-	tmp= (char*) val + min(2, val_len);
+	tmp= (char*) val + MIN(2, val_len);
 	l_time->year= (int) my_strtoll10(val, &tmp, &error);
 	val= tmp;
         l_time->year= year_2000_handling(l_time->year);
@@ -322,7 +322,7 @@
 	/* Month */
       case 'm':
       case 'c':
-	tmp= (char*) val + min(2, val_len);
+	tmp= (char*) val + MIN(2, val_len);
 	l_time->month= (int) my_strtoll10(val, &tmp, &error);
 	val= tmp;
 	break;
@@ -339,15 +339,15 @@
 	/* Day */
       case 'd':
       case 'e':
-	tmp= (char*) val + min(2, val_len);
+	tmp= (char*) val + MIN(2, val_len);
 	l_time->day= (int) my_strtoll10(val, &tmp, &error);
 	val= tmp;
 	break;
       case 'D':
-	tmp= (char*) val + min(2, val_len);
+	tmp= (char*) val + MIN(2, val_len);
 	l_time->day= (int) my_strtoll10(val, &tmp, &error);
 	/* Skip 'st, 'nd, 'th .. */
-	val= tmp + min((int) (val_end-tmp), 2);
+	val= tmp + MIN((int) (val_end-tmp), 2);
 	break;
 
 	/* Hour */
@@ -358,14 +358,14 @@
 	/* fall through */
       case 'k':
       case 'H':
-	tmp= (char*) val + min(2, val_len);
+	tmp= (char*) val + MIN(2, val_len);
 	l_time->hour= (int) my_strtoll10(val, &tmp, &error);
 	val= tmp;
 	break;
 
 	/* Minute */
       case 'i':
-	tmp= (char*) val + min(2, val_len);
+	tmp= (char*) val + MIN(2, val_len);
 	l_time->minute= (int) my_strtoll10(val, &tmp, &error);
 	val= tmp;
 	break;
@@ -373,7 +373,7 @@
 	/* Second */
       case 's':
       case 'S':
-	tmp= (char*) val + min(2, val_len);
+	tmp= (char*) val + MIN(2, val_len);
 	l_time->second= (int) my_strtoll10(val, &tmp, &error);
 	val= tmp;
 	break;
@@ -425,7 +425,7 @@
 	val= tmp;
 	break;
       case 'j':
-	tmp= (char*) val + min(val_len, 3);
+	tmp= (char*) val + MIN(val_len, 3);
 	yearday= (int) my_strtoll10(val, &tmp, &error);
 	val= tmp;
 	break;
@@ -437,7 +437,7 @@
       case 'u':
         sunday_first_n_first_week_non_iso= (*ptr=='U' || *ptr== 'V');
         strict_week_number= (*ptr=='V' || *ptr=='v');
-	tmp= (char*) val + min(val_len, 2);
+	tmp= (char*) val + MIN(val_len, 2);
 	if ((week_number= (int) my_strtoll10(val, &tmp, &error)) < 0 ||
             strict_week_number && !week_number ||
             week_number > 53)
@@ -449,7 +449,7 @@
       case 'X':
       case 'x':
         strict_week_number_year_type= (*ptr=='X');
-        tmp= (char*) val + min(4, val_len);
+        tmp= (char*) val + MIN(4, val_len);
         strict_week_number_year= (int) my_strtoll10(val, &tmp, &error);
         val= tmp;
         break;
@@ -594,7 +594,7 @@
 err:
   {
     char buff[128];
-    strmake(buff, val_begin, min(length, sizeof(buff)-1));
+    strmake(buff, val_begin, MIN(length, sizeof(buff)-1));
     push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
                         ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE),
                         date_time_type, buff, "str_to_time");
@@ -1706,7 +1706,7 @@
   else
   {
     fixed_length=0;
-    max_length=min(arg1->max_length, MAX_BLOB_WIDTH) * 10 *
+    max_length=MIN(arg1->max_length, MAX_BLOB_WIDTH) * 10 *
                    collation.collation->mbmaxlen;
     set_if_smaller(max_length,MAX_BLOB_WIDTH);
   }
--- ./sql/handler.h.orig	Wed May  9 14:45:11 2007
+++ ./sql/handler.h	Wed May 30 11:33:06 2007
@@ -1513,15 +1513,15 @@
   { return (HA_ERR_WRONG_COMMAND); }
 
   uint max_record_length() const
-  { return min(HA_MAX_REC_LENGTH, max_supported_record_length()); }
+  { return MIN(HA_MAX_REC_LENGTH, max_supported_record_length()); }
   uint max_keys() const
-  { return min(MAX_KEY, max_supported_keys()); }
+  { return MIN(MAX_KEY, max_supported_keys()); }
   uint max_key_parts() const
-  { return min(MAX_REF_PARTS, max_supported_key_parts()); }
+  { return MIN(MAX_REF_PARTS, max_supported_key_parts()); }
   uint max_key_length() const
-  { return min(MAX_KEY_LENGTH, max_supported_key_length()); }
+  { return MIN(MAX_KEY_LENGTH, max_supported_key_length()); }
   uint max_key_part_length() const
-  { return min(MAX_KEY_LENGTH, max_supported_key_part_length()); }
+  { return MIN(MAX_KEY_LENGTH, max_supported_key_part_length()); }
 
   virtual uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; }
   virtual uint max_supported_keys() const { return 0; }
--- ./sql/sql_parse.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/sql_parse.cc	Wed May 30 11:33:27 2007
@@ -5028,7 +5028,7 @@
     return 1;
   }
 #ifndef DBUG_OFF
-  max_stack_used= max(max_stack_used, stack_used);
+  max_stack_used= MAX(max_stack_used, stack_used);
 #endif
   return 0;
 }
--- ./sql/protocol.cc.orig	Fri Mar 23 22:08:28 2007
+++ ./sql/protocol.cc	Wed May 30 11:33:06 2007
@@ -191,7 +191,7 @@
   length=sizeof(text_pos)-1;
 #endif
   length=my_vsnprintf(my_const_cast(char*) (text_pos),
-                      min(length, sizeof(net->last_error)),
+                      MIN(length, sizeof(net->last_error)),
                       format,args);
   va_end(args);
 
@@ -297,7 +297,7 @@
     pos+=2;
 
     /* We can only return up to 65535 warnings in two bytes */
-    uint tmp= min(thd->total_warn_count, 65535);
+    uint tmp= MIN(thd->total_warn_count, 65535);
     int2store(pos, tmp);
     pos+= 2;
   }
@@ -372,7 +372,7 @@
       Don't send warn count during SP execution, as the warn_list
       is cleared between substatements, and mysqltest gets confused
     */
-    uint tmp= (thd->spcont ? 0 : min(thd->total_warn_count, 65535));
+    uint tmp= (thd->spcont ? 0 : MIN(thd->total_warn_count, 65535));
     buff[0]= 254;
     int2store(buff+1, tmp);
     /*
--- ./sql/rpl_rli.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/rpl_rli.cc	Wed May 30 11:33:27 2007
@@ -664,7 +664,7 @@
     goto err;
   }
   // Convert 0-3 to 4
-  log_pos= max(log_pos, BIN_LOG_HEADER_SIZE);
+  log_pos= MAX(log_pos, BIN_LOG_HEADER_SIZE);
   /* p points to '.' */
   log_name_extension= strtoul(++p, &p_end, 10);
   /*
--- ./sql/sql_select.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/sql_select.cc	Wed May 30 11:33:27 2007
@@ -845,7 +845,7 @@
   }
 #endif
 
-  /* Optimize count(*), MIN() and max() */
+  /* Optimize count(*), MIN() and MAX() */
   if (tables_list && tmp_table_param.sum_func_count && ! group_list)
   {
     int res;
@@ -3579,7 +3579,7 @@
     substitution of field arguments by equal fields. There
     can be not more than cond_equal->max_members such substitutions.
   */ 
-  sz= max(sizeof(KEY_FIELD),sizeof(SARGABLE_PARAM))*
+  sz= MAX(sizeof(KEY_FIELD),sizeof(SARGABLE_PARAM))*
       (((thd->lex->current_select->cond_count+1)*2 +
 	thd->lex->current_select->between_count)*m+1);
   if (!(key_fields=(KEY_FIELD*)	thd->alloc(sz)))
@@ -3732,7 +3732,7 @@
       if (map == 1)			// Only one table
       {
 	TABLE *tmp_table=join->all_tables[tablenr];
-	keyuse->ref_table_rows= max(tmp_table->file->stats.records, 100);
+	keyuse->ref_table_rows= MAX(tmp_table->file->stats.records, 100);
       }
     }
     /*
@@ -5114,7 +5114,7 @@
   {
     uint blob_length=(uint) (join_tab->table->file->stats.mean_rec_length-
 			     (join_tab->table->s->reclength- rec_length));
-    rec_length+=(uint) max(4,blob_length);
+    rec_length+=(uint) MAX(4,blob_length);
   }
   join_tab->used_fields=fields;
   join_tab->used_fieldlength=rec_length;
@@ -6460,7 +6460,7 @@
         a correlated subquery itself, but has subqueries, we can free it
         fully and also free JOINs of all its subqueries. The exception
         is a subquery in SELECT list, e.g:
-        SELECT a, (select max(b) from t1) group by c
+        SELECT a, (select MAX(b) from t1) group by c
         This subquery will not be evaluated at first sweep and its value will
         not be inserted into the temporary table. Instead, it's evaluated
         when selecting from the temporary table. Therefore, it can't be freed
@@ -13205,7 +13205,7 @@
     count++;
   if (!sortorder)
     sortorder= (SORT_FIELD*) sql_alloc(sizeof(SORT_FIELD) *
-                                       (max(count, *length) + 1));
+                                       (MAX(count, *length) + 1));
   pos= sort= sortorder;
 
   if (!pos)
@@ -13322,7 +13322,7 @@
   cache->length=length+blobs*sizeof(char*);
   cache->blobs=blobs;
   *blob_ptr=0;					/* End sequentel */
-  size=max(thd->variables.join_buff_size, cache->length);
+  size=MAX(thd->variables.join_buff_size, cache->length);
   if (!(cache->buff=(uchar*) my_malloc(size,MYF(0))))
     DBUG_RETURN(1);				/* Don't use cache */ /* purecov: inspected */
   cache->end=cache->buff+size;
--- ./sql/sql_string.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/sql_string.cc	Wed May 30 11:49:50 2007
@@ -652,7 +652,7 @@
 {
   if (Alloced_length < str_length + space_needed)
   {
-    if (realloc(Alloced_length + max(space_needed, grow_by) - 1))
+    if (realloc(Alloced_length + MAX(space_needed, grow_by) - 1))
       return TRUE;
   }
   return FALSE;
@@ -896,7 +896,7 @@
 
     if (to_cs == &my_charset_bin)
     {
-      res= MIN(min(nchars, to_length), from_length);
+      res= MIN(MIN(nchars, to_length), from_length);
       memmove(to, from, res);
       *from_end_pos= from + res;
       *well_formed_error_pos= NULL;
--- ./sql/mysqld.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/mysqld.cc	Wed May 30 11:50:41 2007
@@ -2771,7 +2771,7 @@
       can't get max_connections*5 but still got no less than was
       requested (value of wanted_files).
     */
-    max_open_files= max(max(wanted_files, max_connections*5),
+    max_open_files= MAX(MAX(wanted_files, max_connections*5),
                         open_files_limit);
     files= my_set_max_open_files(max_open_files);
 
@@ -2791,7 +2791,7 @@
           never increase table_cache_size automatically (that could
           happen if max_connections is decreased above).
         */
-        table_cache_size= (ulong) MIN(max((files-10-max_connections)/2,
+        table_cache_size= (ulong) MIN(MAX((files-10-max_connections)/2,
                                           TABLE_OPEN_CACHE_MIN),
                                       table_cache_size);    
 	DBUG_PRINT("warning",
@@ -4349,7 +4349,7 @@
 {
   my_socket sock,new_sock;
   uint error_count=0;
-  uint max_used_connection= (uint) (max(ip_sock,unix_sock)+1);
+  uint max_used_connection= (uint) (MAX(ip_sock,unix_sock)+1);
   fd_set readFDs,clientFDs;
   THD *thd;
   struct sockaddr_in cAddr;
--- ./sql/sql_table.cc.orig	Mon May 28 10:08:51 2007
+++ ./sql/sql_table.cc	Wed May 30 11:33:06 2007
@@ -2896,7 +2896,7 @@
 	  if ((length=column->length) > max_key_length ||
 	      length > file->max_key_part_length())
 	  {
-	    length=min(max_key_length, file->max_key_part_length());
+	    length=MIN(max_key_length, file->max_key_part_length());
 	    if (key->type == Key::MULTIPLE)
 	    {
 	      /* not a critical problem */
@@ -4757,14 +4757,14 @@
     if (src_db)
     {
       strmake(src_db_name_buff, src_db,
-              min(sizeof(src_db_name_buff) - 1, table_ident->db.length));
+              MIN(sizeof(src_db_name_buff) - 1, table_ident->db.length));
       my_casedn_str(files_charset_info, src_db_name_buff);
       src_db= src_db_name_buff;
     }
     if (src_table)
     {
       strmake(src_table_name_buff, src_table,
-              min(sizeof(src_table_name_buff) - 1, table_ident->table.length));
+              MIN(sizeof(src_table_name_buff) - 1, table_ident->table.length));
       my_casedn_str(files_charset_info, src_table_name_buff);
       src_table= src_table_name_buff;
     }
--- ./sql/item_strfunc.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/item_strfunc.cc	Wed May 30 11:33:27 2007
@@ -1869,7 +1869,7 @@
   if ((null_value= args[0]->null_value))
     return 0; /* purecov: inspected */
 
-  if (tmp_value.alloc(max(res->length(), 4 * cs->mbminlen)))
+  if (tmp_value.alloc(MAX(res->length(), 4 * cs->mbminlen)))
     return str; /* purecov: inspected */
   char *to= (char *) tmp_value.ptr();
   char *to_end= to + tmp_value.alloced_length();
@@ -2989,7 +2989,7 @@
 
 void Item_func_export_set::fix_length_and_dec()
 {
-  uint length=max(args[1]->max_length,args[2]->max_length);
+  uint length=MAX(args[1]->max_length,args[2]->max_length);
   uint sep_length=(arg_count > 3 ? args[3]->max_length : 1);
   max_length=length*64+sep_length*63;
 
--- ./sql/net_serv.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/net_serv.cc	Wed May 30 11:33:28 2007
@@ -933,7 +933,7 @@
 	len=uint3korr(net->buff+net->where_b);
 	if (!len)				/* End of big multi-packet */
 	  goto end;
-	helping = max(len,*complen) + net->where_b;
+	helping = MAX(len,*complen) + net->where_b;
 	/* The necessary size of net->buff */
 	if (helping >= net->max_packet)
 	{
--- ./sql/sql_show.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/sql_show.cc	Wed May 30 11:33:28 2007
@@ -654,14 +654,14 @@
   {
     field_list.push_back(new Item_empty_string("View",NAME_CHAR_LEN));
     field_list.push_back(new Item_empty_string("Create View",
-                                               max(buffer.length(),1024)));
+                                               MAX(buffer.length(),1024)));
   }
   else
   {
     field_list.push_back(new Item_empty_string("Table",NAME_CHAR_LEN));
     // 1024 is for not to confuse old clients
     field_list.push_back(new Item_empty_string("Create Table",
-                                               max(buffer.length(),1024)));
+                                               MAX(buffer.length(),1024)));
   }
 
   if (protocol->send_fields(&field_list,
--- ./sql/item.cc.orig	Wed May 30 11:33:06 2007
+++ ./sql/item.cc	Wed May 30 11:33:28 2007
@@ -6632,12 +6632,12 @@
     /* fix variable decimals which always is NOT_FIXED_DEC */
     if (Field::result_merge_type(fld_type) == INT_RESULT)
       item_decimals= 0;
-    decimals= max(decimals, item_decimals);
+    decimals= MAX(decimals, item_decimals);
   }
   if (Field::result_merge_type(fld_type) == DECIMAL_RESULT)
   {
-    decimals= MIN(max(decimals, item->decimals), DECIMAL_MAX_SCALE);
-    int precision= MIN(max(prev_decimal_int_part, item->decimal_int_part())
+    decimals= MIN(MAX(decimals, item->decimals), DECIMAL_MAX_SCALE);
+    int precision= MIN(MAX(prev_decimal_int_part, item->decimal_int_part())
                        + decimals, DECIMAL_MAX_PRECISION);
     unsigned_flag&= item->unsigned_flag;
     max_length= my_decimal_precision_to_length(precision, decimals,
@@ -6666,7 +6666,7 @@
       expansion of the size of the values because of character set
       conversions.
      */
-    max_length= max(old_max_chars * collation.collation->mbmaxlen,
+    max_length= MAX(old_max_chars * collation.collation->mbmaxlen,
                     display_length(item) / item->collation.collation->mbmaxlen *
                     collation.collation->mbmaxlen);
     break;
@@ -6677,7 +6677,7 @@
     {
       int delta1= max_length_orig - decimals_orig;
       int delta2= item->max_length - item->decimals;
-      max_length= max(delta1, delta2) + decimals;
+      max_length= MAX(delta1, delta2) + decimals;
       if (fld_type == MYSQL_TYPE_FLOAT && max_length > FLT_DIG + 2) 
       {
         max_length= FLT_DIG + 6;
@@ -6694,7 +6694,7 @@
     break;
   }
   default:
-    max_length= max(max_length, display_length(item));
+    max_length= MAX(max_length, display_length(item));
   };
   maybe_null|= item->maybe_null;
   get_full_info(item);
--- ./sql/sp_head.cc.orig	Mon May 21 11:20:37 2007
+++ ./sql/sp_head.cc	Wed May 30 11:33:27 2007
@@ -2126,7 +2126,7 @@
   field_list.push_back(new Item_empty_string("sql_mode", sql_mode.length));
   // 1024 is for not to confuse old clients
   Item_empty_string *definition=
-    new Item_empty_string("Create Procedure", max(buffer.length(),1024));
+    new Item_empty_string("Create Procedure", MAX(buffer.length(),1024));
   definition->maybe_null= TRUE;
   field_list.push_back(definition);
 
@@ -2191,7 +2191,7 @@
   field_list.push_back(new Item_empty_string("Function",NAME_CHAR_LEN));
   field_list.push_back(new Item_empty_string("sql_mode", sql_mode.length));
   Item_empty_string *definition=
-    new Item_empty_string("Create Function", max(buffer.length(),1024));
+    new Item_empty_string("Create Function", MAX(buffer.length(),1024));
   definition->maybe_null= TRUE;
   field_list.push_back(definition);
 
@@ -2340,7 +2340,7 @@
   field_list.push_back(new Item_uint("Pos", 9));
   // 1024 is for not to confuse old clients
   field_list.push_back(new Item_empty_string("Instruction",
-					     max(buffer.length(), 1024)));
+					     MAX(buffer.length(), 1024)));
   if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS |
                                          Protocol::SEND_EOF))
     DBUG_RETURN(1);
--- ./sql/sql_client.cc.orig	Fri Apr 27 08:47:48 2007
+++ ./sql/sql_client.cc	Wed May 30 11:33:27 2007
@@ -31,7 +31,7 @@
   net->read_timeout= (uint) global_system_variables.net_read_timeout;
   net->write_timeout=(uint) global_system_variables.net_write_timeout;
   net->retry_count=  (uint) global_system_variables.net_retry_count;
-  net->max_packet_size= max(global_system_variables.net_buffer_length,
+  net->max_packet_size= MAX(global_system_variables.net_buffer_length,
 			    global_system_variables.max_allowed_packet);
 #endif
 }
--- ./sql/sql_partition.cc.orig	Mon May 21 11:20:37 2007
+++ ./sql/sql_partition.cc	Wed May 30 11:33:27 2007
@@ -4415,7 +4415,7 @@
             */
             start_part= 0;
             end_part= new_total_partitions - (upper_2n + 1);
-            end_part= max(lower_2n - 1, end_part);
+            end_part= MAX(lower_2n - 1, end_part);
           }
           else if (new_total_partitions <= upper_2n)
           {
--- ./sql/sql_repl.cc.orig	Wed May  9 14:45:12 2007
+++ ./sql/sql_repl.cc	Wed May 30 11:33:27 2007
@@ -1189,12 +1189,12 @@
    {
      /*
        Sometimes mi->rli.master_log_pos == 0 (it happens when the SQL thread is
-       not initialized), so we use a max().
+       not initialized), so we use a MAX().
        What happens to mi->rli.master_log_pos during the initialization stages
        of replication is not 100% clear, so we guard against problems using
-       max().
+       MAX().
       */
-     mi->master_log_pos = max(BIN_LOG_HEADER_SIZE,
+     mi->master_log_pos = MAX(BIN_LOG_HEADER_SIZE,
 			      mi->rli.group_master_log_pos);
      strmake(mi->master_log_name, mi->rli.group_master_log_name,
              sizeof(mi->master_log_name)-1);
@@ -1339,7 +1339,7 @@
     LEX_MASTER_INFO *lex_mi= &thd->lex->mi;
     SELECT_LEX_UNIT *unit= &thd->lex->unit;
     ha_rows event_count, limit_start, limit_end;
-    my_off_t pos = max(BIN_LOG_HEADER_SIZE, lex_mi->pos); // user-friendly
+    my_off_t pos = MAX(BIN_LOG_HEADER_SIZE, lex_mi->pos); // user-friendly
     char search_file_name[FN_REFLEN], *name;
     const char *log_file_name = lex_mi->log_file_name;
     pthread_mutex_t *log_lock = mysql_bin_log.get_log_lock();
--- ./sql/ha_partition.cc.orig	Wed May  9 14:45:11 2007
+++ ./sql/ha_partition.cc	Wed May 30 11:33:27 2007
@@ -2755,7 +2755,7 @@
   /*
     TODO:
       set_internal_auto_increment=
-        max(set_internal_auto_increment, new_data->auto_increment)
+        MAX(set_internal_auto_increment, new_data->auto_increment)
   */
   m_last_part= new_part_id;
   if (new_part_id == old_part_id)
--- ./sql/sql_load.cc.orig	Fri May 11 16:44:06 2007
+++ ./sql/sql_load.cc	Wed May 30 11:33:28 2007
@@ -910,7 +910,7 @@
 
 
   /* Set of a stack for unget if long terminators */
-  uint length=max(field_term_length,line_term_length)+1;
+  uint length=MAX(field_term_length,line_term_length)+1;
   set_if_bigger(length,line_start.length());
   stack=stack_pos=(int*) sql_alloc(sizeof(int)*length);
 
--- ./sql/sql_yacc.yy.orig	Wed May 30 11:59:05 2007
+++ ./sql/sql_yacc.yy	Wed May 30 11:53:04 2007
@@ -1543,7 +1543,7 @@
               from 0" (4 in fact), unspecified means "don't change the position
               (keep the preceding value)").
            */
-           Lex->mi.pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.pos);
+           Lex->mi.pos = MAX(BIN_LOG_HEADER_SIZE, Lex->mi.pos);
          }
        | RELAY_LOG_FILE_SYM EQ TEXT_STRING_sys
          {
@@ -1553,7 +1553,7 @@
          {
            Lex->mi.relay_log_pos = $3;
            /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
-           Lex->mi.relay_log_pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
+           Lex->mi.relay_log_pos = MAX(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
          }
        ;
 
--- ./vio/viosocket.c.orig	Fri Apr 27 08:47:49 2007
+++ ./vio/viosocket.c	Wed May 30 11:33:06 2007
@@ -69,7 +69,7 @@
 
   if (vio->read_pos < vio->read_end)
   {
-    rc= min(vio->read_end - vio->read_pos, size);
+    rc= MIN(vio->read_end - vio->read_pos, size);
     memcpy(buf, vio->read_pos, rc);
     vio->read_pos+= rc;
     /*
--- ./dbug/dbug.c.orig	Wed May 30 11:33:06 2007
+++ ./dbug/dbug.c	Wed May 30 11:33:28 2007
@@ -1176,7 +1176,7 @@
     if (TRACING)
     {
       Indent(cs, cs->level + 1);
-      pos= MIN(max(cs->level-cs->stack->sub_level,0)*INDENT,80);
+      pos= MIN(MAX(cs->level-cs->stack->sub_level,0)*INDENT,80);
     }
     else
     {
@@ -1660,7 +1660,7 @@
 {
   REGISTER int count;
 
-  indent= max(indent-1-cs->stack->sub_level,0)*INDENT;
+  indent= MAX(indent-1-cs->stack->sub_level,0)*INDENT;
   for (count= 0; count < indent ; count++)
   {
     if ((count % INDENT) == 0)
--- ./libmysqld/lib_sql.cc.orig	Thu Mar 22 10:20:46 2007
+++ ./libmysqld/lib_sql.cc	Wed May 30 11:33:06 2007
@@ -791,7 +791,7 @@
     is cleared between substatements, and mysqltest gets confused
   */
   thd->cur_data->embedded_info->warning_count=
-    (thd->spcont ? 0 : min(thd->total_warn_count, 65535));
+    (thd->spcont ? 0 : MIN(thd->total_warn_count, 65535));
 }
 
 
--- ./sql-common/client.c.orig	Mon Apr 16 17:08:28 2007
+++ ./sql-common/client.c	Wed May 30 11:33:06 2007
@@ -617,7 +617,7 @@
 	pos+= SQLSTATE_LENGTH+1;
       }
       (void) strmake(net->last_error,(char*) pos,
-		     min((uint) len,(uint) sizeof(net->last_error)-1));
+		     MIN((uint) len,(uint) sizeof(net->last_error)-1));
     }
     else
       set_mysql_error(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate);
@@ -2013,7 +2013,7 @@
 	goto error;
       }
       memcpy(&sock_addr.sin_addr, hp->h_addr,
-             min(sizeof(sock_addr.sin_addr), (size_t) hp->h_length));
+             MIN(sizeof(sock_addr.sin_addr), (size_t) hp->h_length));
       my_gethostbyname_r_free();
     }
     sock_addr.sin_port = (ushort) htons((ushort) port);
--- ./sql-common/my_time.c.orig	Thu May 24 09:45:11 2007
+++ ./sql-common/my_time.c	Wed May 30 11:33:28 2007
@@ -251,7 +251,7 @@
     2003-03-03 20:00:20 AM
     20:00:20.000000 AM 03-03-2000
   */
-  i= max((uint) format_position[0], (uint) format_position[1]);
+  i= MAX((uint) format_position[0], (uint) format_position[1]);
   set_if_bigger(i, (uint) format_position[2]);
   allow_space= ((1 << i) | (1 << format_position[6]));
   allow_space&= (1 | 2 | 4 | 8);
--- ./mysys/my_handler.c.orig	Wed Mar 28 21:05:01 2007
+++ ./mysys/my_handler.c	Wed May 30 11:33:06 2007
@@ -33,7 +33,7 @@
 static int compare_bin(uchar *a, uint a_length, uchar *b, uint b_length,
                        my_bool part_key, my_bool skip_end_space)
 {
-  uint length= min(a_length,b_length);
+  uint length= MIN(a_length,b_length);
   uchar *end= a+ length;
   int flag;
 
@@ -161,7 +161,7 @@
         continue;                               /* To next key part */
       }
     }
-    end= a+ min(keyseg->length,key_length);
+    end= a+ MIN(keyseg->length,key_length);
     next_key_length=key_length-keyseg->length;
 
     switch ((enum ha_base_keytype) keyseg->type) {
--- ./mysys/safemalloc.c.orig	Fri Apr 13 09:25:35 2007
+++ ./mysys/safemalloc.c	Wed May 30 11:33:06 2007
@@ -237,7 +237,7 @@
 
   if ((data= _mymalloc(size,filename,lineno,MyFlags))) /* Allocate new area */
   {
-    size=min(size, irem->datasize);		/* Move as much as possibly */
+    size=MIN(size, irem->datasize);		/* Move as much as possibly */
     memcpy((byte*) data, ptr, (size_t) size);	/* Copy old data */
     _myfree(ptr, filename, lineno, 0);		/* Free not needed area */
   }
--- ./mysys/testhash.c.orig	Fri Apr 27 08:47:51 2007
+++ ./mysys/testhash.c	Wed May 30 11:33:06 2007
@@ -79,7 +79,7 @@
 
   for (i=0 ; i < recant ; i++)
   {
-    n1=rnd(1000); n2=rnd(100); n3=rnd(min(recant*5,MAX_RECORDS));
+    n1=rnd(1000); n2=rnd(100); n3=rnd(MIN(recant*5,MAX_RECORDS));
     record= (char*) my_malloc(reclength,MYF(MY_FAE));
     sprintf(record,"%6d:%4d:%8d:Pos: %4d      ",n1,n2,n3,write_count);
     if (my_hash_insert(&hash,record))
@@ -133,7 +133,7 @@
   printf("- Update\n");
   for (i=0 ; i < write_count/10 ; i++)
   {
-    n1=rnd(1000); n2=rnd(100); n3=rnd(min(recant*2,MAX_RECORDS));
+    n1=rnd(1000); n2=rnd(100); n3=rnd(MIN(recant*2,MAX_RECORDS));
     for (j=rnd(1000) ; j>0 && key1[j] == 0 ; j--) ;
     if (j)
     {
--- ./mysys/mf_format.c.orig	Fri Apr 27 08:47:51 2007
+++ ./mysys/mf_format.c	Wed May 30 11:33:06 2007
@@ -81,7 +81,7 @@
       return NullS;
     tmp_length=strlength(startpos);
     DBUG_PRINT("error",("dev: '%s'  ext: '%s'  length: %d",dev,ext,length));
-    (void) strmake(to,startpos,min(tmp_length,FN_REFLEN-1));
+    (void) strmake(to,startpos,MIN(tmp_length,FN_REFLEN-1));
   }
   else
   {
--- ./mysys/my_conio.c.orig	Fri Apr 27 08:47:49 2007
+++ ./mysys/my_conio.c	Wed May 30 11:33:06 2007
@@ -164,13 +164,13 @@
     though it is known it should not be more than 64K               
     so we cut 64K and try first size of screen buffer               
     if it is still to large we cut half of it and try again         
-    later we may want to cycle from min(clen, 65535) to allowed size
+    later we may want to cycle from MIN(clen, 65535) to allowed size
     with small decrement to determine exact allowed buffer           
   */
-  clen= min(clen, 65535);
+  clen= MIN(clen, 65535);
   do
   {
-    clen= min(clen, (unsigned long)csbi.dwSize.X*csbi.dwSize.Y);
+    clen= MIN(clen, (unsigned long)csbi.dwSize.X*csbi.dwSize.Y);
     if (!ReadConsole((HANDLE)my_coninpfh, (LPVOID)buffer, clen - 1, plen, NULL))
     {
       result= NULL;
--- ./mysys/mf_dirname.c.orig	Fri Apr 27 08:47:52 2007
+++ ./mysys/mf_dirname.c	Wed May 30 11:33:06 2007
@@ -72,7 +72,7 @@
   SYNPOSIS
     convert_dirname()
     to				Store result here. Must be at least of size
-    				min(FN_REFLEN, strlen(from) + 1) to make room
+    				MIN(FN_REFLEN, strlen(from) + 1) to make room
     				for adding FN_LIBCHAR at the end.
     from			Original filename. May be == to
     from_end			Pointer at end of filename (normally end \0)
--- ./mysys/my_static.h.orig	Fri Mar 23 12:01:47 2007
+++ ./mysys/my_static.h	Wed May 30 11:33:06 2007
@@ -22,7 +22,7 @@
 #include <signal.h>
 
 #define MAX_SIGNALS	10		/* Max signals under a dont-allow */
-#define MIN_KEYBLOCK	(min(IO_SIZE,1024))
+#define MIN_KEYBLOCK	(MIN(IO_SIZE,1024))
 #define MAX_KEYBLOCK	8192		/* Max keyblocklength == 8*IO_SIZE */
 #define MAX_BLOCK_TYPES MAX_KEYBLOCK/MIN_KEYBLOCK
 
--- ./mysys/my_compress.c.orig	Fri Apr 27 08:47:54 2007
+++ ./mysys/my_compress.c	Wed May 30 11:33:28 2007
@@ -206,7 +206,7 @@
 
    if (ver != 1)
      DBUG_RETURN(1);
-   if (!(data= my_malloc(max(orglen, complen), MYF(MY_WME))))
+   if (!(data= my_malloc(MAX(orglen, complen), MYF(MY_WME))))
      DBUG_RETURN(2);
    memcpy(data, blob->data, complen);
 
--- ./mysys/mf_iocache.c.orig	Wed Mar 28 21:05:01 2007
+++ ./mysys/mf_iocache.c	Wed May 30 11:33:06 2007
@@ -1090,7 +1090,7 @@
   */
   while (write_length)
   {
-    uint copy_length= min(write_length, write_cache->buffer_length);
+    uint copy_length= MIN(write_length, write_cache->buffer_length);
     int  __attribute__((unused)) rc;
 
     rc= lock_io_cache(write_cache, write_cache->pos_in_file);
@@ -1250,7 +1250,7 @@
       TODO: figure out if the assert below is needed or correct.
     */
     DBUG_ASSERT(pos_in_file == info->end_of_file);
-    copy_len=min(Count, len_in_buff);
+    copy_len=MIN(Count, len_in_buff);
     memcpy(Buffer, info->append_read_pos, copy_len);
     info->append_read_pos += copy_len;
     Count -= copy_len;
@@ -1358,7 +1358,7 @@
     }
 #endif
 	/* Copy found bytes to buffer */
-    length=min(Count,read_length);
+    length=MIN(Count,read_length);
     memcpy(Buffer,info->read_pos,(size_t) length);
     Buffer+=length;
     Count-=length;
@@ -1392,7 +1392,7 @@
       if ((read_length=my_read(info->file,info->request_pos,
 			       read_length, info->myflags)) == (uint) -1)
         return info->error= -1;
-      use_length=min(Count,read_length);
+      use_length=MIN(Count,read_length);
       memcpy(Buffer,info->request_pos,(size_t) use_length);
       info->read_pos=info->request_pos+Count;
       info->read_end=info->request_pos+read_length;
--- ./mysys/default.c.orig	Thu May  3 10:16:43 2007
+++ ./mysys/default.c	Wed May 30 11:33:06 2007
@@ -721,7 +721,7 @@
       for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;/* Remove end space */
       end[0]=0;
 
-      strnmov(curr_gr, ptr, min((uint) (end-ptr)+1, 4096));
+      strnmov(curr_gr, ptr, MIN((uint) (end-ptr)+1, 4096));
 
       /* signal that a new group is found */
       opt_handler(handler_ctx, curr_gr, NULL);
--- ./mysys/my_bitmap.c.orig	Mon Jan 29 01:47:29 2007
+++ ./mysys/my_bitmap.c	Wed May 30 11:33:06 2007
@@ -364,7 +364,7 @@
 
   DBUG_ASSERT(map->bitmap && map2->bitmap);
 
-  end= to+min(len,len2);
+  end= to+MIN(len,len2);
   *map2->last_word_ptr&= ~map2->last_word_mask; /*Clear last bits in map2*/
   while (to < end)
     *to++ &= *from++;
--- ./mysys/my_file.c.orig	Wed May 30 11:33:06 2007
+++ ./mysys/my_file.c	Wed May 30 11:33:28 2007
@@ -109,7 +109,7 @@
   memcpy((char*) tmp, (char*) my_file_info,
          sizeof(*tmp) * MIN(my_file_limit, files));
   bzero((char*) (tmp + my_file_limit),
-        max((int) (files- my_file_limit), 0)*sizeof(*tmp));
+        MAX((int) (files- my_file_limit), 0)*sizeof(*tmp));
   my_free_open_file_info();			/* Free if already allocated */
   my_file_info= tmp;
   my_file_limit= files;
--- ./mysys/my_getopt.c.orig	Wed May  9 14:45:11 2007
+++ ./mysys/my_getopt.c	Wed May 30 11:33:28 2007
@@ -766,7 +766,7 @@
     num= (ulonglong) optp->max_value;
   num= ((num - optp->sub_size) / block_size);
   num= (longlong) (num * block_size);
-  return max(num, optp->min_value);
+  return MAX(num, optp->min_value);
 }
 
 /*
--- ./mysys/array.c.orig	Wed May  9 14:45:11 2007
+++ ./mysys/array.c	Wed May 30 11:33:28 2007
@@ -47,7 +47,7 @@
   DBUG_ENTER("init_dynamic_array");
   if (!alloc_increment)
   {
-    alloc_increment=max((8192-MALLOC_OVERHEAD)/element_size,16);
+    alloc_increment=MAX((8192-MALLOC_OVERHEAD)/element_size,16);
     if (init_alloc > 8 && alloc_increment > init_alloc * 2)
       alloc_increment=init_alloc*2;
   }
@@ -313,7 +313,7 @@
 
 void freeze_size(DYNAMIC_ARRAY *array)
 {
-  uint elements=max(array->elements,1);
+  uint elements=MAX(array->elements,1);
 
   /*
     Do nothing if we are using a static buffer
--- ./mysys/my_alloc.c.orig	Thu Apr 19 05:00:10 2007
+++ ./mysys/my_alloc.c	Wed May 30 11:33:28 2007
@@ -196,7 +196,7 @@
   {						/* Time to alloc new block */
     block_size= mem_root->block_size * (mem_root->block_num >> 2);
     get_size= Size+ALIGN_SIZE(sizeof(USED_MEM));
-    get_size= max(get_size, block_size);
+    get_size= MAX(get_size, block_size);
 
     if (!(next = (USED_MEM*) my_malloc(get_size,MYF(MY_WME))))
     {
--- ./tests/mysql_client_test.c.orig	Thu May  3 10:16:45 2007
+++ ./tests/mysql_client_test.c	Wed May 30 11:33:06 2007
@@ -567,7 +567,7 @@
     return row_count;
   }
 
-  field_count= min(mysql_num_fields(result), MAX_RES_FIELDS);
+  field_count= MIN(mysql_num_fields(result), MAX_RES_FIELDS);
 
   bzero((char*) buffer, sizeof(buffer));
   bzero((char*) length, sizeof(length));
--- ./include/my_global.h.orig	Wed May 30 11:33:06 2007
+++ ./include/my_global.h	Wed May 30 11:37:54 2007
@@ -562,8 +562,8 @@
 #endif
 
 /* Define some useful general macros */
-#if !defined(max)
-#define max(a, b)	((a) > (b) ? (a) : (b))
+#if !defined(MAX)
+#define MAX(a, b)	((a) > (b) ? (a) : (b))
 #define MIN(a, b)	((a) < (b) ? (a) : (b))
 #endif
 
--- ./libmysql/libmysql.c.orig	Wed May 30 11:33:06 2007
+++ ./libmysql/libmysql.c	Wed May 30 11:33:28 2007
@@ -1525,7 +1525,7 @@
   net->read_timeout= (uint) net_read_timeout;
   net->write_timeout=(uint) net_write_timeout;
   net->retry_count=  1;
-  net->max_packet_size= max(net_buffer_length, max_allowed_packet);
+  net->max_packet_size= MAX(net_buffer_length, max_allowed_packet);
 }
 
 /*
--- ./server-tools/instance-manager/buffer.cc.orig	Wed May 30 11:33:06 2007
+++ ./server-tools/instance-manager/buffer.cc	Wed May 30 11:33:28 2007
@@ -84,7 +84,7 @@
   {
     buffer= (char*) my_realloc(buffer,
                                 MIN(MAX_BUFFER_SIZE,
-                                    max((uint) (buffer_size*1.5),
+                                    MAX((uint) (buffer_size*1.5),
                                         position + len_arg)), MYF(0));
     if (!(buffer))
       goto err;
--- ./server-tools/instance-manager/listener.cc.orig	Thu Feb 22 20:59:41 2007
+++ ./server-tools/instance-manager/listener.cc	Wed May 30 11:33:28 2007
@@ -102,7 +102,7 @@
 
   /* II. Listen sockets and spawn childs */
   for (i= 0; i < num_sockets; i++)
-    n= max(n, sockets[i]);
+    n= MAX(n, sockets[i]);
   n++;
 
   timeval tv;
--- ./storage/example/ha_example.h.orig	Sat Mar 17 01:13:19 2007
+++ ./storage/example/ha_example.h	Wed May 30 11:33:06 2007
@@ -105,14 +105,14 @@
     max_supported_key_parts(), uint max_supported_key_length()
     to make sure that the storage engine can handle the data it is about to
     send. Return *real* limits of your storage engine here; MySQL will do
-    min(your_limits, MySQL_limits) automatically.
+    MIN(your_limits, MySQL_limits) automatically.
    */
   uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; }
 
   /** @brief
     unireg.cc will call this to make sure that the storage engine can handle
     the data it is about to send. Return *real* limits of your storage engine
-    here; MySQL will do min(your_limits, MySQL_limits) automatically.
+    here; MySQL will do MIN(your_limits, MySQL_limits) automatically.
 
       @details
     There is no need to implement ..._key_... methods if your engine doesn't
@@ -123,7 +123,7 @@
   /** @brief
     unireg.cc will call this to make sure that the storage engine can handle
     the data it is about to send. Return *real* limits of your storage engine
-    here; MySQL will do min(your_limits, MySQL_limits) automatically.
+    here; MySQL will do MIN(your_limits, MySQL_limits) automatically.
 
       @details
     There is no need to implement ..._key_... methods if your engine doesn't
@@ -134,7 +134,7 @@
   /** @brief
     unireg.cc will call this to make sure that the storage engine can handle
     the data it is about to send. Return *real* limits of your storage engine
-    here; MySQL will do min(your_limits, MySQL_limits) automatically.
+    here; MySQL will do MIN(your_limits, MySQL_limits) automatically.
 
       @details
     There is no need to implement ..._key_... methods if your engine doesn't
--- ./storage/ndb/test/src/getarg.c.orig	Fri Apr 27 08:47:51 2007
+++ ./storage/ndb/test/src/getarg.c	Wed May 30 11:33:28 2007
@@ -66,7 +66,7 @@
 #define ISFLAG(X) ((X).type == arg_flag || (X).type == arg_negative_flag)
 
 #ifndef max
-#define max(a, b) (a) > (b) ? (a) : (b)
+#define MAX(a, b) (a) > (b) ? (a) : (b)
 #endif
 
 #ifdef HAVE___PROGNAME
@@ -306,7 +306,7 @@
 	}
 	if (args[i].long_name && args[i].short_name)
 	    len += 2; /* ", " */
-	max_len = max(max_len, len);
+	max_len = MAX(max_len, len);
     }
     if (extra_string) {
 	col = check_column(stderr, col, strlen(extra_string) + 1, columns);
--- ./storage/heap/hp_test2.c.orig	Fri Apr 27 08:47:47 2007
+++ ./storage/heap/hp_test2.c	Wed May 30 11:33:06 2007
@@ -136,7 +136,7 @@
 
   for (i=0 ; i < recant ; i++)
   {
-    n1=rnd(1000); n2=rnd(100); n3=rnd(min(recant*5,MAX_RECORDS));
+    n1=rnd(1000); n2=rnd(100); n3=rnd(MIN(recant*5,MAX_RECORDS));
     make_record(record,n1,n2,n3,"Pos",write_count);
 
     if (heap_write(file,record))
@@ -217,7 +217,7 @@
   printf("- Update\n");
   for (i=0 ; i < write_count/10 ; i++)
   {
-    n1=rnd(1000); n2=rnd(100); n3=rnd(min(recant*2,MAX_RECORDS));
+    n1=rnd(1000); n2=rnd(100); n3=rnd(MIN(recant*2,MAX_RECORDS));
     make_record(record2, n1, n2, n3, "XXX", update);
     if (rnd(2) == 1)
     {
--- ./storage/heap/hp_create.c.orig	Fri Apr 27 08:47:50 2007
+++ ./storage/heap/hp_create.c	Wed May 30 11:33:28 2007
@@ -215,7 +215,7 @@
 {
   uint i,recbuffer,records_in_block;
 
-  max_records= max(min_records,max_records);
+  max_records= MAX(min_records,max_records);
   if (!max_records)
     max_records= 1000;			/* As good as quess as anything */
   recbuffer= (uint) (reclength + sizeof(byte**) - 1) & ~(sizeof(byte**) - 1);
--- ./storage/myisammrg/ha_myisammrg.cc.orig	Wed May  9 14:45:12 2007
+++ ./storage/myisammrg/ha_myisammrg.cc	Wed May 30 11:33:06 2007
@@ -351,7 +351,7 @@
       memcpy((char*) table->key_info[0].rec_per_key,
 	     (char*) mrg_info.rec_per_key,
              sizeof(table->key_info[0].rec_per_key) *
-             min(file->keys, table->s->key_parts));
+             MIN(file->keys, table->s->key_parts));
     }
   }
   return 0;
--- ./storage/innobase/handler/ha_innodb.cc.orig	Wed May  9 14:45:12 2007
+++ ./storage/innobase/handler/ha_innodb.cc	Wed May 30 11:33:28 2007
@@ -7057,7 +7057,7 @@
 			goto func_exit;
 		}
 	} else {
-		/* Initialize to max(col) + 1; we use
+		/* Initialize to MAX(col) + 1; we use
 		'found_next_number_field' below because MySQL in SHOW TABLE
 		STATUS does not seem to set 'next_number_field'. The comment
 		in table.h says that 'next_number_field' is set when it is
--- ./storage/innobase/include/ut0byte.h.orig	Wed May 30 11:33:06 2007
+++ ./storage/innobase/include/ut0byte.h	Wed May 30 11:33:28 2007
@@ -87,7 +87,7 @@
 dulint
 ut_dulint_get_max(
 /*==============*/
-			/* out: max(a, b) */
+			/* out: MAX(a, b) */
 	dulint	a,	/* in: dulint */
 	dulint	b);	/* in: dulint */
 /***********************************************************
--- ./storage/csv/ha_tina.cc.orig	Fri Mar  9 12:12:27 2007
+++ ./storage/csv/ha_tina.cc	Wed May 30 11:33:06 2007
@@ -1127,7 +1127,7 @@
   if (closest_hole == chain_ptr) /* no more chains */
     *end_pos= file_buff->end();
   else
-    *end_pos= min(file_buff->end(),
+    *end_pos= MIN(file_buff->end(),
                   closest_hole->begin);
   return (closest_hole != chain_ptr) && (*end_pos == closest_hole->begin);
 }
@@ -1336,7 +1336,7 @@
   /* write repaired file */
   while (1)
   {
-    write_end= min(file_buff->end(), current_position);
+    write_end= MIN(file_buff->end(), current_position);
     if ((write_end - write_begin) &&
         (my_write(repair_file, (byte*)file_buff->ptr(),
                   write_end - write_begin, MYF_RW)))
--- ./storage/myisam/mi_packrec.c.orig	Wed May 30 11:33:06 2007
+++ ./storage/myisam/mi_packrec.c	Wed May 30 11:33:28 2007
@@ -677,7 +677,7 @@
       return OFFSET_TABLE_SIZE;
     }
     length2= find_longest_bitstream(next, end) + 1;
-    length=max(length,length2);
+    length=MAX(length,length2);
   }
   return length;
 }
--- ./storage/myisam/rt_mbr.c.orig	Wed May 30 11:33:06 2007
+++ ./storage/myisam/rt_mbr.c	Wed May 30 11:33:28 2007
@@ -326,7 +326,7 @@
   amax = korr_func(a+len); \
   bmax = korr_func(b+len); \
   amin = MIN(amin, bmin); \
-  amax = max(amax, bmax); \
+  amax = MAX(amax, bmax); \
   store_func(c, amin); \
   store_func(c+len, amax); \
 }
@@ -339,7 +339,7 @@
   get_func(amax, a+len); \
   get_func(bmax, b+len); \
   amin = MIN(amin, bmin); \
-  amax = max(amax, bmax); \
+  amax = MAX(amax, bmax); \
   store_func(c, amin); \
   store_func(c+len, amax); \
 }
@@ -417,7 +417,7 @@
   bmin = korr_func(b); \
   amax = korr_func(a+len); \
   bmax = korr_func(b+len); \
-  amin = max(amin, bmin); \
+  amin = MAX(amin, bmin); \
   amax = MIN(amax, bmax); \
   if (amin >= amax) \
     return 0; \
@@ -431,7 +431,7 @@
   get_func(bmin, b); \
   get_func(amax, a+len); \
   get_func(bmax, b+len); \
-  amin = max(amin, bmin); \
+  amin = MAX(amin, bmin); \
   amax = MIN(amax, bmax); \
   if (amin >= amax)  \
     return 0; \
@@ -508,7 +508,7 @@
    amax = korr_func(a+len); \
    bmax = korr_func(b+len); \
    a_area *= (((double)amax) - ((double)amin)); \
-   loc_ab_area *= ((double)max(amax, bmax) - (double)MIN(amin, bmin)); \
+   loc_ab_area *= ((double)MAX(amax, bmax) - (double)MIN(amin, bmin)); \
 }
 
 #define RT_AREA_INC_GET(type, get_func, len)\
@@ -519,7 +519,7 @@
    get_func(amax, a+len); \
    get_func(bmax, b+len); \
    a_area *= (((double)amax) - ((double)amin)); \
-   loc_ab_area *= ((double)max(amax, bmax) - (double)MIN(amin, bmin)); \
+   loc_ab_area *= ((double)MAX(amax, bmax) - (double)MIN(amin, bmin)); \
 }
 
 /*
@@ -601,7 +601,7 @@
    amax = korr_func(a+len); \
    bmax = korr_func(b+len); \
    a_perim+= (((double)amax) - ((double)amin)); \
-   *ab_perim+= ((double)max(amax, bmax) - (double)MIN(amin, bmin)); \
+   *ab_perim+= ((double)MAX(amax, bmax) - (double)MIN(amin, bmin)); \
 }
 
 #define RT_PERIM_INC_GET(type, get_func, len)\
@@ -612,7 +612,7 @@
    get_func(amax, a+len); \
    get_func(bmax, b+len); \
    a_perim+= (((double)amax) - ((double)amin)); \
-   *ab_perim+= ((double)max(amax, bmax) - (double)MIN(amin, bmin)); \
+   *ab_perim+= ((double)MAX(amax, bmax) - (double)MIN(amin, bmin)); \
 }
 
 /*
--- ./storage/myisam/mi_dynrec.c.orig	Wed Mar 28 21:05:08 2007
+++ ./storage/myisam/mi_dynrec.c	Wed May 30 11:33:06 2007
@@ -782,7 +782,7 @@
 	uint tmp=MY_ALIGN(reclength - length + 3 +
 			  test(reclength >= 65520L),MI_DYN_ALIGN_SIZE);
 	/* Don't create a block bigger than MI_MAX_BLOCK_LENGTH */
-	tmp= min(length+tmp, MI_MAX_BLOCK_LENGTH)-length;
+	tmp= MIN(length+tmp, MI_MAX_BLOCK_LENGTH)-length;
 	/* Check if we can extend this block */
 	if (block_info.filepos + block_info.block_len ==
 	    info->state->data_file_length &&
--- ./storage/myisam/mi_open.c.orig	Wed May 30 11:33:06 2007
+++ ./storage/myisam/mi_open.c	Wed May 30 11:33:28 2007
@@ -697,7 +697,7 @@
     /* to simplify initial init of info->rec_buf in mi_open and mi_extra */
     if (length == (ulong) -1)
     {
-      length= max(info->s->base.pack_reclength,
+      length= MAX(info->s->base.pack_reclength,
                   info->s->base.max_key_length);
       /* Avoid unnecessary realloc */
       if (newptr && length == old_length)
--- ./storage/myisam/mi_create.c.orig	Wed May 30 11:33:06 2007
+++ ./storage/myisam/mi_create.c	Wed May 30 11:33:28 2007
@@ -438,7 +438,7 @@
     block_length= (keydef->block_length ? 
                    my_round_up_to_next_power(keydef->block_length) :
                    myisam_block_size);
-    block_length= max(block_length, MI_MIN_KEY_BLOCK_LENGTH);
+    block_length= MAX(block_length, MI_MIN_KEY_BLOCK_LENGTH);
     block_length= MIN(block_length, MI_MAX_KEY_BLOCK_LENGTH);
 
     keydef->block_length= (uint16) MI_BLOCK_SIZE(length-real_length_diff,
@@ -528,7 +528,7 @@
     got from MYI file header (see also myisampack.c:save_state)
   */
   share.base.key_reflength=
-    mi_get_pointer_length(max(ci->key_file_length,tmp),3);
+    mi_get_pointer_length(MAX(ci->key_file_length,tmp),3);
   share.base.keys= share.state.header.keys= keys;
   share.state.header.uniques= uniques;
   share.state.header.fulltext_keys= fulltext_keys;
@@ -566,7 +566,7 @@
   share.base.min_block_length=
     (share.base.pack_reclength+3 < MI_EXTEND_BLOCK_LENGTH &&
      ! share.base.blobs) ?
-    max(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
+    MAX(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
     MI_EXTEND_BLOCK_LENGTH;
   if (! (flags & HA_DONT_TOUCH_DATA))
     share.state.create_time= (long) time((time_t*) 0);
--- ./storage/myisam/mi_test2.c.orig	Fri Apr 27 08:47:52 2007
+++ ./storage/myisam/mi_test2.c	Wed May 30 11:33:06 2007
@@ -597,7 +597,7 @@
     goto err;
 
   bmove(read_record2,read_record,reclength);
-  for (i=min(2,keys) ; i-- > 0 ;)
+  for (i=MIN(2,keys) ; i-- > 0 ;)
   {
     if (mi_rsame(file,read_record2,(int) i)) goto err;
     if (bcmp(read_record,read_record2,reclength) != 0)
--- ./storage/myisam/mi_cache.c.orig	Fri Apr 27 08:47:54 2007
+++ ./storage/myisam/mi_cache.c	Wed May 30 11:33:06 2007
@@ -61,7 +61,7 @@
       (my_off_t) (info->read_end - info->request_pos))
   {
     in_buff_pos=info->request_pos+(uint) offset;
-    in_buff_length= min(length,(uint) (info->read_end-in_buff_pos));
+    in_buff_length= MIN(length,(uint) (info->read_end-in_buff_pos));
     memcpy(buff,info->request_pos+(uint) offset,(size_t) in_buff_length);
     if (!(length-=in_buff_length))
       DBUG_RETURN(0);
--- ./storage/myisam/sort.c.orig	Wed May 30 11:33:06 2007
+++ ./storage/myisam/sort.c	Wed May 30 11:33:28 2007
@@ -131,7 +131,7 @@
   sort_keys= (uchar **) NULL; error= 1;
   maxbuffer=1;
 
-  memavl=max(sortbuff_size,MIN_SORT_MEMORY);
+  memavl=MAX(sortbuff_size,MIN_SORT_MEMORY);
   records=	info->sort_info->max_records;
   sort_length=	info->key_length;
   LINT_INIT(keys);
@@ -347,7 +347,7 @@
     bzero((char*) &sort_param->unique,  sizeof(sort_param->unique));
     sort_keys= (uchar **) NULL;
 
-    memavl=       max(sort_param->sortbuff_size, MIN_SORT_MEMORY);
+    memavl=       MAX(sort_param->sortbuff_size, MIN_SORT_MEMORY);
     idx=          sort_param->sort_info->max_records;
     sort_length=  sort_param->key_length;
     maxbuffer=    1;
--- ./storage/myisam/mi_extra.c.orig	Tue Mar 13 17:43:41 2007
+++ ./storage/myisam/mi_extra.c	Wed May 30 11:33:06 2007
@@ -99,7 +99,7 @@
       cache_size= (extra_arg ? *(ulong*) extra_arg :
 		   my_default_record_cache_size);
       if (!(init_io_cache(&info->rec_cache,info->dfile,
-			 (uint) min(info->state->data_file_length+1,
+			 (uint) MIN(info->state->data_file_length+1,
 				    cache_size),
 			  READ_CACHE,0L,(pbool) (info->lock_type != F_UNLCK),
 			  MYF(share->write_flag & MY_WAIT_IF_FULL))))
--- ./storage/myisam/myisamlog.c.orig	Fri Apr 27 08:47:50 2007
+++ ./storage/myisam/myisamlog.c	Wed May 30 11:33:06 2007
@@ -88,7 +88,7 @@
   log_filename=myisam_log_filename;
   get_options(&argc,&argv);
   /* Number of MyISAM files we can have open at one time */
-  max_files= (my_set_max_open_files(min(max_files,8))-6)/2;
+  max_files= (my_set_max_open_files(MIN(max_files,8))-6)/2;
   if (update)
     printf("Trying to %s MyISAM files according to log '%s'\n",
 	   (recover ? "recover" : "update"),log_filename);
--- ./storage/myisam/ha_myisam.cc.orig	Mon May 28 10:08:51 2007
+++ ./storage/myisam/ha_myisam.cc	Wed May 30 11:33:06 2007
@@ -1492,7 +1492,7 @@
 {
   DBUG_ENTER("ha_myisam::start_bulk_insert");
   THD *thd= current_thd;
-  ulong size= min(thd->variables.read_buff_size,
+  ulong size= MIN(thd->variables.read_buff_size,
                   table->s->avg_row_length*rows);
   DBUG_PRINT("info",("start_bulk_insert: rows %lu size %lu",
                      (ulong) rows, size));
--- ./storage/myisam/mi_check.c.orig	Wed May 30 11:33:06 2007
+++ ./storage/myisam/mi_check.c	Wed May 30 11:33:28 2007
@@ -2214,7 +2214,7 @@
   init_alloc_root(&sort_param.wordroot, FTPARSER_MEMROOT_ALLOC_SIZE, 0);
 
   if (share->data_file_type == DYNAMIC_RECORD)
-    length=max(share->base.min_pack_length+1,share->base.min_block_length);
+    length=MAX(share->base.min_pack_length+1,share->base.min_block_length);
   else if (share->data_file_type == COMPRESSED_RECORD)
     length=share->base.min_block_length;
   else
@@ -2665,7 +2665,7 @@
     my_seek(param->read_cache.file,0L,MY_SEEK_END,MYF(0));
 
   if (share->data_file_type == DYNAMIC_RECORD)
-    rec_length=max(share->base.min_pack_length+1,share->base.min_block_length);
+    rec_length=MAX(share->base.min_pack_length+1,share->base.min_block_length);
   else if (share->data_file_type == COMPRESSED_RECORD)
     rec_length=share->base.min_block_length;
   else
@@ -3846,7 +3846,7 @@
   ft_buf->buf=ft_buf->lastkey+a_len;
   /*
     32 is just a safety margin here
-    (at least max(val_len, sizeof(nod_flag)) should be there).
+    (at least MAX(val_len, sizeof(nod_flag)) should be there).
     May be better performance could be achieved if we'd put
       (sort_info->keyinfo->block_length-32)/XXX
       instead.
@@ -4197,7 +4197,7 @@
 
   VOID(mi_close(*org_info));
   bzero((char*) &create_info,sizeof(create_info));
-  create_info.max_rows=max(max_records,share.base.records);
+  create_info.max_rows=MAX(max_records,share.base.records);
   create_info.reloc_rows=share.base.reloc;
   create_info.old_options=(share.options |
 			   (unpack ? HA_OPTION_TEMP_COMPRESS_RECORD : 0));
--- ./storage/myisam/mi_test1.c.orig	Wed Jan  3 11:27:44 2007
+++ ./storage/myisam/mi_test1.c	Wed May 30 11:33:28 2007
@@ -434,7 +434,7 @@
     uint tmp;
     char *ptr;;
     sprintf(blob_record,"... row: %d", rownr);
-    strappend(blob_record,max(MAX_REC_LENGTH-rownr,10),' ');
+    strappend(blob_record,MAX(MAX_REC_LENGTH-rownr,10),' ');
     tmp=strlen(blob_record);
     int4store(pos,tmp);
     ptr=blob_record;
--- ./storage/myisam/myisampack.c.orig	Wed Jan 24 19:57:02 2007
+++ ./storage/myisam/myisampack.c	Wed May 30 11:33:28 2007
@@ -1239,7 +1239,7 @@
     {
       if (huff_counts->field_length > 2 &&
 	  huff_counts->empty_fields + (records - huff_counts->empty_fields)*
-	  (1+max_bit(max(huff_counts->max_pre_space,
+	  (1+max_bit(MAX(huff_counts->max_pre_space,
 			 huff_counts->max_end_space))) <
 	  records * max_bit(huff_counts->field_length))
       {
@@ -3001,7 +3001,7 @@
   if (mrg->src_file_has_indexes_disabled)
   {
     isam_file->s->state.state.key_file_length=
-      max(isam_file->s->state.state.key_file_length, new_length);
+      MAX(isam_file->s->state.state.key_file_length, new_length);
   }
   state.dellink= HA_OFFSET_ERROR;
   state.version=(ulong) time((time_t*) 0);
--- ./storage/federated/ha_federated.cc.orig	Wed May  9 14:45:12 2007
+++ ./storage/federated/ha_federated.cc	Wed May 30 11:33:06 2007
@@ -585,7 +585,7 @@
   int buf_len;
   DBUG_ENTER("ha_federated parse_url_error");
 
-  buf_len= min(table->s->connect_string.length,
+  buf_len= MIN(table->s->connect_string.length,
                FEDERATED_QUERY_BUFFER_SIZE-1);
   strmake(buf, table->s->connect_string.str, buf_len);
   my_error(error_num, MYF(0), buf);
@@ -1323,7 +1323,7 @@
     {
       Field *field= key_part->field;
       uint store_length= key_part->store_length;
-      uint part_length= min(store_length, length);
+      uint part_length= MIN(store_length, length);
       needs_quotes= field->str_needs_quotes();
       DBUG_DUMP("key, start of loop", (char *) ptr, length);
 
--- ./strings/ctype-bin.c.orig	Wed Jan 24 19:57:04 2007
+++ ./strings/ctype-bin.c	Wed May 30 11:33:06 2007
@@ -80,7 +80,7 @@
                                const uchar *t, uint tlen,
                                my_bool t_is_prefix)
 {
-  uint len=min(slen,tlen);
+  uint len=MIN(slen,tlen);
   int cmp= memcmp(s,t,len);
   return cmp ? cmp : (int)((t_is_prefix ? len : slen) - tlen);
 }
@@ -131,7 +131,7 @@
                                  const uchar *t, uint tlen,
                                  my_bool t_is_prefix)
 {
-  uint len=min(slen,tlen);
+  uint len=MIN(slen,tlen);
   int cmp= memcmp(s,t,len);
   return cmp ? cmp : (int)((t_is_prefix ? len : slen) - tlen);
 }
@@ -175,7 +175,7 @@
   diff_if_only_endspace_difference= 0;
 #endif
 
-  end= a + (length= min(a_length, b_length));
+  end= a + (length= MIN(a_length, b_length));
   while (a < end)
   {
     if (*a++ != *b++)
@@ -379,7 +379,7 @@
                            const uchar *src, uint srclen)
 {
   if (dest != src)
-    memcpy(dest, src, min(dstlen,srclen));
+    memcpy(dest, src, MIN(dstlen,srclen));
   if (dstlen > srclen)
     bfill(dest + srclen, dstlen - srclen, 0);
   return dstlen;
@@ -392,7 +392,7 @@
                          const uchar *src, uint srclen)
 {
   if (dest != src)
-    memcpy(dest, src, min(dstlen,srclen));
+    memcpy(dest, src, MIN(dstlen,srclen));
   if (dstlen > srclen)
     bfill(dest + srclen, dstlen - srclen, ' ');
   return dstlen;
--- ./strings/ctype-gbk.c.orig	Fri Apr 27 08:47:55 2007
+++ ./strings/ctype-gbk.c	Wed May 30 11:33:06 2007
@@ -2616,7 +2616,7 @@
                      const uchar *b, uint b_length,
                      my_bool b_is_prefix)
 {
-  uint length= min(a_length, b_length);
+  uint length= MIN(a_length, b_length);
   int res= my_strnncoll_gbk_internal(&a, &b, length);
   return res ? res : (int) ((b_is_prefix ? length : a_length) - b_length);
 }
@@ -2627,7 +2627,7 @@
 			      const uchar *b, uint b_length,
                               my_bool diff_if_only_endspace_difference)
 {
-  uint length= min(a_length, b_length);
+  uint length= MIN(a_length, b_length);
   int res= my_strnncoll_gbk_internal(&a, &b, length);
 
 #ifndef VARCHAR_WITH_DIFF_ENDSPACE_ARE_DIFFERENT_FOR_UNIQUE
--- ./strings/ctype-uca.c.orig	Thu Mar 29 08:32:35 2007
+++ ./strings/ctype-uca.c	Wed May 30 11:33:06 2007
@@ -7566,7 +7566,7 @@
 {
   char tail[30];
   size_t len= lexem->end - lexem->prev;
-  strmake (tail, lexem->prev, (uint) min(len, sizeof(tail)-1));
+  strmake (tail, lexem->prev, (uint) MIN(len, sizeof(tail)-1));
   errstr[errsize-1]= '\0';
   my_snprintf(errstr,errsize-1,"%s at '%s'", txt, tail);
 }
--- ./strings/my_vsnprintf.c.orig	Mon Jan 22 14:10:43 2007
+++ ./strings/my_vsnprintf.c	Wed May 30 11:33:06 2007
@@ -140,7 +140,7 @@
       /* If %#d syntax was used, we have to pre-zero/pre-space the string */
       if (store_start == buff)
       {
-	length= min(length, to_length);
+	length= MIN(length, to_length);
 	if (res_length < length)
 	{
 	  uint diff= (length- res_length);
--- ./strings/ctype-tis620.c.orig	Fri Apr 27 08:47:48 2007
+++ ./strings/ctype-tis620.c	Wed May 30 11:33:06 2007
@@ -581,7 +581,7 @@
   a_length= thai2sortable(a, a_length);
   b_length= thai2sortable(b, b_length);
   
-  end= a + (length= min(a_length, b_length));
+  end= a + (length= MIN(a_length, b_length));
   while (a < end)
   {
     if (*a++ != *b++)
@@ -638,7 +638,7 @@
                        const uchar * src, uint srclen)
 {
   uint dstlen= len;
-  len= (uint) (strmake((char*) dest, (char*) src, min(len, srclen)) -
+  len= (uint) (strmake((char*) dest, (char*) src, MIN(len, srclen)) -
 	       (char*) dest);
   len= thai2sortable(dest, len);
   if (dstlen > len)
--- ./strings/decimal.c.orig	Wed May 30 11:33:06 2007
+++ ./strings/decimal.c	Wed May 30 11:33:28 2007
@@ -1520,8 +1520,8 @@
 
   if (to != from || intg1>intg0)
   {
-    dec1 *p0= buf0+intg0+max(frac1, frac0);
-    dec1 *p1= buf1+intg1+max(frac1, frac0);
+    dec1 *p0= buf0+intg0+MAX(frac1, frac0);
+    dec1 *p1= buf1+intg1+MAX(frac1, frac0);
 
     to->buf[0]= 0;
     while (buf0 < p0)
@@ -1621,7 +1621,7 @@
         scale=frac0*DIG_PER_DEC1;
         error=E_DEC_TRUNCATED; /* XXX */
       }
-      for (buf1=to->buf+intg0+max(frac0,0); buf1 > to->buf; buf1--)
+      for (buf1=to->buf+intg0+MAX(frac0,0); buf1 > to->buf; buf1--)
       {
         buf1[0]=buf1[-1];
       }
@@ -1640,7 +1640,7 @@
         /* making 'zero' with the proper scale */
         dec1 *p0= to->buf + frac0 + 1;
         to->intg=1;
-        to->frac= max(scale, 0);
+        to->frac= MAX(scale, 0);
         to->sign= 0;
         for (buf1= to->buf; buf1<p0; buf1++)
           *buf1= 0;
@@ -1689,11 +1689,11 @@
 {
   switch (op) {
   case '-':
-    return ROUND_UP(max(from1->intg, from2->intg)) +
-           ROUND_UP(max(from1->frac, from2->frac));
+    return ROUND_UP(MAX(from1->intg, from2->intg)) +
+           ROUND_UP(MAX(from1->frac, from2->frac));
   case '+':
-    return ROUND_UP(max(from1->intg, from2->intg)+1) +
-           ROUND_UP(max(from1->frac, from2->frac));
+    return ROUND_UP(MAX(from1->intg, from2->intg)+1) +
+           ROUND_UP(MAX(from1->frac, from2->frac));
   case '*':
     return ROUND_UP(from1->intg+from2->intg)+
            ROUND_UP(from1->frac)+ROUND_UP(from2->frac);
@@ -1708,7 +1708,7 @@
 {
   int intg1=ROUND_UP(from1->intg), intg2=ROUND_UP(from2->intg),
       frac1=ROUND_UP(from1->frac), frac2=ROUND_UP(from2->frac),
-      frac0=max(frac1, frac2), intg0=max(intg1, intg2), error;
+      frac0=MAX(frac1, frac2), intg0=MAX(intg1, intg2), error;
   dec1 *buf1, *buf2, *buf0, *stop, *stop2, x, carry;
 
   sanity(to);
@@ -1733,7 +1733,7 @@
   buf0=to->buf+intg0+frac0;
 
   to->sign=from1->sign;
-  to->frac=max(from1->frac, from2->frac);
+  to->frac=MAX(from1->frac, from2->frac);
   to->intg=intg0*DIG_PER_DEC1;
   if (unlikely(error))
   {
@@ -1744,7 +1744,7 @@
     set_if_smaller(intg2, intg0);
   }
 
-  /* part 1 - max(frac) ... min (frac) */
+  /* part 1 - MAX(frac) ... min (frac) */
   if (frac1 > frac2)
   {
     buf1=from1->buf+intg1+frac1;
@@ -1769,7 +1769,7 @@
     ADD(*--buf0, *--buf1, *--buf2, carry);
   }
 
-  /* part 3 - MIN(intg) ... max(intg) */
+  /* part 3 - MIN(intg) ... MAX(intg) */
   buf1= intg1 > intg2 ? ((stop=from1->buf)+intg1-intg2) :
                         ((stop=from2->buf)+intg2-intg1) ;
   while (buf1 > stop)
@@ -1790,7 +1790,7 @@
 {
   int intg1=ROUND_UP(from1->intg), intg2=ROUND_UP(from2->intg),
       frac1=ROUND_UP(from1->frac), frac2=ROUND_UP(from2->frac);
-  int frac0=max(frac1, frac2), error;
+  int frac0=MAX(frac1, frac2), error;
   dec1 *buf1, *buf2, *buf0, *stop1, *stop2, *start1, *start2, carry=0;
 
   /* let carry:=1 if from2 > from1 */
@@ -1865,7 +1865,7 @@
   FIX_INTG_FRAC_ERROR(to->len, intg1, frac0, error);
   buf0=to->buf+intg1+frac0;
 
-  to->frac=max(from1->frac, from2->frac);
+  to->frac=MAX(from1->frac, from2->frac);
   to->intg=intg1*DIG_PER_DEC1;
   if (unlikely(error))
   {
@@ -1876,7 +1876,7 @@
   }
   carry=0;
 
-  /* part 1 - max(frac) ... min (frac) */
+  /* part 1 - MAX(frac) ... min (frac) */
   if (frac1 > frac2)
   {
     buf1=start1+intg1+frac1;
@@ -2158,11 +2158,11 @@
   {
     /* we're calculating N1 % N2.
        The result will have
-         frac=max(frac1, frac2), as for subtraction
+         frac=MAX(frac1, frac2), as for subtraction
          intg=intg2
     */
     to->sign=from1->sign;
-    to->frac=max(from1->frac, from2->frac);
+    to->frac=MAX(from1->frac, from2->frac);
     frac0=0;
   }
   else
@@ -2286,7 +2286,7 @@
     /*
       now the result is in tmp1, it has
         intg=prec1-frac1
-        frac=max(frac1, frac2)=to->frac
+        frac=MAX(frac1, frac2)=to->frac
     */
     if (dcarry)
       *--start1=dcarry;
--- ./strings/ctype-big5.c.orig	Fri Apr 27 08:47:47 2007
+++ ./strings/ctype-big5.c	Wed May 30 11:33:07 2007
@@ -253,7 +253,7 @@
                              const uchar *b, uint b_length,
                              my_bool b_is_prefix)
 {
-  uint length= min(a_length, b_length);
+  uint length= MIN(a_length, b_length);
   int res= my_strnncoll_big5_internal(&a, &b, length);
   return res ? res : (int)((b_is_prefix ? length : a_length) - b_length);
 }
@@ -266,7 +266,7 @@
 			       const uchar *b, uint b_length,
                                my_bool diff_if_only_endspace_difference)
 {
-  uint length= min(a_length, b_length);
+  uint length= MIN(a_length, b_length);
   int res= my_strnncoll_big5_internal(&a, &b, length);
 
 #ifndef VARCHAR_WITH_DIFF_ENDSPACE_ARE_DIFFERENT_FOR_UNIQUE
--- ./strings/ctype-mb.c.orig	Wed Jan 24 19:57:04 2007
+++ ./strings/ctype-mb.c	Wed May 30 11:33:07 2007
@@ -364,7 +364,7 @@
 				const uchar *t, uint tlen,
                                 my_bool t_is_prefix)
 {
-  uint len=min(slen,tlen);
+  uint len=MIN(slen,tlen);
   int cmp= memcmp(s,t,len);
   return cmp ? cmp : (int) ((t_is_prefix ? len : slen) - tlen);
 }
@@ -408,7 +408,7 @@
   diff_if_only_endspace_difference= 0;
 #endif
   
-  end= a + (length= min(a_length, b_length));
+  end= a + (length= MIN(a_length, b_length));
   while (a < end)
   {
     if (*a++ != *b++)
@@ -447,7 +447,7 @@
                               const uchar *src, uint srclen)
 {
   if (dest != src)
-    memcpy(dest, src, min(dstlen, srclen));
+    memcpy(dest, src, MIN(dstlen, srclen));
   if (dstlen > srclen)
     bfill(dest + srclen, dstlen - srclen, ' ');
   return dstlen;
--- ./strings/str2int.c.orig	Fri Apr 27 08:47:55 2007
+++ ./strings/str2int.c	Wed May 30 11:33:07 2007
@@ -82,7 +82,7 @@
       machines all, if +|n| is representable, so is -|n|, but on
       twos complement machines the converse is not true.  So the
       "maximum" representable number has a negative representative.
-      Limit is set to min(-|lower|,-|upper|); this is the "largest"
+      Limit is set to MIN(-|lower|,-|upper|); this is the "largest"
       number we are concerned with.	*/
 
   /*  Calculate Limit using Scale as a scratch variable  */
--- ./strings/ctype-simple.c.orig	Wed Jan 24 19:57:04 2007
+++ ./strings/ctype-simple.c	Wed May 30 11:33:07 2007
@@ -153,7 +153,7 @@
   diff_if_only_endspace_difference= 0;
 #endif
 
-  end= a + (length= min(a_length, b_length));
+  end= a + (length= MIN(a_length, b_length));
   while (a < end)
   {
     if (map[*a++] != map[*b++])
@@ -863,7 +863,7 @@
     val= new_val;
   }
   
-  len= min(len, (uint) (e-p));
+  len= MIN(len, (uint) (e-p));
   memcpy(dst, p, len);
   return (int) len+sign;
 }
@@ -914,7 +914,7 @@
     long_val= quo;
   }
   
-  len= min(len, (uint) (e-p));
+  len= MIN(len, (uint) (e-p));
 cnv:
   memcpy(dst, p, len);
   return len+sign;
@@ -1144,7 +1144,7 @@
 {
   uint nbytes= (uint) (end-start);
   *error= 0;
-  return min(nbytes, nchars);
+  return MIN(nbytes, nchars);
 }
 
 
--- ./strings/ctype-ucs2.c.orig	Tue Feb 27 11:27:00 2007
+++ ./strings/ctype-ucs2.c	Wed May 30 11:33:07 2007
@@ -279,7 +279,7 @@
   se= s + slen;
   te= t + tlen;
 
-  for (minlen= min(slen, tlen); minlen; minlen-= 2)
+  for (minlen= MIN(slen, tlen); minlen; minlen-= 2)
   {
     int s_wc = uni_plane[s[0]] ? (int) uni_plane[s[0]][s[1]].sort :
                                  (((int) s[0]) << 8) + (int) s[1];
@@ -1329,7 +1329,7 @@
   uint nbytes= ((uint) (e-b)) & ~(uint) 1;
   *error= 0;
   nchars*= 2;
-  return min(nbytes, nchars);
+  return MIN(nbytes, nchars);
 }
 
 
@@ -1425,7 +1425,7 @@
   se= s + slen;
   te= t + tlen;
 
-  for (minlen= min(slen, tlen); minlen; minlen-= 2)
+  for (minlen= MIN(slen, tlen); minlen; minlen-= 2)
   {
     int s_wc= s[0] * 256 + s[1];
     int t_wc= t[0] * 256 + t[1];
@@ -1472,7 +1472,7 @@
 			 const uchar *src, uint srclen)
 {
   if (dst != src)
-    memcpy(dst,src,srclen= min(dstlen,srclen));
+    memcpy(dst,src,srclen= MIN(dstlen,srclen));
   if (dstlen > srclen)
     cs->cset->fill(cs, (char*) dst + srclen, dstlen - srclen, ' ');
   return dstlen;
--- ./strings/ctype-utf8.c.orig	Tue Apr  3 14:51:24 2007
+++ ./strings/ctype-utf8.c	Wed May 30 11:33:07 2007
@@ -1937,7 +1937,7 @@
                          const uchar *t, const uchar *te)
 {
   int slen= (int) (se-s), tlen= (int) (te-t);
-  int len=min(slen,tlen);
+  int len=MIN(slen,tlen);
   int cmp= memcmp(s,t,len);
   return cmp ? cmp : slen-tlen;
 }
--- ./client/sql_string.cc.orig	Wed May 30 11:33:07 2007
+++ ./client/sql_string.cc	Wed May 30 11:33:28 2007
@@ -662,7 +662,7 @@
 {
   if (Alloced_length < str_length + space_needed)
   {
-    if (realloc(Alloced_length + max(space_needed, grow_by) - 1))
+    if (realloc(Alloced_length + MAX(space_needed, grow_by) - 1))
       return TRUE;
   }
   return FALSE;
--- ./client/mysql.cc.orig	Wed May 30 11:33:07 2007
+++ ./client/mysql.cc	Wed May 30 11:33:28 2007
@@ -2358,9 +2358,9 @@
   {
     uint length= column_names ? field->name_length : 0;
     if (quick)
-      length=max(length,field->length);
+      length=MAX(length,field->length);
     else
-      length=max(length,field->max_length);
+      length=MAX(length,field->max_length);
     if (length < 4 && !IS_NOT_NULL(field->flags))
       length=4;					// Room for "NULL"
     field->max_length=length;
--- ./client/mysqldump.c.orig	Thu May 24 09:45:11 2007
+++ ./client/mysqldump.c	Wed May 30 11:33:07 2007
@@ -773,7 +773,7 @@
                                     &err_ptr, &err_len);
       if (err_len)
       {
-        strmake(buff, err_ptr, min(sizeof(buff), err_len));
+        strmake(buff, err_ptr, MIN(sizeof(buff), err_len));
         fprintf(stderr, "Invalid mode to --compatible: %s\n", buff);
         exit(1);
       }
@@ -3742,7 +3742,7 @@
 
       for (; pos != end && *pos != ','; pos++) ;
       var_len= (uint) (pos - start);
-      strmake(buff, start, min(sizeof(buff), var_len));
+      strmake(buff, start, MIN(sizeof(buff), var_len));
       find= find_type(buff, lib, var_len);
       if (!find)
       {
--- ./client/mysql_upgrade.c.orig	Wed May 30 11:33:07 2007
+++ ./client/mysql_upgrade.c	Wed May 30 11:33:28 2007
@@ -390,7 +390,7 @@
     DBUG_PRINT("enter", ("path: %s", path));
 
     /* Chop off last char(since it might be a /) */
-    path[max((strlen(path)-1), 0)]= 0;
+    path[MAX((strlen(path)-1), 0)]= 0;
 
     /* Chop off last dir part */
     dirname_part(path, path);
--- ./client/mysqltest.c.orig	Thu May 24 09:45:11 2007
+++ ./client/mysqltest.c	Wed May 30 11:33:07 2007
@@ -3859,9 +3859,9 @@
       }
       else if ((c == '{' &&
                 (!my_strnncoll_simple(charset_info, (const uchar*) "while", 5,
-                                      (uchar*) buf, min(5, p - buf), 0) ||
+                                      (uchar*) buf, MIN(5, p - buf), 0) ||
                  !my_strnncoll_simple(charset_info, (const uchar*) "if", 2,
-                                      (uchar*) buf, min(2, p - buf), 0))))
+                                      (uchar*) buf, MIN(2, p - buf), 0))))
       {
         /* Only if and while commands can be terminated by { */
         *p++= c;
--- ./client/mysqlbinlog.cc.orig	Fri Apr 20 11:46:35 2007
+++ ./client/mysqlbinlog.cc	Wed May 30 11:33:07 2007
@@ -1422,7 +1422,7 @@
       my_off_t length,tmp;
       for (length= start_position_mot ; length > 0 ; length-=tmp)
       {
-	tmp=min(length,sizeof(buff));
+	tmp=MIN(length,sizeof(buff));
 	if (my_b_read(file, buff, (uint) tmp))
         {
           error= 1;


