1
/*****************************************************************************
3
Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
4
Copyright (c) 2008, Google Inc.
5
Copyright (c) 2009, Sun Microsystems, Inc.
7
Portions of this file contain modifications contributed and copyrighted by
8
Google, Inc. Those modifications are gratefully acknowledged and are described
9
briefly in the InnoDB documentation. The contributions by Google are
10
incorporated with their permission, and subject to the conditions contained in
11
the file COPYING.Google.
13
Portions of this file contain modifications contributed and copyrighted by
14
Sun Microsystems, Inc. Those modifications are gratefully acknowledged and
15
are described briefly in the InnoDB documentation. The contributions by
16
Sun Microsystems are incorporated with their permission, and subject to the
17
conditions contained in the file COPYING.Sun_Microsystems.
19
This program is free software; you can redistribute it and/or modify it under
20
the terms of the GNU General Public License as published by the Free Software
21
Foundation; version 2 of the License.
23
This program is distributed in the hope that it will be useful, but WITHOUT
24
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
25
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
27
You should have received a copy of the GNU General Public License along with
28
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
29
Place, Suite 330, Boston, MA 02111-1307 USA
31
*****************************************************************************/
33
/***********************************************************************//**
35
Version control for database, common definitions, and include files
37
Created 1/20/1994 Heikki Tuuri
38
****************************************************************************/
51
#endif /* UNIV_HOTBACKUP */
53
#define INNODB_VERSION_MAJOR 1
54
#define INNODB_VERSION_MINOR 0
55
#define INNODB_VERSION_BUGFIX 4
57
/* The following is the InnoDB version as shown in
58
SELECT plugin_version FROM information_schema.plugins;
59
calculated in in make_version_string() in sql/sql_show.cc like this:
60
"version >> 8" . "version & 0xff"
61
because the version is shown with only one dot, we skip the last
62
component, i.e. we show M.N.P as M.N */
63
#define INNODB_VERSION_SHORT \
64
(INNODB_VERSION_MAJOR << 8 | INNODB_VERSION_MINOR)
66
/* auxiliary macros to help creating the version as string */
67
#define __INNODB_VERSION(a, b, c) (#a "." #b "." #c)
68
#define _INNODB_VERSION(a, b, c) __INNODB_VERSION(a, b, c)
70
#define INNODB_VERSION_STR \
71
_INNODB_VERSION(INNODB_VERSION_MAJOR, \
72
INNODB_VERSION_MINOR, \
73
INNODB_VERSION_BUGFIX)
75
#define REFMAN "http://dev.mysql.com/doc/refman/5.1/en/"
77
#ifdef MYSQL_DYNAMIC_PLUGIN
78
/* In the dynamic plugin, redefine some externally visible symbols
79
in order not to conflict with the symbols of a builtin InnoDB. */
81
/* Rename all C++ classes that contain virtual functions, because we
82
have not figured out how to apply the visibility=hidden attribute to
83
the virtual method table (vtable) in GCC 3. */
84
# define ha_innobase ha_innodb
85
#endif /* MYSQL_DYNAMIC_PLUGIN */
87
#if (defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)) && !defined(MYSQL_SERVER) && !defined(__WIN__)
93
# if defined(HAVE_WINDOWS_ATOMICS)
94
/* If atomics are defined we use them in InnoDB mutex implementation */
95
# define HAVE_ATOMIC_BUILTINS
96
# endif /* HAVE_WINDOWS_ATOMICS */
103
/* The defines used with MySQL */
105
/* Include two header files from MySQL to make the Unix flavor used
106
in compiling more Posix-compatible. These headers also define __WIN__
107
if we are compiling on Windows. */
109
# if !defined(BUILD_DRIZZLE)
110
# ifndef UNIV_HOTBACKUP
111
# include <my_global.h>
112
# include <my_pthread.h>
113
# endif /* UNIV_HOTBACKUP */
116
/* Include <sys/stat.h> to get S_I... macros defined for os0file.c */
117
# include <sys/stat.h>
118
# if !defined(__NETWARE__) && !defined(__WIN__)
119
# include <sys/mman.h> /* mmap() for os0proc.c */
125
/* Include the header file generated by GNU autoconf */
126
# if !defined(__WIN__) && !defined(BUILD_DRIZZLE)
127
# ifndef UNIV_HOTBACKUP
129
# endif /* UNIV_HOTBACKUP */
136
# if defined(HAVE_GCC_ATOMIC_BUILTINS) || defined(HAVE_SOLARIS_ATOMICS) \
137
|| defined(HAVE_WINDOWS_ATOMICS)
138
/* If atomics are defined we use them in InnoDB mutex implementation */
139
# define HAVE_ATOMIC_BUILTINS
140
# endif /* (HAVE_GCC_ATOMIC_BUILTINS) || (HAVE_SOLARIS_ATOMICS)
141
|| (HAVE_WINDOWS_ATOMICS) */
143
/* For InnoDB rw_locks to work with atomics we need the thread_id
144
to be no more than machine word wide. The following enables using
145
atomics for InnoDB rw_locks where these conditions are met. */
146
#ifdef HAVE_ATOMIC_BUILTINS
147
/* if HAVE_ATOMIC_PTHREAD_T is defined at this point that means that
148
the code from plug.in has defined it and we do not need to include
149
ut0auxconf.h which would either define HAVE_ATOMIC_PTHREAD_T or will
151
# ifndef HAVE_ATOMIC_PTHREAD_T
152
# include "ut0auxconf.h"
153
# endif /* HAVE_ATOMIC_PTHREAD_T */
154
/* now HAVE_ATOMIC_PTHREAD_T is eventually defined either by plug.in or
155
from Makefile.in->ut0auxconf.h */
156
# ifdef HAVE_ATOMIC_PTHREAD_T
157
# define INNODB_RW_LOCKS_USE_ATOMICS
158
# endif /* HAVE_ATOMIC_PTHREAD_T */
159
#endif /* HAVE_ATOMIC_BUILTINS */
161
/* We only try to do explicit inlining of functions with gcc and
164
# if !defined(__GNUC__) && !(defined(__SUNPRO_C) || defined(__SUNPRO_CC))
165
# undef UNIV_MUST_NOT_INLINE /* Remove compiler warning */
166
# define UNIV_MUST_NOT_INLINE
173
#endif /* #if (defined(WIN32) || ... */
175
/* DEBUG VERSION CONTROL
176
===================== */
178
/* The following flag will make InnoDB to initialize
179
all memory it allocates to zero. It hides Purify
180
warnings about reading unallocated memory unless
181
memory is read outside the allocated blocks. */
183
#define UNIV_INIT_MEM_TO_ZERO
186
/* When this macro is defined then additional test functions will be
187
compiled. These functions live at the end of each relevant source file
188
and have "test_" prefix. These functions are not called from anywhere in
189
the code, they can be called from gdb after
190
innobase_start_or_create_for_mysql() has executed using the call
191
command. Not tested on Windows. */
193
#define UNIV_COMPILE_TEST_FUNCS
197
#define UNIV_DEBUG_VALGRIND /* Enable extra
198
Valgrind instrumentation */
199
#define UNIV_DEBUG_PRINT /* Enable the compilation of
200
some debug print functions */
201
#define UNIV_AHI_DEBUG /* Enable adaptive hash index
202
debugging without UNIV_DEBUG */
203
#define UNIV_BUF_DEBUG /* Enable buffer pool
204
debugging without UNIV_DEBUG */
205
#define UNIV_DEBUG /* Enable ut_ad() assertions
206
and disable UNIV_INLINE */
207
#define UNIV_DEBUG_FILE_ACCESSES /* Debug .ibd file access
208
(field file_page_was_freed
210
#define UNIV_LRU_DEBUG /* debug the buffer pool LRU */
211
#define UNIV_HASH_DEBUG /* debug HASH_ macros */
212
#define UNIV_LIST_DEBUG /* debug UT_LIST_ macros */
213
#define UNIV_MEM_DEBUG /* detect memory leaks etc */
214
#define UNIV_IBUF_DEBUG /* debug the insert buffer */
215
#define UNIV_IBUF_COUNT_DEBUG /* debug the insert buffer;
216
this limits the database to IBUF_COUNT_N_SPACES and IBUF_COUNT_N_PAGES,
217
and the insert buffer must be empty when the database is started */
218
#define UNIV_SYNC_DEBUG /* debug mutex and latch
219
operations (very slow); also UNIV_DEBUG must be defined */
220
#define UNIV_SEARCH_DEBUG /* debug B-tree comparisons */
221
#define UNIV_SYNC_PERF_STAT /* operation counts for
222
rw-locks and mutexes */
223
#define UNIV_SEARCH_PERF_STAT /* statistics for the
224
adaptive hash index */
225
#define UNIV_SRV_PRINT_LATCH_WAITS /* enable diagnostic output
227
#define UNIV_BTR_PRINT /* enable functions for
229
#define UNIV_ZIP_DEBUG /* extensive consistency checks
230
for compressed pages */
231
#define UNIV_ZIP_COPY /* call page_zip_copy_recs()
235
#define UNIV_BTR_DEBUG /* check B-tree links */
236
#define UNIV_LIGHT_MEM_DEBUG /* light memory debugging */
239
/* The following sets all new allocated memory to zero before use:
240
this can be used to eliminate unnecessary Purify warnings, but note that
241
it also masks many bugs Purify could detect. For detailed Purify analysis it
242
is best to remove the define below and look through the warnings one
244
#define UNIV_SET_MEM_TO_ZERO
248
#define UNIV_SQL_DEBUG
249
#define UNIV_LOG_DEBUG
251
/* the above option prevents forcing of log to disk
252
at a buffer page write: it should be tested with this
253
option off; also some ibuf tests are suppressed */
255
#define UNIV_BASIC_LOG_DEBUG
257
/* the above option enables basic recovery debugging:
258
new allocated file pages are reset */
260
/* Linkage specifier for non-static InnoDB symbols (variables and functions)
261
that are only referenced from within InnoDB, not from MySQL */
262
#if defined(HAVE_ATTR_HIDDEN)
263
# define UNIV_INTERN __attribute__((visibility ("hidden")))
268
#if (!defined(UNIV_DEBUG) && !defined(UNIV_MUST_NOT_INLINE))
269
/* Definition for inline version */
272
# define UNIV_INLINE __inline
273
#elif defined(__SUNPRO_CC) || defined(__SUNPRO_C)
274
# define UNIV_INLINE static inline
276
# define UNIV_INLINE static __inline__
280
/* If we want to compile a noninlined version we use the following macro
284
#define UNIV_INLINE UNIV_INTERN
286
#endif /* UNIV_DEBUG */
289
#define UNIV_WORD_SIZE 4
290
#elif defined(_WIN64)
291
#define UNIV_WORD_SIZE 8
293
/* MySQL config.h generated by GNU autoconf will define SIZEOF_LONG in Posix */
294
#define UNIV_WORD_SIZE SIZEOF_LONG
297
/* The following alignment is used in memory allocations in memory heap
298
management to ensure correct alignment for doubles etc. */
299
#define UNIV_MEM_ALIGNMENT 8
301
/* The following alignment is used in aligning lints etc. */
302
#define UNIV_WORD_ALIGNMENT UNIV_WORD_SIZE
305
DATABASE VERSION CONTROL
306
========================
309
/* The 2-logarithm of UNIV_PAGE_SIZE: */
310
#define UNIV_PAGE_SIZE_SHIFT 14
311
/* The universal page size of the database */
312
#define UNIV_PAGE_SIZE (1 << UNIV_PAGE_SIZE_SHIFT)
314
/* Maximum number of parallel threads in a parallelized operation */
315
#define UNIV_MAX_PARALLELISM 32
318
UNIVERSAL TYPE DEFINITIONS
319
==========================
322
/* Note that inside MySQL 'byte' is defined as char on Linux! */
323
#define byte unsigned char
325
/* Define an unsigned integer type that is exactly 32 bits. */
328
typedef unsigned int ib_uint32_t;
329
#elif SIZEOF_LONG == 4
330
typedef unsigned long ib_uint32_t;
332
#error "Neither int or long is 4 bytes"
335
/* Another basic type we use is unsigned long integer which should be equal to
336
the word size of the machine, that is on a 32-bit platform 32 bits, and on a
337
64-bit platform 64 bits. We also give the printf format for the type as a
341
typedef unsigned __int64 ulint;
342
#define ULINTPF "%I64u"
343
typedef __int64 lint;
345
typedef unsigned long int ulint;
346
#define ULINTPF "%lu"
347
typedef long int lint;
351
typedef __int64 ib_int64_t;
352
typedef unsigned __int64 ib_uint64_t;
353
#elif !defined(UNIV_HOTBACKUP)
354
/* Note: longlong and ulonglong come from MySQL headers. */
355
# if defined(BUILD_DRIZZLE)
356
typedef int64_t ib_int64_t;
357
typedef uint64_t ib_uint64_t;
358
typedef uint16_t uint16;
359
typedef bool my_bool;
360
typedef uint32_t uint32;
362
typedef longlong ib_int64_t;
363
typedef ulonglong ib_uint64_t;
368
#ifndef UNIV_HOTBACKUP
369
typedef unsigned long long int ullint;
370
#endif /* UNIV_HOTBACKUP */
373
#if SIZEOF_LONG != SIZEOF_VOIDP
374
#error "Error: InnoDB's ulint must be of the same size as void*"
378
/* The 'undefined' value for a ulint */
379
#define ULINT_UNDEFINED ((ulint)(-1))
381
/* The undefined 32-bit unsigned integer */
382
#define ULINT32_UNDEFINED 0xFFFFFFFF
384
/* Maximum value for a ulint */
385
#define ULINT_MAX ((ulint)(-2))
387
/* Maximum value for ib_uint64_t */
388
#define IB_ULONGLONG_MAX ((ib_uint64_t) (~0ULL))
390
/* This 'ibool' type is used within Innobase. Remember that different included
391
headers may define 'bool' differently. Do not assume that 'bool' is a ulint! */
401
/* The following number as the length of a logical field means that the field
402
has the SQL NULL as its value. NOTE that because we assume that the length
403
of a field is a 32-bit integer when we store it, for example, to an undo log
404
on disk, we must have also this number fit in 32 bits, also in 64-bit
407
#define UNIV_SQL_NULL ULINT32_UNDEFINED
409
/* Lengths which are not UNIV_SQL_NULL, but bigger than the following
410
number indicate that a field contains a reference to an externally
411
stored part of the field in the tablespace. The length field then
412
contains the sum of the following flag and the locally stored len. */
414
#define UNIV_EXTERN_STORAGE_FIELD (UNIV_SQL_NULL - UNIV_PAGE_SIZE)
416
/* Some macros to improve branch prediction and reduce cache misses */
417
#if defined(__GNUC__) && (__GNUC__ > 2) && ! defined(__INTEL_COMPILER)
418
/* Tell the compiler that 'expr' probably evaluates to 'constant'. */
419
# define UNIV_EXPECT(expr,constant) __builtin_expect(expr, constant)
420
/* Tell the compiler that a pointer is likely to be NULL */
421
# define UNIV_LIKELY_NULL(ptr) __builtin_expect((ulint) ptr, 0)
422
/* Minimize cache-miss latency by moving data at addr into a cache before
424
# define UNIV_PREFETCH_R(addr) __builtin_prefetch(addr, 0, 3)
425
/* Minimize cache-miss latency by moving data at addr into a cache before
426
it is read or written. */
427
# define UNIV_PREFETCH_RW(addr) __builtin_prefetch(addr, 1, 3)
428
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
429
# include <sun_prefetch.h>
430
#if __SUNPRO_C >= 0x550
432
# define UNIV_INTERN __hidden
433
#endif /* __SUNPRO_C >= 0x550 */
434
/* Use sun_prefetch when compile with Sun Studio */
435
# define UNIV_EXPECT(expr,value) (expr)
436
# define UNIV_LIKELY_NULL(expr) (expr)
437
# define UNIV_PREFETCH_R(addr) sun_prefetch_read_many((void *)(addr))
438
# define UNIV_PREFETCH_RW(addr) sun_prefetch_write_many((void *)(addr))
440
/* Dummy versions of the macros */
441
# define UNIV_EXPECT(expr,value) (expr)
442
# define UNIV_LIKELY_NULL(expr) (expr)
443
# define UNIV_PREFETCH_R(addr) ((void) 0)
444
# define UNIV_PREFETCH_RW(addr) ((void) 0)
446
/* Tell the compiler that cond is likely to hold */
447
#define UNIV_LIKELY(cond) UNIV_EXPECT(cond, TRUE)
448
/* Tell the compiler that cond is unlikely to hold */
449
#define UNIV_UNLIKELY(cond) UNIV_EXPECT(cond, FALSE)
451
/* Compile-time constant of the given array's size. */
452
#define UT_ARR_SIZE(a) (sizeof(a) / sizeof((a)[0]))
454
/* The return type from a thread's start function differs between Unix and
455
Windows, so define a typedef for it and a macro to use at the end of such
459
typedef ulint os_thread_ret_t;
460
#define OS_THREAD_DUMMY_RETURN return(0)
462
typedef void* os_thread_ret_t;
463
#define OS_THREAD_DUMMY_RETURN return(NULL)
470
#ifdef UNIV_DEBUG_VALGRIND
471
# include <valgrind/memcheck.h>
472
# define UNIV_MEM_VALID(addr, size) VALGRIND_MAKE_MEM_DEFINED(addr, size)
473
# define UNIV_MEM_INVALID(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size)
474
# define UNIV_MEM_FREE(addr, size) VALGRIND_MAKE_MEM_NOACCESS(addr, size)
475
# define UNIV_MEM_ALLOC(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size)
476
# define UNIV_MEM_DESC(addr, size, b) VALGRIND_CREATE_BLOCK(addr, size, b)
477
# define UNIV_MEM_UNDESC(b) VALGRIND_DISCARD(b)
478
# define UNIV_MEM_ASSERT_RW(addr, size) do { \
479
const void* _p = (const void*) (ulint) \
480
VALGRIND_CHECK_MEM_IS_DEFINED(addr, size); \
481
if (UNIV_LIKELY_NULL(_p)) \
482
fprintf(stderr, "%s:%d: %p[%u] undefined at %ld\n", \
483
__FILE__, __LINE__, \
484
(const void*) (addr), (unsigned) (size), (long) \
485
(((const char*) _p) - ((const char*) (addr)))); \
487
# define UNIV_MEM_ASSERT_W(addr, size) do { \
488
const void* _p = (const void*) (ulint) \
489
VALGRIND_CHECK_MEM_IS_ADDRESSABLE(addr, size); \
490
if (UNIV_LIKELY_NULL(_p)) \
491
fprintf(stderr, "%s:%d: %p[%u] unwritable at %ld\n", \
492
__FILE__, __LINE__, \
493
(const void*) (addr), (unsigned) (size), (long) \
494
(((const char*) _p) - ((const char*) (addr)))); \
497
# define UNIV_MEM_VALID(addr, size) do {} while(0)
498
# define UNIV_MEM_INVALID(addr, size) do {} while(0)
499
# define UNIV_MEM_FREE(addr, size) do {} while(0)
500
# define UNIV_MEM_ALLOC(addr, size) do {} while(0)
501
# define UNIV_MEM_DESC(addr, size, b) do {} while(0)
502
# define UNIV_MEM_UNDESC(b) do {} while(0)
503
# define UNIV_MEM_ASSERT_RW(addr, size) do {} while(0)
504
# define UNIV_MEM_ASSERT_W(addr, size) do {} while(0)
506
#define UNIV_MEM_ASSERT_AND_FREE(addr, size) do { \
507
UNIV_MEM_ASSERT_W(addr, size); \
508
UNIV_MEM_FREE(addr, size); \
510
#define UNIV_MEM_ASSERT_AND_ALLOC(addr, size) do { \
511
UNIV_MEM_ASSERT_W(addr, size); \
512
UNIV_MEM_ALLOC(addr, size); \