| 1 |
/***************************************************************************** |
| 2 |
Copyright (c) 2021, 2026, Oracle and/or its affiliates. |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or modify it under |
| 5 |
the terms of the GNU General Public License, version 2.0, as published by the |
| 6 |
Free Software Foundation. |
| 7 |
|
| 8 |
This program is designed to work with certain software (including |
| 9 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 10 |
as designated in a particular file or component or in included license |
| 11 |
documentation. The authors of MySQL hereby grant you an additional |
| 12 |
permission to link the program and your derivative works with the |
| 13 |
separately licensed software that they have either included with |
| 14 |
the program or referenced in the documentation. |
| 15 |
|
| 16 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 17 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 18 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 19 |
for more details. |
| 20 |
|
| 21 |
You should have received a copy of the GNU General Public License along with |
| 22 |
this program; if not, write to the Free Software Foundation, Inc., |
| 23 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 24 |
|
| 25 |
*****************************************************************************/ |
| 26 |
|
| 27 |
/** @file include/rem0wrec.h |
| 28 |
Record manager wrapper declaration. |
| 29 |
|
| 30 |
After INSTANT ADD/DROP feature, fields index on logical record might not be |
| 31 |
same as field index on physical record. So this wrapper is implemented which |
| 32 |
translates logical index to physical index. And then functions of low level |
| 33 |
record manager (rem0lrec.h) are called with physical index of the field. |
| 34 |
|
| 35 |
Created 13/08/2021 Mayank Prasad |
| 36 |
******************************************************************************/ |
| 37 |
|
| 38 |
#ifndef rem0wrec_h |
| 39 |
#define rem0wrec_h |
| 40 |
|
| 41 |
#include "rem/rec.h" |
| 42 |
|
| 43 |
const byte *rec_get_nth_field_old(const dict_index_t *index, const rec_t *rec, |
| 44 |
ulint n, ulint *len); |
| 45 |
|
| 46 |
/** Gets the physical size of an old-style field. |
| 47 |
Also an SQL null may have a field of size > 0, if the data type is of a fixed |
| 48 |
size. |
| 49 |
@param[in] index record descriptor |
| 50 |
@param[in] rec record |
| 51 |
@param[in] n index of the field |
| 52 |
@return field size in bytes */ |
| 53 |
[[nodiscard]] ulint rec_get_nth_field_size(const dict_index_t *index, |
| 54 |
const rec_t *rec, ulint n); |
| 55 |
|
| 56 |
/** The following function is used to get an offset to the nth data field in a |
| 57 |
record. |
| 58 |
@param[in] index record descriptor |
| 59 |
@param[in] offsets array returned by rec_get_offsets() |
| 60 |
@param[in] n index of the field |
| 61 |
@param[out] len length of the field; UNIV_SQL_NULL if SQL null; |
| 62 |
UNIV_SQL_ADD_COL_DEFAULT if it's default value and no |
| 63 |
value inlined |
| 64 |
@note This long method is made inline because it is on performance sensitive hot |
| 65 |
path. One must run performance tests if they intend to improve this method. |
| 66 |
@return offset from the origin of rec */ |
| 67 |
inline ulint rec_get_nth_field_offs(const dict_index_t *index, |
| 68 |
const ulint *offsets, ulint n, ulint *len) { |
| 69 |
if (index && index->has_row_versions()) { |
| 70 |
n = index->get_field_off_pos(n); |
| 71 |
} |
| 72 |
|
| 73 |
ulint offs; |
| 74 |
ulint length; |
| 75 |
ut_ad(n < rec_offs_n_fields(offsets)); |
| 76 |
ut_ad(len); |
| 77 |
|
| 78 |
if (n == 0) { |
| 79 |
offs = 0; |
| 80 |
} else { |
| 81 |
offs = rec_offs_base(offsets)[n] & REC_OFFS_MASK; |
| 82 |
} |
| 83 |
|
| 84 |
length = rec_offs_base(offsets)[1 + n]; |
| 85 |
|
| 86 |
if (length & REC_OFFS_SQL_NULL) { |
| 87 |
length = UNIV_SQL_NULL; |
| 88 |
} else if (length & REC_OFFS_DEFAULT) { |
| 89 |
length = UNIV_SQL_ADD_COL_DEFAULT; |
| 90 |
} else if (length & REC_OFFS_DROP) { |
| 91 |
length = UNIV_SQL_INSTANT_DROP_COL; |
| 92 |
} else { |
| 93 |
length &= REC_OFFS_MASK; |
| 94 |
length -= offs; |
| 95 |
} |
| 96 |
|
| 97 |
*len = length; |
| 98 |
return (offs); |
| 99 |
} |
| 100 |
|
| 101 |
/** Gets the value of the specified field in the record. |
| 102 |
@param[in] index record descriptor |
| 103 |
@param[in] rec physical record |
| 104 |
@param[in] offsets array returned by rec_get_offsets() |
| 105 |
@param[in] n index of the field |
| 106 |
@param[out] len length of the field, UNIV_SQL_NULL if SQL null |
| 107 |
@return value of the field */ |
| 108 |
inline const byte *rec_get_nth_field(const dict_index_t *index, |
| 109 |
const rec_t *rec, const ulint *offsets, |
| 110 |
ulint n, ulint *len) { |
| 111 |
return rec + rec_get_nth_field_offs(index, offsets, n, len); |
| 112 |
} |
| 113 |
|
| 114 |
/** Gets the value of the specified field in the record. |
| 115 |
@param[in] index record descriptor |
| 116 |
@param[in] rec physical record |
| 117 |
@param[in] offsets array returned by rec_get_offsets() |
| 118 |
@param[in] n index of the field |
| 119 |
@param[out] len length of the field, UNIV_SQL_NULL if SQL null |
| 120 |
@return value of the field */ |
| 121 |
inline byte *rec_get_nth_field(const dict_index_t *index, rec_t *rec, |
| 122 |
const ulint *offsets, ulint n, ulint *len) { |
| 123 |
return const_cast<byte *>(rec_get_nth_field( |
| 124 |
index, const_cast<const rec_t *>(rec), offsets, n, len)); |
| 125 |
} |
| 126 |
|
| 127 |
/** The following function is used to get the offset to the nth |
| 128 |
data field in an old-style record. |
| 129 |
@param[in] index record descriptor |
| 130 |
@param[in] rec record |
| 131 |
@param[in] n index of the field |
| 132 |
@param[in] len length of the field;UNIV_SQL_NULL if SQL null |
| 133 |
@return offset to the field */ |
| 134 |
ulint rec_get_nth_field_offs_old(const dict_index_t *index, const rec_t *rec, |
| 135 |
ulint n, ulint *len); |
| 136 |
|
| 137 |
/** Validates offset and field number. |
| 138 |
@param[in] index record descriptor |
| 139 |
@param[in] offsets array returned by rec_get_offsets() |
| 140 |
@param[in] n nth field |
| 141 |
@param[in] L Line number of calling satement*/ |
| 142 |
void validate_rec_offset(const dict_index_t *index, const ulint *offsets, |
| 143 |
ulint n, ut::Location L); |
| 144 |
|
| 145 |
/** Returns nonzero if the extern bit is set in nth field of rec. |
| 146 |
@param[in] index record descriptor |
| 147 |
@param[in] offsets array returned by rec_get_offsets() |
| 148 |
@param[in] n nth field |
| 149 |
@return nonzero if externally stored */ |
| 150 |
[[nodiscard]] inline ulint rec_offs_nth_extern(const dict_index_t *index, |
| 151 |
const ulint *offsets, ulint n) { |
| 152 |
if (index && index->has_row_versions()) { |
| 153 |
n = index->get_field_off_pos(n); |
| 154 |
} |
| 155 |
|
| 156 |
validate_rec_offset(index, offsets, n, UT_LOCATION_HERE); |
| 157 |
/* Returns nonzero if the extern bit is set in nth field of rec. */ |
| 158 |
return rec_offs_base(offsets)[1 + n] & REC_OFFS_EXTERNAL; |
| 159 |
} |
| 160 |
|
| 161 |
/** Mark the nth field as externally stored. |
| 162 |
@param[in] index record descriptor |
| 163 |
@param[in] offsets array returned by rec_get_offsets() |
| 164 |
@param[in] n nth field */ |
| 165 |
void rec_offs_make_nth_extern(dict_index_t *index, ulint *offsets, ulint n); |
| 166 |
|
| 167 |
/** Returns nonzero if the SQL NULL bit is set in nth field of rec. |
| 168 |
@param[in] index record descriptor |
| 169 |
@param[in] offsets array returned by rec_get_offsets() |
| 170 |
@param[in] n nth field |
| 171 |
@return nonzero if SQL NULL */ |
| 172 |
[[nodiscard]] ulint rec_offs_nth_sql_null(const dict_index_t *index, |
| 173 |
const ulint *offsets, ulint n); |
| 174 |
|
| 175 |
/** Returns nonzero if the default bit is set in nth field of rec. |
| 176 |
@param[in] index record descriptor |
| 177 |
@param[in] offsets array returned by rec_get_offsets() |
| 178 |
@param[in] n nth field |
| 179 |
@return nonzero if default bit is set */ |
| 180 |
ulint rec_offs_nth_default(const dict_index_t *index, const ulint *offsets, |
| 181 |
ulint n); |
| 182 |
|
| 183 |
/** Gets the physical size of a field. |
| 184 |
@param[in] index record descriptor |
| 185 |
@param[in] offsets array returned by rec_get_offsets() |
| 186 |
@param[in] n nth field |
| 187 |
@return length of field */ |
| 188 |
[[nodiscard]] ulint rec_offs_nth_size(const dict_index_t *index, |
| 189 |
const ulint *offsets, ulint n); |
| 190 |
|
| 191 |
/** This is used to modify the value of an already existing field in a record. |
| 192 |
The previous value must have exactly the same size as the new value. If len is |
| 193 |
UNIV_SQL_NULL then the field is treated as an SQL null. |
| 194 |
For records in ROW_FORMAT=COMPACT (new-style records), len must not be |
| 195 |
UNIV_SQL_NULL unless the field already is SQL null. |
| 196 |
@param[in] index record descriptor |
| 197 |
@param[in] rec record |
| 198 |
@param[in] offsets array returned by rec_get_offsets() |
| 199 |
@param[in] n index number of the field |
| 200 |
@param[in] len length of the data or UNIV_SQL_NULL. |
| 201 |
If not SQL null, must have the same length as the |
| 202 |
previous value. |
| 203 |
If SQL null, previous value must be SQL null. |
| 204 |
@param[in] data pointer to the data if not SQL null */ |
| 205 |
void rec_set_nth_field(const dict_index_t *index, rec_t *rec, |
| 206 |
const ulint *offsets, ulint n, const void *data, |
| 207 |
ulint len); |
| 208 |
|
| 209 |
/** Returns nonzero if the field is stored off-page. |
| 210 |
@param[in] index index |
| 211 |
@param[in] rec record |
| 212 |
@param[in] n field index |
| 213 |
@retval 0 if the field is stored in-page |
| 214 |
@retval REC_2BYTE_EXTERN_MASK if the field is stored externally */ |
| 215 |
[[nodiscard]] ulint rec_2_is_field_extern(const dict_index_t *index, |
| 216 |
const rec_t *rec, ulint n); |
| 217 |
|
| 218 |
/** The following function returns the data size of an old-style physical |
| 219 |
record, that is the sum of field lengths. SQL null fields are counted as length |
| 220 |
0 fields. The value returned by the function is the distance from record origin |
| 221 |
to record end in bytes. |
| 222 |
@return size */ |
| 223 |
ulint rec_get_data_size_old(const rec_t *rec); |
| 224 |
#endif |