Debian Codegraph @

storage/innobase/rem/rem0wrec.cc

raw
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 implementation
29
30 Created 13/08/2021 Mayank Prasad
31 ******************************************************************************/
32
33 #include "rem0wrec.h"
34 #include "rem0lrec.h"
35
36 #ifndef UNIV_NO_ERR_MSGS
37 /** Dumps metadata of table.
38 @param[in] table InnoDB table object*/
39 static void dump_metadata_dict_table(const dict_table_t *table) {
40 ib::info(ER_IB_DICT_LOG_TABLE_INFO) << "Table Id : " << table->id;
41 ib::info(ER_IB_DICT_LOG_TABLE_INFO) << "Table Name : " << table->name.m_name;
42 ib::info(ER_IB_DICT_LOG_TABLE_INFO)
43 << "Has instant cols : " << table->has_instant_cols();
44 ib::info(ER_IB_DICT_LOG_TABLE_INFO)
45 << "Has instant row versions : " << table->has_row_versions();
46 ib::info(ER_IB_DICT_LOG_TABLE_INFO)
47 << "Current row version : " << table->current_row_version;
48 ib::info(ER_IB_DICT_LOG_TABLE_INFO)
49 << "Table initial column count : " << table->initial_col_count;
50 ib::info(ER_IB_DICT_LOG_TABLE_INFO)
51 << "Table current column count : " << table->current_col_count;
52 ib::info(ER_IB_DICT_LOG_TABLE_INFO)
53 << "Table total column count : " << table->total_col_count;
54 ib::info(ER_IB_DICT_LOG_TABLE_INFO) << "Number of columns added instantly : "
55 << table->get_n_instant_add_cols();
56 ib::info(ER_IB_DICT_LOG_TABLE_INFO)
57 << "Number of columns dropped instantly : "
58 << table->get_n_instant_drop_cols();
59 ib::info(ER_IB_DICT_LOG_TABLE_INFO)
60 << "Table uses COMPACT page format : " << dict_table_is_comp(table);
61 }
62 #endif /* !UNIV_NO_ERR_MSGS */
63
64 void validate_rec_offset(const dict_index_t *index, const ulint *offsets,
65 ulint n, ut::Location L) {
66 ut_ad(rec_offs_validate(nullptr, nullptr, offsets));
67 if (n >= rec_offs_n_fields(offsets)) {
68 #ifndef UNIV_NO_ERR_MSGS
69 dump_metadata_dict_table(index->table);
70 auto num_fields = static_cast<size_t>(rec_offs_n_fields(offsets));
71 ib::fatal(L, ER_IB_DICT_INVALID_COLUMN_POSITION, ulonglong{n}, num_fields);
72 #endif /* !UNIV_NO_ERR_MSGS */
73 }
74 }
75
76 const byte *rec_get_nth_field_old(const dict_index_t *index, const rec_t *rec,
77 ulint n, ulint *len) {
78 const byte *field = rec + rec_get_nth_field_offs_old(index, rec, n, len);
79 return (field);
80 }
81
82 ulint rec_get_nth_field_size(const dict_index_t *index, const rec_t *rec,
83 ulint n) {
84 if (index) {
85 ut_ad(!dict_table_is_comp(index->table));
86 if (index->has_row_versions()) {
87 uint8_t version = UINT8_UNDEFINED;
88 if (rec_old_is_versioned(rec)) {
89 version = rec_get_instant_row_version_old(rec);
90 }
91
92 n = index->get_field_phy_pos(n, version);
93 }
94 }
95
96 return rec_get_nth_field_size_low(rec, n);
97 }
98
99 ulint rec_get_nth_field_offs_old(const dict_index_t *index, const rec_t *rec,
100 ulint n, ulint *len) {
101 if (index) {
102 ut_ad(!dict_table_is_comp(index->table));
103 if (index->has_row_versions()) {
104 uint8_t version = UINT8_UNDEFINED;
105 if (rec_old_is_versioned(rec)) {
106 version = rec_get_instant_row_version_old(rec);
107 }
108
109 n = index->get_field_phy_pos(n, version);
110 }
111 }
112
113 return rec_get_nth_field_offs_old_low(rec, n, len);
114 }
115
116 void rec_offs_make_nth_extern(dict_index_t *index, ulint *offsets, ulint n) {
117 if (index && index->has_row_versions()) {
118 n = index->get_field_off_pos(n);
119 }
120
121 rec_offs_make_nth_extern_low(offsets, n);
122 }
123
124 ulint rec_offs_nth_sql_null(const dict_index_t *index, const ulint *offsets,
125 ulint n) {
126 if (index && index->has_row_versions()) {
127 n = index->get_field_off_pos(n);
128 }
129
130 validate_rec_offset(index, offsets, n, UT_LOCATION_HERE);
131 return (rec_offs_nth_sql_null_low(offsets, n));
132 }
133
134 ulint rec_offs_nth_default(const dict_index_t *index, const ulint *offsets,
135 ulint n) {
136 if (index && index->has_row_versions()) {
137 n = index->get_field_off_pos(n);
138 }
139
140 validate_rec_offset(index, offsets, n, UT_LOCATION_HERE);
141 return (rec_offs_nth_default_low(offsets, n));
142 }
143
144 ulint rec_offs_nth_size(const dict_index_t *index, const ulint *offsets,
145 ulint n) {
146 if (index && index->has_row_versions()) {
147 n = index->get_field_off_pos(n);
148 }
149
150 validate_rec_offset(index, offsets, n, UT_LOCATION_HERE);
151 return (rec_offs_nth_size_low(offsets, n));
152 }
153
154 void rec_set_nth_field(const dict_index_t *index, rec_t *rec,
155 const ulint *offsets, ulint n, const void *data,
156 ulint len) {
157 if (index && index->has_row_versions()) {
158 n = index->get_field_off_pos(n);
159 }
160
161 rec_set_nth_field_low(rec, offsets, n, data, len);
162 }
163
164 ulint rec_2_is_field_extern(const dict_index_t *index, const rec_t *rec,
165 ulint n) {
166 if (index) {
167 ut_ad(!dict_table_is_comp(index->table));
168 if (index->has_row_versions()) {
169 uint8_t version = UINT8_UNDEFINED;
170 if (rec_old_is_versioned(rec)) {
171 version = rec_get_instant_row_version_old(rec);
172 }
173
174 n = index->get_field_phy_pos(n, version);
175 }
176 }
177
178 return (rec_2_get_field_end_info_low(rec, n) & REC_2BYTE_EXTERN_MASK);
179 }
180
181 ulint rec_get_data_size_old(const rec_t *rec) {
182 ut_ad(rec);
183
184 return (rec_get_field_start_offs_low(rec, rec_get_n_fields_old_raw(rec)));
185 }