drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
definitions.h
Go to the documentation of this file.
1/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2008 Sun Microsystems, Inc.
5 *
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.
9 *
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.
14 *
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
18 */
19
25
26#pragma once
27
28#include <drizzled/enum.h>
29
30#include <stdint.h>
31
32#include "common.h"
33
34namespace drizzled
35{
36
37/* Global value for how we extend our temporary directory */
38#define GLOBAL_TEMPORARY_EXT ".temporary"
39
40#define LANGUAGE "english/"
41#define TEMP_PREFIX "MY"
42
43#define ER(X) ::drizzled::error_message((X))
44
45/* buffer size for strerror_r() */
46#define STRERROR_MAX 256
47
48/* extra 4+4 bytes for slave tmp tables */
49#define MAX_FIELD_NAME 34 /* Max colum name length +2 */
50#define MAX_SYS_VAR_LENGTH 32
51#define MAX_INDEXES 64
52const uint32_t MAX_KEY = MAX_INDEXES; /* Max used keys */
53const uint32_t MAX_REF_PARTS = 16; /* Max parts used as ref */
54const uint32_t MAX_KEY_LENGTH = 4096; // max possible key
55const uint32_t MAX_KEY_LENGTH_DECIMAL_WIDTH = 4; // strlen("4096")
56
57#if SIZEOF_OFF_T > 4
58#define MAX_REFLENGTH 8 /* Max length for record ref */
59#else
60#define MAX_REFLENGTH 4 /* Max length for record ref */
61#endif
62
63#define MAX_MBWIDTH 4 /* Max multibyte sequence */
64#define MAX_FIELD_CHARLENGTH 255
65#define MAX_FIELD_VARCHARLENGTH 65535
66#define CONVERT_IF_BIGGER_TO_BLOB 512 /* Used for CREATE ... SELECT */
67
68/* Max column width +1 */
69#define MAX_FIELD_WIDTH (MAX_FIELD_CHARLENGTH*MAX_MBWIDTH+1)
70
71#define MAX_TABLES (sizeof(table_map)*8-3) /* Max tables in join */
72#define PARAM_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-3))
73#define OUTER_REF_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-2))
74#define RAND_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-1))
75#define PSEUDO_TABLE_BITS (PARAM_TABLE_BIT | OUTER_REF_TABLE_BIT | \
76 RAND_TABLE_BIT)
77#define MAX_FIELDS 4096 /* Historical limit from MySQL FRM. */
78
79#define MAX_SELECT_NESTING (sizeof(nesting_map)*8-1)
80
81#define MAX_SORT_MEMORY (2048*1024-MALLOC_OVERHEAD)
82#define MIN_SORT_MEMORY (32*1024-MALLOC_OVERHEAD)
83
84#define DEFAULT_ERROR_COUNT 64
85#define EXTRA_RECORDS 10 /* Extra records in sort */
86#define NAMES_SEP_CHAR '\377' /* Char to sep. names */
87
88#define READ_RECORD_BUFFER (uint32_t) (IO_SIZE*8) /* Pointer_buffer_size */
89#define DISK_BUFFER_SIZE (uint32_t) (IO_SIZE*16) /* Size of diskbuffer */
90
91#define ME_ERROR (ME_BELL+ME_OLDWIN+ME_NOREFRESH)
92#define MYF_RW MYF(MY_WME+MY_NABP) /* Vid my_read & my_write */
93
94/*
95 Minimum length pattern before Turbo Boyer-Moore is used
96 for SELECT "text" LIKE "%pattern%", excluding the two
97 wildcards in class Item_func_like.
98*/
99#define MIN_TURBOBM_PATTERN_LEN 3
100
101/* Below are #defines that used to be in mysql_priv.h */
102/***************************************************************************
103 Configuration parameters
104****************************************************************************/
105#define MAX_FIELDS_BEFORE_HASH 32
106#define TABLE_OPEN_CACHE_MIN 64
107#define TABLE_OPEN_CACHE_DEFAULT 1024
108
109/*
110 Value of 9236 discovered through binary search 2006-09-26 on Ubuntu Dapper
111 Drake, libc6 2.3.6-0ubuntu2, Linux kernel 2.6.15-27-686, on x86. (Added
112 100 bytes as reasonable buffer against growth and other environments'
113 requirements.)
114
115 Feel free to raise this by the smallest amount you can to get the
116 "execution_constants" test to pass.
117 */
118#define STACK_MIN_SIZE 12000
119
120#define STACK_MIN_SIZE_FOR_OPEN 1024*80
121#define STACK_BUFF_ALLOC 352
122
123#define QUERY_ALLOC_BLOCK_SIZE 8192
124#define QUERY_ALLOC_PREALLOC_SIZE 8192
125#define RANGE_ALLOC_BLOCK_SIZE 4096
126#define TABLE_ALLOC_BLOCK_SIZE 1024
127#define WARN_ALLOC_BLOCK_SIZE 2048
128#define WARN_ALLOC_PREALLOC_SIZE 1024
129
130/*
131 The following parameters is to decide when to use an extra cache to
132 optimise seeks when reading a big table in sorted order
133*/
134#define MIN_FILE_LENGTH_TO_USE_ROW_CACHE (10L*1024*1024)
135#define MIN_ROWS_TO_USE_TABLE_CACHE 100
136
142#define TIME_FOR_COMPARE 5 // 5 compares == one read
143
148#define TIME_FOR_COMPARE_ROWID (TIME_FOR_COMPARE*2)
149
150/*
151 For sequential disk seeks the cost formula is:
152 DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip
153
154 The cost of average seek
155 DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST*BLOCKS_IN_AVG_SEEK =1.0.
156*/
157#define DISK_SEEK_BASE_COST ((double)0.9)
158
159#define BLOCKS_IN_AVG_SEEK 128
160
161#define DISK_SEEK_PROP_COST ((double)0.1/BLOCKS_IN_AVG_SEEK)
162
163
169#define MATCHING_ROWS_IN_OTHER_TABLE 10
170
172#define KEY_DEFAULT_PACK_LENGTH 8
173
175#define PROCESS_LIST_WIDTH 100
176
177/* Bits for different SQL modes modes (including ANSI mode) */
178#define MODE_NO_ZERO_DATE (2)
179#define MODE_INVALID_DATES (MODE_NO_ZERO_DATE*2)
180
181#define MY_CHARSET_BIN_MB_MAXLEN 1
182
183// uncachable cause
184static const uint32_t UNCACHEABLE_DEPENDENT= 1;
185static const uint32_t UNCACHEABLE_RAND= 2;
186static const uint32_t UNCACHEABLE_SIDEEFFECT= 3;
188static const uint32_t UNCACHEABLE_EXPLAIN= 4;
190static const uint32_t UNCACHEABLE_PREPARE= 5;
191/* For uncorrelated SELECT in an UNION with some correlated SELECTs */
192static const uint32_t UNCACHEABLE_UNITED= 6;
193
194/* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */
195#define UNDEF_POS (-1)
196
197/* Options to add_table_to_list() */
198static const uint32_t TL_OPTION_UPDATING= 0;
199static const uint32_t TL_OPTION_FORCE_INDEX= 1;
200static const uint32_t TL_OPTION_IGNORE_LEAVES= 2;
201static const uint32_t TL_OPTION_ALIAS= 3;
202static const uint32_t NUM_OF_TABLE_OPTIONS= 4;
203
204/* Some portable defines */
205
206#define portable_sizeof_char_ptr 8
207
208#define TMP_FILE_PREFIX "#sql"
209#define TMP_FILE_PREFIX_LENGTH 4
210
211/* Flags for calc_week() function. */
212#define WEEK_MONDAY_FIRST 1
213#define WEEK_YEAR 2
214#define WEEK_FIRST_WEEKDAY 4
215
216/* used in date and time conversions */
217/* Daynumber from year 0 to 9999-12-31 */
218#define MAX_DAY_NUMBER 3652424L
219
220#define STRING_BUFFER_USUAL_SIZE 80
221
222typedef void *range_seq_t;
223
224enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
225// the following is for checking tables
226
227#define HA_ADMIN_ALREADY_DONE 1
228#define HA_ADMIN_OK 0
229#define HA_ADMIN_NOT_IMPLEMENTED -1
230#define HA_ADMIN_FAILED -2
231#define HA_ADMIN_CORRUPT -3
232#define HA_ADMIN_INTERNAL_ERROR -4
233#define HA_ADMIN_INVALID -5
234#define HA_ADMIN_REJECT -6
235
236/* bits in index_flags(index_number) for what you can do with index */
237#define HA_READ_NEXT 1 /* TODO really use this flag */
238#define HA_READ_PREV 2 /* supports ::index_prev */
239#define HA_READ_ORDER 4 /* index_next/prev follow sort order */
240#define HA_READ_RANGE 8 /* can find all records in a range */
241#define HA_ONLY_WHOLE_INDEX 16 /* Can't use part key searches */
242#define HA_KEYREAD_ONLY 64 /* Support HA_EXTRA_KEYREAD */
243/*
244 Index scan will not return records in rowid order. Not guaranteed to be
245 set for unordered (e.g. HASH) indexes.
246*/
247#define HA_KEY_SCAN_NOT_ROR 128
248
249/* operations for disable/enable indexes */
250#define HA_KEY_SWITCH_NONUNIQ 0
251#define HA_KEY_SWITCH_ALL 1
252#define HA_KEY_SWITCH_NONUNIQ_SAVE 2
253#define HA_KEY_SWITCH_ALL_SAVE 3
254
255/*
256 Parameters for open() (in register form->filestat)
257 HA_GET_INFO does an implicit HA_ABORT_IF_LOCKED
258*/
259
260#define HA_OPEN_KEYFILE 1
261#define HA_OPEN_RNDFILE 2
262#define HA_GET_INDEX 4
263#define HA_GET_INFO 8 /* do a ha_info() after open */
264#define HA_READ_ONLY 16 /* File opened as readonly */
265/* Try readonly if can't open with read and write */
266#define HA_TRY_READ_ONLY 32
267#define HA_WAIT_IF_LOCKED 64 /* Wait if locked on open */
268#define HA_ABORT_IF_LOCKED 128 /* skip if locked on open.*/
269#define HA_BLOCK_LOCK 256 /* unlock when reading some records */
270#define HA_OPEN_TEMPORARY 512
271
272/* Some key definitions */
273#define HA_KEY_NULL_LENGTH 1
274#define HA_KEY_BLOB_LENGTH 2
275
276const uint32_t HA_MAX_REC_LENGTH = 65535;
277
278/* Options of START TRANSACTION statement (and later of SET TRANSACTION stmt) */
279enum start_transaction_option_t
280{
281 START_TRANS_NO_OPTIONS,
282 START_TRANS_OPT_WITH_CONS_SNAPSHOT
283};
284
285/* Flags for method is_fatal_error */
286#define HA_CHECK_DUP_KEY 1
287#define HA_CHECK_DUP_UNIQUE 2
288#define HA_CHECK_DUP (HA_CHECK_DUP_KEY + HA_CHECK_DUP_UNIQUE)
289
290
291/* Bits in used_fields */
292#define HA_CREATE_USED_AUTO (1L << 0)
293#define HA_CREATE_USED_CHARSET (1L << 8)
294#define HA_CREATE_USED_DEFAULT_CHARSET (1L << 9)
295
296/*
297 The below two are not used (and not handled) in this milestone of this WL
298 entry because there seems to be no use for them at this stage of
299 implementation.
300*/
301#define HA_MRR_SINGLE_POINT 1
302#define HA_MRR_FIXED_KEY 2
303
304/*
305 Indicates that RANGE_SEQ_IF::next(&range) doesn't need to fill in the
306 'range' parameter.
307*/
308#define HA_MRR_NO_ASSOCIATION 4
309
310/*
311 The MRR user will provide ranges in key order, and MRR implementation
312 must return rows in key order.
313*/
314#define HA_MRR_SORTED 8
315
316/* MRR implementation doesn't have to retrieve full records */
317#define HA_MRR_INDEX_ONLY 16
318
319/*
320 The passed memory buffer is of maximum possible size, the caller can't
321 assume larger buffer.
322*/
323#define HA_MRR_LIMITS 32
324
325
326/*
327 Flag set <=> default MRR implementation is used
328 (The choice is made by **_info[_const]() function which may set this
329 flag. SQL layer remembers the flag value and then passes it to
330 multi_read_range_init().
331*/
332#define HA_MRR_USE_DEFAULT_IMPL 64
333
334typedef int myf;
335#define MYF(v) (static_cast<drizzled::myf>(v))
336
337/*
338 "Declared Type Collation"
339 A combination of collation and its derivation.
340
341 Flags for collation aggregation modes:
342 MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset
343 MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
344 (i.e. constant).
345 MY_COLL_ALLOW_CONV - allow any kind of conversion
346 (combination of the above two)
347 MY_COLL_DISALLOW_NONE - don't allow return DERIVATION_NONE
348 (e.g. when aggregating for comparison)
349 MY_COLL_CMP_CONV - combination of MY_COLL_ALLOW_CONV
350 and MY_COLL_DISALLOW_NONE
351*/
352
353#define MY_COLL_ALLOW_SUPERSET_CONV 1
354#define MY_COLL_ALLOW_COERCIBLE_CONV 2
355#define MY_COLL_ALLOW_CONV 3
356#define MY_COLL_DISALLOW_NONE 4
357#define MY_COLL_CMP_CONV 7
358
359inline static void clear_timestamp_auto_bits(timestamp_auto_set_type &_target_,
360 timestamp_auto_set_type _bits_)
361{
362 _target_= static_cast<timestamp_auto_set_type>(_target_ & ~_bits_);
363}
364
365/*
366 * The following are for the interface with the .frm file
367 */
368
369#define FIELDFLAG_PACK_SHIFT 3
370#define FIELDFLAG_MAX_DEC 31
371
372#ifdef __cplusplus
373// FIXME: T will just be drizzled::Field::utype, but that would
374// require including field.h. Moving the function elsewhere might be a
375// better idea. Leaving it for restructuring.
376template <typename T>
377T MTYP_TYPENR(const T& type)
378{
379 return static_cast<T>(type & 127);
380}
381#else
382#define MTYP_TYPENR(type) (type & 127) /* Remove bits from type */
383#endif
384
385inline static uint32_t f_settype(const enum enum_field_types x)
386{
387 return (uint32_t(x) << FIELDFLAG_PACK_SHIFT);
388}
389
390#ifdef __cplusplus
391template <class T> void set_if_bigger(T &a, const T &b)
392{
393 if (a < b)
394 a=b;
395}
396
397template <class T> void set_if_smaller(T &a, const T &b)
398{
399 if (a > b)
400 a=b;
401}
402#else
403#define set_if_bigger(a,b) do { \
404 const typeof(a) _a = (a); \
405 const typeof(b) _b = (b); \
406 (void) (&_a == &_b); \
407 if ((a) < (b)) (a)=(b); \
408 } while(0)
409#define set_if_smaller(a,b) do { \
410 const typeof(a) _a = (a); \
411 const typeof(b) _b = (b); \
412 (void) (&_a == &_b); \
413 if ((a) > (b)) (a)=(b); \
414 } while(0)
415#endif
416
417template<class T> inline void safe_delete(T*& ptr)
418{
419 delete ptr;
420 ptr = 0;
421}
422
423#define array_elements(a) \
424 ((sizeof(a) / sizeof(*(a))) / \
425 static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
426
427#define FN_LIBCHAR '/'
428
429/*
430 How much overhead does malloc have. The code often allocates
431 something like 1024-MALLOC_OVERHEAD bytes
432*/
433#define MALLOC_OVERHEAD 8
434
435/* get memory in huncs */
436static const uint32_t ONCE_ALLOC_INIT= 4096;
437/* Typical record cash */
438static const uint32_t RECORD_CACHE_SIZE= 64*1024;
439
440
441/* Some things that this system doesn't have */
442
443/* Some defines of functions for portability */
444
445#ifndef uint64_t2double
446#define uint64_t2double(A) ((double) (uint64_t) (A))
447#endif
448
449#ifndef int64_t2double
450#define int64_t2double(A) ((double) (int64_t) (A))
451#endif
452
453#ifndef offsetof
454#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
455#endif
456
457/* From limits.h instead */
458#ifndef DBL_MIN
459#define DBL_MIN 4.94065645841246544e-324
460#endif
461#ifndef DBL_MAX
462#define DBL_MAX 1.79769313486231470e+308
463#endif
464
465
466/* Define missing math constants. */
467#ifndef M_PI
468#define M_PI 3.14159265358979323846
469#endif
470#ifndef M_E
471#define M_E 2.7182818284590452354
472#endif
473#ifndef M_LN2
474#define M_LN2 0.69314718055994530942
475#endif
476
477/*
478 Max size that must be added to a so that we know Size to make
479 adressable obj.
480*/
481#define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1))
482#define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double))
483#ifdef __cplusplus
484#define ADD_TO_PTR(ptr,size,type) (type) (reinterpret_cast<const unsigned char*>(ptr)+size)
485#else
486 #define ADD_TO_PTR(ptr,size,type) (type) ((unsigned char*) (ptr)+size)
487#endif
488
489#define MY_DIV_UP(A, B) (((A) + (B) - 1) / (B))
490#define MY_ALIGNED_BYTE_ARRAY(N, S, T) T N[MY_DIV_UP(S, sizeof(T))]
491
492/* Typdefs for easyier portability */
493
494
495#if defined(SIZEOF_OFF_T)
496# if (SIZEOF_OFF_T == 8)
497# define OFF_T_MAX (INT64_MAX)
498# else
499# define OFF_T_MAX (INT32_MAX)
500# endif
501#endif
502
503#define MY_FILEPOS_ERROR -1
504
505#define DRIZZLE_SERVER
506
507/* Length of decimal number represented by INT32. */
508#define MY_INT32_NUM_DECIMAL_DIGITS 11
509
510/* Length of decimal number represented by INT64. */
511#define MY_INT64_NUM_DECIMAL_DIGITS 21
512
513/*
514 Io buffer size; Must be a power of 2 and
515 a multiple of 512. May be
516 smaller what the disk page size. This influences the speed of the
517 isam btree library. eg to big to slow.
518*/
519#define IO_SIZE 4096
520/* Max file name len */
521#define FN_LEN 256
522/* Max length of full path-name */
523#define FN_REFLEN 512
524/* File extension character */
525#define FN_EXTCHAR '.'
526/* ~ is used as abbrev for home dir */
527#define FN_HOMELIB '~'
528/* ./ is used as abbrev for current dir */
529#define FN_CURLIB '.'
530/* Parent directory; Must be a string */
531#define FN_PARENTDIR ".."
532
533/* Quote argument (before cpp) */
534#ifndef QUOTE_ARG
535# define QUOTE_ARG(x) #x
536#endif
537/* Quote argument, (after cpp) */
538#ifndef STRINGIFY_ARG
539# define STRINGIFY_ARG(x) QUOTE_ARG(x)
540#endif
541
542/*
543 * The macros below are borrowed from include/linux/compiler.h in the
544 * Linux kernel. Use them to indicate the likelyhood of the truthfulness
545 * of a condition. This serves two purposes - newer versions of gcc will be
546 * able to optimize for branch predication, which could yield siginficant
547 * performance gains in frequently executed sections of the code, and the
548 * other reason to use them is for documentation
549 */
550#define DRIZZLE_LIKELY(x) __builtin_expect((x),1)
551#define DRIZZLE_UNLIKELY(x) __builtin_expect((x),0)
552
553
554/*
555 Only Linux is known to need an explicit sync of the directory to make sure a
556 file creation/deletion/renaming in(from,to) this directory durable.
557*/
558#define NEED_EXPLICIT_SYNC_DIR 1
559
560/* We need to turn off _DTRACE_VERSION if we're not going to use dtrace */
561# undef _DTRACE_VERSION
562# define _DTRACE_VERSION 0
563
564typedef uint64_t table_map; /* Used for table bits in join */
565typedef uint32_t nesting_map; /* Used for flags of nesting constructs */
566
567} /* namespace drizzled */
Convert from decimal to binary representation.
Definition common_fwd.h:215
TODO: Rename this file - func.h is stupid.
static const uint32_t UNCACHEABLE_EXPLAIN
forcing to save JOIN for explain
static const uint32_t UNCACHEABLE_PREPARE