Drizzled Public API Documentation

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