| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 1994, 2026, Oracle and/or its affiliates. |
| 4 |
Copyright (c) 2008, Google Inc. |
| 5 |
|
| 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. |
| 11 |
|
| 12 |
This program is free software; you can redistribute it and/or modify it under |
| 13 |
the terms of the GNU General Public License, version 2.0, as published by the |
| 14 |
Free Software Foundation. |
| 15 |
|
| 16 |
This program is designed to work with certain software (including |
| 17 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 18 |
as designated in a particular file or component or in included license |
| 19 |
documentation. The authors of MySQL hereby grant you an additional |
| 20 |
permission to link the program and your derivative works with the |
| 21 |
separately licensed software that they have either included with |
| 22 |
the program or referenced in the documentation. |
| 23 |
|
| 24 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 25 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 26 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 27 |
for more details. |
| 28 |
|
| 29 |
You should have received a copy of the GNU General Public License along with |
| 30 |
this program; if not, write to the Free Software Foundation, Inc., |
| 31 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 32 |
|
| 33 |
*****************************************************************************/ |
| 34 |
|
| 35 |
/***********************************************************************/ /** |
| 36 |
@file include/univ.i |
| 37 |
Version control for database, common definitions, and include files |
| 38 |
|
| 39 |
Created 1/20/1994 Heikki Tuuri |
| 40 |
****************************************************************************/ |
| 41 |
|
| 42 |
#ifndef univ_i |
| 43 |
#define univ_i |
| 44 |
|
| 45 |
#ifdef UNIV_HOTBACKUP |
| 46 |
#include "hb_univ.i" |
| 47 |
#endif /* UNIV_HOTBACKUP */ |
| 48 |
|
| 49 |
/* aux macros to convert M into "123" (string) if M is defined like |
| 50 |
#define M 123 */ |
| 51 |
#define _IB_TO_STR(s) #s |
| 52 |
#define IB_TO_STR(s) _IB_TO_STR(s) |
| 53 |
|
| 54 |
#define INNODB_VERSION_MAJOR MYSQL_VERSION_MAJOR |
| 55 |
#define INNODB_VERSION_MINOR MYSQL_VERSION_MINOR |
| 56 |
#define INNODB_VERSION_BUGFIX MYSQL_VERSION_PATCH |
| 57 |
|
| 58 |
/* The following is the InnoDB version as shown in |
| 59 |
SELECT plugin_version FROM information_schema.plugins; |
| 60 |
calculated in make_version_string() in sql/sql_show.cc like this: |
| 61 |
"version >> 8" . "version & 0xff" |
| 62 |
because the version is shown with only one dot, we skip the last |
| 63 |
component, i.e. we show M.N.P as M.N */ |
| 64 |
#define INNODB_VERSION_SHORT (INNODB_VERSION_MAJOR << 8 | INNODB_VERSION_MINOR) |
| 65 |
|
| 66 |
#define INNODB_VERSION_STR \ |
| 67 |
IB_TO_STR(INNODB_VERSION_MAJOR) \ |
| 68 |
"." IB_TO_STR(INNODB_VERSION_MINOR) "." IB_TO_STR(INNODB_VERSION_BUGFIX) |
| 69 |
|
| 70 |
#define REFMAN \ |
| 71 |
"http://dev.mysql.com/doc/refman/" IB_TO_STR( \ |
| 72 |
MYSQL_VERSION_MAJOR) "." IB_TO_STR(MYSQL_VERSION_MINOR) "/en/" |
| 73 |
|
| 74 |
#ifdef MYSQL_DYNAMIC_PLUGIN |
| 75 |
/* In the dynamic plugin, redefine some externally visible symbols |
| 76 |
in order not to conflict with the symbols of a builtin InnoDB. */ |
| 77 |
|
| 78 |
/* Rename all C++ classes that contain virtual functions, because we |
| 79 |
have not figured out how to apply the visibility=hidden attribute to |
| 80 |
the virtual method table (vtable) in GCC 3. */ |
| 81 |
#define ha_innobase ha_innodb |
| 82 |
#endif /* MYSQL_DYNAMIC_PLUGIN */ |
| 83 |
|
| 84 |
#if defined(_WIN32) |
| 85 |
#include <windows.h> |
| 86 |
#endif /* _WIN32 */ |
| 87 |
|
| 88 |
/* The defines used with MySQL */ |
| 89 |
|
| 90 |
/* Include a minimum number of SQL header files so that few changes |
| 91 |
made in SQL code cause a complete InnoDB rebuild. These headers are |
| 92 |
used throughout InnoDB but do not include too much themselves. They |
| 93 |
support cross-platform development and expose commonly used SQL names. */ |
| 94 |
|
| 95 |
#include "m_string.h" |
| 96 |
#ifndef UNIV_HOTBACKUP |
| 97 |
#include "my_thread.h" |
| 98 |
#endif /* !UNIV_HOTBACKUP */ |
| 99 |
|
| 100 |
#include <limits> |
| 101 |
/* Include <sys/stat.h> to get S_I... macros defined for os0file.cc */ |
| 102 |
#include <sys/stat.h> |
| 103 |
|
| 104 |
#include "my_psi_config.h" |
| 105 |
|
| 106 |
#ifndef _WIN32 |
| 107 |
#include <sched.h> |
| 108 |
#include <sys/mman.h> /* mmap() for os0proc.cc */ |
| 109 |
#endif /* !_WIN32 */ |
| 110 |
|
| 111 |
/* Include the header file generated by CMake */ |
| 112 |
#ifndef _WIN32 |
| 113 |
#ifndef UNIV_HOTBACKUP |
| 114 |
#include "my_config.h" |
| 115 |
#endif /* !UNIV_HOTBACKUP */ |
| 116 |
#endif |
| 117 |
|
| 118 |
#ifndef UNIV_HOTBACKUP |
| 119 |
#include <inttypes.h> |
| 120 |
#include <stdint.h> |
| 121 |
#ifdef HAVE_UNISTD_H |
| 122 |
#include <unistd.h> |
| 123 |
#endif |
| 124 |
#endif /* !UNIV_HOTBACKUP */ |
| 125 |
|
| 126 |
/* Following defines are to enable performance schema |
| 127 |
instrumentation in each of five InnoDB modules if |
| 128 |
HAVE_PSI_INTERFACE is defined. */ |
| 129 |
#if defined(HAVE_PSI_INTERFACE) && !defined(UNIV_LIBRARY) |
| 130 |
#ifdef HAVE_PSI_MUTEX_INTERFACE |
| 131 |
#define UNIV_PFS_MUTEX |
| 132 |
#endif /* HAVE_PSI_MUTEX_INTERFACE */ |
| 133 |
|
| 134 |
#if defined HAVE_PSI_RWLOCK_INTERFACE && defined UNIV_PFS_MUTEX |
| 135 |
/* For the rwlocks to be tracked UNIV_PFS_MUTEX has to be defined. If not |
| 136 |
defined, the rwlocks are simply not tracked. */ |
| 137 |
#define UNIV_PFS_RWLOCK |
| 138 |
#endif /* HAVE_PSI_RWLOCK_INTERFACE */ |
| 139 |
|
| 140 |
#ifdef HAVE_PSI_FILE_INTERFACE |
| 141 |
#define UNIV_PFS_IO |
| 142 |
#endif /* HAVE_PSI_FILE_INTERFACE */ |
| 143 |
|
| 144 |
#ifdef HAVE_PSI_THREAD_INTERFACE |
| 145 |
#define UNIV_PFS_THREAD |
| 146 |
#endif /* HAVE_PSI_THREAD_INTERFACE */ |
| 147 |
|
| 148 |
#ifdef HAVE_PSI_MEMORY_INTERFACE |
| 149 |
#define UNIV_PFS_MEMORY |
| 150 |
#endif /* HAVE_PSI_MEMORY_INTERFACE */ |
| 151 |
|
| 152 |
#include "mysql/psi/mysql_file.h" |
| 153 |
#include "mysql/psi/mysql_mutex.h" |
| 154 |
#include "mysql/psi/mysql_rwlock.h" |
| 155 |
#include "mysql/psi/mysql_thread.h" |
| 156 |
/* For PSI_FILE_CALL(). */ |
| 157 |
#include "pfs_file_provider.h" |
| 158 |
#include "pfs_mutex_provider.h" |
| 159 |
#include "pfs_rwlock_provider.h" |
| 160 |
/* For PSI_MUTEX_CALL() and similar. */ |
| 161 |
#include "pfs_thread_provider.h" |
| 162 |
|
| 163 |
#endif /* HAVE_PSI_INTERFACE && !UNIV_LIBRARY */ |
| 164 |
|
| 165 |
#ifdef _WIN32 |
| 166 |
#define YY_NO_UNISTD_H 1 |
| 167 |
/* VC++ tries to optimise for size by default, from V8+. The size of |
| 168 |
the pointer to member depends on whether the type is defined before the |
| 169 |
compiler sees the type in the translation unit. This default behaviour |
| 170 |
can cause the pointer to be a different size in different translation |
| 171 |
units, depending on the above rule. We force optimise for size behaviour |
| 172 |
for all cases. This is used by ut0lst.h related code. */ |
| 173 |
#pragma pointers_to_members(full_generality, single_inheritance) |
| 174 |
#endif /* _WIN32 */ |
| 175 |
|
| 176 |
/* DEBUG VERSION CONTROL |
| 177 |
===================== */ |
| 178 |
|
| 179 |
/* When this macro is defined then additional test functions will be |
| 180 |
compiled. These functions live at the end of each relevant source file |
| 181 |
and have "test_" prefix. These functions can be called from gdb after |
| 182 |
srv_start() has executed using the call command. */ |
| 183 |
/* |
| 184 |
#define UNIV_COMPILE_TEST_FUNCS |
| 185 |
#define UNIV_ENABLE_UNIT_TEST_GET_PARENT_DIR |
| 186 |
#define UNIV_ENABLE_UNIT_TEST_MAKE_FILEPATH |
| 187 |
#define UNIV_ENABLE_UNIT_TEST_DICT_STATS |
| 188 |
#define UNIV_ENABLE_UNIT_TEST_ROW_RAW_FORMAT_INT |
| 189 |
*/ |
| 190 |
|
| 191 |
#if defined HAVE_VALGRIND |
| 192 |
#define UNIV_DEBUG_VALGRIND |
| 193 |
#endif /* HAVE_VALGRIND */ |
| 194 |
|
| 195 |
#ifdef NDEBUG |
| 196 |
#undef UNIV_DEBUG |
| 197 |
#elif !defined UNIV_DEBUG |
| 198 |
#define UNIV_DEBUG |
| 199 |
#endif |
| 200 |
|
| 201 |
#if 0 |
| 202 |
#define UNIV_DEBUG_VALGRIND /* Enable extra \ |
| 203 |
Valgrind instrumentation */ |
| 204 |
#define UNIV_DEBUG_PRINT /* Enable the compilation of \ |
| 205 |
some debug print functions */ |
| 206 |
#define UNIV_AHI_DEBUG /* Enable adaptive hash index \ |
| 207 |
debugging without UNIV_DEBUG */ |
| 208 |
#define UNIV_BUF_DEBUG /* Enable buffer pool \ |
| 209 |
debugging without UNIV_DEBUG */ |
| 210 |
#define UNIV_BLOB_LIGHT_DEBUG /* Enable off-page column \ |
| 211 |
debugging without UNIV_DEBUG */ |
| 212 |
#define UNIV_DEBUG_LOCK_VALIDATE /* Enable \ |
| 213 |
ut_d(lock_rec_validate_page()) \ |
| 214 |
assertions. */ |
| 215 |
#define UNIV_LRU_DEBUG /* debug the buffer pool LRU */ |
| 216 |
#define UNIV_HASH_DEBUG /* debug HASH_ macros */ |
| 217 |
#define UNIV_LOG_LSN_DEBUG /* write LSN to the redo log; \ |
| 218 |
this will break redo log file compatibility, but it may be useful when \ |
| 219 |
debugging redo log application problems. */ |
| 220 |
#define UNIV_IBUF_DEBUG /* debug the insert buffer */ |
| 221 |
#define UNIV_IBUF_COUNT_DEBUG /* debug the insert buffer; \ |
| 222 |
this limits the database to IBUF_COUNT_N_SPACES and IBUF_COUNT_N_PAGES, \ |
| 223 |
and the insert buffer must be empty when the database is started */ |
| 224 |
#define UNIV_PERF_DEBUG /* debug flag that enables \ |
| 225 |
light weight performance \ |
| 226 |
related stuff. */ |
| 227 |
#define UNIV_SEARCH_PERF_STAT /* statistics for the \ |
| 228 |
adaptive hash index */ |
| 229 |
#define UNIV_SRV_PRINT_LATCH_WAITS /* enable diagnostic output \ |
| 230 |
in sync0sync.cc */ |
| 231 |
#define UNIV_BTR_PRINT /* enable functions for \ |
| 232 |
printing B-trees */ |
| 233 |
#define UNIV_ZIP_DEBUG /* extensive consistency checks \ |
| 234 |
for compressed pages */ |
| 235 |
#define UNIV_ZIP_COPY /* call page_zip_copy_recs() \ |
| 236 |
more often */ |
| 237 |
#define UNIV_AIO_DEBUG /* prints info about \ |
| 238 |
submitted and reaped AIO \ |
| 239 |
requests to the log. */ |
| 240 |
#define UNIV_STATS_DEBUG /* prints various stats \ |
| 241 |
related debug info from \ |
| 242 |
dict0stats.c */ |
| 243 |
#define FTS_INTERNAL_DIAG_PRINT /* FTS internal debugging \ |
| 244 |
info output */ |
| 245 |
#define UNIV_DEBUG_DEDICATED /* dedicated server debugging \ |
| 246 |
info output and code coverage */ |
| 247 |
#endif |
| 248 |
|
| 249 |
#define UNIV_BTR_DEBUG /* check B-tree links */ |
| 250 |
#define UNIV_LIGHT_MEM_DEBUG /* light memory debugging */ |
| 251 |
|
| 252 |
// #define UNIV_SQL_DEBUG |
| 253 |
|
| 254 |
#if defined(COMPILER_HINTS) && defined __GNUC__ && \ |
| 255 |
(__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 3) |
| 256 |
|
| 257 |
/** Starting with GCC 4.3, the "cold" attribute is used to inform the |
| 258 |
compiler that a function is unlikely executed. The function is |
| 259 |
optimized for size rather than speed and on many targets it is placed |
| 260 |
into special subsection of the text section so all cold functions |
| 261 |
appears close together improving code locality of non-cold parts of |
| 262 |
program. The paths leading to call of cold functions within code are |
| 263 |
marked as unlikely by the branch prediction mechanism. optimize a |
| 264 |
rarely invoked function for size instead for speed. */ |
| 265 |
#define UNIV_COLD MY_ATTRIBUTE((cold)) |
| 266 |
#else |
| 267 |
#define UNIV_COLD /* empty */ |
| 268 |
#endif |
| 269 |
|
| 270 |
#ifdef _WIN32 |
| 271 |
#ifdef _WIN64 |
| 272 |
constexpr size_t UNIV_WORD_SIZE = 8; |
| 273 |
#else |
| 274 |
constexpr size_t UNIV_WORD_SIZE = 4; |
| 275 |
#endif |
| 276 |
#else /* !_WIN32 */ |
| 277 |
/** MySQL config.h generated by CMake will define SIZEOF_LONG in Posix */ |
| 278 |
constexpr size_t UNIV_WORD_SIZE = SIZEOF_LONG; |
| 279 |
#endif /* _WIN32 */ |
| 280 |
|
| 281 |
/** The following alignment is used in memory allocations in memory heap |
| 282 |
management to ensure correct alignment for doubles etc. */ |
| 283 |
constexpr uint32_t UNIV_MEM_ALIGNMENT = 8; |
| 284 |
|
| 285 |
/* |
| 286 |
DATABASE VERSION CONTROL |
| 287 |
======================== |
| 288 |
*/ |
| 289 |
|
| 290 |
/** The 2-logarithm of UNIV_PAGE_SIZE: */ |
| 291 |
#define UNIV_PAGE_SIZE_SHIFT srv_page_size_shift |
| 292 |
|
| 293 |
/** The universal page size of the database */ |
| 294 |
#define UNIV_PAGE_SIZE ((ulint)srv_page_size) |
| 295 |
|
| 296 |
/** log2 of smallest compressed page size (1<<10 == 1024 bytes) |
| 297 |
Note: This must never change! */ |
| 298 |
constexpr uint32_t UNIV_ZIP_SIZE_SHIFT_MIN = 10; |
| 299 |
|
| 300 |
/** log2 of largest compressed page size (1<<14 == 16384 bytes). |
| 301 |
A compressed page directory entry reserves 14 bits for the start offset |
| 302 |
and 2 bits for flags. This limits the uncompressed page size to 16k. |
| 303 |
Even though a 16k uncompressed page can theoretically be compressed |
| 304 |
into a larger compressed page, it is not a useful feature so we will |
| 305 |
limit both with this same constant. */ |
| 306 |
constexpr uint32_t UNIV_ZIP_SIZE_SHIFT_MAX = 14; |
| 307 |
|
| 308 |
/* Define the Min, Max, Default page sizes. */ |
| 309 |
/** Minimum Page Size Shift (power of 2) */ |
| 310 |
constexpr uint32_t UNIV_PAGE_SIZE_SHIFT_MIN = 12; |
| 311 |
/** Maximum Page Size Shift (power of 2) */ |
| 312 |
constexpr uint32_t UNIV_PAGE_SIZE_SHIFT_MAX = 16; |
| 313 |
/** Default Page Size Shift (power of 2) */ |
| 314 |
constexpr uint32_t UNIV_PAGE_SIZE_SHIFT_DEF = 14; |
| 315 |
/** Original 16k InnoDB Page Size Shift, in case the default changes */ |
| 316 |
constexpr uint32_t UNIV_PAGE_SIZE_SHIFT_ORIG = 14; |
| 317 |
/** Original 16k InnoDB Page Size as an ssize (log2 - 9) */ |
| 318 |
constexpr uint32_t UNIV_PAGE_SSIZE_ORIG = UNIV_PAGE_SIZE_SHIFT_ORIG - 9; |
| 319 |
|
| 320 |
/** Minimum page size InnoDB currently supports. */ |
| 321 |
constexpr uint32_t UNIV_PAGE_SIZE_MIN = 1 << UNIV_PAGE_SIZE_SHIFT_MIN; |
| 322 |
/** Maximum page size InnoDB currently supports. */ |
| 323 |
constexpr size_t UNIV_PAGE_SIZE_MAX = 1 << UNIV_PAGE_SIZE_SHIFT_MAX; |
| 324 |
/** Default page size for InnoDB tablespaces. */ |
| 325 |
constexpr uint32_t UNIV_PAGE_SIZE_DEF = 1 << UNIV_PAGE_SIZE_SHIFT_DEF; |
| 326 |
/** Original 16k page size for InnoDB tablespaces. */ |
| 327 |
constexpr uint32_t UNIV_PAGE_SIZE_ORIG = 1 << UNIV_PAGE_SIZE_SHIFT_ORIG; |
| 328 |
|
| 329 |
/** Smallest compressed page size */ |
| 330 |
constexpr uint32_t UNIV_ZIP_SIZE_MIN = 1 << UNIV_ZIP_SIZE_SHIFT_MIN; |
| 331 |
|
| 332 |
/** Largest compressed page size */ |
| 333 |
constexpr uint32_t UNIV_ZIP_SIZE_MAX = 1 << UNIV_ZIP_SIZE_SHIFT_MAX; |
| 334 |
|
| 335 |
/** Largest possible ssize for an uncompressed page. |
| 336 |
(The convention 'ssize' is used for 'log2 minus 9' or the number of |
| 337 |
shifts starting with 512.) |
| 338 |
This max number varies depending on UNIV_PAGE_SIZE. */ |
| 339 |
#define UNIV_PAGE_SSIZE_MAX \ |
| 340 |
static_cast<ulint>(UNIV_PAGE_SIZE_SHIFT - UNIV_ZIP_SIZE_SHIFT_MIN + 1) |
| 341 |
|
| 342 |
/** Smallest possible ssize for an uncompressed page. */ |
| 343 |
#define UNIV_PAGE_SSIZE_MIN \ |
| 344 |
static_cast<ulint>(UNIV_PAGE_SIZE_SHIFT_MIN - UNIV_ZIP_SIZE_SHIFT_MIN + 1) |
| 345 |
|
| 346 |
/** Maximum number of parallel threads in a parallelized operation */ |
| 347 |
constexpr uint32_t UNIV_MAX_PARALLELISM = 32; |
| 348 |
|
| 349 |
/** This is the "mbmaxlen" for my_charset_filename (defined in |
| 350 |
strings/ctype-utf8.c), which is used to encode File and Database names. */ |
| 351 |
constexpr uint32_t FILENAME_CHARSET_MAXNAMLEN = 5; |
| 352 |
|
| 353 |
/** The maximum length of an encode table name in bytes. The max |
| 354 |
table and database names are NAME_CHAR_LEN (64) characters. After the |
| 355 |
encoding, the max length would be NAME_CHAR_LEN (64) * |
| 356 |
FILENAME_CHARSET_MAXNAMLEN (5) = 320 bytes. The number does not include a |
| 357 |
terminating '\0'. InnoDB can handle longer names internally */ |
| 358 |
constexpr uint32_t MAX_TABLE_NAME_LEN = 320; |
| 359 |
|
| 360 |
/** The maximum length of a database name. Like MAX_TABLE_NAME_LEN this is |
| 361 |
the MySQL's NAME_LEN, see check_and_convert_db_name(). */ |
| 362 |
constexpr uint32_t MAX_DATABASE_NAME_LEN = MAX_TABLE_NAME_LEN; |
| 363 |
|
| 364 |
/** MAX_FULL_NAME_LEN defines the full name path including the |
| 365 |
database name and table name. In addition, 14 bytes is added for: |
| 366 |
2 for surrounding quotes around table name |
| 367 |
1 for the separating dot (.) |
| 368 |
9 for the #mysql50# prefix */ |
| 369 |
constexpr uint32_t MAX_FULL_NAME_LEN = |
| 370 |
MAX_TABLE_NAME_LEN + MAX_DATABASE_NAME_LEN + 14; |
| 371 |
|
| 372 |
/** Maximum length of the compression algorithm string. Currently we support |
| 373 |
only (NONE | ZLIB | LZ4). */ |
| 374 |
constexpr uint32_t MAX_COMPRESSION_LEN = 4; |
| 375 |
|
| 376 |
/* |
| 377 |
UNIVERSAL TYPE DEFINITIONS |
| 378 |
========================== |
| 379 |
*/ |
| 380 |
|
| 381 |
/* Note that inside MySQL 'byte' is defined as char on Linux! */ |
| 382 |
using byte = unsigned char; |
| 383 |
|
| 384 |
/* Another basic type we use is unsigned long integer which should be equal to |
| 385 |
the word size of the machine, that is on a 32-bit platform 32 bits, and on a |
| 386 |
64-bit platform 64 bits. We also give the printf format for the type as a |
| 387 |
macro ULINTPF. We also give the printf format suffix (without '%') macro |
| 388 |
ULINTPFS, this one can be useful if we want to put something between % and |
| 389 |
lu/llu, like in %03lu. */ |
| 390 |
|
| 391 |
/* Use the integer types and formatting strings defined in the C++11 standard. |
| 392 |
*/ |
| 393 |
#define UINT16PF "%" PRIu16 |
| 394 |
#define UINT32PF "%" PRIu32 |
| 395 |
#define UINT32PFS PRIu32 |
| 396 |
#define UINT64PF "%" PRIu64 |
| 397 |
#define UINT64PFx "%016" PRIx64 |
| 398 |
|
| 399 |
#define IB_ID_FMT UINT64PF |
| 400 |
|
| 401 |
#ifdef _WIN64 |
| 402 |
typedef unsigned __int64 ulint; |
| 403 |
typedef __int64 lint; |
| 404 |
#define ULINTPFS "llu" |
| 405 |
#else |
| 406 |
typedef unsigned long int ulint; |
| 407 |
typedef long int lint; |
| 408 |
#define ULINTPFS "lu" |
| 409 |
#endif /* _WIN64 */ |
| 410 |
|
| 411 |
#define ULINTPF "%" ULINTPFS |
| 412 |
|
| 413 |
#ifndef _WIN32 |
| 414 |
#if SIZEOF_LONG != SIZEOF_VOIDP |
| 415 |
#error "Error: InnoDB's ulint must be of the same size as void*" |
| 416 |
#endif |
| 417 |
#endif |
| 418 |
|
| 419 |
/** The 'undefined' value for a ulint */ |
| 420 |
constexpr ulint ULINT_UNDEFINED = ~ulint{0U}; |
| 421 |
|
| 422 |
constexpr ulong ULONG_UNDEFINED = ~0UL; |
| 423 |
|
| 424 |
/** The 'undefined' value for a 64-bit unsigned integer */ |
| 425 |
constexpr uint64_t UINT64_UNDEFINED = ~0ULL; |
| 426 |
|
| 427 |
/** The 'undefined' value for a 32-bit unsigned integer */ |
| 428 |
constexpr uint32_t UINT32_UNDEFINED = ~0U; |
| 429 |
|
| 430 |
/** The 'undefined' value for a 16-bit unsigned integer */ |
| 431 |
constexpr uint16_t UINT16_UNDEFINED = std::numeric_limits<uint16_t>::max(); |
| 432 |
|
| 433 |
/** The 'undefined' value for a 8-bit unsigned integer */ |
| 434 |
constexpr uint8_t UINT8_UNDEFINED = std::numeric_limits<uint8_t>::max(); |
| 435 |
|
| 436 |
/** The bitmask of 32-bit unsigned integer */ |
| 437 |
constexpr uint32_t UINT32_MASK = 0xFFFFFFFF; |
| 438 |
|
| 439 |
/** Maximum value for a ulint */ |
| 440 |
constexpr ulint ULINT_MAX = std::numeric_limits<ulint>::max() - 1; |
| 441 |
|
| 442 |
/** The generic InnoDB system object identifier data type */ |
| 443 |
typedef uint64_t ib_id_t; |
| 444 |
constexpr ib_id_t IB_ID_MAX = std::numeric_limits<uint64_t>::max(); |
| 445 |
|
| 446 |
/** Page number */ |
| 447 |
typedef uint32_t page_no_t; |
| 448 |
/** Tablespace identifier */ |
| 449 |
typedef uint32_t space_id_t; |
| 450 |
|
| 451 |
#define SPACE_ID_PF UINT32PF |
| 452 |
#define SPACE_ID_PFS UINT32PFS |
| 453 |
#define PAGE_NO_PF UINT32PF |
| 454 |
#define PAGE_ID_PF "page " SPACE_ID_PF ":" PAGE_NO_PF |
| 455 |
|
| 456 |
#define UNIV_NOTHROW |
| 457 |
|
| 458 |
/** The following number as the length of a logical field means that the field |
| 459 |
has the SQL NULL as its value. NOTE that because we assume that the length |
| 460 |
of a field is a 32-bit integer when we store it, for example, to an undo log |
| 461 |
on disk, we must have also this number fit in 32 bits, also in 64-bit |
| 462 |
computers! */ |
| 463 |
constexpr uint32_t UNIV_SQL_NULL = UINT32_UNDEFINED; |
| 464 |
|
| 465 |
/** Flag to indicate a field which was added instantly */ |
| 466 |
constexpr auto UNIV_SQL_ADD_COL_DEFAULT = UNIV_SQL_NULL - 1; |
| 467 |
|
| 468 |
/** The following number as the length of a logical field means that no |
| 469 |
attribute value for the multi-value index exists in the JSON doc */ |
| 470 |
constexpr auto UNIV_NO_INDEX_VALUE = UNIV_SQL_ADD_COL_DEFAULT - 1; |
| 471 |
|
| 472 |
/** The following number as the length marker of a logical field, which |
| 473 |
is only used for multi-value field data, means the data itself of the |
| 474 |
field is actually an array. */ |
| 475 |
const uint32_t UNIV_MULTI_VALUE_ARRAY_MARKER = UNIV_NO_INDEX_VALUE - 1; |
| 476 |
|
| 477 |
/** Flag to indicate a field which was dropped instantly */ |
| 478 |
constexpr auto UNIV_SQL_INSTANT_DROP_COL = UNIV_MULTI_VALUE_ARRAY_MARKER - 1; |
| 479 |
|
| 480 |
/** Lengths which are not UNIV_SQL_NULL, but bigger than the following |
| 481 |
number indicate that a field contains a reference to an externally |
| 482 |
stored part of the field in the tablespace. The length field then |
| 483 |
contains the sum of the following flag and the locally stored len. */ |
| 484 |
|
| 485 |
constexpr uint32_t UNIV_EXTERN_STORAGE_FIELD = |
| 486 |
UNIV_SQL_NULL - UNIV_PAGE_SIZE_DEF; |
| 487 |
|
| 488 |
/* Some macros to improve branch prediction and reduce cache misses */ |
| 489 |
#if defined(COMPILER_HINTS) && defined(__GNUC__) |
| 490 |
/* Tell the compiler that 'expr' probably evaluates to 'constant'. */ |
| 491 |
#define UNIV_EXPECT(expr, constant) __builtin_expect(expr, constant) |
| 492 |
/* Tell the compiler that a pointer is likely to be NULL */ |
| 493 |
#define UNIV_LIKELY_NULL(ptr) __builtin_expect((ulint)ptr, 0) |
| 494 |
/* Minimize cache-miss latency by moving data at addr into a cache before |
| 495 |
it is read. */ |
| 496 |
#define UNIV_PREFETCH_R(addr) __builtin_prefetch(addr, 0, 3) |
| 497 |
/* Minimize cache-miss latency by moving data at addr into a cache before |
| 498 |
it is read or written. */ |
| 499 |
#define UNIV_PREFETCH_RW(addr) __builtin_prefetch(addr, 1, 3) |
| 500 |
|
| 501 |
#elif defined __WIN__ && defined COMPILER_HINTS |
| 502 |
#include <xmmintrin.h> |
| 503 |
|
| 504 |
#define UNIV_EXPECT(expr, value) (expr) |
| 505 |
#define UNIV_LIKELY_NULL(expr) (expr) |
| 506 |
// __MM_HINT_T0 - (temporal data) |
| 507 |
// prefetch data into all levels of the cache hierarchy. |
| 508 |
#define UNIV_PREFETCH_R(addr) _mm_prefetch((char *)addr, _MM_HINT_T0) |
| 509 |
#define UNIV_PREFETCH_RW(addr) _mm_prefetch((char *)addr, _MM_HINT_T0) |
| 510 |
#else |
| 511 |
/* Dummy versions of the macros */ |
| 512 |
#define UNIV_EXPECT(expr, value) expr |
| 513 |
#define UNIV_LIKELY_NULL(expr) expr |
| 514 |
#define UNIV_PREFETCH_R(addr) ((void)0) |
| 515 |
#define UNIV_PREFETCH_RW(addr) ((void)0) |
| 516 |
#endif |
| 517 |
|
| 518 |
/* Tell the compiler that cond is likely to hold */ |
| 519 |
#define UNIV_LIKELY(cond) UNIV_EXPECT(cond, true) |
| 520 |
/* Tell the compiler that cond is unlikely to hold */ |
| 521 |
#define UNIV_UNLIKELY(cond) UNIV_EXPECT(cond, false) |
| 522 |
|
| 523 |
/* Compile-time constant of the given array's size. */ |
| 524 |
#define UT_ARR_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 525 |
|
| 526 |
/* The return type from a thread's start function differs between Unix and |
| 527 |
Windows, so define a typedef for it and a macro to use at the end of such |
| 528 |
functions. */ |
| 529 |
|
| 530 |
#ifdef _WIN32 |
| 531 |
typedef ulint os_thread_ret_t; |
| 532 |
#define OS_PATH_SEPARATOR_STR "\\" |
| 533 |
#define OS_PATH_SEPARATOR '\\' |
| 534 |
#define OS_PATH_SEPARATOR_ALT '/' |
| 535 |
#else |
| 536 |
typedef void *os_thread_ret_t; |
| 537 |
#define OS_PATH_SEPARATOR_STR "/" |
| 538 |
#define OS_PATH_SEPARATOR '/' |
| 539 |
#define OS_PATH_SEPARATOR_ALT '\\' |
| 540 |
#endif /* _WIN32 */ |
| 541 |
|
| 542 |
#include <stdio.h> |
| 543 |
|
| 544 |
#include "db0err.h" |
| 545 |
#include "sync0types.h" |
| 546 |
#include "ut0dbg.h" |
| 547 |
#include "ut0lst.h" |
| 548 |
#include "ut0ut.h" |
| 549 |
|
| 550 |
#ifdef UNIV_DEBUG_VALGRIND |
| 551 |
#include <valgrind/memcheck.h> |
| 552 |
|
| 553 |
#define UNIV_MEM_VALID(addr, size) VALGRIND_MAKE_MEM_DEFINED(addr, size) |
| 554 |
#define UNIV_MEM_INVALID(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size) |
| 555 |
#define UNIV_MEM_FREE(addr, size) VALGRIND_MAKE_MEM_NOACCESS(addr, size) |
| 556 |
#define UNIV_MEM_ALLOC(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size) |
| 557 |
#define UNIV_MEM_DESC(addr, size) VALGRIND_CREATE_BLOCK(addr, size, #addr) |
| 558 |
#define UNIV_MEM_UNDESC(b) VALGRIND_DISCARD(b) |
| 559 |
#define UNIV_MEM_ASSERT_RW_LOW(addr, size, should_abort) \ |
| 560 |
do { \ |
| 561 |
const void *_p = \ |
| 562 |
(const void *)(ulint)VALGRIND_CHECK_MEM_IS_DEFINED(addr, size); \ |
| 563 |
if (UNIV_LIKELY_NULL(_p)) { \ |
| 564 |
fprintf(stderr, "%s:%d: %p[%u] undefined at %ld\n", __FILE__, __LINE__, \ |
| 565 |
(const void *)(addr), (unsigned)(size), \ |
| 566 |
(long)(((const char *)_p) - ((const char *)(addr)))); \ |
| 567 |
if (should_abort) { \ |
| 568 |
ut_error; \ |
| 569 |
} \ |
| 570 |
} \ |
| 571 |
} while (0) |
| 572 |
#define UNIV_MEM_ASSERT_RW(addr, size) UNIV_MEM_ASSERT_RW_LOW(addr, size, false) |
| 573 |
#define UNIV_MEM_ASSERT_RW_ABORT(addr, size) \ |
| 574 |
UNIV_MEM_ASSERT_RW_LOW(addr, size, true) |
| 575 |
#define UNIV_MEM_ASSERT_W(addr, size) \ |
| 576 |
do { \ |
| 577 |
const void *_p = \ |
| 578 |
(const void *)(ulint)VALGRIND_CHECK_MEM_IS_ADDRESSABLE(addr, size); \ |
| 579 |
if (UNIV_LIKELY_NULL(_p)) \ |
| 580 |
fprintf(stderr, "%s:%d: %p[%u] unwritable at %ld\n", __FILE__, __LINE__, \ |
| 581 |
(const void *)(addr), (unsigned)(size), \ |
| 582 |
(long)(((const char *)_p) - ((const char *)(addr)))); \ |
| 583 |
} while (0) |
| 584 |
#define UNIV_MEM_TRASH(addr, c, size) \ |
| 585 |
do { \ |
| 586 |
void *p = (addr); \ |
| 587 |
ut_d(memset(p, c, size)); \ |
| 588 |
UNIV_MEM_INVALID(p, size); \ |
| 589 |
} while (0) |
| 590 |
#else |
| 591 |
#define UNIV_MEM_VALID(addr, size) \ |
| 592 |
do { \ |
| 593 |
} while (0) |
| 594 |
#define UNIV_MEM_INVALID(addr, size) \ |
| 595 |
do { \ |
| 596 |
} while (0) |
| 597 |
#define UNIV_MEM_FREE(addr, size) \ |
| 598 |
do { \ |
| 599 |
} while (0) |
| 600 |
#define UNIV_MEM_ALLOC(addr, size) \ |
| 601 |
do { \ |
| 602 |
} while (0) |
| 603 |
#define UNIV_MEM_DESC(addr, size) \ |
| 604 |
do { \ |
| 605 |
} while (0) |
| 606 |
#define UNIV_MEM_UNDESC(b) \ |
| 607 |
do { \ |
| 608 |
} while (0) |
| 609 |
#define UNIV_MEM_ASSERT_RW_LOW(addr, size, should_abort) \ |
| 610 |
do { \ |
| 611 |
} while (0) |
| 612 |
#define UNIV_MEM_ASSERT_RW(addr, size) \ |
| 613 |
do { \ |
| 614 |
} while (0) |
| 615 |
#define UNIV_MEM_ASSERT_RW_ABORT(addr, size) \ |
| 616 |
do { \ |
| 617 |
} while (0) |
| 618 |
#define UNIV_MEM_ASSERT_W(addr, size) \ |
| 619 |
do { \ |
| 620 |
} while (0) |
| 621 |
#define UNIV_MEM_TRASH(addr, c, size) \ |
| 622 |
do { \ |
| 623 |
} while (0) |
| 624 |
#endif |
| 625 |
#define UNIV_MEM_ASSERT_AND_FREE(addr, size) \ |
| 626 |
do { \ |
| 627 |
UNIV_MEM_ASSERT_W(addr, size); \ |
| 628 |
UNIV_MEM_FREE(addr, size); \ |
| 629 |
} while (0) |
| 630 |
#define UNIV_MEM_ASSERT_AND_ALLOC(addr, size) \ |
| 631 |
do { \ |
| 632 |
UNIV_MEM_ASSERT_W(addr, size); \ |
| 633 |
UNIV_MEM_ALLOC(addr, size); \ |
| 634 |
} while (0) |
| 635 |
|
| 636 |
extern ulong srv_page_size_shift; |
| 637 |
extern ulong srv_page_size; |
| 638 |
|
| 639 |
static const size_t UNIV_SECTOR_SIZE = 512; |
| 640 |
|
| 641 |
/* Dimension of spatial object we support so far. It has its root in |
| 642 |
myisam/sp_defs.h. We only support 2 dimension data */ |
| 643 |
constexpr uint32_t SPDIMS = 2; |
| 644 |
|
| 645 |
/** Hard-coded data dictionary entry */ |
| 646 |
#define INNODB_DD_TABLE(name, n_indexes) \ |
| 647 |
{ name, n_indexes } |
| 648 |
|
| 649 |
/** Explicitly call the destructor, this is to get around Clang bug#12350. |
| 650 |
@param[in,out] p Instance on which to call the destructor */ |
| 651 |
template <typename T> |
| 652 |
void call_destructor(T *p) { |
| 653 |
p->~T(); |
| 654 |
} |
| 655 |
|
| 656 |
template <typename T> |
| 657 |
constexpr auto to_int(T v) -> typename std::underlying_type<T>::type { |
| 658 |
return (static_cast<typename std::underlying_type<T>::type>(v)); |
| 659 |
} |
| 660 |
|
| 661 |
/** If we are doing something that takes longer than this many seconds then |
| 662 |
print an informative message. */ |
| 663 |
static constexpr std::chrono::seconds PRINT_INTERVAL{10}; |
| 664 |
|
| 665 |
#if defined(UNIV_LIBRARY) && !defined(UNIV_NO_ERR_MSGS) |
| 666 |
|
| 667 |
/** Don't use the server logging infrastructure if building |
| 668 |
as a standalone library. */ |
| 669 |
#define UNIV_NO_ERR_MSGS |
| 670 |
|
| 671 |
#endif /* UNIV_LIBRARY && !UNIV_NO_ERR_MSGS */ |
| 672 |
|
| 673 |
#ifdef UNIV_DEBUG |
| 674 |
#define IF_DEBUG(...) __VA_ARGS__ |
| 675 |
#define IF_ENABLED(s, ...) \ |
| 676 |
if (Sync_point::enabled((s))) { \ |
| 677 |
__VA_ARGS__ \ |
| 678 |
} |
| 679 |
#else |
| 680 |
|
| 681 |
/* Expand the macro if we are generating Doxygen documentation. */ |
| 682 |
#ifdef DOXYGEN_IF_DEBUG |
| 683 |
#define IF_DEBUG(...) __VA_ARGS__ |
| 684 |
#else |
| 685 |
#define IF_DEBUG(...) |
| 686 |
#endif /* DOXYGEN_IF_DEBUG */ |
| 687 |
|
| 688 |
#define IF_ENABLED(s, ...) |
| 689 |
#endif /* UNIV_DEBUG */ |
| 690 |
|
| 691 |
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG |
| 692 |
#define IF_AHI_DEBUG(...) __VA_ARGS__ |
| 693 |
#else /* UNIV_AHI_DEBUG || defined UNIV_DEBUG */ |
| 694 |
#define IF_AHI_DEBUG(...) |
| 695 |
#endif /* UNIV_AHI_DEBUG || defined UNIV_DEBUG */ |
| 696 |
using Col_offsets_t = ulint; |
| 697 |
|
| 698 |
#endif /* univ_i */ |