Gentoo Archives: gentoo-commits

From: "Robin H. Johnson" <robbat2@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/mysql-extras:master commit in: /
Date: Tue, 28 May 2013 19:34:26
Message-Id: 1369769647.0e606bcb2c2a1e99e6184c9c9c6e74b1631e1393.robbat2@gentoo
1 commit: 0e606bcb2c2a1e99e6184c9c9c6e74b1631e1393
2 Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
3 AuthorDate: Tue May 28 19:34:07 2013 +0000
4 Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
5 CommitDate: Tue May 28 19:34:07 2013 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/mysql-extras.git;a=commit;h=0e606bcb
7
8 Port min/max patch.
9
10 Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>
11
12 ---
13 00000_index.txt | 9 +-
14 07110_all_mysql_gcc-4.2_5.1.69.patch | 3838 ++++++++++++++++++++++++++++++++++
15 2 files changed, 3846 insertions(+), 1 deletion(-)
16
17 diff --git a/00000_index.txt b/00000_index.txt
18 index 22de958..ebf5c95 100644
19 --- a/00000_index.txt
20 +++ b/00000_index.txt
21 @@ -573,11 +573,18 @@
22 @@ FIXME: Testing patch - applies cleanly
23
24 @patch 07110_all_mysql_gcc-4.2_5.1.65.patch
25 -@ver 5.01.65.00 to 5.01.99.99
26 +@ver 5.01.65.00 to 5.01.68.99
27 @pn mysql
28 @@ Replace max() and min() macro with MYSQL_MIN() and MYSQL_MAX()
29 @@ FIXME: Testing patch - applies cleanly
30
31 +@patch 07110_all_mysql_gcc-4.2_5.1.69.patch
32 +@ver 5.01.69.00 to 5.01.99.99
33 +@pn mysql
34 +@@ Replace max() and min() macro with MYSQL_MIN() and MYSQL_MAX()
35 +@@ FIXME: Testing patch - applies cleanly
36 +
37 +
38 @patch 07120_all_openssl_handshake_mybug_33050.patch
39 @ver 5.00.50.00 to 5.00.54.99
40 @pn mysql
41
42 diff --git a/07110_all_mysql_gcc-4.2_5.1.69.patch b/07110_all_mysql_gcc-4.2_5.1.69.patch
43 new file mode 100644
44 index 0000000..e5919c4
45 --- /dev/null
46 +++ b/07110_all_mysql_gcc-4.2_5.1.69.patch
47 @@ -0,0 +1,3838 @@
48 +X-Gentoo-Bug: 280843
49 +X-Upstream-Bug: 30866
50 +X-Gentoo-Bug-URL: http://bugs.gentoo.org/show_bug.cgi?id=280843
51 +X-Upstream-Bug-URL: http://bugs.mysql.com/bug.php?id=30866
52 +
53 +diff -ur mysql-orig/client/mysqlbinlog.cc mysql/client/mysqlbinlog.cc
54 +--- mysql-orig/client/mysqlbinlog.cc 2012-08-14 01:12:29.733435005 +0000
55 ++++ mysql/client/mysqlbinlog.cc 2012-08-14 01:14:59.292197574 +0000
56 +@@ -1978,7 +1978,7 @@
57 + my_off_t length,tmp;
58 + for (length= start_position_mot ; length > 0 ; length-=tmp)
59 + {
60 +- tmp=min(length,sizeof(buff));
61 ++ tmp=MYSQL_MIN(length,sizeof(buff));
62 + if (my_b_read(file, buff, (uint) tmp))
63 + {
64 + error("Failed reading from file.");
65 +diff -ur mysql-orig/client/mysql.cc mysql/client/mysql.cc
66 +--- mysql-orig/client/mysql.cc 2012-08-14 01:12:29.733435005 +0000
67 ++++ mysql/client/mysql.cc 2012-08-14 01:14:59.322198687 +0000
68 +@@ -3334,9 +3334,9 @@
69 + {
70 + uint length= column_names ? field->name_length : 0;
71 + if (quick)
72 +- length=max(length,field->length);
73 ++ length=MYSQL_MAX(length,field->length);
74 + else
75 +- length=max(length,field->max_length);
76 ++ length=MYSQL_MAX(length,field->max_length);
77 + if (length < 4 && !IS_NOT_NULL(field->flags))
78 + length=4; // Room for "NULL"
79 + field->max_length=length;
80 +@@ -3356,7 +3356,7 @@
81 + field->name,
82 + field->name + name_length);
83 + uint display_length= field->max_length + name_length - numcells;
84 +- tee_fprintf(PAGER, " %-*s |",(int) min(display_length,
85 ++ tee_fprintf(PAGER, " %-*s |",(int) MYSQL_MIN(display_length,
86 + MAX_COLUMN_LENGTH),
87 + field->name);
88 + num_flag[off]= IS_NUM(field->type);
89 +diff -ur mysql-orig/client/mysqldump.c mysql/client/mysqldump.c
90 +--- mysql-orig/client/mysqldump.c 2012-08-14 01:12:29.733435005 +0000
91 ++++ mysql/client/mysqldump.c 2012-08-14 01:14:59.322198687 +0000
92 +@@ -849,7 +849,7 @@
93 + &err_ptr, &err_len);
94 + if (err_len)
95 + {
96 +- strmake(buff, err_ptr, min(sizeof(buff) - 1, err_len));
97 ++ strmake(buff, err_ptr, MYSQL_MIN(sizeof(buff) - 1, err_len));
98 + fprintf(stderr, "Invalid mode to --compatible: %s\n", buff);
99 + exit(1);
100 + }
101 +@@ -4769,7 +4769,7 @@
102 +
103 + for (; pos != end && *pos != ','; pos++) ;
104 + var_len= (uint) (pos - start);
105 +- strmake(buff, start, min(sizeof(buff) - 1, var_len));
106 ++ strmake(buff, start, MYSQL_MIN(sizeof(buff) - 1, var_len));
107 + find= find_type(buff, lib, var_len);
108 + if (!find)
109 + {
110 +diff -ur mysql-orig/client/mysqltest.cc mysql/client/mysqltest.cc
111 +--- mysql-orig/client/mysqltest.cc 2012-08-14 01:12:29.733435005 +0000
112 ++++ mysql/client/mysqltest.cc 2012-08-14 01:14:59.322198687 +0000
113 +@@ -5666,9 +5666,9 @@
114 + }
115 + else if ((c == '{' &&
116 + (!my_strnncoll_simple(charset_info, (const uchar*) "while", 5,
117 +- (uchar*) buf, min(5, p - buf), 0) ||
118 ++ (uchar*) buf, MYSQL_MIN(5, p - buf), 0) ||
119 + !my_strnncoll_simple(charset_info, (const uchar*) "if", 2,
120 +- (uchar*) buf, min(2, p - buf), 0))))
121 ++ (uchar*) buf, MYSQL_MIN(2, p - buf), 0))))
122 + {
123 + /* Only if and while commands can be terminated by { */
124 + *p++= c;
125 +diff -ur mysql-orig/client/mysql_upgrade.c mysql/client/mysql_upgrade.c
126 +--- mysql-orig/client/mysql_upgrade.c 2012-08-14 01:12:29.733435005 +0000
127 ++++ mysql/client/mysql_upgrade.c 2012-08-14 01:14:59.332198575 +0000
128 +@@ -533,7 +533,7 @@
129 + if ((value_end= strchr(value_start, '\n')) == NULL)
130 + return 1; /* Unexpected result */
131 +
132 +- strncpy(value, value_start, min(FN_REFLEN, value_end-value_start));
133 ++ strncpy(value, value_start, MYSQL_MIN(FN_REFLEN, value_end-value_start));
134 + return 0;
135 + }
136 +
137 +diff -ur mysql-orig/client/sql_string.cc mysql/client/sql_string.cc
138 +--- mysql-orig/client/sql_string.cc 2012-08-14 01:12:29.733435005 +0000
139 ++++ mysql/client/sql_string.cc 2012-08-14 01:14:59.332198575 +0000
140 +@@ -665,7 +665,7 @@
141 + {
142 + if (Alloced_length < str_length + space_needed)
143 + {
144 +- if (realloc(Alloced_length + max(space_needed, grow_by) - 1))
145 ++ if (realloc(Alloced_length + MYSQL_MAX(space_needed, grow_by) - 1))
146 + return TRUE;
147 + }
148 + return FALSE;
149 +@@ -751,7 +751,7 @@
150 +
151 + int stringcmp(const String *s,const String *t)
152 + {
153 +- uint32 s_len=s->length(),t_len=t->length(),len=min(s_len,t_len);
154 ++ uint32 s_len=s->length(),t_len=t->length(),len=MYSQL_MIN(s_len,t_len);
155 + int cmp= memcmp(s->ptr(), t->ptr(), len);
156 + return (cmp) ? cmp : (int) (s_len - t_len);
157 + }
158 +@@ -768,7 +768,7 @@
159 + }
160 + if (to->realloc(from_length))
161 + return from; // Actually an error
162 +- if ((to->str_length=min(from->str_length,from_length)))
163 ++ if ((to->str_length=MYSQL_MIN(from->str_length,from_length)))
164 + memcpy(to->Ptr,from->Ptr,to->str_length);
165 + to->str_charset=from->str_charset;
166 + return to;
167 +diff -ur mysql-orig/dbug/dbug.c mysql/dbug/dbug.c
168 +--- mysql-orig/dbug/dbug.c 2012-08-14 01:12:29.743434923 +0000
169 ++++ mysql/dbug/dbug.c 2012-08-14 01:14:59.332198575 +0000
170 +@@ -1205,7 +1205,7 @@
171 + if (TRACING)
172 + {
173 + Indent(cs, cs->level + 1);
174 +- pos= min(max(cs->level-cs->stack->sub_level,0)*INDENT,80);
175 ++ pos= MYSQL_MIN(MYSQL_MAX(cs->level-cs->stack->sub_level,0)*INDENT,80);
176 + }
177 + else
178 + {
179 +@@ -1690,7 +1690,7 @@
180 + {
181 + REGISTER int count;
182 +
183 +- indent= max(indent-1-cs->stack->sub_level,0)*INDENT;
184 ++ indent= MYSQL_MAX(indent-1-cs->stack->sub_level,0)*INDENT;
185 + for (count= 0; count < indent ; count++)
186 + {
187 + if ((count % INDENT) == 0)
188 +diff -ur mysql-orig/extra/yassl/src/ssl.cpp mysql/extra/yassl/src/ssl.cpp
189 +--- mysql-orig/extra/yassl/src/ssl.cpp 2012-08-14 01:12:29.693435335 +0000
190 ++++ mysql/extra/yassl/src/ssl.cpp 2012-08-14 01:14:59.332198575 +0000
191 +@@ -39,6 +39,7 @@
192 + #include "file.hpp" // for TaoCrypt Source
193 + #include "coding.hpp" // HexDecoder
194 + #include "helpers.hpp" // for placement new hack
195 ++#include "my_global.h"
196 + #include <stdio.h>
197 +
198 + #ifdef _WIN32
199 +@@ -114,7 +115,7 @@
200 + // use file's salt for key derivation, but not real iv
201 + TaoCrypt::Source source(info.iv, info.ivSz);
202 + TaoCrypt::HexDecoder dec(source);
203 +- memcpy(info.iv, source.get_buffer(), min((uint)sizeof(info.iv),
204 ++ memcpy(info.iv, source.get_buffer(), MYSQL_MIN((uint)sizeof(info.iv),
205 + source.size()));
206 + EVP_BytesToKey(info.name, "MD5", info.iv, (byte*)password,
207 + passwordSz, 1, key, iv);
208 +diff -ur mysql-orig/extra/yassl/taocrypt/include/pwdbased.hpp mysql/extra/yassl/taocrypt/include/pwdbased.hpp
209 +--- mysql-orig/extra/yassl/taocrypt/include/pwdbased.hpp 2012-08-14 01:12:29.693435335 +0000
210 ++++ mysql/extra/yassl/taocrypt/include/pwdbased.hpp 2012-08-14 01:14:59.332198575 +0000
211 +@@ -68,7 +68,7 @@
212 + }
213 + hmac.Final(buffer.get_buffer());
214 +
215 +- word32 segmentLen = min(dLen, buffer.size());
216 ++ word32 segmentLen = MYSQL_MIN(dLen, buffer.size());
217 + memcpy(derived, buffer.get_buffer(), segmentLen);
218 +
219 + for (j = 1; j < iterations; j++) {
220 +diff -ur mysql-orig/extra/yassl/taocrypt/src/dh.cpp mysql/extra/yassl/taocrypt/src/dh.cpp
221 +--- mysql-orig/extra/yassl/taocrypt/src/dh.cpp 2012-08-14 01:12:29.693435335 +0000
222 ++++ mysql/extra/yassl/taocrypt/src/dh.cpp 2012-08-14 01:14:59.332198575 +0000
223 +@@ -23,6 +23,7 @@
224 + #include "runtime.hpp"
225 + #include "dh.hpp"
226 + #include "asn.hpp"
227 ++#include "my_global.h"
228 + #include <math.h>
229 +
230 + namespace TaoCrypt {
231 +@@ -54,7 +55,7 @@
232 + // Generate private value
233 + void DH::GeneratePrivate(RandomNumberGenerator& rng, byte* priv)
234 + {
235 +- Integer x(rng, Integer::One(), min(p_ - 1,
236 ++ Integer x(rng, Integer::One(), MYSQL_MIN(p_ - 1,
237 + Integer::Power2(2*DiscreteLogWorkFactor(p_.BitCount())) ) );
238 + x.Encode(priv, p_.ByteCount());
239 + }
240 +diff -ur mysql-orig/include/my_global.h mysql/include/my_global.h
241 +--- mysql-orig/include/my_global.h 2012-08-14 01:12:29.713435171 +0000
242 ++++ mysql/include/my_global.h 2012-08-14 01:14:59.332198575 +0000
243 +@@ -586,10 +586,8 @@
244 + #endif
245 +
246 + /* Define some useful general macros */
247 +-#if !defined(max)
248 +-#define max(a, b) ((a) > (b) ? (a) : (b))
249 +-#define min(a, b) ((a) < (b) ? (a) : (b))
250 +-#endif
251 ++#define MYSQL_MAX(a, b) ((a) > (b) ? (a) : (b))
252 ++#define MYSQL_MIN(a, b) ((a) < (b) ? (a) : (b))
253 +
254 + #if !defined(HAVE_UINT)
255 + #undef HAVE_UINT
256 +diff -ur mysql-orig/libmysql/libmysql.c mysql/libmysql/libmysql.c
257 +--- mysql-orig/libmysql/libmysql.c 2012-08-14 01:12:29.713435171 +0000
258 ++++ mysql/libmysql/libmysql.c 2012-08-14 01:14:59.332198575 +0000
259 +@@ -1572,7 +1572,7 @@
260 + my_net_set_read_timeout(net, CLIENT_NET_READ_TIMEOUT);
261 + my_net_set_write_timeout(net, CLIENT_NET_WRITE_TIMEOUT);
262 + net->retry_count= 1;
263 +- net->max_packet_size= max(net_buffer_length, max_allowed_packet);
264 ++ net->max_packet_size= MYSQL_MAX(net_buffer_length, max_allowed_packet);
265 + }
266 +
267 + /*
268 +@@ -3622,7 +3622,7 @@
269 + copy_length= end - start;
270 + /* We've got some data beyond offset: copy up to buffer_length bytes */
271 + if (param->buffer_length)
272 +- memcpy(buffer, start, min(copy_length, param->buffer_length));
273 ++ memcpy(buffer, start, MYSQL_MIN(copy_length, param->buffer_length));
274 + }
275 + else
276 + copy_length= 0;
277 +@@ -3855,9 +3855,9 @@
278 + precisions. This will ensure that on the same machine you get the
279 + same value as a string independent of the protocol you use.
280 + */
281 +- sprintf(buff, "%-*.*g", (int) min(sizeof(buff)-1,
282 ++ sprintf(buff, "%-*.*g", (int) MYSQL_MIN(sizeof(buff)-1,
283 + param->buffer_length),
284 +- min(DBL_DIG, width), value);
285 ++ MYSQL_MIN(DBL_DIG,width), value);
286 + end= strcend(buff, ' ');
287 + *end= 0;
288 + }
289 +@@ -4175,7 +4175,7 @@
290 + uchar **row)
291 + {
292 + ulong length= net_field_length(row);
293 +- ulong copy_length= min(length, param->buffer_length);
294 ++ ulong copy_length= MYSQL_MIN(length, param->buffer_length);
295 + memcpy(param->buffer, (char *)*row, copy_length);
296 + *param->length= length;
297 + *param->error= copy_length < length;
298 +@@ -4187,7 +4187,7 @@
299 + uchar **row)
300 + {
301 + ulong length= net_field_length(row);
302 +- ulong copy_length= min(length, param->buffer_length);
303 ++ ulong copy_length= MYSQL_MIN(length, param->buffer_length);
304 + memcpy(param->buffer, (char *)*row, copy_length);
305 + /* Add an end null if there is room in the buffer */
306 + if (copy_length != param->buffer_length)
307 +diff -ur mysql-orig/libmysqld/lib_sql.cc mysql/libmysqld/lib_sql.cc
308 +--- mysql-orig/libmysqld/lib_sql.cc 2012-08-14 01:12:29.723435087 +0000
309 ++++ mysql/libmysqld/lib_sql.cc 2012-08-14 01:14:59.372198019 +0000
310 +@@ -844,7 +844,7 @@
311 + is cleared between substatements, and mysqltest gets confused
312 + */
313 + thd->cur_data->embedded_info->warning_count=
314 +- (thd->spcont ? 0 : min(total_warn_count, 65535));
315 ++ (thd->spcont ? 0 : MYSQL_MIN(total_warn_count, 65535));
316 + return FALSE;
317 + }
318 +
319 +diff -ur mysql-orig/mysys/array.c mysql/mysys/array.c
320 +--- mysql-orig/mysys/array.c 2012-08-14 01:12:29.713435171 +0000
321 ++++ mysql/mysys/array.c 2012-08-14 01:14:59.372198019 +0000
322 +@@ -50,7 +50,7 @@
323 + DBUG_ENTER("init_dynamic_array");
324 + if (!alloc_increment)
325 + {
326 +- alloc_increment=max((8192-MALLOC_OVERHEAD)/element_size,16);
327 ++ alloc_increment=MYSQL_MAX((8192-MALLOC_OVERHEAD)/element_size,16);
328 + if (init_alloc > 8 && alloc_increment > init_alloc * 2)
329 + alloc_increment=init_alloc*2;
330 + }
331 +@@ -344,7 +344,7 @@
332 +
333 + void freeze_size(DYNAMIC_ARRAY *array)
334 + {
335 +- uint elements=max(array->elements,1);
336 ++ uint elements=MYSQL_MAX(array->elements,1);
337 +
338 + /*
339 + Do nothing if we are using a static buffer
340 +diff -ur mysql-orig/mysys/default.c mysql/mysys/default.c
341 +--- mysql-orig/mysys/default.c 2012-08-14 01:12:29.713435171 +0000
342 ++++ mysql/mysys/default.c 2012-08-14 01:14:59.372198019 +0000
343 +@@ -796,7 +796,7 @@
344 + for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;
345 + end[0]=0;
346 +
347 +- strmake(curr_gr, ptr, min((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
348 ++ strmake(curr_gr, ptr, MYSQL_MIN((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
349 +
350 + /* signal that a new group is found */
351 + opt_handler(handler_ctx, curr_gr, NULL);
352 +diff -ur mysql-orig/mysys/mf_format.c mysql/mysys/mf_format.c
353 +--- mysql-orig/mysys/mf_format.c 2012-08-14 01:12:29.713435171 +0000
354 ++++ mysql/mysys/mf_format.c 2012-08-14 01:14:59.372198019 +0000
355 +@@ -86,7 +86,7 @@
356 + tmp_length= strlength(startpos);
357 + DBUG_PRINT("error",("dev: '%s' ext: '%s' length: %u",dev,ext,
358 + (uint) length));
359 +- (void) strmake(to,startpos,min(tmp_length,FN_REFLEN-1));
360 ++ (void) strmake(to,startpos,MYSQL_MIN(tmp_length,FN_REFLEN-1));
361 + }
362 + else
363 + {
364 +diff -ur mysql-orig/mysys/mf_iocache.c mysql/mysys/mf_iocache.c
365 +--- mysql-orig/mysys/mf_iocache.c 2012-08-14 01:12:29.713435171 +0000
366 ++++ mysql/mysys/mf_iocache.c 2012-08-14 01:14:59.372198019 +0000
367 +@@ -1099,7 +1099,7 @@
368 + */
369 + while (write_length)
370 + {
371 +- size_t copy_length= min(write_length, write_cache->buffer_length);
372 ++ size_t copy_length= MYSQL_MIN(write_length, write_cache->buffer_length);
373 + int __attribute__((unused)) rc;
374 +
375 + rc= lock_io_cache(write_cache, write_cache->pos_in_file);
376 +@@ -1258,7 +1258,7 @@
377 + TODO: figure out if the assert below is needed or correct.
378 + */
379 + DBUG_ASSERT(pos_in_file == info->end_of_file);
380 +- copy_len=min(Count, len_in_buff);
381 ++ copy_len=MYSQL_MIN(Count, len_in_buff);
382 + memcpy(Buffer, info->append_read_pos, copy_len);
383 + info->append_read_pos += copy_len;
384 + Count -= copy_len;
385 +@@ -1367,7 +1367,7 @@
386 + }
387 + #endif
388 + /* Copy found bytes to buffer */
389 +- length=min(Count,read_length);
390 ++ length=MYSQL_MIN(Count,read_length);
391 + memcpy(Buffer,info->read_pos,(size_t) length);
392 + Buffer+=length;
393 + Count-=length;
394 +@@ -1401,7 +1401,7 @@
395 + if ((read_length=my_read(info->file,info->request_pos,
396 + read_length, info->myflags)) == (size_t) -1)
397 + return info->error= -1;
398 +- use_length=min(Count,read_length);
399 ++ use_length=MYSQL_MIN(Count,read_length);
400 + memcpy(Buffer,info->request_pos,(size_t) use_length);
401 + info->read_pos=info->request_pos+Count;
402 + info->read_end=info->request_pos+read_length;
403 +diff -ur mysql-orig/mysys/my_alloc.c mysql/mysys/my_alloc.c
404 +--- mysql-orig/mysys/my_alloc.c 2012-08-14 01:12:29.713435171 +0000
405 ++++ mysql/mysys/my_alloc.c 2012-08-14 01:14:59.372198019 +0000
406 +@@ -214,7 +214,7 @@
407 + { /* Time to alloc new block */
408 + block_size= mem_root->block_size * (mem_root->block_num >> 2);
409 + get_size= length+ALIGN_SIZE(sizeof(USED_MEM));
410 +- get_size= max(get_size, block_size);
411 ++ get_size= MYSQL_MAX(get_size, block_size);
412 +
413 + if (!(next = (USED_MEM*) my_malloc(get_size,MYF(MY_WME))))
414 + {
415 +diff -ur mysql-orig/mysys/my_bitmap.c mysql/mysys/my_bitmap.c
416 +--- mysql-orig/mysys/my_bitmap.c 2012-08-14 01:12:29.713435171 +0000
417 ++++ mysql/mysys/my_bitmap.c 2012-08-14 01:14:59.372198019 +0000
418 +@@ -425,7 +425,7 @@
419 +
420 + DBUG_ASSERT(map->bitmap && map2->bitmap);
421 +
422 +- end= to+min(len,len2);
423 ++ end= to+MYSQL_MIN(len,len2);
424 + for (; to < end; to++, from++)
425 + *to &= *from;
426 +
427 +diff -ur mysql-orig/mysys/my_compare.c mysql/mysys/my_compare.c
428 +--- mysql-orig/mysys/my_compare.c 2012-08-14 01:12:29.713435171 +0000
429 ++++ mysql/mysys/my_compare.c 2012-08-14 01:14:59.372198019 +0000
430 +@@ -30,7 +30,7 @@
431 + static int compare_bin(uchar *a, uint a_length, uchar *b, uint b_length,
432 + my_bool part_key, my_bool skip_end_space)
433 + {
434 +- uint length= min(a_length,b_length);
435 ++ uint length= MYSQL_MIN(a_length,b_length);
436 + uchar *end= a+ length;
437 + int flag;
438 +
439 +@@ -158,7 +158,7 @@
440 + continue; /* To next key part */
441 + }
442 + }
443 +- end= a+ min(keyseg->length,key_length);
444 ++ end= a+ MYSQL_MIN(keyseg->length,key_length);
445 + next_key_length=key_length-keyseg->length;
446 +
447 + switch ((enum ha_base_keytype) keyseg->type) {
448 +diff -ur mysql-orig/mysys/my_compress.c mysql/mysys/my_compress.c
449 +--- mysql-orig/mysys/my_compress.c 2012-08-14 01:12:29.713435171 +0000
450 ++++ mysql/mysys/my_compress.c 2012-08-14 01:14:59.372198019 +0000
451 +@@ -244,7 +244,7 @@
452 +
453 + if (ver != 1)
454 + DBUG_RETURN(1);
455 +- if (!(data= my_malloc(max(orglen, complen), MYF(MY_WME))))
456 ++ if (!(data= my_malloc(MYSQL_MAX(orglen, complen), MYF(MY_WME))))
457 + DBUG_RETURN(2);
458 + memcpy(data, pack_data + BLOB_HEADER, complen);
459 +
460 +diff -ur mysql-orig/mysys/my_conio.c mysql/mysys/my_conio.c
461 +--- mysql-orig/mysys/my_conio.c 2012-08-14 01:12:29.713435171 +0000
462 ++++ mysql/mysys/my_conio.c 2012-08-14 01:14:59.372198019 +0000
463 +@@ -165,13 +165,13 @@
464 + though it is known it should not be more than 64K
465 + so we cut 64K and try first size of screen buffer
466 + if it is still to large we cut half of it and try again
467 +- later we may want to cycle from min(clen, 65535) to allowed size
468 ++ later we may want to cycle from MYSQL_MIN(clen, 65535) to allowed size
469 + with small decrement to determine exact allowed buffer
470 + */
471 +- clen= min(clen, 65535);
472 ++ clen= MYSQL_MIN(clen, 65535);
473 + do
474 + {
475 +- clen= min(clen, (size_t) csbi.dwSize.X*csbi.dwSize.Y);
476 ++ clen= MYSQL_MIN(clen, (size_t) csbi.dwSize.X*csbi.dwSize.Y);
477 + if (!ReadConsole((HANDLE)my_coninpfh, (LPVOID)buffer, (DWORD) clen - 1, &plen_res,
478 + NULL))
479 + {
480 +diff -ur mysql-orig/mysys/my_file.c mysql/mysys/my_file.c
481 +--- mysql-orig/mysys/my_file.c 2012-08-14 01:12:29.713435171 +0000
482 ++++ mysql/mysys/my_file.c 2012-08-14 01:14:59.372198019 +0000
483 +@@ -77,7 +77,7 @@
484 + static uint set_max_open_files(uint max_file_limit)
485 + {
486 + /* We don't know the limit. Return best guess */
487 +- return min(max_file_limit, OS_FILE_LIMIT);
488 ++ return MYSQL_MIN(max_file_limit, OS_FILE_LIMIT);
489 + }
490 + #endif
491 +
492 +@@ -99,7 +99,7 @@
493 + DBUG_ENTER("my_set_max_open_files");
494 + DBUG_PRINT("enter",("files: %u my_file_limit: %u", files, my_file_limit));
495 +
496 +- files= set_max_open_files(min(files, OS_FILE_LIMIT));
497 ++ files= set_max_open_files(MYSQL_MIN(files, OS_FILE_LIMIT));
498 + if (files <= MY_NFILE)
499 + DBUG_RETURN(files);
500 +
501 +@@ -109,9 +109,9 @@
502 +
503 + /* Copy any initialized files */
504 + memcpy((char*) tmp, (char*) my_file_info,
505 +- sizeof(*tmp) * min(my_file_limit, files));
506 ++ sizeof(*tmp) * MYSQL_MIN(my_file_limit, files));
507 + bzero((char*) (tmp + my_file_limit),
508 +- max((int) (files- my_file_limit), 0)*sizeof(*tmp));
509 ++ MYSQL_MAX((int) (files- my_file_limit), 0)*sizeof(*tmp));
510 + my_free_open_file_info(); /* Free if already allocated */
511 + my_file_info= tmp;
512 + my_file_limit= files;
513 +diff -ur mysql-orig/mysys/my_getopt.c mysql/mysys/my_getopt.c
514 +--- mysql-orig/mysys/my_getopt.c 2012-08-14 01:12:29.713435171 +0000
515 ++++ mysql/mysys/my_getopt.c 2012-08-14 01:14:59.372198019 +0000
516 +@@ -985,7 +985,7 @@
517 + }
518 + if (optp->max_value && num > (double) optp->max_value)
519 + num= (double) optp->max_value;
520 +- return max(num, (double) optp->min_value);
521 ++ return MYSQL_MAX(num, (double) optp->min_value);
522 + }
523 +
524 + /*
525 +diff -ur mysql-orig/mysys/my_static.h mysql/mysys/my_static.h
526 +--- mysql-orig/mysys/my_static.h 2012-08-14 01:12:29.713435171 +0000
527 ++++ mysql/mysys/my_static.h 2012-08-14 01:14:59.372198019 +0000
528 +@@ -22,7 +22,7 @@
529 + #include <signal.h>
530 +
531 + #define MAX_SIGNALS 10 /* Max signals under a dont-allow */
532 +-#define MIN_KEYBLOCK (min(IO_SIZE,1024))
533 ++#define MIN_KEYBLOCK (MYSQL_MIN(IO_SIZE,1024))
534 + #define MAX_KEYBLOCK 8192 /* Max keyblocklength == 8*IO_SIZE */
535 + #define MAX_BLOCK_TYPES MAX_KEYBLOCK/MIN_KEYBLOCK
536 +
537 +diff -ur mysql-orig/mysys/safemalloc.c mysql/mysys/safemalloc.c
538 +--- mysql-orig/mysys/safemalloc.c 2012-08-14 01:12:29.713435171 +0000
539 ++++ mysql/mysys/safemalloc.c 2012-08-14 01:14:59.372198019 +0000
540 +@@ -250,7 +250,7 @@
541 +
542 + if ((data= _mymalloc(size,filename,lineno,MyFlags))) /* Allocate new area */
543 + {
544 +- size=min(size, irem->datasize); /* Move as much as possibly */
545 ++ size=MYSQL_MIN(size, irem->datasize); /* Move as much as possibly */
546 + memcpy((uchar*) data, ptr, (size_t) size); /* Copy old data */
547 + _myfree(ptr, filename, lineno, 0); /* Free not needed area */
548 + }
549 +diff -ur mysql-orig/mysys/stacktrace.c mysql/mysys/stacktrace.c
550 +--- mysql-orig/mysys/stacktrace.c 2012-08-14 01:12:29.713435171 +0000
551 ++++ mysql/mysys/stacktrace.c 2012-08-14 01:14:59.372198019 +0000
552 +@@ -98,7 +98,7 @@
553 + /* Read up to the maximum number of bytes. */
554 + while (total)
555 + {
556 +- count= min(sizeof(buf), total);
557 ++ count= MYSQL_MIN(sizeof(buf), total);
558 +
559 + if ((nbytes= pread(fd, buf, count, offset)) < 0)
560 + {
561 +@@ -328,7 +328,7 @@
562 +
563 + if (!stack_bottom || (uchar*) stack_bottom > (uchar*) &fp)
564 + {
565 +- ulong tmp= min(0x10000,thread_stack);
566 ++ ulong tmp= MYSQL_MIN(0x10000,thread_stack);
567 + /* Assume that the stack starts at the previous even 65K */
568 + stack_bottom= (uchar*) (((ulong) &fp + tmp) & ~(ulong) 0xFFFF);
569 + my_safe_printf_stderr("Cannot determine thread, fp=%p, "
570 +diff -ur mysql-orig/server-tools/instance-manager/buffer.cc mysql/server-tools/instance-manager/buffer.cc
571 +--- mysql-orig/server-tools/instance-manager/buffer.cc 2012-08-14 01:12:29.703435253 +0000
572 ++++ mysql/server-tools/instance-manager/buffer.cc 2012-08-14 01:14:59.372198019 +0000
573 +@@ -86,8 +86,8 @@
574 + if (position + len_arg >= buffer_size)
575 + {
576 + buffer= (uchar*) my_realloc(buffer,
577 +- min(MAX_BUFFER_SIZE,
578 +- max((uint) (buffer_size*1.5),
579 ++ MYSQL_MIN(MAX_BUFFER_SIZE,
580 ++ MYSQL_MAX((uint) (buffer_size*1.5),
581 + position + len_arg)), MYF(0));
582 + if (!(buffer))
583 + goto err;
584 +diff -ur mysql-orig/server-tools/instance-manager/listener.cc mysql/server-tools/instance-manager/listener.cc
585 +--- mysql-orig/server-tools/instance-manager/listener.cc 2012-08-14 01:12:29.703435253 +0000
586 ++++ mysql/server-tools/instance-manager/listener.cc 2012-08-14 01:14:59.372198019 +0000
587 +@@ -106,7 +106,7 @@
588 +
589 + /* II. Listen sockets and spawn childs */
590 + for (i= 0; i < num_sockets; i++)
591 +- n= max(n, sockets[i]);
592 ++ n= MYSQL_MAX(n, sockets[i]);
593 + n++;
594 +
595 + timeval tv;
596 +diff -ur mysql-orig/sql/debug_sync.cc mysql/sql/debug_sync.cc
597 +--- mysql-orig/sql/debug_sync.cc 2012-08-14 01:12:29.423437567 +0000
598 ++++ mysql/sql/debug_sync.cc 2012-08-14 01:14:59.372198019 +0000
599 +@@ -1036,7 +1036,7 @@
600 + DBUG_ASSERT(action);
601 + DBUG_ASSERT(ds_control);
602 +
603 +- action->activation_count= max(action->hit_limit, action->execute);
604 ++ action->activation_count= MYSQL_MAX(action->hit_limit, action->execute);
605 + if (!action->activation_count)
606 + {
607 + debug_sync_remove_action(ds_control, action);
608 +diff -ur mysql-orig/sql/field.cc mysql/sql/field.cc
609 +--- mysql-orig/sql/field.cc 2012-08-14 01:12:29.413437640 +0000
610 ++++ mysql/sql/field.cc 2012-08-14 01:14:59.382197947 +0000
611 +@@ -55,7 +55,7 @@
612 + #define LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE 128
613 + #define DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE 128
614 + #define BLOB_PACK_LENGTH_TO_MAX_LENGH(arg) \
615 +-((ulong) ((LL(1) << min(arg, 4) * 8) - LL(1)))
616 ++((ulong) ((LL(1) << MYSQL_MIN(arg, 4) * 8) - LL(1)))
617 +
618 + #define ASSERT_COLUMN_MARKED_FOR_READ DBUG_ASSERT(!table || (!table->read_set || bitmap_is_set(table->read_set, field_index)))
619 + #define ASSERT_COLUMN_MARKED_FOR_WRITE DBUG_ASSERT(!table || (!table->write_set || bitmap_is_set(table->write_set, field_index)))
620 +@@ -2073,7 +2073,7 @@
621 + tmp_uint=tmp_dec+(uint)(int_digits_end-int_digits_from);
622 + else if (expo_sign_char == '-')
623 + {
624 +- tmp_uint=min(exponent,(uint)(int_digits_end-int_digits_from));
625 ++ tmp_uint=MYSQL_MIN(exponent,(uint)(int_digits_end-int_digits_from));
626 + frac_digits_added_zeros=exponent-tmp_uint;
627 + int_digits_end -= tmp_uint;
628 + frac_digits_head_end=int_digits_end+tmp_uint;
629 +@@ -2081,7 +2081,7 @@
630 + }
631 + else // (expo_sign_char=='+')
632 + {
633 +- tmp_uint=min(exponent,(uint)(frac_digits_end-frac_digits_from));
634 ++ tmp_uint=MYSQL_MIN(exponent,(uint)(frac_digits_end-frac_digits_from));
635 + int_digits_added_zeros=exponent-tmp_uint;
636 + int_digits_tail_from=frac_digits_from;
637 + frac_digits_from=frac_digits_from+tmp_uint;
638 +@@ -2506,7 +2506,7 @@
639 + {
640 + signed int overflow;
641 +
642 +- dec= min(dec, DECIMAL_MAX_SCALE);
643 ++ dec= MYSQL_MIN(dec, DECIMAL_MAX_SCALE);
644 +
645 + /*
646 + If the value still overflows the field with the corrected dec,
647 +@@ -2522,7 +2522,7 @@
648 + overflow= required_length - len;
649 +
650 + if (overflow > 0)
651 +- dec= max(0, dec - overflow); // too long, discard fract
652 ++ dec= MYSQL_MAX(0, dec - overflow); // too long, discard fract
653 + else
654 + /* Corrected value fits. */
655 + len= required_length;
656 +@@ -3092,7 +3092,7 @@
657 + ASSERT_COLUMN_MARKED_FOR_READ;
658 + CHARSET_INFO *cs= &my_charset_bin;
659 + uint length;
660 +- uint mlength=max(field_length+1,5*cs->mbmaxlen);
661 ++ uint mlength=MYSQL_MAX(field_length+1,5*cs->mbmaxlen);
662 + val_buffer->alloc(mlength);
663 + char *to=(char*) val_buffer->ptr();
664 +
665 +@@ -3304,7 +3304,7 @@
666 + ASSERT_COLUMN_MARKED_FOR_READ;
667 + CHARSET_INFO *cs= &my_charset_bin;
668 + uint length;
669 +- uint mlength=max(field_length+1,7*cs->mbmaxlen);
670 ++ uint mlength=MYSQL_MAX(field_length+1,7*cs->mbmaxlen);
671 + val_buffer->alloc(mlength);
672 + char *to=(char*) val_buffer->ptr();
673 + short j;
674 +@@ -3521,7 +3521,7 @@
675 + ASSERT_COLUMN_MARKED_FOR_READ;
676 + CHARSET_INFO *cs= &my_charset_bin;
677 + uint length;
678 +- uint mlength=max(field_length+1,10*cs->mbmaxlen);
679 ++ uint mlength=MYSQL_MAX(field_length+1,10*cs->mbmaxlen);
680 + val_buffer->alloc(mlength);
681 + char *to=(char*) val_buffer->ptr();
682 + long j= unsigned_flag ? (long) uint3korr(ptr) : sint3korr(ptr);
683 +@@ -3740,7 +3740,7 @@
684 + ASSERT_COLUMN_MARKED_FOR_READ;
685 + CHARSET_INFO *cs= &my_charset_bin;
686 + uint length;
687 +- uint mlength=max(field_length+1,12*cs->mbmaxlen);
688 ++ uint mlength=MYSQL_MAX(field_length+1,12*cs->mbmaxlen);
689 + val_buffer->alloc(mlength);
690 + char *to=(char*) val_buffer->ptr();
691 + int32 j;
692 +@@ -3981,7 +3981,7 @@
693 + {
694 + CHARSET_INFO *cs= &my_charset_bin;
695 + uint length;
696 +- uint mlength=max(field_length+1,22*cs->mbmaxlen);
697 ++ uint mlength=MYSQL_MAX(field_length+1,22*cs->mbmaxlen);
698 + val_buffer->alloc(mlength);
699 + char *to=(char*) val_buffer->ptr();
700 + longlong j;
701 +@@ -4204,7 +4204,7 @@
702 + #endif
703 + memcpy_fixed((uchar*) &nr,ptr,sizeof(nr));
704 +
705 +- uint to_length=max(field_length,70);
706 ++ uint to_length=MYSQL_MAX(field_length,70);
707 + val_buffer->alloc(to_length);
708 + char *to=(char*) val_buffer->ptr();
709 +
710 +@@ -6443,13 +6443,13 @@
711 + calculate the maximum number of significant digits if the 'f'-format
712 + would be used (+1 for decimal point if the number has a fractional part).
713 + */
714 +- digits= max(1, (int) max_length - fractional);
715 ++ digits= MYSQL_MAX(1, (int) max_length - fractional);
716 + /*
717 + If the exponent is negative, decrease digits by the number of leading zeros
718 + after the decimal point that do not count as significant digits.
719 + */
720 + if (exp < 0)
721 +- digits= max(1, (int) digits + exp);
722 ++ digits= MYSQL_MAX(1, (int) digits + exp);
723 + /*
724 + 'e'-format is used only if the exponent is less than -4 or greater than or
725 + equal to the precision. In this case we need to adjust the number of
726 +@@ -6457,7 +6457,7 @@
727 + We also have to reserve one additional character if abs(exp) >= 100.
728 + */
729 + if (exp >= (int) digits || exp < -4)
730 +- digits= max(1, (int) (max_length - 5 - (exp >= 100 || exp <= -100)));
731 ++ digits= MYSQL_MAX(1, (int) (max_length - 5 - (exp >= 100 || exp <= -100)));
732 +
733 + /* Limit precision to DBL_DIG to avoid garbage past significant digits */
734 + set_if_smaller(digits, DBL_DIG);
735 +@@ -6715,7 +6715,7 @@
736 + uint max_length,
737 + bool low_byte_first __attribute__((unused)))
738 + {
739 +- uint length= min(field_length,max_length);
740 ++ uint length= MYSQL_MIN(field_length,max_length);
741 + uint local_char_length= max_length/field_charset->mbmaxlen;
742 + if (length > local_char_length)
743 + local_char_length= my_charpos(field_charset, from, from+length,
744 +@@ -7709,7 +7709,7 @@
745 + from= tmpstr.ptr();
746 + }
747 +
748 +- new_length= min(max_data_length(), field_charset->mbmaxlen * length);
749 ++ new_length= MYSQL_MIN(max_data_length(), field_charset->mbmaxlen * length);
750 + if (value.alloc(new_length))
751 + goto oom_error;
752 +
753 +@@ -7869,7 +7869,7 @@
754 + b_length=get_length(b_ptr);
755 + if (b_length > max_length)
756 + b_length=max_length;
757 +- diff=memcmp(a,b,min(a_length,b_length));
758 ++ diff=memcmp(a,b,MYSQL_MIN(a_length,b_length));
759 + return diff ? diff : (int) (a_length - b_length);
760 + }
761 +
762 +@@ -8065,7 +8065,7 @@
763 + length given is smaller than the actual length of the blob, we
764 + just store the initial bytes of the blob.
765 + */
766 +- store_length(to, packlength, min(length, max_length), low_byte_first);
767 ++ store_length(to, packlength, MYSQL_MIN(length, max_length), low_byte_first);
768 +
769 + /*
770 + Store the actual blob data, which will occupy 'length' bytes.
771 +@@ -9112,7 +9112,7 @@
772 + {
773 + ASSERT_COLUMN_MARKED_FOR_READ;
774 + char buff[sizeof(longlong)];
775 +- uint length= min(pack_length(), sizeof(longlong));
776 ++ uint length= MYSQL_MIN(pack_length(), sizeof(longlong));
777 + ulonglong bits= val_int();
778 + mi_int8store(buff,bits);
779 +
780 +@@ -9198,7 +9198,7 @@
781 + *buff++= bits;
782 + length--;
783 + }
784 +- uint data_length = min(length, bytes_in_rec);
785 ++ uint data_length = MYSQL_MIN(length, bytes_in_rec);
786 + memcpy(buff, ptr, data_length);
787 + return data_length + 1;
788 + }
789 +@@ -9326,7 +9326,7 @@
790 + uchar bits= get_rec_bits(bit_ptr + (from - ptr), bit_ofs, bit_len);
791 + *to++= bits;
792 + }
793 +- length= min(bytes_in_rec, max_length - (bit_len > 0));
794 ++ length= MYSQL_MIN(bytes_in_rec, max_length - (bit_len > 0));
795 + memcpy(to, from, length);
796 + return to + length;
797 + }
798 +@@ -9783,7 +9783,7 @@
799 + DBUG_ASSERT(MAX_DATETIME_COMPRESSED_WIDTH < UINT_MAX);
800 + if (length != UINT_MAX) /* avoid overflow; is safe because of min() */
801 + length= ((length+1)/2)*2;
802 +- length= min(length, MAX_DATETIME_COMPRESSED_WIDTH);
803 ++ length= MYSQL_MIN(length, MAX_DATETIME_COMPRESSED_WIDTH);
804 + }
805 + flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
806 + /*
807 +diff -ur mysql-orig/sql/filesort.cc mysql/sql/filesort.cc
808 +--- mysql-orig/sql/filesort.cc 2012-08-14 01:12:29.413437640 +0000
809 ++++ mysql/sql/filesort.cc 2012-08-14 01:14:59.382197947 +0000
810 +@@ -194,7 +194,7 @@
811 + #ifdef CAN_TRUST_RANGE
812 + if (select && select->quick && select->quick->records > 0L)
813 + {
814 +- records=min((ha_rows) (select->quick->records*2+EXTRA_RECORDS*2),
815 ++ records=MYSQL_MIN((ha_rows) (select->quick->records*2+EXTRA_RECORDS*2),
816 + table->file->stats.records)+EXTRA_RECORDS;
817 + selected_records_file=0;
818 + }
819 +@@ -216,12 +216,12 @@
820 + goto err;
821 +
822 + memavl= thd->variables.sortbuff_size;
823 +- min_sort_memory= max(MIN_SORT_MEMORY, param.sort_length*MERGEBUFF2);
824 ++ min_sort_memory= MYSQL_MAX(MIN_SORT_MEMORY, param.sort_length*MERGEBUFF2);
825 + while (memavl >= min_sort_memory)
826 + {
827 + ulong old_memavl;
828 + ulong keys= memavl/(param.rec_length+sizeof(char*));
829 +- param.keys=(uint) min(records+1, keys);
830 ++ param.keys=(uint) MYSQL_MIN(records+1, keys);
831 +
832 + if (table_sort.sort_keys &&
833 + table_sort.sort_keys_size != char_array_size(param.keys,
834 +@@ -1133,7 +1133,7 @@
835 + register uint count;
836 + uint length;
837 +
838 +- if ((count=(uint) min((ha_rows) buffpek->max_keys,buffpek->count)))
839 ++ if ((count=(uint) MYSQL_MIN((ha_rows) buffpek->max_keys,buffpek->count)))
840 + {
841 + if (my_pread(fromfile->file,(uchar*) buffpek->base,
842 + (length= rec_length*count),buffpek->file_pos,MYF_RW))
843 +@@ -1396,7 +1396,7 @@
844 + != -1 && error != 0);
845 +
846 + end:
847 +- lastbuff->count= min(org_max_rows-max_rows, param->max_rows);
848 ++ lastbuff->count= MYSQL_MIN(org_max_rows-max_rows, param->max_rows);
849 + lastbuff->file_pos= to_start_filepos;
850 + err:
851 + delete_queue(&queue);
852 +diff -ur mysql-orig/sql/ha_ndbcluster.cc mysql/sql/ha_ndbcluster.cc
853 +--- mysql-orig/sql/ha_ndbcluster.cc 2012-08-14 01:12:29.413437640 +0000
854 ++++ mysql/sql/ha_ndbcluster.cc 2012-08-14 01:14:59.382197947 +0000
855 +@@ -799,7 +799,7 @@
856 +
857 + DBUG_PRINT("value", ("set blob ptr: 0x%lx len: %u",
858 + (long) blob_ptr, blob_len));
859 +- DBUG_DUMP("value", blob_ptr, min(blob_len, 26));
860 ++ DBUG_DUMP("value", blob_ptr, MYSQL_MIN(blob_len, 26));
861 +
862 + if (set_blob_value)
863 + *set_blob_value= TRUE;
864 +diff -ur mysql-orig/sql/handler.h mysql/sql/handler.h
865 +--- mysql-orig/sql/handler.h 2012-08-14 01:12:29.423437567 +0000
866 ++++ mysql/sql/handler.h 2012-08-14 01:14:59.382197947 +0000
867 +@@ -1607,15 +1607,15 @@
868 + { return (HA_ERR_WRONG_COMMAND); }
869 +
870 + uint max_record_length() const
871 +- { return min(HA_MAX_REC_LENGTH, max_supported_record_length()); }
872 ++ { return MYSQL_MIN(HA_MAX_REC_LENGTH, max_supported_record_length()); }
873 + uint max_keys() const
874 +- { return min(MAX_KEY, max_supported_keys()); }
875 ++ { return MYSQL_MIN(MAX_KEY, max_supported_keys()); }
876 + uint max_key_parts() const
877 +- { return min(MAX_REF_PARTS, max_supported_key_parts()); }
878 ++ { return MYSQL_MIN(MAX_REF_PARTS, max_supported_key_parts()); }
879 + uint max_key_length() const
880 +- { return min(MAX_KEY_LENGTH, max_supported_key_length()); }
881 ++ { return MYSQL_MIN(MAX_KEY_LENGTH, max_supported_key_length()); }
882 + uint max_key_part_length() const
883 +- { return min(MAX_KEY_LENGTH, max_supported_key_part_length()); }
884 ++ { return MYSQL_MIN(MAX_KEY_LENGTH, max_supported_key_part_length()); }
885 +
886 + virtual uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; }
887 + virtual uint max_supported_keys() const { return 0; }
888 +diff -ur mysql-orig/sql/ha_partition.cc mysql/sql/ha_partition.cc
889 +--- mysql-orig/sql/ha_partition.cc 2012-08-14 01:12:29.423437567 +0000
890 ++++ mysql/sql/ha_partition.cc 2012-08-14 01:14:59.392197867 +0000
891 +@@ -6138,7 +6138,7 @@
892 + {
893 + *first= bitmap_get_first_set(&(m_part_info->used_partitions));
894 + *num_used_parts= bitmap_bits_set(&(m_part_info->used_partitions));
895 +- *check_min_num= min(MAX_PARTS_FOR_OPTIMIZER_CALLS, *num_used_parts);
896 ++ *check_min_num= MYSQL_MIN(MAX_PARTS_FOR_OPTIMIZER_CALLS, *num_used_parts);
897 + }
898 +
899 +
900 +diff -ur mysql-orig/sql/item_buff.cc mysql/sql/item_buff.cc
901 +--- mysql-orig/sql/item_buff.cc 2012-08-14 01:12:29.423437567 +0000
902 ++++ mysql/sql/item_buff.cc 2012-08-14 01:14:59.392197867 +0000
903 +@@ -61,7 +61,7 @@
904 +
905 + Cached_item_str::Cached_item_str(THD *thd, Item *arg)
906 + :item(arg),
907 +- value_max_length(min(arg->max_length, thd->variables.max_sort_length)),
908 ++ value_max_length(MYSQL_MIN(arg->max_length, thd->variables.max_sort_length)),
909 + value(value_max_length)
910 + {}
911 +
912 +@@ -71,7 +71,7 @@
913 + bool tmp;
914 +
915 + if ((res=item->val_str(&tmp_value)))
916 +- res->length(min(res->length(), value_max_length));
917 ++ res->length(MYSQL_MIN(res->length(), value_max_length));
918 + if (null_value != item->null_value)
919 + {
920 + if ((null_value= item->null_value))
921 +diff -ur mysql-orig/sql/item.cc mysql/sql/item.cc
922 +--- mysql-orig/sql/item.cc 2012-08-14 01:12:29.423437567 +0000
923 ++++ mysql/sql/item.cc 2012-08-14 01:14:59.392197867 +0000
924 +@@ -76,7 +76,7 @@
925 + Hybrid_type_traits_decimal::fix_length_and_dec(Item *item, Item *arg) const
926 + {
927 + item->decimals= arg->decimals;
928 +- item->max_length= min(arg->max_length + DECIMAL_LONGLONG_DIGITS,
929 ++ item->max_length= MYSQL_MIN(arg->max_length + DECIMAL_LONGLONG_DIGITS,
930 + DECIMAL_MAX_STR_LENGTH);
931 + }
932 +
933 +@@ -444,9 +444,9 @@
934 + {
935 + uint prec=
936 + my_decimal_length_to_precision(max_length, decimals, unsigned_flag);
937 +- return min(prec, DECIMAL_MAX_PRECISION);
938 ++ return MYSQL_MIN(prec, DECIMAL_MAX_PRECISION);
939 + }
940 +- return min(max_length, DECIMAL_MAX_PRECISION);
941 ++ return MYSQL_MIN(max_length, DECIMAL_MAX_PRECISION);
942 + }
943 +
944 +
945 +@@ -752,7 +752,7 @@
946 + &res_length);
947 + }
948 + else
949 +- name= sql_strmake(str, (name_length= min(length,MAX_ALIAS_NAME)));
950 ++ name= sql_strmake(str, (name_length= MYSQL_MIN(length,MAX_ALIAS_NAME)));
951 + }
952 +
953 +
954 +@@ -5417,7 +5417,7 @@
955 + // following assert is redundant, because fixed=1 assigned in constructor
956 + DBUG_ASSERT(fixed == 1);
957 + char *end=(char*) str_value.ptr()+str_value.length(),
958 +- *ptr=end-min(str_value.length(),sizeof(longlong));
959 ++ *ptr=end-MYSQL_MIN(str_value.length(),sizeof(longlong));
960 +
961 + ulonglong value=0;
962 + for (; ptr != end ; ptr++)
963 +@@ -5472,7 +5472,7 @@
964 + void Item_hex_string::print(String *str, enum_query_type query_type)
965 + {
966 + char *end= (char*) str_value.ptr() + str_value.length(),
967 +- *ptr= end - min(str_value.length(), sizeof(longlong));
968 ++ *ptr= end - MYSQL_MIN(str_value.length(), sizeof(longlong));
969 + str->append("0x");
970 + for (; ptr != end ; ptr++)
971 + {
972 +@@ -7554,14 +7554,14 @@
973 + /* fix variable decimals which always is NOT_FIXED_DEC */
974 + if (Field::result_merge_type(fld_type) == INT_RESULT)
975 + item_decimals= 0;
976 +- decimals= max(decimals, item_decimals);
977 ++ decimals= MYSQL_MAX(decimals, item_decimals);
978 + }
979 + if (Field::result_merge_type(fld_type) == DECIMAL_RESULT)
980 + {
981 +- decimals= min(max(decimals, item->decimals), DECIMAL_MAX_SCALE);
982 ++ decimals= MYSQL_MIN(MYSQL_MAX(decimals, item->decimals), DECIMAL_MAX_SCALE);
983 + int item_int_part= item->decimal_int_part();
984 +- int item_prec = max(prev_decimal_int_part, item_int_part) + decimals;
985 +- int precision= min(item_prec, DECIMAL_MAX_PRECISION);
986 ++ int item_prec = MYSQL_MAX(prev_decimal_int_part, item_int_part) + decimals;
987 ++ int precision= MYSQL_MIN(item_prec, DECIMAL_MAX_PRECISION);
988 + unsigned_flag&= item->unsigned_flag;
989 + max_length= my_decimal_precision_to_length_no_truncation(precision,
990 + decimals,
991 +@@ -7592,7 +7592,7 @@
992 + */
993 + if (collation.collation != &my_charset_bin)
994 + {
995 +- max_length= max(old_max_chars * collation.collation->mbmaxlen,
996 ++ max_length= MYSQL_MAX(old_max_chars * collation.collation->mbmaxlen,
997 + display_length(item) /
998 + item->collation.collation->mbmaxlen *
999 + collation.collation->mbmaxlen);
1000 +@@ -7614,7 +7614,7 @@
1001 + {
1002 + int delta1= max_length_orig - decimals_orig;
1003 + int delta2= item->max_length - item->decimals;
1004 +- max_length= max(delta1, delta2) + decimals;
1005 ++ max_length= MYSQL_MAX(delta1, delta2) + decimals;
1006 + if (fld_type == MYSQL_TYPE_FLOAT && max_length > FLT_DIG + 2)
1007 + {
1008 + max_length= MAX_FLOAT_STR_LENGTH;
1009 +@@ -7632,7 +7632,7 @@
1010 + break;
1011 + }
1012 + default:
1013 +- max_length= max(max_length, display_length(item));
1014 ++ max_length= MYSQL_MAX(max_length, display_length(item));
1015 + };
1016 + maybe_null|= item->maybe_null;
1017 + get_full_info(item);
1018 +diff -ur mysql-orig/sql/item_cmpfunc.cc mysql/sql/item_cmpfunc.cc
1019 +--- mysql-orig/sql/item_cmpfunc.cc 2012-08-14 01:12:29.423437567 +0000
1020 ++++ mysql/sql/item_cmpfunc.cc 2012-08-14 01:14:59.392197867 +0000
1021 +@@ -628,7 +628,7 @@
1022 + {
1023 + if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
1024 + {
1025 +- precision= 5 / log_10[max((*a)->decimals, (*b)->decimals) + 1];
1026 ++ precision= 5 / log_10[MYSQL_MAX((*a)->decimals, (*b)->decimals) + 1];
1027 + if (func == &Arg_comparator::compare_real)
1028 + func= &Arg_comparator::compare_real_fixed;
1029 + else if (func == &Arg_comparator::compare_e_real)
1030 +@@ -1315,7 +1315,7 @@
1031 + owner->null_value= 0;
1032 + uint res1_length= res1->length();
1033 + uint res2_length= res2->length();
1034 +- int cmp= memcmp(res1->ptr(), res2->ptr(), min(res1_length,res2_length));
1035 ++ int cmp= memcmp(res1->ptr(), res2->ptr(), MYSQL_MIN(res1_length,res2_length));
1036 + return cmp ? cmp : (int) (res1_length - res2_length);
1037 + }
1038 + }
1039 +@@ -2447,7 +2447,7 @@
1040 + {
1041 + agg_result_type(&hybrid_type, args, 2);
1042 + maybe_null=args[1]->maybe_null;
1043 +- decimals= max(args[0]->decimals, args[1]->decimals);
1044 ++ decimals= MYSQL_MAX(args[0]->decimals, args[1]->decimals);
1045 + unsigned_flag= args[0]->unsigned_flag && args[1]->unsigned_flag;
1046 +
1047 + if (hybrid_type == DECIMAL_RESULT || hybrid_type == INT_RESULT)
1048 +@@ -2458,10 +2458,10 @@
1049 + int len1= args[1]->max_length - args[1]->decimals
1050 + - (args[1]->unsigned_flag ? 0 : 1);
1051 +
1052 +- max_length= max(len0, len1) + decimals + (unsigned_flag ? 0 : 1);
1053 ++ max_length= MYSQL_MAX(len0, len1) + decimals + (unsigned_flag ? 0 : 1);
1054 + }
1055 + else
1056 +- max_length= max(args[0]->max_length, args[1]->max_length);
1057 ++ max_length= MYSQL_MAX(args[0]->max_length, args[1]->max_length);
1058 +
1059 + switch (hybrid_type) {
1060 + case STRING_RESULT:
1061 +@@ -2485,9 +2485,9 @@
1062 + {
1063 + int arg0_int_part= args[0]->decimal_int_part();
1064 + int arg1_int_part= args[1]->decimal_int_part();
1065 +- int max_int_part= max(arg0_int_part, arg1_int_part);
1066 ++ int max_int_part= MYSQL_MAX(arg0_int_part, arg1_int_part);
1067 + int precision= max_int_part + decimals;
1068 +- return min(precision, DECIMAL_MAX_PRECISION);
1069 ++ return MYSQL_MIN(precision, DECIMAL_MAX_PRECISION);
1070 + }
1071 +
1072 +
1073 +@@ -2615,7 +2615,7 @@
1074 + Item_func_if::fix_length_and_dec()
1075 + {
1076 + maybe_null=args[1]->maybe_null || args[2]->maybe_null;
1077 +- decimals= max(args[1]->decimals, args[2]->decimals);
1078 ++ decimals= MYSQL_MAX(args[1]->decimals, args[2]->decimals);
1079 + unsigned_flag=args[1]->unsigned_flag && args[2]->unsigned_flag;
1080 +
1081 + enum Item_result arg1_type=args[1]->result_type();
1082 +@@ -2659,10 +2659,10 @@
1083 + int len2= args[2]->max_length - args[2]->decimals
1084 + - (args[2]->unsigned_flag ? 0 : 1);
1085 +
1086 +- max_length=max(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
1087 ++ max_length=MYSQL_MAX(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
1088 + }
1089 + else
1090 +- max_length= max(args[1]->max_length, args[2]->max_length);
1091 ++ max_length= MYSQL_MAX(args[1]->max_length, args[2]->max_length);
1092 + }
1093 +
1094 +
1095 +@@ -2670,8 +2670,8 @@
1096 + {
1097 + int arg1_prec= args[1]->decimal_int_part();
1098 + int arg2_prec= args[2]->decimal_int_part();
1099 +- int precision=max(arg1_prec,arg2_prec) + decimals;
1100 +- return min(precision, DECIMAL_MAX_PRECISION);
1101 ++ int precision=MYSQL_MAX(arg1_prec,arg2_prec) + decimals;
1102 ++ return MYSQL_MIN(precision, DECIMAL_MAX_PRECISION);
1103 + }
1104 +
1105 +
1106 +@@ -3081,7 +3081,7 @@
1107 +
1108 + if (else_expr_num != -1)
1109 + set_if_bigger(max_int_part, args[else_expr_num]->decimal_int_part());
1110 +- return min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
1111 ++ return MYSQL_MIN(max_int_part + decimals, DECIMAL_MAX_PRECISION);
1112 + }
1113 +
1114 +
1115 +@@ -4979,7 +4979,7 @@
1116 + else
1117 + {
1118 + if (i < g)
1119 +- g = i; // g = min(i, g)
1120 ++ g = i; // g = MYSQL_MIN(i, g)
1121 + f = i;
1122 + while (g >= 0 && pattern[g] == pattern[g + plm1 - f])
1123 + g--;
1124 +@@ -4998,7 +4998,7 @@
1125 + else
1126 + {
1127 + if (i < g)
1128 +- g = i; // g = min(i, g)
1129 ++ g = i; // g = MYSQL_MIN(i, g)
1130 + f = i;
1131 + while (g >= 0 &&
1132 + likeconv(cs, pattern[g]) == likeconv(cs, pattern[g + plm1 - f]))
1133 +@@ -5119,14 +5119,14 @@
1134 + register const int v = plm1 - i;
1135 + turboShift = u - v;
1136 + bcShift = bmBc[(uint) (uchar) text[i + j]] - plm1 + i;
1137 +- shift = max(turboShift, bcShift);
1138 +- shift = max(shift, bmGs[i]);
1139 ++ shift = MYSQL_MAX(turboShift, bcShift);
1140 ++ shift = MYSQL_MAX(shift, bmGs[i]);
1141 + if (shift == bmGs[i])
1142 +- u = min(pattern_len - shift, v);
1143 ++ u = MYSQL_MIN(pattern_len - shift, v);
1144 + else
1145 + {
1146 + if (turboShift < bcShift)
1147 +- shift = max(shift, u + 1);
1148 ++ shift = MYSQL_MAX(shift, u + 1);
1149 + u = 0;
1150 + }
1151 + j+= shift;
1152 +@@ -5150,14 +5150,14 @@
1153 + register const int v = plm1 - i;
1154 + turboShift = u - v;
1155 + bcShift = bmBc[(uint) likeconv(cs, text[i + j])] - plm1 + i;
1156 +- shift = max(turboShift, bcShift);
1157 +- shift = max(shift, bmGs[i]);
1158 ++ shift = MYSQL_MAX(turboShift, bcShift);
1159 ++ shift = MYSQL_MAX(shift, bmGs[i]);
1160 + if (shift == bmGs[i])
1161 +- u = min(pattern_len - shift, v);
1162 ++ u = MYSQL_MIN(pattern_len - shift, v);
1163 + else
1164 + {
1165 + if (turboShift < bcShift)
1166 +- shift = max(shift, u + 1);
1167 ++ shift = MYSQL_MAX(shift, u + 1);
1168 + u = 0;
1169 + }
1170 + j+= shift;
1171 +diff -ur mysql-orig/sql/item_func.cc mysql/sql/item_func.cc
1172 +--- mysql-orig/sql/item_func.cc 2012-08-14 01:12:29.423437567 +0000
1173 ++++ mysql/sql/item_func.cc 2012-08-14 01:14:59.392197867 +0000
1174 +@@ -549,7 +549,7 @@
1175 + set_if_bigger(max_int_part, args[i]->decimal_int_part());
1176 + set_if_smaller(unsigned_flag, args[i]->unsigned_flag);
1177 + }
1178 +- int precision= min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
1179 ++ int precision= MYSQL_MIN(max_int_part + decimals, DECIMAL_MAX_PRECISION);
1180 + max_length= my_decimal_precision_to_length_no_truncation(precision, decimals,
1181 + unsigned_flag);
1182 + }
1183 +@@ -1143,10 +1143,10 @@
1184 + */
1185 + void Item_func_additive_op::result_precision()
1186 + {
1187 +- decimals= max(args[0]->decimals, args[1]->decimals);
1188 ++ decimals= MYSQL_MAX(args[0]->decimals, args[1]->decimals);
1189 + int arg1_int= args[0]->decimal_precision() - args[0]->decimals;
1190 + int arg2_int= args[1]->decimal_precision() - args[1]->decimals;
1191 +- int precision= max(arg1_int, arg2_int) + 1 + decimals;
1192 ++ int precision= MYSQL_MAX(arg1_int, arg2_int) + 1 + decimals;
1193 +
1194 + /* Integer operations keep unsigned_flag if one of arguments is unsigned */
1195 + if (result_type() == INT_RESULT)
1196 +@@ -1256,9 +1256,9 @@
1197 + unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag;
1198 + else
1199 + unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
1200 +- decimals= min(args[0]->decimals + args[1]->decimals, DECIMAL_MAX_SCALE);
1201 ++ decimals= MYSQL_MIN(args[0]->decimals + args[1]->decimals, DECIMAL_MAX_SCALE);
1202 + uint est_prec = args[0]->decimal_precision() + args[1]->decimal_precision();
1203 +- uint precision= min(est_prec, DECIMAL_MAX_PRECISION);
1204 ++ uint precision= MYSQL_MIN(est_prec, DECIMAL_MAX_PRECISION);
1205 + max_length= my_decimal_precision_to_length_no_truncation(precision, decimals,
1206 + unsigned_flag);
1207 + }
1208 +@@ -1306,7 +1306,7 @@
1209 +
1210 + void Item_func_div::result_precision()
1211 + {
1212 +- uint precision=min(args[0]->decimal_precision() +
1213 ++ uint precision=MYSQL_MIN(args[0]->decimal_precision() +
1214 + args[1]->decimals + prec_increment,
1215 + DECIMAL_MAX_PRECISION);
1216 +
1217 +@@ -1315,7 +1315,7 @@
1218 + unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag;
1219 + else
1220 + unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
1221 +- decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
1222 ++ decimals= MYSQL_MIN(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
1223 + max_length= my_decimal_precision_to_length_no_truncation(precision, decimals,
1224 + unsigned_flag);
1225 + }
1226 +@@ -1329,7 +1329,7 @@
1227 + switch(hybrid_type) {
1228 + case REAL_RESULT:
1229 + {
1230 +- decimals=max(args[0]->decimals,args[1]->decimals)+prec_increment;
1231 ++ decimals=MYSQL_MAX(args[0]->decimals,args[1]->decimals)+prec_increment;
1232 + set_if_smaller(decimals, NOT_FIXED_DEC);
1233 + uint tmp=float_length(decimals);
1234 + if (decimals == NOT_FIXED_DEC)
1235 +@@ -1460,8 +1460,8 @@
1236 +
1237 + void Item_func_mod::result_precision()
1238 + {
1239 +- decimals= max(args[0]->decimals, args[1]->decimals);
1240 +- max_length= max(args[0]->max_length, args[1]->max_length);
1241 ++ decimals= MYSQL_MAX(args[0]->decimals, args[1]->decimals);
1242 ++ max_length= MYSQL_MAX(args[0]->max_length, args[1]->max_length);
1243 + }
1244 +
1245 +
1246 +@@ -1983,7 +1983,7 @@
1247 +
1248 + if (args[0]->decimals == NOT_FIXED_DEC)
1249 + {
1250 +- decimals= min(decimals_to_set, NOT_FIXED_DEC);
1251 ++ decimals= MYSQL_MIN(decimals_to_set, NOT_FIXED_DEC);
1252 + max_length= float_length(decimals);
1253 + hybrid_type= REAL_RESULT;
1254 + return;
1255 +@@ -1993,7 +1993,7 @@
1256 + case REAL_RESULT:
1257 + case STRING_RESULT:
1258 + hybrid_type= REAL_RESULT;
1259 +- decimals= min(decimals_to_set, NOT_FIXED_DEC);
1260 ++ decimals= MYSQL_MIN(decimals_to_set, NOT_FIXED_DEC);
1261 + max_length= float_length(decimals);
1262 + break;
1263 + case INT_RESULT:
1264 +@@ -2010,13 +2010,13 @@
1265 + case DECIMAL_RESULT:
1266 + {
1267 + hybrid_type= DECIMAL_RESULT;
1268 +- decimals_to_set= min(DECIMAL_MAX_SCALE, decimals_to_set);
1269 ++ decimals_to_set= MYSQL_MIN(DECIMAL_MAX_SCALE, decimals_to_set);
1270 + int decimals_delta= args[0]->decimals - decimals_to_set;
1271 + int precision= args[0]->decimal_precision();
1272 + int length_increase= ((decimals_delta <= 0) || truncate) ? 0:1;
1273 +
1274 + precision-= decimals_delta - length_increase;
1275 +- decimals= min(decimals_to_set, DECIMAL_MAX_SCALE);
1276 ++ decimals= MYSQL_MIN(decimals_to_set, DECIMAL_MAX_SCALE);
1277 + max_length= my_decimal_precision_to_length_no_truncation(precision,
1278 + decimals,
1279 + unsigned_flag);
1280 +@@ -2117,7 +2117,7 @@
1281 + my_decimal val, *value= args[0]->val_decimal(&val);
1282 + longlong dec= args[1]->val_int();
1283 + if (dec >= 0 || args[1]->unsigned_flag)
1284 +- dec= min((ulonglong) dec, decimals);
1285 ++ dec= MYSQL_MIN((ulonglong) dec, decimals);
1286 + else if (dec < INT_MIN)
1287 + dec= INT_MIN;
1288 +
1289 +@@ -2989,7 +2989,7 @@
1290 + free_udf(u_d);
1291 + DBUG_RETURN(TRUE);
1292 + }
1293 +- func->max_length=min(initid.max_length,MAX_BLOB_WIDTH);
1294 ++ func->max_length=MYSQL_MIN(initid.max_length,MAX_BLOB_WIDTH);
1295 + func->maybe_null=initid.maybe_null;
1296 + const_item_cache=initid.const_item;
1297 + /*
1298 +@@ -2998,7 +2998,7 @@
1299 + */
1300 + if (!const_item_cache && !used_tables_cache)
1301 + used_tables_cache= RAND_TABLE_BIT;
1302 +- func->decimals=min(initid.decimals,NOT_FIXED_DEC);
1303 ++ func->decimals=MYSQL_MIN(initid.decimals,NOT_FIXED_DEC);
1304 + }
1305 + initialized=1;
1306 + if (error)
1307 +diff -ur mysql-orig/sql/item_func.h mysql/sql/item_func.h
1308 +--- mysql-orig/sql/item_func.h 2012-08-14 01:12:29.423437567 +0000
1309 ++++ mysql/sql/item_func.h 2012-08-14 01:14:59.402197785 +0000
1310 +@@ -421,7 +421,7 @@
1311 + const char *func_name() const { return "cast_as_unsigned"; }
1312 + void fix_length_and_dec()
1313 + {
1314 +- max_length= min(args[0]->max_length, MY_INT64_NUM_DECIMAL_DIGITS);
1315 ++ max_length= MYSQL_MIN(args[0]->max_length, MY_INT64_NUM_DECIMAL_DIGITS);
1316 + unsigned_flag=1;
1317 + }
1318 + longlong val_int();
1319 +diff -ur mysql-orig/sql/item_strfunc.cc mysql/sql/item_strfunc.cc
1320 +--- mysql-orig/sql/item_strfunc.cc 2012-08-14 01:12:29.413437640 +0000
1321 ++++ mysql/sql/item_strfunc.cc 2012-08-14 01:14:59.402197785 +0000
1322 +@@ -389,7 +389,7 @@
1323 + }
1324 + else
1325 + {
1326 +- uint new_len = max(tmp_value.alloced_length() * 2, concat_len);
1327 ++ uint new_len = MYSQL_MAX(tmp_value.alloced_length() * 2, concat_len);
1328 +
1329 + if (tmp_value.realloc(new_len))
1330 + goto null;
1331 +@@ -750,7 +750,7 @@
1332 + }
1333 + else
1334 + {
1335 +- uint new_len = max(tmp_value.alloced_length() * 2, concat_len);
1336 ++ uint new_len = MYSQL_MAX(tmp_value.alloced_length() * 2, concat_len);
1337 +
1338 + if (tmp_value.realloc(new_len))
1339 + goto null;
1340 +@@ -1251,7 +1251,7 @@
1341 +
1342 + length= res->charpos((int) length, (uint32) start);
1343 + tmp_length= res->length() - start;
1344 +- length= min(length, tmp_length);
1345 ++ length= MYSQL_MIN(length, tmp_length);
1346 +
1347 + if (!start && (longlong) res->length() == length)
1348 + return res;
1349 +@@ -1271,7 +1271,7 @@
1350 + if (start < 0)
1351 + max_length= ((uint)(-start) > max_length) ? 0 : (uint)(-start);
1352 + else
1353 +- max_length-= min((uint)(start - 1), max_length);
1354 ++ max_length-= MYSQL_MIN((uint)(start - 1), max_length);
1355 + }
1356 + if (arg_count == 3 && args[2]->const_item())
1357 + {
1358 +@@ -1962,7 +1962,7 @@
1359 + if ((null_value= args[0]->null_value))
1360 + return 0; /* purecov: inspected */
1361 +
1362 +- if (tmp_value.alloc(max(res->length(), 4 * cs->mbminlen)))
1363 ++ if (tmp_value.alloc(MYSQL_MAX(res->length(), 4 * cs->mbminlen)))
1364 + return str; /* purecov: inspected */
1365 + char *to= (char *) tmp_value.ptr();
1366 + char *to_end= to + tmp_value.alloced_length();
1367 +@@ -3114,11 +3114,11 @@
1368 +
1369 + void Item_func_export_set::fix_length_and_dec()
1370 + {
1371 +- uint length=max(args[1]->max_length,args[2]->max_length);
1372 ++ uint length=MYSQL_MAX(args[1]->max_length,args[2]->max_length);
1373 + uint sep_length=(arg_count > 3 ? args[3]->max_length : 1);
1374 + max_length=length*64+sep_length*63;
1375 +
1376 +- if (agg_arg_charsets(collation, args+1, min(4,arg_count)-1,
1377 ++ if (agg_arg_charsets(collation, args+1, MYSQL_MIN(4,arg_count)-1,
1378 + MY_COLL_ALLOW_CONV, 1))
1379 + return;
1380 + }
1381 +@@ -3582,7 +3582,7 @@
1382 + /*
1383 + -1 so we won't make tv= uuid_time for nanoseq >= (tv - uuid_time)
1384 + */
1385 +- ulong delta= min(nanoseq, (ulong) (tv - uuid_time -1));
1386 ++ ulong delta= MYSQL_MIN(nanoseq, (ulong) (tv - uuid_time -1));
1387 + tv-= delta;
1388 + nanoseq-= delta;
1389 + }
1390 +diff -ur mysql-orig/sql/item_strfunc.h mysql/sql/item_strfunc.h
1391 +--- mysql-orig/sql/item_strfunc.h 2012-08-14 01:12:29.413437640 +0000
1392 ++++ mysql/sql/item_strfunc.h 2012-08-14 01:14:59.402197785 +0000
1393 +@@ -709,7 +709,7 @@
1394 + collation.set(args[0]->collation);
1395 + ulonglong max_result_length= (ulonglong) args[0]->max_length * 2 +
1396 + 2 * collation.collation->mbmaxlen;
1397 +- max_length= (uint32) min(max_result_length, MAX_BLOB_WIDTH);
1398 ++ max_length= (uint32) MYSQL_MIN(max_result_length, MAX_BLOB_WIDTH);
1399 + }
1400 + };
1401 +
1402 +diff -ur mysql-orig/sql/item_sum.cc mysql/sql/item_sum.cc
1403 +--- mysql-orig/sql/item_sum.cc 2012-08-14 01:12:29.413437640 +0000
1404 ++++ mysql/sql/item_sum.cc 2012-08-14 01:14:59.402197785 +0000
1405 +@@ -1139,7 +1139,7 @@
1406 + AVG() will divide val by count. We need to reserve digits
1407 + after decimal point as the result can be fractional.
1408 + */
1409 +- decimals= min(decimals + prec_increment, NOT_FIXED_DEC);
1410 ++ decimals= MYSQL_MIN(decimals + prec_increment, NOT_FIXED_DEC);
1411 + }
1412 +
1413 +
1414 +@@ -1202,16 +1202,16 @@
1415 + if (hybrid_type == DECIMAL_RESULT)
1416 + {
1417 + int precision= args[0]->decimal_precision() + prec_increment;
1418 +- decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
1419 ++ decimals= MYSQL_MIN(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
1420 + max_length= my_decimal_precision_to_length_no_truncation(precision,
1421 + decimals,
1422 + unsigned_flag);
1423 +- f_precision= min(precision+DECIMAL_LONGLONG_DIGITS, DECIMAL_MAX_PRECISION);
1424 ++ f_precision= MYSQL_MIN(precision+DECIMAL_LONGLONG_DIGITS, DECIMAL_MAX_PRECISION);
1425 + f_scale= args[0]->decimals;
1426 + dec_bin_size= my_decimal_get_binary_size(f_precision, f_scale);
1427 + }
1428 + else {
1429 +- decimals= min(args[0]->decimals + prec_increment, NOT_FIXED_DEC);
1430 ++ decimals= MYSQL_MIN(args[0]->decimals + prec_increment, NOT_FIXED_DEC);
1431 + max_length= args[0]->max_length + prec_increment;
1432 + }
1433 + }
1434 +@@ -1402,13 +1402,13 @@
1435 + switch (args[0]->result_type()) {
1436 + case REAL_RESULT:
1437 + case STRING_RESULT:
1438 +- decimals= min(args[0]->decimals + 4, NOT_FIXED_DEC);
1439 ++ decimals= MYSQL_MIN(args[0]->decimals + 4, NOT_FIXED_DEC);
1440 + break;
1441 + case INT_RESULT:
1442 + case DECIMAL_RESULT:
1443 + {
1444 + int precision= args[0]->decimal_precision()*2 + prec_increment;
1445 +- decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
1446 ++ decimals= MYSQL_MIN(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
1447 + max_length= my_decimal_precision_to_length_no_truncation(precision,
1448 + decimals,
1449 + unsigned_flag);
1450 +@@ -3345,7 +3345,7 @@
1451 + syntax of this function). If there is no ORDER BY clause, we don't
1452 + create this tree.
1453 + */
1454 +- init_tree(tree, (uint) min(thd->variables.max_heap_table_size,
1455 ++ init_tree(tree, (uint) MYSQL_MIN(thd->variables.max_heap_table_size,
1456 + thd->variables.sortbuff_size/16), 0,
1457 + tree_key_length,
1458 + group_concat_key_cmp_with_order , 0, NULL, (void*) this);
1459 +diff -ur mysql-orig/sql/item_timefunc.cc mysql/sql/item_timefunc.cc
1460 +--- mysql-orig/sql/item_timefunc.cc 2012-08-14 01:12:29.423437567 +0000
1461 ++++ mysql/sql/item_timefunc.cc 2012-08-14 01:14:59.402197785 +0000
1462 +@@ -310,14 +310,14 @@
1463 + switch (*++ptr) {
1464 + /* Year */
1465 + case 'Y':
1466 +- tmp= (char*) val + min(4, val_len);
1467 ++ tmp= (char*) val + MYSQL_MIN(4, val_len);
1468 + l_time->year= (int) my_strtoll10(val, &tmp, &error);
1469 + if ((int) (tmp-val) <= 2)
1470 + l_time->year= year_2000_handling(l_time->year);
1471 + val= tmp;
1472 + break;
1473 + case 'y':
1474 +- tmp= (char*) val + min(2, val_len);
1475 ++ tmp= (char*) val + MYSQL_MIN(2, val_len);
1476 + l_time->year= (int) my_strtoll10(val, &tmp, &error);
1477 + val= tmp;
1478 + l_time->year= year_2000_handling(l_time->year);
1479 +@@ -326,7 +326,7 @@
1480 + /* Month */
1481 + case 'm':
1482 + case 'c':
1483 +- tmp= (char*) val + min(2, val_len);
1484 ++ tmp= (char*) val + MYSQL_MIN(2, val_len);
1485 + l_time->month= (int) my_strtoll10(val, &tmp, &error);
1486 + val= tmp;
1487 + break;
1488 +@@ -343,15 +343,15 @@
1489 + /* Day */
1490 + case 'd':
1491 + case 'e':
1492 +- tmp= (char*) val + min(2, val_len);
1493 ++ tmp= (char*) val + MYSQL_MIN(2, val_len);
1494 + l_time->day= (int) my_strtoll10(val, &tmp, &error);
1495 + val= tmp;
1496 + break;
1497 + case 'D':
1498 +- tmp= (char*) val + min(2, val_len);
1499 ++ tmp= (char*) val + MYSQL_MIN(2, val_len);
1500 + l_time->day= (int) my_strtoll10(val, &tmp, &error);
1501 + /* Skip 'st, 'nd, 'th .. */
1502 +- val= tmp + min((int) (val_end-tmp), 2);
1503 ++ val= tmp + MYSQL_MIN((int) (val_end-tmp), 2);
1504 + break;
1505 +
1506 + /* Hour */
1507 +@@ -362,14 +362,14 @@
1508 + /* fall through */
1509 + case 'k':
1510 + case 'H':
1511 +- tmp= (char*) val + min(2, val_len);
1512 ++ tmp= (char*) val + MYSQL_MIN(2, val_len);
1513 + l_time->hour= (int) my_strtoll10(val, &tmp, &error);
1514 + val= tmp;
1515 + break;
1516 +
1517 + /* Minute */
1518 + case 'i':
1519 +- tmp= (char*) val + min(2, val_len);
1520 ++ tmp= (char*) val + MYSQL_MIN(2, val_len);
1521 + l_time->minute= (int) my_strtoll10(val, &tmp, &error);
1522 + val= tmp;
1523 + break;
1524 +@@ -377,7 +377,7 @@
1525 + /* Second */
1526 + case 's':
1527 + case 'S':
1528 +- tmp= (char*) val + min(2, val_len);
1529 ++ tmp= (char*) val + MYSQL_MIN(2, val_len);
1530 + l_time->second= (int) my_strtoll10(val, &tmp, &error);
1531 + val= tmp;
1532 + break;
1533 +@@ -429,7 +429,7 @@
1534 + val= tmp;
1535 + break;
1536 + case 'j':
1537 +- tmp= (char*) val + min(val_len, 3);
1538 ++ tmp= (char*) val + MYSQL_MIN(val_len, 3);
1539 + yearday= (int) my_strtoll10(val, &tmp, &error);
1540 + val= tmp;
1541 + break;
1542 +@@ -441,7 +441,7 @@
1543 + case 'u':
1544 + sunday_first_n_first_week_non_iso= (*ptr=='U' || *ptr== 'V');
1545 + strict_week_number= (*ptr=='V' || *ptr=='v');
1546 +- tmp= (char*) val + min(val_len, 2);
1547 ++ tmp= (char*) val + MYSQL_MIN(val_len, 2);
1548 + if ((week_number= (int) my_strtoll10(val, &tmp, &error)) < 0 ||
1549 + (strict_week_number && !week_number) ||
1550 + week_number > 53)
1551 +@@ -453,7 +453,7 @@
1552 + case 'X':
1553 + case 'x':
1554 + strict_week_number_year_type= (*ptr=='X');
1555 +- tmp= (char*) val + min(4, val_len);
1556 ++ tmp= (char*) val + MYSQL_MIN(4, val_len);
1557 + strict_week_number_year= (int) my_strtoll10(val, &tmp, &error);
1558 + val= tmp;
1559 + break;
1560 +@@ -598,7 +598,7 @@
1561 + err:
1562 + {
1563 + char buff[128];
1564 +- strmake(buff, val_begin, min(length, sizeof(buff)-1));
1565 ++ strmake(buff, val_begin, MYSQL_MIN(length, sizeof(buff)-1));
1566 + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
1567 + ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE),
1568 + date_time_type, buff, "str_to_date");
1569 +@@ -1830,7 +1830,7 @@
1570 + else
1571 + {
1572 + fixed_length=0;
1573 +- max_length=min(arg1->max_length, MAX_BLOB_WIDTH) * 10 *
1574 ++ max_length=MYSQL_MIN(arg1->max_length, MAX_BLOB_WIDTH) * 10 *
1575 + collation.collation->mbmaxlen;
1576 + set_if_smaller(max_length,MAX_BLOB_WIDTH);
1577 + }
1578 +diff -ur mysql-orig/sql/key.cc mysql/sql/key.cc
1579 +--- mysql-orig/sql/key.cc 2012-08-14 01:12:29.413437640 +0000
1580 ++++ mysql/sql/key.cc 2012-08-14 01:14:59.402197785 +0000
1581 +@@ -128,13 +128,13 @@
1582 + key_part->key_part_flag & HA_VAR_LENGTH_PART)
1583 + {
1584 + key_length-= HA_KEY_BLOB_LENGTH;
1585 +- length= min(key_length, key_part->length);
1586 ++ length= MYSQL_MIN(key_length, key_part->length);
1587 + key_part->field->get_key_image(to_key, length, Field::itRAW);
1588 + to_key+= HA_KEY_BLOB_LENGTH;
1589 + }
1590 + else
1591 + {
1592 +- length= min(key_length, key_part->length);
1593 ++ length= MYSQL_MIN(key_length, key_part->length);
1594 + Field *field= key_part->field;
1595 + CHARSET_INFO *cs= field->charset();
1596 + uint bytes= field->get_key_image(to_key, length, Field::itRAW);
1597 +@@ -218,7 +218,7 @@
1598 + my_ptrdiff_t ptrdiff= to_record - field->table->record[0];
1599 + field->move_field_offset(ptrdiff);
1600 + key_length-= HA_KEY_BLOB_LENGTH;
1601 +- length= min(key_length, key_part->length);
1602 ++ length= MYSQL_MIN(key_length, key_part->length);
1603 + old_map= dbug_tmp_use_all_columns(field->table, field->table->write_set);
1604 + field->set_key_image(from_key, length);
1605 + dbug_tmp_restore_column_map(field->table->write_set, old_map);
1606 +@@ -227,7 +227,7 @@
1607 + }
1608 + else
1609 + {
1610 +- length= min(key_length, key_part->length);
1611 ++ length= MYSQL_MIN(key_length, key_part->length);
1612 + /* skip the byte with 'uneven' bits, if used */
1613 + memcpy(to_record + key_part->offset, from_key + used_uneven_bits
1614 + , (size_t) length - used_uneven_bits);
1615 +@@ -288,7 +288,7 @@
1616 + return 1;
1617 + continue;
1618 + }
1619 +- length= min((uint) (key_end-key), store_length);
1620 ++ length= MYSQL_MIN((uint) (key_end-key), store_length);
1621 + if (!(key_part->key_type & (FIELDFLAG_NUMBER+FIELDFLAG_BINARY+
1622 + FIELDFLAG_PACK)))
1623 + {
1624 +@@ -354,7 +354,7 @@
1625 + {
1626 + field->val_str(&tmp);
1627 + if (key_part->length < field->pack_length())
1628 +- tmp.length(min(tmp.length(),key_part->length));
1629 ++ tmp.length(MYSQL_MIN(tmp.length(),key_part->length));
1630 + to->append(tmp);
1631 + }
1632 + else
1633 +diff -ur mysql-orig/sql/log.cc mysql/sql/log.cc
1634 +--- mysql-orig/sql/log.cc 2012-08-14 01:12:29.423437567 +0000
1635 ++++ mysql/sql/log.cc 2012-08-14 01:14:59.402197785 +0000
1636 +@@ -597,11 +597,11 @@
1637 + t.neg= 0;
1638 +
1639 + /* fill in query_time field */
1640 +- calc_time_from_sec(&t, (long) min(query_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
1641 ++ calc_time_from_sec(&t, (long) MYSQL_MIN(query_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
1642 + if (table->field[2]->store_time(&t, MYSQL_TIMESTAMP_TIME))
1643 + goto err;
1644 + /* lock_time */
1645 +- calc_time_from_sec(&t, (long) min(lock_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
1646 ++ calc_time_from_sec(&t, (long) MYSQL_MIN(lock_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
1647 + if (table->field[3]->store_time(&t, MYSQL_TIMESTAMP_TIME))
1648 + goto err;
1649 + /* rows_sent */
1650 +@@ -2432,7 +2432,7 @@
1651 + {
1652 + char *p= fn_ext(log_name);
1653 + uint length= (uint) (p - log_name);
1654 +- strmake(buff, log_name, min(length, FN_REFLEN-1));
1655 ++ strmake(buff, log_name, MYSQL_MIN(length, FN_REFLEN-1));
1656 + return (const char*)buff;
1657 + }
1658 + return log_name;
1659 +@@ -5238,7 +5238,7 @@
1660 + DBUG_ENTER("print_buffer_to_nt_eventlog");
1661 +
1662 + /* Add ending CR/LF's to string, overwrite last chars if necessary */
1663 +- strmov(buffptr+min(length, buffLen-5), "\r\n\r\n");
1664 ++ strmov(buffptr+MYSQL_MIN(length, buffLen-5), "\r\n\r\n");
1665 +
1666 + setup_windows_event_source();
1667 + if ((event= RegisterEventSource(NULL,"MySQL")))
1668 +diff -ur mysql-orig/sql/log_event.cc mysql/sql/log_event.cc
1669 +--- mysql-orig/sql/log_event.cc 2012-08-14 01:12:29.413437640 +0000
1670 ++++ mysql/sql/log_event.cc 2012-08-14 01:14:59.412197702 +0000
1671 +@@ -1099,7 +1099,7 @@
1672 + of 13 bytes, whereas LOG_EVENT_MINIMAL_HEADER_LEN is 19 bytes (it's
1673 + "minimal" over the set {MySQL >=4.0}).
1674 + */
1675 +- uint header_size= min(description_event->common_header_len,
1676 ++ uint header_size= MYSQL_MIN(description_event->common_header_len,
1677 + LOG_EVENT_MINIMAL_HEADER_LEN);
1678 +
1679 + LOCK_MUTEX;
1680 +@@ -2695,7 +2695,7 @@
1681 + be even bigger, but this will suffice to catch most corruption
1682 + errors that can lead to a crash.
1683 + */
1684 +- if (status_vars_len > min(data_len, MAX_SIZE_LOG_EVENT_STATUS))
1685 ++ if (status_vars_len > MYSQL_MIN(data_len, MAX_SIZE_LOG_EVENT_STATUS))
1686 + {
1687 + DBUG_PRINT("info", ("status_vars_len (%u) > data_len (%lu); query= 0",
1688 + status_vars_len, data_len));
1689 +@@ -5676,7 +5676,7 @@
1690 + char buf[UV_NAME_LEN_SIZE];
1691 + char buf1[UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE +
1692 + UV_CHARSET_NUMBER_SIZE + UV_VAL_LEN_SIZE];
1693 +- uchar buf2[max(8, DECIMAL_MAX_FIELD_SIZE + 2)], *pos= buf2;
1694 ++ uchar buf2[MYSQL_MAX(8, DECIMAL_MAX_FIELD_SIZE + 2)], *pos= buf2;
1695 + uint buf1_length;
1696 + ulong event_length;
1697 +
1698 +@@ -7426,7 +7426,7 @@
1699 + trigger false warnings.
1700 + */
1701 + #ifndef HAVE_purify
1702 +- DBUG_DUMP("row_data", row_data, min(length, 32));
1703 ++ DBUG_DUMP("row_data", row_data, MYSQL_MIN(length, 32));
1704 + #endif
1705 +
1706 + DBUG_ASSERT(m_rows_buf <= m_rows_cur);
1707 +diff -ur mysql-orig/sql/log_event_old.cc mysql/sql/log_event_old.cc
1708 +--- mysql-orig/sql/log_event_old.cc 2012-08-14 01:12:29.423437567 +0000
1709 ++++ mysql/sql/log_event_old.cc 2012-08-14 01:14:59.412197702 +0000
1710 +@@ -1434,7 +1434,7 @@
1711 + trigger false warnings.
1712 + */
1713 + #ifndef HAVE_purify
1714 +- DBUG_DUMP("row_data", row_data, min(length, 32));
1715 ++ DBUG_DUMP("row_data", row_data, MYSQL_MIN(length, 32));
1716 + #endif
1717 +
1718 + DBUG_ASSERT(m_rows_buf <= m_rows_cur);
1719 +diff -ur mysql-orig/sql/mysqld.cc mysql/sql/mysqld.cc
1720 +--- mysql-orig/sql/mysqld.cc 2012-08-14 01:12:29.413437640 +0000
1721 ++++ mysql/sql/mysqld.cc 2012-08-14 01:14:59.412197702 +0000
1722 +@@ -3241,7 +3241,7 @@
1723 + can't get max_connections*5 but still got no less than was
1724 + requested (value of wanted_files).
1725 + */
1726 +- max_open_files= max(max(wanted_files, max_connections*5),
1727 ++ max_open_files= MYSQL_MAX(MYSQL_MAX(wanted_files, max_connections*5),
1728 + open_files_limit);
1729 + files= my_set_max_open_files(max_open_files);
1730 +
1731 +@@ -3253,15 +3253,15 @@
1732 + If we have requested too much file handles than we bring
1733 + max_connections in supported bounds.
1734 + */
1735 +- max_connections= (ulong) min(files-10-TABLE_OPEN_CACHE_MIN*2,
1736 ++ max_connections= (ulong) MYSQL_MIN(files-10-TABLE_OPEN_CACHE_MIN*2,
1737 + max_connections);
1738 + /*
1739 + Decrease table_cache_size according to max_connections, but
1740 +- not below TABLE_OPEN_CACHE_MIN. Outer min() ensures that we
1741 ++ not below TABLE_OPEN_CACHE_MIN. Outer MYSQL_MIN() ensures that we
1742 + never increase table_cache_size automatically (that could
1743 + happen if max_connections is decreased above).
1744 + */
1745 +- table_cache_size= (ulong) min(max((files-10-max_connections)/2,
1746 ++ table_cache_size= (ulong) MYSQL_MIN(MYSQL_MAX((files-10-max_connections)/2,
1747 + TABLE_OPEN_CACHE_MIN),
1748 + table_cache_size);
1749 + DBUG_PRINT("warning",
1750 +@@ -4947,7 +4947,7 @@
1751 + {
1752 + my_socket sock,new_sock;
1753 + uint error_count=0;
1754 +- uint max_used_connection= (uint) (max(ip_sock,unix_sock)+1);
1755 ++ uint max_used_connection= (uint) (MYSQL_MAX(ip_sock,unix_sock)+1);
1756 + fd_set readFDs,clientFDs;
1757 + THD *thd;
1758 + struct sockaddr_in cAddr;
1759 +diff -ur mysql-orig/sql/net_serv.cc mysql/sql/net_serv.cc
1760 +--- mysql-orig/sql/net_serv.cc 2012-08-14 01:12:29.413437640 +0000
1761 ++++ mysql/sql/net_serv.cc 2012-08-14 01:14:59.412197702 +0000
1762 +@@ -755,7 +755,7 @@
1763 + {
1764 + while (remain > 0)
1765 + {
1766 +- size_t length= min(remain, net->max_packet);
1767 ++ size_t length= MYSQL_MIN(remain, net->max_packet);
1768 + if (net_safe_read(net, net->buff, length, alarmed))
1769 + DBUG_RETURN(1);
1770 + update_statistics(thd_increment_bytes_received(length));
1771 +@@ -946,7 +946,7 @@
1772 + len=uint3korr(net->buff+net->where_b);
1773 + if (!len) /* End of big multi-packet */
1774 + goto end;
1775 +- helping = max(len,*complen) + net->where_b;
1776 ++ helping = MYSQL_MAX(len,*complen) + net->where_b;
1777 + /* The necessary size of net->buff */
1778 + if (helping >= net->max_packet)
1779 + {
1780 +diff -ur mysql-orig/sql/opt_range.cc mysql/sql/opt_range.cc
1781 +--- mysql-orig/sql/opt_range.cc 2012-08-14 01:12:29.413437640 +0000
1782 ++++ mysql/sql/opt_range.cc 2012-08-14 01:14:59.422197616 +0000
1783 +@@ -2347,7 +2347,7 @@
1784 + group_trp= get_best_group_min_max(&param, tree);
1785 + if (group_trp)
1786 + {
1787 +- param.table->quick_condition_rows= min(group_trp->records,
1788 ++ param.table->quick_condition_rows= MYSQL_MIN(group_trp->records,
1789 + head->file->stats.records);
1790 + if (group_trp->read_cost < best_read_time)
1791 + {
1792 +@@ -3823,7 +3823,7 @@
1793 + {
1794 + imerge_trp->read_cost= imerge_cost;
1795 + imerge_trp->records= non_cpk_scan_records + cpk_scan_records;
1796 +- imerge_trp->records= min(imerge_trp->records,
1797 ++ imerge_trp->records= MYSQL_MIN(imerge_trp->records,
1798 + param->table->file->stats.records);
1799 + imerge_trp->range_scans= range_scans;
1800 + imerge_trp->range_scans_end= range_scans + n_child_scans;
1801 +@@ -7471,7 +7471,7 @@
1802 + param->table->quick_key_parts[key]=param->max_key_part+1;
1803 + param->table->quick_n_ranges[key]= param->n_ranges;
1804 + param->table->quick_condition_rows=
1805 +- min(param->table->quick_condition_rows, records);
1806 ++ MYSQL_MIN(param->table->quick_condition_rows, records);
1807 + }
1808 + /*
1809 + Need to save quick_rows in any case as it is used when calculating
1810 +@@ -7540,7 +7540,7 @@
1811 + uchar *tmp_min_key, *tmp_max_key;
1812 + uint8 save_first_null_comp= param->first_null_comp;
1813 +
1814 +- param->max_key_part=max(param->max_key_part,key_tree->part);
1815 ++ param->max_key_part=MYSQL_MAX(param->max_key_part,key_tree->part);
1816 + if (key_tree->left != &null_element)
1817 + {
1818 + /*
1819 +@@ -8462,13 +8462,13 @@
1820 + /* Do not allocate the buffers twice. */
1821 + if (multi_range_length)
1822 + {
1823 +- DBUG_ASSERT(multi_range_length == min(multi_range_count, ranges.elements));
1824 ++ DBUG_ASSERT(multi_range_length == MYSQL_MIN(multi_range_count, ranges.elements));
1825 + DBUG_RETURN(0);
1826 + }
1827 +
1828 + /* Allocate the ranges array. */
1829 + DBUG_ASSERT(ranges.elements);
1830 +- multi_range_length= min(multi_range_count, ranges.elements);
1831 ++ multi_range_length= MYSQL_MIN(multi_range_count, ranges.elements);
1832 + DBUG_ASSERT(multi_range_length > 0);
1833 + while (multi_range_length && ! (multi_range= (KEY_MULTI_RANGE*)
1834 + my_malloc(multi_range_length *
1835 +@@ -8487,7 +8487,7 @@
1836 + /* Allocate the handler buffer if necessary. */
1837 + if (file->ha_table_flags() & HA_NEED_READ_RANGE_BUFFER)
1838 + {
1839 +- mrange_bufsiz= min(multi_range_bufsiz,
1840 ++ mrange_bufsiz= MYSQL_MIN(multi_range_bufsiz,
1841 + ((uint)QUICK_SELECT_I::records + 1)* head->s->reclength);
1842 +
1843 + while (mrange_bufsiz &&
1844 +@@ -8568,7 +8568,7 @@
1845 + goto end;
1846 + }
1847 +
1848 +- uint count= min(multi_range_length, ranges.elements -
1849 ++ uint count= MYSQL_MIN(multi_range_length, ranges.elements -
1850 + (cur_range - (QUICK_RANGE**) ranges.buffer));
1851 + if (count == 0)
1852 + {
1853 +@@ -9270,7 +9270,7 @@
1854 +
1855 + TODO
1856 + - What happens if the query groups by the MIN/MAX field, and there is no
1857 +- other field as in: "select min(a) from t1 group by a" ?
1858 ++ other field as in: "select MYSQL_MIN(a) from t1 group by a" ?
1859 + - We assume that the general correctness of the GROUP-BY query was checked
1860 + before this point. Is this correct, or do we have to check it completely?
1861 + - Lift the limitation in condition (B3), that is, make this access method
1862 +@@ -9496,7 +9496,7 @@
1863 + cur_group_prefix_len+= cur_part->store_length;
1864 + used_key_parts_map.set_bit(key_part_nr);
1865 + ++cur_group_key_parts;
1866 +- max_key_part= max(max_key_part,key_part_nr);
1867 ++ max_key_part= MYSQL_MAX(max_key_part,key_part_nr);
1868 + }
1869 + /*
1870 + Check that used key parts forms a prefix of the index.
1871 +@@ -10132,9 +10132,9 @@
1872 + {
1873 + double blocks_per_group= (double) num_blocks / (double) num_groups;
1874 + p_overlap= (blocks_per_group * (keys_per_subgroup - 1)) / keys_per_group;
1875 +- p_overlap= min(p_overlap, 1.0);
1876 ++ p_overlap= MYSQL_MIN(p_overlap, 1.0);
1877 + }
1878 +- io_cost= (double) min(num_groups * (1 + p_overlap), num_blocks);
1879 ++ io_cost= (double) MYSQL_MIN(num_groups * (1 + p_overlap), num_blocks);
1880 + }
1881 + else
1882 + io_cost= (keys_per_group > keys_per_block) ?
1883 +diff -ur mysql-orig/sql/opt_range.h mysql/sql/opt_range.h
1884 +--- mysql-orig/sql/opt_range.h 2012-08-14 01:12:29.413437640 +0000
1885 ++++ mysql/sql/opt_range.h 2012-08-14 01:14:59.422197616 +0000
1886 +@@ -85,7 +85,7 @@
1887 + void make_min_endpoint(key_range *kr, uint prefix_length,
1888 + key_part_map keypart_map) {
1889 + make_min_endpoint(kr);
1890 +- kr->length= min(kr->length, prefix_length);
1891 ++ kr->length= MYSQL_MIN(kr->length, prefix_length);
1892 + kr->keypart_map&= keypart_map;
1893 + }
1894 +
1895 +@@ -123,7 +123,7 @@
1896 + void make_max_endpoint(key_range *kr, uint prefix_length,
1897 + key_part_map keypart_map) {
1898 + make_max_endpoint(kr);
1899 +- kr->length= min(kr->length, prefix_length);
1900 ++ kr->length= MYSQL_MIN(kr->length, prefix_length);
1901 + kr->keypart_map&= keypart_map;
1902 + }
1903 +
1904 +diff -ur mysql-orig/sql/protocol.cc mysql/sql/protocol.cc
1905 +--- mysql-orig/sql/protocol.cc 2012-08-14 01:12:29.413437640 +0000
1906 ++++ mysql/sql/protocol.cc 2012-08-14 01:14:59.422197616 +0000
1907 +@@ -168,7 +168,7 @@
1908 + pos+=2;
1909 +
1910 + /* We can only return up to 65535 warnings in two bytes */
1911 +- uint tmp= min(total_warn_count, 65535);
1912 ++ uint tmp= MYSQL_MIN(total_warn_count, 65535);
1913 + int2store(pos, tmp);
1914 + pos+= 2;
1915 + }
1916 +@@ -263,7 +263,7 @@
1917 + Don't send warn count during SP execution, as the warn_list
1918 + is cleared between substatements, and mysqltest gets confused
1919 + */
1920 +- uint tmp= min(total_warn_count, 65535);
1921 ++ uint tmp= MYSQL_MIN(total_warn_count, 65535);
1922 + buff[0]= 254;
1923 + int2store(buff+1, tmp);
1924 + /*
1925 +diff -ur mysql-orig/sql/rpl_record.cc mysql/sql/rpl_record.cc
1926 +--- mysql-orig/sql/rpl_record.cc 2012-08-14 01:12:29.413437640 +0000
1927 ++++ mysql/sql/rpl_record.cc 2012-08-14 01:14:59.422197616 +0000
1928 +@@ -287,7 +287,7 @@
1929 + /*
1930 + throw away master's extra fields
1931 + */
1932 +- uint max_cols= min(tabledef->size(), cols->n_bits);
1933 ++ uint max_cols= MYSQL_MIN(tabledef->size(), cols->n_bits);
1934 + for (; i < max_cols; i++)
1935 + {
1936 + if (bitmap_is_set(cols, i))
1937 +diff -ur mysql-orig/sql/rpl_rli.cc mysql/sql/rpl_rli.cc
1938 +--- mysql-orig/sql/rpl_rli.cc 2012-08-14 01:12:29.423437567 +0000
1939 ++++ mysql/sql/rpl_rli.cc 2012-08-14 01:14:59.422197616 +0000
1940 +@@ -690,7 +690,7 @@
1941 + ulong log_name_extension;
1942 + char log_name_tmp[FN_REFLEN]; //make a char[] from String
1943 +
1944 +- strmake(log_name_tmp, log_name->ptr(), min(log_name->length(), FN_REFLEN-1));
1945 ++ strmake(log_name_tmp, log_name->ptr(), MYSQL_MIN(log_name->length(), FN_REFLEN-1));
1946 +
1947 + char *p= fn_ext(log_name_tmp);
1948 + char *p_end;
1949 +@@ -700,7 +700,7 @@
1950 + goto err;
1951 + }
1952 + // Convert 0-3 to 4
1953 +- log_pos= max(log_pos, BIN_LOG_HEADER_SIZE);
1954 ++ log_pos= MYSQL_MAX(log_pos, BIN_LOG_HEADER_SIZE);
1955 + /* p points to '.' */
1956 + log_name_extension= strtoul(++p, &p_end, 10);
1957 + /*
1958 +diff -ur mysql-orig/sql/rpl_utility.cc mysql/sql/rpl_utility.cc
1959 +--- mysql-orig/sql/rpl_utility.cc 2012-08-14 01:12:29.423437567 +0000
1960 ++++ mysql/sql/rpl_utility.cc 2012-08-14 01:14:59.422197616 +0000
1961 +@@ -182,7 +182,7 @@
1962 + /*
1963 + We only check the initial columns for the tables.
1964 + */
1965 +- uint const cols_to_check= min(table->s->fields, size());
1966 ++ uint const cols_to_check= MYSQL_MIN(table->s->fields, size());
1967 + int error= 0;
1968 + Relay_log_info const *rli= const_cast<Relay_log_info*>(rli_arg);
1969 +
1970 +diff -ur mysql-orig/sql/rpl_utility.h mysql/sql/rpl_utility.h
1971 +--- mysql-orig/sql/rpl_utility.h 2012-08-14 01:12:29.423437567 +0000
1972 ++++ mysql/sql/rpl_utility.h 2012-08-14 01:14:59.422197616 +0000
1973 +@@ -315,7 +315,7 @@
1974 + do { \
1975 + char buf[256]; \
1976 + uint i; \
1977 +- for (i = 0 ; i < min(sizeof(buf) - 1, (BS)->n_bits) ; i++) \
1978 ++ for (i = 0 ; i < MYSQL_MIN(sizeof(buf) - 1, (BS)->n_bits) ; i++) \
1979 + buf[i] = bitmap_is_set((BS), i) ? '1' : '0'; \
1980 + buf[i] = '\0'; \
1981 + DBUG_PRINT((N), ((FRM), buf)); \
1982 +diff -ur mysql-orig/sql/set_var.cc mysql/sql/set_var.cc
1983 +--- mysql-orig/sql/set_var.cc 2012-08-14 01:12:29.423437567 +0000
1984 ++++ mysql/sql/set_var.cc 2012-08-14 01:14:59.422197616 +0000
1985 +@@ -1849,7 +1849,7 @@
1986 + &not_used));
1987 + if (error_len)
1988 + {
1989 +- strmake(buff, error, min(sizeof(buff) - 1, error_len));
1990 ++ strmake(buff, error, MYSQL_MIN(sizeof(buff) - 1, error_len));
1991 + goto err;
1992 + }
1993 + }
1994 +@@ -4034,7 +4034,7 @@
1995 + &error, &error_len, &not_used);
1996 + if (error_len)
1997 + {
1998 +- strmake(buff, error, min(sizeof(buff) - 1, error_len));
1999 ++ strmake(buff, error, MYSQL_MIN(sizeof(buff) - 1, error_len));
2000 + goto err;
2001 + }
2002 + return FALSE;
2003 +diff -ur mysql-orig/sql/slave.cc mysql/sql/slave.cc
2004 +--- mysql-orig/sql/slave.cc 2012-08-14 01:12:29.413437640 +0000
2005 ++++ mysql/sql/slave.cc 2012-08-14 01:14:59.422197616 +0000
2006 +@@ -1791,7 +1791,7 @@
2007 + special marker to say "consider we have caught up".
2008 + */
2009 + protocol->store((longlong)(mi->rli.last_master_timestamp ?
2010 +- max(0, time_diff) : 0));
2011 ++ MYSQL_MAX(0, time_diff) : 0));
2012 + }
2013 + else
2014 + {
2015 +@@ -2408,7 +2408,7 @@
2016 + exec_res= 0;
2017 + rli->cleanup_context(thd, 1);
2018 + /* chance for concurrent connection to get more locks */
2019 +- safe_sleep(thd, min(rli->trans_retries, MAX_SLAVE_RETRY_PAUSE),
2020 ++ safe_sleep(thd, MYSQL_MIN(rli->trans_retries, MAX_SLAVE_RETRY_PAUSE),
2021 + (CHECK_KILLED_FUNC)sql_slave_killed, (void*)rli);
2022 + pthread_mutex_lock(&rli->data_lock); // because of SHOW STATUS
2023 + rli->trans_retries++;
2024 +@@ -4112,7 +4112,7 @@
2025 + relay_log_pos Current log pos
2026 + pending Number of bytes already processed from the event
2027 + */
2028 +- rli->event_relay_log_pos= max(rli->event_relay_log_pos, BIN_LOG_HEADER_SIZE);
2029 ++ rli->event_relay_log_pos= MYSQL_MAX(rli->event_relay_log_pos, BIN_LOG_HEADER_SIZE);
2030 + my_b_seek(cur_log,rli->event_relay_log_pos);
2031 + DBUG_RETURN(cur_log);
2032 + }
2033 +diff -ur mysql-orig/sql/spatial.h mysql/sql/spatial.h
2034 +--- mysql-orig/sql/spatial.h 2012-08-14 01:12:29.423437567 +0000
2035 ++++ mysql/sql/spatial.h 2012-08-14 01:14:59.432197532 +0000
2036 +@@ -182,8 +182,8 @@
2037 + if (d != mbr->dimension() || d <= 0 || contains(mbr) || within(mbr))
2038 + return 0;
2039 +
2040 +- MBR intersection(max(xmin, mbr->xmin), max(ymin, mbr->ymin),
2041 +- min(xmax, mbr->xmax), min(ymax, mbr->ymax));
2042 ++ MBR intersection(MYSQL_MAX(xmin, mbr->xmin), MYSQL_MAX(ymin, mbr->ymin),
2043 ++ MYSQL_MIN(xmax, mbr->xmax), MYSQL_MIN(ymax, mbr->ymax));
2044 +
2045 + return (d == intersection.dimension());
2046 + }
2047 +diff -ur mysql-orig/sql/sp_head.cc mysql/sql/sp_head.cc
2048 +--- mysql-orig/sql/sp_head.cc 2012-08-14 01:12:29.423437567 +0000
2049 ++++ mysql/sql/sp_head.cc 2012-08-14 01:14:59.432197532 +0000
2050 +@@ -2481,7 +2481,7 @@
2051 +
2052 + Item_empty_string *stmt_fld=
2053 + new Item_empty_string(col3_caption,
2054 +- max(m_defstr.length, 1024));
2055 ++ MYSQL_MAX(m_defstr.length, 1024));
2056 +
2057 + stmt_fld->maybe_null= TRUE;
2058 +
2059 +@@ -2682,7 +2682,7 @@
2060 + field_list.push_back(new Item_uint("Pos", 9));
2061 + // 1024 is for not to confuse old clients
2062 + field_list.push_back(new Item_empty_string("Instruction",
2063 +- max(buffer.length(), 1024)));
2064 ++ MYSQL_MAX(buffer.length(), 1024)));
2065 + if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS |
2066 + Protocol::SEND_EOF))
2067 + DBUG_RETURN(1);
2068 +diff -ur mysql-orig/sql/sql_acl.cc mysql/sql/sql_acl.cc
2069 +--- mysql-orig/sql/sql_acl.cc 2012-08-14 01:12:29.423437567 +0000
2070 ++++ mysql/sql/sql_acl.cc 2012-08-14 01:14:59.432197532 +0000
2071 +@@ -824,7 +824,7 @@
2072 + chars= 128; // Marker that chars existed
2073 + }
2074 + }
2075 +- sort= (sort << 8) + (wild_pos ? min(wild_pos, 127) : chars);
2076 ++ sort= (sort << 8) + (wild_pos ? MYSQL_MIN(wild_pos, 127) : chars);
2077 + }
2078 + va_end(args);
2079 + return sort;
2080 +diff -ur mysql-orig/sql/sql_analyse.cc mysql/sql/sql_analyse.cc
2081 +--- mysql-orig/sql/sql_analyse.cc 2012-08-14 01:12:29.413437640 +0000
2082 ++++ mysql/sql/sql_analyse.cc 2012-08-14 01:14:59.442197450 +0000
2083 +@@ -282,16 +282,16 @@
2084 + {
2085 + if (((longlong) info->ullval) < 0)
2086 + return 0; // Impossible to store as a negative number
2087 +- ev_info->llval = -(longlong) max((ulonglong) -ev_info->llval,
2088 ++ ev_info->llval = -(longlong) MYSQL_MAX((ulonglong) -ev_info->llval,
2089 + info->ullval);
2090 +- ev_info->min_dval = (double) -max(-ev_info->min_dval, info->dval);
2091 ++ ev_info->min_dval = (double) -MYSQL_MAX(-ev_info->min_dval, info->dval);
2092 + }
2093 + else // ulonglong is as big as bigint in MySQL
2094 + {
2095 + if ((check_ulonglong(num, info->integers) == DECIMAL_NUM))
2096 + return 0;
2097 +- ev_info->ullval = (ulonglong) max(ev_info->ullval, info->ullval);
2098 +- ev_info->max_dval = (double) max(ev_info->max_dval, info->dval);
2099 ++ ev_info->ullval = (ulonglong) MYSQL_MAX(ev_info->ullval, info->ullval);
2100 ++ ev_info->max_dval = (double) MYSQL_MAX(ev_info->max_dval, info->dval);
2101 + }
2102 + return 1;
2103 + } // get_ev_num_info
2104 +@@ -1045,7 +1045,7 @@
2105 + my_decimal_div(E_DEC_FATAL_ERROR, &avg_val, sum+cur_sum, &num, prec_increment);
2106 + /* TODO remove this after decimal_div returns proper frac */
2107 + my_decimal_round(E_DEC_FATAL_ERROR, &avg_val,
2108 +- min(sum[cur_sum].frac + prec_increment, DECIMAL_MAX_SCALE),
2109 ++ MYSQL_MIN(sum[cur_sum].frac + prec_increment, DECIMAL_MAX_SCALE),
2110 + FALSE,&rounded_avg);
2111 + my_decimal2string(E_DEC_FATAL_ERROR, &rounded_avg, 0, 0, '0', s);
2112 + return s;
2113 +@@ -1070,7 +1070,7 @@
2114 + my_decimal_div(E_DEC_FATAL_ERROR, &tmp, &sum2, &num, prec_increment);
2115 + my_decimal2double(E_DEC_FATAL_ERROR, &tmp, &std_sqr);
2116 + s->set_real(((double) std_sqr <= 0.0 ? 0.0 : sqrt(std_sqr)),
2117 +- min(item->decimals + prec_increment, NOT_FIXED_DEC), my_thd_charset);
2118 ++ MYSQL_MIN(item->decimals + prec_increment, NOT_FIXED_DEC), my_thd_charset);
2119 +
2120 + return s;
2121 + }
2122 +@@ -1187,7 +1187,7 @@
2123 + func_items[8] = new Item_proc_string("Std", 255);
2124 + func_items[8]->maybe_null = 1;
2125 + func_items[9] = new Item_proc_string("Optimal_fieldtype",
2126 +- max(64, output_str_length));
2127 ++ MYSQL_MAX(64, output_str_length));
2128 +
2129 + for (uint i = 0; i < array_elements(func_items); i++)
2130 + field_list.push_back(func_items[i]);
2131 +diff -ur mysql-orig/sql/sql_cache.cc mysql/sql/sql_cache.cc
2132 +--- mysql-orig/sql/sql_cache.cc 2012-08-14 01:12:29.423437567 +0000
2133 ++++ mysql/sql/sql_cache.cc 2012-08-14 01:14:59.442197450 +0000
2134 +@@ -1006,7 +1006,7 @@
2135 + }
2136 + last_result_block= header->result()->prev;
2137 + allign_size= ALIGN_SIZE(last_result_block->used);
2138 +- len= max(query_cache.min_allocation_unit, allign_size);
2139 ++ len= MYSQL_MAX(query_cache.min_allocation_unit, allign_size);
2140 + if (last_result_block->length >= query_cache.min_allocation_unit + len)
2141 + query_cache.split_block(last_result_block,len);
2142 +
2143 +@@ -2451,7 +2451,7 @@
2144 + DBUG_ENTER("Query_cache::write_block_data");
2145 + DBUG_PRINT("qcache", ("data: %ld, header: %ld, all header: %ld",
2146 + data_len, header_len, all_headers_len));
2147 +- Query_cache_block *block= allocate_block(max(align_len,
2148 ++ Query_cache_block *block= allocate_block(MYSQL_MAX(align_len,
2149 + min_allocation_unit),1, 0);
2150 + if (block != 0)
2151 + {
2152 +@@ -2506,7 +2506,7 @@
2153 + ulong append_min = get_min_append_result_data_size();
2154 + if (last_block_free_space < data_len &&
2155 + append_next_free_block(last_block,
2156 +- max(tail, append_min)))
2157 ++ MYSQL_MAX(tail, append_min)))
2158 + last_block_free_space = last_block->length - last_block->used;
2159 + // If no space in last block (even after join) allocate new block
2160 + if (last_block_free_space < data_len)
2161 +@@ -2534,7 +2534,7 @@
2162 + // Now finally write data to the last block
2163 + if (success && last_block_free_space > 0)
2164 + {
2165 +- ulong to_copy = min(data_len,last_block_free_space);
2166 ++ ulong to_copy = MYSQL_MIN(data_len,last_block_free_space);
2167 + DBUG_PRINT("qcache", ("use free space %lub at block 0x%lx to copy %lub",
2168 + last_block_free_space, (ulong)last_block, to_copy));
2169 + memcpy((uchar*) last_block + last_block->used, data, to_copy);
2170 +@@ -2622,8 +2622,8 @@
2171 + if (queries_in_cache < QUERY_CACHE_MIN_ESTIMATED_QUERIES_NUMBER)
2172 + return min_result_data_size;
2173 + ulong avg_result = (query_cache_size - free_memory) / queries_in_cache;
2174 +- avg_result = min(avg_result, query_cache_limit);
2175 +- return max(min_result_data_size, avg_result);
2176 ++ avg_result = MYSQL_MIN(avg_result, query_cache_limit);
2177 ++ return MYSQL_MAX(min_result_data_size, avg_result);
2178 + }
2179 +
2180 + inline ulong Query_cache::get_min_append_result_data_size()
2181 +@@ -2655,7 +2655,7 @@
2182 + ulong len= data_len + all_headers_len;
2183 + ulong align_len= ALIGN_SIZE(len);
2184 +
2185 +- if (!(new_block= allocate_block(max(min_size, align_len),
2186 ++ if (!(new_block= allocate_block(MYSQL_MAX(min_size, align_len),
2187 + min_result_data_size == 0,
2188 + all_headers_len + min_result_data_size)))
2189 + {
2190 +@@ -2664,7 +2664,7 @@
2191 + }
2192 +
2193 + new_block->n_tables = 0;
2194 +- new_block->used = min(len, new_block->length);
2195 ++ new_block->used = MYSQL_MIN(len, new_block->length);
2196 + new_block->type = Query_cache_block::RES_INCOMPLETE;
2197 + new_block->next = new_block->prev = new_block;
2198 + Query_cache_result *header = new_block->result();
2199 +@@ -3087,7 +3087,7 @@
2200 + DBUG_PRINT("qcache", ("len %lu, not less %d, min %lu",
2201 + len, not_less,min));
2202 +
2203 +- if (len >= min(query_cache_size, query_cache_limit))
2204 ++ if (len >= MYSQL_MIN(query_cache_size, query_cache_limit))
2205 + {
2206 + DBUG_PRINT("qcache", ("Query cache hase only %lu memory and limit %lu",
2207 + query_cache_size, query_cache_limit));
2208 +diff -ur mysql-orig/sql/sql_class.cc mysql/sql/sql_class.cc
2209 +--- mysql-orig/sql/sql_class.cc 2012-08-14 01:12:29.423437567 +0000
2210 ++++ mysql/sql/sql_class.cc 2012-08-14 01:14:59.442197450 +0000
2211 +@@ -418,7 +418,7 @@
2212 + if (max_query_len < 1)
2213 + len= thd->query_length();
2214 + else
2215 +- len= min(thd->query_length(), max_query_len);
2216 ++ len= MYSQL_MIN(thd->query_length(), max_query_len);
2217 + str.append('\n');
2218 + str.append(thd->query(), len);
2219 + }
2220 +@@ -433,7 +433,7 @@
2221 + was reallocated to a larger buffer to be able to fit.
2222 + */
2223 + DBUG_ASSERT(buffer != NULL);
2224 +- length= min(str.length(), length-1);
2225 ++ length= MYSQL_MIN(str.length(), length-1);
2226 + memcpy(buffer, str.c_ptr_quick(), length);
2227 + /* Make sure that the new string is null terminated */
2228 + buffer[length]= '\0';
2229 +@@ -2116,7 +2116,7 @@
2230 + else
2231 + {
2232 + if (fixed_row_size)
2233 +- used_length=min(res->length(),item->max_length);
2234 ++ used_length=MYSQL_MIN(res->length(),item->max_length);
2235 + else
2236 + used_length=res->length();
2237 + if ((result_type == STRING_RESULT || is_unsafe_field_sep) &&
2238 +diff -ur mysql-orig/sql/sql_client.cc mysql/sql/sql_client.cc
2239 +--- mysql-orig/sql/sql_client.cc 2012-08-14 01:12:29.413437640 +0000
2240 ++++ mysql/sql/sql_client.cc 2012-08-14 01:14:59.452197368 +0000
2241 +@@ -34,7 +34,7 @@
2242 + (uint)global_system_variables.net_write_timeout);
2243 +
2244 + net->retry_count= (uint) global_system_variables.net_retry_count;
2245 +- net->max_packet_size= max(global_system_variables.net_buffer_length,
2246 ++ net->max_packet_size= MYSQL_MAX(global_system_variables.net_buffer_length,
2247 + global_system_variables.max_allowed_packet);
2248 + #endif
2249 + }
2250 +diff -ur mysql-orig/sql/sql_connect.cc mysql/sql/sql_connect.cc
2251 +--- mysql-orig/sql/sql_connect.cc 2012-08-14 01:12:29.413437640 +0000
2252 ++++ mysql/sql/sql_connect.cc 2012-08-14 01:14:59.452197368 +0000
2253 +@@ -845,7 +845,7 @@
2254 + if (thd->main_security_ctx.host)
2255 + {
2256 + if (thd->main_security_ctx.host != my_localhost)
2257 +- thd->main_security_ctx.host[min(strlen(thd->main_security_ctx.host),
2258 ++ thd->main_security_ctx.host[MYSQL_MIN(strlen(thd->main_security_ctx.host),
2259 + HOSTNAME_LENGTH)]= 0;
2260 + thd->main_security_ctx.host_or_ip= thd->main_security_ctx.host;
2261 + }
2262 +diff -ur mysql-orig/sql/sql_parse.cc mysql/sql/sql_parse.cc
2263 +--- mysql-orig/sql/sql_parse.cc 2012-08-14 01:12:29.413437640 +0000
2264 ++++ mysql/sql/sql_parse.cc 2012-08-14 01:14:59.452197368 +0000
2265 +@@ -5762,7 +5762,7 @@
2266 + return 1;
2267 + }
2268 + #ifndef DBUG_OFF
2269 +- max_stack_used= max(max_stack_used, stack_used);
2270 ++ max_stack_used= MYSQL_MAX(max_stack_used, stack_used);
2271 + #endif
2272 + return 0;
2273 + }
2274 +@@ -7293,7 +7293,7 @@
2275 + char command[80];
2276 + Lex_input_stream *lip= & thd->m_parser_state->m_lip;
2277 + strmake(command, lip->yylval->symbol.str,
2278 +- min(lip->yylval->symbol.length, sizeof(command)-1));
2279 ++ MYSQL_MIN(lip->yylval->symbol.length, sizeof(command)-1));
2280 + my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command);
2281 + return 1;
2282 + }
2283 +diff -ur mysql-orig/sql/sql_partition.cc mysql/sql/sql_partition.cc
2284 +--- mysql-orig/sql/sql_partition.cc 2012-08-14 01:12:29.423437567 +0000
2285 ++++ mysql/sql/sql_partition.cc 2012-08-14 01:14:59.462197286 +0000
2286 +@@ -4592,7 +4592,7 @@
2287 + */
2288 + start_part= 0;
2289 + end_part= new_total_partitions - (upper_2n + 1);
2290 +- end_part= max(lower_2n - 1, end_part);
2291 ++ end_part= MYSQL_MAX(lower_2n - 1, end_part);
2292 + }
2293 + else if (new_total_partitions <= upper_2n)
2294 + {
2295 +diff -ur mysql-orig/sql/sql_plugin.cc mysql/sql/sql_plugin.cc
2296 +--- mysql-orig/sql/sql_plugin.cc 2012-08-14 01:12:29.423437567 +0000
2297 ++++ mysql/sql/sql_plugin.cc 2012-08-14 01:14:59.472197202 +0000
2298 +@@ -512,7 +512,7 @@
2299 + for (i=0;
2300 + (old=(struct st_mysql_plugin *)(ptr+i*sizeof_st_plugin))->info;
2301 + i++)
2302 +- memcpy(cur+i, old, min(sizeof(cur[i]), sizeof_st_plugin));
2303 ++ memcpy(cur+i, old, MYSQL_MIN(sizeof(cur[i]), sizeof_st_plugin));
2304 +
2305 + sym= cur;
2306 + }
2307 +@@ -2131,7 +2131,7 @@
2308 + &error, &error_len, &not_used);
2309 + if (error_len)
2310 + {
2311 +- strmake(buff, error, min(sizeof(buff) - 1, error_len));
2312 ++ strmake(buff, error, MYSQL_MIN(sizeof(buff) - 1, error_len));
2313 + strvalue= buff;
2314 + goto err;
2315 + }
2316 +diff -ur mysql-orig/sql/sql_prepare.cc mysql/sql/sql_prepare.cc
2317 +--- mysql-orig/sql/sql_prepare.cc 2012-08-14 01:12:29.413437640 +0000
2318 ++++ mysql/sql/sql_prepare.cc 2012-08-14 01:14:59.482197120 +0000
2319 +@@ -249,7 +249,7 @@
2320 + int2store(buff+5, columns);
2321 + int2store(buff+7, stmt->param_count);
2322 + buff[9]= 0; // Guard against a 4.1 client
2323 +- tmp= min(stmt->thd->total_warn_count, 65535);
2324 ++ tmp= MYSQL_MIN(stmt->thd->total_warn_count, 65535);
2325 + int2store(buff+10, tmp);
2326 +
2327 + /*
2328 +diff -ur mysql-orig/sql/sql_profile.cc mysql/sql/sql_profile.cc
2329 +--- mysql-orig/sql/sql_profile.cc 2012-08-14 01:12:29.423437567 +0000
2330 ++++ mysql/sql/sql_profile.cc 2012-08-14 01:14:59.482197120 +0000
2331 +@@ -254,7 +254,7 @@
2332 + uint query_length_arg)
2333 + {
2334 + /* Truncate to avoid DoS attacks. */
2335 +- uint length= min(MAX_QUERY_LENGTH, query_length_arg);
2336 ++ uint length= MYSQL_MIN(MAX_QUERY_LENGTH, query_length_arg);
2337 +
2338 + DBUG_ASSERT(query_source == NULL); /* we don't leak memory */
2339 + if (query_source_arg != NULL)
2340 +diff -ur mysql-orig/sql/sql_repl.cc mysql/sql/sql_repl.cc
2341 +--- mysql-orig/sql/sql_repl.cc 2012-08-14 01:12:29.413437640 +0000
2342 ++++ mysql/sql/sql_repl.cc 2012-08-14 01:14:59.482197120 +0000
2343 +@@ -1299,12 +1299,12 @@
2344 + {
2345 + /*
2346 + Sometimes mi->rli.master_log_pos == 0 (it happens when the SQL thread is
2347 +- not initialized), so we use a max().
2348 ++ not initialized), so we use a MYSQL_MAX().
2349 + What happens to mi->rli.master_log_pos during the initialization stages
2350 + of replication is not 100% clear, so we guard against problems using
2351 + max().
2352 + */
2353 +- mi->master_log_pos = max(BIN_LOG_HEADER_SIZE,
2354 ++ mi->master_log_pos = MYSQL_MAX(BIN_LOG_HEADER_SIZE,
2355 + mi->rli.group_master_log_pos);
2356 + strmake(mi->master_log_name, mi->rli.group_master_log_name,
2357 + sizeof(mi->master_log_name)-1);
2358 +@@ -1478,7 +1478,7 @@
2359 + LEX_MASTER_INFO *lex_mi= &thd->lex->mi;
2360 + SELECT_LEX_UNIT *unit= &thd->lex->unit;
2361 + ha_rows event_count, limit_start, limit_end;
2362 +- my_off_t pos = max(BIN_LOG_HEADER_SIZE, lex_mi->pos); // user-friendly
2363 ++ my_off_t pos = MYSQL_MAX(BIN_LOG_HEADER_SIZE, lex_mi->pos); // user-friendly
2364 + char search_file_name[FN_REFLEN], *name;
2365 + const char *log_file_name = lex_mi->log_file_name;
2366 + pthread_mutex_t *log_lock = mysql_bin_log.get_log_lock();
2367 +@@ -1750,14 +1750,14 @@
2368 + DBUG_RETURN(0);
2369 +
2370 + for (block_len= (uint) (my_b_get_bytes_in_buffer(file)); block_len > 0;
2371 +- buffer += min(block_len, max_event_size),
2372 +- block_len -= min(block_len, max_event_size))
2373 ++ buffer += MYSQL_MIN(block_len, max_event_size),
2374 ++ block_len -= MYSQL_MIN(block_len, max_event_size))
2375 + {
2376 + lf_info->last_pos_in_file= my_b_get_pos_in_file(file);
2377 + if (lf_info->wrote_create_file)
2378 + {
2379 + Append_block_log_event a(lf_info->thd, lf_info->thd->db, buffer,
2380 +- min(block_len, max_event_size),
2381 ++ MYSQL_MIN(block_len, max_event_size),
2382 + lf_info->log_delayed);
2383 + if (mysql_bin_log.write(&a))
2384 + DBUG_RETURN(1);
2385 +@@ -1766,7 +1766,7 @@
2386 + {
2387 + Begin_load_query_log_event b(lf_info->thd, lf_info->thd->db,
2388 + buffer,
2389 +- min(block_len, max_event_size),
2390 ++ MYSQL_MIN(block_len, max_event_size),
2391 + lf_info->log_delayed);
2392 + if (mysql_bin_log.write(&b))
2393 + DBUG_RETURN(1);
2394 +diff -ur mysql-orig/sql/sql_select.cc mysql/sql/sql_select.cc
2395 +--- mysql-orig/sql/sql_select.cc 2012-08-14 01:12:29.423437567 +0000
2396 ++++ mysql/sql/sql_select.cc 2012-08-14 01:14:59.482197120 +0000
2397 +@@ -3022,7 +3022,7 @@
2398 + This is can't be to high as otherwise we are likely to use
2399 + table scan.
2400 + */
2401 +- s->worst_seeks= min((double) s->found_records / 10,
2402 ++ s->worst_seeks= MYSQL_MIN((double) s->found_records / 10,
2403 + (double) s->read_time*3);
2404 + if (s->worst_seeks < 2.0) // Fix for small tables
2405 + s->worst_seeks=2.0;
2406 +@@ -3958,7 +3958,7 @@
2407 + uint and_level,i,found_eq_constant;
2408 + KEY_FIELD *key_fields, *end, *field;
2409 + uint sz;
2410 +- uint m= max(select_lex->max_equal_elems,1);
2411 ++ uint m= MYSQL_MAX(select_lex->max_equal_elems,1);
2412 +
2413 + /*
2414 + We use the same piece of memory to store both KEY_FIELD
2415 +@@ -3981,7 +3981,7 @@
2416 + can be not more than select_lex->max_equal_elems such
2417 + substitutions.
2418 + */
2419 +- sz= max(sizeof(KEY_FIELD),sizeof(SARGABLE_PARAM))*
2420 ++ sz= MYSQL_MAX(sizeof(KEY_FIELD),sizeof(SARGABLE_PARAM))*
2421 + (((thd->lex->current_select->cond_count+1)*2 +
2422 + thd->lex->current_select->between_count)*m+1);
2423 + if (!(key_fields=(KEY_FIELD*) thd->alloc(sz)))
2424 +@@ -4144,7 +4144,7 @@
2425 + if (map == 1) // Only one table
2426 + {
2427 + TABLE *tmp_table=join->all_tables[tablenr];
2428 +- keyuse->ref_table_rows= max(tmp_table->file->stats.records, 100);
2429 ++ keyuse->ref_table_rows= MYSQL_MAX(tmp_table->file->stats.records, 100);
2430 + }
2431 + }
2432 + /*
2433 +@@ -4464,7 +4464,7 @@
2434 + tmp= record_count*(tmp+keys_per_block-1)/keys_per_block;
2435 + }
2436 + else
2437 +- tmp= record_count*min(tmp,s->worst_seeks);
2438 ++ tmp= record_count*MYSQL_MIN(tmp,s->worst_seeks);
2439 + }
2440 + }
2441 + else
2442 +@@ -4631,7 +4631,7 @@
2443 + tmp= record_count*(tmp+keys_per_block-1)/keys_per_block;
2444 + }
2445 + else
2446 +- tmp= record_count*min(tmp,s->worst_seeks);
2447 ++ tmp= record_count*MYSQL_MIN(tmp,s->worst_seeks);
2448 + }
2449 + else
2450 + tmp= best_time; // Do nothing
2451 +@@ -5581,7 +5581,7 @@
2452 + {
2453 + uint blob_length=(uint) (join_tab->table->file->stats.mean_rec_length-
2454 + (join_tab->table->s->reclength- rec_length));
2455 +- rec_length+=(uint) max(4,blob_length);
2456 ++ rec_length+=(uint) MYSQL_MAX(4,blob_length);
2457 + }
2458 + join_tab->used_fields=fields;
2459 + join_tab->used_fieldlength=rec_length;
2460 +@@ -10488,7 +10488,7 @@
2461 + share->max_rows= ~(ha_rows) 0;
2462 + else
2463 + share->max_rows= (ha_rows) (((share->db_type() == heap_hton) ?
2464 +- min(thd->variables.tmp_table_size,
2465 ++ MYSQL_MIN(thd->variables.tmp_table_size,
2466 + thd->variables.max_heap_table_size) :
2467 + thd->variables.tmp_table_size) /
2468 + share->reclength);
2469 +@@ -13708,7 +13708,7 @@
2470 + index entry.
2471 + */
2472 + index_scan_time= select_limit/rec_per_key *
2473 +- min(rec_per_key, table->file->scan_time());
2474 ++ MYSQL_MIN(rec_per_key, table->file->scan_time());
2475 + if ((ref_key < 0 && is_covering) ||
2476 + (ref_key < 0 && (group || table->force_index)) ||
2477 + index_scan_time < read_time)
2478 +@@ -13720,7 +13720,7 @@
2479 + if (table->quick_keys.is_set(nr))
2480 + quick_records= table->quick_rows[nr];
2481 + if (best_key < 0 ||
2482 +- (select_limit <= min(quick_records,best_records) ?
2483 ++ (select_limit <= MYSQL_MIN(quick_records,best_records) ?
2484 + keyinfo->key_parts < best_key_parts :
2485 + quick_records < best_records))
2486 + {
2487 +@@ -14416,7 +14416,7 @@
2488 + count++;
2489 + if (!sortorder)
2490 + sortorder= (SORT_FIELD*) sql_alloc(sizeof(SORT_FIELD) *
2491 +- (max(count, *length) + 1));
2492 ++ (MYSQL_MAX(count, *length) + 1));
2493 + pos= sort= sortorder;
2494 +
2495 + if (!pos)
2496 +@@ -14538,7 +14538,7 @@
2497 + cache->length=length+blobs*sizeof(char*);
2498 + cache->blobs=blobs;
2499 + *blob_ptr=0; /* End sequentel */
2500 +- size=max(thd->variables.join_buff_size, cache->length);
2501 ++ size=MYSQL_MAX(thd->variables.join_buff_size, cache->length);
2502 + if (!(cache->buff=(uchar*) my_malloc(size,MYF(0))))
2503 + DBUG_RETURN(1); /* Don't use cache */ /* purecov: inspected */
2504 + cache->end=cache->buff+size;
2505 +diff -ur mysql-orig/sql/sql_show.cc mysql/sql/sql_show.cc
2506 +--- mysql-orig/sql/sql_show.cc 2012-08-14 01:12:29.413437640 +0000
2507 ++++ mysql/sql/sql_show.cc 2012-08-14 01:14:59.492197038 +0000
2508 +@@ -753,7 +753,7 @@
2509 + {
2510 + field_list.push_back(new Item_empty_string("View",NAME_CHAR_LEN));
2511 + field_list.push_back(new Item_empty_string("Create View",
2512 +- max(buffer.length(),1024)));
2513 ++ MYSQL_MAX(buffer.length(),1024)));
2514 + field_list.push_back(new Item_empty_string("character_set_client",
2515 + MY_CS_NAME_SIZE));
2516 + field_list.push_back(new Item_empty_string("collation_connection",
2517 +@@ -764,7 +764,7 @@
2518 + field_list.push_back(new Item_empty_string("Table",NAME_CHAR_LEN));
2519 + // 1024 is for not to confuse old clients
2520 + field_list.push_back(new Item_empty_string("Create Table",
2521 +- max(buffer.length(),1024)));
2522 ++ MYSQL_MAX(buffer.length(),1024)));
2523 + }
2524 +
2525 + if (protocol->send_fields(&field_list,
2526 +@@ -1875,7 +1875,7 @@
2527 + pthread_mutex_lock(&tmp->LOCK_thd_data);
2528 + if (tmp->query())
2529 + {
2530 +- uint length= min(max_query_length, tmp->query_length());
2531 ++ uint length= MYSQL_MIN(max_query_length, tmp->query_length());
2532 + thd_info->query= (char*) thd->strmake(tmp->query(),length);
2533 + }
2534 + pthread_mutex_unlock(&tmp->LOCK_thd_data);
2535 +@@ -2006,7 +2006,7 @@
2536 + if (tmp->query())
2537 + {
2538 + table->field[7]->store(tmp->query(),
2539 +- min(PROCESS_LIST_INFO_WIDTH,
2540 ++ MYSQL_MIN(PROCESS_LIST_INFO_WIDTH,
2541 + tmp->query_length()), cs);
2542 + table->field[7]->set_notnull();
2543 + }
2544 +@@ -3276,7 +3276,7 @@
2545 + for (ptr=tables->table->field; (field= *ptr) ; ptr++)
2546 + {
2547 + star_table_open_method=
2548 +- min(star_table_open_method,
2549 ++ MYSQL_MIN(star_table_open_method,
2550 + schema_table->fields_info[field_indx].open_method);
2551 + if (bitmap_is_set(tables->table->read_set, field->field_index))
2552 + {
2553 +@@ -7095,7 +7095,7 @@
2554 +
2555 + Item_empty_string *stmt_fld=
2556 + new Item_empty_string("SQL Original Statement",
2557 +- max(trg_sql_original_stmt.length, 1024));
2558 ++ MYSQL_MAX(trg_sql_original_stmt.length, 1024));
2559 +
2560 + stmt_fld->maybe_null= TRUE;
2561 +
2562 +diff -ur mysql-orig/sql/sql_string.cc mysql/sql/sql_string.cc
2563 +--- mysql-orig/sql/sql_string.cc 2012-08-14 01:12:29.423437567 +0000
2564 ++++ mysql/sql/sql_string.cc 2012-08-14 01:14:59.492197038 +0000
2565 +@@ -700,7 +700,7 @@
2566 + {
2567 + if (Alloced_length < str_length + space_needed)
2568 + {
2569 +- if (realloc(Alloced_length + max(space_needed, grow_by) - 1))
2570 ++ if (realloc(Alloced_length + MYSQL_MAX(space_needed, grow_by) - 1))
2571 + return TRUE;
2572 + }
2573 + return FALSE;
2574 +@@ -786,7 +786,7 @@
2575 +
2576 + int stringcmp(const String *s,const String *t)
2577 + {
2578 +- uint32 s_len=s->length(),t_len=t->length(),len=min(s_len,t_len);
2579 ++ uint32 s_len=s->length(),t_len=t->length(),len=MYSQL_MIN(s_len,t_len);
2580 + int cmp= memcmp(s->ptr(), t->ptr(), len);
2581 + return (cmp) ? cmp : (int) (s_len - t_len);
2582 + }
2583 +@@ -803,7 +803,7 @@
2584 + }
2585 + if (to->realloc(from_length))
2586 + return from; // Actually an error
2587 +- if ((to->str_length=min(from->str_length,from_length)))
2588 ++ if ((to->str_length=MYSQL_MIN(from->str_length,from_length)))
2589 + memcpy(to->Ptr,from->Ptr,to->str_length);
2590 + to->str_charset=from->str_charset;
2591 + return to;
2592 +@@ -1004,7 +1004,7 @@
2593 +
2594 + if (to_cs == &my_charset_bin)
2595 + {
2596 +- res= min(min(nchars, to_length), from_length);
2597 ++ res= MYSQL_MIN(MYSQL_MIN(nchars, to_length), from_length);
2598 + memmove(to, from, res);
2599 + *from_end_pos= from + res;
2600 + *well_formed_error_pos= NULL;
2601 +@@ -1190,7 +1190,7 @@
2602 + char *t= to;
2603 + char *t_end= to + to_len - 1; // '- 1' is for the '\0' at the end
2604 + const char *f= from;
2605 +- const char *f_end= from + (nbytes ? min(from_len, nbytes) : from_len);
2606 ++ const char *f_end= from + (nbytes ? MYSQL_MIN(from_len, nbytes) : from_len);
2607 + char *dots= to; // last safe place to append '...'
2608 +
2609 + if (!f || t == t_end)
2610 +diff -ur mysql-orig/sql/sql_table.cc mysql/sql/sql_table.cc
2611 +--- mysql-orig/sql/sql_table.cc 2012-08-14 01:12:29.413437640 +0000
2612 ++++ mysql/sql/sql_table.cc 2012-08-14 01:14:59.492197038 +0000
2613 +@@ -3276,7 +3276,7 @@
2614 + if ((length=column->length) > max_key_length ||
2615 + length > file->max_key_part_length())
2616 + {
2617 +- length=min(max_key_length, file->max_key_part_length());
2618 ++ length=MYSQL_MIN(max_key_length, file->max_key_part_length());
2619 + if (key->type == Key::MULTIPLE)
2620 + {
2621 + /* not a critical problem */
2622 +diff -ur mysql-orig/sql/sql_yacc.cc mysql/sql/sql_yacc.cc
2623 +--- mysql-orig/sql/sql_yacc.cc 2012-08-14 01:12:29.423437567 +0000
2624 ++++ mysql/sql/sql_yacc.cc 2012-08-14 01:14:59.502196954 +0000
2625 +@@ -16217,7 +16217,7 @@
2626 + from 0" (4 in fact), unspecified means "don't change the position
2627 + (keep the preceding value)").
2628 + */
2629 +- Lex->mi.pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.pos);
2630 ++ Lex->mi.pos = MYSQL_MAX(BIN_LOG_HEADER_SIZE, Lex->mi.pos);
2631 + }
2632 + break;
2633 +
2634 +@@ -16237,7 +16237,7 @@
2635 + {
2636 + Lex->mi.relay_log_pos = (yyvsp[(3) - (3)].ulong_num);
2637 + /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
2638 +- Lex->mi.relay_log_pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
2639 ++ Lex->mi.relay_log_pos = MYSQL_MAX(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
2640 + }
2641 + break;
2642 +
2643 +diff -ur mysql-orig/sql/sql_yacc.yy mysql/sql/sql_yacc.yy
2644 +--- mysql-orig/sql/sql_yacc.yy 2012-08-14 01:12:29.423437567 +0000
2645 ++++ mysql/sql/sql_yacc.yy 2012-08-14 01:14:59.512196872 +0000
2646 +@@ -1807,7 +1807,7 @@
2647 + from 0" (4 in fact), unspecified means "don't change the position
2648 + (keep the preceding value)").
2649 + */
2650 +- Lex->mi.pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.pos);
2651 ++ Lex->mi.pos = MYSQL_MAX(BIN_LOG_HEADER_SIZE, Lex->mi.pos);
2652 + }
2653 + | RELAY_LOG_FILE_SYM EQ TEXT_STRING_sys
2654 + {
2655 +@@ -1817,7 +1817,7 @@
2656 + {
2657 + Lex->mi.relay_log_pos = $3;
2658 + /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
2659 +- Lex->mi.relay_log_pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
2660 ++ Lex->mi.relay_log_pos = MYSQL_MAX(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
2661 + }
2662 + ;
2663 +
2664 +diff -ur mysql-orig/sql/thr_malloc.cc mysql/sql/thr_malloc.cc
2665 +--- mysql-orig/sql/thr_malloc.cc 2012-08-14 01:12:29.423437567 +0000
2666 ++++ mysql/sql/thr_malloc.cc 2012-08-14 01:14:59.512196872 +0000
2667 +@@ -132,7 +132,7 @@
2668 + if ((from_cs == &my_charset_bin) || (to_cs == &my_charset_bin))
2669 + {
2670 + // Safety if to_cs->mbmaxlen > 0
2671 +- new_length= min(arg_length, max_res_length);
2672 ++ new_length= MYSQL_MIN(arg_length, max_res_length);
2673 + memcpy(pos, str, new_length);
2674 + }
2675 + else
2676 +diff -ur mysql-orig/sql/tztime.cc mysql/sql/tztime.cc
2677 +--- mysql-orig/sql/tztime.cc 2012-08-14 01:12:29.413437640 +0000
2678 ++++ mysql/sql/tztime.cc 2012-08-14 01:14:59.512196872 +0000
2679 +@@ -169,7 +169,7 @@
2680 + uchar buf[sizeof(struct tzhead) + sizeof(my_time_t) * TZ_MAX_TIMES +
2681 + TZ_MAX_TIMES + sizeof(TRAN_TYPE_INFO) * TZ_MAX_TYPES +
2682 + #ifdef ABBR_ARE_USED
2683 +- max(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1))) +
2684 ++ MYSQL_MAX(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1))) +
2685 + #endif
2686 + sizeof(LS_INFO) * TZ_MAX_LEAPS];
2687 + } u;
2688 +@@ -398,7 +398,7 @@
2689 + Let us choose end_t as point before next time type change or leap
2690 + second correction.
2691 + */
2692 +- end_t= min((next_trans_idx < sp->timecnt) ? sp->ats[next_trans_idx] - 1:
2693 ++ end_t= MYSQL_MIN((next_trans_idx < sp->timecnt) ? sp->ats[next_trans_idx] - 1:
2694 + MY_TIME_T_MAX,
2695 + (next_leap_idx < sp->leapcnt) ?
2696 + sp->lsis[next_leap_idx].ls_trans - 1: MY_TIME_T_MAX);
2697 +@@ -1825,7 +1825,7 @@
2698 + uchar types[TZ_MAX_TIMES];
2699 + TRAN_TYPE_INFO ttis[TZ_MAX_TYPES];
2700 + #ifdef ABBR_ARE_USED
2701 +- char chars[max(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1)))];
2702 ++ char chars[MYSQL_MAX(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1)))];
2703 + #endif
2704 + /*
2705 + Used as a temporary tz_info until we decide that we actually want to
2706 +diff -ur mysql-orig/sql/unireg.cc mysql/sql/unireg.cc
2707 +--- mysql-orig/sql/unireg.cc 2012-08-14 01:12:29.413437640 +0000
2708 ++++ mysql/sql/unireg.cc 2012-08-14 01:14:59.512196872 +0000
2709 +@@ -498,7 +498,7 @@
2710 + }
2711 + cfield->row=(uint8) row;
2712 + cfield->col=(uint8) (length+1);
2713 +- cfield->sc_length=(uint8) min(cfield->length,cols-(length+2));
2714 ++ cfield->sc_length=(uint8) MYSQL_MIN(cfield->length,cols-(length+2));
2715 + }
2716 + length=(uint) (pos-start_screen);
2717 + int2store(start_screen,length);
2718 +@@ -718,7 +718,7 @@
2719 + DBUG_RETURN(1);
2720 + }
2721 + /* Hack to avoid bugs with small static rows in MySQL */
2722 +- reclength=max(file->min_record_length(table_options),reclength);
2723 ++ reclength=MYSQL_MAX(file->min_record_length(table_options),reclength);
2724 + if (info_length+(ulong) create_fields.elements*FCOMP+288+
2725 + n_length+int_length+com_length > 65535L || int_count > 255)
2726 + {
2727 +diff -ur mysql-orig/sql-common/client.c mysql/sql-common/client.c
2728 +--- mysql-orig/sql-common/client.c 2012-08-14 01:12:29.723435087 +0000
2729 ++++ mysql/sql-common/client.c 2012-08-14 01:14:59.512196872 +0000
2730 +@@ -730,7 +730,7 @@
2731 + }
2732 +
2733 + (void) strmake(net->last_error,(char*) pos,
2734 +- min((uint) len,(uint) sizeof(net->last_error)-1));
2735 ++ MYSQL_MIN((uint) len,(uint) sizeof(net->last_error)-1));
2736 + }
2737 + else
2738 + set_mysql_error(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate);
2739 +@@ -2113,7 +2113,7 @@
2740 + {
2741 + IF_DBUG(char ipaddr[18];)
2742 + memcpy(&sock_addr.sin_addr, hp->h_addr_list[i],
2743 +- min(sizeof(sock_addr.sin_addr), (size_t) hp->h_length));
2744 ++ MYSQL_MIN(sizeof(sock_addr.sin_addr), (size_t) hp->h_length));
2745 + DBUG_PRINT("info",("Trying %s...",
2746 + (my_inet_ntoa(sock_addr.sin_addr, ipaddr), ipaddr)));
2747 + status= my_connect(sock, (struct sockaddr *) &sock_addr,
2748 +diff -ur mysql-orig/sql-common/my_time.c mysql/sql-common/my_time.c
2749 +--- mysql-orig/sql-common/my_time.c 2012-08-14 01:12:29.723435087 +0000
2750 ++++ mysql/sql-common/my_time.c 2012-08-14 01:14:59.512196872 +0000
2751 +@@ -251,7 +251,7 @@
2752 + 2003-03-03 20:00:20 AM
2753 + 20:00:20.000000 AM 03-03-2000
2754 + */
2755 +- i= max((uint) format_position[0], (uint) format_position[1]);
2756 ++ i= MYSQL_MAX((uint) format_position[0], (uint) format_position[1]);
2757 + set_if_bigger(i, (uint) format_position[2]);
2758 + allow_space= ((1 << i) | (1 << format_position[6]));
2759 + allow_space&= (1 | 2 | 4 | 8);
2760 +diff -ur mysql-orig/storage/csv/ha_tina.cc mysql/storage/csv/ha_tina.cc
2761 +--- mysql-orig/storage/csv/ha_tina.cc 2012-08-14 01:12:29.663435583 +0000
2762 ++++ mysql/storage/csv/ha_tina.cc 2012-08-14 01:14:59.512196872 +0000
2763 +@@ -1195,7 +1195,7 @@
2764 + if (closest_hole == chain_ptr) /* no more chains */
2765 + *end_pos= file_buff->end();
2766 + else
2767 +- *end_pos= min(file_buff->end(),
2768 ++ *end_pos= MYSQL_MIN(file_buff->end(),
2769 + closest_hole->begin);
2770 + return (closest_hole != chain_ptr) && (*end_pos == closest_hole->begin);
2771 + }
2772 +@@ -1431,7 +1431,7 @@
2773 + /* write repaired file */
2774 + while (1)
2775 + {
2776 +- write_end= min(file_buff->end(), current_position);
2777 ++ write_end= MYSQL_MIN(file_buff->end(), current_position);
2778 + if ((write_end - write_begin) &&
2779 + (my_write(repair_file, (uchar*)file_buff->ptr(),
2780 + (size_t) (write_end - write_begin), MYF_RW)))
2781 +diff -ur mysql-orig/storage/example/ha_example.h mysql/storage/example/ha_example.h
2782 +--- mysql-orig/storage/example/ha_example.h 2012-08-14 01:12:29.693435335 +0000
2783 ++++ mysql/storage/example/ha_example.h 2012-08-14 01:14:59.512196872 +0000
2784 +@@ -112,14 +112,14 @@
2785 + max_supported_key_parts(), uint max_supported_key_length()
2786 + to make sure that the storage engine can handle the data it is about to
2787 + send. Return *real* limits of your storage engine here; MySQL will do
2788 +- min(your_limits, MySQL_limits) automatically.
2789 ++ MYSQL_MIN(your_limits, MySQL_limits) automatically.
2790 + */
2791 + uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; }
2792 +
2793 + /** @brief
2794 + unireg.cc will call this to make sure that the storage engine can handle
2795 + the data it is about to send. Return *real* limits of your storage engine
2796 +- here; MySQL will do min(your_limits, MySQL_limits) automatically.
2797 ++ here; MySQL will do MYSQL_MIN(your_limits, MySQL_limits) automatically.
2798 +
2799 + @details
2800 + There is no need to implement ..._key_... methods if your engine doesn't
2801 +@@ -130,7 +130,7 @@
2802 + /** @brief
2803 + unireg.cc will call this to make sure that the storage engine can handle
2804 + the data it is about to send. Return *real* limits of your storage engine
2805 +- here; MySQL will do min(your_limits, MySQL_limits) automatically.
2806 ++ here; MySQL will do MYSQL_MIN(your_limits, MySQL_limits) automatically.
2807 +
2808 + @details
2809 + There is no need to implement ..._key_... methods if your engine doesn't
2810 +@@ -141,7 +141,7 @@
2811 + /** @brief
2812 + unireg.cc will call this to make sure that the storage engine can handle
2813 + the data it is about to send. Return *real* limits of your storage engine
2814 +- here; MySQL will do min(your_limits, MySQL_limits) automatically.
2815 ++ here; MySQL will do MYSQL_MIN(your_limits, MySQL_limits) automatically.
2816 +
2817 + @details
2818 + There is no need to implement ..._key_... methods if your engine doesn't
2819 +diff -ur mysql-orig/storage/federated/ha_federated.cc mysql/storage/federated/ha_federated.cc
2820 +--- mysql-orig/storage/federated/ha_federated.cc 2012-08-14 01:12:29.643435749 +0000
2821 ++++ mysql/storage/federated/ha_federated.cc 2012-08-14 01:14:59.512196872 +0000
2822 +@@ -546,7 +546,7 @@
2823 + size_t buf_len;
2824 + DBUG_ENTER("ha_federated parse_url_error");
2825 +
2826 +- buf_len= min(table->s->connect_string.length,
2827 ++ buf_len= MYSQL_MIN(table->s->connect_string.length,
2828 + FEDERATED_QUERY_BUFFER_SIZE-1);
2829 + strmake(buf, table->s->connect_string.str, buf_len);
2830 + my_error(error_num, MYF(0), buf);
2831 +@@ -1291,7 +1291,7 @@
2832 + {
2833 + Field *field= key_part->field;
2834 + uint store_length= key_part->store_length;
2835 +- uint part_length= min(store_length, length);
2836 ++ uint part_length= MYSQL_MIN(store_length, length);
2837 + needs_quotes= field->str_needs_quotes();
2838 + DBUG_DUMP("key, start of loop", ptr, length);
2839 +
2840 +diff -ur mysql-orig/storage/heap/hp_create.c mysql/storage/heap/hp_create.c
2841 +--- mysql-orig/storage/heap/hp_create.c 2012-08-14 01:12:29.643435749 +0000
2842 ++++ mysql/storage/heap/hp_create.c 2012-08-14 01:14:59.512196872 +0000
2843 +@@ -230,7 +230,7 @@
2844 + {
2845 + uint i,recbuffer,records_in_block;
2846 +
2847 +- max_records= max(min_records,max_records);
2848 ++ max_records= MYSQL_MAX(min_records,max_records);
2849 + if (!max_records)
2850 + max_records= 1000; /* As good as quess as anything */
2851 + recbuffer= (uint) (reclength + sizeof(uchar**) - 1) & ~(sizeof(uchar**) - 1);
2852 +diff -ur mysql-orig/storage/heap/hp_test2.c mysql/storage/heap/hp_test2.c
2853 +--- mysql-orig/storage/heap/hp_test2.c 2012-08-14 01:12:29.643435749 +0000
2854 ++++ mysql/storage/heap/hp_test2.c 2012-08-14 01:14:59.512196872 +0000
2855 +@@ -138,7 +138,7 @@
2856 +
2857 + for (i=0 ; i < recant ; i++)
2858 + {
2859 +- n1=rnd(1000); n2=rnd(100); n3=rnd(min(recant*5,MAX_RECORDS));
2860 ++ n1=rnd(1000); n2=rnd(100); n3=rnd(MYSQL_MIN(recant*5,MAX_RECORDS));
2861 + make_record(record,n1,n2,n3,"Pos",write_count);
2862 +
2863 + if (heap_write(file,record))
2864 +@@ -219,7 +219,7 @@
2865 + printf("- Update\n");
2866 + for (i=0 ; i < write_count/10 ; i++)
2867 + {
2868 +- n1=rnd(1000); n2=rnd(100); n3=rnd(min(recant*2,MAX_RECORDS));
2869 ++ n1=rnd(1000); n2=rnd(100); n3=rnd(MYSQL_MIN(recant*2,MAX_RECORDS));
2870 + make_record(record2, n1, n2, n3, "XXX", update);
2871 + if (rnd(2) == 1)
2872 + {
2873 +diff -ur mysql-orig/storage/innobase/include/ut0byte.h mysql/storage/innobase/include/ut0byte.h
2874 +--- mysql-orig/storage/innobase/include/ut0byte.h 2012-08-14 01:12:29.653435667 +0000
2875 ++++ mysql/storage/innobase/include/ut0byte.h 2012-08-14 01:14:59.522196790 +0000
2876 +@@ -87,7 +87,7 @@
2877 + dulint
2878 + ut_dulint_get_max(
2879 + /*==============*/
2880 +- /* out: max(a, b) */
2881 ++ /* out: MYSQL_MAX(a, b) */
2882 + dulint a, /* in: dulint */
2883 + dulint b); /* in: dulint */
2884 + /***********************************************************
2885 +@@ -96,7 +96,7 @@
2886 + dulint
2887 + ut_dulint_get_min(
2888 + /*==============*/
2889 +- /* out: min(a, b) */
2890 ++ /* out: MYSQL_MIN(a, b) */
2891 + dulint a, /* in: dulint */
2892 + dulint b); /* in: dulint */
2893 + /***********************************************************
2894 +diff -ur mysql-orig/storage/innodb_plugin/dict/dict0dict.c mysql/storage/innodb_plugin/dict/dict0dict.c
2895 +--- mysql-orig/storage/innodb_plugin/dict/dict0dict.c 2012-08-14 01:12:29.643435749 +0000
2896 ++++ mysql/storage/innodb_plugin/dict/dict0dict.c 2012-08-14 01:14:59.522196790 +0000
2897 +@@ -4898,7 +4898,7 @@
2898 +
2899 + /**********************************************************************//**
2900 + In case there is more than one index with the same name return the index
2901 +-with the min(id).
2902 ++with the MYSQL_MIN(id).
2903 + @return index, NULL if does not exist */
2904 + UNIV_INTERN
2905 + dict_index_t*
2906 +@@ -4908,7 +4908,7 @@
2907 + const char* name) /*!< in: name of the index to find */
2908 + {
2909 + dict_index_t* index;
2910 +- dict_index_t* min_index; /* Index with matching name and min(id) */
2911 ++ dict_index_t* min_index; /* Index with matching name and MYSQL_MIN(id) */
2912 +
2913 + min_index = NULL;
2914 + index = dict_table_get_first_index(table);
2915 +diff -ur mysql-orig/storage/innodb_plugin/include/dict0dict.h mysql/storage/innodb_plugin/include/dict0dict.h
2916 +--- mysql-orig/storage/innodb_plugin/include/dict0dict.h 2012-08-14 01:12:29.643435749 +0000
2917 ++++ mysql/storage/innodb_plugin/include/dict0dict.h 2012-08-14 01:14:59.552196542 +0000
2918 +@@ -1115,7 +1115,7 @@
2919 + const char* name); /*!< in: name of the index to find */
2920 + /**********************************************************************//**
2921 + In case there is more than one index with the same name return the index
2922 +-with the min(id).
2923 ++with the MYSQL_MIN(id).
2924 + @return index, NULL if does not exist */
2925 + UNIV_INTERN
2926 + dict_index_t*
2927 +diff -ur mysql-orig/storage/myisam/ft_boolean_search.c mysql/storage/myisam/ft_boolean_search.c
2928 +--- mysql-orig/storage/myisam/ft_boolean_search.c 2012-08-14 01:12:29.643435749 +0000
2929 ++++ mysql/storage/myisam/ft_boolean_search.c 2012-08-14 01:14:59.552196542 +0000
2930 +@@ -48,9 +48,9 @@
2931 + three subexpressions (including the top-level one),
2932 + every one has its own max_docid, updated by its plus word.
2933 + but for the search word6 uses
2934 +- max(word1.max_docid, word3.max_docid, word5.max_docid),
2935 ++ MYSQL_MAX(word1.max_docid, word3.max_docid, word5.max_docid),
2936 + while word4 uses, accordingly,
2937 +- max(word1.max_docid, word3.max_docid).
2938 ++ MYSQL_MAX(word1.max_docid, word3.max_docid).
2939 + */
2940 +
2941 + #define FT_CORE
2942 +diff -ur mysql-orig/storage/myisam/ha_myisam.cc mysql/storage/myisam/ha_myisam.cc
2943 +--- mysql-orig/storage/myisam/ha_myisam.cc 2012-08-14 01:12:29.653435667 +0000
2944 ++++ mysql/storage/myisam/ha_myisam.cc 2012-08-14 01:14:59.552196542 +0000
2945 +@@ -1546,7 +1546,7 @@
2946 + {
2947 + DBUG_ENTER("ha_myisam::start_bulk_insert");
2948 + THD *thd= current_thd;
2949 +- ulong size= min(thd->variables.read_buff_size,
2950 ++ ulong size= MYSQL_MIN(thd->variables.read_buff_size,
2951 + (ulong) (table->s->avg_row_length*rows));
2952 + DBUG_PRINT("info",("start_bulk_insert: rows %lu size %lu",
2953 + (ulong) rows, size));
2954 +diff -ur mysql-orig/storage/myisam/mi_cache.c mysql/storage/myisam/mi_cache.c
2955 +--- mysql-orig/storage/myisam/mi_cache.c 2012-08-14 01:12:29.643435749 +0000
2956 ++++ mysql/storage/myisam/mi_cache.c 2012-08-14 01:14:59.572196376 +0000
2957 +@@ -61,7 +61,7 @@
2958 + (my_off_t) (info->read_end - info->request_pos))
2959 + {
2960 + in_buff_pos=info->request_pos+(uint) offset;
2961 +- in_buff_length= min(length, (size_t) (info->read_end-in_buff_pos));
2962 ++ in_buff_length= MYSQL_MIN(length, (size_t) (info->read_end-in_buff_pos));
2963 + memcpy(buff,info->request_pos+(uint) offset,(size_t) in_buff_length);
2964 + if (!(length-=in_buff_length))
2965 + DBUG_RETURN(0);
2966 +diff -ur mysql-orig/storage/myisam/mi_check.c mysql/storage/myisam/mi_check.c
2967 +--- mysql-orig/storage/myisam/mi_check.c 2012-08-14 01:12:29.653435667 +0000
2968 ++++ mysql/storage/myisam/mi_check.c 2012-08-14 01:14:59.572196376 +0000
2969 +@@ -2175,7 +2175,7 @@
2970 + ulong buff_length;
2971 + DBUG_ENTER("filecopy");
2972 +
2973 +- buff_length=(ulong) min(param->write_buffer_length,length);
2974 ++ buff_length=(ulong) MYSQL_MIN(param->write_buffer_length,length);
2975 + if (!(buff=my_malloc(buff_length,MYF(0))))
2976 + {
2977 + buff=tmp_buff; buff_length=IO_SIZE;
2978 +@@ -2331,7 +2331,7 @@
2979 + init_alloc_root(&sort_param.wordroot, FTPARSER_MEMROOT_ALLOC_SIZE, 0);
2980 +
2981 + if (share->data_file_type == DYNAMIC_RECORD)
2982 +- length=max(share->base.min_pack_length+1,share->base.min_block_length);
2983 ++ length=MYSQL_MAX(share->base.min_pack_length+1,share->base.min_block_length);
2984 + else if (share->data_file_type == COMPRESSED_RECORD)
2985 + length=share->base.min_block_length;
2986 + else
2987 +@@ -2420,7 +2420,7 @@
2988 + (see _create_index_by_sort)
2989 + */
2990 + sort_info.max_records= 10 *
2991 +- max(param->sort_buffer_length, MIN_SORT_BUFFER) /
2992 ++ MYSQL_MAX(param->sort_buffer_length, MIN_SORT_BUFFER) /
2993 + sort_param.key_length;
2994 + }
2995 +
2996 +@@ -2784,7 +2784,7 @@
2997 + my_seek(param->read_cache.file,0L,MY_SEEK_END,MYF(0));
2998 +
2999 + if (share->data_file_type == DYNAMIC_RECORD)
3000 +- rec_length=max(share->base.min_pack_length+1,share->base.min_block_length);
3001 ++ rec_length=MYSQL_MAX(share->base.min_pack_length+1,share->base.min_block_length);
3002 + else if (share->data_file_type == COMPRESSED_RECORD)
3003 + rec_length=share->base.min_block_length;
3004 + else
3005 +@@ -3982,7 +3982,7 @@
3006 + ft_buf->buf=ft_buf->lastkey+a_len;
3007 + /*
3008 + 32 is just a safety margin here
3009 +- (at least max(val_len, sizeof(nod_flag)) should be there).
3010 ++ (at least MYSQL_MAX(val_len, sizeof(nod_flag)) should be there).
3011 + May be better performance could be achieved if we'd put
3012 + (sort_info->keyinfo->block_length-32)/XXX
3013 + instead.
3014 +diff -ur mysql-orig/storage/myisam/mi_create.c mysql/storage/myisam/mi_create.c
3015 +--- mysql-orig/storage/myisam/mi_create.c 2012-08-14 01:12:29.643435749 +0000
3016 ++++ mysql/storage/myisam/mi_create.c 2012-08-14 01:14:59.572196376 +0000
3017 +@@ -439,8 +439,8 @@
3018 + block_length= (keydef->block_length ?
3019 + my_round_up_to_next_power(keydef->block_length) :
3020 + myisam_block_size);
3021 +- block_length= max(block_length, MI_MIN_KEY_BLOCK_LENGTH);
3022 +- block_length= min(block_length, MI_MAX_KEY_BLOCK_LENGTH);
3023 ++ block_length= MYSQL_MAX(block_length, MI_MIN_KEY_BLOCK_LENGTH);
3024 ++ block_length= MYSQL_MIN(block_length, MI_MAX_KEY_BLOCK_LENGTH);
3025 +
3026 + keydef->block_length= (uint16) MI_BLOCK_SIZE(length-real_length_diff,
3027 + pointer,MI_MAX_KEYPTR_SIZE,
3028 +@@ -529,7 +529,7 @@
3029 + got from MYI file header (see also myisampack.c:save_state)
3030 + */
3031 + share.base.key_reflength=
3032 +- mi_get_pointer_length(max(ci->key_file_length,tmp),3);
3033 ++ mi_get_pointer_length(MYSQL_MAX(ci->key_file_length,tmp),3);
3034 + share.base.keys= share.state.header.keys= keys;
3035 + share.state.header.uniques= uniques;
3036 + share.state.header.fulltext_keys= fulltext_keys;
3037 +@@ -567,7 +567,7 @@
3038 + share.base.min_block_length=
3039 + (share.base.pack_reclength+3 < MI_EXTEND_BLOCK_LENGTH &&
3040 + ! share.base.blobs) ?
3041 +- max(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
3042 ++ MYSQL_MAX(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
3043 + MI_EXTEND_BLOCK_LENGTH;
3044 + if (! (flags & HA_DONT_TOUCH_DATA))
3045 + share.state.create_time= (long) time((time_t*) 0);
3046 +diff -ur mysql-orig/storage/myisam/mi_dynrec.c mysql/storage/myisam/mi_dynrec.c
3047 +--- mysql-orig/storage/myisam/mi_dynrec.c 2012-08-14 01:12:29.643435749 +0000
3048 ++++ mysql/storage/myisam/mi_dynrec.c 2012-08-14 01:14:59.572196376 +0000
3049 +@@ -882,7 +882,7 @@
3050 + uint tmp=MY_ALIGN(reclength - length + 3 +
3051 + test(reclength >= 65520L),MI_DYN_ALIGN_SIZE);
3052 + /* Don't create a block bigger than MI_MAX_BLOCK_LENGTH */
3053 +- tmp= min(length+tmp, MI_MAX_BLOCK_LENGTH)-length;
3054 ++ tmp= MYSQL_MIN(length+tmp, MI_MAX_BLOCK_LENGTH)-length;
3055 + /* Check if we can extend this block */
3056 + if (block_info.filepos + block_info.block_len ==
3057 + info->state->data_file_length &&
3058 +diff -ur mysql-orig/storage/myisam/mi_extra.c mysql/storage/myisam/mi_extra.c
3059 +--- mysql-orig/storage/myisam/mi_extra.c 2012-08-14 01:12:29.653435667 +0000
3060 ++++ mysql/storage/myisam/mi_extra.c 2012-08-14 01:14:59.572196376 +0000
3061 +@@ -101,7 +101,7 @@
3062 + cache_size= (extra_arg ? *(ulong*) extra_arg :
3063 + my_default_record_cache_size);
3064 + if (!(init_io_cache(&info->rec_cache,info->dfile,
3065 +- (uint) min(info->state->data_file_length+1,
3066 ++ (uint) MYSQL_MIN(info->state->data_file_length+1,
3067 + cache_size),
3068 + READ_CACHE,0L,(pbool) (info->lock_type != F_UNLCK),
3069 + MYF(share->write_flag & MY_WAIT_IF_FULL))))
3070 +diff -ur mysql-orig/storage/myisam/mi_open.c mysql/storage/myisam/mi_open.c
3071 +--- mysql-orig/storage/myisam/mi_open.c 2012-08-14 01:12:29.643435749 +0000
3072 ++++ mysql/storage/myisam/mi_open.c 2012-08-14 01:14:59.582196294 +0000
3073 +@@ -330,7 +330,7 @@
3074 + strmov(share->index_file_name, index_name);
3075 + strmov(share->data_file_name, data_name);
3076 +
3077 +- share->blocksize=min(IO_SIZE,myisam_block_size);
3078 ++ share->blocksize=MYSQL_MIN(IO_SIZE,myisam_block_size);
3079 + {
3080 + HA_KEYSEG *pos=share->keyparts;
3081 + uint32 ftkey_nr= 1;
3082 +@@ -503,7 +503,7 @@
3083 + share->base.margin_key_file_length=(share->base.max_key_file_length -
3084 + (keys ? MI_INDEX_BLOCK_MARGIN *
3085 + share->blocksize * keys : 0));
3086 +- share->blocksize=min(IO_SIZE,myisam_block_size);
3087 ++ share->blocksize=MYSQL_MIN(IO_SIZE,myisam_block_size);
3088 + share->data_file_type=STATIC_RECORD;
3089 + if (share->options & HA_OPTION_COMPRESS_RECORD)
3090 + {
3091 +@@ -716,10 +716,10 @@
3092 + if (length == (ulong) -1)
3093 + {
3094 + if (info->s->options & HA_OPTION_COMPRESS_RECORD)
3095 +- length= max(info->s->base.pack_reclength, info->s->max_pack_length);
3096 ++ length= MYSQL_MAX(info->s->base.pack_reclength, info->s->max_pack_length);
3097 + else
3098 + length= info->s->base.pack_reclength;
3099 +- length= max(length, info->s->base.max_key_length);
3100 ++ length= MYSQL_MAX(length, info->s->base.max_key_length);
3101 + /* Avoid unnecessary realloc */
3102 + if (newptr && length == old_length)
3103 + return newptr;
3104 +diff -ur mysql-orig/storage/myisam/mi_packrec.c mysql/storage/myisam/mi_packrec.c
3105 +--- mysql-orig/storage/myisam/mi_packrec.c 2012-08-14 01:12:29.643435749 +0000
3106 ++++ mysql/storage/myisam/mi_packrec.c 2012-08-14 01:14:59.582196294 +0000
3107 +@@ -686,7 +686,7 @@
3108 + return OFFSET_TABLE_SIZE;
3109 + }
3110 + length2= find_longest_bitstream(next, end) + 1;
3111 +- length=max(length,length2);
3112 ++ length=MYSQL_MAX(length,length2);
3113 + }
3114 + return length;
3115 + }
3116 +@@ -1401,7 +1401,7 @@
3117 + info->filepos=filepos+head_length;
3118 + if (file > 0)
3119 + {
3120 +- info->offset=min(info->rec_len, ref_length - head_length);
3121 ++ info->offset=MYSQL_MIN(info->rec_len, ref_length - head_length);
3122 + memcpy(*rec_buff_p, header + head_length, info->offset);
3123 + }
3124 + return 0;
3125 +diff -ur mysql-orig/storage/myisam/mi_test1.c mysql/storage/myisam/mi_test1.c
3126 +--- mysql-orig/storage/myisam/mi_test1.c 2012-08-14 01:12:29.653435667 +0000
3127 ++++ mysql/storage/myisam/mi_test1.c 2012-08-14 01:14:59.582196294 +0000
3128 +@@ -438,7 +438,7 @@
3129 + uint tmp;
3130 + uchar *ptr;;
3131 + sprintf((char*) blob_record,"... row: %d", rownr);
3132 +- strappend((char*) blob_record,max(MAX_REC_LENGTH-rownr,10),' ');
3133 ++ strappend((char*) blob_record,MYSQL_MAX(MAX_REC_LENGTH-rownr,10),' ');
3134 + tmp=strlen((char*) blob_record);
3135 + int4store(pos,tmp);
3136 + ptr=blob_record;
3137 +diff -ur mysql-orig/storage/myisam/mi_test2.c mysql/storage/myisam/mi_test2.c
3138 +--- mysql-orig/storage/myisam/mi_test2.c 2012-08-14 01:12:29.653435667 +0000
3139 ++++ mysql/storage/myisam/mi_test2.c 2012-08-14 01:14:59.582196294 +0000
3140 +@@ -603,7 +603,7 @@
3141 + goto err;
3142 +
3143 + bmove(read_record2,read_record,reclength);
3144 +- for (i=min(2,keys) ; i-- > 0 ;)
3145 ++ for (i=MYSQL_MIN(2,keys) ; i-- > 0 ;)
3146 + {
3147 + if (mi_rsame(file,read_record2,(int) i)) goto err;
3148 + if (memcmp(read_record,read_record2,reclength) != 0)
3149 +diff -ur mysql-orig/storage/myisam/myisamlog.c mysql/storage/myisam/myisamlog.c
3150 +--- mysql-orig/storage/myisam/myisamlog.c 2012-08-14 01:12:29.653435667 +0000
3151 ++++ mysql/storage/myisam/myisamlog.c 2012-08-14 01:14:59.582196294 +0000
3152 +@@ -92,7 +92,7 @@
3153 + log_filename=myisam_log_filename;
3154 + get_options(&argc,&argv);
3155 + /* Number of MyISAM files we can have open at one time */
3156 +- max_files= (my_set_max_open_files(min(max_files,8))-6)/2;
3157 ++ max_files= (my_set_max_open_files(MYSQL_MIN(max_files,8))-6)/2;
3158 + if (update)
3159 + printf("Trying to %s MyISAM files according to log '%s'\n",
3160 + (recover ? "recover" : "update"),log_filename);
3161 +diff -ur mysql-orig/storage/myisam/myisampack.c mysql/storage/myisam/myisampack.c
3162 +--- mysql-orig/storage/myisam/myisampack.c 2012-08-14 01:12:29.643435749 +0000
3163 ++++ mysql/storage/myisam/myisampack.c 2012-08-14 01:14:59.582196294 +0000
3164 +@@ -1240,7 +1240,7 @@
3165 + {
3166 + if (huff_counts->field_length > 2 &&
3167 + huff_counts->empty_fields + (records - huff_counts->empty_fields)*
3168 +- (1+max_bit(max(huff_counts->max_pre_space,
3169 ++ (1+max_bit(MYSQL_MAX(huff_counts->max_pre_space,
3170 + huff_counts->max_end_space))) <
3171 + records * max_bit(huff_counts->field_length))
3172 + {
3173 +@@ -3002,7 +3002,7 @@
3174 + if (mrg->src_file_has_indexes_disabled)
3175 + {
3176 + isam_file->s->state.state.key_file_length=
3177 +- max(isam_file->s->state.state.key_file_length, new_length);
3178 ++ MYSQL_MAX(isam_file->s->state.state.key_file_length, new_length);
3179 + }
3180 + state.dellink= HA_OFFSET_ERROR;
3181 + state.version=(ulong) time((time_t*) 0);
3182 +diff -ur mysql-orig/storage/myisam/rt_mbr.c mysql/storage/myisam/rt_mbr.c
3183 +--- mysql-orig/storage/myisam/rt_mbr.c 2012-08-14 01:12:29.643435749 +0000
3184 ++++ mysql/storage/myisam/rt_mbr.c 2012-08-14 01:14:59.582196294 +0000
3185 +@@ -325,8 +325,8 @@
3186 + bmin = korr_func(b); \
3187 + amax = korr_func(a+len); \
3188 + bmax = korr_func(b+len); \
3189 +- amin = min(amin, bmin); \
3190 +- amax = max(amax, bmax); \
3191 ++ amin = MYSQL_MIN(amin, bmin); \
3192 ++ amax = MYSQL_MAX(amax, bmax); \
3193 + store_func(c, amin); \
3194 + store_func(c+len, amax); \
3195 + }
3196 +@@ -338,8 +338,8 @@
3197 + get_func(bmin, b); \
3198 + get_func(amax, a+len); \
3199 + get_func(bmax, b+len); \
3200 +- amin = min(amin, bmin); \
3201 +- amax = max(amax, bmax); \
3202 ++ amin = MYSQL_MIN(amin, bmin); \
3203 ++ amax = MYSQL_MAX(amax, bmax); \
3204 + store_func(c, amin); \
3205 + store_func(c+len, amax); \
3206 + }
3207 +@@ -417,8 +417,8 @@
3208 + bmin = korr_func(b); \
3209 + amax = korr_func(a+len); \
3210 + bmax = korr_func(b+len); \
3211 +- amin = max(amin, bmin); \
3212 +- amax = min(amax, bmax); \
3213 ++ amin = MYSQL_MAX(amin, bmin); \
3214 ++ amax = MYSQL_MIN(amax, bmax); \
3215 + if (amin >= amax) \
3216 + return 0; \
3217 + res *= amax - amin; \
3218 +@@ -431,8 +431,8 @@
3219 + get_func(bmin, b); \
3220 + get_func(amax, a+len); \
3221 + get_func(bmax, b+len); \
3222 +- amin = max(amin, bmin); \
3223 +- amax = min(amax, bmax); \
3224 ++ amin = MYSQL_MAX(amin, bmin); \
3225 ++ amax = MYSQL_MIN(amax, bmax); \
3226 + if (amin >= amax) \
3227 + return 0; \
3228 + res *= amax - amin; \
3229 +@@ -508,7 +508,7 @@
3230 + amax = korr_func(a+len); \
3231 + bmax = korr_func(b+len); \
3232 + a_area *= (((double)amax) - ((double)amin)); \
3233 +- loc_ab_area *= ((double)max(amax, bmax) - (double)min(amin, bmin)); \
3234 ++ loc_ab_area *= ((double)MYSQL_MAX(amax, bmax) - (double)MYSQL_MIN(amin, bmin)); \
3235 + }
3236 +
3237 + #define RT_AREA_INC_GET(type, get_func, len)\
3238 +@@ -519,7 +519,7 @@
3239 + get_func(amax, a+len); \
3240 + get_func(bmax, b+len); \
3241 + a_area *= (((double)amax) - ((double)amin)); \
3242 +- loc_ab_area *= ((double)max(amax, bmax) - (double)min(amin, bmin)); \
3243 ++ loc_ab_area *= ((double)MYSQL_MAX(amax, bmax) - (double)MYSQL_MIN(amin, bmin)); \
3244 + }
3245 +
3246 + /*
3247 +@@ -604,7 +604,7 @@
3248 + amax = korr_func(a+len); \
3249 + bmax = korr_func(b+len); \
3250 + a_perim+= (((double)amax) - ((double)amin)); \
3251 +- *ab_perim+= ((double)max(amax, bmax) - (double)min(amin, bmin)); \
3252 ++ *ab_perim+= ((double)MYSQL_MAX(amax, bmax) - (double)MYSQL_MIN(amin, bmin)); \
3253 + }
3254 +
3255 + #define RT_PERIM_INC_GET(type, get_func, len)\
3256 +@@ -615,7 +615,7 @@
3257 + get_func(amax, a+len); \
3258 + get_func(bmax, b+len); \
3259 + a_perim+= (((double)amax) - ((double)amin)); \
3260 +- *ab_perim+= ((double)max(amax, bmax) - (double)min(amin, bmin)); \
3261 ++ *ab_perim+= ((double)MYSQL_MAX(amax, bmax) - (double)MYSQL_MIN(amin, bmin)); \
3262 + }
3263 +
3264 + /*
3265 +diff -ur mysql-orig/storage/myisam/sort.c mysql/storage/myisam/sort.c
3266 +--- mysql-orig/storage/myisam/sort.c 2012-08-14 01:12:29.643435749 +0000
3267 ++++ mysql/storage/myisam/sort.c 2012-08-14 01:14:59.582196294 +0000
3268 +@@ -131,7 +131,7 @@
3269 + sort_keys= (uchar **) NULL; error= 1;
3270 + maxbuffer=1;
3271 +
3272 +- memavl= max(sortbuff_size, MIN_SORT_BUFFER);
3273 ++ memavl= MYSQL_MAX(sortbuff_size, MIN_SORT_BUFFER);
3274 + records= info->sort_info->max_records;
3275 + sort_length= info->key_length;
3276 + LINT_INIT(keys);
3277 +@@ -348,7 +348,7 @@
3278 + bzero((char*) &sort_param->unique, sizeof(sort_param->unique));
3279 + sort_keys= (uchar **) NULL;
3280 +
3281 +- memavl= max(sort_param->sortbuff_size, MIN_SORT_BUFFER);
3282 ++ memavl= MYSQL_MAX(sort_param->sortbuff_size, MIN_SORT_BUFFER);
3283 + idx= (uint)sort_param->sort_info->max_records;
3284 + sort_length= sort_param->key_length;
3285 + maxbuffer= 1;
3286 +@@ -822,7 +822,7 @@
3287 + register uint count;
3288 + uint length;
3289 +
3290 +- if ((count=(uint) min((ha_rows) buffpek->max_keys,buffpek->count)))
3291 ++ if ((count=(uint) MYSQL_MIN((ha_rows) buffpek->max_keys,buffpek->count)))
3292 + {
3293 + if (my_pread(fromfile->file,(uchar*) buffpek->base,
3294 + (length= sort_length*count),buffpek->file_pos,MYF_RW))
3295 +@@ -843,7 +843,7 @@
3296 + uint idx;
3297 + uchar *buffp;
3298 +
3299 +- if ((count=(uint) min((ha_rows) buffpek->max_keys,buffpek->count)))
3300 ++ if ((count=(uint) MYSQL_MIN((ha_rows) buffpek->max_keys,buffpek->count)))
3301 + {
3302 + buffp = buffpek->base;
3303 +
3304 +diff -ur mysql-orig/storage/myisammrg/ha_myisammrg.cc mysql/storage/myisammrg/ha_myisammrg.cc
3305 +--- mysql-orig/storage/myisammrg/ha_myisammrg.cc 2012-08-14 01:12:29.643435749 +0000
3306 ++++ mysql/storage/myisammrg/ha_myisammrg.cc 2012-08-14 01:14:59.582196294 +0000
3307 +@@ -965,7 +965,7 @@
3308 + memcpy((char*) table->key_info[0].rec_per_key,
3309 + (char*) mrg_info.rec_per_key,
3310 + sizeof(table->key_info[0].rec_per_key[0]) *
3311 +- min(file->keys, table->s->key_parts));
3312 ++ MYSQL_MIN(file->keys, table->s->key_parts));
3313 + }
3314 + }
3315 + if (flag & HA_STATUS_ERRKEY)
3316 +diff -ur mysql-orig/storage/ndb/src/common/portlib/NdbTCP.cpp mysql/storage/ndb/src/common/portlib/NdbTCP.cpp
3317 +--- mysql-orig/storage/ndb/src/common/portlib/NdbTCP.cpp 2012-08-14 01:12:29.673435501 +0000
3318 ++++ mysql/storage/ndb/src/common/portlib/NdbTCP.cpp 2012-08-14 01:14:59.582196294 +0000
3319 +@@ -30,7 +30,7 @@
3320 + &tmp_errno);
3321 + if (hp)
3322 + {
3323 +- memcpy(dst, hp->h_addr, min(sizeof(*dst), (size_t) hp->h_length));
3324 ++ memcpy(dst, hp->h_addr, MYSQL_MIN(sizeof(*dst), (size_t) hp->h_length));
3325 + my_gethostbyname_r_free();
3326 + return 0; //DBUG_RETURN(0);
3327 + }
3328 +diff -ur mysql-orig/storage/ndb/src/kernel/blocks/dbtux/DbtuxDebug.cpp mysql/storage/ndb/src/kernel/blocks/dbtux/DbtuxDebug.cpp
3329 +--- mysql-orig/storage/ndb/src/kernel/blocks/dbtux/DbtuxDebug.cpp 2012-08-14 01:12:29.683435419 +0000
3330 ++++ mysql/storage/ndb/src/kernel/blocks/dbtux/DbtuxDebug.cpp 2012-08-14 01:14:59.582196294 +0000
3331 +@@ -212,7 +212,7 @@
3332 + }
3333 + }
3334 + // return values
3335 +- par.m_depth = 1 + max(cpar[0].m_depth, cpar[1].m_depth);
3336 ++ par.m_depth = 1 + MYSQL_MAX(cpar[0].m_depth, cpar[1].m_depth);
3337 + par.m_occup = node.getOccup();
3338 + for (unsigned i = 0; i <= 1; i++) {
3339 + if (node.getLink(i) == NullTupLoc)
3340 +diff -ur mysql-orig/storage/ndb/src/ndbapi/NdbBlob.cpp mysql/storage/ndb/src/ndbapi/NdbBlob.cpp
3341 +--- mysql-orig/storage/ndb/src/ndbapi/NdbBlob.cpp 2012-08-14 01:12:29.693435335 +0000
3342 ++++ mysql/storage/ndb/src/ndbapi/NdbBlob.cpp 2012-08-14 01:14:59.582196294 +0000
3343 +@@ -1523,7 +1523,7 @@
3344 + }
3345 + // these buffers are always used
3346 + theKeyBuf.alloc(theTable->m_keyLenInWords << 2);
3347 +- thePackKeyBuf.alloc(max(theTable->m_keyLenInWords, theAccessTable->m_keyLenInWords) << 2);
3348 ++ thePackKeyBuf.alloc(MYSQL_MAX(theTable->m_keyLenInWords, theAccessTable->m_keyLenInWords) << 2);
3349 + theHeadInlineBuf.alloc(sizeof(Head) + theInlineSize);
3350 + theHead = (Head*)theHeadInlineBuf.data;
3351 + theInlineData = theHeadInlineBuf.data + sizeof(Head);
3352 +diff -ur mysql-orig/storage/ndb/test/ndbapi/testIndexStat.cpp mysql/storage/ndb/test/ndbapi/testIndexStat.cpp
3353 +--- mysql-orig/storage/ndb/test/ndbapi/testIndexStat.cpp 2012-08-14 01:12:29.663435583 +0000
3354 ++++ mysql/storage/ndb/test/ndbapi/testIndexStat.cpp 2012-08-14 01:14:59.582196294 +0000
3355 +@@ -30,10 +30,10 @@
3356 + * 0. baseline with same options as handler
3357 + */
3358 +
3359 +-#undef min
3360 +-#undef max
3361 +-#define min(a, b) ((a) <= (b) ? (a) : (b))
3362 +-#define max(a, b) ((a) >= (b) ? (a) : (b))
3363 ++#undef MYSQL_MIN
3364 ++#undef MYSQL_MAX
3365 ++#define MYSQL_MIN(a, b) ((a) <= (b) ? (a) : (b))
3366 ++#define MYSQL_MAX(a, b) ((a) >= (b) ? (a) : (b))
3367 +
3368 + inline NdbOut&
3369 + NdbOut::operator<<(double x)
3370 +@@ -784,13 +784,13 @@
3371 + uint
3372 + Range::minattrs() const
3373 + {
3374 +- return min(bnd[0].val.numattrs, bnd[1].val.numattrs);
3375 ++ return MYSQL_MIN(bnd[0].val.numattrs, bnd[1].val.numattrs);
3376 + }
3377 +
3378 + uint
3379 + Range::maxattrs() const
3380 + {
3381 +- return max(bnd[0].val.numattrs, bnd[1].val.numattrs);
3382 ++ return MYSQL_MAX(bnd[0].val.numattrs, bnd[1].val.numattrs);
3383 + }
3384 +
3385 + int
3386 +@@ -856,8 +856,8 @@
3387 + lim[i] = lo;
3388 + }
3389 + // the range
3390 +- const int lo = max(lim[0], 0);
3391 +- const int hi = min(lim[1], (int)g_sortcount - 1);
3392 ++ const int lo = MYSQL_MAX(lim[0], 0);
3393 ++ const int hi = MYSQL_MIN(lim[1], (int)g_sortcount - 1);
3394 + if (! g_opts.nochecks) {
3395 + int curr = -1;
3396 + for (i = 0; i < (int)g_sortcount; i++) {
3397 +diff -ur mysql-orig/storage/ndb/test/src/getarg.c mysql/storage/ndb/test/src/getarg.c
3398 +--- mysql-orig/storage/ndb/test/src/getarg.c 2012-08-14 01:12:29.663435583 +0000
3399 ++++ mysql/storage/ndb/test/src/getarg.c 2012-08-14 01:14:59.582196294 +0000
3400 +@@ -65,8 +65,8 @@
3401 +
3402 + #define ISFLAG(X) ((X).type == arg_flag || (X).type == arg_negative_flag)
3403 +
3404 +-#ifndef max
3405 +-#define max(a, b) (a) > (b) ? (a) : (b)
3406 ++#ifndef MYSQL_MAX
3407 ++#define MYSQL_MAX(a, b) (a) > (b) ? (a) : (b)
3408 + #endif
3409 +
3410 + #ifdef HAVE___PROGNAME
3411 +@@ -306,7 +306,7 @@
3412 + }
3413 + if (args[i].long_name && args[i].short_name)
3414 + len += 2; /* ", " */
3415 +- max_len = max(max_len, len);
3416 ++ max_len = MYSQL_MAX(max_len, len);
3417 + }
3418 + if (extra_string) {
3419 + col = check_column(stderr, col, strlen(extra_string) + 1, columns);
3420 +diff -ur mysql-orig/strings/ctype-big5.c mysql/strings/ctype-big5.c
3421 +--- mysql-orig/strings/ctype-big5.c 2012-08-14 01:12:29.723435087 +0000
3422 ++++ mysql/strings/ctype-big5.c 2012-08-14 01:14:59.592196210 +0000
3423 +@@ -254,7 +254,7 @@
3424 + const uchar *b, size_t b_length,
3425 + my_bool b_is_prefix)
3426 + {
3427 +- size_t length= min(a_length, b_length);
3428 ++ size_t length= MYSQL_MIN(a_length, b_length);
3429 + int res= my_strnncoll_big5_internal(&a, &b, length);
3430 + return res ? res : (int)((b_is_prefix ? length : a_length) - b_length);
3431 + }
3432 +@@ -267,7 +267,7 @@
3433 + const uchar *b, size_t b_length,
3434 + my_bool diff_if_only_endspace_difference)
3435 + {
3436 +- size_t length= min(a_length, b_length);
3437 ++ size_t length= MYSQL_MIN(a_length, b_length);
3438 + int res= my_strnncoll_big5_internal(&a, &b, length);
3439 +
3440 + #ifndef VARCHAR_WITH_DIFF_ENDSPACE_ARE_DIFFERENT_FOR_UNIQUE
3441 +diff -ur mysql-orig/strings/ctype-bin.c mysql/strings/ctype-bin.c
3442 +--- mysql-orig/strings/ctype-bin.c 2012-08-14 01:12:29.723435087 +0000
3443 ++++ mysql/strings/ctype-bin.c 2012-08-14 01:14:59.592196210 +0000
3444 +@@ -82,7 +82,7 @@
3445 + const uchar *t, size_t tlen,
3446 + my_bool t_is_prefix)
3447 + {
3448 +- size_t len=min(slen,tlen);
3449 ++ size_t len=MYSQL_MIN(slen,tlen);
3450 + int cmp= memcmp(s,t,len);
3451 + return cmp ? cmp : (int)((t_is_prefix ? len : slen) - tlen);
3452 + }
3453 +@@ -133,7 +133,7 @@
3454 + const uchar *t, size_t tlen,
3455 + my_bool t_is_prefix)
3456 + {
3457 +- size_t len=min(slen,tlen);
3458 ++ size_t len=MYSQL_MIN(slen,tlen);
3459 + int cmp= memcmp(s,t,len);
3460 + return cmp ? cmp : (int)((t_is_prefix ? len : slen) - tlen);
3461 + }
3462 +@@ -177,7 +177,7 @@
3463 + diff_if_only_endspace_difference= 0;
3464 + #endif
3465 +
3466 +- end= a + (length= min(a_length, b_length));
3467 ++ end= a + (length= MYSQL_MIN(a_length, b_length));
3468 + while (a < end)
3469 + {
3470 + if (*a++ != *b++)
3471 +@@ -406,7 +406,7 @@
3472 + const uchar *src, size_t srclen)
3473 + {
3474 + if (dest != src)
3475 +- memcpy(dest, src, min(dstlen,srclen));
3476 ++ memcpy(dest, src, MYSQL_MIN(dstlen,srclen));
3477 + if (dstlen > srclen)
3478 + bfill(dest + srclen, dstlen - srclen, 0);
3479 + return dstlen;
3480 +@@ -419,7 +419,7 @@
3481 + const uchar *src, size_t srclen)
3482 + {
3483 + if (dest != src)
3484 +- memcpy(dest, src, min(dstlen,srclen));
3485 ++ memcpy(dest, src, MYSQL_MIN(dstlen,srclen));
3486 + if (dstlen > srclen)
3487 + bfill(dest + srclen, dstlen - srclen, ' ');
3488 + return dstlen;
3489 +diff -ur mysql-orig/strings/ctype-gbk.c mysql/strings/ctype-gbk.c
3490 +--- mysql-orig/strings/ctype-gbk.c 2012-08-14 01:12:29.723435087 +0000
3491 ++++ mysql/strings/ctype-gbk.c 2012-08-14 01:14:59.592196210 +0000
3492 +@@ -2617,7 +2617,7 @@
3493 + const uchar *b, size_t b_length,
3494 + my_bool b_is_prefix)
3495 + {
3496 +- size_t length= min(a_length, b_length);
3497 ++ size_t length= MYSQL_MIN(a_length, b_length);
3498 + int res= my_strnncoll_gbk_internal(&a, &b, length);
3499 + return res ? res : (int) ((b_is_prefix ? length : a_length) - b_length);
3500 + }
3501 +@@ -2628,7 +2628,7 @@
3502 + const uchar *b, size_t b_length,
3503 + my_bool diff_if_only_endspace_difference)
3504 + {
3505 +- size_t length= min(a_length, b_length);
3506 ++ size_t length= MYSQL_MIN(a_length, b_length);
3507 + int res= my_strnncoll_gbk_internal(&a, &b, length);
3508 +
3509 + #ifndef VARCHAR_WITH_DIFF_ENDSPACE_ARE_DIFFERENT_FOR_UNIQUE
3510 +diff -ur mysql-orig/strings/ctype-mb.c mysql/strings/ctype-mb.c
3511 +--- mysql-orig/strings/ctype-mb.c 2012-08-14 01:12:29.723435087 +0000
3512 ++++ mysql/strings/ctype-mb.c 2012-08-14 01:14:59.592196210 +0000
3513 +@@ -369,7 +369,7 @@
3514 + const uchar *t, size_t tlen,
3515 + my_bool t_is_prefix)
3516 + {
3517 +- size_t len=min(slen,tlen);
3518 ++ size_t len=MYSQL_MIN(slen,tlen);
3519 + int cmp= memcmp(s,t,len);
3520 + return cmp ? cmp : (int) ((t_is_prefix ? len : slen) - tlen);
3521 + }
3522 +@@ -413,7 +413,7 @@
3523 + diff_if_only_endspace_difference= 0;
3524 + #endif
3525 +
3526 +- end= a + (length= min(a_length, b_length));
3527 ++ end= a + (length= MYSQL_MIN(a_length, b_length));
3528 + while (a < end)
3529 + {
3530 + if (*a++ != *b++)
3531 +@@ -452,7 +452,7 @@
3532 + const uchar *src, size_t srclen)
3533 + {
3534 + if (dest != src)
3535 +- memcpy(dest, src, min(dstlen, srclen));
3536 ++ memcpy(dest, src, MYSQL_MIN(dstlen, srclen));
3537 + if (dstlen > srclen)
3538 + bfill(dest + srclen, dstlen - srclen, ' ');
3539 + return dstlen;
3540 +diff -ur mysql-orig/strings/ctype-simple.c mysql/strings/ctype-simple.c
3541 +--- mysql-orig/strings/ctype-simple.c 2012-08-14 01:12:29.723435087 +0000
3542 ++++ mysql/strings/ctype-simple.c 2012-08-14 01:14:59.592196210 +0000
3543 +@@ -161,7 +161,7 @@
3544 + diff_if_only_endspace_difference= 0;
3545 + #endif
3546 +
3547 +- end= a + (length= min(a_length, b_length));
3548 ++ end= a + (length= MYSQL_MIN(a_length, b_length));
3549 + while (a < end)
3550 + {
3551 + if (map[*a++] != map[*b++])
3552 +@@ -875,7 +875,7 @@
3553 + val= new_val;
3554 + }
3555 +
3556 +- len= min(len, (size_t) (e-p));
3557 ++ len= MYSQL_MIN(len, (size_t) (e-p));
3558 + memcpy(dst, p, len);
3559 + return len+sign;
3560 + }
3561 +@@ -929,7 +929,7 @@
3562 + long_val= quo;
3563 + }
3564 +
3565 +- len= min(len, (size_t) (e-p));
3566 ++ len= MYSQL_MIN(len, (size_t) (e-p));
3567 + cnv:
3568 + memcpy(dst, p, len);
3569 + return len+sign;
3570 +@@ -1160,7 +1160,7 @@
3571 + {
3572 + size_t nbytes= (size_t) (end-start);
3573 + *error= 0;
3574 +- return min(nbytes, nchars);
3575 ++ return MYSQL_MIN(nbytes, nchars);
3576 + }
3577 +
3578 +
3579 +diff -ur mysql-orig/strings/ctype-tis620.c mysql/strings/ctype-tis620.c
3580 +--- mysql-orig/strings/ctype-tis620.c 2012-08-14 01:12:29.723435087 +0000
3581 ++++ mysql/strings/ctype-tis620.c 2012-08-14 01:14:59.592196210 +0000
3582 +@@ -583,7 +583,7 @@
3583 + a_length= thai2sortable(a, a_length);
3584 + b_length= thai2sortable(b, b_length);
3585 +
3586 +- end= a + (length= min(a_length, b_length));
3587 ++ end= a + (length= MYSQL_MIN(a_length, b_length));
3588 + while (a < end)
3589 + {
3590 + if (*a++ != *b++)
3591 +@@ -640,7 +640,7 @@
3592 + const uchar *src, size_t srclen)
3593 + {
3594 + size_t dstlen= len;
3595 +- len= (size_t) (strmake((char*) dest, (char*) src, min(len, srclen)) -
3596 ++ len= (size_t) (strmake((char*) dest, (char*) src, MYSQL_MIN(len, srclen)) -
3597 + (char*) dest);
3598 + len= thai2sortable(dest, len);
3599 + if (dstlen > len)
3600 +diff -ur mysql-orig/strings/ctype-uca.c mysql/strings/ctype-uca.c
3601 +--- mysql-orig/strings/ctype-uca.c 2012-08-14 01:12:29.723435087 +0000
3602 ++++ mysql/strings/ctype-uca.c 2012-08-14 01:14:59.592196210 +0000
3603 +@@ -7569,7 +7569,7 @@
3604 + {
3605 + char tail[30];
3606 + size_t len= lexem->end - lexem->prev;
3607 +- strmake (tail, lexem->prev, (size_t) min(len, sizeof(tail)-1));
3608 ++ strmake (tail, lexem->prev, (size_t) MYSQL_MIN(len, sizeof(tail)-1));
3609 + errstr[errsize-1]= '\0';
3610 + my_snprintf(errstr,errsize-1,"%s at '%s'", txt, tail);
3611 + }
3612 +diff -ur mysql-orig/strings/ctype-ucs2.c mysql/strings/ctype-ucs2.c
3613 +--- mysql-orig/strings/ctype-ucs2.c 2012-08-14 01:12:29.723435087 +0000
3614 ++++ mysql/strings/ctype-ucs2.c 2012-08-14 01:14:59.602196128 +0000
3615 +@@ -280,7 +280,7 @@
3616 + se= s + slen;
3617 + te= t + tlen;
3618 +
3619 +- for (minlen= min(slen, tlen); minlen; minlen-= 2)
3620 ++ for (minlen= MYSQL_MIN(slen, tlen); minlen; minlen-= 2)
3621 + {
3622 + int s_wc = uni_plane[s[0]] ? (int) uni_plane[s[0]][s[1]].sort :
3623 + (((int) s[0]) << 8) + (int) s[1];
3624 +@@ -1332,7 +1332,7 @@
3625 + size_t nbytes= ((size_t) (e-b)) & ~(size_t) 1;
3626 + *error= 0;
3627 + nchars*= 2;
3628 +- return min(nbytes, nchars);
3629 ++ return MYSQL_MIN(nbytes, nchars);
3630 + }
3631 +
3632 +
3633 +@@ -1426,7 +1426,7 @@
3634 + se= s + slen;
3635 + te= t + tlen;
3636 +
3637 +- for (minlen= min(slen, tlen); minlen; minlen-= 2)
3638 ++ for (minlen= MYSQL_MIN(slen, tlen); minlen; minlen-= 2)
3639 + {
3640 + int s_wc= s[0] * 256 + s[1];
3641 + int t_wc= t[0] * 256 + t[1];
3642 +@@ -1473,7 +1473,7 @@
3643 + const uchar *src, size_t srclen)
3644 + {
3645 + if (dst != src)
3646 +- memcpy(dst,src,srclen= min(dstlen,srclen));
3647 ++ memcpy(dst,src,srclen= MYSQL_MIN(dstlen,srclen));
3648 + if (dstlen > srclen)
3649 + cs->cset->fill(cs, (char*) dst + srclen, dstlen - srclen, ' ');
3650 + return dstlen;
3651 +diff -ur mysql-orig/strings/ctype-utf8.c mysql/strings/ctype-utf8.c
3652 +--- mysql-orig/strings/ctype-utf8.c 2012-08-14 01:12:29.723435087 +0000
3653 ++++ mysql/strings/ctype-utf8.c 2012-08-14 01:14:59.602196128 +0000
3654 +@@ -2114,7 +2114,7 @@
3655 + const uchar *t, const uchar *te)
3656 + {
3657 + int slen= (int) (se-s), tlen= (int) (te-t);
3658 +- int len=min(slen,tlen);
3659 ++ int len=MYSQL_MIN(slen,tlen);
3660 + int cmp= memcmp(s,t,len);
3661 + return cmp ? cmp : slen-tlen;
3662 + }
3663 +diff -ur mysql-orig/strings/decimal.c mysql/strings/decimal.c
3664 +--- mysql-orig/strings/decimal.c 2012-08-14 01:12:29.723435087 +0000
3665 ++++ mysql/strings/decimal.c 2012-08-14 01:14:59.602196128 +0000
3666 +@@ -405,7 +405,7 @@
3667 + for (; frac>0; frac-=DIG_PER_DEC1)
3668 + {
3669 + dec1 x=*buf++;
3670 +- for (i=min(frac, DIG_PER_DEC1); i; i--)
3671 ++ for (i=MYSQL_MIN(frac, DIG_PER_DEC1); i; i--)
3672 + {
3673 + dec1 y=x/DIG_MASK;
3674 + *s1++='0'+(uchar)y;
3675 +@@ -428,7 +428,7 @@
3676 + for (buf=buf0+ROUND_UP(intg); intg>0; intg-=DIG_PER_DEC1)
3677 + {
3678 + dec1 x=*--buf;
3679 +- for (i=min(intg, DIG_PER_DEC1); i; i--)
3680 ++ for (i=MYSQL_MIN(intg, DIG_PER_DEC1); i; i--)
3681 + {
3682 + dec1 y=x/10;
3683 + *--s='0'+(uchar)(x-y*10);
3684 +@@ -1531,8 +1531,8 @@
3685 +
3686 + if (to != from)
3687 + {
3688 +- dec1 *p0= buf0+intg0+max(frac1, frac0);
3689 +- dec1 *p1= buf1+intg0+max(frac1, frac0);
3690 ++ dec1 *p0= buf0+intg0+MYSQL_MAX(frac1, frac0);
3691 ++ dec1 *p1= buf1+intg0+MYSQL_MAX(frac1, frac0);
3692 +
3693 + DBUG_ASSERT(p0 - buf0 <= len);
3694 + DBUG_ASSERT(p1 - buf1 <= len);
3695 +@@ -1543,7 +1543,7 @@
3696 + buf0=to->buf;
3697 + buf1=to->buf;
3698 + to->sign=from->sign;
3699 +- to->intg=min(intg0, len)*DIG_PER_DEC1;
3700 ++ to->intg=MYSQL_MIN(intg0, len)*DIG_PER_DEC1;
3701 + }
3702 +
3703 + if (frac0 > frac1)
3704 +@@ -1645,7 +1645,7 @@
3705 + scale=frac0*DIG_PER_DEC1;
3706 + error=E_DEC_TRUNCATED; /* XXX */
3707 + }
3708 +- for (buf1=to->buf+intg0+max(frac0,0); buf1 > to->buf; buf1--)
3709 ++ for (buf1=to->buf+intg0+MYSQL_MAX(frac0,0); buf1 > to->buf; buf1--)
3710 + {
3711 + buf1[0]=buf1[-1];
3712 + }
3713 +@@ -1664,7 +1664,7 @@
3714 + /* making 'zero' with the proper scale */
3715 + dec1 *p0= to->buf + frac0 + 1;
3716 + to->intg=1;
3717 +- to->frac= max(scale, 0);
3718 ++ to->frac= MYSQL_MAX(scale, 0);
3719 + to->sign= 0;
3720 + for (buf1= to->buf; buf1<p0; buf1++)
3721 + *buf1= 0;
3722 +@@ -1713,11 +1713,11 @@
3723 + {
3724 + switch (op) {
3725 + case '-':
3726 +- return ROUND_UP(max(from1->intg, from2->intg)) +
3727 +- ROUND_UP(max(from1->frac, from2->frac));
3728 ++ return ROUND_UP(MYSQL_MAX(from1->intg, from2->intg)) +
3729 ++ ROUND_UP(MYSQL_MAX(from1->frac, from2->frac));
3730 + case '+':
3731 +- return ROUND_UP(max(from1->intg, from2->intg)+1) +
3732 +- ROUND_UP(max(from1->frac, from2->frac));
3733 ++ return ROUND_UP(MYSQL_MAX(from1->intg, from2->intg)+1) +
3734 ++ ROUND_UP(MYSQL_MAX(from1->frac, from2->frac));
3735 + case '*':
3736 + return ROUND_UP(from1->intg+from2->intg)+
3737 + ROUND_UP(from1->frac)+ROUND_UP(from2->frac);
3738 +@@ -1732,7 +1732,7 @@
3739 + {
3740 + int intg1=ROUND_UP(from1->intg), intg2=ROUND_UP(from2->intg),
3741 + frac1=ROUND_UP(from1->frac), frac2=ROUND_UP(from2->frac),
3742 +- frac0=max(frac1, frac2), intg0=max(intg1, intg2), error;
3743 ++ frac0=MYSQL_MAX(frac1, frac2), intg0=MYSQL_MAX(intg1, intg2), error;
3744 + dec1 *buf1, *buf2, *buf0, *stop, *stop2, x, carry;
3745 +
3746 + sanity(to);
3747 +@@ -1757,7 +1757,7 @@
3748 + buf0=to->buf+intg0+frac0;
3749 +
3750 + to->sign=from1->sign;
3751 +- to->frac=max(from1->frac, from2->frac);
3752 ++ to->frac=MYSQL_MAX(from1->frac, from2->frac);
3753 + to->intg=intg0*DIG_PER_DEC1;
3754 + if (unlikely(error))
3755 + {
3756 +@@ -1768,7 +1768,7 @@
3757 + set_if_smaller(intg2, intg0);
3758 + }
3759 +
3760 +- /* part 1 - max(frac) ... min (frac) */
3761 ++ /* part 1 - MYSQL_MAX(frac) ... MYSQL_MIN(frac) */
3762 + if (frac1 > frac2)
3763 + {
3764 + buf1=from1->buf+intg1+frac1;
3765 +@@ -1786,14 +1786,14 @@
3766 + while (buf1 > stop)
3767 + *--buf0=*--buf1;
3768 +
3769 +- /* part 2 - min(frac) ... min(intg) */
3770 ++ /* part 2 - MYSQL_MIN(frac) ... MYSQL_MIN(intg) */
3771 + carry=0;
3772 + while (buf1 > stop2)
3773 + {
3774 + ADD(*--buf0, *--buf1, *--buf2, carry);
3775 + }
3776 +
3777 +- /* part 3 - min(intg) ... max(intg) */
3778 ++ /* part 3 - MYSQL_MIN(intg) ... MYSQL_MAX(intg) */
3779 + buf1= intg1 > intg2 ? ((stop=from1->buf)+intg1-intg2) :
3780 + ((stop=from2->buf)+intg2-intg1) ;
3781 + while (buf1 > stop)
3782 +@@ -1814,7 +1814,7 @@
3783 + {
3784 + int intg1=ROUND_UP(from1->intg), intg2=ROUND_UP(from2->intg),
3785 + frac1=ROUND_UP(from1->frac), frac2=ROUND_UP(from2->frac);
3786 +- int frac0=max(frac1, frac2), error;
3787 ++ int frac0=MYSQL_MAX(frac1, frac2), error;
3788 + dec1 *buf1, *buf2, *buf0, *stop1, *stop2, *start1, *start2, carry=0;
3789 +
3790 + /* let carry:=1 if from2 > from1 */
3791 +@@ -1889,7 +1889,7 @@
3792 + FIX_INTG_FRAC_ERROR(to->len, intg1, frac0, error);
3793 + buf0=to->buf+intg1+frac0;
3794 +
3795 +- to->frac=max(from1->frac, from2->frac);
3796 ++ to->frac=MYSQL_MAX(from1->frac, from2->frac);
3797 + to->intg=intg1*DIG_PER_DEC1;
3798 + if (unlikely(error))
3799 + {
3800 +@@ -1900,7 +1900,7 @@
3801 + }
3802 + carry=0;
3803 +
3804 +- /* part 1 - max(frac) ... min (frac) */
3805 ++ /* part 1 - MYSQL_MAX(frac) ... MYSQL_MIN (frac) */
3806 + if (frac1 > frac2)
3807 + {
3808 + buf1=start1+intg1+frac1;
3809 +@@ -1924,7 +1924,7 @@
3810 + }
3811 + }
3812 +
3813 +- /* part 2 - min(frac) ... intg2 */
3814 ++ /* part 2 - MYSQL_MIN(frac) ... intg2 */
3815 + while (buf2 > start2)
3816 + {
3817 + SUB(*--buf0, *--buf1, *--buf2, carry);
3818 +@@ -2187,11 +2187,11 @@
3819 + {
3820 + /* we're calculating N1 % N2.
3821 + The result will have
3822 +- frac=max(frac1, frac2), as for subtraction
3823 ++ frac=MYSQL_MAX(frac1, frac2), as for subtraction
3824 + intg=intg2
3825 + */
3826 + to->sign=from1->sign;
3827 +- to->frac=max(from1->frac, from2->frac);
3828 ++ to->frac=MYSQL_MAX(from1->frac, from2->frac);
3829 + frac0=0;
3830 + }
3831 + else
3832 +@@ -2315,7 +2315,7 @@
3833 + /*
3834 + now the result is in tmp1, it has
3835 + intg=prec1-frac1
3836 +- frac=max(frac1, frac2)=to->frac
3837 ++ frac=MYSQL_MAX(frac1, frac2)=to->frac
3838 + */
3839 + if (dcarry)
3840 + *--start1=dcarry;
3841 +@@ -2353,7 +2353,7 @@
3842 + }
3843 + DBUG_ASSERT(intg0 <= ROUND_UP(from2->intg));
3844 + stop1=start1+frac0+intg0;
3845 +- to->intg=min(intg0*DIG_PER_DEC1, from2->intg);
3846 ++ to->intg=MYSQL_MIN(intg0*DIG_PER_DEC1, from2->intg);
3847 + }
3848 + if (unlikely(intg0+frac0 > to->len))
3849 + {
3850 +diff -ur mysql-orig/strings/my_vsnprintf.c mysql/strings/my_vsnprintf.c
3851 +--- mysql-orig/strings/my_vsnprintf.c 2012-08-14 01:12:29.723435087 +0000
3852 ++++ mysql/strings/my_vsnprintf.c 2012-08-14 01:14:59.602196128 +0000
3853 +@@ -143,7 +143,7 @@
3854 + /* If %#d syntax was used, we have to pre-zero/pre-space the string */
3855 + if (store_start == buff)
3856 + {
3857 +- length= min(length, to_length);
3858 ++ length= MYSQL_MIN(length, to_length);
3859 + if (res_length < length)
3860 + {
3861 + size_t diff= (length- res_length);
3862 +diff -ur mysql-orig/strings/str2int.c mysql/strings/str2int.c
3863 +--- mysql-orig/strings/str2int.c 2012-08-14 01:12:29.723435087 +0000
3864 ++++ mysql/strings/str2int.c 2012-08-14 01:14:59.602196128 +0000
3865 +@@ -84,7 +84,7 @@
3866 + machines all, if +|n| is representable, so is -|n|, but on
3867 + twos complement machines the converse is not true. So the
3868 + "maximum" representable number has a negative representative.
3869 +- Limit is set to min(-|lower|,-|upper|); this is the "largest"
3870 ++ Limit is set to MYSQL_MIN(-|lower|,-|upper|); this is the "largest"
3871 + number we are concerned with. */
3872 +
3873 + /* Calculate Limit using Scale as a scratch variable */
3874 +diff -ur mysql-orig/vio/viosocket.c mysql/vio/viosocket.c
3875 +--- mysql-orig/vio/viosocket.c 2012-08-14 01:12:29.723435087 +0000
3876 ++++ mysql/vio/viosocket.c 2012-08-14 01:14:59.602196128 +0000
3877 +@@ -79,7 +79,7 @@
3878 +
3879 + if (vio->read_pos < vio->read_end)
3880 + {
3881 +- rc= min((size_t) (vio->read_end - vio->read_pos), size);
3882 ++ rc= MYSQL_MIN((size_t) (vio->read_end - vio->read_pos), size);
3883 + memcpy(buf, vio->read_pos, rc);
3884 + vio->read_pos+= rc;
3885 + /*