~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/data0data.h

  • Committer: Monty Taylor
  • Date: 2010-09-16 23:12:30 UTC
  • mto: (1775.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1773.
  • Revision ID: mordred@inaugust.com-20100916231230-uchkqks21rwzbmpz
Include files in tarball that were being left out.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1994, 2009, Innobase Oy. All Rights Reserved.
4
 
 
5
 
This program is free software; you can redistribute it and/or modify it under
6
 
the terms of the GNU General Public License as published by the Free Software
7
 
Foundation; version 2 of the License.
8
 
 
9
 
This program is distributed in the hope that it will be useful, but WITHOUT
10
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
 
 
13
 
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/********************************************************************//**
20
 
@file include/data0data.h
21
 
SQL data field and tuple
22
 
 
23
 
Created 5/30/1994 Heikki Tuuri
24
 
*************************************************************************/
25
 
 
26
 
#ifndef data0data_h
27
 
#define data0data_h
28
 
 
29
 
#include "univ.i"
30
 
 
31
 
#include "data0types.h"
32
 
#include "data0type.h"
33
 
#include "mem0mem.h"
34
 
#include "dict0types.h"
35
 
 
36
 
/** Storage for overflow data in a big record, that is, a clustered
37
 
index record which needs external storage of data fields */
38
 
typedef struct big_rec_struct           big_rec_t;
39
 
 
40
 
#ifdef UNIV_DEBUG
41
 
/*********************************************************************//**
42
 
Gets pointer to the type struct of SQL data field.
43
 
@return pointer to the type struct */
44
 
UNIV_INLINE
45
 
dtype_t*
46
 
dfield_get_type(
47
 
/*============*/
48
 
        const dfield_t* field); /*!< in: SQL data field */
49
 
/*********************************************************************//**
50
 
Gets pointer to the data in a field.
51
 
@return pointer to data */
52
 
UNIV_INLINE
53
 
void*
54
 
dfield_get_data(
55
 
/*============*/
56
 
        const dfield_t* field); /*!< in: field */
57
 
#else /* UNIV_DEBUG */
58
 
# define dfield_get_type(field) (&(field)->type)
59
 
# define dfield_get_data(field) ((field)->data)
60
 
#endif /* UNIV_DEBUG */
61
 
/*********************************************************************//**
62
 
Sets the type struct of SQL data field. */
63
 
UNIV_INLINE
64
 
void
65
 
dfield_set_type(
66
 
/*============*/
67
 
        dfield_t*       field,  /*!< in: SQL data field */
68
 
        dtype_t*        type);  /*!< in: pointer to data type struct */
69
 
/*********************************************************************//**
70
 
Gets length of field data.
71
 
@return length of data; UNIV_SQL_NULL if SQL null data */
72
 
UNIV_INLINE
73
 
ulint
74
 
dfield_get_len(
75
 
/*===========*/
76
 
        const dfield_t* field); /*!< in: field */
77
 
/*********************************************************************//**
78
 
Sets length in a field. */
79
 
UNIV_INLINE
80
 
void
81
 
dfield_set_len(
82
 
/*===========*/
83
 
        dfield_t*       field,  /*!< in: field */
84
 
        ulint           len);   /*!< in: length or UNIV_SQL_NULL */
85
 
/*********************************************************************//**
86
 
Determines if a field is SQL NULL
87
 
@return nonzero if SQL null data */
88
 
UNIV_INLINE
89
 
ulint
90
 
dfield_is_null(
91
 
/*===========*/
92
 
        const dfield_t* field); /*!< in: field */
93
 
/*********************************************************************//**
94
 
Determines if a field is externally stored
95
 
@return nonzero if externally stored */
96
 
UNIV_INLINE
97
 
ulint
98
 
dfield_is_ext(
99
 
/*==========*/
100
 
        const dfield_t* field); /*!< in: field */
101
 
/*********************************************************************//**
102
 
Sets the "external storage" flag */
103
 
UNIV_INLINE
104
 
void
105
 
dfield_set_ext(
106
 
/*===========*/
107
 
        dfield_t*       field); /*!< in/out: field */
108
 
/*********************************************************************//**
109
 
Sets pointer to the data and length in a field. */
110
 
UNIV_INLINE
111
 
void
112
 
dfield_set_data(
113
 
/*============*/
114
 
        dfield_t*       field,  /*!< in: field */
115
 
        const void*     data,   /*!< in: data */
116
 
        ulint           len);   /*!< in: length or UNIV_SQL_NULL */
117
 
/*********************************************************************//**
118
 
Sets a data field to SQL NULL. */
119
 
UNIV_INLINE
120
 
void
121
 
dfield_set_null(
122
 
/*============*/
123
 
        dfield_t*       field); /*!< in/out: field */
124
 
/**********************************************************************//**
125
 
Writes an SQL null field full of zeros. */
126
 
UNIV_INLINE
127
 
void
128
 
data_write_sql_null(
129
 
/*================*/
130
 
        byte*   data,   /*!< in: pointer to a buffer of size len */
131
 
        ulint   len);   /*!< in: SQL null size in bytes */
132
 
/*********************************************************************//**
133
 
Copies the data and len fields. */
134
 
UNIV_INLINE
135
 
void
136
 
dfield_copy_data(
137
 
/*=============*/
138
 
        dfield_t*       field1, /*!< out: field to copy to */
139
 
        const dfield_t* field2);/*!< in: field to copy from */
140
 
/*********************************************************************//**
141
 
Copies a data field to another. */
142
 
UNIV_INLINE
143
 
void
144
 
dfield_copy(
145
 
/*========*/
146
 
        dfield_t*       field1, /*!< out: field to copy to */
147
 
        const dfield_t* field2);/*!< in: field to copy from */
148
 
/*********************************************************************//**
149
 
Copies the data pointed to by a data field. */
150
 
UNIV_INLINE
151
 
void
152
 
dfield_dup(
153
 
/*=======*/
154
 
        dfield_t*       field,  /*!< in/out: data field */
155
 
        mem_heap_t*     heap);  /*!< in: memory heap where allocated */
156
 
/*********************************************************************//**
157
 
Tests if data length and content is equal for two dfields.
158
 
@return TRUE if equal */
159
 
UNIV_INLINE
160
 
ibool
161
 
dfield_datas_are_binary_equal(
162
 
/*==========================*/
163
 
        const dfield_t* field1, /*!< in: field */
164
 
        const dfield_t* field2);/*!< in: field */
165
 
/*********************************************************************//**
166
 
Tests if dfield data length and content is equal to the given.
167
 
@return TRUE if equal */
168
 
UNIV_INTERN
169
 
ibool
170
 
dfield_data_is_binary_equal(
171
 
/*========================*/
172
 
        const dfield_t* field,  /*!< in: field */
173
 
        ulint           len,    /*!< in: data length or UNIV_SQL_NULL */
174
 
        const byte*     data);  /*!< in: data */
175
 
/*********************************************************************//**
176
 
Gets number of fields in a data tuple.
177
 
@return number of fields */
178
 
UNIV_INLINE
179
 
ulint
180
 
dtuple_get_n_fields(
181
 
/*================*/
182
 
        const dtuple_t* tuple); /*!< in: tuple */
183
 
#ifdef UNIV_DEBUG
184
 
/*********************************************************************//**
185
 
Gets nth field of a tuple.
186
 
@return nth field */
187
 
UNIV_INLINE
188
 
dfield_t*
189
 
dtuple_get_nth_field(
190
 
/*=================*/
191
 
        const dtuple_t* tuple,  /*!< in: tuple */
192
 
        ulint           n);     /*!< in: index of field */
193
 
#else /* UNIV_DEBUG */
194
 
# define dtuple_get_nth_field(tuple, n) ((tuple)->fields + (n))
195
 
#endif /* UNIV_DEBUG */
196
 
/*********************************************************************//**
197
 
Gets info bits in a data tuple.
198
 
@return info bits */
199
 
UNIV_INLINE
200
 
ulint
201
 
dtuple_get_info_bits(
202
 
/*=================*/
203
 
        const dtuple_t* tuple); /*!< in: tuple */
204
 
/*********************************************************************//**
205
 
Sets info bits in a data tuple. */
206
 
UNIV_INLINE
207
 
void
208
 
dtuple_set_info_bits(
209
 
/*=================*/
210
 
        dtuple_t*       tuple,          /*!< in: tuple */
211
 
        ulint           info_bits);     /*!< in: info bits */
212
 
/*********************************************************************//**
213
 
Gets number of fields used in record comparisons.
214
 
@return number of fields used in comparisons in rem0cmp.* */
215
 
UNIV_INLINE
216
 
ulint
217
 
dtuple_get_n_fields_cmp(
218
 
/*====================*/
219
 
        const dtuple_t* tuple); /*!< in: tuple */
220
 
/*********************************************************************//**
221
 
Gets number of fields used in record comparisons. */
222
 
UNIV_INLINE
223
 
void
224
 
dtuple_set_n_fields_cmp(
225
 
/*====================*/
226
 
        dtuple_t*       tuple,          /*!< in: tuple */
227
 
        ulint           n_fields_cmp);  /*!< in: number of fields used in
228
 
                                        comparisons in rem0cmp.* */
229
 
/**********************************************************//**
230
 
Creates a data tuple to a memory heap. The default value for number
231
 
of fields used in record comparisons for this tuple is n_fields.
232
 
@return own: created tuple */
233
 
UNIV_INLINE
234
 
dtuple_t*
235
 
dtuple_create(
236
 
/*==========*/
237
 
        mem_heap_t*     heap,   /*!< in: memory heap where the tuple
238
 
                                is created */
239
 
        ulint           n_fields); /*!< in: number of fields */
240
 
 
241
 
/**********************************************************//**
242
 
Wrap data fields in a tuple. The default value for number
243
 
of fields used in record comparisons for this tuple is n_fields.
244
 
@return data tuple */
245
 
UNIV_INLINE
246
 
const dtuple_t*
247
 
dtuple_from_fields(
248
 
/*===============*/
249
 
        dtuple_t*       tuple,          /*!< in: storage for data tuple */
250
 
        const dfield_t* fields,         /*!< in: fields */
251
 
        ulint           n_fields);      /*!< in: number of fields */
252
 
 
253
 
/*********************************************************************//**
254
 
Sets number of fields used in a tuple. Normally this is set in
255
 
dtuple_create, but if you want later to set it smaller, you can use this. */
256
 
UNIV_INTERN
257
 
void
258
 
dtuple_set_n_fields(
259
 
/*================*/
260
 
        dtuple_t*       tuple,          /*!< in: tuple */
261
 
        ulint           n_fields);      /*!< in: number of fields */
262
 
/*********************************************************************//**
263
 
Copies a data tuple to another.  This is a shallow copy; if a deep copy
264
 
is desired, dfield_dup() will have to be invoked on each field.
265
 
@return own: copy of tuple */
266
 
UNIV_INLINE
267
 
dtuple_t*
268
 
dtuple_copy(
269
 
/*========*/
270
 
        const dtuple_t* tuple,  /*!< in: tuple to copy from */
271
 
        mem_heap_t*     heap);  /*!< in: memory heap
272
 
                                where the tuple is created */
273
 
/**********************************************************//**
274
 
The following function returns the sum of data lengths of a tuple. The space
275
 
occupied by the field structs or the tuple struct is not counted.
276
 
@return sum of data lens */
277
 
UNIV_INLINE
278
 
ulint
279
 
dtuple_get_data_size(
280
 
/*=================*/
281
 
        const dtuple_t* tuple,  /*!< in: typed data tuple */
282
 
        ulint           comp);  /*!< in: nonzero=ROW_FORMAT=COMPACT  */
283
 
/*********************************************************************//**
284
 
Computes the number of externally stored fields in a data tuple.
285
 
@return number of fields */
286
 
UNIV_INLINE
287
 
ulint
288
 
dtuple_get_n_ext(
289
 
/*=============*/
290
 
        const dtuple_t* tuple); /*!< in: tuple */
291
 
/************************************************************//**
292
 
Compare two data tuples, respecting the collation of character fields.
293
 
@return 1, 0 , -1 if tuple1 is greater, equal, less, respectively,
294
 
than tuple2 */
295
 
UNIV_INTERN
296
 
int
297
 
dtuple_coll_cmp(
298
 
/*============*/
299
 
        const dtuple_t* tuple1, /*!< in: tuple 1 */
300
 
        const dtuple_t* tuple2);/*!< in: tuple 2 */
301
 
/************************************************************//**
302
 
Folds a prefix given as the number of fields of a tuple.
303
 
@return the folded value */
304
 
UNIV_INLINE
305
 
ulint
306
 
dtuple_fold(
307
 
/*========*/
308
 
        const dtuple_t* tuple,  /*!< in: the tuple */
309
 
        ulint           n_fields,/*!< in: number of complete fields to fold */
310
 
        ulint           n_bytes,/*!< in: number of bytes to fold in an
311
 
                                incomplete last field */
312
 
        index_id_t      tree_id)/*!< in: index tree id */
313
 
        __attribute__((pure));
314
 
/*******************************************************************//**
315
 
Sets types of fields binary in a tuple. */
316
 
UNIV_INLINE
317
 
void
318
 
dtuple_set_types_binary(
319
 
/*====================*/
320
 
        dtuple_t*       tuple,  /*!< in: data tuple */
321
 
        ulint           n);     /*!< in: number of fields to set */
322
 
/**********************************************************************//**
323
 
Checks if a dtuple contains an SQL null value.
324
 
@return TRUE if some field is SQL null */
325
 
UNIV_INLINE
326
 
ibool
327
 
dtuple_contains_null(
328
 
/*=================*/
329
 
        const dtuple_t* tuple); /*!< in: dtuple */
330
 
/**********************************************************//**
331
 
Checks that a data field is typed. Asserts an error if not.
332
 
@return TRUE if ok */
333
 
UNIV_INTERN
334
 
ibool
335
 
dfield_check_typed(
336
 
/*===============*/
337
 
        const dfield_t* field); /*!< in: data field */
338
 
/**********************************************************//**
339
 
Checks that a data tuple is typed. Asserts an error if not.
340
 
@return TRUE if ok */
341
 
UNIV_INTERN
342
 
ibool
343
 
dtuple_check_typed(
344
 
/*===============*/
345
 
        const dtuple_t* tuple); /*!< in: tuple */
346
 
/**********************************************************//**
347
 
Checks that a data tuple is typed.
348
 
@return TRUE if ok */
349
 
UNIV_INTERN
350
 
ibool
351
 
dtuple_check_typed_no_assert(
352
 
/*=========================*/
353
 
        const dtuple_t* tuple); /*!< in: tuple */
354
 
#ifdef UNIV_DEBUG
355
 
/**********************************************************//**
356
 
Validates the consistency of a tuple which must be complete, i.e,
357
 
all fields must have been set.
358
 
@return TRUE if ok */
359
 
UNIV_INTERN
360
 
ibool
361
 
dtuple_validate(
362
 
/*============*/
363
 
        const dtuple_t* tuple); /*!< in: tuple */
364
 
#endif /* UNIV_DEBUG */
365
 
/*************************************************************//**
366
 
Pretty prints a dfield value according to its data type. */
367
 
UNIV_INTERN
368
 
void
369
 
dfield_print(
370
 
/*=========*/
371
 
        const dfield_t* dfield);/*!< in: dfield */
372
 
/*************************************************************//**
373
 
Pretty prints a dfield value according to its data type. Also the hex string
374
 
is printed if a string contains non-printable characters. */
375
 
UNIV_INTERN
376
 
void
377
 
dfield_print_also_hex(
378
 
/*==================*/
379
 
        const dfield_t* dfield);         /*!< in: dfield */
380
 
/**********************************************************//**
381
 
The following function prints the contents of a tuple. */
382
 
UNIV_INTERN
383
 
void
384
 
dtuple_print(
385
 
/*=========*/
386
 
        FILE*           f,      /*!< in: output stream */
387
 
        const dtuple_t* tuple); /*!< in: tuple */
388
 
/**************************************************************//**
389
 
Moves parts of long fields in entry to the big record vector so that
390
 
the size of tuple drops below the maximum record size allowed in the
391
 
database. Moves data only from those fields which are not necessary
392
 
to determine uniquely the insertion place of the tuple in the index.
393
 
@return own: created big record vector, NULL if we are not able to
394
 
shorten the entry enough, i.e., if there are too many fixed-length or
395
 
short fields in entry or the index is clustered */
396
 
UNIV_INTERN
397
 
big_rec_t*
398
 
dtuple_convert_big_rec(
399
 
/*===================*/
400
 
        dict_index_t*   index,  /*!< in: index */
401
 
        dtuple_t*       entry,  /*!< in/out: index entry */
402
 
        ulint*          n_ext); /*!< in/out: number of
403
 
                                externally stored columns */
404
 
/**************************************************************//**
405
 
Puts back to entry the data stored in vector. Note that to ensure the
406
 
fields in entry can accommodate the data, vector must have been created
407
 
from entry with dtuple_convert_big_rec. */
408
 
UNIV_INTERN
409
 
void
410
 
dtuple_convert_back_big_rec(
411
 
/*========================*/
412
 
        dict_index_t*   index,  /*!< in: index */
413
 
        dtuple_t*       entry,  /*!< in: entry whose data was put to vector */
414
 
        big_rec_t*      vector);/*!< in, own: big rec vector; it is
415
 
                                freed in this function */
416
 
/**************************************************************//**
417
 
Frees the memory in a big rec vector. */
418
 
UNIV_INLINE
419
 
void
420
 
dtuple_big_rec_free(
421
 
/*================*/
422
 
        big_rec_t*      vector);        /*!< in, own: big rec vector; it is
423
 
                                freed in this function */
424
 
 
425
 
/*######################################################################*/
426
 
 
427
 
/** Structure for an SQL data field */
428
 
struct dfield_struct{
429
 
        void*           data;   /*!< pointer to data */
430
 
        unsigned        ext:1;  /*!< TRUE=externally stored, FALSE=local */
431
 
        unsigned        len:32; /*!< data length; UNIV_SQL_NULL if SQL null */
432
 
        dtype_t         type;   /*!< type of data */
433
 
};
434
 
 
435
 
/** Structure for an SQL data tuple of fields (logical record) */
436
 
struct dtuple_struct {
437
 
        ulint           info_bits;      /*!< info bits of an index record:
438
 
                                        the default is 0; this field is used
439
 
                                        if an index record is built from
440
 
                                        a data tuple */
441
 
        ulint           n_fields;       /*!< number of fields in dtuple */
442
 
        ulint           n_fields_cmp;   /*!< number of fields which should
443
 
                                        be used in comparison services
444
 
                                        of rem0cmp.*; the index search
445
 
                                        is performed by comparing only these
446
 
                                        fields, others are ignored; the
447
 
                                        default value in dtuple creation is
448
 
                                        the same value as n_fields */
449
 
        dfield_t*       fields;         /*!< fields */
450
 
        UT_LIST_NODE_T(dtuple_t) tuple_list;
451
 
                                        /*!< data tuples can be linked into a
452
 
                                        list using this field */
453
 
#ifdef UNIV_DEBUG
454
 
        ulint           magic_n;        /*!< magic number, used in
455
 
                                        debug assertions */
456
 
/** Value of dtuple_struct::magic_n */
457
 
# define                DATA_TUPLE_MAGIC_N      65478679
458
 
#endif /* UNIV_DEBUG */
459
 
};
460
 
 
461
 
/** A slot for a field in a big rec vector */
462
 
typedef struct big_rec_field_struct     big_rec_field_t;
463
 
/** A slot for a field in a big rec vector */
464
 
struct big_rec_field_struct {
465
 
        ulint           field_no;       /*!< field number in record */
466
 
        ulint           len;            /*!< stored data length, in bytes */
467
 
        const void*     data;           /*!< stored data */
468
 
};
469
 
 
470
 
/** Storage format for overflow data in a big record, that is, a
471
 
clustered index record which needs external storage of data fields */
472
 
struct big_rec_struct {
473
 
        mem_heap_t*     heap;           /*!< memory heap from which
474
 
                                        allocated */
475
 
        ulint           n_fields;       /*!< number of stored fields */
476
 
        big_rec_field_t*fields;         /*!< stored fields */
477
 
};
478
 
 
479
 
#ifndef UNIV_NONINL
480
 
#include "data0data.ic"
481
 
#endif
482
 
 
483
 
#endif