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., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/*******************************************************************//**
1
/***********************************************************************
21
2
Comparison services for records
4
(c) 1994-1996 Innobase Oy
23
6
Created 7/1/1994 Heikki Tuuri
24
7
************************************************************************/
51
34
has more fields than the other. */
54
/*************************************************************//**
37
/*****************************************************************
55
38
Used in debug checking of cmp_dtuple_... .
56
39
This function is used to compare a data tuple to a physical record. If
57
40
dtuple has n fields then rec must have either m >= n fields, or it must
58
differ from dtuple in some of the m fields rec has.
59
@return 1, 0, -1, if dtuple is greater, equal, less than rec,
60
respectively, when only the common first fields are compared */
41
differ from dtuple in some of the m fields rec has. */
63
44
cmp_debug_dtuple_rec_with_match(
64
45
/*============================*/
65
const dtuple_t* dtuple, /*!< in: data tuple */
66
const rec_t* rec, /*!< in: physical record which differs from
46
/* out: 1, 0, -1, if dtuple is greater, equal,
47
less than rec, respectively, when only the
48
common first fields are compared */
49
const dtuple_t* dtuple, /* in: data tuple */
50
const rec_t* rec, /* in: physical record which differs from
67
51
dtuple in some of the common fields, or which
68
52
has an equal number or more fields than
70
const ulint* offsets,/*!< in: array returned by rec_get_offsets() */
71
ulint* matched_fields);/*!< in/out: number of already
54
const ulint* offsets,/* in: array returned by rec_get_offsets() */
55
ulint* matched_fields);/* in/out: number of already
72
56
completely matched fields; when function
73
57
returns, contains the value for current
75
59
#endif /* UNIV_DEBUG */
76
/*************************************************************//**
60
#ifndef UNIV_HOTBACKUP
61
/*****************************************************************
77
62
This function is used to compare two data fields for which the data type
78
63
is such that we must use MySQL code to compare them. The prototype here
79
must be a copy of the the one in ha_innobase.cc!
80
@return 1, 0, -1, if a is greater, equal, less than b, respectively */
64
must be a copy of the the one in ha_innobase.cc! */
83
67
innobase_mysql_cmp(
84
68
/*===============*/
85
int mysql_type, /*!< in: MySQL type */
86
uint charset_number, /*!< in: number of the charset */
87
const unsigned char* a, /*!< in: data field */
88
unsigned int a_length, /*!< in: data field length,
90
const unsigned char* b, /*!< in: data field */
91
unsigned int b_length); /*!< in: data field length,
93
/*********************************************************************//**
69
/* out: 1, 0, -1, if a is greater,
70
equal, less than b, respectively */
71
int mysql_type, /* in: MySQL type */
72
uint charset_number, /* in: number of the charset */
73
const unsigned char* a, /* in: data field */
74
unsigned int a_length, /* in: data field length,
76
const unsigned char* b, /* in: data field */
77
unsigned int b_length); /* in: data field length,
79
#endif /* !UNIV_HOTBACKUP */
80
/*************************************************************************
94
81
Transforms the character code so that it is ordered appropriately for the
95
82
language. This is only used for the latin1 char set. MySQL does the
96
comparisons for other char sets.
97
@return collation order position */
83
comparisons for other char sets. */
102
ulint code) /*!< in: code of a character stored in database record */
88
/* out: collation order position */
89
ulint code) /* in: code of a character stored in database record */
104
91
return((ulint) srv_latin1_ordering[code]);
107
/*************************************************************//**
108
Returns TRUE if two columns are equal for comparison purposes.
109
@return TRUE if the columns are considered equal in comparisons */
94
/*****************************************************************
95
Returns TRUE if two columns are equal for comparison purposes. */
112
98
cmp_cols_are_equal(
113
99
/*===============*/
114
const dict_col_t* col1, /*!< in: column 1 */
115
const dict_col_t* col2, /*!< in: column 2 */
100
/* out: TRUE if the columns are
101
considered equal in comparisons */
102
const dict_col_t* col1, /* in: column 1 */
103
const dict_col_t* col2, /* in: column 2 */
116
104
ibool check_charsets)
117
/*!< in: whether to check charsets */
105
/* in: whether to check charsets */
119
107
if (dtype_is_non_binary_string_type(col1->mtype, col1->prtype)
120
108
&& dtype_is_non_binary_string_type(col2->mtype, col2->prtype)) {
157
145
return(col1->mtype != DATA_INT || col1->len == col2->len);
160
/*************************************************************//**
148
#ifndef UNIV_HOTBACKUP
149
/*****************************************************************
161
150
Innobase uses this function to compare two data fields for which the data type
162
is such that we must compare whole fields or call MySQL to do the comparison
163
@return 1, 0, -1, if a is greater, equal, less than b, respectively */
151
is such that we must compare whole fields or call MySQL to do the comparison */
168
ulint mtype, /*!< in: main type */
169
ulint prtype, /*!< in: precise type */
170
const byte* a, /*!< in: data field */
171
unsigned int a_length, /*!< in: data field length,
156
/* out: 1, 0, -1, if a is greater,
157
equal, less than b, respectively */
158
ulint mtype, /* in: main type */
159
ulint prtype, /* in: precise type */
160
const byte* a, /* in: data field */
161
unsigned int a_length, /* in: data field length,
172
162
not UNIV_SQL_NULL */
173
const byte* b, /*!< in: data field */
174
unsigned int b_length) /*!< in: data field length,
163
const byte* b, /* in: data field */
164
unsigned int b_length) /* in: data field length,
175
165
not UNIV_SQL_NULL */
275
#endif /* !UNIV_HOTBACKUP */
286
/*************************************************************//**
277
/*****************************************************************
287
278
This function is used to compare two data fields for which we know the
289
@return 1, 0, -1, if data1 is greater, equal, less than data2, respectively */
292
282
cmp_data_data_slow(
293
283
/*===============*/
294
ulint mtype, /*!< in: main type */
295
ulint prtype, /*!< in: precise type */
296
const byte* data1, /*!< in: data field (== a pointer to a memory
298
ulint len1, /*!< in: data field length or UNIV_SQL_NULL */
299
const byte* data2, /*!< in: data field (== a pointer to a memory
301
ulint len2) /*!< in: data field length or UNIV_SQL_NULL */
284
/* out: 1, 0, -1, if data1 is greater, equal,
285
less than data2, respectively */
286
ulint mtype, /* in: main type */
287
ulint prtype, /* in: precise type */
288
const byte* data1, /* in: data field (== a pointer to a memory
290
ulint len1, /* in: data field length or UNIV_SQL_NULL */
291
const byte* data2, /* in: data field (== a pointer to a memory
293
ulint len2) /* in: data field length or UNIV_SQL_NULL */
295
#ifndef UNIV_HOTBACKUP
303
296
ulint data1_byte;
304
297
ulint data2_byte;
388
#else /* !UNIV_HOTBACKUP */
389
/* This function depends on MySQL code that is not included in
390
InnoDB Hot Backup builds. Besides, this function should never
391
be called in InnoDB Hot Backup. */
393
#endif /* !UNIV_HOTBACKUP */
398
/*************************************************************//**
397
/*****************************************************************
399
398
This function is used to compare a data tuple to a physical record.
400
399
Only dtuple->n_fields_cmp first fields are taken into account for
401
400
the the data tuple! If we denote by n = n_fields_cmp, then rec must
402
401
have either m >= n fields, or it must differ from dtuple in some of
403
402
the m fields rec has. If rec has an externally stored field we do not
404
403
compare it but return with value 0 if such a comparison should be
406
@return 1, 0, -1, if dtuple is greater, equal, less than rec,
407
respectively, when only the common first fields are compared, or until
408
the first externally stored field in rec */
411
407
cmp_dtuple_rec_with_match(
412
408
/*======================*/
413
const dtuple_t* dtuple, /*!< in: data tuple */
414
const rec_t* rec, /*!< in: physical record which differs from
409
/* out: 1, 0, -1, if dtuple is greater, equal,
410
less than rec, respectively, when only the
411
common first fields are compared, or
412
until the first externally stored field in
414
const dtuple_t* dtuple, /* in: data tuple */
415
const rec_t* rec, /* in: physical record which differs from
415
416
dtuple in some of the common fields, or which
416
417
has an equal number or more fields than
418
const ulint* offsets,/*!< in: array returned by rec_get_offsets() */
419
ulint* matched_fields, /*!< in/out: number of already completely
419
const ulint* offsets,/* in: array returned by rec_get_offsets() */
420
ulint* matched_fields, /* in/out: number of already completely
420
421
matched fields; when function returns,
421
422
contains the value for current comparison */
422
ulint* matched_bytes) /*!< in/out: number of already matched
423
ulint* matched_bytes) /* in/out: number of already matched
423
424
bytes within the first field not completely
424
425
matched; when function returns, contains the
425
426
value for current comparison */
428
#ifndef UNIV_HOTBACKUP
427
429
const dfield_t* dtuple_field; /* current field in logical record */
428
430
ulint dtuple_f_len; /* the length of the current field
429
431
in the logical record */
631
633
*matched_bytes = cur_bytes;
636
#else /* !UNIV_HOTBACKUP */
637
/* This function depends on MySQL code that is not included in
638
InnoDB Hot Backup builds. Besides, this function should never
639
be called in InnoDB Hot Backup. */
642
#endif /* !UNIV_HOTBACKUP */
636
/**************************************************************//**
637
Compares a data tuple to a physical record.
638
@see cmp_dtuple_rec_with_match
639
@return 1, 0, -1, if dtuple is greater, equal, less than rec, respectively */
645
/******************************************************************
646
Compares a data tuple to a physical record. */
644
const dtuple_t* dtuple, /*!< in: data tuple */
645
const rec_t* rec, /*!< in: physical record */
646
const ulint* offsets)/*!< in: array returned by rec_get_offsets() */
651
/* out: 1, 0, -1, if dtuple is greater, equal,
652
less than rec, respectively; see the comments
653
for cmp_dtuple_rec_with_match */
654
const dtuple_t* dtuple, /* in: data tuple */
655
const rec_t* rec, /* in: physical record */
656
const ulint* offsets)/* in: array returned by rec_get_offsets() */
648
658
ulint matched_fields = 0;
649
659
ulint matched_bytes = 0;
653
663
&matched_fields, &matched_bytes));
656
/**************************************************************//**
666
/******************************************************************
657
667
Checks if a dtuple is a prefix of a record. The last field in dtuple
658
is allowed to be a prefix of the corresponding field in the record.
659
@return TRUE if prefix */
668
is allowed to be a prefix of the corresponding field in the record. */
662
671
cmp_dtuple_is_prefix_of_rec(
663
672
/*========================*/
664
const dtuple_t* dtuple, /*!< in: data tuple */
665
const rec_t* rec, /*!< in: physical record */
666
const ulint* offsets)/*!< in: array returned by rec_get_offsets() */
673
/* out: TRUE if prefix */
674
const dtuple_t* dtuple, /* in: data tuple */
675
const rec_t* rec, /* in: physical record */
676
const ulint* offsets)/* in: array returned by rec_get_offsets() */
669
679
ulint matched_fields = 0;
696
/*************************************************************//**
706
#ifndef UNIV_HOTBACKUP
707
/*****************************************************************
697
708
Compare two physical records that contain the same number of columns,
698
none of which are stored externally.
699
@return 1, 0, -1 if rec1 is greater, equal, less, respectively, than rec2 */
709
none of which are stored externally. */
702
712
cmp_rec_rec_simple(
703
713
/*===============*/
704
const rec_t* rec1, /*!< in: physical record */
705
const rec_t* rec2, /*!< in: physical record */
706
const ulint* offsets1,/*!< in: rec_get_offsets(rec1, ...) */
707
const ulint* offsets2,/*!< in: rec_get_offsets(rec2, ...) */
708
const dict_index_t* index, /*!< in: data dictionary index */
709
ibool* null_eq)/*!< out: set to TRUE if
710
found matching null values */
714
/* out: 1, 0 , -1 if rec1 is greater,
715
equal, less, respectively, than rec2 */
716
const rec_t* rec1, /* in: physical record */
717
const rec_t* rec2, /* in: physical record */
718
const ulint* offsets1,/* in: rec_get_offsets(rec1, index) */
719
const ulint* offsets2,/* in: rec_get_offsets(rec2, index) */
720
const dict_index_t* index) /* in: data dictionary index */
712
ulint rec1_f_len; /*!< length of current field in rec1 */
713
const byte* rec1_b_ptr; /*!< pointer to the current byte
722
ulint rec1_f_len; /* length of current field in rec1 */
723
const byte* rec1_b_ptr; /* pointer to the current byte
715
ulint rec1_byte; /*!< value of current byte to be
725
ulint rec1_byte; /* value of current byte to be
716
726
compared in rec1 */
717
ulint rec2_f_len; /*!< length of current field in rec2 */
718
const byte* rec2_b_ptr; /*!< pointer to the current byte
727
ulint rec2_f_len; /* length of current field in rec2 */
728
const byte* rec2_b_ptr; /* pointer to the current byte
720
ulint rec2_byte; /*!< value of current byte to be
730
ulint rec2_byte; /* value of current byte to be
721
731
compared in rec2 */
722
ulint cur_field; /*!< current field number */
732
ulint cur_field; /* current field number */
725
735
n_uniq = dict_index_get_n_unique(index);
846
853
/* If we ran out of fields, rec1 was equal to rec2. */
856
#endif /* !UNIV_HOTBACKUP */
850
/*************************************************************//**
858
/*****************************************************************
851
859
This function is used to compare two physical records. Only the common
852
860
first fields are compared, and if an externally stored field is
853
encountered, then 0 is returned.
854
@return 1, 0, -1 if rec1 is greater, equal, less, respectively */
861
encountered, then 0 is returned. */
857
864
cmp_rec_rec_with_match(
858
865
/*===================*/
859
const rec_t* rec1, /*!< in: physical record */
860
const rec_t* rec2, /*!< in: physical record */
861
const ulint* offsets1,/*!< in: rec_get_offsets(rec1, index) */
862
const ulint* offsets2,/*!< in: rec_get_offsets(rec2, index) */
863
dict_index_t* index, /*!< in: data dictionary index */
864
ulint* matched_fields, /*!< in/out: number of already completely
866
/* out: 1, 0 , -1 if rec1 is greater, equal,
867
less, respectively, than rec2; only the common
868
first fields are compared */
869
const rec_t* rec1, /* in: physical record */
870
const rec_t* rec2, /* in: physical record */
871
const ulint* offsets1,/* in: rec_get_offsets(rec1, index) */
872
const ulint* offsets2,/* in: rec_get_offsets(rec2, index) */
873
dict_index_t* index, /* in: data dictionary index */
874
ulint* matched_fields, /* in/out: number of already completely
865
875
matched fields; when the function returns,
866
876
contains the value the for current
868
ulint* matched_bytes) /*!< in/out: number of already matched
878
ulint* matched_bytes) /* in/out: number of already matched
869
879
bytes within the first field not completely
870
880
matched; when the function returns, contains
871
881
the value for the current comparison */
883
#ifndef UNIV_HOTBACKUP
873
884
ulint rec1_n_fields; /* the number of fields in rec */
874
885
ulint rec1_f_len; /* length of current field in rec */
875
886
const byte* rec1_b_ptr; /* pointer to the current byte
1083
1094
*matched_bytes = cur_bytes;
1097
#else /* !UNIV_HOTBACKUP */
1098
/* This function depends on MySQL code that is not included in
1099
InnoDB Hot Backup builds. Besides, this function should never
1100
be called in InnoDB Hot Backup. */
1103
#endif /* !UNIV_HOTBACKUP */
1088
1106
#ifdef UNIV_DEBUG
1089
/*************************************************************//**
1107
/*****************************************************************
1090
1108
Used in debug checking of cmp_dtuple_... .
1091
1109
This function is used to compare a data tuple to a physical record. If
1092
1110
dtuple has n fields then rec must have either m >= n fields, or it must
1093
1111
differ from dtuple in some of the m fields rec has. If encounters an
1094
externally stored field, returns 0.
1095
@return 1, 0, -1, if dtuple is greater, equal, less than rec,
1096
respectively, when only the common first fields are compared */
1112
externally stored field, returns 0. */
1099
1115
cmp_debug_dtuple_rec_with_match(
1100
1116
/*============================*/
1101
const dtuple_t* dtuple, /*!< in: data tuple */
1102
const rec_t* rec, /*!< in: physical record which differs from
1117
/* out: 1, 0, -1, if dtuple is greater, equal,
1118
less than rec, respectively, when only the
1119
common first fields are compared */
1120
const dtuple_t* dtuple, /* in: data tuple */
1121
const rec_t* rec, /* in: physical record which differs from
1103
1122
dtuple in some of the common fields, or which
1104
1123
has an equal number or more fields than
1106
const ulint* offsets,/*!< in: array returned by rec_get_offsets() */
1107
ulint* matched_fields) /*!< in/out: number of already
1125
const ulint* offsets,/* in: array returned by rec_get_offsets() */
1126
ulint* matched_fields) /* in/out: number of already
1108
1127
completely matched fields; when function
1109
1128
returns, contains the value for current