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, Inc.
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>
38
/* Global value for how we extend our temporary directory */
39
#define GLOBAL_TEMPORARY_EXT ".temporary"
41
/* These paths are converted to other systems (WIN95) before use */
43
#define LANGUAGE "english/"
44
#define TEMP_PREFIX "MY"
46
#define ER(X) ::drizzled::error_message((X))
48
/* buffer size for strerror_r() */
49
#define STRERROR_MAX 256
51
/* extra 4+4 bytes for slave tmp tables */
52
#define MAX_FIELD_NAME 34 /* Max colum name length +2 */
53
#define MAX_SYS_VAR_LENGTH 32
54
#define MAX_INDEXES 64
55
const uint32_t MAX_KEY = MAX_INDEXES; /* Max used keys */
56
const uint32_t MAX_REF_PARTS = 16; /* Max parts used as ref */
57
const uint32_t MAX_KEY_LENGTH = 4096; // max possible key
58
const uint32_t 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 */
66
#define MAX_MBWIDTH 4 /* Max multibyte sequence */
67
#define MAX_FIELD_CHARLENGTH 255
68
#define MAX_FIELD_VARCHARLENGTH 65535
69
#define CONVERT_IF_BIGGER_TO_BLOB 512 /* Used for CREATE ... SELECT */
71
/* Max column width +1 */
72
#define MAX_FIELD_WIDTH (MAX_FIELD_CHARLENGTH*MAX_MBWIDTH+1)
74
#define MAX_TABLES (sizeof(table_map)*8-3) /* Max tables in join */
75
#define PARAM_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-3))
76
#define OUTER_REF_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-2))
77
#define RAND_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-1))
78
#define PSEUDO_TABLE_BITS (PARAM_TABLE_BIT | OUTER_REF_TABLE_BIT | \
80
#define MAX_FIELDS 4096 /* Historical limit from MySQL FRM. */
82
#define MAX_SELECT_NESTING (sizeof(nesting_map)*8-1)
84
#define MAX_SORT_MEMORY (2048*1024-MALLOC_OVERHEAD)
85
#define MIN_SORT_MEMORY (32*1024-MALLOC_OVERHEAD)
87
#define DEFAULT_ERROR_COUNT 64
88
#define EXTRA_RECORDS 10 /* Extra records in sort */
89
#define NAMES_SEP_CHAR '\377' /* Char to sep. names */
91
#define READ_RECORD_BUFFER (uint32_t) (IO_SIZE*8) /* Pointer_buffer_size */
92
#define DISK_BUFFER_SIZE (uint32_t) (IO_SIZE*16) /* Size of diskbuffer */
94
#define ME_ERROR (ME_BELL+ME_OLDWIN+ME_NOREFRESH)
95
#define MYF_RW MYF(MY_WME+MY_NABP) /* Vid my_read & my_write */
98
Minimum length pattern before Turbo Boyer-Moore is used
99
for SELECT "text" LIKE "%pattern%", excluding the two
100
wildcards in class Item_func_like.
102
#define MIN_TURBOBM_PATTERN_LEN 3
104
/* Below are #defines that used to be in mysql_priv.h */
105
/***************************************************************************
106
Configuration parameters
107
****************************************************************************/
108
#define MAX_FIELDS_BEFORE_HASH 32
109
#define TABLE_OPEN_CACHE_MIN 64
110
#define TABLE_OPEN_CACHE_DEFAULT 1024
113
Value of 9236 discovered through binary search 2006-09-26 on Ubuntu Dapper
114
Drake, libc6 2.3.6-0ubuntu2, Linux kernel 2.6.15-27-686, on x86. (Added
115
100 bytes as reasonable buffer against growth and other environments'
118
Feel free to raise this by the smallest amount you can to get the
119
"execution_constants" test to pass.
121
#define STACK_MIN_SIZE 12000 ///< Abort if less stack during eval.
123
#define STACK_MIN_SIZE_FOR_OPEN 1024*80
124
#define STACK_BUFF_ALLOC 352 ///< For stack overrun checks
126
#define QUERY_ALLOC_BLOCK_SIZE 8192
127
#define QUERY_ALLOC_PREALLOC_SIZE 8192
128
#define RANGE_ALLOC_BLOCK_SIZE 4096
129
#define TABLE_ALLOC_BLOCK_SIZE 1024
130
#define WARN_ALLOC_BLOCK_SIZE 2048
131
#define WARN_ALLOC_PREALLOC_SIZE 1024
134
The following parameters is to decide when to use an extra cache to
135
optimise seeks when reading a big table in sorted order
137
#define MIN_FILE_LENGTH_TO_USE_ROW_CACHE (10L*1024*1024)
138
#define MIN_ROWS_TO_USE_TABLE_CACHE 100
141
The following is used to decide if MySQL should use table scanning
142
instead of reading with keys. The number says how many evaluation of the
143
WHERE clause is comparable to reading one extra row from a table.
145
#define TIME_FOR_COMPARE 5 // 5 compares == one read
148
Number of comparisons of table rowids equivalent to reading one row from a
151
#define TIME_FOR_COMPARE_ROWID (TIME_FOR_COMPARE*2)
154
For sequential disk seeks the cost formula is:
155
DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip
157
The cost of average seek
158
DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST*BLOCKS_IN_AVG_SEEK =1.0.
160
#define DISK_SEEK_BASE_COST ((double)0.9)
162
#define BLOCKS_IN_AVG_SEEK 128
164
#define DISK_SEEK_PROP_COST ((double)0.1/BLOCKS_IN_AVG_SEEK)
168
Number of rows in a reference table when refereed through a not unique key.
169
This value is only used when we don't know anything about the key
172
#define MATCHING_ROWS_IN_OTHER_TABLE 10
174
/** Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used). */
175
#define KEY_DEFAULT_PACK_LENGTH 8
177
/** Characters shown for the command in 'show processlist'. */
178
#define PROCESS_LIST_WIDTH 100
180
/* Bits for different SQL modes modes (including ANSI mode) */
181
#define MODE_NO_ZERO_DATE (2)
182
#define MODE_INVALID_DATES (MODE_NO_ZERO_DATE*2)
184
#define MY_CHARSET_BIN_MB_MAXLEN 1
187
static const uint32_t UNCACHEABLE_DEPENDENT= 1;
188
static const uint32_t UNCACHEABLE_RAND= 2;
189
static const uint32_t UNCACHEABLE_SIDEEFFECT= 3;
190
/// forcing to save JOIN for explain
191
static const uint32_t UNCACHEABLE_EXPLAIN= 4;
192
/** Don't evaluate subqueries in prepare even if they're not correlated */
193
static const uint32_t UNCACHEABLE_PREPARE= 5;
194
/* For uncorrelated SELECT in an UNION with some correlated SELECTs */
195
static const uint32_t UNCACHEABLE_UNITED= 6;
197
/* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */
198
#define UNDEF_POS (-1)
200
/* Options to add_table_to_list() */
201
static const uint32_t TL_OPTION_UPDATING= 0;
202
static const uint32_t TL_OPTION_FORCE_INDEX= 1;
203
static const uint32_t TL_OPTION_IGNORE_LEAVES= 2;
204
static const uint32_t TL_OPTION_ALIAS= 3;
205
static const uint32_t NUM_OF_TABLE_OPTIONS= 4;
207
/* Some portable defines */
209
#define portable_sizeof_char_ptr 8
211
#define TMP_FILE_PREFIX "#sql" /**< Prefix for tmp tables */
212
#define TMP_FILE_PREFIX_LENGTH 4
214
/* Flags for calc_week() function. */
215
#define WEEK_MONDAY_FIRST 1
217
#define WEEK_FIRST_WEEKDAY 4
219
/* used in date and time conversions */
220
/* Daynumber from year 0 to 9999-12-31 */
221
#define MAX_DAY_NUMBER 3652424L
223
#define STRING_BUFFER_USUAL_SIZE 80
225
typedef void *range_seq_t;
227
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
228
// the following is for checking tables
230
#define HA_ADMIN_ALREADY_DONE 1
231
#define HA_ADMIN_OK 0
232
#define HA_ADMIN_NOT_IMPLEMENTED -1
233
#define HA_ADMIN_FAILED -2
234
#define HA_ADMIN_CORRUPT -3
235
#define HA_ADMIN_INTERNAL_ERROR -4
236
#define HA_ADMIN_INVALID -5
237
#define HA_ADMIN_REJECT -6
239
/* bits in index_flags(index_number) for what you can do with index */
240
#define HA_READ_NEXT 1 /* TODO really use this flag */
241
#define HA_READ_PREV 2 /* supports ::index_prev */
242
#define HA_READ_ORDER 4 /* index_next/prev follow sort order */
243
#define HA_READ_RANGE 8 /* can find all records in a range */
244
#define HA_ONLY_WHOLE_INDEX 16 /* Can't use part key searches */
245
#define HA_KEYREAD_ONLY 64 /* Support HA_EXTRA_KEYREAD */
247
Index scan will not return records in rowid order. Not guaranteed to be
248
set for unordered (e.g. HASH) indexes.
250
#define HA_KEY_SCAN_NOT_ROR 128
252
/* operations for disable/enable indexes */
253
#define HA_KEY_SWITCH_NONUNIQ 0
254
#define HA_KEY_SWITCH_ALL 1
255
#define HA_KEY_SWITCH_NONUNIQ_SAVE 2
256
#define HA_KEY_SWITCH_ALL_SAVE 3
259
Parameters for open() (in register form->filestat)
260
HA_GET_INFO does an implicit HA_ABORT_IF_LOCKED
263
#define HA_OPEN_KEYFILE 1
264
#define HA_OPEN_RNDFILE 2
265
#define HA_GET_INDEX 4
266
#define HA_GET_INFO 8 /* do a ha_info() after open */
267
#define HA_READ_ONLY 16 /* File opened as readonly */
268
/* Try readonly if can't open with read and write */
269
#define HA_TRY_READ_ONLY 32
270
#define HA_WAIT_IF_LOCKED 64 /* Wait if locked on open */
271
#define HA_ABORT_IF_LOCKED 128 /* skip if locked on open.*/
272
#define HA_BLOCK_LOCK 256 /* unlock when reading some records */
273
#define HA_OPEN_TEMPORARY 512
275
/* Some key definitions */
276
#define HA_KEY_NULL_LENGTH 1
277
#define HA_KEY_BLOB_LENGTH 2
279
const uint32_t HA_MAX_REC_LENGTH = 65535;
281
/* Options of START TRANSACTION statement (and later of SET TRANSACTION stmt) */
282
enum start_transaction_option_t
284
START_TRANS_NO_OPTIONS,
285
START_TRANS_OPT_WITH_CONS_SNAPSHOT
288
/* Flags for method is_fatal_error */
289
#define HA_CHECK_DUP_KEY 1
290
#define HA_CHECK_DUP_UNIQUE 2
291
#define HA_CHECK_DUP (HA_CHECK_DUP_KEY + HA_CHECK_DUP_UNIQUE)
294
/* Bits in used_fields */
295
#define HA_CREATE_USED_AUTO (1L << 0)
296
#define HA_CREATE_USED_CHARSET (1L << 8)
297
#define HA_CREATE_USED_DEFAULT_CHARSET (1L << 9)
300
The below two are not used (and not handled) in this milestone of this WL
301
entry because there seems to be no use for them at this stage of
304
#define HA_MRR_SINGLE_POINT 1
305
#define HA_MRR_FIXED_KEY 2
308
Indicates that RANGE_SEQ_IF::next(&range) doesn't need to fill in the
311
#define HA_MRR_NO_ASSOCIATION 4
314
The MRR user will provide ranges in key order, and MRR implementation
315
must return rows in key order.
317
#define HA_MRR_SORTED 8
319
/* MRR implementation doesn't have to retrieve full records */
320
#define HA_MRR_INDEX_ONLY 16
323
The passed memory buffer is of maximum possible size, the caller can't
324
assume larger buffer.
326
#define HA_MRR_LIMITS 32
330
Flag set <=> default MRR implementation is used
331
(The choice is made by **_info[_const]() function which may set this
332
flag. SQL layer remembers the flag value and then passes it to
333
multi_read_range_init().
335
#define HA_MRR_USE_DEFAULT_IMPL 64
338
#define MYF(v) (static_cast<drizzled::myf>(v))
341
"Declared Type Collation"
342
A combination of collation and its derivation.
344
Flags for collation aggregation modes:
345
MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset
346
MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
348
MY_COLL_ALLOW_CONV - allow any kind of conversion
349
(combination of the above two)
350
MY_COLL_DISALLOW_NONE - don't allow return DERIVATION_NONE
351
(e.g. when aggregating for comparison)
352
MY_COLL_CMP_CONV - combination of MY_COLL_ALLOW_CONV
353
and MY_COLL_DISALLOW_NONE
356
#define MY_COLL_ALLOW_SUPERSET_CONV 1
357
#define MY_COLL_ALLOW_COERCIBLE_CONV 2
358
#define MY_COLL_ALLOW_CONV 3
359
#define MY_COLL_DISALLOW_NONE 4
360
#define MY_COLL_CMP_CONV 7
362
inline static void clear_timestamp_auto_bits(timestamp_auto_set_type &_target_,
363
timestamp_auto_set_type _bits_)
365
_target_= static_cast<timestamp_auto_set_type>(_target_ & ~_bits_);
369
* The following are for the interface with the .frm file
372
#define FIELDFLAG_PACK_SHIFT 3
373
#define FIELDFLAG_MAX_DEC 31
376
// FIXME: T will just be drizzled::Field::utype, but that would
377
// require including field.h. Moving the function elsewhere might be a
378
// better idea. Leaving it for restructuring.
379
template <typename T>
380
T MTYP_TYPENR(const T& type)
382
return static_cast<T>(type & 127);
385
#define MTYP_TYPENR(type) (type & 127) /* Remove bits from type */
388
inline static uint32_t f_settype(const enum enum_field_types x)
390
return (uint32_t(x) << FIELDFLAG_PACK_SHIFT);
394
template <class T> void set_if_bigger(T &a, const T &b)
400
template <class T> void set_if_smaller(T &a, const T &b)
406
template<class T> inline void safe_delete(T*& ptr)
413
#define set_if_bigger(a,b) do { \
414
const typeof(a) _a = (a); \
415
const typeof(b) _b = (b); \
416
(void) (&_a == &_b); \
417
if ((a) < (b)) (a)=(b); \
419
#define set_if_smaller(a,b) do { \
420
const typeof(a) _a = (a); \
421
const typeof(b) _b = (b); \
422
(void) (&_a == &_b); \
423
if ((a) > (b)) (a)=(b); \
427
#define set_if_bigger(a,b) do { if ((a) < (b)) (a)=(b); } while(0)
428
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
433
#define array_elements(a) \
434
((sizeof(a) / sizeof(*(a))) / \
435
static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
438
/* Some types that is different between systems */
441
#define FN_LIBCHAR '/'
442
#define FN_ROOTDIR "/"
444
#define MY_NFILE 64 /* This is only used to save filenames */
445
#ifndef OS_FILE_LIMIT
446
#define OS_FILE_LIMIT 65535
450
How much overhead does malloc have. The code often allocates
451
something like 1024-MALLOC_OVERHEAD bytes
453
#define MALLOC_OVERHEAD 8
455
/* get memory in huncs */
456
static const uint32_t ONCE_ALLOC_INIT= 4096;
457
/* Typical record cash */
458
static const uint32_t RECORD_CACHE_SIZE= 64*1024;
461
/* Some things that this system doesn't have */
463
/* Some defines of functions for portability */
465
#ifndef uint64_t2double
466
#define uint64_t2double(A) ((double) (uint64_t) (A))
469
#ifndef int64_t2double
470
#define int64_t2double(A) ((double) (int64_t) (A))
474
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
477
/* From limits.h instead */
479
#define DBL_MIN 4.94065645841246544e-324
482
#define DBL_MAX 1.79769313486231470e+308
486
/* Define missing math constants. */
488
#define M_PI 3.14159265358979323846
491
#define M_E 2.7182818284590452354
494
#define M_LN2 0.69314718055994530942
498
Max size that must be added to a so that we know Size to make
501
#define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1))
502
#define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double))
504
#define ADD_TO_PTR(ptr,size,type) (type) (reinterpret_cast<const unsigned char*>(ptr)+size)
506
#define ADD_TO_PTR(ptr,size,type) (type) ((unsigned char*) (ptr)+size)
509
#define MY_DIV_UP(A, B) (((A) + (B) - 1) / (B))
510
#define MY_ALIGNED_BYTE_ARRAY(N, S, T) T N[MY_DIV_UP(S, sizeof(T))]
512
/* Typdefs for easyier portability */
515
#if defined(SIZEOF_OFF_T)
516
# if (SIZEOF_OFF_T == 8)
517
# define OFF_T_MAX (INT64_MAX)
519
# define OFF_T_MAX (INT32_MAX)
523
#define MY_FILEPOS_ERROR -1
525
#define DRIZZLE_SERVER
527
/* Length of decimal number represented by INT32. */
528
#define MY_INT32_NUM_DECIMAL_DIGITS 11
530
/* Length of decimal number represented by INT64. */
531
#define MY_INT64_NUM_DECIMAL_DIGITS 21
534
Io buffer size; Must be a power of 2 and
535
a multiple of 512. May be
536
smaller what the disk page size. This influences the speed of the
537
isam btree library. eg to big to slow.
540
/* Max file name len */
542
/* Max length of full path-name */
543
#define FN_REFLEN 512
544
/* File extension character */
545
#define FN_EXTCHAR '.'
546
/* ~ is used as abbrev for home dir */
547
#define FN_HOMELIB '~'
548
/* ./ is used as abbrev for current dir */
549
#define FN_CURLIB '.'
550
/* Parent directory; Must be a string */
551
#define FN_PARENTDIR ".."
553
/* Quote argument (before cpp) */
555
# define QUOTE_ARG(x) #x
557
/* Quote argument, (after cpp) */
558
#ifndef STRINGIFY_ARG
559
# define STRINGIFY_ARG(x) QUOTE_ARG(x)
563
* The macros below are borrowed from include/linux/compiler.h in the
564
* Linux kernel. Use them to indicate the likelyhood of the truthfulness
565
* of a condition. This serves two purposes - newer versions of gcc will be
566
* able to optimize for branch predication, which could yield siginficant
567
* performance gains in frequently executed sections of the code, and the
568
* other reason to use them is for documentation
570
#if !defined(__GNUC__)
571
#define __builtin_expect(x, expected_value) (x)
574
#define likely(x) __builtin_expect((x),1)
575
#define unlikely(x) __builtin_expect((x),0)
579
Only Linux is known to need an explicit sync of the directory to make sure a
580
file creation/deletion/renaming in(from,to) this directory durable.
582
#ifdef TARGET_OS_LINUX
583
#define NEED_EXPLICIT_SYNC_DIR 1
586
/* We need to turn off _DTRACE_VERSION if we're not going to use dtrace */
587
#if !defined(HAVE_DTRACE)
588
# undef _DTRACE_VERSION
589
# define _DTRACE_VERSION 0
592
typedef uint64_t table_map; /* Used for table bits in join */
593
typedef uint32_t nesting_map; /* Used for flags of nesting constructs */
595
} /* namespace drizzled */
597
#endif /* DRIZZLED_DEFINITIONS_H */