~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
typedef struct big_rec_struct           big_rec_t;
20
20
 
21
 
#ifdef UNIV_DEBUG
 
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 */
 
40
 
22
41
/*************************************************************************
23
42
Gets pointer to the type struct of SQL data field. */
24
43
UNIV_INLINE
26
45
dfield_get_type(
27
46
/*============*/
28
47
                                /* out: pointer to the type struct */
29
 
        const dfield_t* field); /* in: SQL data field */
30
 
/*************************************************************************
31
 
Gets pointer to the data in a field. */
32
 
UNIV_INLINE
33
 
void*
34
 
dfield_get_data(
35
 
/*============*/
36
 
                                /* out: pointer to data */
37
 
        const dfield_t* field); /* in: field */
38
 
#else /* UNIV_DEBUG */
39
 
# define dfield_get_type(field) (&(field)->type)
40
 
# define dfield_get_data(field) ((field)->data)
41
 
#endif /* UNIV_DEBUG */
 
48
        dfield_t*       field); /* in: SQL data field */
42
49
/*************************************************************************
43
50
Sets the type struct of SQL data field. */
44
51
UNIV_INLINE
48
55
        dfield_t*       field,  /* in: SQL data field */
49
56
        dtype_t*        type);  /* in: pointer to data type struct */
50
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
/*************************************************************************
51
66
Gets length of field data. */
52
67
UNIV_INLINE
53
68
ulint
55
70
/*===========*/
56
71
                                /* out: length of data; UNIV_SQL_NULL if
57
72
                                SQL null data */
58
 
        const dfield_t* field); /* in: field */
 
73
        dfield_t* field);       /* in: field */
59
74
/*************************************************************************
60
75
Sets length in a field. */
61
76
UNIV_INLINE
65
80
        dfield_t*       field,  /* in: field */
66
81
        ulint           len);   /* in: length or UNIV_SQL_NULL */
67
82
/*************************************************************************
68
 
Determines if a field is SQL NULL */
69
 
UNIV_INLINE
70
 
ulint
71
 
dfield_is_null(
72
 
/*===========*/
73
 
                                /* out: nonzero if SQL null data */
74
 
        const dfield_t* field); /* in: field */
75
 
/*************************************************************************
76
 
Determines if a field is externally stored */
77
 
UNIV_INLINE
78
 
ulint
79
 
dfield_is_ext(
80
 
/*==========*/
81
 
                                /* out: nonzero if externally stored */
82
 
        const dfield_t* field); /* in: field */
83
 
/*************************************************************************
84
 
Sets the "external storage" flag */
85
 
UNIV_INLINE
86
 
void
87
 
dfield_set_ext(
88
 
/*===========*/
89
 
        dfield_t*       field); /* in/out: field */
90
 
/*************************************************************************
91
83
Sets pointer to the data and length in a field. */
92
84
UNIV_INLINE
93
85
void
96
88
        dfield_t*       field,  /* in: field */
97
89
        const void*     data,   /* in: data */
98
90
        ulint           len);   /* in: length or UNIV_SQL_NULL */
99
 
/*************************************************************************
100
 
Sets a data field to SQL NULL. */
101
 
UNIV_INLINE
102
 
void
103
 
dfield_set_null(
104
 
/*============*/
105
 
        dfield_t*       field); /* in/out: field */
106
91
/**************************************************************************
107
92
Writes an SQL null field full of zeros. */
108
93
UNIV_INLINE
117
102
void
118
103
dfield_copy_data(
119
104
/*=============*/
120
 
        dfield_t*       field1, /* out: field to copy to */
121
 
        const dfield_t* field2);/* in: field to copy from */
 
105
        dfield_t*       field1, /* in: field to copy to */
 
106
        dfield_t*       field2);/* in: field to copy from */
122
107
/*************************************************************************
123
108
Copies a data field to another. */
124
109
UNIV_INLINE
125
110
void
126
111
dfield_copy(
127
112
/*========*/
128
 
        dfield_t*       field1, /* out: field to copy to */
129
 
        const dfield_t* field2);/* in: field to copy from */
130
 
/*************************************************************************
131
 
Copies the data pointed to by a data field. */
132
 
UNIV_INLINE
133
 
void
134
 
dfield_dup(
135
 
/*=======*/
136
 
        dfield_t*       field,  /* in/out: data field */
137
 
        mem_heap_t*     heap);  /* in: memory heap where allocated */
 
113
        dfield_t*       field1, /* in: field to copy to */
 
114
        dfield_t*       field2);/* in: field to copy from */
138
115
/*************************************************************************
139
116
Tests if data length and content is equal for two dfields. */
140
117
UNIV_INLINE
142
119
dfield_datas_are_binary_equal(
143
120
/*==========================*/
144
121
                                /* out: TRUE if equal */
145
 
        const dfield_t* field1, /* in: field */
146
 
        const dfield_t* field2);/* in: field */
 
122
        dfield_t*       field1, /* in: field */
 
123
        dfield_t*       field2);/* in: field */
147
124
/*************************************************************************
148
125
Tests if dfield data length and content is equal to the given. */
149
 
UNIV_INTERN
 
126
 
150
127
ibool
151
128
dfield_data_is_binary_equal(
152
129
/*========================*/
153
130
                                /* out: TRUE if equal */
154
 
        const dfield_t* field,  /* in: field */
 
131
        dfield_t*       field,  /* in: field */
155
132
        ulint           len,    /* in: data length or UNIV_SQL_NULL */
156
 
        const byte*     data);  /* in: data */
 
133
        byte*           data);  /* in: data */
157
134
/*************************************************************************
158
135
Gets number of fields in a data tuple. */
159
136
UNIV_INLINE
161
138
dtuple_get_n_fields(
162
139
/*================*/
163
140
                                /* out: number of fields */
164
 
        const dtuple_t* tuple); /* in: tuple */
165
 
#ifdef UNIV_DEBUG
 
141
        dtuple_t*       tuple); /* in: tuple */
166
142
/*************************************************************************
167
143
Gets nth field of a tuple. */
168
144
UNIV_INLINE
170
146
dtuple_get_nth_field(
171
147
/*=================*/
172
148
                                /* out: nth field */
173
 
        const dtuple_t* tuple,  /* in: tuple */
 
149
        dtuple_t*       tuple,  /* in: tuple */
174
150
        ulint           n);     /* in: index of field */
175
 
#else /* UNIV_DEBUG */
176
 
# define dtuple_get_nth_field(tuple, n) ((tuple)->fields + (n))
177
 
#endif /* UNIV_DEBUG */
178
151
/*************************************************************************
179
152
Gets info bits in a data tuple. */
180
153
UNIV_INLINE
182
155
dtuple_get_info_bits(
183
156
/*=================*/
184
157
                                /* out: info bits */
185
 
        const dtuple_t* tuple); /* in: tuple */
 
158
        dtuple_t*       tuple); /* in: tuple */
186
159
/*************************************************************************
187
160
Sets info bits in a data tuple. */
188
161
UNIV_INLINE
199
172
/*====================*/
200
173
                                /* out: number of fields used in comparisons
201
174
                                in rem0cmp.* */
202
 
        const dtuple_t* tuple); /* in: tuple */
 
175
        dtuple_t*       tuple); /* in: tuple */
203
176
/*************************************************************************
204
177
Gets number of fields used in record comparisons. */
205
178
UNIV_INLINE
221
194
                                is created */
222
195
        ulint           n_fields); /* in: number of fields */
223
196
 
224
 
/**************************************************************
225
 
Wrap data fields in a tuple. The default value for number
226
 
of fields used in record comparisons for this tuple is n_fields. */
227
 
UNIV_INLINE
228
 
const dtuple_t*
229
 
dtuple_from_fields(
230
 
/*===============*/
231
 
                                        /* out: data tuple */
232
 
        dtuple_t*       tuple,          /* in: storage for data tuple */
233
 
        const dfield_t* fields,         /* in: fields */
234
 
        ulint           n_fields);      /* in: number of fields */
235
 
 
 
197
/*************************************************************************
 
198
Creates a dtuple for use in MySQL. */
 
199
 
 
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. */
 
208
 
 
209
void
 
210
dtuple_free_for_mysql(
 
211
/*==================*/
 
212
        void* heap);
236
213
/*************************************************************************
237
214
Sets number of fields used in a tuple. Normally this is set in
238
215
dtuple_create, but if you want later to set it smaller, you can use this. */
239
 
UNIV_INTERN
 
216
 
240
217
void
241
218
dtuple_set_n_fields(
242
219
/*================*/
243
220
        dtuple_t*       tuple,          /* in: tuple */
244
221
        ulint           n_fields);      /* in: number of fields */
245
 
/*************************************************************************
246
 
Copies a data tuple to another.  This is a shallow copy; if a deep copy
247
 
is desired, dfield_dup() will have to be invoked on each field. */
248
 
UNIV_INLINE
249
 
dtuple_t*
250
 
dtuple_copy(
251
 
/*========*/
252
 
                                /* out, own: copy of tuple */
253
 
        const dtuple_t* tuple,  /* in: tuple to copy from */
254
 
        mem_heap_t*     heap);  /* in: memory heap
255
 
                                where the tuple is created */
256
222
/**************************************************************
257
223
The following function returns the sum of data lengths of a tuple. The space
258
224
occupied by the field structs or the tuple struct is not counted. */
261
227
dtuple_get_data_size(
262
228
/*=================*/
263
229
                                /* out: sum of data lens */
264
 
        const dtuple_t* tuple); /* in: typed data tuple */
265
 
/*************************************************************************
266
 
Computes the number of externally stored fields in a data tuple. */
267
 
UNIV_INLINE
268
 
ulint
269
 
dtuple_get_n_ext(
270
 
/*=============*/
271
 
                                /* out: number of fields */
272
 
        const dtuple_t* tuple); /* in: tuple */
 
230
        dtuple_t*       tuple); /* in: typed data tuple */
273
231
/****************************************************************
274
 
Compare two data tuples, respecting the collation of character fields. */
275
 
UNIV_INTERN
276
 
int
277
 
dtuple_coll_cmp(
278
 
/*============*/
279
 
                                /* out: 1, 0 , -1 if tuple1 is greater, equal,
280
 
                                less, respectively, than tuple2 */
281
 
        const dtuple_t* tuple1, /* in: tuple 1 */
282
 
        const dtuple_t* tuple2);/* in: tuple 2 */
 
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). */
 
235
 
 
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 */
283
245
/****************************************************************
284
246
Folds a prefix given as the number of fields of a tuple. */
285
247
UNIV_INLINE
287
249
dtuple_fold(
288
250
/*========*/
289
251
                                /* out: the folded value */
290
 
        const dtuple_t* tuple,  /* in: the tuple */
 
252
        dtuple_t*       tuple,  /* in: the tuple */
291
253
        ulint           n_fields,/* in: number of complete fields to fold */
292
254
        ulint           n_bytes,/* in: number of bytes to fold in an
293
255
                                incomplete last field */
294
 
        dulint          tree_id)/* in: index tree id */
295
 
        __attribute__((pure));
 
256
        dulint          tree_id);/* in: index tree id */
296
257
/***********************************************************************
297
258
Sets types of fields binary in a tuple. */
298
259
UNIV_INLINE
308
269
dtuple_contains_null(
309
270
/*=================*/
310
271
                                /* out: TRUE if some field is SQL null */
311
 
        const dtuple_t* tuple); /* in: dtuple */
 
272
        dtuple_t*       tuple); /* in: dtuple */
312
273
/**************************************************************
313
274
Checks that a data field is typed. Asserts an error if not. */
314
 
UNIV_INTERN
 
275
 
315
276
ibool
316
277
dfield_check_typed(
317
278
/*===============*/
318
279
                                /* out: TRUE if ok */
319
 
        const dfield_t* field); /* in: data field */
 
280
        dfield_t*       field); /* in: data field */
320
281
/**************************************************************
321
282
Checks that a data tuple is typed. Asserts an error if not. */
322
 
UNIV_INTERN
 
283
 
323
284
ibool
324
285
dtuple_check_typed(
325
286
/*===============*/
326
287
                                /* out: TRUE if ok */
327
 
        const dtuple_t* tuple); /* in: tuple */
 
288
        dtuple_t*       tuple); /* in: tuple */
328
289
/**************************************************************
329
290
Checks that a data tuple is typed. */
330
 
UNIV_INTERN
 
291
 
331
292
ibool
332
293
dtuple_check_typed_no_assert(
333
294
/*=========================*/
334
295
                                /* out: TRUE if ok */
335
 
        const dtuple_t* tuple); /* in: tuple */
 
296
        dtuple_t*       tuple); /* in: tuple */
336
297
#ifdef UNIV_DEBUG
337
298
/**************************************************************
338
299
Validates the consistency of a tuple which must be complete, i.e,
339
300
all fields must have been set. */
340
 
UNIV_INTERN
 
301
 
341
302
ibool
342
303
dtuple_validate(
343
304
/*============*/
344
305
                                /* out: TRUE if ok */
345
 
        const dtuple_t* tuple); /* in: tuple */
 
306
        dtuple_t*       tuple); /* in: tuple */
346
307
#endif /* UNIV_DEBUG */
347
308
/*****************************************************************
348
309
Pretty prints a dfield value according to its data type. */
349
 
UNIV_INTERN
 
310
 
350
311
void
351
312
dfield_print(
352
313
/*=========*/
353
 
        const dfield_t* dfield);/* in: dfield */
 
314
        dfield_t*       dfield);/* in: dfield */
354
315
/*****************************************************************
355
316
Pretty prints a dfield value according to its data type. Also the hex string
356
317
is printed if a string contains non-printable characters. */
357
 
UNIV_INTERN
 
318
 
358
319
void
359
320
dfield_print_also_hex(
360
321
/*==================*/
361
 
        const dfield_t* dfield);         /* in: dfield */
 
322
        dfield_t*       dfield);         /* in: dfield */
362
323
/**************************************************************
363
324
The following function prints the contents of a tuple. */
364
 
UNIV_INTERN
 
325
 
365
326
void
366
327
dtuple_print(
367
328
/*=========*/
368
329
        FILE*           f,      /* in: output stream */
369
 
        const dtuple_t* tuple); /* in: tuple */
 
330
        dtuple_t*       tuple); /* in: tuple */
370
331
/******************************************************************
371
332
Moves parts of long fields in entry to the big record vector so that
372
333
the size of tuple drops below the maximum record size allowed in the
373
334
database. Moves data only from those fields which are not necessary
374
335
to determine uniquely the insertion place of the tuple in the index. */
375
 
UNIV_INTERN
 
336
 
376
337
big_rec_t*
377
338
dtuple_convert_big_rec(
378
339
/*===================*/
379
340
                                /* out, own: created big record vector,
380
341
                                NULL if we are not able to shorten
381
342
                                the entry enough, i.e., if there are
382
 
                                too many fixed-length or short fields
383
 
                                in entry or the index is clustered */
 
343
                                too many short fields in entry */
384
344
        dict_index_t*   index,  /* in: index */
385
 
        dtuple_t*       entry,  /* in/out: index entry */
386
 
        ulint*          n_ext); /* in/out: number of
387
 
                                externally stored columns */
 
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 */
388
351
/******************************************************************
389
352
Puts back to entry the data stored in vector. Note that to ensure the
390
353
fields in entry can accommodate the data, vector must have been created
391
354
from entry with dtuple_convert_big_rec. */
392
 
UNIV_INTERN
 
355
 
393
356
void
394
357
dtuple_convert_back_big_rec(
395
358
/*========================*/
399
362
                                freed in this function */
400
363
/******************************************************************
401
364
Frees the memory in a big rec vector. */
402
 
UNIV_INLINE
 
365
 
403
366
void
404
367
dtuple_big_rec_free(
405
368
/*================*/
411
374
/* Structure for an SQL data field */
412
375
struct dfield_struct{
413
376
        void*           data;   /* pointer to data */
414
 
        unsigned        ext:1;  /* TRUE=externally stored, FALSE=local */
415
 
        unsigned        len:32; /* data length; UNIV_SQL_NULL if SQL null */
 
377
        ulint           len;    /* data length; UNIV_SQL_NULL if SQL null; */
416
378
        dtype_t         type;   /* type of data */
417
379
};
418
380
 
433
395
        UT_LIST_NODE_T(dtuple_t) tuple_list;
434
396
                                        /* data tuples can be linked into a
435
397
                                        list using this field */
436
 
#ifdef UNIV_DEBUG
437
398
        ulint           magic_n;
438
 
# define                DATA_TUPLE_MAGIC_N      65478679
439
 
#endif /* UNIV_DEBUG */
440
399
};
 
400
#define DATA_TUPLE_MAGIC_N      65478679
441
401
 
442
402
/* A slot for a field in a big rec vector */
443
403
 
445
405
struct big_rec_field_struct {
446
406
        ulint           field_no;       /* field number in record */
447
407
        ulint           len;            /* stored data len */
448
 
        const void*     data;           /* stored data */
 
408
        byte*           data;           /* stored data */
449
409
};
450
410
 
451
411
/* Storage format for overflow data in a big record, that is, a record