1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
* Mostly constants and some macros/functions used by the server
26
#ifndef DRIZZLED_DEFINITIONS_H
27
#define DRIZZLED_DEFINITIONS_H
29
#include <drizzled/enum.h>
36
/* Global value for how we extend our temporary directory */
37
#define GLOBAL_TEMPORARY_EXT ".temporary"
39
/* These paths are converted to other systems (WIN95) before use */
41
#define LANGUAGE "english/"
42
#define TEMP_PREFIX "MY"
43
#define LOG_PREFIX "ML"
45
#define ER(X) ::drizzled::error_message((X))
47
/* buffer size for strerror_r() */
48
#define STRERROR_MAX 256
50
/* extra 4+4 bytes for slave tmp tables */
51
#define MAX_DBKEY_LENGTH (NAME_LEN*2+1+1+4+4)
52
#define MAX_ALIAS_NAME 256
53
#define MAX_FIELD_NAME 34 /* Max colum name length +2 */
54
#define MAX_SYS_VAR_LENGTH 32
55
#define MAX_INDEXES 64
56
#define MAX_KEY MAX_INDEXES /* Max used keys */
57
#define MAX_REF_PARTS 16 /* Max parts used as ref */
58
#define MAX_KEY_LENGTH 4096 /* max possible key */
59
#define MAX_KEY_LENGTH_DECIMAL_WIDTH 4 /* strlen("4096") */
61
#define MAX_REFLENGTH 8 /* Max length for record ref */
63
#define MAX_REFLENGTH 4 /* Max length for record ref */
65
#define MAX_HOSTNAME 61 /* len+1 in mysql.user */
67
#define MAX_MBWIDTH 4 /* Max multibyte sequence */
68
#define MAX_FIELD_CHARLENGTH 255
69
#define MAX_FIELD_VARCHARLENGTH 65535
70
#define CONVERT_IF_BIGGER_TO_BLOB 512 /* Used for CREATE ... SELECT */
72
/* Max column width +1 */
73
#define MAX_FIELD_WIDTH (MAX_FIELD_CHARLENGTH*MAX_MBWIDTH+1)
75
#define MAX_DATETIME_COMPRESSED_WIDTH 14 /* YYYYMMDDHHMMSS */
77
#define MAX_TABLES (sizeof(table_map)*8-3) /* Max tables in join */
78
#define PARAM_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-3))
79
#define OUTER_REF_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-2))
80
#define RAND_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-1))
81
#define PSEUDO_TABLE_BITS (PARAM_TABLE_BIT | OUTER_REF_TABLE_BIT | \
83
#define MAX_FIELDS 4096 /* Historical limit from MySQL FRM. */
85
#define MAX_SELECT_NESTING (sizeof(nesting_map)*8-1)
87
#define MAX_SORT_MEMORY (2048*1024-MALLOC_OVERHEAD)
88
#define MIN_SORT_MEMORY (32*1024-MALLOC_OVERHEAD)
90
#define DEFAULT_ERROR_COUNT 64
91
#define EXTRA_RECORDS 10 /* Extra records in sort */
92
#define NAMES_SEP_CHAR '\377' /* Char to sep. names */
94
#define READ_RECORD_BUFFER (uint32_t) (IO_SIZE*8) /* Pointer_buffer_size */
95
#define DISK_BUFFER_SIZE (uint32_t) (IO_SIZE*16) /* Size of diskbuffer */
97
#define ME_ERROR (ME_BELL+ME_OLDWIN+ME_NOREFRESH)
98
#define MYF_RW MYF(MY_WME+MY_NABP) /* Vid my_read & my_write */
101
Minimum length pattern before Turbo Boyer-Moore is used
102
for SELECT "text" LIKE "%pattern%", excluding the two
103
wildcards in class Item_func_like.
105
#define MIN_TURBOBM_PATTERN_LEN 3
108
Defines for binary logging.
109
Do not decrease the value of BIN_LOG_HEADER_SIZE.
110
Do not even increase it before checking code.
113
#define BIN_LOG_HEADER_SIZE 4
115
/* Below are #defines that used to be in mysql_priv.h */
116
/***************************************************************************
117
Configuration parameters
118
****************************************************************************/
119
#define MAX_FIELDS_BEFORE_HASH 32
120
#define USER_VARS_HASH_SIZE 16
121
#define TABLE_OPEN_CACHE_MIN 64
122
#define TABLE_OPEN_CACHE_DEFAULT 1024
125
Value of 9236 discovered through binary search 2006-09-26 on Ubuntu Dapper
126
Drake, libc6 2.3.6-0ubuntu2, Linux kernel 2.6.15-27-686, on x86. (Added
127
100 bytes as reasonable buffer against growth and other environments'
130
Feel free to raise this by the smallest amount you can to get the
131
"execution_constants" test to pass.
133
#define STACK_MIN_SIZE 12000 ///< Abort if less stack during eval.
135
#define STACK_MIN_SIZE_FOR_OPEN 1024*80
136
#define STACK_BUFF_ALLOC 352 ///< For stack overrun checks
138
#define QUERY_ALLOC_BLOCK_SIZE 8192
139
#define QUERY_ALLOC_PREALLOC_SIZE 8192
140
#define RANGE_ALLOC_BLOCK_SIZE 4096
141
#define TABLE_ALLOC_BLOCK_SIZE 1024
142
#define WARN_ALLOC_BLOCK_SIZE 2048
143
#define WARN_ALLOC_PREALLOC_SIZE 1024
146
The following parameters is to decide when to use an extra cache to
147
optimise seeks when reading a big table in sorted order
149
#define MIN_FILE_LENGTH_TO_USE_ROW_CACHE (10L*1024*1024)
150
#define MIN_ROWS_TO_USE_TABLE_CACHE 100
153
The following is used to decide if MySQL should use table scanning
154
instead of reading with keys. The number says how many evaluation of the
155
WHERE clause is comparable to reading one extra row from a table.
157
#define TIME_FOR_COMPARE 5 // 5 compares == one read
160
Number of comparisons of table rowids equivalent to reading one row from a
163
#define TIME_FOR_COMPARE_ROWID (TIME_FOR_COMPARE*2)
166
For sequential disk seeks the cost formula is:
167
DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip
169
The cost of average seek
170
DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST*BLOCKS_IN_AVG_SEEK =1.0.
172
#define DISK_SEEK_BASE_COST ((double)0.9)
174
#define BLOCKS_IN_AVG_SEEK 128
176
#define DISK_SEEK_PROP_COST ((double)0.1/BLOCKS_IN_AVG_SEEK)
180
Number of rows in a reference table when refereed through a not unique key.
181
This value is only used when we don't know anything about the key
184
#define MATCHING_ROWS_IN_OTHER_TABLE 10
186
/** Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used). */
187
#define KEY_DEFAULT_PACK_LENGTH 8
189
/** Characters shown for the command in 'show processlist'. */
190
#define PROCESS_LIST_WIDTH 100
192
#define PRECISION_FOR_DOUBLE 53
193
#define PRECISION_FOR_FLOAT 24
195
/* The following can also be changed from the command line */
196
#define DEFAULT_CONCURRENCY 10
197
#define FLUSH_TIME 0 /**< Don't flush tables */
198
#define MAX_CONNECT_ERRORS 10 ///< errors before disabling host
200
/* Bits from testflag */
203
TEST_PRINT_CACHED_TABLES= 1,
206
TEST_KEEP_TMP_TABLES,
207
TEST_READCHECK, /**< Force use of readcheck */
209
TEST_CORE_ON_SIGNAL, /**< Give core if signal */
211
TEST_SIGINT, /**< Allow sigint on threads */
212
TEST_SYNCHRONIZATION /**< get server to do sleep in some places */
215
/* Bits for different SQL modes modes (including ANSI mode) */
216
#define MODE_NO_ZERO_DATE (2)
217
#define MODE_INVALID_DATES (MODE_NO_ZERO_DATE*2)
219
#define MY_CHARSET_BIN_MB_MAXLEN 1
222
#define UNCACHEABLE_DEPENDENT 1
223
#define UNCACHEABLE_RAND 2
224
#define UNCACHEABLE_SIDEEFFECT 4
225
/// forcing to save JOIN for explain
226
#define UNCACHEABLE_EXPLAIN 8
227
/** Don't evaluate subqueries in prepare even if they're not correlated */
228
#define UNCACHEABLE_PREPARE 16
229
/* For uncorrelated SELECT in an UNION with some correlated SELECTs */
230
#define UNCACHEABLE_UNITED 32
232
/* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */
233
#define UNDEF_POS (-1)
235
/* Options to add_table_to_list() */
236
#define TL_OPTION_UPDATING 1
237
#define TL_OPTION_FORCE_INDEX 2
238
#define TL_OPTION_IGNORE_LEAVES 4
239
#define TL_OPTION_ALIAS 8
241
/* Some portable defines */
243
#define portable_sizeof_char_ptr 8
245
#define TMP_FILE_PREFIX "#sql" /**< Prefix for tmp tables */
246
#define TMP_FILE_PREFIX_LENGTH 4
248
/* Flags for calc_week() function. */
249
#define WEEK_MONDAY_FIRST 1
251
#define WEEK_FIRST_WEEKDAY 4
253
/* used in date and time conversions */
254
/* Daynumber from year 0 to 9999-12-31 */
255
#define MAX_DAY_NUMBER 3652424L
257
#define STRING_BUFFER_USUAL_SIZE 80
259
typedef void *range_seq_t;
261
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
262
// the following is for checking tables
264
#define HA_ADMIN_ALREADY_DONE 1
265
#define HA_ADMIN_OK 0
266
#define HA_ADMIN_NOT_IMPLEMENTED -1
267
#define HA_ADMIN_FAILED -2
268
#define HA_ADMIN_CORRUPT -3
269
#define HA_ADMIN_INTERNAL_ERROR -4
270
#define HA_ADMIN_INVALID -5
271
#define HA_ADMIN_REJECT -6
273
/* bits in index_flags(index_number) for what you can do with index */
274
#define HA_READ_NEXT 1 /* TODO really use this flag */
275
#define HA_READ_PREV 2 /* supports ::index_prev */
276
#define HA_READ_ORDER 4 /* index_next/prev follow sort order */
277
#define HA_READ_RANGE 8 /* can find all records in a range */
278
#define HA_ONLY_WHOLE_INDEX 16 /* Can't use part key searches */
279
#define HA_KEYREAD_ONLY 64 /* Support HA_EXTRA_KEYREAD */
281
Index scan will not return records in rowid order. Not guaranteed to be
282
set for unordered (e.g. HASH) indexes.
284
#define HA_KEY_SCAN_NOT_ROR 128
286
/* operations for disable/enable indexes */
287
#define HA_KEY_SWITCH_NONUNIQ 0
288
#define HA_KEY_SWITCH_ALL 1
289
#define HA_KEY_SWITCH_NONUNIQ_SAVE 2
290
#define HA_KEY_SWITCH_ALL_SAVE 3
293
Note: the following includes binlog and closing 0.
294
so: innodb + bdb + ndb + binlog + myisam + myisammrg + archive +
295
example + csv + heap + blackhole + federated + 0
296
(yes, the sum is deliberately inaccurate)
297
TODO remove the limit, use dynarrays
302
Parameters for open() (in register form->filestat)
303
HA_GET_INFO does an implicit HA_ABORT_IF_LOCKED
306
#define HA_OPEN_KEYFILE 1
307
#define HA_OPEN_RNDFILE 2
308
#define HA_GET_INDEX 4
309
#define HA_GET_INFO 8 /* do a ha_info() after open */
310
#define HA_READ_ONLY 16 /* File opened as readonly */
311
/* Try readonly if can't open with read and write */
312
#define HA_TRY_READ_ONLY 32
313
#define HA_WAIT_IF_LOCKED 64 /* Wait if locked on open */
314
#define HA_ABORT_IF_LOCKED 128 /* skip if locked on open.*/
315
#define HA_BLOCK_LOCK 256 /* unlock when reading some records */
316
#define HA_OPEN_TEMPORARY 512
318
/* For transactional LOCK Table. handler::lock_table() */
319
#define HA_LOCK_IN_SHARE_MODE F_RDLCK
320
#define HA_LOCK_IN_EXCLUSIVE_MODE F_WRLCK
322
/* Some key definitions */
323
#define HA_KEY_NULL_LENGTH 1
324
#define HA_KEY_BLOB_LENGTH 2
326
#define HA_MAX_REC_LENGTH 65535
328
/* Options of START TRANSACTION statement (and later of SET TRANSACTION stmt) */
329
enum start_transaction_option_t
331
START_TRANS_NO_OPTIONS,
332
START_TRANS_OPT_WITH_CONS_SNAPSHOT
335
/* Flags for method is_fatal_error */
336
#define HA_CHECK_DUP_KEY 1
337
#define HA_CHECK_DUP_UNIQUE 2
338
#define HA_CHECK_DUP (HA_CHECK_DUP_KEY + HA_CHECK_DUP_UNIQUE)
341
/* Bits in used_fields */
342
#define HA_CREATE_USED_AUTO (1L << 0)
343
#define HA_CREATE_USED_CHARSET (1L << 8)
344
#define HA_CREATE_USED_DEFAULT_CHARSET (1L << 9)
345
#define HA_CREATE_USED_ROW_FORMAT (1L << 15)
348
The below two are not used (and not handled) in this milestone of this WL
349
entry because there seems to be no use for them at this stage of
352
#define HA_MRR_SINGLE_POINT 1
353
#define HA_MRR_FIXED_KEY 2
356
Indicates that RANGE_SEQ_IF::next(&range) doesn't need to fill in the
359
#define HA_MRR_NO_ASSOCIATION 4
362
The MRR user will provide ranges in key order, and MRR implementation
363
must return rows in key order.
365
#define HA_MRR_SORTED 8
367
/* MRR implementation doesn't have to retrieve full records */
368
#define HA_MRR_INDEX_ONLY 16
371
The passed memory buffer is of maximum possible size, the caller can't
372
assume larger buffer.
374
#define HA_MRR_LIMITS 32
378
Flag set <=> default MRR implementation is used
379
(The choice is made by **_info[_const]() function which may set this
380
flag. SQL layer remembers the flag value and then passes it to
381
multi_read_range_init().
383
#define HA_MRR_USE_DEFAULT_IMPL 64
386
#define MYF(v) (static_cast<drizzled::myf>(v))
389
"Declared Type Collation"
390
A combination of collation and its derivation.
392
Flags for collation aggregation modes:
393
MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset
394
MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
396
MY_COLL_ALLOW_CONV - allow any kind of conversion
397
(combination of the above two)
398
MY_COLL_DISALLOW_NONE - don't allow return DERIVATION_NONE
399
(e.g. when aggregating for comparison)
400
MY_COLL_CMP_CONV - combination of MY_COLL_ALLOW_CONV
401
and MY_COLL_DISALLOW_NONE
404
#define MY_COLL_ALLOW_SUPERSET_CONV 1
405
#define MY_COLL_ALLOW_COERCIBLE_CONV 2
406
#define MY_COLL_ALLOW_CONV 3
407
#define MY_COLL_DISALLOW_NONE 4
408
#define MY_COLL_CMP_CONV 7
409
#define clear_timestamp_auto_bits(_target_, _bits_) \
410
(_target_)= (enum timestamp_auto_set_type)((int)(_target_) & ~(int)(_bits_))
413
* The following are for the interface with the .frm file
416
#define FIELDFLAG_PACK_SHIFT 3
417
#define FIELDFLAG_MAX_DEC 31
419
#define MTYP_TYPENR(type) (type & 127) /* Remove bits from type */
421
#define f_settype(x) (((int) x) << FIELDFLAG_PACK_SHIFT)
425
template <class T> void set_if_bigger(T &a, const T &b)
431
template <class T> void set_if_smaller(T &a, const T &b)
438
#define set_if_bigger(a,b) do { \
439
const typeof(a) _a = (a); \
440
const typeof(b) _b = (b); \
441
(void) (&_a == &_b); \
442
if ((a) < (b)) (a)=(b); \
444
#define set_if_smaller(a,b) do { \
445
const typeof(a) _a = (a); \
446
const typeof(b) _b = (b); \
447
(void) (&_a == &_b); \
448
if ((a) > (b)) (a)=(b); \
452
#define set_if_bigger(a,b) do { if ((a) < (b)) (a)=(b); } while(0)
453
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
458
#define array_elements(a) \
459
((sizeof(a) / sizeof(*(a))) / \
460
static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
463
/* Some types that is different between systems */
466
#define FN_LIBCHAR '/'
467
#define FN_ROOTDIR "/"
469
#define MY_NFILE 64 /* This is only used to save filenames */
470
#ifndef OS_FILE_LIMIT
471
#define OS_FILE_LIMIT 65535
475
How much overhead does malloc have. The code often allocates
476
something like 1024-MALLOC_OVERHEAD bytes
478
#define MALLOC_OVERHEAD 8
480
/* get memory in huncs */
481
static const uint32_t ONCE_ALLOC_INIT= 4096;
482
/* Typical record cash */
483
static const uint32_t RECORD_CACHE_SIZE= 64*1024;
486
/* Some things that this system doesn't have */
488
/* Some defines of functions for portability */
490
#ifndef uint64_t2double
491
#define uint64_t2double(A) ((double) (uint64_t) (A))
495
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
497
#define ulong_to_double(X) ((double) (ulong) (X))
499
/* From limits.h instead */
501
#define DBL_MIN 4.94065645841246544e-324
504
#define DBL_MAX 1.79769313486231470e+308
508
/* Define missing math constants. */
510
#define M_PI 3.14159265358979323846
513
#define M_E 2.7182818284590452354
516
#define M_LN2 0.69314718055994530942
520
Max size that must be added to a so that we know Size to make
523
#define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1))
524
#define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double))
525
/* Size to make adressable obj. */
526
#define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
527
/* Offset of field f in structure t */
528
#define OFFSET(t, f) ((size_t)(char *)&((t *)0)->f)
530
#define ADD_TO_PTR(ptr,size,type) (type) (reinterpret_cast<const unsigned char*>(ptr)+size)
531
#define PTR_BYTE_DIFF(A,B) (ptrdiff_t) (reinterpret_cast<const unsigned char*>(A) - reinterpret_cast<const unsigned char*>(B))
533
#define ADD_TO_PTR(ptr,size,type) (type) ((unsigned char*) (ptr)+size)
534
#define PTR_BYTE_DIFF(A,B) (ptrdiff_t) ((unsigned char*) (A) - (unsigned char*) (B))
537
#define MY_DIV_UP(A, B) (((A) + (B) - 1) / (B))
538
#define MY_ALIGNED_BYTE_ARRAY(N, S, T) T N[MY_DIV_UP(S, sizeof(T))]
540
/* Typdefs for easyier portability */
543
#if defined(SIZEOF_OFF_T)
544
# if (SIZEOF_OFF_T == 8)
545
# define OFF_T_MAX (INT64_MAX)
547
# define OFF_T_MAX (INT32_MAX)
551
#define MY_FILEPOS_ERROR -1
553
#define DRIZZLE_SERVER
555
/* Length of decimal number represented by INT32. */
556
#define MY_INT32_NUM_DECIMAL_DIGITS 11
558
/* Length of decimal number represented by INT64. */
559
#define MY_INT64_NUM_DECIMAL_DIGITS 21
562
Io buffer size; Must be a power of 2 and
563
a multiple of 512. May be
564
smaller what the disk page size. This influences the speed of the
565
isam btree library. eg to big to slow.
568
/* Max file name len */
570
/* Max length of extension (part of FN_LEN) */
572
/* Max length of full path-name */
573
#define FN_REFLEN 512
574
/* File extension character */
575
#define FN_EXTCHAR '.'
576
/* ~ is used as abbrev for home dir */
577
#define FN_HOMELIB '~'
578
/* ./ is used as abbrev for current dir */
579
#define FN_CURLIB '.'
580
/* Parent directory; Must be a string */
581
#define FN_PARENTDIR ".."
583
/* Quote argument (before cpp) */
585
# define QUOTE_ARG(x) #x
587
/* Quote argument, (after cpp) */
588
#ifndef STRINGIFY_ARG
589
# define STRINGIFY_ARG(x) QUOTE_ARG(x)
593
* The macros below are borrowed from include/linux/compiler.h in the
594
* Linux kernel. Use them to indicate the likelyhood of the truthfulness
595
* of a condition. This serves two purposes - newer versions of gcc will be
596
* able to optimize for branch predication, which could yield siginficant
597
* performance gains in frequently executed sections of the code, and the
598
* other reason to use them is for documentation
600
#if !defined(__GNUC__)
601
#define __builtin_expect(x, expected_value) (x)
604
#define likely(x) __builtin_expect((x),1)
605
#define unlikely(x) __builtin_expect((x),0)
609
Only Linux is known to need an explicit sync of the directory to make sure a
610
file creation/deletion/renaming in(from,to) this directory durable.
612
#ifdef TARGET_OS_LINUX
613
#define NEED_EXPLICIT_SYNC_DIR 1
616
/* We need to turn off _DTRACE_VERSION if we're not going to use dtrace */
617
#if !defined(HAVE_DTRACE)
618
# undef _DTRACE_VERSION
619
# define _DTRACE_VERSION 0
622
} /* namespace drizzled */
624
#endif /* DRIZZLED_DEFINITIONS_H */