1
/************************************************************************
2
SQL data field and tuple
4
(c) 1994-1996 Innobase Oy
6
Created 5/30/1994 Heikki Tuuri
7
*************************************************************************/
13
extern byte data_error;
14
#endif /* UNIV_DEBUG */
16
/*************************************************************************
17
Gets pointer to the type struct of SQL data field. */
22
/* out: pointer to the type struct */
23
dfield_t* field) /* in: SQL data field */
27
return(&(field->type));
30
/*************************************************************************
31
Sets the type struct of SQL data field. */
36
dfield_t* field, /* in: SQL data field */
37
dtype_t* type) /* in: pointer to data type struct */
44
/*************************************************************************
45
Gets pointer to the data in a field. */
50
/* out: pointer to data */
51
dfield_t* field) /* in: field */
54
ut_ad((field->len == UNIV_SQL_NULL)
55
|| (field->data != &data_error));
60
/*************************************************************************
61
Gets length of field data. */
66
/* out: length of data; UNIV_SQL_NULL if
68
dfield_t* field) /* in: field */
71
ut_ad((field->len == UNIV_SQL_NULL)
72
|| (field->data != &data_error));
77
/*************************************************************************
78
Sets length in a field. */
83
dfield_t* field, /* in: field */
84
ulint len) /* in: length or UNIV_SQL_NULL */
91
/*************************************************************************
92
Sets pointer to the data and length in a field. */
97
dfield_t* field, /* in: field */
98
const void* data, /* in: data */
99
ulint len) /* in: length or UNIV_SQL_NULL */
103
field->data = (void*) data;
107
/*************************************************************************
108
Copies the data and len fields. */
113
dfield_t* field1, /* in: field to copy to */
114
dfield_t* field2) /* in: field to copy from */
116
ut_ad(field1 && field2);
118
field1->data = field2->data;
119
field1->len = field2->len;
122
/*************************************************************************
123
Copies a data field to another. */
128
dfield_t* field1, /* in: field to copy to */
129
dfield_t* field2) /* in: field to copy from */
134
/*************************************************************************
135
Tests if data length and content is equal for two dfields. */
138
dfield_datas_are_binary_equal(
139
/*==========================*/
140
/* out: TRUE if equal */
141
dfield_t* field1, /* in: field */
142
dfield_t* field2) /* in: field */
148
if ((len != field2->len)
149
|| ((len != UNIV_SQL_NULL)
150
&& (0 != ut_memcmp(field1->data, field2->data,
159
/*************************************************************************
160
Gets info bits in a data tuple. */
163
dtuple_get_info_bits(
164
/*=================*/
166
dtuple_t* tuple) /* in: tuple */
170
return(tuple->info_bits);
173
/*************************************************************************
174
Sets info bits in a data tuple. */
177
dtuple_set_info_bits(
178
/*=================*/
179
dtuple_t* tuple, /* in: tuple */
180
ulint info_bits) /* in: info bits */
184
tuple->info_bits = info_bits;
187
/*************************************************************************
188
Gets number of fields used in record comparisons. */
191
dtuple_get_n_fields_cmp(
192
/*====================*/
193
/* out: number of fields used in comparisons
195
dtuple_t* tuple) /* in: tuple */
199
return(tuple->n_fields_cmp);
202
/*************************************************************************
203
Sets number of fields used in record comparisons. */
206
dtuple_set_n_fields_cmp(
207
/*====================*/
208
dtuple_t* tuple, /* in: tuple */
209
ulint n_fields_cmp) /* in: number of fields used in
210
comparisons in rem0cmp.* */
213
ut_ad(n_fields_cmp <= tuple->n_fields);
215
tuple->n_fields_cmp = n_fields_cmp;
218
/*************************************************************************
219
Gets number of fields in a data tuple. */
224
/* out: number of fields */
225
dtuple_t* tuple) /* in: tuple */
229
return(tuple->n_fields);
232
/*************************************************************************
233
Gets nth field of a tuple. */
236
dtuple_get_nth_field(
237
/*=================*/
239
dtuple_t* tuple, /* in: tuple */
240
ulint n) /* in: index of field */
243
ut_ad(n < tuple->n_fields);
245
return(tuple->fields + n);
248
/**************************************************************
249
Creates a data tuple to a memory heap. The default value for number
250
of fields used in record comparisons for this tuple is n_fields. */
255
/* out, own: created tuple */
256
mem_heap_t* heap, /* in: memory heap where the tuple
258
ulint n_fields) /* in: number of fields */
264
tuple = (dtuple_t*) mem_heap_alloc(heap, sizeof(dtuple_t)
265
+ n_fields * sizeof(dfield_t));
266
tuple->info_bits = 0;
267
tuple->n_fields = n_fields;
268
tuple->n_fields_cmp = n_fields;
269
tuple->fields = (dfield_t*)(((byte*)tuple) + sizeof(dtuple_t));
272
tuple->magic_n = DATA_TUPLE_MAGIC_N;
274
{ /* In the debug version, initialize fields to an error value */
277
for (i = 0; i < n_fields; i++) {
278
(tuple->fields + i)->data = &data_error;
279
dfield_get_type(tuple->fields + i)->mtype = DATA_ERROR;
286
/**************************************************************
287
The following function returns the sum of data lengths of a tuple. The space
288
occupied by the field structs or the tuple struct is not counted. Neither
289
is possible space in externally stored parts of the field. */
292
dtuple_get_data_size(
293
/*=================*/
294
/* out: sum of data lengths */
295
dtuple_t* tuple) /* in: typed data tuple */
304
ut_ad(dtuple_check_typed(tuple));
305
ut_ad(tuple->magic_n == DATA_TUPLE_MAGIC_N);
307
n_fields = tuple->n_fields;
309
for (i = 0; i < n_fields; i++) {
310
field = dtuple_get_nth_field(tuple, i);
311
len = dfield_get_len(field);
313
if (len == UNIV_SQL_NULL) {
314
len = dtype_get_sql_null_size(dfield_get_type(field));
323
/***********************************************************************
324
Sets types of fields binary in a tuple. */
327
dtuple_set_types_binary(
328
/*====================*/
329
dtuple_t* tuple, /* in: data tuple */
330
ulint n) /* in: number of fields to set */
332
dtype_t* dfield_type;
335
for (i = 0; i < n; i++) {
336
dfield_type = dfield_get_type(dtuple_get_nth_field(tuple, i));
337
dtype_set(dfield_type, DATA_BINARY, 0, 0);
341
/****************************************************************
342
Folds a prefix given as the number of fields of a tuple. */
347
/* out: the folded value */
348
dtuple_t* tuple, /* in: the tuple */
349
ulint n_fields,/* in: number of complete fields to fold */
350
ulint n_bytes,/* in: number of bytes to fold in an
351
incomplete last field */
352
dulint tree_id)/* in: index tree id */
361
ut_ad(tuple->magic_n == DATA_TUPLE_MAGIC_N);
362
ut_ad(dtuple_check_typed(tuple));
364
fold = ut_fold_dulint(tree_id);
366
for (i = 0; i < n_fields; i++) {
367
field = dtuple_get_nth_field(tuple, i);
369
data = (byte*) dfield_get_data(field);
370
len = dfield_get_len(field);
372
if (len != UNIV_SQL_NULL) {
373
fold = ut_fold_ulint_pair(fold,
374
ut_fold_binary(data, len));
379
field = dtuple_get_nth_field(tuple, i);
381
data = (byte*) dfield_get_data(field);
382
len = dfield_get_len(field);
384
if (len != UNIV_SQL_NULL) {
389
fold = ut_fold_ulint_pair(fold,
390
ut_fold_binary(data, len));
397
/**************************************************************************
398
Writes an SQL null field full of zeros. */
403
byte* data, /* in: pointer to a buffer of size len */
404
ulint len) /* in: SQL null size in bytes */
408
for (j = 0; j < len; j++) {
413
/**************************************************************************
414
Checks if a dtuple contains an SQL null value. */
417
dtuple_contains_null(
418
/*=================*/
419
/* out: TRUE if some field is SQL null */
420
dtuple_t* tuple) /* in: dtuple */
425
n = dtuple_get_n_fields(tuple);
427
for (i = 0; i < n; i++) {
428
if (dfield_get_len(dtuple_get_nth_field(tuple, i))