00001 /************************************************************************ 00002 SQL data field and tuple 00003 00004 (c) 1994-1996 Innobase Oy 00005 00006 Created 5/30/1994 Heikki Tuuri 00007 *************************************************************************/ 00008 00009 #ifndef data0data_h 00010 #define data0data_h 00011 00012 #include "univ.i" 00013 00014 #include "data0types.h" 00015 #include "data0type.h" 00016 #include "mem0mem.h" 00017 #include "dict0types.h" 00018 00019 typedef struct big_rec_struct big_rec_t; 00020 00021 /* Some non-inlined functions used in the MySQL interface: */ 00022 void 00023 dfield_set_data_noninline( 00024 dfield_t* field, /* in: field */ 00025 void* data, /* in: data */ 00026 ulint len); /* in: length or UNIV_SQL_NULL */ 00027 void* 00028 dfield_get_data_noninline( 00029 dfield_t* field); /* in: field */ 00030 ulint 00031 dfield_get_len_noninline( 00032 dfield_t* field); /* in: field */ 00033 ulint 00034 dtuple_get_n_fields_noninline( 00035 dtuple_t* tuple); /* in: tuple */ 00036 dfield_t* 00037 dtuple_get_nth_field_noninline( 00038 dtuple_t* tuple, /* in: tuple */ 00039 ulint n); /* in: index of field */ 00040 00041 /************************************************************************* 00042 Gets pointer to the type struct of SQL data field. */ 00043 UNIV_INLINE 00044 dtype_t* 00045 dfield_get_type( 00046 /*============*/ 00047 /* out: pointer to the type struct */ 00048 dfield_t* field); /* in: SQL data field */ 00049 /************************************************************************* 00050 Sets the type struct of SQL data field. */ 00051 UNIV_INLINE 00052 void 00053 dfield_set_type( 00054 /*============*/ 00055 dfield_t* field, /* in: SQL data field */ 00056 dtype_t* type); /* in: pointer to data type struct */ 00057 /************************************************************************* 00058 Gets pointer to the data in a field. */ 00059 UNIV_INLINE 00060 void* 00061 dfield_get_data( 00062 /*============*/ 00063 /* out: pointer to data */ 00064 dfield_t* field); /* in: field */ 00065 /************************************************************************* 00066 Gets length of field data. */ 00067 UNIV_INLINE 00068 ulint 00069 dfield_get_len( 00070 /*===========*/ 00071 /* out: length of data; UNIV_SQL_NULL if 00072 SQL null data */ 00073 dfield_t* field); /* in: field */ 00074 /************************************************************************* 00075 Sets length in a field. */ 00076 UNIV_INLINE 00077 void 00078 dfield_set_len( 00079 /*===========*/ 00080 dfield_t* field, /* in: field */ 00081 ulint len); /* in: length or UNIV_SQL_NULL */ 00082 /************************************************************************* 00083 Sets pointer to the data and length in a field. */ 00084 UNIV_INLINE 00085 void 00086 dfield_set_data( 00087 /*============*/ 00088 dfield_t* field, /* in: field */ 00089 const void* data, /* in: data */ 00090 ulint len); /* in: length or UNIV_SQL_NULL */ 00091 /************************************************************************** 00092 Writes an SQL null field full of zeros. */ 00093 UNIV_INLINE 00094 void 00095 data_write_sql_null( 00096 /*================*/ 00097 byte* data, /* in: pointer to a buffer of size len */ 00098 ulint len); /* in: SQL null size in bytes */ 00099 /************************************************************************* 00100 Copies the data and len fields. */ 00101 UNIV_INLINE 00102 void 00103 dfield_copy_data( 00104 /*=============*/ 00105 dfield_t* field1, /* in: field to copy to */ 00106 dfield_t* field2);/* in: field to copy from */ 00107 /************************************************************************* 00108 Copies a data field to another. */ 00109 UNIV_INLINE 00110 void 00111 dfield_copy( 00112 /*========*/ 00113 dfield_t* field1, /* in: field to copy to */ 00114 dfield_t* field2);/* in: field to copy from */ 00115 /************************************************************************* 00116 Tests if data length and content is equal for two dfields. */ 00117 UNIV_INLINE 00118 ibool 00119 dfield_datas_are_binary_equal( 00120 /*==========================*/ 00121 /* out: TRUE if equal */ 00122 dfield_t* field1, /* in: field */ 00123 dfield_t* field2);/* in: field */ 00124 /************************************************************************* 00125 Tests if dfield data length and content is equal to the given. */ 00126 00127 ibool 00128 dfield_data_is_binary_equal( 00129 /*========================*/ 00130 /* out: TRUE if equal */ 00131 dfield_t* field, /* in: field */ 00132 ulint len, /* in: data length or UNIV_SQL_NULL */ 00133 byte* data); /* in: data */ 00134 /************************************************************************* 00135 Gets number of fields in a data tuple. */ 00136 UNIV_INLINE 00137 ulint 00138 dtuple_get_n_fields( 00139 /*================*/ 00140 /* out: number of fields */ 00141 dtuple_t* tuple); /* in: tuple */ 00142 /************************************************************************* 00143 Gets nth field of a tuple. */ 00144 UNIV_INLINE 00145 dfield_t* 00146 dtuple_get_nth_field( 00147 /*=================*/ 00148 /* out: nth field */ 00149 dtuple_t* tuple, /* in: tuple */ 00150 ulint n); /* in: index of field */ 00151 /************************************************************************* 00152 Gets info bits in a data tuple. */ 00153 UNIV_INLINE 00154 ulint 00155 dtuple_get_info_bits( 00156 /*=================*/ 00157 /* out: info bits */ 00158 dtuple_t* tuple); /* in: tuple */ 00159 /************************************************************************* 00160 Sets info bits in a data tuple. */ 00161 UNIV_INLINE 00162 void 00163 dtuple_set_info_bits( 00164 /*=================*/ 00165 dtuple_t* tuple, /* in: tuple */ 00166 ulint info_bits); /* in: info bits */ 00167 /************************************************************************* 00168 Gets number of fields used in record comparisons. */ 00169 UNIV_INLINE 00170 ulint 00171 dtuple_get_n_fields_cmp( 00172 /*====================*/ 00173 /* out: number of fields used in comparisons 00174 in rem0cmp.* */ 00175 dtuple_t* tuple); /* in: tuple */ 00176 /************************************************************************* 00177 Gets number of fields used in record comparisons. */ 00178 UNIV_INLINE 00179 void 00180 dtuple_set_n_fields_cmp( 00181 /*====================*/ 00182 dtuple_t* tuple, /* in: tuple */ 00183 ulint n_fields_cmp); /* in: number of fields used in 00184 comparisons in rem0cmp.* */ 00185 /************************************************************** 00186 Creates a data tuple to a memory heap. The default value for number 00187 of fields used in record comparisons for this tuple is n_fields. */ 00188 UNIV_INLINE 00189 dtuple_t* 00190 dtuple_create( 00191 /*==========*/ 00192 /* out, own: created tuple */ 00193 mem_heap_t* heap, /* in: memory heap where the tuple 00194 is created */ 00195 ulint n_fields); /* in: number of fields */ 00196 00197 /************************************************************************* 00198 Creates a dtuple for use in MySQL. */ 00199 00200 dtuple_t* 00201 dtuple_create_for_mysql( 00202 /*====================*/ 00203 /* out, own created dtuple */ 00204 void** heap, /* out: created memory heap */ 00205 ulint n_fields); /* in: number of fields */ 00206 /************************************************************************* 00207 Frees a dtuple used in MySQL. */ 00208 00209 void 00210 dtuple_free_for_mysql( 00211 /*==================*/ 00212 void* heap); 00213 /************************************************************************* 00214 Sets number of fields used in a tuple. Normally this is set in 00215 dtuple_create, but if you want later to set it smaller, you can use this. */ 00216 00217 void 00218 dtuple_set_n_fields( 00219 /*================*/ 00220 dtuple_t* tuple, /* in: tuple */ 00221 ulint n_fields); /* in: number of fields */ 00222 /************************************************************** 00223 The following function returns the sum of data lengths of a tuple. The space 00224 occupied by the field structs or the tuple struct is not counted. */ 00225 UNIV_INLINE 00226 ulint 00227 dtuple_get_data_size( 00228 /*=================*/ 00229 /* out: sum of data lens */ 00230 dtuple_t* tuple); /* in: typed data tuple */ 00231 /**************************************************************** 00232 Returns TRUE if lengths of two dtuples are equal and respective data fields 00233 in them are equal when compared with collation in char fields (not as binary 00234 strings). */ 00235 00236 ibool 00237 dtuple_datas_are_ordering_equal( 00238 /*============================*/ 00239 /* out: TRUE if length and fieds are equal 00240 when compared with cmp_data_data: 00241 NOTE: in character type fields some letters 00242 are identified with others! (collation) */ 00243 dtuple_t* tuple1, /* in: tuple 1 */ 00244 dtuple_t* tuple2);/* in: tuple 2 */ 00245 /**************************************************************** 00246 Folds a prefix given as the number of fields of a tuple. */ 00247 UNIV_INLINE 00248 ulint 00249 dtuple_fold( 00250 /*========*/ 00251 /* out: the folded value */ 00252 dtuple_t* tuple, /* in: the tuple */ 00253 ulint n_fields,/* in: number of complete fields to fold */ 00254 ulint n_bytes,/* in: number of bytes to fold in an 00255 incomplete last field */ 00256 dulint tree_id);/* in: index tree id */ 00257 /*********************************************************************** 00258 Sets types of fields binary in a tuple. */ 00259 UNIV_INLINE 00260 void 00261 dtuple_set_types_binary( 00262 /*====================*/ 00263 dtuple_t* tuple, /* in: data tuple */ 00264 ulint n); /* in: number of fields to set */ 00265 /************************************************************************** 00266 Checks if a dtuple contains an SQL null value. */ 00267 UNIV_INLINE 00268 ibool 00269 dtuple_contains_null( 00270 /*=================*/ 00271 /* out: TRUE if some field is SQL null */ 00272 dtuple_t* tuple); /* in: dtuple */ 00273 /************************************************************** 00274 Checks that a data field is typed. Asserts an error if not. */ 00275 00276 ibool 00277 dfield_check_typed( 00278 /*===============*/ 00279 /* out: TRUE if ok */ 00280 dfield_t* field); /* in: data field */ 00281 /************************************************************** 00282 Checks that a data tuple is typed. Asserts an error if not. */ 00283 00284 ibool 00285 dtuple_check_typed( 00286 /*===============*/ 00287 /* out: TRUE if ok */ 00288 dtuple_t* tuple); /* in: tuple */ 00289 /************************************************************** 00290 Checks that a data tuple is typed. */ 00291 00292 ibool 00293 dtuple_check_typed_no_assert( 00294 /*=========================*/ 00295 /* out: TRUE if ok */ 00296 dtuple_t* tuple); /* in: tuple */ 00297 #ifdef UNIV_DEBUG 00298 /************************************************************** 00299 Validates the consistency of a tuple which must be complete, i.e, 00300 all fields must have been set. */ 00301 00302 ibool 00303 dtuple_validate( 00304 /*============*/ 00305 /* out: TRUE if ok */ 00306 dtuple_t* tuple); /* in: tuple */ 00307 #endif /* UNIV_DEBUG */ 00308 /***************************************************************** 00309 Pretty prints a dfield value according to its data type. */ 00310 00311 void 00312 dfield_print( 00313 /*=========*/ 00314 dfield_t* dfield);/* in: dfield */ 00315 /***************************************************************** 00316 Pretty prints a dfield value according to its data type. Also the hex string 00317 is printed if a string contains non-printable characters. */ 00318 00319 void 00320 dfield_print_also_hex( 00321 /*==================*/ 00322 dfield_t* dfield); /* in: dfield */ 00323 /***************************************************************** 00324 Print a dfield value using ut_print_buf. */ 00325 00326 void 00327 dfield_print_raw( 00328 /*=============*/ 00329 FILE* f, /* in: output stream */ 00330 dfield_t* dfield); /* in: dfield */ 00331 /************************************************************** 00332 The following function prints the contents of a tuple. */ 00333 00334 void 00335 dtuple_print( 00336 /*=========*/ 00337 FILE* f, /* in: output stream */ 00338 dtuple_t* tuple); /* in: tuple */ 00339 /****************************************************************** 00340 Moves parts of long fields in entry to the big record vector so that 00341 the size of tuple drops below the maximum record size allowed in the 00342 database. Moves data only from those fields which are not necessary 00343 to determine uniquely the insertion place of the tuple in the index. */ 00344 00345 big_rec_t* 00346 dtuple_convert_big_rec( 00347 /*===================*/ 00348 /* out, own: created big record vector, 00349 NULL if we are not able to shorten 00350 the entry enough, i.e., if there are 00351 too many short fields in entry */ 00352 dict_index_t* index, /* in: index */ 00353 dtuple_t* entry, /* in: index entry */ 00354 ulint* ext_vec,/* in: array of externally stored fields, 00355 or NULL: if a field already is externally 00356 stored, then we cannot move it to the vector 00357 this function returns */ 00358 ulint n_ext_vec);/* in: number of elements is ext_vec */ 00359 /****************************************************************** 00360 Puts back to entry the data stored in vector. Note that to ensure the 00361 fields in entry can accommodate the data, vector must have been created 00362 from entry with dtuple_convert_big_rec. */ 00363 00364 void 00365 dtuple_convert_back_big_rec( 00366 /*========================*/ 00367 dict_index_t* index, /* in: index */ 00368 dtuple_t* entry, /* in: entry whose data was put to vector */ 00369 big_rec_t* vector);/* in, own: big rec vector; it is 00370 freed in this function */ 00371 /****************************************************************** 00372 Frees the memory in a big rec vector. */ 00373 00374 void 00375 dtuple_big_rec_free( 00376 /*================*/ 00377 big_rec_t* vector); /* in, own: big rec vector; it is 00378 freed in this function */ 00379 00380 /*######################################################################*/ 00381 00382 /* Structure for an SQL data field */ 00383 struct dfield_struct{ 00384 void* data; /* pointer to data */ 00385 ulint len; /* data length; UNIV_SQL_NULL if SQL null; */ 00386 dtype_t type; /* type of data */ 00387 }; 00388 00389 struct dtuple_struct { 00390 ulint info_bits; /* info bits of an index record: 00391 the default is 0; this field is used 00392 if an index record is built from 00393 a data tuple */ 00394 ulint n_fields; /* number of fields in dtuple */ 00395 ulint n_fields_cmp; /* number of fields which should 00396 be used in comparison services 00397 of rem0cmp.*; the index search 00398 is performed by comparing only these 00399 fields, others are ignored; the 00400 default value in dtuple creation is 00401 the same value as n_fields */ 00402 dfield_t* fields; /* fields */ 00403 UT_LIST_NODE_T(dtuple_t) tuple_list; 00404 /* data tuples can be linked into a 00405 list using this field */ 00406 ulint magic_n; 00407 }; 00408 #define DATA_TUPLE_MAGIC_N 65478679 00409 00410 /* A slot for a field in a big rec vector */ 00411 00412 typedef struct big_rec_field_struct big_rec_field_t; 00413 struct big_rec_field_struct { 00414 ulint field_no; /* field number in record */ 00415 ulint len; /* stored data len */ 00416 byte* data; /* stored data */ 00417 }; 00418 00419 /* Storage format for overflow data in a big record, that is, a record 00420 which needs external storage of data fields */ 00421 00422 struct big_rec_struct { 00423 mem_heap_t* heap; /* memory heap from which allocated */ 00424 ulint n_fields; /* number of stored fields */ 00425 big_rec_field_t* fields; /* stored fields */ 00426 }; 00427 00428 #ifndef UNIV_NONINL 00429 #include "data0data.ic" 00430 #endif 00431 00432 #endif
1.4.7

