| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 1996, 2026, Oracle and/or its affiliates. |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify it under |
| 6 |
the terms of the GNU General Public License, version 2.0, as published by the |
| 7 |
Free Software Foundation. |
| 8 |
|
| 9 |
This program is designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
/** @file include/row0row.h |
| 29 |
General row routines |
| 30 |
|
| 31 |
Created 4/20/1996 Heikki Tuuri |
| 32 |
*******************************************************/ |
| 33 |
|
| 34 |
#ifndef row0row_h |
| 35 |
#define row0row_h |
| 36 |
|
| 37 |
#include "btr0types.h" |
| 38 |
#include "data0data.h" |
| 39 |
#include "dict0types.h" |
| 40 |
#include "mtr0mtr.h" |
| 41 |
#include "que0types.h" |
| 42 |
#include "rem0types.h" |
| 43 |
#include "row0types.h" |
| 44 |
#include "trx0types.h" |
| 45 |
#include "univ.i" |
| 46 |
|
| 47 |
/** Gets the offset of the DB_TRX_ID field, in bytes relative to the origin of |
| 48 |
a clustered index record. |
| 49 |
@param[in] index Clustered index. |
| 50 |
@param[in] offsets rec_get_offsets(rec, index). |
| 51 |
@return offset of DATA_TRX_ID */ |
| 52 |
[[nodiscard]] static inline ulint row_get_trx_id_offset( |
| 53 |
const dict_index_t *index, const ulint *offsets); |
| 54 |
/** Reads the trx id field from a clustered index record. |
| 55 |
@param[in] rec Record. |
| 56 |
@param[in] index Clustered index. |
| 57 |
@param[in] offsets rec_get_offsets(rec, index). |
| 58 |
@return value of the field */ |
| 59 |
[[nodiscard]] static inline trx_id_t row_get_rec_trx_id( |
| 60 |
const rec_t *rec, const dict_index_t *index, const ulint *offsets); |
| 61 |
/** Reads the roll pointer field from a clustered index record. |
| 62 |
@param[in] rec Record. |
| 63 |
@param[in] index Clustered index. |
| 64 |
@param[in] offsets rec_get_offsets(rec, index). |
| 65 |
@return value of the field */ |
| 66 |
[[nodiscard]] static inline roll_ptr_t row_get_rec_roll_ptr( |
| 67 |
const rec_t *rec, const dict_index_t *index, const ulint *offsets); |
| 68 |
|
| 69 |
/* Flags for row build type. */ |
| 70 |
/** build index row */ |
| 71 |
constexpr uint32_t ROW_BUILD_NORMAL = 0; |
| 72 |
/** build row for purge. */ |
| 73 |
constexpr uint32_t ROW_BUILD_FOR_PURGE = 1; |
| 74 |
/** build row for undo. */ |
| 75 |
constexpr uint32_t ROW_BUILD_FOR_UNDO = 2; |
| 76 |
/** build row for insert. */ |
| 77 |
constexpr uint32_t ROW_BUILD_FOR_INSERT = 3; |
| 78 |
/** When an insert or purge to a table is performed, this function builds |
| 79 |
the entry to be inserted into or purged from an index on the table. |
| 80 |
@param[in] row Row which should be inserted or purged. |
| 81 |
@param[in] ext Externally stored column prefixes, or nullptr. |
| 82 |
@param[in] index Index on the table. |
| 83 |
@param[in] heap Memory heap from which the memory for the index entry is |
| 84 |
allocated. |
| 85 |
@param[in] flag ROW_BUILD_NORMAL, ROW_BUILD_FOR_PURGE or ROW_BUILD_FOR_UNDO. |
| 86 |
@return index entry which should be inserted or purged |
| 87 |
@retval NULL if the externally stored columns in the clustered index record |
| 88 |
are unavailable and ext != nullptr, or row is missing some needed columns. */ |
| 89 |
[[nodiscard]] dtuple_t *row_build_index_entry_low(const dtuple_t *row, |
| 90 |
const row_ext_t *ext, |
| 91 |
const dict_index_t *index, |
| 92 |
mem_heap_t *heap, ulint flag); |
| 93 |
/** When an insert or purge to a table is performed, this function builds |
| 94 |
the entry to be inserted into or purged from an index on the table. |
| 95 |
@return index entry which should be inserted or purged, or NULL if the |
| 96 |
externally stored columns in the clustered index record are |
| 97 |
unavailable and ext != nullptr |
| 98 |
@param[in] row Row which should be inserted or purged. |
| 99 |
@param[in] ext Externally stored column prefixes, or nullptr. |
| 100 |
@param[in] index Index on the table. |
| 101 |
@param[in] heap Memory heap from which the memory for the index entry is |
| 102 |
allocated. */ |
| 103 |
[[nodiscard]] static inline dtuple_t *row_build_index_entry( |
| 104 |
const dtuple_t *row, const row_ext_t *ext, const dict_index_t *index, |
| 105 |
mem_heap_t *heap); |
| 106 |
/** An inverse function to row_build_index_entry. Builds a row from a |
| 107 |
record in a clustered index. |
| 108 |
@param[in] type ROW_COPY_POINTERS or ROW_COPY_DATA; the latter copies also |
| 109 |
the data fields to heap while the first only places pointers to data fields on |
| 110 |
the index page, and thus is more efficient. |
| 111 |
@param[in] index Clustered index. |
| 112 |
@param[in] rec Record in the clustered index; NOTE: in the case |
| 113 |
ROW_COPY_POINTERS the data fields in the row will point directly into this |
| 114 |
record, therefore, the buffer page of this record must be at least s-latched and |
| 115 |
the latch held as long as the row dtuple is used! |
| 116 |
@param[in] offsets rec_get_offsets(rec,index) or nullptr, in which case this |
| 117 |
function will invoke rec_get_offsets(). |
| 118 |
@param[in] col_table Table, to check which externally stored columns occur in |
| 119 |
the ordering columns of an index, or nullptr if index->table should be consulted |
| 120 |
instead; the user columns in this table should be the same columns as in |
| 121 |
index->table. |
| 122 |
@param[in] add_cols Default values of added columns, or nullptr. |
| 123 |
@param[in] col_map Mapping of old column numbers to new ones, or nullptr. |
| 124 |
@param[out] ext cache of externally stored column prefixes, or nullptr. |
| 125 |
@param[in] heap Memory heap from which the memory needed is allocated. |
| 126 |
@return own: row built; see the NOTE below! */ |
| 127 |
dtuple_t *row_build(ulint type, const dict_index_t *index, const rec_t *rec, |
| 128 |
const ulint *offsets, const dict_table_t *col_table, |
| 129 |
const dtuple_t *add_cols, const ulint *col_map, |
| 130 |
row_ext_t **ext, mem_heap_t *heap); |
| 131 |
|
| 132 |
/** An inverse function to row_build_index_entry. Builds a row from a |
| 133 |
record in a clustered index, with possible indexing on ongoing |
| 134 |
addition of new virtual columns. |
| 135 |
@param[in] type ROW_COPY_POINTERS or ROW_COPY_DATA; |
| 136 |
@param[in] index clustered index |
| 137 |
@param[in] rec record in the clustered index |
| 138 |
@param[in] offsets rec_get_offsets(rec,index) or NULL |
| 139 |
@param[in] col_table table, to check which |
| 140 |
externally stored columns |
| 141 |
occur in the ordering columns |
| 142 |
of an index, or NULL if |
| 143 |
index->table should be |
| 144 |
consulted instead |
| 145 |
@param[in] add_cols default values of added columns, or NULL |
| 146 |
@param[in] add_v new virtual columns added |
| 147 |
along with new indexes |
| 148 |
@param[in] col_map mapping of old column |
| 149 |
numbers to new ones, or NULL |
| 150 |
@param[in] ext cache of externally stored column |
| 151 |
prefixes, or NULL |
| 152 |
@param[in] heap memory heap from which |
| 153 |
the memory needed is allocated |
| 154 |
@return own: row built */ |
| 155 |
dtuple_t *row_build_w_add_vcol(ulint type, const dict_index_t *index, |
| 156 |
const rec_t *rec, const ulint *offsets, |
| 157 |
const dict_table_t *col_table, |
| 158 |
const dtuple_t *add_cols, |
| 159 |
const dict_add_v_col_t *add_v, |
| 160 |
const ulint *col_map, row_ext_t **ext, |
| 161 |
mem_heap_t *heap); |
| 162 |
|
| 163 |
/** Converts an index record to a typed data tuple. |
| 164 |
@return index entry built; does not set info_bits, and the data fields |
| 165 |
in the entry will point directly to rec */ |
| 166 |
[[nodiscard]] dtuple_t *row_rec_to_index_entry_low( |
| 167 |
const rec_t *rec, /*!< in: record in the index */ |
| 168 |
const dict_index_t *index, /*!< in: index */ |
| 169 |
const ulint *offsets, /*!< in: rec_get_offsets(rec, index) */ |
| 170 |
mem_heap_t *heap); /*!< in: memory heap from which |
| 171 |
the memory needed is allocated */ |
| 172 |
/** Converts an index record to a typed data tuple. NOTE that externally |
| 173 |
stored (often big) fields are NOT copied to heap. |
| 174 |
@return own: index entry built */ |
| 175 |
[[nodiscard]] dtuple_t *row_rec_to_index_entry( |
| 176 |
const rec_t *rec, /*!< in: record in the index */ |
| 177 |
const dict_index_t *index, /*!< in: index */ |
| 178 |
const ulint *offsets, /*!< in/out: rec_get_offsets(rec) */ |
| 179 |
mem_heap_t *heap); /*!< in: memory heap from which |
| 180 |
the memory needed is allocated */ |
| 181 |
/** Builds from a secondary index record a row reference with which we can |
| 182 |
search the clustered index record. |
| 183 |
@return own: row reference built; see the NOTE below! */ |
| 184 |
[[nodiscard]] dtuple_t *row_build_row_ref( |
| 185 |
ulint type, /*!< in: ROW_COPY_DATA, or ROW_COPY_POINTERS: |
| 186 |
the former copies also the data fields to |
| 187 |
heap, whereas the latter only places pointers |
| 188 |
to data fields on the index page */ |
| 189 |
const dict_index_t *index, /*!< in: secondary index */ |
| 190 |
const rec_t *rec, /*!< in: record in the index; |
| 191 |
NOTE: in the case ROW_COPY_POINTERS |
| 192 |
the data fields in the row will point |
| 193 |
directly into this record, therefore, |
| 194 |
the buffer page of this record must be |
| 195 |
at least s-latched and the latch held |
| 196 |
as long as the row reference is used! */ |
| 197 |
mem_heap_t *heap); /*!< in: memory heap from which the memory |
| 198 |
needed is allocated */ |
| 199 |
|
| 200 |
/** Builds from a secondary index record a row reference with which we can |
| 201 |
search the clustered index record. |
| 202 |
@param[in,out] ref Row reference built; see the note below! |
| 203 |
@param[in,out] rec Record in the index; note: the data fields in ref will point |
| 204 |
directly into this record, therefore, the buffer page of this record must be at |
| 205 |
least s-latched and the latch held as long as the row reference is used! |
| 206 |
@param[in] index Secondary index |
| 207 |
@param[in] offsets Rec_get_offsets(rec, index) or null */ |
| 208 |
void row_build_row_ref_in_tuple(dtuple_t *ref, const rec_t *rec, |
| 209 |
const dict_index_t *index, ulint *offsets); |
| 210 |
|
| 211 |
/** Builds from a secondary index record a row reference with which we can |
| 212 |
search the clustered index record. |
| 213 |
@param[in,out] ref typed data tuple where the reference is built |
| 214 |
@param[in] map array of field numbers in rec telling how ref should |
| 215 |
be built from the fields of rec |
| 216 |
@param[in] rec record in the index; must be preserved while ref is |
| 217 |
used, as we do not copy field values to heap |
| 218 |
@param[in] offsets array returned by rec_get_offsets() */ |
| 219 |
static inline void row_build_row_ref_fast(dtuple_t *ref, const ulint *map, |
| 220 |
const rec_t *rec, |
| 221 |
const ulint *offsets); |
| 222 |
|
| 223 |
/** Searches the clustered index record for a row, if we have the row |
| 224 |
reference. |
| 225 |
@return true if found */ |
| 226 |
[[nodiscard]] bool row_search_on_row_ref( |
| 227 |
btr_pcur_t *pcur, /*!< out: persistent cursor, which |
| 228 |
must be closed by the caller */ |
| 229 |
ulint mode, /*!< in: BTR_MODIFY_LEAF, ... */ |
| 230 |
dict_table_t *table, /*!< in: table */ |
| 231 |
const dtuple_t *ref, /*!< in: row reference */ |
| 232 |
mtr_t *mtr); /*!< in/out: mtr */ |
| 233 |
/** Fetches the clustered index record for a secondary index record. The latches |
| 234 |
on the secondary index record are preserved. |
| 235 |
@return record or NULL, if no record found */ |
| 236 |
[[nodiscard]] rec_t *row_get_clust_rec( |
| 237 |
ulint mode, /*!< in: BTR_MODIFY_LEAF, ... */ |
| 238 |
const rec_t *rec, /*!< in: record in a secondary index */ |
| 239 |
const dict_index_t *index, /*!< in: secondary index */ |
| 240 |
dict_index_t **clust_index, /*!< out: clustered index */ |
| 241 |
mtr_t *mtr); /*!< in: mtr */ |
| 242 |
|
| 243 |
/** Parse the integer data from specified data, which could be |
| 244 |
DATA_INT, DATA_FLOAT or DATA_DOUBLE. If the value is less than 0 |
| 245 |
and the type is not unsigned then we reset the value to 0 |
| 246 |
@param[in] data data to read |
| 247 |
@param[in] len length of data |
| 248 |
@param[in] mtype mtype of data |
| 249 |
@param[in] unsigned_type if the data is unsigned |
| 250 |
@return the integer value from the data */ |
| 251 |
inline uint64_t row_parse_int(const byte *data, ulint len, ulint mtype, |
| 252 |
bool unsigned_type); |
| 253 |
|
| 254 |
/** Parse the integer data from specified field, which could be |
| 255 |
DATA_INT, DATA_FLOAT or DATA_DOUBLE. We could return 0 if |
| 256 |
1) the value is less than 0 and the type is not unsigned |
| 257 |
or 2) the field is null. |
| 258 |
@param[in] field field to read the int value |
| 259 |
@return the integer value read from the field, 0 for negative signed |
| 260 |
int or NULL field */ |
| 261 |
uint64_t row_parse_int_from_field(const dfield_t *field); |
| 262 |
|
| 263 |
/** Read the autoinc counter from the clustered index row. |
| 264 |
@param[in] row row to read the autoinc counter |
| 265 |
@param[in] n autoinc counter is in the nth field |
| 266 |
@return the autoinc counter read */ |
| 267 |
uint64_t row_get_autoinc_counter(const dtuple_t *row, ulint n); |
| 268 |
|
| 269 |
/** Result of row_search_index_entry */ |
| 270 |
enum row_search_result { |
| 271 |
ROW_FOUND = 0, /*!< the record was found */ |
| 272 |
ROW_NOT_FOUND, /*!< record not found */ |
| 273 |
ROW_BUFFERED, /*!< one of BTR_INSERT, BTR_DELETE, or |
| 274 |
BTR_DELETE_MARK was specified, the |
| 275 |
secondary index leaf page was not in |
| 276 |
the buffer pool, and the operation was |
| 277 |
enqueued in the insert/delete buffer */ |
| 278 |
ROW_NOT_DELETED_REF /*!< BTR_DELETE was specified, and |
| 279 |
row_purge_poss_sec() failed */ |
| 280 |
}; |
| 281 |
|
| 282 |
/** Searches an index record. |
| 283 |
@return whether the record was found or buffered */ |
| 284 |
[[nodiscard]] enum row_search_result row_search_index_entry( |
| 285 |
dict_index_t *index, /*!< in: index */ |
| 286 |
const dtuple_t *entry, /*!< in: index entry */ |
| 287 |
ulint mode, /*!< in: BTR_MODIFY_LEAF, ... */ |
| 288 |
btr_pcur_t *pcur, /*!< in/out: persistent cursor, which must |
| 289 |
be closed by the caller */ |
| 290 |
mtr_t *mtr); /*!< in: mtr */ |
| 291 |
|
| 292 |
constexpr uint32_t ROW_COPY_DATA = 1; |
| 293 |
constexpr uint32_t ROW_COPY_POINTERS = 2; |
| 294 |
|
| 295 |
/* The allowed latching order of index records is the following: |
| 296 |
(1) a secondary index record -> |
| 297 |
(2) the clustered index record -> |
| 298 |
(3) rollback segment data for the clustered index record. */ |
| 299 |
|
| 300 |
/** Formats the raw data in "data" (in InnoDB on-disk format) using |
| 301 |
"dict_field" and writes the result to "buf". |
| 302 |
Not more than "buf_size" bytes are written to "buf". |
| 303 |
The result is always NUL-terminated (provided buf_size is positive) and the |
| 304 |
number of bytes that were written to "buf" is returned (including the |
| 305 |
terminating NUL). |
| 306 |
@return number of bytes that were written */ |
| 307 |
[[nodiscard]] ulint row_raw_format( |
| 308 |
const char *data, /*!< in: raw data */ |
| 309 |
ulint data_len, /*!< in: raw data length |
| 310 |
in bytes */ |
| 311 |
const dict_field_t *dict_field, /*!< in: index field */ |
| 312 |
char *buf, /*!< out: output buffer */ |
| 313 |
ulint buf_size); /*!< in: output buffer size |
| 314 |
in bytes */ |
| 315 |
|
| 316 |
/** Class to build a series of entries based on one multi-value field. |
| 317 |
It assumes that there is only one multi-value field on multi-value index. */ |
| 318 |
class Multi_value_entry_builder { |
| 319 |
public: |
| 320 |
/** Constructor */ |
| 321 |
Multi_value_entry_builder(dict_index_t *index, dtuple_t *entry, bool selected) |
| 322 |
: m_index(index), |
| 323 |
m_selected(selected), |
| 324 |
m_entry(entry), |
| 325 |
m_pos(0), |
| 326 |
m_mv_data(nullptr), |
| 327 |
m_mv_field_no(0) {} |
| 328 |
|
| 329 |
virtual ~Multi_value_entry_builder() = default; |
| 330 |
|
| 331 |
/** Get the first index entry. If the multi-value field on the index |
| 332 |
is null, then it's the entry including the null field, otherwise, |
| 333 |
it should be the entry with multi-value data at the 'pos' position. |
| 334 |
@param[in] pos position of the multi-value array, default value |
| 335 |
will always start from 0 |
| 336 |
@return the first index entry to handle, the one including null |
| 337 |
multi-value field, or the multi-value data at the 'pos' position */ |
| 338 |
dtuple_t *begin(uint32_t pos = 0) { |
| 339 |
if (!prepare_multi_value_field()) { |
| 340 |
return (nullptr); |
| 341 |
} |
| 342 |
|
| 343 |
prepare_entry_if_necessary(); |
| 344 |
ut_ad(m_entry != nullptr); |
| 345 |
|
| 346 |
m_pos = pos; |
| 347 |
return (m_mv_data == nullptr ? m_entry : next()); |
| 348 |
} |
| 349 |
|
| 350 |
/** Get next index entry based on next multi-value data. |
| 351 |
If the previous value is null, then always no next. |
| 352 |
@return next index entry, or nullptr if no more multi-value data */ |
| 353 |
dtuple_t *next() { |
| 354 |
if (m_mv_data == nullptr || m_pos >= m_mv_data->num_v) { |
| 355 |
return (nullptr); |
| 356 |
} |
| 357 |
|
| 358 |
ut_ad(m_entry != nullptr); |
| 359 |
dfield_t *field = dtuple_get_nth_field(m_entry, m_mv_field_no); |
| 360 |
ut_ad(dfield_is_multi_value(field)); |
| 361 |
|
| 362 |
if (m_selected && (skip() == m_mv_data->num_v)) { |
| 363 |
return (nullptr); |
| 364 |
} |
| 365 |
|
| 366 |
const auto len = m_mv_data->data_len[m_pos]; |
| 367 |
dfield_set_data(field, m_mv_data->datap[m_pos], len); |
| 368 |
|
| 369 |
++m_pos; |
| 370 |
return (m_entry); |
| 371 |
} |
| 372 |
|
| 373 |
/** Get the position of last generated multi-value data |
| 374 |
@return the position */ |
| 375 |
uint32_t last_multi_value_position() const { |
| 376 |
return (m_pos > 0 ? m_pos - 1 : 0); |
| 377 |
} |
| 378 |
|
| 379 |
protected: |
| 380 |
/** Find the multi-value field from the passed in entry or row. |
| 381 |
m_mv_field_no should be set once the multi-value field found. |
| 382 |
@return the multi-value field pointer, or nullptr if not found */ |
| 383 |
virtual dfield_t *find_multi_value_field() = 0; |
| 384 |
|
| 385 |
/** Prepare the corresponding multi-value field from the row. |
| 386 |
This function will set the m_mv_data if the proper field found. |
| 387 |
@return true if the multi-value field with data on index found, |
| 388 |
otherwise, false */ |
| 389 |
virtual bool prepare_multi_value_field() { |
| 390 |
dfield_t *field = find_multi_value_field(); |
| 391 |
|
| 392 |
if (field == nullptr || field->len == UNIV_NO_INDEX_VALUE) { |
| 393 |
return (false); |
| 394 |
} |
| 395 |
|
| 396 |
ut_ad(m_mv_field_no > 0); |
| 397 |
ut_ad(dfield_is_multi_value(field)); |
| 398 |
|
| 399 |
--m_mv_field_no; |
| 400 |
|
| 401 |
if (!dfield_is_null(field)) { |
| 402 |
m_mv_data = static_cast<multi_value_data *>(field->data); |
| 403 |
} |
| 404 |
|
| 405 |
return (true); |
| 406 |
} |
| 407 |
|
| 408 |
/** Prepare the entry when the entry is not passed in */ |
| 409 |
virtual void prepare_entry_if_necessary() { return; } |
| 410 |
|
| 411 |
/** Skip the not selected values and stop m_pos at the next selected one |
| 412 |
@return the next valid value position, or size of m_mv_data to indicate |
| 413 |
there is no more valid value */ |
| 414 |
virtual uint32_t skip() { |
| 415 |
ut_ad(m_mv_data != nullptr); |
| 416 |
ut_ad(m_selected); |
| 417 |
return (m_mv_data->num_v); |
| 418 |
} |
| 419 |
|
| 420 |
protected: |
| 421 |
/** Based on which index to build the entry */ |
| 422 |
dict_index_t *m_index; |
| 423 |
|
| 424 |
/** True if only the selected(bitmap set) multi-value data would be |
| 425 |
used to build the entries, otherwise false. */ |
| 426 |
const bool m_selected; |
| 427 |
|
| 428 |
/** Entry built for the index */ |
| 429 |
dtuple_t *m_entry; |
| 430 |
|
| 431 |
/** Multi-value data position */ |
| 432 |
uint32_t m_pos; |
| 433 |
|
| 434 |
/** Multi-value data */ |
| 435 |
const multi_value_data *m_mv_data; |
| 436 |
|
| 437 |
/** Field number of multi-value data on the index */ |
| 438 |
uint32_t m_mv_field_no; |
| 439 |
}; |
| 440 |
|
| 441 |
/** The subclass of the multi-value entry builder, for non-INSERT cases, |
| 442 |
With this class, there should be no need to build separate entries for |
| 443 |
different values in the same multi-value field. */ |
| 444 |
class Multi_value_entry_builder_normal : public Multi_value_entry_builder { |
| 445 |
public: |
| 446 |
/** Constructor |
| 447 |
@param[in] row based on which complete row to build |
| 448 |
the index row |
| 449 |
@param[in] ext externally stored column prefixes of |
| 450 |
the row |
| 451 |
@param[in,out] index multi-value index |
| 452 |
@param[in,out] heap memory heap |
| 453 |
@param[in] check true if type can be checked, otherwise |
| 454 |
skip checking |
| 455 |
@param[in] selected true if only the selected(bitmap set) |
| 456 |
multi-value data would be used to build |
| 457 |
the entries, otherwise false. */ |
| 458 |
Multi_value_entry_builder_normal(const dtuple_t *row, const row_ext_t *ext, |
| 459 |
dict_index_t *index, mem_heap_t *heap, |
| 460 |
bool check, bool selected) |
| 461 |
: Multi_value_entry_builder(index, nullptr, selected), |
| 462 |
m_row(row), |
| 463 |
m_ext(ext), |
| 464 |
m_heap(heap), |
| 465 |
m_check(check) {} |
| 466 |
|
| 467 |
private: |
| 468 |
/** Find the multi-value field from the passed in entry or row. |
| 469 |
m_mv_field_no should be set once the multi-value field found. |
| 470 |
@return the multi-value field pointer, or nullptr if not found */ |
| 471 |
dfield_t *find_multi_value_field() override; |
| 472 |
|
| 473 |
/** Prepare the entry when the entry is not passed in */ |
| 474 |
void prepare_entry_if_necessary() override { |
| 475 |
if (m_check) { |
| 476 |
m_entry = row_build_index_entry(m_row, m_ext, m_index, m_heap); |
| 477 |
} else { |
| 478 |
/* If not check, then it's basically coming from purge. And actually, |
| 479 |
for multi-value index, this flag really doesn't matter. */ |
| 480 |
m_entry = row_build_index_entry_low(m_row, m_ext, m_index, m_heap, |
| 481 |
ROW_BUILD_FOR_PURGE); |
| 482 |
} |
| 483 |
} |
| 484 |
|
| 485 |
/** Skip the not selected values and stop m_pos at the next selected one |
| 486 |
@return the next valid value position, or size of m_mv_data to indicate |
| 487 |
there is no more valid value */ |
| 488 |
uint32_t skip() override { |
| 489 |
ut_ad(m_selected); |
| 490 |
|
| 491 |
if (m_mv_data->bitset == nullptr) { |
| 492 |
return (m_pos); |
| 493 |
} |
| 494 |
|
| 495 |
while (m_pos < m_mv_data->num_v && !m_mv_data->bitset->test(m_pos)) { |
| 496 |
++m_pos; |
| 497 |
} |
| 498 |
|
| 499 |
return (m_pos); |
| 500 |
} |
| 501 |
|
| 502 |
private: |
| 503 |
/** Based on which complete row to build the index row */ |
| 504 |
const dtuple_t *m_row; |
| 505 |
|
| 506 |
/** Externally stored column prefixes, or nullptr */ |
| 507 |
const row_ext_t *m_ext; |
| 508 |
|
| 509 |
/** Memory heap */ |
| 510 |
mem_heap_t *m_heap; |
| 511 |
|
| 512 |
/** True if dfield type should be checked, otherwise false */ |
| 513 |
const bool m_check; |
| 514 |
}; |
| 515 |
|
| 516 |
/** The subclass of the multi-value row builder, for INSERT cases. |
| 517 |
It simply replace the pointers to the multi-value field data for |
| 518 |
each different value */ |
| 519 |
class Multi_value_entry_builder_insert : public Multi_value_entry_builder { |
| 520 |
public: |
| 521 |
/** Constructor |
| 522 |
@param[in,out] index multi-value index |
| 523 |
@param[in] entry entry to insert based on the index */ |
| 524 |
Multi_value_entry_builder_insert(dict_index_t *index, dtuple_t *entry) |
| 525 |
: Multi_value_entry_builder(index, entry, false) {} |
| 526 |
|
| 527 |
private: |
| 528 |
/** Find the multi-value field from the passed entry in or row. |
| 529 |
m_mv_field_no should be set once the multi-value field found. |
| 530 |
@return the multi-value field pointer, or nullptr if not found */ |
| 531 |
dfield_t *find_multi_value_field() override { |
| 532 |
uint16_t i = 0; |
| 533 |
dfield_t *field = nullptr; |
| 534 |
|
| 535 |
ut_ad(m_entry != nullptr); |
| 536 |
|
| 537 |
m_mv_field_no = 0; |
| 538 |
for (; i < m_entry->n_fields; ++i) { |
| 539 |
field = &m_entry->fields[i]; |
| 540 |
if (!dfield_is_multi_value(field)) { |
| 541 |
continue; |
| 542 |
} |
| 543 |
|
| 544 |
m_mv_field_no = i + 1; |
| 545 |
break; |
| 546 |
} |
| 547 |
|
| 548 |
return (i == m_entry->n_fields ? nullptr : field); |
| 549 |
} |
| 550 |
}; |
| 551 |
|
| 552 |
#include "row0row.ic" |
| 553 |
|
| 554 |
#endif |