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