MySQL 9.1.0
Source Code Documentation
rem0wrec.h
Go to the documentation of this file.
1/*****************************************************************************
2Copyright (c) 2021, 2024, 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/** Gets the physical size of an old-style field.
47Also an SQL null may have a field of size > 0, if the data type is of a fixed
48size.
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
57record.
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
65path. One must run performance tests if they intend to improve this method.
66@return offset from the origin of rec */
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;
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
88 } else if (length & REC_OFFS_DEFAULT) {
90 } else if (length & REC_OFFS_DROP) {
92 } else {
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 */
108inline 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 */
121inline 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
128data 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 */
134ulint 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*/
142void validate_rec_offset(const dict_index_t *index, const ulint *offsets,
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 */
165void 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 */
180ulint 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.
192The previous value must have exactly the same size as the new value. If len is
193UNIV_SQL_NULL then the field is treated as an SQL null.
194For records in ROW_FORMAT=COMPACT (new-style records), len must not be
195UNIV_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 */
205void 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
219record, that is the sum of field lengths. SQL null fields are counted as length
2200 fields. The value returned by the function is the distance from record origin
221to record end in bytes.
222@return size */
224#endif
#define L
Definition: ctype-tis620.cc:75
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
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:510
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:116
ulint rec_get_nth_field_size(const dict_index_t *index, const rec_t *rec, ulint n)
Gets the physical size of an old-style field.
Definition: rem0wrec.cc:82
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:134
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:108
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:154
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:99
const byte * rec_get_nth_field_old(const dict_index_t *index, const rec_t *rec, ulint n, ulint *len)
Definition: rem0wrec.cc:76
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:144
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:67
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:164
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:150
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:124
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:181
Data structure for an index.
Definition: dict0mem.h:1041
uint16_t get_field_off_pos(ulint pos) const
Get the physical position of a field on a row.
Definition: dict0mem.h:1521
bool has_row_versions() const
Check whether index belongs to a table having row versions.
Definition: dict0mem.h:1343
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:463
constexpr auto UNIV_SQL_ADD_COL_DEFAULT
Flag to indicate a field which was added instantly.
Definition: univ.i:466
unsigned long int ulint
Definition: univ.i:406
constexpr auto UNIV_SQL_INSTANT_DROP_COL
Flag to indicate a field which was dropped instantly.
Definition: univ.i:478
#define UT_LOCATION_HERE
Definition: ut0core.h:73
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105
int n
Definition: xcom_base.cc:509