~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/base.h

  • Committer: Jay Pipes
  • Date: 2009-09-15 21:01:42 UTC
  • mto: (1126.2.5 merge)
  • mto: This revision was merged to the branch mainline in revision 1128.
  • Revision ID: jpipes@serialcoder-20090915210142-x8mwiqn1q0vzjspp
Moves Alter_info out into its own header and source file, cleans up some related include mess in sql_lex.h, and renames Alter_info to AlterInfo.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
21
21
 
22
22
/**
23
23
 * @TODO Name this file something better and split it out if necessary.
 
24
 * base.h isn't descriptive, especially compared to global.h
24
25
 *
25
26
 * @TODO Convert HA_XXX defines into enums and/or bitmaps
26
27
 */
27
28
 
28
 
#include "definitions.h"
29
 
 
30
 
#ifndef DRIZZLED_BASE_H
31
 
#define DRIZZLED_BASE_H
32
 
 
33
 
namespace drizzled
34
 
{
 
29
#ifndef DRIZZLE_SERVER_BASE_H
 
30
#define DRIZZLE_SERVER_BASE_H
 
31
 
 
32
#define CHSIZE_USED
35
33
 
36
34
/* The following is bits in the flag parameter to ha_open() */
37
35
 
39
37
#define HA_OPEN_WAIT_IF_LOCKED          1
40
38
#define HA_OPEN_IGNORE_IF_LOCKED        2
41
39
#define HA_OPEN_TMP_TABLE               4       /* Table is a temp table */
 
40
#define HA_OPEN_ABORT_IF_CRASHED        16
 
41
#define HA_OPEN_FOR_REPAIR              32      /* open even if crashed */
42
42
/* Internal temp table, used for temporary results */
43
43
#define HA_OPEN_INTERNAL_TABLE          512
44
44
 
84
84
enum ha_key_alg {
85
85
  HA_KEY_ALG_UNDEF=     0,              /* Not specified (old file) */
86
86
  HA_KEY_ALG_BTREE=     1,              /* B-tree, default one          */
87
 
  HA_KEY_ALG_HASH=      3               /* HASH keys (HEAP tables) */
 
87
  HA_KEY_ALG_RTREE=     2,              /* R-tree, for spatial searches */
 
88
  HA_KEY_ALG_HASH=      3,              /* HASH keys (HEAP tables) */
 
89
  HA_KEY_ALG_FULLTEXT=  4               /* FULLTEXT (MyISAM tables) */
88
90
};
89
91
 
90
92
        /* Index and table build methods */
175
177
  HA_EXTRA_PREPARE_FOR_RENAME
176
178
};
177
179
 
 
180
/* Compatible option, to be deleted in 6.0 */
 
181
#define HA_EXTRA_PREPARE_FOR_DELETE HA_EXTRA_PREPARE_FOR_DROP
 
182
 
178
183
        /* The following is parameter to ha_panic() */
179
184
 
180
185
enum ha_panic_function {
189
194
  HA_KEYTYPE_END=0,
190
195
  HA_KEYTYPE_TEXT=1,                    /* Key is sorted as letters */
191
196
  HA_KEYTYPE_BINARY=2,                  /* Key is sorted as unsigned chars */
 
197
  HA_KEYTYPE_SHORT_INT=3,
192
198
  HA_KEYTYPE_LONG_INT=4,
 
199
  HA_KEYTYPE_FLOAT=5,
193
200
  HA_KEYTYPE_DOUBLE=6,
 
201
  HA_KEYTYPE_NUM=7,                     /* Not packed num with pre-space */
 
202
  HA_KEYTYPE_USHORT_INT=8,
194
203
  HA_KEYTYPE_ULONG_INT=9,
195
204
  HA_KEYTYPE_LONGLONG=10,
196
205
  HA_KEYTYPE_ULONGLONG=11,
 
206
  HA_KEYTYPE_INT24=12,
 
207
  HA_KEYTYPE_UINT24=13,
 
208
  HA_KEYTYPE_INT8=14,
197
209
  /* Varchar (0-255 bytes) with length packed with 1 byte */
198
210
  HA_KEYTYPE_VARTEXT1=15,               /* Key is sorted as letters */
199
211
  HA_KEYTYPE_VARBINARY1=16,             /* Key is sorted as unsigned chars */
200
212
  /* Varchar (0-65535 bytes) with length packed with 2 bytes */
201
213
  HA_KEYTYPE_VARTEXT2=17,               /* Key is sorted as letters */
202
 
  HA_KEYTYPE_VARBINARY2=18              /* Key is sorted as unsigned chars */
 
214
  HA_KEYTYPE_VARBINARY2=18,             /* Key is sorted as unsigned chars */
 
215
  HA_KEYTYPE_BIT=19
203
216
};
204
217
 
 
218
#define HA_MAX_KEYTYPE  31              /* Must be log2-1 */
 
219
 
205
220
        /* These flags kan be OR:ed to key-flag */
206
221
 
207
222
#define HA_NOSAME                1      /* Set if not dupplicated records */
212
227
#define HA_NULL_ARE_EQUAL       2048    /* NULL in key are cmp as equal */
213
228
#define HA_GENERATED_KEY        8192    /* Automaticly generated key */
214
229
 
 
230
        /* The combination of the above can be used for key type comparison. */
 
231
#define HA_KEYFLAG_MASK (HA_NOSAME | HA_PACK_KEY | HA_AUTO_KEY | \
 
232
                         HA_BINARY_PACK_KEY | HA_UNIQUE_CHECK | \
 
233
                         HA_NULL_ARE_EQUAL | HA_GENERATED_KEY)
 
234
 
215
235
#define HA_KEY_HAS_PART_KEY_SEG 65536   /* Key contains partial segments */
216
236
 
217
237
        /* Automatic bits in key-flag */
246
266
#define HA_OPTION_COMPRESS_RECORD       4
247
267
#define HA_OPTION_TMP_TABLE             16
248
268
#define HA_OPTION_NO_PACK_KEYS          128  /* Reserved for MySQL */
 
269
#define HA_OPTION_CREATE_FROM_ENGINE    256
 
270
#define HA_OPTION_NULL_FIELDS           1024
 
271
#define HA_OPTION_PAGE_CHECKSUM         2048
249
272
#define HA_OPTION_TEMP_COMPRESS_RECORD  ((uint32_t) 16384)      /* set by isamchk */
250
273
#define HA_OPTION_READ_ONLY_DATA        ((uint32_t) 32768)      /* Set by isamchk */
251
274
 
302
325
/*
303
326
  Errorcodes given by handler functions
304
327
 
305
 
  optimizer::sum_query() assumes these codes are > 1
 
328
  opt_sum_query() assumes these codes are > 1
306
329
  Do not add error numbers before HA_ERR_FIRST.
307
330
  If necessary to add lower numbers, change HA_ERR_FIRST accordingly.
308
331
*/
309
332
#define HA_ERR_FIRST            120     /* Copy of first error nr.*/
310
333
 
311
 
/* Other constants */
312
 
 
313
 
typedef unsigned long key_part_map;
 
334
#define HA_ERR_KEY_NOT_FOUND    120     /* Didn't find key on read or update */
 
335
#define HA_ERR_FOUND_DUPP_KEY   121     /* Dupplicate key on write */
 
336
#define HA_ERR_INTERNAL_ERROR   122     /* Internal error */
 
337
#define HA_ERR_RECORD_CHANGED   123     /* Uppdate with is recoverable */
 
338
#define HA_ERR_WRONG_INDEX      124     /* Wrong index given to function */
 
339
#define HA_ERR_CRASHED          126     /* Indexfile is crashed */
 
340
#define HA_ERR_WRONG_IN_RECORD  127     /* Record-file is crashed */
 
341
#define HA_ERR_OUT_OF_MEM       128     /* Record-file is crashed */
 
342
#define HA_ERR_NOT_A_TABLE      130     /* not a MYI file - no signature */
 
343
#define HA_ERR_WRONG_COMMAND    131     /* Command not supported */
 
344
#define HA_ERR_OLD_FILE         132     /* old databasfile */
 
345
#define HA_ERR_NO_ACTIVE_RECORD 133     /* No record read in update() */
 
346
#define HA_ERR_RECORD_DELETED   134     /* A record is not there */
 
347
#define HA_ERR_RECORD_FILE_FULL 135     /* No more room in file */
 
348
#define HA_ERR_INDEX_FILE_FULL  136     /* No more room in file */
 
349
#define HA_ERR_END_OF_FILE      137     /* end in next/prev/first/last */
 
350
#define HA_ERR_UNSUPPORTED      138     /* unsupported extension used */
 
351
#define HA_ERR_TO_BIG_ROW       139     /* Too big row */
 
352
#define HA_WRONG_CREATE_OPTION  140     /* Wrong create option */
 
353
#define HA_ERR_FOUND_DUPP_UNIQUE 141    /* Dupplicate unique on write */
 
354
#define HA_ERR_UNKNOWN_CHARSET   142    /* Can't open charset */
 
355
#define HA_ERR_WRONG_MRG_TABLE_DEF 143  /* conflicting tables in MERGE */
 
356
#define HA_ERR_CRASHED_ON_REPAIR 144    /* Last (automatic?) repair failed */
 
357
#define HA_ERR_CRASHED_ON_USAGE  145    /* Table must be repaired */
 
358
#define HA_ERR_LOCK_WAIT_TIMEOUT 146
 
359
#define HA_ERR_LOCK_TABLE_FULL   147
 
360
#define HA_ERR_READ_ONLY_TRANSACTION 148 /* Updates not allowed */
 
361
#define HA_ERR_LOCK_DEADLOCK     149
 
362
#define HA_ERR_CANNOT_ADD_FOREIGN 150    /* Cannot add a foreign key constr. */
 
363
#define HA_ERR_NO_REFERENCED_ROW 151     /* Cannot add a child row */
 
364
#define HA_ERR_ROW_IS_REFERENCED 152     /* Cannot delete a parent row */
 
365
#define HA_ERR_NO_SAVEPOINT      153     /* No savepoint with that name */
 
366
#define HA_ERR_NON_UNIQUE_BLOCK_SIZE 154 /* Non unique key block size */
 
367
#define HA_ERR_NO_SUCH_TABLE     155  /* The table does not exist in engine */
 
368
#define HA_ERR_TABLE_EXIST       156  /* The table existed in storage engine */
 
369
#define HA_ERR_NO_CONNECTION     157  /* Could not connect to storage engine */
 
370
/* NULLs are not supported in spatial index */
 
371
#define HA_ERR_NULL_IN_SPATIAL   158
 
372
#define HA_ERR_TABLE_DEF_CHANGED 159  /* The table changed in storage engine */
 
373
/* There's no partition in table for given value */
 
374
#define HA_ERR_NO_PARTITION_FOUND 160
 
375
#define HA_ERR_RBR_LOGGING_FAILED 161  /* Row-based binlogging of row failed */
 
376
#define HA_ERR_DROP_INDEX_FK      162  /* Index needed in foreign key constr */
 
377
/*
 
378
  Upholding foreign key constraints would lead to a duplicate key error
 
379
  in some other table.
 
380
*/
 
381
#define HA_ERR_FOREIGN_DUPLICATE_KEY 163
 
382
/* The table changed in storage engine */
 
383
#define HA_ERR_TABLE_NEEDS_UPGRADE 164
 
384
#define HA_ERR_TABLE_READONLY      165   /* The table is not writable */
 
385
 
 
386
#define HA_ERR_AUTOINC_READ_FAILED 166   /* Failed to get next autoinc value */
 
387
#define HA_ERR_AUTOINC_ERANGE    167     /* Failed to set row autoinc value */
 
388
#define HA_ERR_GENERIC           168     /* Generic error */
 
389
/* row not actually updated: new values same as the old values */
 
390
#define HA_ERR_RECORD_IS_THE_SAME 169
 
391
/* It is not possible to log this statement */
 
392
#define HA_ERR_LOGGING_IMPOSSIBLE 170    /* It is not possible to log this
 
393
                                            statement */
 
394
#define HA_ERR_TABLESPACE_EXIST   171
 
395
#define HA_ERR_CORRUPT_EVENT      172    /* The event was corrupt, leading to
 
396
                                            illegal data being read */
 
397
#define HA_ERR_NEW_FILE           173    /* New file format */
 
398
#define HA_ERR_ROWS_EVENT_APPLY   174    /* The event could not be processed
 
399
                                            no other hanlder error happened */
 
400
#define HA_ERR_INITIALIZATION     175    /* Error during initialization */
 
401
#define HA_ERR_FILE_TOO_SHORT     176    /* File too short */
 
402
#define HA_ERR_WRONG_CRC          177    /* Wrong CRC on page */
 
403
#define HA_ERR_LOCK_OR_ACTIVE_TRANSACTION 178
 
404
#define HA_ERR_NO_SUCH_TABLESPACE 179
 
405
#define HA_ERR_TABLESPACE_NOT_EMPTY 180
 
406
#define HA_ERR_LAST               180    /* Copy of last error nr */
 
407
 
 
408
/* Number of different errors */
 
409
#define HA_ERR_ERRORS            (HA_ERR_LAST - HA_ERR_FIRST + 1)
 
410
 
 
411
        /* Other constants */
 
412
 
 
413
#define HA_NAMELEN 64                   /* Max length of saved filename */
 
414
#define NO_SUCH_KEY (~(uint32_t)0)          /* used as a key no. */
 
415
 
 
416
typedef ulong key_part_map;
314
417
#define HA_WHOLE_KEY  (~(key_part_map)0)
315
418
 
316
419
        /* Intern constants in databases */
330
433
#define MBR_WITHIN      2048
331
434
#define MBR_DISJOINT    4096
332
435
#define MBR_EQUAL       8192
 
436
#define MBR_DATA        16384
333
437
#define SEARCH_NULL_ARE_EQUAL 32768     /* NULL in keys are equal */
334
438
#define SEARCH_NULL_ARE_NOT_EQUAL 65536 /* NULL in keys are not equal */
335
439
 
336
440
        /* bits in opt_flag */
 
441
#define QUICK_USED      1
337
442
#define READ_CACHE_USED 2
338
443
#define READ_CHECK_USED 4
339
444
#define KEY_READ_USED   8
347
452
#define HA_STATE_DELETED        8
348
453
#define HA_STATE_NEXT_FOUND     16      /* Next found record (record before) */
349
454
#define HA_STATE_PREV_FOUND     32      /* Prev found record (record after) */
 
455
#define HA_STATE_NO_KEY         64      /* Last read didn't find record */
350
456
#define HA_STATE_KEY_CHANGED    128
351
457
#define HA_STATE_WRITE_AT_END   256     /* set in _ps_find_writepos */
 
458
#define HA_STATE_BUFF_SAVED     512     /* If current keybuff is info->buff */
352
459
#define HA_STATE_ROW_CHANGED    1024    /* To invalide ROW cache */
353
460
#define HA_STATE_EXTEND_BLOCK   2048
354
461
#define HA_STATE_RNEXT_SAME     4096    /* rnext_same occupied lastkey2 */
398
505
*/
399
506
#define NULL_RANGE      64
400
507
 
401
 
class key_range
 
508
typedef struct st_key_range
402
509
{
403
 
public:
404
510
  const unsigned char *key;
405
511
  uint32_t length;
406
512
  enum ha_rkey_function flag;
407
513
  key_part_map keypart_map;
408
 
};
 
514
} key_range;
409
515
 
410
 
class KEY_MULTI_RANGE
 
516
typedef struct st_key_multi_range
411
517
{
412
 
public:
413
518
  key_range start_key;
414
519
  key_range end_key;
415
520
  char  *ptr;                 /* Free to use by caller (ptr to row etc) */
416
521
  uint32_t  range_flag;           /* key range flags see above */
417
 
};
 
522
} KEY_MULTI_RANGE;
418
523
 
419
524
 
420
525
/* For number of records */
421
526
typedef uint64_t        ha_rows;
422
 
inline static double rows2double(ha_rows rows)
423
 
{  
424
 
  return uint64_t2double(rows);
425
 
}
 
527
#define rows2double(A)  uint64_t2double(A)
426
528
 
427
 
#define HA_POS_ERROR    (~ (::drizzled::ha_rows) 0)
428
 
#define HA_OFFSET_ERROR (~ (::drizzled::internal::my_off_t) 0)
 
529
#define HA_POS_ERROR    (~ (ha_rows) 0)
 
530
#define HA_OFFSET_ERROR (~ (my_off_t) 0)
429
531
 
430
532
#if SIZEOF_OFF_T == 4
431
533
#define MAX_FILE_SIZE   INT32_MAX
433
535
#define MAX_FILE_SIZE   INT64_MAX
434
536
#endif
435
537
 
436
 
inline static uint32_t ha_varchar_packlength(uint32_t field_length)
437
 
{
438
 
  return (field_length < 256 ? 1 :2);
439
 
}
440
 
 
441
 
 
442
 
} /* namespace drizzled */
443
 
 
444
 
#endif /* DRIZZLED_BASE_H */
 
538
#define HA_VARCHAR_PACKLENGTH(field_length) ((field_length) < 256 ? 1 :2)
 
539
 
 
540
#endif /* DRIZZLE_SERVER_BASE_H */