17
17
*****************************************************************************/
19
/************************************************************************
19
/********************************************************************//**
20
@file data/data0data.c
20
21
SQL data field and tuple
22
23
Created 5/30/1994 Heikki Tuuri
36
38
#include "btr0cur.h"
41
#endif /* !UNIV_HOTBACKUP */
41
/* data pointers of tuple fields are initialized to point here
44
/** Dummy variable to catch access to uninitialized fields. In the
45
debug version, dtuple_create() will make all fields of dtuple_t point
43
47
UNIV_INTERN byte data_error;
45
49
# ifndef UNIV_DEBUG_VALGRIND
46
/* this is used to fool the compiler in dtuple_validate */
50
/** this is used to fool the compiler in dtuple_validate */
47
51
UNIV_INTERN ulint data_dummy;
48
52
# endif /* !UNIV_DEBUG_VALGRIND */
49
53
#endif /* UNIV_DEBUG */
51
/*************************************************************************
52
Tests if dfield data length and content is equal to the given. */
55
#ifndef UNIV_HOTBACKUP
56
/*********************************************************************//**
57
Tests if dfield data length and content is equal to the given.
58
@return TRUE if equal */
55
61
dfield_data_is_binary_equal(
56
62
/*========================*/
57
/* out: TRUE if equal */
58
const dfield_t* field, /* in: field */
59
ulint len, /* in: data length or UNIV_SQL_NULL */
60
const byte* data) /* in: data */
63
const dfield_t* field, /*!< in: field */
64
ulint len, /*!< in: data length or UNIV_SQL_NULL */
65
const byte* data) /*!< in: data */
62
67
if (len != dfield_get_len(field)) {
80
/****************************************************************
81
Compare two data tuples, respecting the collation of character fields. */
85
/************************************************************//**
86
Compare two data tuples, respecting the collation of character fields.
87
@return 1, 0 , -1 if tuple1 is greater, equal, less, respectively,
86
/* out: 1, 0 , -1 if tuple1 is greater, equal,
87
less, respectively, than tuple2 */
88
const dtuple_t* tuple1, /* in: tuple 1 */
89
const dtuple_t* tuple2) /* in: tuple 2 */
93
const dtuple_t* tuple1, /*!< in: tuple 1 */
94
const dtuple_t* tuple2) /*!< in: tuple 2 */
122
/*************************************************************************
127
/*********************************************************************//**
123
128
Sets number of fields used in a tuple. Normally this is set in
124
129
dtuple_create, but if you want later to set it smaller, you can use this. */
127
132
dtuple_set_n_fields(
128
133
/*================*/
129
dtuple_t* tuple, /* in: tuple */
130
ulint n_fields) /* in: number of fields */
134
dtuple_t* tuple, /*!< in: tuple */
135
ulint n_fields) /*!< in: number of fields */
135
140
tuple->n_fields_cmp = n_fields;
138
/**************************************************************
139
Checks that a data field is typed. */
143
/**********************************************************//**
144
Checks that a data field is typed.
145
@return TRUE if ok */
142
148
dfield_check_typed_no_assert(
143
149
/*=========================*/
144
/* out: TRUE if ok */
145
const dfield_t* field) /* in: data field */
150
const dfield_t* field) /*!< in: data field */
147
152
if (dfield_get_type(field)->mtype > DATA_MYSQL
148
153
|| dfield_get_type(field)->mtype < DATA_VARCHAR) {
160
/**************************************************************
161
Checks that a data tuple is typed. */
165
/**********************************************************//**
166
Checks that a data tuple is typed.
167
@return TRUE if ok */
164
170
dtuple_check_typed_no_assert(
165
171
/*=========================*/
166
/* out: TRUE if ok */
167
const dtuple_t* tuple) /* in: tuple */
172
const dtuple_t* tuple) /*!< in: tuple */
169
174
const dfield_t* field;
200
#endif /* !UNIV_HOTBACKUP */
196
/**************************************************************
197
Checks that a data field is typed. Asserts an error if not. */
203
/**********************************************************//**
204
Checks that a data field is typed. Asserts an error if not.
205
@return TRUE if ok */
200
208
dfield_check_typed(
201
209
/*===============*/
202
/* out: TRUE if ok */
203
const dfield_t* field) /* in: data field */
210
const dfield_t* field) /*!< in: data field */
205
212
if (dfield_get_type(field)->mtype > DATA_MYSQL
206
213
|| dfield_get_type(field)->mtype < DATA_VARCHAR) {
219
/**************************************************************
220
Checks that a data tuple is typed. Asserts an error if not. */
226
/**********************************************************//**
227
Checks that a data tuple is typed. Asserts an error if not.
228
@return TRUE if ok */
223
231
dtuple_check_typed(
224
232
/*===============*/
225
/* out: TRUE if ok */
226
const dtuple_t* tuple) /* in: tuple */
233
const dtuple_t* tuple) /*!< in: tuple */
228
235
const dfield_t* field;
242
/**************************************************************
248
/**********************************************************//**
243
249
Validates the consistency of a tuple which must be complete, i.e,
244
all fields must have been set. */
250
all fields must have been set.
251
@return TRUE if ok */
249
/* out: TRUE if ok */
250
const dtuple_t* tuple) /* in: tuple */
256
const dtuple_t* tuple) /*!< in: tuple */
252
258
const dfield_t* field;
292
298
#endif /* UNIV_DEBUG */
294
/*****************************************************************
300
#ifndef UNIV_HOTBACKUP
301
/*************************************************************//**
295
302
Pretty prints a dfield value according to its data type. */
300
const dfield_t* dfield) /* in: dfield */
307
const dfield_t* dfield) /*!< in: dfield */
302
309
const byte* data;
336
/*****************************************************************
343
/*************************************************************//**
337
344
Pretty prints a dfield value according to its data type. Also the hex string
338
345
is printed if a string contains non-printable characters. */
341
348
dfield_print_also_hex(
342
349
/*==================*/
343
const dfield_t* dfield) /* in: dfield */
350
const dfield_t* dfield) /*!< in: dfield */
345
352
const byte* data;
508
/*****************************************************************
515
/*************************************************************//**
509
516
Print a dfield value using ut_print_buf. */
512
519
dfield_print_raw(
513
520
/*=============*/
514
FILE* f, /* in: output stream */
515
const dfield_t* dfield) /* in: dfield */
521
FILE* f, /*!< in: output stream */
522
const dfield_t* dfield) /*!< in: dfield */
517
524
ulint len = dfield_get_len(dfield);
518
525
if (!dfield_is_null(dfield)) {
531
/**************************************************************
538
/**********************************************************//**
532
539
The following function prints the contents of a tuple. */
537
FILE* f, /* in: output stream */
538
const dtuple_t* tuple) /* in: tuple */
544
FILE* f, /*!< in: output stream */
545
const dtuple_t* tuple) /*!< in: tuple */
556
563
ut_ad(dtuple_validate(tuple));
559
/******************************************************************
566
/**************************************************************//**
560
567
Moves parts of long fields in entry to the big record vector so that
561
568
the size of tuple drops below the maximum record size allowed in the
562
569
database. Moves data only from those fields which are not necessary
563
to determine uniquely the insertion place of the tuple in the index. */
570
to determine uniquely the insertion place of the tuple in the index.
571
@return own: created big record vector, NULL if we are not able to
572
shorten the entry enough, i.e., if there are too many fixed-length or
573
short fields in entry or the index is clustered */
566
576
dtuple_convert_big_rec(
567
577
/*===================*/
568
/* out, own: created big record vector,
569
NULL if we are not able to shorten
570
the entry enough, i.e., if there are
571
too many fixed-length or short fields
572
in entry or the index is clustered */
573
dict_index_t* index, /* in: index */
574
dtuple_t* entry, /* in/out: index entry */
575
ulint* n_ext) /* in/out: number of
578
dict_index_t* index, /*!< in: index */
579
dtuple_t* entry, /*!< in/out: index entry */
580
ulint* n_ext) /*!< in/out: number of
576
581
externally stored columns */
578
583
mem_heap_t* heap;
722
/******************************************************************
727
/**************************************************************//**
723
728
Puts back to entry the data stored in vector. Note that to ensure the
724
729
fields in entry can accommodate the data, vector must have been created
725
730
from entry with dtuple_convert_big_rec. */
728
733
dtuple_convert_back_big_rec(
729
734
/*========================*/
730
dict_index_t* index __attribute__((unused)), /* in: index */
731
dtuple_t* entry, /* in: entry whose data was put to vector */
732
big_rec_t* vector) /* in, own: big rec vector; it is
735
dict_index_t* index __attribute__((unused)), /*!< in: index */
736
dtuple_t* entry, /*!< in: entry whose data was put to vector */
737
big_rec_t* vector) /*!< in, own: big rec vector; it is
733
738
freed in this function */
735
740
big_rec_field_t* b = vector->fields;