MySQL 26.7.0
Source Code Documentation
rem0wrec.h
Go to the documentation of this file.
1/*****************************************************************************
2Copyright (c) 2021, 2026, Oracle and/or its affiliates.
3
4This program is free software; you can redistribute it and/or modify it under
5the terms of the GNU General Public License, version 2.0, as published by the
6Free Software Foundation.
7
8This program is designed to work with certain software (including
9but not limited to OpenSSL) that is licensed under separate terms,
10as designated in a particular file or component or in included license
11documentation. The authors of MySQL hereby grant you an additional
12permission to link the program and your derivative works with the
13separately licensed software that they have either included with
14the program or referenced in the documentation.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 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
43const byte *rec_get_nth_field_old(const dict_index_t *index, const rec_t *rec,
44 ulint n, ulint *len);
45
46/** The following function is used to get an offset to the nth data field in a
47record.
48@param[in] index record descriptor
49@param[in] offsets array returned by rec_get_offsets()
50@param[in] n index of the field
51@param[out] len length of the field; UNIV_SQL_NULL if SQL null;
52 UNIV_SQL_ADD_COL_DEFAULT if it's default value and no
53 value inlined
54@note This long method is made inline because it is on performance sensitive hot
55path. One must run performance tests if they intend to improve this method.
56@return offset from the origin of rec */
58 const ulint *offsets, ulint n, ulint *len) {
59 if (index && index->has_row_versions()) {
60 n = index->get_field_off_pos(n);
61 }
62
63 ulint offs;
65 ut_ad(n < rec_offs_n_fields(offsets));
66 ut_ad(len);
67
68 if (n == 0) {
69 offs = 0;
70 } else {
71 offs = rec_offs_base(offsets)[n] & REC_OFFS_MASK;
72 }
73
74 length = rec_offs_base(offsets)[1 + n];
75
78 } else if (length & REC_OFFS_DEFAULT) {
80 } else if (length & REC_OFFS_DROP) {
82 } else {
84 length -= offs;
85 }
86
87 *len = length;
88 return (offs);
89}
90
91/** Gets the value of the specified field in the record.
92@param[in] index record descriptor
93@param[in] rec physical record
94@param[in] offsets array returned by rec_get_offsets()
95@param[in] n index of the field
96@param[out] len length of the field, UNIV_SQL_NULL if SQL null
97@return value of the field */
98inline const byte *rec_get_nth_field(const dict_index_t *index,
99 const rec_t *rec, const ulint *offsets,
100 ulint n, ulint *len) {
101 return rec + rec_get_nth_field_offs(index, offsets, n, len);
102}
103
104/** Gets the value of the specified field in the record.
105@param[in] index record descriptor
106@param[in] rec physical record
107@param[in] offsets array returned by rec_get_offsets()
108@param[in] n index of the field
109@param[out] len length of the field, UNIV_SQL_NULL if SQL null
110@return value of the field */
111inline byte *rec_get_nth_field(const dict_index_t *index, rec_t *rec,
112 const ulint *offsets, ulint n, ulint *len) {
113 return const_cast<byte *>(rec_get_nth_field(
114 index, const_cast<const rec_t *>(rec), offsets, n, len));
115}
116
117/** The following function is used to get the offset to the nth
118data field in an old-style record.
119@param[in] index record descriptor
120@param[in] rec record
121@param[in] n index of the field
122@param[in] len length of the field;UNIV_SQL_NULL if SQL null
123@return offset to the field */
125 ulint n, ulint *len);
126
127/** Validates offset and field number.
128@param[in] index record descriptor
129@param[in] offsets array returned by rec_get_offsets()
130@param[in] n nth field
131@param[in] L Line number of calling satement*/
132void validate_rec_offset(const dict_index_t *index, const ulint *offsets,
134
135/** Returns nonzero if the extern bit is set in nth field of rec.
136@param[in] index record descriptor
137@param[in] offsets array returned by rec_get_offsets()
138@param[in] n nth field
139@return nonzero if externally stored */
140[[nodiscard]] inline ulint rec_offs_nth_extern(const dict_index_t *index,
141 const ulint *offsets, ulint n) {
142 if (index && index->has_row_versions()) {
143 n = index->get_field_off_pos(n);
144 }
145
147 /* Returns nonzero if the extern bit is set in nth field of rec. */
148 return rec_offs_base(offsets)[1 + n] & REC_OFFS_EXTERNAL;
149}
150
151/** Mark the nth field as externally stored.
152@param[in] index record descriptor
153@param[in] offsets array returned by rec_get_offsets()
154@param[in] n nth field */
156
157/** Returns nonzero if the SQL NULL bit is set in nth field of rec.
158@param[in] index record descriptor
159@param[in] offsets array returned by rec_get_offsets()
160@param[in] n nth field
161@return nonzero if SQL NULL */
162[[nodiscard]] ulint rec_offs_nth_sql_null(const dict_index_t *index,
163 const ulint *offsets, ulint n);
164
165/** Returns nonzero if the default bit is set in nth field of rec.
166@param[in] index record descriptor
167@param[in] offsets array returned by rec_get_offsets()
168@param[in] n nth field
169@return nonzero if default bit is set */
170ulint rec_offs_nth_default(const dict_index_t *index, const ulint *offsets,
171 ulint n);
172
173/** Gets the physical size of a field.
174@param[in] index record descriptor
175@param[in] offsets array returned by rec_get_offsets()
176@param[in] n nth field
177@return length of field */
178[[nodiscard]] ulint rec_offs_nth_size(const dict_index_t *index,
179 const ulint *offsets, ulint n);
180
181/** This is used to modify the value of an already existing field in a record.
182The previous value must have exactly the same size as the new value. If len is
183UNIV_SQL_NULL then the field is treated as an SQL null.
184For records in ROW_FORMAT=COMPACT (new-style records), len must not be
185UNIV_SQL_NULL unless the field already is SQL null.
186@param[in] index record descriptor
187@param[in] rec record
188@param[in] offsets array returned by rec_get_offsets()
189@param[in] n index number of the field
190@param[in] len length of the data or UNIV_SQL_NULL.
191 If not SQL null, must have the same length as the
192 previous value.
193 If SQL null, previous value must be SQL null.
194@param[in] data pointer to the data if not SQL null */
195void rec_set_nth_field(const dict_index_t *index, rec_t *rec,
196 const ulint *offsets, ulint n, const void *data,
197 ulint len);
198
199/** Returns nonzero if the field is stored off-page.
200@param[in] index index
201@param[in] rec record
202@param[in] n field index
203@retval 0 if the field is stored in-page
204@retval REC_2BYTE_EXTERN_MASK if the field is stored externally */
205[[nodiscard]] ulint rec_2_is_field_extern(const dict_index_t *index,
206 const rec_t *rec, ulint n);
207
208/** The following function returns the data size of an old-style physical
209record, that is the sum of field lengths. SQL null fields are counted as length
2100 fields. The value returned by the function is the distance from record origin
211to record end in bytes.
212@return size */
214#endif
#define L
Definition: ctype-tis620.cc:74
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
Record manager.
constexpr uint32_t REC_OFFS_EXTERNAL
Definition: rec.h:75
constexpr uint32_t REC_OFFS_DEFAULT
Definition: rec.h:77
constexpr uint32_t REC_OFFS_DROP
Definition: rec.h:79
constexpr uint32_t REC_OFFS_MASK
Definition: rec.h:81
constexpr uint32_t REC_OFFS_SQL_NULL
Definition: rec.h:73
static ulint rec_offs_n_fields(const ulint *offsets)
The following function returns the number of fields in a record.
Definition: rec.h:506
static const ulint * rec_offs_base(const ulint *offsets)
Definition: rec.h:227
byte rec_t
Definition: rem0types.h:41
void rec_offs_make_nth_extern(dict_index_t *index, ulint *offsets, ulint n)
Mark the nth field as externally stored.
Definition: rem0wrec.cc:101
ulint rec_offs_nth_default(const dict_index_t *index, const ulint *offsets, ulint n)
Returns nonzero if the default bit is set in nth field of rec.
Definition: rem0wrec.cc:119
const byte * rec_get_nth_field(const dict_index_t *index, const rec_t *rec, const ulint *offsets, ulint n, ulint *len)
Gets the value of the specified field in the record.
Definition: rem0wrec.h:98
void rec_set_nth_field(const dict_index_t *index, rec_t *rec, const ulint *offsets, ulint n, const void *data, ulint len)
This is used to modify the value of an already existing field in a record.
Definition: rem0wrec.cc:139
ulint rec_get_nth_field_offs_old(const dict_index_t *index, const rec_t *rec, ulint n, ulint *len)
The following function is used to get the offset to the nth data field in an old-style record.
Definition: rem0wrec.cc:84
const byte * rec_get_nth_field_old(const dict_index_t *index, const rec_t *rec, ulint n, ulint *len)
Definition: rem0wrec.cc:78
ulint rec_offs_nth_size(const dict_index_t *index, const ulint *offsets, ulint n)
Gets the physical size of a field.
Definition: rem0wrec.cc:129
ulint rec_get_nth_field_offs(const dict_index_t *index, const ulint *offsets, ulint n, ulint *len)
The following function is used to get an offset to the nth data field in a record.
Definition: rem0wrec.h:57
ulint rec_2_is_field_extern(const dict_index_t *index, const rec_t *rec, ulint n)
Returns nonzero if the field is stored off-page.
Definition: rem0wrec.cc:149
ulint rec_offs_nth_extern(const dict_index_t *index, const ulint *offsets, ulint n)
Returns nonzero if the extern bit is set in nth field of rec.
Definition: rem0wrec.h:140
void validate_rec_offset(const dict_index_t *index, const ulint *offsets, ulint n, ut::Location L)
Validates offset and field number.
Definition: rem0wrec.cc:64
ulint rec_offs_nth_sql_null(const dict_index_t *index, const ulint *offsets, ulint n)
Returns nonzero if the SQL NULL bit is set in nth field of rec.
Definition: rem0wrec.cc:109
ulint rec_get_data_size_old(const rec_t *rec)
The following function returns the data size of an old-style physical record, that is the sum of fiel...
Definition: rem0wrec.cc:166
Data structure for an index.
Definition: dict0mem.h:1069
Definition: ut0core.h:36
constexpr uint32_t UNIV_SQL_NULL
The following number as the length of a logical field means that the field has the SQL NULL as its va...
Definition: univ.i:466
constexpr auto UNIV_SQL_ADD_COL_DEFAULT
Flag to indicate a field which was added instantly.
Definition: univ.i:469
unsigned long int ulint
Definition: univ.i:403
constexpr auto UNIV_SQL_INSTANT_DROP_COL
Flag to indicate a field which was dropped instantly.
Definition: univ.i:481
#define UT_LOCATION_HERE
Definition: ut0core.h:73
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:109
int n
Definition: xcom_base.cc:509