Drizzled Public API Documentation

base.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 /* This file includes constants used with all databases */
00021 
00028 #include <drizzled/definitions.h>
00029 
00030 #pragma once
00031 
00032 namespace drizzled
00033 {
00034 
00035 /* The following is bits in the flag parameter to ha_open() */
00036 
00037 #define HA_OPEN_ABORT_IF_LOCKED   0 /* default */
00038 #define HA_OPEN_WAIT_IF_LOCKED    1
00039 #define HA_OPEN_IGNORE_IF_LOCKED  2
00040 #define HA_OPEN_TMP_TABLE   4 /* Table is a temp table */
00041 /* Internal temp table, used for temporary results */
00042 #define HA_OPEN_INTERNAL_TABLE          512
00043 
00044 /* The following is parameter to ha_rkey() how to use key */
00045 
00046 /*
00047   We define a complete-field prefix of a key value as a prefix where
00048   the last included field in the prefix contains the full field, not
00049   just some bytes from the start of the field. A partial-field prefix
00050   is allowed to contain only a few first bytes from the last included
00051   field.
00052 
00053   Below HA_READ_KEY_EXACT, ..., HA_READ_BEFORE_KEY can take a
00054   complete-field prefix of a key value as the search
00055   key. HA_READ_PREFIX and HA_READ_PREFIX_LAST could also take a
00056   partial-field prefix, but currently (4.0.10) they are only used with
00057   complete-field prefixes. MySQL uses a padding trick to implement
00058   LIKE 'abc%' queries.
00059 
00060   NOTE that in InnoDB HA_READ_PREFIX_LAST will NOT work with a
00061   partial-field prefix because InnoDB currently strips spaces from the
00062   end of varchar fields!
00063 */
00064 
00065 enum ha_rkey_function {
00066   HA_READ_KEY_EXACT,              /* Find first record else error */
00067   HA_READ_KEY_OR_NEXT,            /* Record or next record */
00068   HA_READ_KEY_OR_PREV,            /* Record or previous */
00069   HA_READ_AFTER_KEY,              /* Find next rec. after key-record */
00070   HA_READ_BEFORE_KEY,             /* Find next rec. before key-record */
00071   HA_READ_PREFIX,                 /* Key which as same prefix */
00072   HA_READ_PREFIX_LAST,            /* Last key with the same prefix */
00073   HA_READ_PREFIX_LAST_OR_PREV,    /* Last or prev key with the same prefix */
00074   HA_READ_MBR_CONTAIN,
00075   HA_READ_MBR_INTERSECT,
00076   HA_READ_MBR_WITHIN,
00077   HA_READ_MBR_DISJOINT,
00078   HA_READ_MBR_EQUAL
00079 };
00080 
00081   /* Key algorithm types */
00082 
00083 enum ha_key_alg {
00084   HA_KEY_ALG_UNDEF= 0,    /* Not specified (old file) */
00085   HA_KEY_ALG_BTREE= 1,    /* B-tree, default one          */
00086   HA_KEY_ALG_HASH=  3   /* HASH keys (HEAP tables) */
00087 };
00088 
00089   /* The following is parameter to ha_extra() */
00090 
00091 enum ha_extra_function {
00092   HA_EXTRA_NORMAL=0,      /* Optimize for space (def) */
00093   HA_EXTRA_QUICK=1,     /* Optimize for speed */
00094   HA_EXTRA_NOT_USED=2,
00095   HA_EXTRA_CACHE=3,     /* Cache record in HA_rrnd() */
00096   HA_EXTRA_NO_CACHE=4,      /* End caching of records (def) */
00097   HA_EXTRA_NO_READCHECK=5,    /* No readcheck on update */
00098   HA_EXTRA_READCHECK=6,     /* Use readcheck (def) */
00099   HA_EXTRA_KEYREAD=7,     /* Read only key to database */
00100   HA_EXTRA_NO_KEYREAD=8,    /* Normal read of records (def) */
00101   HA_EXTRA_NO_USER_CHANGE=9,    /* No user is allowed to write */
00102   HA_EXTRA_KEY_CACHE=10,
00103   HA_EXTRA_NO_KEY_CACHE=11,
00104   HA_EXTRA_WAIT_LOCK=12,    /* Wait until file is avalably (def) */
00105   HA_EXTRA_NO_WAIT_LOCK=13,   /* If file is locked, return quickly */
00106   HA_EXTRA_WRITE_CACHE=14,    /* Use write cache in ha_write() */
00107   HA_EXTRA_FLUSH_CACHE=15,    /* flush write_record_cache */
00108   HA_EXTRA_NO_KEYS=16,      /* Remove all update of keys */
00109   HA_EXTRA_KEYREAD_CHANGE_POS=17, /* Keyread, but change pos */
00110           /* xxxxchk -r must be used */
00111   HA_EXTRA_REMEMBER_POS=18,   /* Remember pos for next/prev */
00112   HA_EXTRA_RESTORE_POS=19,
00113   HA_EXTRA_REINIT_CACHE=20,   /* init cache from current record */
00114   HA_EXTRA_FORCE_REOPEN=21,   /* Datafile have changed on disk */
00115   HA_EXTRA_FLUSH,     /* Flush tables to disk */
00116   HA_EXTRA_NO_ROWS,     /* Don't write rows */
00117   HA_EXTRA_RESET_STATE,     /* Reset positions */
00118   HA_EXTRA_IGNORE_DUP_KEY,    /* Dup keys don't rollback everything*/
00119   HA_EXTRA_NO_IGNORE_DUP_KEY,
00120   HA_EXTRA_PREPARE_FOR_DROP,
00121   HA_EXTRA_PREPARE_FOR_UPDATE,    /* Remove read cache if problems */
00122   HA_EXTRA_PRELOAD_BUFFER_SIZE,         /* Set buffer size for preloading */
00123   /*
00124     On-the-fly switching between unique and non-unique key inserting.
00125   */
00126   HA_EXTRA_CHANGE_KEY_TO_UNIQUE,
00127   HA_EXTRA_CHANGE_KEY_TO_DUP,
00128   /*
00129     When using HA_EXTRA_KEYREAD, overwrite only key member fields and keep
00130     other fields intact. When this is off (by default) InnoDB will use memcpy
00131     to overwrite entire row.
00132   */
00133   HA_EXTRA_KEYREAD_PRESERVE_FIELDS,
00134   /*
00135     Ignore if the a tuple is not found, continue processing the
00136     transaction and ignore that 'row'.  Needed for idempotency
00137     handling on the slave
00138 
00139     Currently only used by NDB storage engine. Partition handler ignores flag.
00140   */
00141   HA_EXTRA_IGNORE_NO_KEY,
00142   HA_EXTRA_NO_IGNORE_NO_KEY,
00143   /*
00144     Informs handler that write_row() which tries to insert new row into the
00145     table and encounters some already existing row with same primary/unique
00146     key can replace old row with new row instead of reporting error (basically
00147     it informs handler that we do REPLACE instead of simple INSERT).
00148     Off by default.
00149   */
00150   HA_EXTRA_WRITE_CAN_REPLACE,
00151   HA_EXTRA_WRITE_CANNOT_REPLACE,
00152   /*
00153     Inform handler that delete_row()/update_row() cannot batch deletes/updates
00154     and should perform them immediately. This may be needed when table has
00155     AFTER DELETE/UPDATE triggers which access to subject table.
00156     These flags are reset by the handler::extra(HA_EXTRA_RESET) call.
00157   */
00158   HA_EXTRA_DELETE_CANNOT_BATCH,
00159   HA_EXTRA_UPDATE_CANNOT_BATCH,
00160   /*
00161     Inform handler that an "INSERT...ON DUPLICATE KEY UPDATE" will be
00162     executed. This condition is unset by HA_EXTRA_NO_IGNORE_DUP_KEY.
00163   */
00164   HA_EXTRA_INSERT_WITH_UPDATE,
00165   /* Inform handler that we will do a rename */
00166   HA_EXTRA_PREPARE_FOR_RENAME
00167 };
00168 
00169   /* The following is parameter to ha_panic() */
00170 
00171 enum ha_panic_function {
00172   HA_PANIC_CLOSE,     /* Close all databases */
00173   HA_PANIC_WRITE,     /* Unlock and write status */
00174   HA_PANIC_READ       /* Lock and read keyinfo */
00175 };
00176 
00177   /* The following is parameter to ha_create(); keytypes */
00178 
00179 enum ha_base_keytype {
00180   HA_KEYTYPE_END=0,
00181   HA_KEYTYPE_TEXT=1,      /* Key is sorted as letters */
00182   HA_KEYTYPE_BINARY=2,      /* Key is sorted as unsigned chars */
00183   HA_KEYTYPE_LONG_INT=4,
00184   HA_KEYTYPE_DOUBLE=6,
00185   HA_KEYTYPE_ULONG_INT=9,
00186   HA_KEYTYPE_LONGLONG=10,
00187   HA_KEYTYPE_ULONGLONG=11,
00188   /* Varchar (0-255 bytes) with length packed with 1 byte */
00189   HA_KEYTYPE_VARTEXT1=15,               /* Key is sorted as letters */
00190   HA_KEYTYPE_VARBINARY1=16,             /* Key is sorted as unsigned chars */
00191   /* Varchar (0-65535 bytes) with length packed with 2 bytes */
00192   HA_KEYTYPE_VARTEXT2=17,   /* Key is sorted as letters */
00193   HA_KEYTYPE_VARBINARY2=18    /* Key is sorted as unsigned chars */
00194 };
00195 
00196   /* These flags kan be OR:ed to key-flag */
00197 
00198 #define HA_NOSAME    1  /* Set if not dupplicated records */
00199 #define HA_PACK_KEY    2  /* Pack string key to previous key */
00200 #define HA_AUTO_KEY    16
00201 #define HA_BINARY_PACK_KEY   32 /* Packing of all keys to prev key */
00202 #define HA_UNIQUE_CHECK   256 /* Check the key for uniqueness */
00203 #define HA_NULL_ARE_EQUAL 2048  /* NULL in key are cmp as equal */
00204 #define HA_GENERATED_KEY  8192  /* Automaticly generated key */
00205 
00206 #define HA_KEY_HAS_PART_KEY_SEG 65536   /* Key contains partial segments */
00207 
00208   /* Automatic bits in key-flag */
00209 
00210 #define HA_SPACE_PACK_USED   4  /* Test for if SPACE_PACK used */
00211 #define HA_VAR_LENGTH_KEY  8
00212 #define HA_NULL_PART_KEY   64
00213 #define HA_USES_COMMENT          4096
00214 #define HA_USES_BLOCK_SIZE   ((uint32_t) 32768)
00215 #define HA_SORT_ALLOWS_SAME      512    /* Intern bit when sorting records */
00216 
00217   /* These flags can be added to key-seg-flag */
00218 
00219 #define HA_SPACE_PACK    1  /* Pack space in key-seg */
00220 #define HA_PART_KEY_SEG    4  /* Used by MySQL for part-key-cols */
00221 #define HA_VAR_LENGTH_PART   8
00222 #define HA_NULL_PART     16
00223 #define HA_BLOB_PART     32
00224 #define HA_SWAP_KEY    64
00225 #define HA_REVERSE_SORT    128  /* Sort key in reverse order */
00226 #define HA_NO_SORT               256 /* do not bother sorting on this keyseg */
00227 /*
00228   End space in unique/varchar are considered equal. (Like 'a' and 'a ')
00229   Only needed for internal temporary tables.
00230 */
00231 #define HA_END_SPACE_ARE_EQUAL   512
00232 #define HA_BIT_PART   1024
00233 
00234   /* optionbits for database */
00235 #define HA_OPTION_PACK_RECORD   1
00236 #define HA_OPTION_PACK_KEYS   2
00237 #define HA_OPTION_COMPRESS_RECORD 4
00238 #define HA_OPTION_TMP_TABLE   16
00239 #define HA_OPTION_NO_PACK_KEYS    128  /* Reserved for MySQL */
00240 #define HA_OPTION_TEMP_COMPRESS_RECORD  ((uint32_t) 16384)  /* set by isamchk */
00241 #define HA_OPTION_READ_ONLY_DATA  ((uint32_t) 32768)  /* Set by isamchk */
00242 
00243   /* Bits in flag to create() */
00244 
00245 #define HA_DONT_TOUCH_DATA  1 /* Don't empty datafile (isamchk) */
00246 #define HA_PACK_RECORD    2 /* Request packed record format */
00247 #define HA_CREATE_TMP_TABLE 4
00248 #define HA_CREATE_KEEP_FILES  16      /* don't overwrite .MYD and MYI */
00249 
00250 /*
00251   The following flags (OR-ed) are passed to handler::info() method.
00252   The method copies misc handler information out of the storage engine
00253   to data structures accessible from MySQL
00254 
00255   Same flags are also passed down to mi_status, myrg_status, etc.
00256 */
00257 
00258 /* this one is not used */
00259 #define HA_STATUS_POS            1
00260 /*
00261   assuming the table keeps shared actual copy of the 'info' and
00262   local, possibly outdated copy, the following flag means that
00263   it should not try to get the actual data (locking the shared structure)
00264   slightly outdated version will suffice
00265 */
00266 #define HA_STATUS_NO_LOCK        2
00267 /* update the time of the last modification (in handler::update_time) */
00268 #define HA_STATUS_TIME           4
00269 /*
00270   update the 'constant' part of the info:
00271   handler::max_data_file_length, max_index_file_length, create_time
00272   sortkey, ref_length, block_size, data_file_name, index_file_name.
00273   handler::table->s->keys_in_use, keys_for_keyread, rec_per_key
00274 */
00275 #define HA_STATUS_CONST          8
00276 /*
00277   update the 'variable' part of the info:
00278   handler::records, deleted, data_file_length, index_file_length,
00279   delete_length, check_time, mean_rec_length
00280 */
00281 #define HA_STATUS_VARIABLE      16
00282 /*
00283   get the information about the key that caused last duplicate value error
00284   update handler::errkey and handler::dupp_ref
00285   see handler::get_dup_key()
00286 */
00287 #define HA_STATUS_ERRKEY        32
00288 /*
00289   update handler::auto_increment_value
00290 */
00291 #define HA_STATUS_AUTO          64
00292 
00293 /*
00294   Errorcodes given by handler functions
00295 
00296   optimizer::sum_query() assumes these codes are > 1
00297   Do not add error numbers before HA_ERR_FIRST.
00298   If necessary to add lower numbers, change HA_ERR_FIRST accordingly.
00299 */
00300 #define HA_ERR_FIRST            120     /* Copy of first error nr.*/
00301 
00302 /* Other constants */
00303 
00304 typedef unsigned long key_part_map;
00305 #define HA_WHOLE_KEY  (~(key_part_map)0)
00306 
00307   /* Intern constants in databases */
00308 
00309   /* bits in _search */
00310 #define SEARCH_FIND 1
00311 #define SEARCH_NO_FIND  2
00312 #define SEARCH_SAME 4
00313 #define SEARCH_BIGGER 8
00314 #define SEARCH_SMALLER  16
00315 #define SEARCH_SAVE_BUFF  32
00316 #define SEARCH_UPDATE 64
00317 #define SEARCH_PREFIX 128
00318 #define SEARCH_LAST 256
00319 #define MBR_CONTAIN     512
00320 #define MBR_INTERSECT   1024
00321 #define MBR_WITHIN      2048
00322 #define MBR_DISJOINT    4096
00323 #define MBR_EQUAL       8192
00324 #define SEARCH_NULL_ARE_EQUAL 32768 /* NULL in keys are equal */
00325 #define SEARCH_NULL_ARE_NOT_EQUAL 65536 /* NULL in keys are not equal */
00326 
00327   /* bits in opt_flag */
00328 #define READ_CACHE_USED 2
00329 #define READ_CHECK_USED 4
00330 #define KEY_READ_USED 8
00331 #define WRITE_CACHE_USED 16
00332 #define OPT_NO_ROWS 32
00333 
00334   /* bits in update */
00335 #define HA_STATE_CHANGED  1 /* Database has changed */
00336 #define HA_STATE_AKTIV    2 /* Has a current record */
00337 #define HA_STATE_WRITTEN  4 /* Record is written */
00338 #define HA_STATE_DELETED  8
00339 #define HA_STATE_NEXT_FOUND 16  /* Next found record (record before) */
00340 #define HA_STATE_PREV_FOUND 32  /* Prev found record (record after) */
00341 #define HA_STATE_KEY_CHANGED  128
00342 #define HA_STATE_WRITE_AT_END 256 /* set in _ps_find_writepos */
00343 #define HA_STATE_ROW_CHANGED  1024  /* To invalide ROW cache */
00344 #define HA_STATE_EXTEND_BLOCK 2048
00345 #define HA_STATE_RNEXT_SAME 4096  /* rnext_same occupied lastkey2 */
00346 
00347 /* myisampack expects no more than 32 field types. */
00348 enum en_fieldtype {
00349   FIELD_LAST=-1,FIELD_NORMAL,FIELD_SKIP_ENDSPACE,FIELD_SKIP_PRESPACE,
00350   FIELD_SKIP_ZERO,FIELD_BLOB,FIELD_CONSTANT,FIELD_INTERVALL,FIELD_ZERO,
00351   FIELD_VARCHAR,FIELD_CHECK,
00352   FIELD_enum_val_count
00353 };
00354 
00355 enum data_file_type {
00356   STATIC_RECORD, DYNAMIC_RECORD, COMPRESSED_RECORD, BLOCK_RECORD
00357 };
00358 
00359 /* For key ranges */
00360 
00361 /* from -inf */
00362 #define NO_MIN_RANGE  1
00363 
00364 /* to +inf */
00365 #define NO_MAX_RANGE  2
00366 
00367 /*  X < key, i.e. not including the left endpoint */
00368 #define NEAR_MIN  4
00369 
00370 /* X > key, i.e. not including the right endpoint */
00371 #define NEAR_MAX  8
00372 
00373 /*
00374   This flag means that index is a unique index, and the interval is
00375   equivalent to "AND(keypart_i = const_i)", where all of const_i are not NULLs.
00376 */
00377 #define UNIQUE_RANGE  16
00378 
00379 /*
00380   This flag means that the interval is equivalent to
00381   "AND(keypart_i = const_i)", where not all key parts may be used but all of
00382   const_i are not NULLs.
00383 */
00384 #define EQ_RANGE  32
00385 
00386 /*
00387   This flag has the same meaning as UNIQUE_RANGE, except that for at least
00388   one keypart the condition is "keypart IS NULL".
00389 */
00390 #define NULL_RANGE  64
00391 
00392 class key_range
00393 {
00394 public:
00395   const unsigned char *key;
00396   uint32_t length;
00397   enum ha_rkey_function flag;
00398   key_part_map keypart_map;
00399 };
00400 
00401 class KEY_MULTI_RANGE
00402 {
00403 public:
00404   key_range start_key;
00405   key_range end_key;
00406   char  *ptr;                 /* Free to use by caller (ptr to row etc) */
00407   uint32_t  range_flag;           /* key range flags see above */
00408 };
00409 
00410 
00411 /* For number of records */
00412 typedef uint64_t  ha_rows;
00413 
00414 #define HA_POS_ERROR  (~ (::drizzled::ha_rows) 0)
00415 #define HA_OFFSET_ERROR (~ (::drizzled::internal::my_off_t) 0)
00416 
00417 #if SIZEOF_OFF_T == 4
00418 #define MAX_FILE_SIZE INT32_MAX
00419 #else
00420 #define MAX_FILE_SIZE INT64_MAX
00421 #endif
00422 
00423 inline static uint32_t ha_varchar_packlength(uint32_t field_length)
00424 {
00425   return (field_length < 256 ? 1 :2);
00426 }
00427 
00428 
00429 } /* namespace drizzled */
00430