MySQL 9.0.0
Source Code Documentation
rem0cmp.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1994, 2024, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 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. */
46
47// Forward declaration
48namespace dd {
49class 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. */
57bool 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
90field, 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 */
104int cmp_dtuple_rec_with_gis(const dtuple_t *dtuple, const rec_t *rec,
105 const ulint *offsets, page_cur_mode_t mode,
107
108/** Compare a GIS data tuple to a physical record in rtree non-leaf node.
109We need to check the page number field, since we don't store pk field in
110rtree 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 */
116int cmp_dtuple_rec_with_gis_internal(const dtuple_t *dtuple, const rec_t *rec,
117 const ulint *offsets,
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 */
131int 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
143field 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,
175none 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,
182or 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
199statistics estimation, and innodb_stats_method=nulls_unequal
200or innodb_stats_method=nulls_ignored
201@param[out] matched_fields number of completely matched fields
202within 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 */
208int 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.
215Only the common first fields are compared, and externally stored field
216are 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
224within 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,
227respectively */
228static 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
Definition: spatial_reference_system.h:53
SQL data field and tuple.
Data types.
Data dictionary system.
Prototypes for global functions in ha_innodb.cc that are called by InnoDB C code.
Common header for many mysys elements.
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
mode
Definition: file_handle.h:61
page_cur_mode_t
Definition: page0types.h:176
static int cmp_dfield_dfield(const dfield_t *dfield1, const dfield_t *dfield2, bool is_asc)
Compare two data fields.
bool cmp_cols_are_equal(const dict_col_t *col1, const dict_col_t *col2, bool check_charsets)
Returns true if two columns are equal for comparison purposes.
Definition: rem0cmp.cc:120
static bool cmp_dfield_dfield_eq_prefix(const dfield_t *dfield1, const dfield_t *dfield2)
Compare two data fields.
static int cmp_rec_rec(const rec_t *rec1, const rec_t *rec2, const ulint *offsets1, const ulint *offsets2, const dict_index_t *index, bool spatial_index_non_leaf, ulint *matched_fields=nullptr, bool cmp_btree_recs=true)
Compare two B-tree records.
int cmp_rec_rec_simple(const rec_t *rec1, const rec_t *rec2, const ulint *offsets1, const ulint *offsets2, const dict_index_t *index, struct TABLE *table)
Compare two physical records that contain the same number of columns, none of which are stored extern...
Definition: rem0cmp.cc:934
int cmp_dtuple_rec_with_gis(const dtuple_t *dtuple, const rec_t *rec, const ulint *offsets, page_cur_mode_t mode, const dd::Spatial_reference_system *srs)
Compare a GIS data tuple to a physical record.
Definition: rem0cmp.cc:546
static int cmp_multi_value_dfield_dfield(const dfield_t *dfield1, const dfield_t *dfield2)
Compare two data fields, the first one can be of any form of multi-value field, while the second one ...
int cmp_dtuple_rec_with_match_bytes(const dtuple_t *dtuple, const rec_t *rec, const dict_index_t *index, const ulint *offsets, ulint *matched_fields, ulint *matched_bytes)
Compare a data tuple to a physical record.
Definition: rem0cmp.cc:732
int cmp_dtuple_rec(const dtuple_t *dtuple, const rec_t *rec, const dict_index_t *index, const ulint *offsets)
Compare a data tuple to a physical record.
Definition: rem0cmp.cc:880
int cmp_rec_rec_with_match(const rec_t *rec1, const rec_t *rec2, const ulint *offsets1, const ulint *offsets2, const dict_index_t *index, bool spatial_index_non_leaf, bool nulls_unequal, ulint *matched_fields, bool cmp_btree_recs=true)
Compare two B-tree records.
Definition: rem0cmp.cc:988
int cmp_dtuple_rec_with_match_low(const dtuple_t *dtuple, const rec_t *rec, const dict_index_t *index, const ulint *offsets, ulint n_cmp, ulint *matched_fields)
Compare a data tuple to a physical record.
Definition: rem0cmp.cc:602
int cmp_data_data(ulint mtype, ulint prtype, bool is_asc, const byte *data1, ulint len1, const byte *data2, ulint len2)
Compare two data fields.
Definition: rem0cmp.cc:597
int cmp_dtuple_rec_with_gis_internal(const dtuple_t *dtuple, const rec_t *rec, const ulint *offsets, const dd::Spatial_reference_system *srs)
Compare a GIS data tuple to a physical record in rtree non-leaf node.
Definition: rem0cmp.cc:566
constexpr auto DISABLE_MIN_REC_FLAG_CHECK
Disable the min flag during row comparisons.
Definition: rem0cmp.h:45
bool cmp_dtuple_is_prefix_of_rec(const dtuple_t *dtuple, const rec_t *rec, const dict_index_t *index, const ulint *offsets)
Check if a dtuple is a prefix of a record.
Definition: rem0cmp.cc:887
Comparison services for records.
Record manager.
byte rec_t
Definition: rem0types.h:41
Definition: table.h:1407
Structure for an SQL data field.
Definition: data0data.h:605
Data structure for a column in a table.
Definition: dict0mem.h:489
Data structure for an index.
Definition: dict0mem.h:1046
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:684
unsigned long int ulint
Definition: univ.i:406
constexpr ulint ULINT_UNDEFINED
The 'undefined' value for a ulint.
Definition: univ.i:420