1
/************************************************************************
2
SQL data field and tuple
4
(c) 1994-1996 Innobase Oy
6
Created 5/30/1994 Heikki Tuuri
7
*************************************************************************/
14
#include "data0types.h"
15
#include "data0type.h"
17
#include "dict0types.h"
19
typedef struct big_rec_struct big_rec_t;
21
/* Some non-inlined functions used in the MySQL interface: */
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 */
28
dfield_get_data_noninline(
29
dfield_t* field); /* in: field */
31
dfield_get_len_noninline(
32
dfield_t* field); /* in: field */
34
dtuple_get_n_fields_noninline(
35
dtuple_t* tuple); /* in: tuple */
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. */
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. */
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. */
63
/* out: pointer to data */
64
dfield_t* field); /* in: field */
65
/*************************************************************************
66
Gets length of field data. */
71
/* out: length of data; UNIV_SQL_NULL if
73
dfield_t* field); /* in: field */
74
/*************************************************************************
75
Sets length in a field. */
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. */
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. */
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. */
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. */
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. */
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. */
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. */
140
/* out: number of fields */
141
dtuple_t* tuple); /* in: tuple */
142
/*************************************************************************
143
Gets nth field of a tuple. */
146
dtuple_get_nth_field(
147
/*=================*/
149
dtuple_t* tuple, /* in: tuple */
150
ulint n); /* in: index of field */
151
/*************************************************************************
152
Gets info bits in a data tuple. */
155
dtuple_get_info_bits(
156
/*=================*/
158
dtuple_t* tuple); /* in: tuple */
159
/*************************************************************************
160
Sets info bits in a data tuple. */
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. */
171
dtuple_get_n_fields_cmp(
172
/*====================*/
173
/* out: number of fields used in comparisons
175
dtuple_t* tuple); /* in: tuple */
176
/*************************************************************************
177
Gets number of fields used in record comparisons. */
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. */
192
/* out, own: created tuple */
193
mem_heap_t* heap, /* in: memory heap where the tuple
195
ulint n_fields); /* in: number of fields */
197
/*************************************************************************
198
Creates a dtuple for use in MySQL. */
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. */
210
dtuple_free_for_mysql(
211
/*==================*/
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. */
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. */
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
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. */
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. */
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. */
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. */
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. */
287
/* out: TRUE if ok */
288
dtuple_t* tuple); /* in: tuple */
289
/**************************************************************
290
Checks that a data tuple is typed. */
293
dtuple_check_typed_no_assert(
294
/*=========================*/
295
/* out: TRUE if ok */
296
dtuple_t* tuple); /* in: tuple */
298
/**************************************************************
299
Validates the consistency of a tuple which must be complete, i.e,
300
all fields must have been set. */
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. */
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. */
320
dfield_print_also_hex(
321
/*==================*/
322
dfield_t* dfield); /* in: dfield */
323
/**************************************************************
324
The following function prints the contents of a tuple. */
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. */
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. */
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. */
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
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 */
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 */
421
#include "data0data.ic"