mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / innobase / include / data0data.h
blob40592c3c0cee9c56f914c9a5fd50512d87477920
1 /************************************************************************
2 SQL data field and tuple
4 (c) 1994-1996 Innobase Oy
6 Created 5/30/1994 Heikki Tuuri
7 *************************************************************************/
9 #ifndef data0data_h
10 #define data0data_h
12 #include "univ.i"
14 #include "data0types.h"
15 #include "data0type.h"
16 #include "mem0mem.h"
17 #include "dict0types.h"
19 typedef struct big_rec_struct big_rec_t;
21 /* Some non-inlined functions used in the MySQL interface: */
22 void
23 dfield_set_data_noninline(
24 dfield_t* field, /* in: field */
25 void* data, /* in: data */
26 ulint len); /* in: length or UNIV_SQL_NULL */
27 void*
28 dfield_get_data_noninline(
29 dfield_t* field); /* in: field */
30 ulint
31 dfield_get_len_noninline(
32 dfield_t* field); /* in: field */
33 ulint
34 dtuple_get_n_fields_noninline(
35 dtuple_t* tuple); /* in: tuple */
36 dfield_t*
37 dtuple_get_nth_field_noninline(
38 dtuple_t* tuple, /* in: tuple */
39 ulint n); /* in: index of field */
41 /*************************************************************************
42 Gets pointer to the type struct of SQL data field. */
43 UNIV_INLINE
44 dtype_t*
45 dfield_get_type(
46 /*============*/
47 /* out: pointer to the type struct */
48 dfield_t* field); /* in: SQL data field */
49 /*************************************************************************
50 Sets the type struct of SQL data field. */
51 UNIV_INLINE
52 void
53 dfield_set_type(
54 /*============*/
55 dfield_t* field, /* in: SQL data field */
56 dtype_t* type); /* in: pointer to data type struct */
57 /*************************************************************************
58 Gets pointer to the data in a field. */
59 UNIV_INLINE
60 void*
61 dfield_get_data(
62 /*============*/
63 /* out: pointer to data */
64 dfield_t* field); /* in: field */
65 /*************************************************************************
66 Gets length of field data. */
67 UNIV_INLINE
68 ulint
69 dfield_get_len(
70 /*===========*/
71 /* out: length of data; UNIV_SQL_NULL if
72 SQL null data */
73 dfield_t* field); /* in: field */
74 /*************************************************************************
75 Sets length in a field. */
76 UNIV_INLINE
77 void
78 dfield_set_len(
79 /*===========*/
80 dfield_t* field, /* in: field */
81 ulint len); /* in: length or UNIV_SQL_NULL */
82 /*************************************************************************
83 Sets pointer to the data and length in a field. */
84 UNIV_INLINE
85 void
86 dfield_set_data(
87 /*============*/
88 dfield_t* field, /* in: field */
89 const void* data, /* in: data */
90 ulint len); /* in: length or UNIV_SQL_NULL */
91 /**************************************************************************
92 Writes an SQL null field full of zeros. */
93 UNIV_INLINE
94 void
95 data_write_sql_null(
96 /*================*/
97 byte* data, /* in: pointer to a buffer of size len */
98 ulint len); /* in: SQL null size in bytes */
99 /*************************************************************************
100 Copies the data and len fields. */
101 UNIV_INLINE
102 void
103 dfield_copy_data(
104 /*=============*/
105 dfield_t* field1, /* in: field to copy to */
106 dfield_t* field2);/* in: field to copy from */
107 /*************************************************************************
108 Copies a data field to another. */
109 UNIV_INLINE
110 void
111 dfield_copy(
112 /*========*/
113 dfield_t* field1, /* in: field to copy to */
114 dfield_t* field2);/* in: field to copy from */
115 /*************************************************************************
116 Tests if data length and content is equal for two dfields. */
117 UNIV_INLINE
118 ibool
119 dfield_datas_are_binary_equal(
120 /*==========================*/
121 /* out: TRUE if equal */
122 dfield_t* field1, /* in: field */
123 dfield_t* field2);/* in: field */
124 /*************************************************************************
125 Tests if dfield data length and content is equal to the given. */
127 ibool
128 dfield_data_is_binary_equal(
129 /*========================*/
130 /* out: TRUE if equal */
131 dfield_t* field, /* in: field */
132 ulint len, /* in: data length or UNIV_SQL_NULL */
133 byte* data); /* in: data */
134 /*************************************************************************
135 Gets number of fields in a data tuple. */
136 UNIV_INLINE
137 ulint
138 dtuple_get_n_fields(
139 /*================*/
140 /* out: number of fields */
141 dtuple_t* tuple); /* in: tuple */
142 /*************************************************************************
143 Gets nth field of a tuple. */
144 UNIV_INLINE
145 dfield_t*
146 dtuple_get_nth_field(
147 /*=================*/
148 /* out: nth field */
149 dtuple_t* tuple, /* in: tuple */
150 ulint n); /* in: index of field */
151 /*************************************************************************
152 Gets info bits in a data tuple. */
153 UNIV_INLINE
154 ulint
155 dtuple_get_info_bits(
156 /*=================*/
157 /* out: info bits */
158 dtuple_t* tuple); /* in: tuple */
159 /*************************************************************************
160 Sets info bits in a data tuple. */
161 UNIV_INLINE
162 void
163 dtuple_set_info_bits(
164 /*=================*/
165 dtuple_t* tuple, /* in: tuple */
166 ulint info_bits); /* in: info bits */
167 /*************************************************************************
168 Gets number of fields used in record comparisons. */
169 UNIV_INLINE
170 ulint
171 dtuple_get_n_fields_cmp(
172 /*====================*/
173 /* out: number of fields used in comparisons
174 in rem0cmp.* */
175 dtuple_t* tuple); /* in: tuple */
176 /*************************************************************************
177 Gets number of fields used in record comparisons. */
178 UNIV_INLINE
179 void
180 dtuple_set_n_fields_cmp(
181 /*====================*/
182 dtuple_t* tuple, /* in: tuple */
183 ulint n_fields_cmp); /* in: number of fields used in
184 comparisons in rem0cmp.* */
185 /**************************************************************
186 Creates a data tuple to a memory heap. The default value for number
187 of fields used in record comparisons for this tuple is n_fields. */
188 UNIV_INLINE
189 dtuple_t*
190 dtuple_create(
191 /*==========*/
192 /* out, own: created tuple */
193 mem_heap_t* heap, /* in: memory heap where the tuple
194 is created */
195 ulint n_fields); /* in: number of fields */
197 /*************************************************************************
198 Creates a dtuple for use in MySQL. */
200 dtuple_t*
201 dtuple_create_for_mysql(
202 /*====================*/
203 /* out, own created dtuple */
204 void** heap, /* out: created memory heap */
205 ulint n_fields); /* in: number of fields */
206 /*************************************************************************
207 Frees a dtuple used in MySQL. */
209 void
210 dtuple_free_for_mysql(
211 /*==================*/
212 void* heap);
213 /*************************************************************************
214 Sets number of fields used in a tuple. Normally this is set in
215 dtuple_create, but if you want later to set it smaller, you can use this. */
217 void
218 dtuple_set_n_fields(
219 /*================*/
220 dtuple_t* tuple, /* in: tuple */
221 ulint n_fields); /* in: number of fields */
222 /**************************************************************
223 The following function returns the sum of data lengths of a tuple. The space
224 occupied by the field structs or the tuple struct is not counted. */
225 UNIV_INLINE
226 ulint
227 dtuple_get_data_size(
228 /*=================*/
229 /* out: sum of data lens */
230 dtuple_t* tuple); /* in: typed data tuple */
231 /****************************************************************
232 Returns TRUE if lengths of two dtuples are equal and respective data fields
233 in them are equal when compared with collation in char fields (not as binary
234 strings). */
236 ibool
237 dtuple_datas_are_ordering_equal(
238 /*============================*/
239 /* out: TRUE if length and fieds are equal
240 when compared with cmp_data_data:
241 NOTE: in character type fields some letters
242 are identified with others! (collation) */
243 dtuple_t* tuple1, /* in: tuple 1 */
244 dtuple_t* tuple2);/* in: tuple 2 */
245 /****************************************************************
246 Folds a prefix given as the number of fields of a tuple. */
247 UNIV_INLINE
248 ulint
249 dtuple_fold(
250 /*========*/
251 /* out: the folded value */
252 dtuple_t* tuple, /* in: the tuple */
253 ulint n_fields,/* in: number of complete fields to fold */
254 ulint n_bytes,/* in: number of bytes to fold in an
255 incomplete last field */
256 dulint tree_id);/* in: index tree id */
257 /***********************************************************************
258 Sets types of fields binary in a tuple. */
259 UNIV_INLINE
260 void
261 dtuple_set_types_binary(
262 /*====================*/
263 dtuple_t* tuple, /* in: data tuple */
264 ulint n); /* in: number of fields to set */
265 /**************************************************************************
266 Checks if a dtuple contains an SQL null value. */
267 UNIV_INLINE
268 ibool
269 dtuple_contains_null(
270 /*=================*/
271 /* out: TRUE if some field is SQL null */
272 dtuple_t* tuple); /* in: dtuple */
273 /**************************************************************
274 Checks that a data field is typed. Asserts an error if not. */
276 ibool
277 dfield_check_typed(
278 /*===============*/
279 /* out: TRUE if ok */
280 dfield_t* field); /* in: data field */
281 /**************************************************************
282 Checks that a data tuple is typed. Asserts an error if not. */
284 ibool
285 dtuple_check_typed(
286 /*===============*/
287 /* out: TRUE if ok */
288 dtuple_t* tuple); /* in: tuple */
289 /**************************************************************
290 Checks that a data tuple is typed. */
292 ibool
293 dtuple_check_typed_no_assert(
294 /*=========================*/
295 /* out: TRUE if ok */
296 dtuple_t* tuple); /* in: tuple */
297 #ifdef UNIV_DEBUG
298 /**************************************************************
299 Validates the consistency of a tuple which must be complete, i.e,
300 all fields must have been set. */
302 ibool
303 dtuple_validate(
304 /*============*/
305 /* out: TRUE if ok */
306 dtuple_t* tuple); /* in: tuple */
307 #endif /* UNIV_DEBUG */
308 /*****************************************************************
309 Pretty prints a dfield value according to its data type. */
311 void
312 dfield_print(
313 /*=========*/
314 dfield_t* dfield);/* in: dfield */
315 /*****************************************************************
316 Pretty prints a dfield value according to its data type. Also the hex string
317 is printed if a string contains non-printable characters. */
319 void
320 dfield_print_also_hex(
321 /*==================*/
322 dfield_t* dfield); /* in: dfield */
323 /**************************************************************
324 The following function prints the contents of a tuple. */
326 void
327 dtuple_print(
328 /*=========*/
329 FILE* f, /* in: output stream */
330 dtuple_t* tuple); /* in: tuple */
331 /******************************************************************
332 Moves parts of long fields in entry to the big record vector so that
333 the size of tuple drops below the maximum record size allowed in the
334 database. Moves data only from those fields which are not necessary
335 to determine uniquely the insertion place of the tuple in the index. */
337 big_rec_t*
338 dtuple_convert_big_rec(
339 /*===================*/
340 /* out, own: created big record vector,
341 NULL if we are not able to shorten
342 the entry enough, i.e., if there are
343 too many short fields in entry */
344 dict_index_t* index, /* in: index */
345 dtuple_t* entry, /* in: index entry */
346 ulint* ext_vec,/* in: array of externally stored fields,
347 or NULL: if a field already is externally
348 stored, then we cannot move it to the vector
349 this function returns */
350 ulint n_ext_vec);/* in: number of elements is ext_vec */
351 /******************************************************************
352 Puts back to entry the data stored in vector. Note that to ensure the
353 fields in entry can accommodate the data, vector must have been created
354 from entry with dtuple_convert_big_rec. */
356 void
357 dtuple_convert_back_big_rec(
358 /*========================*/
359 dict_index_t* index, /* in: index */
360 dtuple_t* entry, /* in: entry whose data was put to vector */
361 big_rec_t* vector);/* in, own: big rec vector; it is
362 freed in this function */
363 /******************************************************************
364 Frees the memory in a big rec vector. */
366 void
367 dtuple_big_rec_free(
368 /*================*/
369 big_rec_t* vector); /* in, own: big rec vector; it is
370 freed in this function */
372 /*######################################################################*/
374 /* Structure for an SQL data field */
375 struct dfield_struct{
376 void* data; /* pointer to data */
377 ulint len; /* data length; UNIV_SQL_NULL if SQL null; */
378 dtype_t type; /* type of data */
381 struct dtuple_struct {
382 ulint info_bits; /* info bits of an index record:
383 the default is 0; this field is used
384 if an index record is built from
385 a data tuple */
386 ulint n_fields; /* number of fields in dtuple */
387 ulint n_fields_cmp; /* number of fields which should
388 be used in comparison services
389 of rem0cmp.*; the index search
390 is performed by comparing only these
391 fields, others are ignored; the
392 default value in dtuple creation is
393 the same value as n_fields */
394 dfield_t* fields; /* fields */
395 UT_LIST_NODE_T(dtuple_t) tuple_list;
396 /* data tuples can be linked into a
397 list using this field */
398 ulint magic_n;
400 #define DATA_TUPLE_MAGIC_N 65478679
402 /* A slot for a field in a big rec vector */
404 typedef struct big_rec_field_struct big_rec_field_t;
405 struct big_rec_field_struct {
406 ulint field_no; /* field number in record */
407 ulint len; /* stored data len */
408 byte* data; /* stored data */
411 /* Storage format for overflow data in a big record, that is, a record
412 which needs external storage of data fields */
414 struct big_rec_struct {
415 mem_heap_t* heap; /* memory heap from which allocated */
416 ulint n_fields; /* number of stored fields */
417 big_rec_field_t* fields; /* stored fields */
420 #ifndef UNIV_NONINL
421 #include "data0data.ic"
422 #endif
424 #endif