00001 /************************************************************************ 00002 Record manager 00003 00004 (c) 1994-1996 Innobase Oy 00005 00006 Created 5/30/1994 Heikki Tuuri 00007 *************************************************************************/ 00008 00009 #ifndef rem0rec_h 00010 #define rem0rec_h 00011 00012 #include "univ.i" 00013 #include "data0data.h" 00014 #include "rem0types.h" 00015 #include "mtr0types.h" 00016 00017 /* Maximum values for various fields (for non-blob tuples) */ 00018 #define REC_MAX_N_FIELDS (1024 - 1) 00019 #define REC_MAX_HEAP_NO (2 * 8192 - 1) 00020 #define REC_MAX_N_OWNED (16 - 1) 00021 00022 /* Info bit denoting the predefined minimum record: this bit is set 00023 if and only if the record is the first user record on a non-leaf 00024 B-tree page that is the leftmost page on its level 00025 (PAGE_LEVEL is nonzero and FIL_PAGE_PREV is FIL_NULL). */ 00026 #define REC_INFO_MIN_REC_FLAG 0x10UL 00027 00028 /* Number of extra bytes in an old-style record, 00029 in addition to the data and the offsets */ 00030 #define REC_N_OLD_EXTRA_BYTES 6 00031 /* Number of extra bytes in a new-style record, 00032 in addition to the data and the offsets */ 00033 #define REC_N_NEW_EXTRA_BYTES 5 00034 00035 /* Record status values */ 00036 #define REC_STATUS_ORDINARY 0 00037 #define REC_STATUS_NODE_PTR 1 00038 #define REC_STATUS_INFIMUM 2 00039 #define REC_STATUS_SUPREMUM 3 00040 00041 /* Number of elements that should be initially allocated for the 00042 offsets[] array, first passed to rec_get_offsets() */ 00043 #define REC_OFFS_NORMAL_SIZE 100 00044 #define REC_OFFS_SMALL_SIZE 10 00045 00046 /********************************************************** 00047 The following function is used to get the offset of the 00048 next chained record on the same page. */ 00049 UNIV_INLINE 00050 ulint 00051 rec_get_next_offs( 00052 /*==============*/ 00053 /* out: the page offset of the next 00054 chained record */ 00055 rec_t* rec, /* in: physical record */ 00056 ulint comp); /* in: nonzero=compact page format */ 00057 /********************************************************** 00058 The following function is used to set the next record offset field 00059 of the record. */ 00060 UNIV_INLINE 00061 void 00062 rec_set_next_offs( 00063 /*==============*/ 00064 rec_t* rec, /* in: physical record */ 00065 ulint comp, /* in: nonzero=compact page format */ 00066 ulint next); /* in: offset of the next record */ 00067 /********************************************************** 00068 The following function is used to get the number of fields 00069 in an old-style record. */ 00070 UNIV_INLINE 00071 ulint 00072 rec_get_n_fields_old( 00073 /*=================*/ 00074 /* out: number of data fields */ 00075 rec_t* rec); /* in: physical record */ 00076 /********************************************************** 00077 The following function is used to get the number of fields 00078 in a record. */ 00079 UNIV_INLINE 00080 ulint 00081 rec_get_n_fields( 00082 /*=============*/ 00083 /* out: number of data fields */ 00084 rec_t* rec, /* in: physical record */ 00085 dict_index_t* index); /* in: record descriptor */ 00086 /********************************************************** 00087 The following function is used to get the number of records 00088 owned by the previous directory record. */ 00089 UNIV_INLINE 00090 ulint 00091 rec_get_n_owned( 00092 /*============*/ 00093 /* out: number of owned records */ 00094 rec_t* rec, /* in: physical record */ 00095 ulint comp); /* in: nonzero=compact page format */ 00096 /********************************************************** 00097 The following function is used to set the number of owned 00098 records. */ 00099 UNIV_INLINE 00100 void 00101 rec_set_n_owned( 00102 /*============*/ 00103 rec_t* rec, /* in: physical record */ 00104 ulint comp, /* in: nonzero=compact page format */ 00105 ulint n_owned); /* in: the number of owned */ 00106 /********************************************************** 00107 The following function is used to retrieve the info bits of 00108 a record. */ 00109 UNIV_INLINE 00110 ulint 00111 rec_get_info_bits( 00112 /*==============*/ 00113 /* out: info bits */ 00114 rec_t* rec, /* in: physical record */ 00115 ulint comp); /* in: nonzero=compact page format */ 00116 /********************************************************** 00117 The following function is used to set the info bits of a record. */ 00118 UNIV_INLINE 00119 void 00120 rec_set_info_bits( 00121 /*==============*/ 00122 rec_t* rec, /* in: physical record */ 00123 ulint comp, /* in: nonzero=compact page format */ 00124 ulint bits); /* in: info bits */ 00125 /********************************************************** 00126 The following function retrieves the status bits of a new-style record. */ 00127 UNIV_INLINE 00128 ulint 00129 rec_get_status( 00130 /*===========*/ 00131 /* out: status bits */ 00132 rec_t* rec); /* in: physical record */ 00133 00134 /********************************************************** 00135 The following function is used to set the status bits of a new-style record. */ 00136 UNIV_INLINE 00137 void 00138 rec_set_status( 00139 /*===========*/ 00140 rec_t* rec, /* in: physical record */ 00141 ulint bits); /* in: info bits */ 00142 00143 /********************************************************** 00144 The following function is used to retrieve the info and status 00145 bits of a record. (Only compact records have status bits.) */ 00146 UNIV_INLINE 00147 ulint 00148 rec_get_info_and_status_bits( 00149 /*=========================*/ 00150 /* out: info bits */ 00151 rec_t* rec, /* in: physical record */ 00152 ulint comp); /* in: nonzero=compact page format */ 00153 /********************************************************** 00154 The following function is used to set the info and status 00155 bits of a record. (Only compact records have status bits.) */ 00156 UNIV_INLINE 00157 void 00158 rec_set_info_and_status_bits( 00159 /*=========================*/ 00160 rec_t* rec, /* in: physical record */ 00161 ulint comp, /* in: nonzero=compact page format */ 00162 ulint bits); /* in: info bits */ 00163 00164 /********************************************************** 00165 The following function tells if record is delete marked. */ 00166 UNIV_INLINE 00167 ulint 00168 rec_get_deleted_flag( 00169 /*=================*/ 00170 /* out: nonzero if delete marked */ 00171 rec_t* rec, /* in: physical record */ 00172 ulint comp); /* in: nonzero=compact page format */ 00173 /********************************************************** 00174 The following function is used to set the deleted bit. */ 00175 UNIV_INLINE 00176 void 00177 rec_set_deleted_flag( 00178 /*=================*/ 00179 rec_t* rec, /* in: physical record */ 00180 ulint comp, /* in: nonzero=compact page format */ 00181 ulint flag); /* in: nonzero if delete marked */ 00182 /********************************************************** 00183 The following function tells if a new-style record is a node pointer. */ 00184 UNIV_INLINE 00185 ibool 00186 rec_get_node_ptr_flag( 00187 /*==================*/ 00188 /* out: TRUE if node pointer */ 00189 rec_t* rec); /* in: physical record */ 00190 /********************************************************** 00191 The following function is used to get the order number 00192 of the record in the heap of the index page. */ 00193 UNIV_INLINE 00194 ulint 00195 rec_get_heap_no( 00196 /*============*/ 00197 /* out: heap order number */ 00198 rec_t* rec, /* in: physical record */ 00199 ulint comp); /* in: nonzero=compact page format */ 00200 /********************************************************** 00201 The following function is used to set the heap number 00202 field in the record. */ 00203 UNIV_INLINE 00204 void 00205 rec_set_heap_no( 00206 /*============*/ 00207 rec_t* rec, /* in: physical record */ 00208 ulint comp, /* in: nonzero=compact page format */ 00209 ulint heap_no);/* in: the heap number */ 00210 /********************************************************** 00211 The following function is used to test whether the data offsets 00212 in the record are stored in one-byte or two-byte format. */ 00213 UNIV_INLINE 00214 ibool 00215 rec_get_1byte_offs_flag( 00216 /*====================*/ 00217 /* out: TRUE if 1-byte form */ 00218 rec_t* rec); /* in: physical record */ 00219 /********************************************************** 00220 The following function determines the offsets to each field 00221 in the record. It can reuse a previously allocated array. */ 00222 00223 ulint* 00224 rec_get_offsets_func( 00225 /*=================*/ 00226 /* out: the new offsets */ 00227 rec_t* rec, /* in: physical record */ 00228 dict_index_t* index, /* in: record descriptor */ 00229 ulint* offsets,/* in: array consisting of offsets[0] 00230 allocated elements, or an array from 00231 rec_get_offsets(), or NULL */ 00232 ulint n_fields,/* in: maximum number of initialized fields 00233 (ULINT_UNDEFINED if all fields) */ 00234 mem_heap_t** heap, /* in/out: memory heap */ 00235 const char* file, /* in: file name where called */ 00236 ulint line); /* in: line number where called */ 00237 00238 #define rec_get_offsets(rec,index,offsets,n,heap) \ 00239 rec_get_offsets_func(rec,index,offsets,n,heap,__FILE__,__LINE__) 00240 00241 /**************************************************************** 00242 Validates offsets returned by rec_get_offsets(). */ 00243 UNIV_INLINE 00244 ibool 00245 rec_offs_validate( 00246 /*==============*/ 00247 /* out: TRUE if valid */ 00248 rec_t* rec, /* in: record or NULL */ 00249 dict_index_t* index, /* in: record descriptor or NULL */ 00250 const ulint* offsets);/* in: array returned by rec_get_offsets() */ 00251 /**************************************************************** 00252 Updates debug data in offsets, in order to avoid bogus 00253 rec_offs_validate() failures. */ 00254 UNIV_INLINE 00255 void 00256 rec_offs_make_valid( 00257 /*================*/ 00258 rec_t* rec, /* in: record */ 00259 dict_index_t* index,/* in: record descriptor */ 00260 ulint* offsets);/* in: array returned by rec_get_offsets() */ 00261 00262 /**************************************************************** 00263 The following function is used to get a pointer to the nth 00264 data field in an old-style record. */ 00265 00266 byte* 00267 rec_get_nth_field_old( 00268 /*==================*/ 00269 /* out: pointer to the field */ 00270 rec_t* rec, /* in: record */ 00271 ulint n, /* in: index of the field */ 00272 ulint* len); /* out: length of the field; UNIV_SQL_NULL 00273 if SQL null */ 00274 /**************************************************************** 00275 Gets the physical size of an old-style field. 00276 Also an SQL null may have a field of size > 0, 00277 if the data type is of a fixed size. */ 00278 UNIV_INLINE 00279 ulint 00280 rec_get_nth_field_size( 00281 /*===================*/ 00282 /* out: field size in bytes */ 00283 rec_t* rec, /* in: record */ 00284 ulint n); /* in: index of the field */ 00285 /**************************************************************** 00286 The following function is used to get a pointer to the nth 00287 data field in a record. */ 00288 UNIV_INLINE 00289 byte* 00290 rec_get_nth_field( 00291 /*==============*/ 00292 /* out: pointer to the field */ 00293 rec_t* rec, /* in: record */ 00294 const ulint* offsets,/* in: array returned by rec_get_offsets() */ 00295 ulint n, /* in: index of the field */ 00296 ulint* len); /* out: length of the field; UNIV_SQL_NULL 00297 if SQL null */ 00298 /********************************************************** 00299 Determine if the offsets are for a record in the new 00300 compact format. */ 00301 UNIV_INLINE 00302 ulint 00303 rec_offs_comp( 00304 /*==========*/ 00305 /* out: nonzero if compact format */ 00306 const ulint* offsets);/* in: array returned by rec_get_offsets() */ 00307 /********************************************************** 00308 Returns nonzero if the extern bit is set in nth field of rec. */ 00309 UNIV_INLINE 00310 ulint 00311 rec_offs_nth_extern( 00312 /*================*/ 00313 /* out: nonzero if externally stored */ 00314 const ulint* offsets,/* in: array returned by rec_get_offsets() */ 00315 ulint n); /* in: nth field */ 00316 /********************************************************** 00317 Returns nonzero if the SQL NULL bit is set in nth field of rec. */ 00318 UNIV_INLINE 00319 ulint 00320 rec_offs_nth_sql_null( 00321 /*==================*/ 00322 /* out: nonzero if SQL NULL */ 00323 const ulint* offsets,/* in: array returned by rec_get_offsets() */ 00324 ulint n); /* in: nth field */ 00325 /********************************************************** 00326 Gets the physical size of a field. */ 00327 UNIV_INLINE 00328 ulint 00329 rec_offs_nth_size( 00330 /*==============*/ 00331 /* out: length of field */ 00332 const ulint* offsets,/* in: array returned by rec_get_offsets() */ 00333 ulint n); /* in: nth field */ 00334 00335 /********************************************************** 00336 Returns TRUE if the extern bit is set in any of the fields 00337 of rec. */ 00338 UNIV_INLINE 00339 ibool 00340 rec_offs_any_extern( 00341 /*================*/ 00342 /* out: TRUE if a field is stored externally */ 00343 const ulint* offsets);/* in: array returned by rec_get_offsets() */ 00344 /*************************************************************** 00345 Sets the value of the ith field extern storage bit. */ 00346 UNIV_INLINE 00347 void 00348 rec_set_nth_field_extern_bit( 00349 /*=========================*/ 00350 rec_t* rec, /* in: record */ 00351 dict_index_t* index, /* in: record descriptor */ 00352 ulint i, /* in: ith field */ 00353 ibool val, /* in: value to set */ 00354 mtr_t* mtr); /* in: mtr holding an X-latch to the page 00355 where rec is, or NULL; in the NULL case 00356 we do not write to log about the change */ 00357 /*************************************************************** 00358 Sets TRUE the extern storage bits of fields mentioned in an array. */ 00359 00360 void 00361 rec_set_field_extern_bits( 00362 /*======================*/ 00363 rec_t* rec, /* in: record */ 00364 dict_index_t* index, /* in: record descriptor */ 00365 const ulint* vec, /* in: array of field numbers */ 00366 ulint n_fields,/* in: number of fields numbers */ 00367 mtr_t* mtr); /* in: mtr holding an X-latch to the page 00368 where rec is, or NULL; in the NULL case 00369 we do not write to log about the change */ 00370 /*************************************************************** 00371 This is used to modify the value of an already existing field in a record. 00372 The previous value must have exactly the same size as the new value. If len 00373 is UNIV_SQL_NULL then the field is treated as an SQL null for old-style 00374 records. For new-style records, len must not be UNIV_SQL_NULL. */ 00375 UNIV_INLINE 00376 void 00377 rec_set_nth_field( 00378 /*==============*/ 00379 rec_t* rec, /* in: record */ 00380 const ulint* offsets,/* in: array returned by rec_get_offsets() */ 00381 ulint n, /* in: index number of the field */ 00382 const void* data, /* in: pointer to the data if not SQL null */ 00383 ulint len); /* in: length of the data or UNIV_SQL_NULL. 00384 If not SQL null, must have the same 00385 length as the previous value. 00386 If SQL null, previous value must be 00387 SQL null. */ 00388 /************************************************************** 00389 The following function returns the data size of an old-style physical 00390 record, that is the sum of field lengths. SQL null fields 00391 are counted as length 0 fields. The value returned by the function 00392 is the distance from record origin to record end in bytes. */ 00393 UNIV_INLINE 00394 ulint 00395 rec_get_data_size_old( 00396 /*==================*/ 00397 /* out: size */ 00398 rec_t* rec); /* in: physical record */ 00399 /************************************************************** 00400 The following function returns the number of fields in a record. */ 00401 UNIV_INLINE 00402 ulint 00403 rec_offs_n_fields( 00404 /*==============*/ 00405 /* out: number of fields */ 00406 const ulint* offsets);/* in: array returned by rec_get_offsets() */ 00407 /************************************************************** 00408 The following function returns the data size of a physical 00409 record, that is the sum of field lengths. SQL null fields 00410 are counted as length 0 fields. The value returned by the function 00411 is the distance from record origin to record end in bytes. */ 00412 UNIV_INLINE 00413 ulint 00414 rec_offs_data_size( 00415 /*===============*/ 00416 /* out: size */ 00417 const ulint* offsets);/* in: array returned by rec_get_offsets() */ 00418 /************************************************************** 00419 Returns the total size of record minus data size of record. 00420 The value returned by the function is the distance from record 00421 start to record origin in bytes. */ 00422 UNIV_INLINE 00423 ulint 00424 rec_offs_extra_size( 00425 /*================*/ 00426 /* out: size */ 00427 const ulint* offsets);/* in: array returned by rec_get_offsets() */ 00428 /************************************************************** 00429 Returns the total size of a physical record. */ 00430 UNIV_INLINE 00431 ulint 00432 rec_offs_size( 00433 /*==========*/ 00434 /* out: size */ 00435 const ulint* offsets);/* in: array returned by rec_get_offsets() */ 00436 /************************************************************** 00437 Returns a pointer to the start of the record. */ 00438 UNIV_INLINE 00439 byte* 00440 rec_get_start( 00441 /*==========*/ 00442 /* out: pointer to start */ 00443 rec_t* rec, /* in: pointer to record */ 00444 const ulint* offsets);/* in: array returned by rec_get_offsets() */ 00445 /************************************************************** 00446 Returns a pointer to the end of the record. */ 00447 UNIV_INLINE 00448 byte* 00449 rec_get_end( 00450 /*========*/ 00451 /* out: pointer to end */ 00452 rec_t* rec, /* in: pointer to record */ 00453 const ulint* offsets);/* in: array returned by rec_get_offsets() */ 00454 /******************************************************************* 00455 Copies a physical record to a buffer. */ 00456 UNIV_INLINE 00457 rec_t* 00458 rec_copy( 00459 /*=====*/ 00460 /* out: pointer to the origin of the copy */ 00461 void* buf, /* in: buffer */ 00462 const rec_t* rec, /* in: physical record */ 00463 const ulint* offsets);/* in: array returned by rec_get_offsets() */ 00464 /****************************************************************** 00465 Copies the first n fields of a physical record to a new physical record in 00466 a buffer. */ 00467 00468 rec_t* 00469 rec_copy_prefix_to_buf( 00470 /*===================*/ 00471 /* out, own: copied record */ 00472 rec_t* rec, /* in: physical record */ 00473 dict_index_t* index, /* in: record descriptor */ 00474 ulint n_fields, /* in: number of fields to copy */ 00475 byte** buf, /* in/out: memory buffer 00476 for the copied prefix, or NULL */ 00477 ulint* buf_size); /* in/out: buffer size */ 00478 /**************************************************************** 00479 Folds a prefix of a physical record to a ulint. */ 00480 UNIV_INLINE 00481 ulint 00482 rec_fold( 00483 /*=====*/ 00484 /* out: the folded value */ 00485 rec_t* rec, /* in: the physical record */ 00486 const ulint* offsets, /* in: array returned by 00487 rec_get_offsets() */ 00488 ulint n_fields, /* in: number of complete 00489 fields to fold */ 00490 ulint n_bytes, /* in: number of bytes to fold 00491 in an incomplete last field */ 00492 dulint tree_id); /* in: index tree id */ 00493 /************************************************************* 00494 Builds a physical record out of a data tuple and stores it beginning from 00495 address destination. */ 00496 00497 rec_t* 00498 rec_convert_dtuple_to_rec( 00499 /*======================*/ 00500 /* out: pointer to the origin 00501 of physical record */ 00502 byte* buf, /* in: start address of the 00503 physical record */ 00504 dict_index_t* index, /* in: record descriptor */ 00505 dtuple_t* dtuple);/* in: data tuple */ 00506 /************************************************************** 00507 Returns the extra size of an old-style physical record if we know its 00508 data size and number of fields. */ 00509 UNIV_INLINE 00510 ulint 00511 rec_get_converted_extra_size( 00512 /*=========================*/ 00513 /* out: extra size */ 00514 ulint data_size, /* in: data size */ 00515 ulint n_fields) /* in: number of fields */ 00516 __attribute__((const)); 00517 /************************************************************** 00518 The following function returns the size of a data tuple when converted to 00519 a physical record. */ 00520 UNIV_INLINE 00521 ulint 00522 rec_get_converted_size( 00523 /*===================*/ 00524 /* out: size */ 00525 dict_index_t* index, /* in: record descriptor */ 00526 dtuple_t* dtuple);/* in: data tuple */ 00527 /****************************************************************** 00528 Copies the first n fields of a physical record to a data tuple. 00529 The fields are copied to the memory heap. */ 00530 00531 void 00532 rec_copy_prefix_to_dtuple( 00533 /*======================*/ 00534 dtuple_t* tuple, /* in: data tuple */ 00535 rec_t* rec, /* in: physical record */ 00536 dict_index_t* index, /* in: record descriptor */ 00537 ulint n_fields, /* in: number of fields to copy */ 00538 mem_heap_t* heap); /* in: memory heap */ 00539 /******************************************************************* 00540 Validates the consistency of a physical record. */ 00541 00542 ibool 00543 rec_validate( 00544 /*=========*/ 00545 /* out: TRUE if ok */ 00546 rec_t* rec, /* in: physical record */ 00547 const ulint* offsets);/* in: array returned by rec_get_offsets() */ 00548 /******************************************************************* 00549 Prints an old-style physical record. */ 00550 00551 void 00552 rec_print_old( 00553 /*==========*/ 00554 FILE* file, /* in: file where to print */ 00555 rec_t* rec); /* in: physical record */ 00556 /******************************************************************* 00557 Prints a physical record. */ 00558 00559 void 00560 rec_print_new( 00561 /*==========*/ 00562 FILE* file, /* in: file where to print */ 00563 rec_t* rec, /* in: physical record */ 00564 const ulint* offsets);/* in: array returned by rec_get_offsets() */ 00565 /******************************************************************* 00566 Prints a physical record. */ 00567 00568 void 00569 rec_print( 00570 /*======*/ 00571 FILE* file, /* in: file where to print */ 00572 rec_t* rec, /* in: physical record */ 00573 dict_index_t* index); /* in: record descriptor */ 00574 00575 #define REC_INFO_BITS 6 /* This is single byte bit-field */ 00576 00577 /* Maximum lengths for the data in a physical record if the offsets 00578 are given in one byte (resp. two byte) format. */ 00579 #define REC_1BYTE_OFFS_LIMIT 0x7FUL 00580 #define REC_2BYTE_OFFS_LIMIT 0x7FFFUL 00581 00582 /* The data size of record must be smaller than this because we reserve 00583 two upmost bits in a two byte offset for special purposes */ 00584 #define REC_MAX_DATA_SIZE (16 * 1024) 00585 00586 #ifndef UNIV_NONINL 00587 #include "rem0rec.ic" 00588 #endif 00589 00590 #endif
1.4.7

