Drizzled Public API Documentation

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