1
/*****************************************************************************
3
Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
17
*****************************************************************************/
19
/***********************************************************************
20
Comparison services for records
22
Created 7/1/1994 Heikki Tuuri
23
************************************************************************/
29
#include "data0data.h"
30
#include "data0type.h"
31
#include "dict0dict.h"
34
/*****************************************************************
35
Returns TRUE if two columns are equal for comparison purposes. */
40
/* out: TRUE if the columns are
41
considered equal in comparisons */
42
const dict_col_t* col1, /* in: column 1 */
43
const dict_col_t* col2, /* in: column 2 */
44
ibool check_charsets);
45
/* in: whether to check charsets */
46
/*****************************************************************
47
This function is used to compare two data fields for which we know the
53
/* out: 1, 0, -1, if data1 is greater, equal,
54
less than data2, respectively */
55
void* cmp_ctx,/* in: client compare context */
56
ulint mtype, /* in: main type */
57
ulint prtype, /* in: precise type */
58
const byte* data1, /* in: data field (== a pointer to a memory
60
ulint len1, /* in: data field length or UNIV_SQL_NULL */
61
const byte* data2, /* in: data field (== a pointer to a memory
63
ulint len2); /* in: data field length or UNIV_SQL_NULL */
64
/*****************************************************************
65
This function is used to compare two data fields for which we know the
71
/* out: 1, 0, -1, if data1 is greater, equal,
72
less than data2, respectively */
73
void* cmp_ctx,/* in: client compare context */
74
ulint mtype, /* in: main type */
75
ulint prtype, /* in: precise type */
76
const byte* data1, /* in: data field (== a pointer to a memory
78
ulint len1, /* in: data field length or UNIV_SQL_NULL */
79
const byte* data2, /* in: data field (== a pointer to a memory
81
ulint len2); /* in: data field length or UNIV_SQL_NULL */
82
/*****************************************************************
83
This function is used to compare two dfields where at least the first
84
has its data type field set. */
89
/* out: 1, 0, -1, if dfield1 is greater, equal,
90
less than dfield2, respectively */
91
void* cmp_ctx,/* in: client compare context */
92
const dfield_t* dfield1,/* in: data field; must have type field set */
93
const dfield_t* dfield2);/* in: data field */
94
/*****************************************************************
95
This function is used to compare a data tuple to a physical record.
96
Only dtuple->n_fields_cmp first fields are taken into account for
97
the the data tuple! If we denote by n = n_fields_cmp, then rec must
98
have either m >= n fields, or it must differ from dtuple in some of
99
the m fields rec has. If rec has an externally stored field we do not
100
compare it but return with value 0 if such a comparison should be
104
cmp_dtuple_rec_with_match(
105
/*======================*/
106
/* out: 1, 0, -1, if dtuple is greater, equal,
107
less than rec, respectively, when only the
108
common first fields are compared, or
109
until the first externally stored field in
111
void* cmp_ctx,/* in: client compare context */
112
const dtuple_t* dtuple, /* in: data tuple */
113
const rec_t* rec, /* in: physical record which differs from
114
dtuple in some of the common fields, or which
115
has an equal number or more fields than
117
const ulint* offsets,/* in: array returned by rec_get_offsets() */
118
ulint* matched_fields, /* in/out: number of already completely
119
matched fields; when function returns,
120
contains the value for current comparison */
121
ulint* matched_bytes); /* in/out: number of already matched
122
bytes within the first field not completely
123
matched; when function returns, contains the
124
value for current comparison */
125
/******************************************************************
126
Compares a data tuple to a physical record. */
131
/* out: 1, 0, -1, if dtuple is greater, equal,
132
less than rec, respectively; see the comments
133
for cmp_dtuple_rec_with_match */
134
void* cmp_ctx,/* in: client compare context */
135
const dtuple_t* dtuple, /* in: data tuple */
136
const rec_t* rec, /* in: physical record */
137
const ulint* offsets);/* in: array returned by rec_get_offsets() */
138
/******************************************************************
139
Checks if a dtuple is a prefix of a record. The last field in dtuple
140
is allowed to be a prefix of the corresponding field in the record. */
143
cmp_dtuple_is_prefix_of_rec(
144
/*========================*/
145
/* out: TRUE if prefix */
146
void* cmp_ctx,/* in: client compare context */
147
const dtuple_t* dtuple, /* in: data tuple */
148
const rec_t* rec, /* in: physical record */
149
const ulint* offsets);/* in: array returned by rec_get_offsets() */
150
/*****************************************************************
151
Compare two physical records that contain the same number of columns,
152
none of which are stored externally. */
157
/* out: 1, 0 , -1 if rec1 is greater,
158
equal, less, respectively, than rec2 */
159
const rec_t* rec1, /* in: physical record */
160
const rec_t* rec2, /* in: physical record */
161
const ulint* offsets1,/* in: rec_get_offsets(rec1, index) */
162
const ulint* offsets2,/* in: rec_get_offsets(rec2, index) */
163
const dict_index_t* index); /* in: data dictionary index */
164
/*****************************************************************
165
This function is used to compare two physical records. Only the common
166
first fields are compared, and if an externally stored field is
167
encountered, then 0 is returned. */
170
cmp_rec_rec_with_match(
171
/*===================*/
172
/* out: 1, 0 , -1 if rec1 is greater, equal,
173
less, respectively, than rec2; only the common
174
first fields are compared */
175
const rec_t* rec1, /* in: physical record */
176
const rec_t* rec2, /* in: physical record */
177
const ulint* offsets1,/* in: rec_get_offsets(rec1, index) */
178
const ulint* offsets2,/* in: rec_get_offsets(rec2, index) */
179
dict_index_t* index, /* in: data dictionary index */
180
ulint* matched_fields, /* in/out: number of already completely
181
matched fields; when the function returns,
182
contains the value the for current
184
ulint* matched_bytes);/* in/out: number of already matched
185
bytes within the first field not completely
186
matched; when the function returns, contains
187
the value for the current comparison */
188
/*****************************************************************
189
This function is used to compare two physical records. Only the common
190
first fields are compared. */
195
/* out: 1, 0 , -1 if rec1 is greater, equal,
196
less, respectively, than rec2; only the common
197
first fields are compared */
198
const rec_t* rec1, /* in: physical record */
199
const rec_t* rec2, /* in: physical record */
200
const ulint* offsets1,/* in: rec_get_offsets(rec1, index) */
201
const ulint* offsets2,/* in: rec_get_offsets(rec2, index) */
202
dict_index_t* index); /* in: data dictionary index */
206
#include "rem0cmp.ic"