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