| 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/row0upd.ic |
| 29 |
Update of a row |
| 30 |
|
| 31 |
Created 12/27/1996 Heikki Tuuri |
| 32 |
*******************************************************/ |
| 33 |
|
| 34 |
#include "mtr0log.h" |
| 35 |
#ifndef UNIV_HOTBACKUP |
| 36 |
#include "lock0lock.h" |
| 37 |
#include "row0row.h" |
| 38 |
#include "trx0trx.h" |
| 39 |
#include "trx0undo.h" |
| 40 |
#endif /* !UNIV_HOTBACKUP */ |
| 41 |
#include "page0zip.h" |
| 42 |
|
| 43 |
inline upd_t *upd_create(ulint n, mem_heap_t *heap) { |
| 44 |
upd_t *update; |
| 45 |
|
| 46 |
update = static_cast<upd_t *>( |
| 47 |
mem_heap_zalloc(heap, sizeof(upd_t) + sizeof(upd_field_t) * n)); |
| 48 |
|
| 49 |
update->n_capacity = n; |
| 50 |
update->n_fields = n; |
| 51 |
update->fields = reinterpret_cast<upd_field_t *>(&update[1]); |
| 52 |
update->heap = heap; |
| 53 |
update->per_stmt_heap = nullptr; |
| 54 |
|
| 55 |
for (ulint i = 0; i < n; ++i) { |
| 56 |
upd_field_t *uf = &update->fields[i]; |
| 57 |
uf->heap = heap; |
| 58 |
} |
| 59 |
|
| 60 |
return (update); |
| 61 |
} |
| 62 |
|
| 63 |
inline ulint upd_get_n_fields(const upd_t *update) { |
| 64 |
ut_ad(update); |
| 65 |
|
| 66 |
return update->n_fields; |
| 67 |
} |
| 68 |
|
| 69 |
class upd_get_nth_field_t_impl { |
| 70 |
template <typename FieldType> |
| 71 |
static FieldType *get(const upd_t *update, ulint n) { |
| 72 |
ut_ad(update); |
| 73 |
ut_ad(n < update->n_fields); |
| 74 |
return update->fields + n; |
| 75 |
} |
| 76 |
friend upd_field_t *upd_get_nth_field(upd_t *update, ulint n) { |
| 77 |
return get<upd_field_t>(update, n); |
| 78 |
} |
| 79 |
friend const upd_field_t *upd_get_nth_field(const upd_t *update, ulint n) { |
| 80 |
return get<const upd_field_t>(update, n); |
| 81 |
} |
| 82 |
}; |
| 83 |
|
| 84 |
inline void upd_field_set_field_no(upd_field_t *upd_field, ulint field_no, |
| 85 |
const dict_index_t *index) { |
| 86 |
upd_field->field_no = field_no; |
| 87 |
upd_field->orig_len = 0; |
| 88 |
|
| 89 |
if (field_no >= dict_index_get_n_fields(index)) { |
| 90 |
ib::error(ER_IB_MSG_628) |
| 91 |
<< " trying to access field " << field_no << " in " << index->name |
| 92 |
<< " of table " << index->table->name << " which contains only " |
| 93 |
<< index->n_fields << " fields"; |
| 94 |
ut_d(ut_error); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
inline void upd_field_set_v_field_no(upd_field_t *upd_field, ulint field_no, |
| 99 |
const dict_index_t *index) { |
| 100 |
upd_field->field_no = field_no; |
| 101 |
upd_field->orig_len = 0; |
| 102 |
|
| 103 |
if (field_no >= dict_table_get_n_v_cols(index->table)) { |
| 104 |
ib::error(ER_IB_MSG_629) << " trying to access virtual field " << field_no |
| 105 |
<< " in " << index->name << " of table " |
| 106 |
<< index->table->name << " which contains only " |
| 107 |
<< index->table->n_v_cols << " virutal columns"; |
| 108 |
ut_d(ut_error); |
| 109 |
} |
| 110 |
|
| 111 |
dict_table_get_nth_v_col(index->table, field_no) |
| 112 |
->m_col.copy_type(dfield_get_type(&upd_field->new_val)); |
| 113 |
} |
| 114 |
|
| 115 |
inline const upd_field_t *upd_get_field_by_field_no(const upd_t *update, |
| 116 |
ulint no, bool is_virtual) { |
| 117 |
ulint i; |
| 118 |
for (i = 0; i < upd_get_n_fields(update); i++) { |
| 119 |
const upd_field_t *uf = upd_get_nth_field(update, i); |
| 120 |
|
| 121 |
/* matches only if the field matches that of is_virtual */ |
| 122 |
if ((!is_virtual) != (!uf->is_virtual())) { |
| 123 |
continue; |
| 124 |
} |
| 125 |
|
| 126 |
if (uf->field_no == no) { |
| 127 |
return uf; |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
return nullptr; |
| 132 |
} |
| 133 |
|
| 134 |
#ifndef UNIV_HOTBACKUP |
| 135 |
|
| 136 |
inline void row_upd_rec_sys_fields(rec_t *rec, page_zip_des_t *page_zip, |
| 137 |
const dict_index_t *index, |
| 138 |
const ulint *offsets, const trx_t *trx, |
| 139 |
roll_ptr_t roll_ptr) { |
| 140 |
ut_ad(index->is_clustered()); |
| 141 |
ut_ad(rec_offs_validate(rec, index, offsets)); |
| 142 |
|
| 143 |
if (page_zip) { |
| 144 |
ulint pos = index->get_sys_col_pos(DATA_TRX_ID); |
| 145 |
page_zip_write_trx_id_and_roll_ptr(page_zip, rec, offsets, pos, trx->id, |
| 146 |
roll_ptr); |
| 147 |
} else { |
| 148 |
ulint offset = index->trx_id_offset; |
| 149 |
|
| 150 |
if (!offset) { |
| 151 |
offset = row_get_trx_id_offset(index, offsets); |
| 152 |
} |
| 153 |
|
| 154 |
/* During IMPORT the trx id in the record can be in the |
| 155 |
future, if the .ibd file is being imported from another |
| 156 |
instance. During IMPORT roll_ptr will be 0. */ |
| 157 |
ut_ad(roll_ptr == 0 || |
| 158 |
lock_check_trx_id_sanity(trx_read_trx_id(rec + offset), rec, index, |
| 159 |
offsets)); |
| 160 |
|
| 161 |
trx_write_trx_id(rec + offset, trx->id); |
| 162 |
trx_write_roll_ptr(rec + offset + DATA_TRX_ID_LEN, roll_ptr); |
| 163 |
} |
| 164 |
} |
| 165 |
#endif /* !UNIV_HOTBACKUP */ |