~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
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
 */
1 by brian
clean slate
19
20
/* This file includes constants used with all databases */
21
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
22
/**
23
 * @TODO Name this file something better and split it out if necessary.
243.1.11 by Jay Pipes
* Added include guards in a couple places, and removed unecessary
24
 *
25
 * @TODO Convert HA_XXX defines into enums and/or bitmaps
26
 */
27
1892.5.2 by Gustaf Thorslund
Replaced macros with functions/templates. Part of blueprint:
28
#include "definitions.h"
29
1122.2.10 by Monty Taylor
Fixed all of the include guards.
30
#ifndef DRIZZLED_BASE_H
31
#define DRIZZLED_BASE_H
1 by brian
clean slate
32
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
33
namespace drizzled
34
{
35
1 by brian
clean slate
36
/* The following is bits in the flag parameter to ha_open() */
37
38
#define HA_OPEN_ABORT_IF_LOCKED		0	/* default */
39
#define HA_OPEN_WAIT_IF_LOCKED		1
40
#define HA_OPEN_IGNORE_IF_LOCKED	2
41
#define HA_OPEN_TMP_TABLE		4	/* Table is a temp table */
42
/* Internal temp table, used for temporary results */
43
#define HA_OPEN_INTERNAL_TABLE          512
44
45
/* The following is parameter to ha_rkey() how to use key */
46
47
/*
48
  We define a complete-field prefix of a key value as a prefix where
49
  the last included field in the prefix contains the full field, not
50
  just some bytes from the start of the field. A partial-field prefix
51
  is allowed to contain only a few first bytes from the last included
52
  field.
53
54
  Below HA_READ_KEY_EXACT, ..., HA_READ_BEFORE_KEY can take a
55
  complete-field prefix of a key value as the search
56
  key. HA_READ_PREFIX and HA_READ_PREFIX_LAST could also take a
57
  partial-field prefix, but currently (4.0.10) they are only used with
58
  complete-field prefixes. MySQL uses a padding trick to implement
59
  LIKE 'abc%' queries.
60
61
  NOTE that in InnoDB HA_READ_PREFIX_LAST will NOT work with a
62
  partial-field prefix because InnoDB currently strips spaces from the
63
  end of varchar fields!
64
*/
65
66
enum ha_rkey_function {
67
  HA_READ_KEY_EXACT,              /* Find first record else error */
68
  HA_READ_KEY_OR_NEXT,            /* Record or next record */
69
  HA_READ_KEY_OR_PREV,            /* Record or previous */
70
  HA_READ_AFTER_KEY,              /* Find next rec. after key-record */
71
  HA_READ_BEFORE_KEY,             /* Find next rec. before key-record */
72
  HA_READ_PREFIX,                 /* Key which as same prefix */
73
  HA_READ_PREFIX_LAST,            /* Last key with the same prefix */
74
  HA_READ_PREFIX_LAST_OR_PREV,    /* Last or prev key with the same prefix */
75
  HA_READ_MBR_CONTAIN,
76
  HA_READ_MBR_INTERSECT,
77
  HA_READ_MBR_WITHIN,
78
  HA_READ_MBR_DISJOINT,
79
  HA_READ_MBR_EQUAL
80
};
81
82
	/* Key algorithm types */
83
84
enum ha_key_alg {
85
  HA_KEY_ALG_UNDEF=	0,		/* Not specified (old file) */
86
  HA_KEY_ALG_BTREE=	1,		/* B-tree, default one          */
1235.1.12 by Brian Aker
Clean up index interface before moving to SE.
87
  HA_KEY_ALG_HASH=	3		/* HASH keys (HEAP tables) */
1 by brian
clean slate
88
};
89
90
	/* Index and table build methods */
91
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
92
enum ha_build_method {
93
  HA_BUILD_DEFAULT,
1 by brian
clean slate
94
  HA_BUILD_ONLINE,
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
95
  HA_BUILD_OFFLINE
1 by brian
clean slate
96
};
97
98
	/* The following is parameter to ha_extra() */
99
100
enum ha_extra_function {
101
  HA_EXTRA_NORMAL=0,			/* Optimize for space (def) */
102
  HA_EXTRA_QUICK=1,			/* Optimize for speed */
103
  HA_EXTRA_NOT_USED=2,
104
  HA_EXTRA_CACHE=3,			/* Cache record in HA_rrnd() */
105
  HA_EXTRA_NO_CACHE=4,			/* End caching of records (def) */
106
  HA_EXTRA_NO_READCHECK=5,		/* No readcheck on update */
107
  HA_EXTRA_READCHECK=6,			/* Use readcheck (def) */
108
  HA_EXTRA_KEYREAD=7,			/* Read only key to database */
109
  HA_EXTRA_NO_KEYREAD=8,		/* Normal read of records (def) */
110
  HA_EXTRA_NO_USER_CHANGE=9,		/* No user is allowed to write */
111
  HA_EXTRA_KEY_CACHE=10,
112
  HA_EXTRA_NO_KEY_CACHE=11,
113
  HA_EXTRA_WAIT_LOCK=12,		/* Wait until file is avalably (def) */
114
  HA_EXTRA_NO_WAIT_LOCK=13,		/* If file is locked, return quickly */
115
  HA_EXTRA_WRITE_CACHE=14,		/* Use write cache in ha_write() */
116
  HA_EXTRA_FLUSH_CACHE=15,		/* flush write_record_cache */
117
  HA_EXTRA_NO_KEYS=16,			/* Remove all update of keys */
118
  HA_EXTRA_KEYREAD_CHANGE_POS=17,	/* Keyread, but change pos */
119
					/* xxxxchk -r must be used */
120
  HA_EXTRA_REMEMBER_POS=18,		/* Remember pos for next/prev */
121
  HA_EXTRA_RESTORE_POS=19,
122
  HA_EXTRA_REINIT_CACHE=20,		/* init cache from current record */
123
  HA_EXTRA_FORCE_REOPEN=21,		/* Datafile have changed on disk */
124
  HA_EXTRA_FLUSH,			/* Flush tables to disk */
125
  HA_EXTRA_NO_ROWS,			/* Don't write rows */
126
  HA_EXTRA_RESET_STATE,			/* Reset positions */
127
  HA_EXTRA_IGNORE_DUP_KEY,		/* Dup keys don't rollback everything*/
128
  HA_EXTRA_NO_IGNORE_DUP_KEY,
129
  HA_EXTRA_PREPARE_FOR_DROP,
130
  HA_EXTRA_PREPARE_FOR_UPDATE,		/* Remove read cache if problems */
131
  HA_EXTRA_PRELOAD_BUFFER_SIZE,         /* Set buffer size for preloading */
132
  /*
133
    On-the-fly switching between unique and non-unique key inserting.
134
  */
135
  HA_EXTRA_CHANGE_KEY_TO_UNIQUE,
136
  HA_EXTRA_CHANGE_KEY_TO_DUP,
137
  /*
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
138
    When using HA_EXTRA_KEYREAD, overwrite only key member fields and keep
1 by brian
clean slate
139
    other fields intact. When this is off (by default) InnoDB will use memcpy
140
    to overwrite entire row.
141
  */
142
  HA_EXTRA_KEYREAD_PRESERVE_FIELDS,
143
  /*
144
    Ignore if the a tuple is not found, continue processing the
145
    transaction and ignore that 'row'.  Needed for idempotency
146
    handling on the slave
147
148
    Currently only used by NDB storage engine. Partition handler ignores flag.
149
  */
150
  HA_EXTRA_IGNORE_NO_KEY,
151
  HA_EXTRA_NO_IGNORE_NO_KEY,
152
  /*
153
    Informs handler that write_row() which tries to insert new row into the
154
    table and encounters some already existing row with same primary/unique
155
    key can replace old row with new row instead of reporting error (basically
156
    it informs handler that we do REPLACE instead of simple INSERT).
157
    Off by default.
158
  */
159
  HA_EXTRA_WRITE_CAN_REPLACE,
160
  HA_EXTRA_WRITE_CANNOT_REPLACE,
161
  /*
162
    Inform handler that delete_row()/update_row() cannot batch deletes/updates
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
163
    and should perform them immediately. This may be needed when table has
1 by brian
clean slate
164
    AFTER DELETE/UPDATE triggers which access to subject table.
165
    These flags are reset by the handler::extra(HA_EXTRA_RESET) call.
166
  */
167
  HA_EXTRA_DELETE_CANNOT_BATCH,
168
  HA_EXTRA_UPDATE_CANNOT_BATCH,
169
  /*
170
    Inform handler that an "INSERT...ON DUPLICATE KEY UPDATE" will be
171
    executed. This condition is unset by HA_EXTRA_NO_IGNORE_DUP_KEY.
172
  */
173
  HA_EXTRA_INSERT_WITH_UPDATE,
174
  /* Inform handler that we will do a rename */
102 by Brian Aker
Final cleanup on enum for MEMORY/DISK
175
  HA_EXTRA_PREPARE_FOR_RENAME
1 by brian
clean slate
176
};
177
178
	/* The following is parameter to ha_panic() */
179
180
enum ha_panic_function {
181
  HA_PANIC_CLOSE,			/* Close all databases */
182
  HA_PANIC_WRITE,			/* Unlock and write status */
183
  HA_PANIC_READ				/* Lock and read keyinfo */
184
};
185
186
	/* The following is parameter to ha_create(); keytypes */
187
188
enum ha_base_keytype {
189
  HA_KEYTYPE_END=0,
190
  HA_KEYTYPE_TEXT=1,			/* Key is sorted as letters */
191
  HA_KEYTYPE_BINARY=2,			/* Key is sorted as unsigned chars */
192
  HA_KEYTYPE_LONG_INT=4,
193
  HA_KEYTYPE_DOUBLE=6,
194
  HA_KEYTYPE_ULONG_INT=9,
195
  HA_KEYTYPE_LONGLONG=10,
196
  HA_KEYTYPE_ULONGLONG=11,
197
  /* Varchar (0-255 bytes) with length packed with 1 byte */
198
  HA_KEYTYPE_VARTEXT1=15,               /* Key is sorted as letters */
199
  HA_KEYTYPE_VARBINARY1=16,             /* Key is sorted as unsigned chars */
200
  /* Varchar (0-65535 bytes) with length packed with 2 bytes */
201
  HA_KEYTYPE_VARTEXT2=17,		/* Key is sorted as letters */
1161.1.7 by Stewart Smith
remove unused HA_KEYTYPE_BIT
202
  HA_KEYTYPE_VARBINARY2=18		/* Key is sorted as unsigned chars */
1 by brian
clean slate
203
};
204
205
	/* These flags kan be OR:ed to key-flag */
206
207
#define HA_NOSAME		 1	/* Set if not dupplicated records */
208
#define HA_PACK_KEY		 2	/* Pack string key to previous key */
209
#define HA_AUTO_KEY		 16
210
#define HA_BINARY_PACK_KEY	 32	/* Packing of all keys to prev key */
211
#define HA_UNIQUE_CHECK		256	/* Check the key for uniqueness */
212
#define HA_NULL_ARE_EQUAL	2048	/* NULL in key are cmp as equal */
213
#define HA_GENERATED_KEY	8192	/* Automaticly generated key */
214
215
#define HA_KEY_HAS_PART_KEY_SEG 65536   /* Key contains partial segments */
216
217
	/* Automatic bits in key-flag */
218
219
#define HA_SPACE_PACK_USED	 4	/* Test for if SPACE_PACK used */
220
#define HA_VAR_LENGTH_KEY	 8
221
#define HA_NULL_PART_KEY	 64
222
#define HA_USES_COMMENT          4096
895 by Brian Aker
Completion (?) of uint conversion.
223
#define HA_USES_BLOCK_SIZE	 ((uint32_t) 32768)
1 by brian
clean slate
224
#define HA_SORT_ALLOWS_SAME      512    /* Intern bit when sorting records */
225
226
	/* These flags can be added to key-seg-flag */
227
228
#define HA_SPACE_PACK		 1	/* Pack space in key-seg */
229
#define HA_PART_KEY_SEG		 4	/* Used by MySQL for part-key-cols */
230
#define HA_VAR_LENGTH_PART	 8
231
#define HA_NULL_PART		 16
232
#define HA_BLOB_PART		 32
233
#define HA_SWAP_KEY		 64
234
#define HA_REVERSE_SORT		 128	/* Sort key in reverse order */
235
#define HA_NO_SORT               256 /* do not bother sorting on this keyseg */
236
/*
237
  End space in unique/varchar are considered equal. (Like 'a' and 'a ')
238
  Only needed for internal temporary tables.
239
*/
240
#define HA_END_SPACE_ARE_EQUAL	 512
241
#define HA_BIT_PART		1024
242
243
	/* optionbits for database */
244
#define HA_OPTION_PACK_RECORD		1
245
#define HA_OPTION_PACK_KEYS		2
246
#define HA_OPTION_COMPRESS_RECORD	4
247
#define HA_OPTION_TMP_TABLE		16
248
#define HA_OPTION_NO_PACK_KEYS		128  /* Reserved for MySQL */
895 by Brian Aker
Completion (?) of uint conversion.
249
#define HA_OPTION_TEMP_COMPRESS_RECORD	((uint32_t) 16384)	/* set by isamchk */
250
#define HA_OPTION_READ_ONLY_DATA	((uint32_t) 32768)	/* Set by isamchk */
1 by brian
clean slate
251
252
	/* Bits in flag to create() */
253
254
#define HA_DONT_TOUCH_DATA	1	/* Don't empty datafile (isamchk) */
255
#define HA_PACK_RECORD		2	/* Request packed record format */
256
#define HA_CREATE_TMP_TABLE	4
257
#define HA_CREATE_KEEP_FILES	16      /* don't overwrite .MYD and MYI */
258
259
/*
260
  The following flags (OR-ed) are passed to handler::info() method.
261
  The method copies misc handler information out of the storage engine
262
  to data structures accessible from MySQL
263
264
  Same flags are also passed down to mi_status, myrg_status, etc.
265
*/
266
267
/* this one is not used */
268
#define HA_STATUS_POS            1
269
/*
270
  assuming the table keeps shared actual copy of the 'info' and
271
  local, possibly outdated copy, the following flag means that
272
  it should not try to get the actual data (locking the shared structure)
273
  slightly outdated version will suffice
274
*/
275
#define HA_STATUS_NO_LOCK        2
276
/* update the time of the last modification (in handler::update_time) */
277
#define HA_STATUS_TIME           4
278
/*
279
  update the 'constant' part of the info:
280
  handler::max_data_file_length, max_index_file_length, create_time
281
  sortkey, ref_length, block_size, data_file_name, index_file_name.
282
  handler::table->s->keys_in_use, keys_for_keyread, rec_per_key
283
*/
284
#define HA_STATUS_CONST          8
285
/*
286
  update the 'variable' part of the info:
287
  handler::records, deleted, data_file_length, index_file_length,
288
  delete_length, check_time, mean_rec_length
289
*/
290
#define HA_STATUS_VARIABLE      16
291
/*
292
  get the information about the key that caused last duplicate value error
293
  update handler::errkey and handler::dupp_ref
294
  see handler::get_dup_key()
295
*/
296
#define HA_STATUS_ERRKEY        32
297
/*
298
  update handler::auto_increment_value
299
*/
300
#define HA_STATUS_AUTO          64
301
302
/*
303
  Errorcodes given by handler functions
304
1237.9.1 by Padraig O'Sullivan
Moved the opt_sum.cc file into the optimizer directory and renamed it to sum.cc. Added a header file
305
  optimizer::sum_query() assumes these codes are > 1
1 by brian
clean slate
306
  Do not add error numbers before HA_ERR_FIRST.
307
  If necessary to add lower numbers, change HA_ERR_FIRST accordingly.
308
*/
309
#define HA_ERR_FIRST            120     /* Copy of first error nr.*/
310
2068.7.3 by Brian Aker
Merge in work for error messages being standardized by error_t
311
/* Other constants */
1 by brian
clean slate
312
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
313
typedef unsigned long key_part_map;
1 by brian
clean slate
314
#define HA_WHOLE_KEY  (~(key_part_map)0)
315
316
	/* Intern constants in databases */
317
318
	/* bits in _search */
319
#define SEARCH_FIND	1
320
#define SEARCH_NO_FIND	2
321
#define SEARCH_SAME	4
322
#define SEARCH_BIGGER	8
323
#define SEARCH_SMALLER	16
324
#define SEARCH_SAVE_BUFF	32
325
#define SEARCH_UPDATE	64
326
#define SEARCH_PREFIX	128
327
#define SEARCH_LAST	256
328
#define MBR_CONTAIN     512
329
#define MBR_INTERSECT   1024
330
#define MBR_WITHIN      2048
331
#define MBR_DISJOINT    4096
332
#define MBR_EQUAL       8192
333
#define SEARCH_NULL_ARE_EQUAL 32768	/* NULL in keys are equal */
334
#define SEARCH_NULL_ARE_NOT_EQUAL 65536	/* NULL in keys are not equal */
335
336
	/* bits in opt_flag */
337
#define READ_CACHE_USED	2
338
#define READ_CHECK_USED 4
339
#define KEY_READ_USED	8
340
#define WRITE_CACHE_USED 16
341
#define OPT_NO_ROWS	32
342
343
	/* bits in update */
344
#define HA_STATE_CHANGED	1	/* Database has changed */
345
#define HA_STATE_AKTIV		2	/* Has a current record */
346
#define HA_STATE_WRITTEN	4	/* Record is written */
347
#define HA_STATE_DELETED	8
348
#define HA_STATE_NEXT_FOUND	16	/* Next found record (record before) */
349
#define HA_STATE_PREV_FOUND	32	/* Prev found record (record after) */
350
#define HA_STATE_KEY_CHANGED	128
351
#define HA_STATE_WRITE_AT_END	256	/* set in _ps_find_writepos */
352
#define HA_STATE_ROW_CHANGED	1024	/* To invalide ROW cache */
353
#define HA_STATE_EXTEND_BLOCK	2048
354
#define HA_STATE_RNEXT_SAME	4096	/* rnext_same occupied lastkey2 */
355
356
/* myisampack expects no more than 32 field types. */
357
enum en_fieldtype {
358
  FIELD_LAST=-1,FIELD_NORMAL,FIELD_SKIP_ENDSPACE,FIELD_SKIP_PRESPACE,
359
  FIELD_SKIP_ZERO,FIELD_BLOB,FIELD_CONSTANT,FIELD_INTERVALL,FIELD_ZERO,
360
  FIELD_VARCHAR,FIELD_CHECK,
361
  FIELD_enum_val_count
362
};
363
364
enum data_file_type {
365
  STATIC_RECORD, DYNAMIC_RECORD, COMPRESSED_RECORD, BLOCK_RECORD
366
};
367
368
/* For key ranges */
369
370
/* from -inf */
371
#define NO_MIN_RANGE	1
372
373
/* to +inf */
374
#define NO_MAX_RANGE	2
375
376
/*  X < key, i.e. not including the left endpoint */
377
#define NEAR_MIN	4
378
379
/* X > key, i.e. not including the right endpoint */
380
#define NEAR_MAX	8
381
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
382
/*
383
  This flag means that index is a unique index, and the interval is
1 by brian
clean slate
384
  equivalent to "AND(keypart_i = const_i)", where all of const_i are not NULLs.
385
*/
386
#define UNIQUE_RANGE	16
387
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
388
/*
389
  This flag means that the interval is equivalent to
390
  "AND(keypart_i = const_i)", where not all key parts may be used but all of
1 by brian
clean slate
391
  const_i are not NULLs.
392
*/
393
#define EQ_RANGE	32
394
395
/*
396
  This flag has the same meaning as UNIQUE_RANGE, except that for at least
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
397
  one keypart the condition is "keypart IS NULL".
1 by brian
clean slate
398
*/
399
#define NULL_RANGE	64
400
1810.5.1 by tdavies
change in file: ../drizzled/base.h. Converted C structs key_range and KEY_MULTI_RANGE to C++ classes
401
class key_range
1 by brian
clean slate
402
{
1810.5.1 by tdavies
change in file: ../drizzled/base.h. Converted C structs key_range and KEY_MULTI_RANGE to C++ classes
403
public:
481 by Brian Aker
Remove all of uchar.
404
  const unsigned char *key;
482 by Brian Aker
Remove uint.
405
  uint32_t length;
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
406
  enum ha_rkey_function flag;
1 by brian
clean slate
407
  key_part_map keypart_map;
1810.5.1 by tdavies
change in file: ../drizzled/base.h. Converted C structs key_range and KEY_MULTI_RANGE to C++ classes
408
};
1 by brian
clean slate
409
1810.5.1 by tdavies
change in file: ../drizzled/base.h. Converted C structs key_range and KEY_MULTI_RANGE to C++ classes
410
class KEY_MULTI_RANGE
1 by brian
clean slate
411
{
1810.5.1 by tdavies
change in file: ../drizzled/base.h. Converted C structs key_range and KEY_MULTI_RANGE to C++ classes
412
public:
1 by brian
clean slate
413
  key_range start_key;
414
  key_range end_key;
415
  char  *ptr;                 /* Free to use by caller (ptr to row etc) */
482 by Brian Aker
Remove uint.
416
  uint32_t  range_flag;           /* key range flags see above */
1810.5.1 by tdavies
change in file: ../drizzled/base.h. Converted C structs key_range and KEY_MULTI_RANGE to C++ classes
417
};
1 by brian
clean slate
418
419
420
/* For number of records */
248 by Brian Aker
Random cleanup in base.h
421
typedef uint64_t	ha_rows;
1 by brian
clean slate
422
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
423
#define HA_POS_ERROR	(~ (::drizzled::ha_rows) 0)
424
#define HA_OFFSET_ERROR	(~ (::drizzled::internal::my_off_t) 0)
1 by brian
clean slate
425
77.1.3 by Monty Taylor
MyISAM cleanups.
426
#if SIZEOF_OFF_T == 4
163 by Brian Aker
Merge Monty's code.
427
#define MAX_FILE_SIZE	INT32_MAX
1 by brian
clean slate
428
#else
163 by Brian Aker
Merge Monty's code.
429
#define MAX_FILE_SIZE	INT64_MAX
1 by brian
clean slate
430
#endif
431
1892.5.2 by Gustaf Thorslund
Replaced macros with functions/templates. Part of blueprint:
432
inline static uint32_t ha_varchar_packlength(uint32_t field_length)
433
{
434
  return (field_length < 256 ? 1 :2);
435
}
1 by brian
clean slate
436
1377.6.3 by pawel
changed function-like defines into functions in some files
437
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
438
} /* namespace drizzled */
439
1122.2.10 by Monty Taylor
Fixed all of the include guards.
440
#endif /* DRIZZLED_BASE_H */