Debian Codegraph @

storage/innobase/include/rem0cmp.h

raw
1 /*****************************************************************************
2
3 Copyright (c) 1994, 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/rem0cmp.h
29 Comparison services for records
30
31 Created 7/1/1994 Heikki Tuuri
32 ************************************************************************/
33
34 #ifndef rem0cmp_h
35 #define rem0cmp_h
36
37 #include <my_sys.h>
38 #include "data0data.h"
39 #include "data0type.h"
40 #include "dict0dict.h"
41 #include "ha_prototypes.h"
42 #include "rem0rec.h"
43
44 /** Disable the min flag during row comparisons. */
45 constexpr auto DISABLE_MIN_REC_FLAG_CHECK = ULINT_UNDEFINED;
46
47 // Forward declaration
48 namespace dd {
49 class Spatial_reference_system;
50 }
51
52 /** Returns true if two columns are equal for comparison purposes.
53 @param[in] col1 Column to compare.
54 @param[in] col2 Column to compare.
55 @param[in] check_charsets if true then check the character sets.
56 @return true if the columns are considered equal in comparisons. */
57 bool cmp_cols_are_equal(const dict_col_t *col1, const dict_col_t *col2,
58 bool check_charsets);
59
60 /*!< in: whether to check charsets */
61 /** Compare two data fields.
62 @param[in] mtype main type
63 @param[in] prtype precise type
64 @param[in] is_asc true=ascending, false=descending order
65 @param[in] data1 data field
66 @param[in] len1 length of data1 in bytes, or UNIV_SQL_NULL
67 @param[in] data2 data field
68 @param[in] len2 length of data2 in bytes, or UNIV_SQL_NULL
69 @return the comparison result of data1 and data2
70 @retval 0 if data1 is equal to data2
71 @retval negative if data1 is less than data2
72 @retval positive if data1 is greater than data2 */
73 [[nodiscard]] int cmp_data_data(ulint mtype, ulint prtype, bool is_asc,
74 const byte *data1, ulint len1,
75 const byte *data2, ulint len2);
76
77 /** Compare two data fields.
78 @param[in] dfield1 data field; must have type field set
79 @param[in] dfield2 data field
80 @param[in] is_asc true=ASC, false=DESC
81 @return the comparison result of dfield1 and dfield2
82 @retval 0 if dfield1 is equal to dfield2
83 @retval negative if dfield1 is less than dfield2
84 @retval positive if dfield1 is greater than dfield2 */
85 [[nodiscard]] static inline int cmp_dfield_dfield(const dfield_t *dfield1,
86 const dfield_t *dfield2,
87 bool is_asc);
88
89 /** Compare two data fields, the first one can be of any form of multi-value
90 field, while the second one must be one field from multi-value index
91 @param[in] dfield1 multi-value data field;
92 @param[in] dfield2 data field; must have type field set
93 @return 0 if dfield1 has dfield2 or they are equal if both NULL, otherwise 1 */
94 [[nodiscard]] static inline int cmp_multi_value_dfield_dfield(
95 const dfield_t *dfield1, const dfield_t *dfield2);
96
97 /** Compare a GIS data tuple to a physical record.
98 @param[in] dtuple data tuple
99 @param[in] rec B-tree record
100 @param[in] offsets rec_get_offsets(rec)
101 @param[in] mode compare mode
102 @param[in] srs Spatial reference system of R-tree
103 @retval negative if dtuple is less than rec */
104 int cmp_dtuple_rec_with_gis(const dtuple_t *dtuple, const rec_t *rec,
105 const ulint *offsets, page_cur_mode_t mode,
106 const dd::Spatial_reference_system *srs);
107
108 /** Compare a GIS data tuple to a physical record in rtree non-leaf node.
109 We need to check the page number field, since we don't store pk field in
110 rtree non-leaf node.
111 @param[in] dtuple data tuple
112 @param[in] rec R-tree record
113 @param[in] offsets rec_get_offsets(rec)
114 @param[in] srs Spatial referenxe system
115 @retval negative if dtuple is less than rec */
116 int cmp_dtuple_rec_with_gis_internal(const dtuple_t *dtuple, const rec_t *rec,
117 const ulint *offsets,
118 const dd::Spatial_reference_system *srs);
119
120 /** Compare a data tuple to a physical record.
121 @param[in] dtuple data tuple
122 @param[in] rec record
123 @param[in] index index
124 @param[in] offsets rec_get_offsets(rec)
125 @param[in] n_cmp number of fields to compare
126 @param[in,out] matched_fields number of completely matched fields
127 @return the comparison result of dtuple and rec
128 @retval 0 if dtuple is equal to rec
129 @retval negative if dtuple is less than rec
130 @retval positive if dtuple is greater than rec */
131 int cmp_dtuple_rec_with_match_low(const dtuple_t *dtuple, const rec_t *rec,
132 const dict_index_t *index,
133 const ulint *offsets, ulint n_cmp,
134 ulint *matched_fields);
135
136 /** Compare a data tuple to a physical record.
137 @param[in] dtuple data tuple
138 @param[in] rec B-tree or R-tree index record
139 @param[in] index index tree
140 @param[in] offsets rec_get_offsets(rec)
141 @param[in,out] matched_fields number of completely matched fields
142 @param[in,out] matched_bytes number of matched bytes in the first
143 field that is not matched
144 @return the comparison result of dtuple and rec
145 @retval 0 if dtuple is equal to rec
146 @retval negative if dtuple is less than rec
147 @retval positive if dtuple is greater than rec */
148 [[nodiscard]] int cmp_dtuple_rec_with_match_bytes(
149 const dtuple_t *dtuple, const rec_t *rec, const dict_index_t *index,
150 const ulint *offsets, ulint *matched_fields, ulint *matched_bytes);
151 /** Compare a data tuple to a physical record.
152 @see cmp_dtuple_rec_with_match
153 @param[in] dtuple data tuple
154 @param[in] rec record
155 @param[in] index index
156 @param[in] offsets rec_get_offsets(rec)
157 @return the comparison result of dtuple and rec
158 @retval 0 if dtuple is equal to rec
159 @retval negative if dtuple is less than rec
160 @retval positive if dtuple is greater than rec */
161 [[nodiscard]] int cmp_dtuple_rec(const dtuple_t *dtuple, const rec_t *rec,
162 const dict_index_t *index,
163 const ulint *offsets);
164 /** Check if a dtuple is a prefix of a record.
165 @param[in] dtuple data tuple
166 @param[in] rec B-tree record
167 @param[in] index B-tree index
168 @param[in] offsets rec_get_offsets(rec)
169 @return true if prefix */
170 [[nodiscard]] bool cmp_dtuple_is_prefix_of_rec(const dtuple_t *dtuple,
171 const rec_t *rec,
172 const dict_index_t *index,
173 const ulint *offsets);
174 /** Compare two physical records that contain the same number of columns,
175 none of which are stored externally.
176 @param[in] rec1 Physical record 1 to compare
177 @param[in] rec2 Physical record 2 to compare
178 @param[in] offsets1 rec_get_offsets(rec1, ...)
179 @param[in] offsets2 rec_get_offsets(rec2, ...)
180 @param[in] index Data dictionary index
181 @param[in] table MySQL table, for reporting duplicate key value if applicable,
182 or nullptr
183 @retval positive if rec1 (including non-ordering columns) is greater than rec2
184 @retval negative if rec1 (including non-ordering columns) is less than rec2
185 @retval 0 if rec1 is a duplicate of rec2 */
186 [[nodiscard]] int cmp_rec_rec_simple(const rec_t *rec1, const rec_t *rec2,
187 const ulint *offsets1,
188 const ulint *offsets2,
189 const dict_index_t *index,
190 struct TABLE *table);
191 /** Compare two B-tree records.
192 @param[in] rec1 B-tree record
193 @param[in] rec2 B-tree record
194 @param[in] offsets1 rec_get_offsets(rec1, index)
195 @param[in] offsets2 rec_get_offsets(rec2, index)
196 @param[in] index B-tree index
197 @param[in] spatial_index_non_leaf true if record is in spatial non leaf page
198 @param[in] nulls_unequal true if this is for index cardinality
199 statistics estimation, and innodb_stats_method=nulls_unequal
200 or innodb_stats_method=nulls_ignored
201 @param[out] matched_fields number of completely matched fields
202 within the first field not completely matched
203 @param[in] cmp_btree_recs true if we're comparing two b-tree records
204 @return the comparison result
205 @retval 0 if rec1 is equal to rec2
206 @retval negative if rec1 is less than rec2
207 @retval positive if rec2 is greater than rec2 */
208 int cmp_rec_rec_with_match(const rec_t *rec1, const rec_t *rec2,
209 const ulint *offsets1, const ulint *offsets2,
210 const dict_index_t *index,
211 bool spatial_index_non_leaf, bool nulls_unequal,
212 ulint *matched_fields, bool cmp_btree_recs = true);
213
214 /** Compare two B-tree records.
215 Only the common first fields are compared, and externally stored field
216 are treated as equal.
217 @param[in] rec1 B-tree record
218 @param[in] rec2 B-tree record
219 @param[in] offsets1 rec_get_offsets(rec1, index)
220 @param[in] offsets2 rec_get_offsets(rec2, index)
221 @param[in] index B-tree index
222 @param[in] spatial_index_non_leaf true if spatial index non leaf records
223 @param[out] matched_fields number of completely matched fields
224 within the first field not completely matched
225 @param[in] cmp_btree_recs true if the both the records are b-tree records
226 @return positive, 0, negative if rec1 is greater, equal, less, than rec2,
227 respectively */
228 static inline int cmp_rec_rec(const rec_t *rec1, const rec_t *rec2,
229 const ulint *offsets1, const ulint *offsets2,
230 const dict_index_t *index,
231 bool spatial_index_non_leaf,
232 ulint *matched_fields = nullptr,
233 bool cmp_btree_recs = true);
234
235 #ifndef UNIV_HOTBACKUP
236 /** Compare two data fields.
237 @param[in] dfield1 data field
238 @param[in] dfield2 data field
239 @return the comparison result of dfield1 and dfield2
240 @retval true if dfield1 is equal to dfield2, or a prefix of dfield1
241 @retval false otherwise */
242 [[nodiscard]] static inline bool cmp_dfield_dfield_eq_prefix(
243 const dfield_t *dfield1, const dfield_t *dfield2);
244 #endif /* !UNIV_HOTBACKUP */
245
246 #include "rem0cmp.ic"
247
248 #endif