mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / innodb_plugin / include / univ.i
blob287e77fd8cec6d0510c03105dd47d5818583b539
1 /*****************************************************************************
3 Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
4 Copyright (c) 2008, Google Inc.
6 Portions of this file contain modifications contributed and copyrighted by
7 Google, Inc. Those modifications are gratefully acknowledged and are described
8 briefly in the InnoDB documentation. The contributions by Google are
9 incorporated with their permission, and subject to the conditions contained in
10 the file COPYING.Google.
12 Portions of this file contain modifications contributed and copyrighted by
13 Sun Microsystems, Inc. Those modifications are gratefully acknowledged and
14 are described briefly in the InnoDB documentation. The contributions by
15 Sun Microsystems are incorporated with their permission, and subject to the
16 conditions contained in the file COPYING.Sun_Microsystems.
18 This program is free software; you can redistribute it and/or modify it under
19 the terms of the GNU General Public License as published by the Free Software
20 Foundation; version 2 of the License.
22 This program is distributed in the hope that it will be useful, but WITHOUT
23 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
24 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License along with
27 this program; if not, write to the Free Software Foundation, Inc.,
28 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 *****************************************************************************/
32 /***********************************************************************//**
33 @file include/univ.i
34 Version control for database, common definitions, and include files
36 Created 1/20/1994 Heikki Tuuri
37 ****************************************************************************/
39 #ifndef univ_i
40 #define univ_i
42 #ifdef UNIV_HOTBACKUP
43 #include "hb_univ.i"
44 #endif /* UNIV_HOTBACKUP */
46 #include <mysql_version.h>
48 /* Set InnoDB Plugin version to be the same as the MySQL server version.
49 MYSQL_VERSION_ID is something like 50168. */
50 #define INNODB_VERSION_MAJOR (MYSQL_VERSION_ID / 10000)
51 #define INNODB_VERSION_MINOR (MYSQL_VERSION_ID / 100 % 100)
53 /* The following is the InnoDB version as shown in
54 SELECT plugin_version FROM information_schema.plugins;
55 calculated in make_version_string() in sql/sql_show.cc like this:
56 "version >> 8" . "version & 0xff"
57 because the version is shown with only one dot, we skip the last
58 component, i.e. we show M.N.P as M.N */
59 #define INNODB_VERSION_SHORT \
60 (INNODB_VERSION_MAJOR << 8 | INNODB_VERSION_MINOR)
62 #define INNODB_VERSION_STR MYSQL_SERVER_VERSION
64 #define REFMAN "http://dev.mysql.com/doc/refman/5.1/en/"
66 #ifdef MYSQL_DYNAMIC_PLUGIN
67 /* In the dynamic plugin, redefine some externally visible symbols
68 in order not to conflict with the symbols of a builtin InnoDB. */
70 /* Rename all C++ classes that contain virtual functions, because we
71 have not figured out how to apply the visibility=hidden attribute to
72 the virtual method table (vtable) in GCC 3. */
73 # define ha_innobase ha_innodb
74 #endif /* MYSQL_DYNAMIC_PLUGIN */
76 /* if any of the following macros is defined at this point this means
77 that the code from the "right" plug.in was executed and we do not
78 need to include ut0auxconf.h which would either define the same macros
79 or will be empty */
80 #if !defined(HAVE_IB_GCC_ATOMIC_BUILTINS) \
81 && !defined(HAVE_IB_ATOMIC_PTHREAD_T_GCC) \
82 && !defined(HAVE_IB_SOLARIS_ATOMICS) \
83 && !defined(HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS) \
84 && !defined(SIZEOF_PTHREAD_T) \
85 && !defined(HAVE_IB_PAUSE_INSTRUCTION)
86 # include "ut0auxconf.h"
87 #endif
89 #if (defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)) && !defined(MYSQL_SERVER) && !defined(__WIN__)
90 # undef __WIN__
91 # define __WIN__
93 # include <windows.h>
95 # ifdef _NT_
96 # define __NT__
97 # endif
99 #else
100 /* The defines used with MySQL */
102 /* Include two header files from MySQL to make the Unix flavor used
103 in compiling more Posix-compatible. These headers also define __WIN__
104 if we are compiling on Windows. */
106 #ifndef UNIV_HOTBACKUP
107 # include <my_global.h>
108 # include <my_pthread.h>
109 #endif /* UNIV_HOTBACKUP */
111 /* Include <sys/stat.h> to get S_I... macros defined for os0file.c */
112 # include <sys/stat.h>
113 # if !defined(__NETWARE__) && !defined(__WIN__)
114 # include <sys/mman.h> /* mmap() for os0proc.c */
115 # endif
117 /* Include the header file generated by GNU autoconf */
118 # ifndef __WIN__
119 # ifndef UNIV_HOTBACKUP
120 # include "config.h"
121 # endif /* UNIV_HOTBACKUP */
122 # endif
124 # ifdef HAVE_SCHED_H
125 # include <sched.h>
126 # endif
128 /* We only try to do explicit inlining of functions with gcc and
129 Sun Studio */
131 # if !defined(__GNUC__) && !(defined(__SUNPRO_C) || defined(__SUNPRO_CC))
132 # undef UNIV_MUST_NOT_INLINE /* Remove compiler warning */
133 # define UNIV_MUST_NOT_INLINE
134 # endif
136 # ifdef HAVE_PREAD
137 # define HAVE_PWRITE
138 # endif
140 #endif /* #if (defined(WIN32) || ... */
142 /* DEBUG VERSION CONTROL
143 ===================== */
145 /* When this macro is defined then additional test functions will be
146 compiled. These functions live at the end of each relevant source file
147 and have "test_" prefix. These functions are not called from anywhere in
148 the code, they can be called from gdb after
149 innobase_start_or_create_for_mysql() has executed using the call
150 command. Not tested on Windows. */
152 #define UNIV_COMPILE_TEST_FUNCS
155 #if defined HAVE_VALGRIND
156 # define UNIV_DEBUG_VALGRIND
157 #endif /* HAVE_VALGRIND */
158 #if 0
159 #define UNIV_DEBUG_VALGRIND /* Enable extra
160 Valgrind instrumentation */
161 #define UNIV_DEBUG_PRINT /* Enable the compilation of
162 some debug print functions */
163 #define UNIV_AHI_DEBUG /* Enable adaptive hash index
164 debugging without UNIV_DEBUG */
165 #define UNIV_BUF_DEBUG /* Enable buffer pool
166 debugging without UNIV_DEBUG */
167 #define UNIV_BLOB_LIGHT_DEBUG /* Enable off-page column
168 debugging without UNIV_DEBUG */
169 #define UNIV_DEBUG /* Enable ut_ad() assertions
170 and disable UNIV_INLINE */
171 #define UNIV_DEBUG_LOCK_VALIDATE /* Enable
172 ut_ad(lock_rec_validate_page())
173 assertions. */
174 #define UNIV_DEBUG_FILE_ACCESSES /* Enable freed block access
175 debugging without UNIV_DEBUG */
176 #define UNIV_LRU_DEBUG /* debug the buffer pool LRU */
177 #define UNIV_HASH_DEBUG /* debug HASH_ macros */
178 #define UNIV_LIST_DEBUG /* debug UT_LIST_ macros */
179 #define UNIV_LOG_LSN_DEBUG /* write LSN to the redo log;
180 this will break redo log file compatibility, but it may be useful when
181 debugging redo log application problems. */
182 #define UNIV_MEM_DEBUG /* detect memory leaks etc */
183 #define UNIV_IBUF_DEBUG /* debug the insert buffer */
184 #define UNIV_BLOB_DEBUG /* track BLOB ownership;
185 assumes that no BLOBs survive server restart */
186 #define UNIV_IBUF_COUNT_DEBUG /* debug the insert buffer;
187 this limits the database to IBUF_COUNT_N_SPACES and IBUF_COUNT_N_PAGES,
188 and the insert buffer must be empty when the database is started */
189 #define UNIV_SYNC_DEBUG /* debug mutex and latch
190 operations (very slow); also UNIV_DEBUG must be defined */
191 #define UNIV_SEARCH_DEBUG /* debug B-tree comparisons */
192 #define UNIV_SYNC_PERF_STAT /* operation counts for
193 rw-locks and mutexes */
194 #define UNIV_SEARCH_PERF_STAT /* statistics for the
195 adaptive hash index */
196 #define UNIV_SRV_PRINT_LATCH_WAITS /* enable diagnostic output
197 in sync0sync.c */
198 #define UNIV_BTR_PRINT /* enable functions for
199 printing B-trees */
200 #define UNIV_ZIP_DEBUG /* extensive consistency checks
201 for compressed pages */
202 #define UNIV_ZIP_COPY /* call page_zip_copy_recs()
203 more often */
204 #endif
206 #define UNIV_BTR_DEBUG /* check B-tree links */
207 #define UNIV_LIGHT_MEM_DEBUG /* light memory debugging */
210 #define UNIV_SQL_DEBUG
211 #define UNIV_LOG_DEBUG
213 /* the above option prevents forcing of log to disk
214 at a buffer page write: it should be tested with this
215 option off; also some ibuf tests are suppressed */
217 /* Linkage specifier for non-static InnoDB symbols (variables and functions)
218 that are only referenced from within InnoDB, not from MySQL */
219 #if defined(__GNUC__) && (__GNUC__ >= 4) || defined(__INTEL_COMPILER)
220 # define UNIV_INTERN __attribute__((visibility ("hidden")))
221 #else
222 # define UNIV_INTERN
223 #endif
225 #if (!defined(UNIV_DEBUG) && !defined(UNIV_MUST_NOT_INLINE))
226 /* Definition for inline version */
228 #ifdef __WIN__
229 # define UNIV_INLINE __inline
230 #elif defined(__SUNPRO_CC) || defined(__SUNPRO_C)
231 # define UNIV_INLINE static inline
232 #else
233 # define UNIV_INLINE static __inline__
234 #endif
236 #else
237 /* If we want to compile a noninlined version we use the following macro
238 definitions: */
240 #define UNIV_NONINL
241 #define UNIV_INLINE UNIV_INTERN
243 #endif /* UNIV_DEBUG */
245 #ifdef _WIN32
246 #define UNIV_WORD_SIZE 4
247 #elif defined(_WIN64)
248 #define UNIV_WORD_SIZE 8
249 #else
250 /* MySQL config.h generated by GNU autoconf will define SIZEOF_LONG in Posix */
251 #define UNIV_WORD_SIZE SIZEOF_LONG
252 #endif
254 /* The following alignment is used in memory allocations in memory heap
255 management to ensure correct alignment for doubles etc. */
256 #define UNIV_MEM_ALIGNMENT 8
258 /* The following alignment is used in aligning lints etc. */
259 #define UNIV_WORD_ALIGNMENT UNIV_WORD_SIZE
262 DATABASE VERSION CONTROL
263 ========================
266 /** There are currently two InnoDB file formats which are used to group
267 features with similar restrictions and dependencies. Using an enum allows
268 switch statements to give a compiler warning when a new one is introduced. */
269 enum innodb_file_formats_enum {
270 /** Antelope File Format: InnoDB/MySQL up to 5.1.
271 This format includes REDUNDANT and COMPACT row formats */
272 UNIV_FORMAT_A = 0,
274 /** Barracuda File Format: Introduced in InnoDB plugin for 5.1:
275 This format includes COMPRESSED and DYNAMIC row formats. It
276 includes the ability to create secondary indexes from data that
277 is not on the clustered index page and the ability to store more
278 data off the clustered index page. */
279 UNIV_FORMAT_B = 1
282 typedef enum innodb_file_formats_enum innodb_file_formats_t;
284 /* The 2-logarithm of UNIV_PAGE_SIZE: */
285 #define UNIV_PAGE_SIZE_SHIFT 14
286 /* The universal page size of the database */
287 #define UNIV_PAGE_SIZE (1 << UNIV_PAGE_SIZE_SHIFT)
289 /* Maximum number of parallel threads in a parallelized operation */
290 #define UNIV_MAX_PARALLELISM 32
292 /* The maximum length of a table name. This is the MySQL limit and is
293 defined in mysql_com.h like NAME_CHAR_LEN*SYSTEM_CHARSET_MBMAXLEN, the
294 number does not include a terminating '\0'. InnoDB probably can handle
295 longer names internally */
296 #define MAX_TABLE_NAME_LEN 192
298 /* The maximum length of a database name. Like MAX_TABLE_NAME_LEN this is
299 the MySQL's NAME_LEN, see check_and_convert_db_name(). */
300 #define MAX_DATABASE_NAME_LEN MAX_TABLE_NAME_LEN
302 /* MAX_FULL_NAME_LEN defines the full name path including the
303 database name and table name. In addition, 14 bytes is added for:
304 2 for surrounding quotes around table name
305 1 for the separating dot (.)
306 9 for the #mysql50# prefix */
307 #define MAX_FULL_NAME_LEN \
308 (MAX_TABLE_NAME_LEN + MAX_DATABASE_NAME_LEN + 14)
311 UNIVERSAL TYPE DEFINITIONS
312 ==========================
315 /* Note that inside MySQL 'byte' is defined as char on Linux! */
316 #define byte unsigned char
318 /* Define an unsigned integer type that is exactly 32 bits. */
320 #if SIZEOF_INT == 4
321 typedef unsigned int ib_uint32_t;
322 #elif SIZEOF_LONG == 4
323 typedef unsigned long ib_uint32_t;
324 #else
325 #error "Neither int or long is 4 bytes"
326 #endif
328 /* Another basic type we use is unsigned long integer which should be equal to
329 the word size of the machine, that is on a 32-bit platform 32 bits, and on a
330 64-bit platform 64 bits. We also give the printf format for the type as a
331 macro ULINTPF. */
333 #ifdef _WIN64
334 typedef unsigned __int64 ulint;
335 #define ULINTPF "%I64u"
336 typedef __int64 lint;
337 #else
338 typedef unsigned long int ulint;
339 #define ULINTPF "%lu"
340 typedef long int lint;
341 #endif
343 #ifdef __WIN__
344 typedef __int64 ib_int64_t;
345 typedef unsigned __int64 ib_uint64_t;
346 #elif !defined(UNIV_HOTBACKUP)
347 /* Note: longlong and ulonglong come from MySQL headers. */
348 typedef longlong ib_int64_t;
349 typedef ulonglong ib_uint64_t;
350 #endif
352 #ifndef UNIV_HOTBACKUP
353 typedef unsigned long long int ullint;
354 #endif /* UNIV_HOTBACKUP */
356 #ifndef __WIN__
357 #if SIZEOF_LONG != SIZEOF_VOIDP
358 #error "Error: InnoDB's ulint must be of the same size as void*"
359 #endif
360 #endif
362 /* The 'undefined' value for a ulint */
363 #define ULINT_UNDEFINED ((ulint)(-1))
365 /* The undefined 32-bit unsigned integer */
366 #define ULINT32_UNDEFINED 0xFFFFFFFF
368 /* Maximum value for a ulint */
369 #define ULINT_MAX ((ulint)(-2))
371 /* Maximum value for ib_uint64_t */
372 #define IB_ULONGLONG_MAX ((ib_uint64_t) (~0ULL))
374 /* THe 'undefined' value for ullint */
375 #define ULLINT_UNDEFINED ((ullint)(-1))
377 /* This 'ibool' type is used within Innobase. Remember that different included
378 headers may define 'bool' differently. Do not assume that 'bool' is a ulint! */
379 #define ibool ulint
381 #ifndef TRUE
383 #define TRUE 1
384 #define FALSE 0
386 #endif
388 /* The following number as the length of a logical field means that the field
389 has the SQL NULL as its value. NOTE that because we assume that the length
390 of a field is a 32-bit integer when we store it, for example, to an undo log
391 on disk, we must have also this number fit in 32 bits, also in 64-bit
392 computers! */
394 #define UNIV_SQL_NULL ULINT32_UNDEFINED
396 /* Lengths which are not UNIV_SQL_NULL, but bigger than the following
397 number indicate that a field contains a reference to an externally
398 stored part of the field in the tablespace. The length field then
399 contains the sum of the following flag and the locally stored len. */
401 #define UNIV_EXTERN_STORAGE_FIELD (UNIV_SQL_NULL - UNIV_PAGE_SIZE)
403 /* Some macros to improve branch prediction and reduce cache misses */
404 #if defined(__GNUC__) && (__GNUC__ > 2) && ! defined(__INTEL_COMPILER)
405 /* Tell the compiler that 'expr' probably evaluates to 'constant'. */
406 # define UNIV_EXPECT(expr,constant) __builtin_expect(expr, constant)
407 /* Tell the compiler that a pointer is likely to be NULL */
408 # define UNIV_LIKELY_NULL(ptr) __builtin_expect((ulint) ptr, 0)
409 /* Minimize cache-miss latency by moving data at addr into a cache before
410 it is read. */
411 # define UNIV_PREFETCH_R(addr) __builtin_prefetch(addr, 0, 3)
412 /* Minimize cache-miss latency by moving data at addr into a cache before
413 it is read or written. */
414 # define UNIV_PREFETCH_RW(addr) __builtin_prefetch(addr, 1, 3)
415 /* Sun Studio includes sun_prefetch.h as of version 5.9 */
416 #elif (defined(__SUNPRO_C) && __SUNPRO_C >= 0x590) \
417 || (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x590)
418 # include <sun_prefetch.h>
419 #if __SUNPRO_C >= 0x550
420 # undef UNIV_INTERN
421 # define UNIV_INTERN __hidden
422 #endif /* __SUNPRO_C >= 0x550 */
423 /* Use sun_prefetch when compile with Sun Studio */
424 # define UNIV_EXPECT(expr,value) (expr)
425 # define UNIV_LIKELY_NULL(expr) (expr)
426 # define UNIV_PREFETCH_R(addr) sun_prefetch_read_many((void*) addr)
427 # define UNIV_PREFETCH_RW(addr) sun_prefetch_write_many(addr)
428 #else
429 /* Dummy versions of the macros */
430 # define UNIV_EXPECT(expr,value) (expr)
431 # define UNIV_LIKELY_NULL(expr) (expr)
432 # define UNIV_PREFETCH_R(addr) ((void) 0)
433 # define UNIV_PREFETCH_RW(addr) ((void) 0)
434 #endif
435 /* Tell the compiler that cond is likely to hold */
436 #define UNIV_LIKELY(cond) UNIV_EXPECT(cond, TRUE)
437 /* Tell the compiler that cond is unlikely to hold */
438 #define UNIV_UNLIKELY(cond) UNIV_EXPECT(cond, FALSE)
440 /* Compile-time constant of the given array's size. */
441 #define UT_ARR_SIZE(a) (sizeof(a) / sizeof((a)[0]))
443 /* The return type from a thread's start function differs between Unix and
444 Windows, so define a typedef for it and a macro to use at the end of such
445 functions. */
447 #ifdef __WIN__
448 typedef ulint os_thread_ret_t;
449 #define OS_THREAD_DUMMY_RETURN return(0)
450 #else
451 typedef void* os_thread_ret_t;
452 #define OS_THREAD_DUMMY_RETURN return(NULL)
453 #endif
455 #include <stdio.h>
456 #include "ut0dbg.h"
457 #include "ut0ut.h"
458 #include "db0err.h"
459 #ifdef UNIV_DEBUG_VALGRIND
460 # include <valgrind/memcheck.h>
461 # define UNIV_MEM_VALID(addr, size) VALGRIND_MAKE_MEM_DEFINED(addr, size)
462 # define UNIV_MEM_INVALID(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size)
463 # define UNIV_MEM_FREE(addr, size) VALGRIND_MAKE_MEM_NOACCESS(addr, size)
464 # define UNIV_MEM_ALLOC(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size)
465 # define UNIV_MEM_DESC(addr, size, b) VALGRIND_CREATE_BLOCK(addr, size, b)
466 # define UNIV_MEM_UNDESC(b) VALGRIND_DISCARD(b)
467 # define UNIV_MEM_ASSERT_RW(addr, size) do { \
468 const void* _p = (const void*) (ulint) \
469 VALGRIND_CHECK_MEM_IS_DEFINED(addr, size); \
470 if (UNIV_LIKELY_NULL(_p)) \
471 fprintf(stderr, "%s:%d: %p[%u] undefined at %ld\n", \
472 __FILE__, __LINE__, \
473 (const void*) (addr), (unsigned) (size), (long) \
474 (((const char*) _p) - ((const char*) (addr)))); \
475 } while (0)
476 # define UNIV_MEM_ASSERT_W(addr, size) do { \
477 const void* _p = (const void*) (ulint) \
478 VALGRIND_CHECK_MEM_IS_ADDRESSABLE(addr, size); \
479 if (UNIV_LIKELY_NULL(_p)) \
480 fprintf(stderr, "%s:%d: %p[%u] unwritable at %ld\n", \
481 __FILE__, __LINE__, \
482 (const void*) (addr), (unsigned) (size), (long) \
483 (((const char*) _p) - ((const char*) (addr)))); \
484 } while (0)
485 #else
486 # define UNIV_MEM_VALID(addr, size) do {} while(0)
487 # define UNIV_MEM_INVALID(addr, size) do {} while(0)
488 # define UNIV_MEM_FREE(addr, size) do {} while(0)
489 # define UNIV_MEM_ALLOC(addr, size) do {} while(0)
490 # define UNIV_MEM_DESC(addr, size, b) do {} while(0)
491 # define UNIV_MEM_UNDESC(b) do {} while(0)
492 # define UNIV_MEM_ASSERT_RW(addr, size) do {} while(0)
493 # define UNIV_MEM_ASSERT_W(addr, size) do {} while(0)
494 #endif
495 #define UNIV_MEM_ASSERT_AND_FREE(addr, size) do { \
496 UNIV_MEM_ASSERT_W(addr, size); \
497 UNIV_MEM_FREE(addr, size); \
498 } while (0)
499 #define UNIV_MEM_ASSERT_AND_ALLOC(addr, size) do { \
500 UNIV_MEM_ASSERT_W(addr, size); \
501 UNIV_MEM_ALLOC(addr, size); \
502 } while (0)
504 #endif