65 cmp_debug_dtuple_rec_with_match(
74 ulint* matched_fields)
78 __attribute__((nonnull, warn_unused_result));
91 const unsigned char* a,
92 unsigned int a_length,
94 const unsigned char* b,
95 unsigned int b_length);
108 const unsigned char* a,
109 unsigned int a_length,
111 const unsigned char* b,
112 unsigned int b_length);
137 ibool check_charsets)
146 if (check_charsets) {
167 if (col1->
mtype == DATA_INT
168 && (col1->
prtype & DATA_UNSIGNED)
169 != (col2->
prtype & DATA_UNSIGNED)) {
178 return(col1->
mtype != DATA_INT || col1->
len == col2->
len);
192 unsigned int a_length,
195 unsigned int b_length)
208 for (; a_length && *a ==
' '; a++, a_length--) { }
209 for (; b_length && *b ==
' '; b++, b_length--) { }
222 }
else if (*b ==
'-') {
227 while (a_length > 0 && (*a ==
'+' || *a ==
'0')) {
231 while (b_length > 0 && (*b ==
'+' || *b ==
'0')) {
235 if (a_length != b_length) {
236 if (a_length < b_length) {
243 while (a_length > 0 && *a == *b) {
245 a++; b++; a_length--;
264 }
else if (d_2 > d_1) {
276 }
else if (f_2 > f_1) {
282 if (prtype & DATA_BINARY_TYPE) {
286 " InnoDB: Error: comparing a binary BLOB"
287 " with a character set sensitive\n"
288 "InnoDB: comparison!\n");
294 (
int)(prtype & DATA_MYSQL_TYPE_MASK),
296 a, a_length, b, b_length));
299 "InnoDB: unknown type number %lu\n",
312 cmp_dfield_dfield_like_prefix(
324 type = dfield_get_type(dfield1);
326 if (type->
mtype >= DATA_FLOAT) {
328 (
int)(type->
prtype & DATA_MYSQL_TYPE_MASK),
330 static_cast<byte*>(dfield_get_data(dfield1)),
332 static_cast<byte*>(dfield_get_data(dfield2)),
335 ret = (cmp_data_data_like_prefix(
336 static_cast<byte*>(dfield_get_data(dfield1)),
338 static_cast<byte*>(dfield_get_data(dfield2)),
366 if (len1 == UNIV_SQL_NULL || len2 == UNIV_SQL_NULL) {
373 if (len1 == UNIV_SQL_NULL) {
383 if (mtype >= DATA_FLOAT
384 || (mtype == DATA_BLOB
385 && 0 == (prtype & DATA_BINARY_TYPE)
387 != DATA_MYSQL_LATIN1_SWEDISH_CHARSET_COLL)) {
389 return(cmp_whole_field(mtype, prtype,
390 data1, (
unsigned) len1,
391 data2, (
unsigned) len2));
399 if (len1 <= cur_bytes) {
400 if (len2 <= cur_bytes) {
407 if (data1_byte == ULINT_UNDEFINED) {
415 if (len2 <= cur_bytes) {
418 if (data2_byte == ULINT_UNDEFINED) {
426 if (data1_byte == data2_byte) {
433 if (mtype <= DATA_CHAR
434 || (mtype == DATA_BLOB
435 && 0 == (prtype & DATA_BINARY_TYPE))) {
441 if (data1_byte > data2_byte) {
444 }
else if (data1_byte < data2_byte) {
463 cmp_data_data_slow_varchar(
476 ut_a(rhs_len != UNIV_SQL_NULL);
478 if (lhs_len == UNIV_SQL_NULL) {
488 for (i = 0; i < lhs_len && i < rhs_len; ++
i, ++rhs, ++lhs) {
489 ulint lhs_byte = *lhs;
490 ulint rhs_byte = *rhs;
492 if (lhs_byte != rhs_byte) {
499 if (lhs_byte > rhs_byte) {
502 }
else if (lhs_byte < rhs_byte) {
509 return(i == lhs_len && i == rhs_len) ? 0 : rhs_len - lhs_len;
517 cmp_data_data_slow_like_prefix(
530 ut_a(len2 != UNIV_SQL_NULL);
532 if (len1 == UNIV_SQL_NULL) {
542 for (i = 0; i < len1 && i < len2; ++
i, ++rhs, ++lhs) {
543 ulint lhs_byte = *lhs;
544 ulint rhs_byte = *rhs;
546 if (lhs_byte != rhs_byte) {
553 if (lhs_byte > rhs_byte) {
556 }
else if (lhs_byte < rhs_byte) {
563 return(i == len2 ? 0 : 1);
571 cmp_data_data_slow_like_suffix(
577 const byte* data1 UNIV_UNUSED,
579 ulint len1 UNIV_UNUSED,
582 const byte* data2 UNIV_UNUSED,
584 ulint len2 UNIV_UNUSED)
596 cmp_data_data_slow_like_substr(
602 const byte* data1 UNIV_UNUSED,
604 ulint len1 UNIV_UNUSED,
607 const byte* data2 UNIV_UNUSED,
609 ulint len2 UNIV_UNUSED)
636 ulint* matched_fields,
639 ulint* matched_bytes)
647 const byte* dtuple_b_ptr;
652 const byte* rec_b_ptr;
661 ut_ad(dtuple && rec && matched_fields && matched_bytes);
663 ut_ad(rec_offs_validate(rec, NULL, offsets));
665 cur_field = *matched_fields;
666 cur_bytes = *matched_bytes;
670 ut_ad(cur_field <= n_cmp);
673 if (cur_bytes == 0 && cur_field == 0) {
678 if (UNIV_UNLIKELY(rec_info & REC_INFO_MIN_REC_FLAG)) {
679 ret = !(tup_info & REC_INFO_MIN_REC_FLAG);
681 }
else if (UNIV_UNLIKELY(tup_info & REC_INFO_MIN_REC_FLAG)) {
690 while (cur_field < n_cmp) {
695 dtuple_field = dtuple_get_nth_field(dtuple, cur_field);
698 = dfield_get_type(dtuple_field);
706 rec_b_ptr = rec_get_nth_field(rec, offsets,
707 cur_field, &rec_f_len);
714 if (UNIV_LIKELY(cur_bytes == 0)) {
724 if (dtuple_f_len == UNIV_SQL_NULL) {
725 if (rec_f_len == UNIV_SQL_NULL) {
732 }
else if (rec_f_len == UNIV_SQL_NULL) {
742 if (mtype >= DATA_FLOAT
743 || (mtype == DATA_BLOB
744 && 0 == (prtype & DATA_BINARY_TYPE)
746 != DATA_MYSQL_LATIN1_SWEDISH_CHARSET_COLL)) {
748 ret = cmp_whole_field(
750 static_cast<const byte*>(
751 dfield_get_data(dtuple_field)),
752 (
unsigned) dtuple_f_len,
753 rec_b_ptr, (
unsigned) rec_f_len);
766 rec_b_ptr = rec_b_ptr + cur_bytes;
767 dtuple_b_ptr = (byte*) dfield_get_data(dtuple_field)
772 if (UNIV_UNLIKELY(rec_f_len <= cur_bytes)) {
773 if (dtuple_f_len <= cur_bytes) {
780 if (rec_byte == ULINT_UNDEFINED) {
786 rec_byte = *rec_b_ptr;
789 if (UNIV_UNLIKELY(dtuple_f_len <= cur_bytes)) {
793 if (dtuple_byte == ULINT_UNDEFINED) {
799 dtuple_byte = *dtuple_b_ptr;
802 if (dtuple_byte == rec_byte) {
810 if (mtype <= DATA_CHAR
811 || (mtype == DATA_BLOB
812 && !(prtype & DATA_BINARY_TYPE))) {
818 ret = (int) (dtuple_byte - rec_byte);
819 if (UNIV_LIKELY(ret)) {
840 ut_ad(cur_bytes == 0);
845 ut_ad((ret >= - 1) && (ret <= 1));
846 ut_ad(ret == cmp_debug_dtuple_rec_with_match(dtuple, rec, offsets,
847 n_cmp, matched_fields));
848 ut_ad(*matched_fields == cur_field);
851 *matched_fields = cur_field;
852 *matched_bytes = cur_bytes;
869 ulint matched_fields = 0;
870 ulint matched_bytes = 0;
872 ut_ad(rec_offs_validate(rec, NULL, offsets));
873 return(cmp_dtuple_rec_with_match(dtuple, rec, offsets,
874 &matched_fields, &matched_bytes));
890 ulint matched_fields = 0;
891 ulint matched_bytes = 0;
893 ut_ad(rec_offs_validate(rec, NULL, offsets));
901 cmp_dtuple_rec_with_match(dtuple, rec, offsets,
902 &matched_fields, &matched_bytes);
903 if (matched_fields == n_fields) {
908 if (matched_fields == n_fields - 1
910 dtuple_get_nth_field(dtuple, n_fields - 1))) {
922 static __attribute__((nonnull, warn_unused_result))
924 cmp_rec_rec_simple_field(
933 const byte* rec1_b_ptr;
934 const byte* rec2_b_ptr;
942 rec1_b_ptr = rec_get_nth_field(rec1, offsets1, n, &rec1_f_len);
943 rec2_b_ptr = rec_get_nth_field(rec2, offsets2, n, &rec2_f_len);
945 if (rec1_f_len == UNIV_SQL_NULL || rec2_f_len == UNIV_SQL_NULL) {
946 if (rec1_f_len == rec2_f_len) {
951 return(rec1_f_len == UNIV_SQL_NULL ? -1 : 1);
954 if (col->
mtype >= DATA_FLOAT
955 || (col->
mtype == DATA_BLOB
956 && !(col->
prtype & DATA_BINARY_TYPE)
958 != DATA_MYSQL_LATIN1_SWEDISH_CHARSET_COLL)) {
960 rec1_b_ptr, (
unsigned) rec1_f_len,
961 rec2_b_ptr, (
unsigned) rec2_f_len));
965 for (ulint cur_bytes = 0;; cur_bytes++, rec1_b_ptr++, rec2_b_ptr++) {
969 if (rec2_f_len <= cur_bytes) {
970 if (rec1_f_len <= cur_bytes) {
977 if (rec2_byte == ULINT_UNDEFINED) {
981 rec2_byte = *rec2_b_ptr;
984 if (rec1_f_len <= cur_bytes) {
988 if (rec1_byte == ULINT_UNDEFINED) {
992 rec1_byte = *rec1_b_ptr;
995 if (rec1_byte == rec2_byte) {
1001 if (col->
mtype <= DATA_CHAR
1002 || (col->
mtype == DATA_BLOB
1003 && !(col->
prtype & DATA_BINARY_TYPE))) {
1009 if (rec1_byte < rec2_byte) {
1011 }
else if (rec1_byte > rec2_byte) {
1038 bool null_eq =
false;
1045 for (n = 0; n < n_uniq; n++) {
1046 int cmp = cmp_rec_rec_simple_field(
1047 rec1, rec2, offsets1, offsets2, index, n);
1077 int cmp = cmp_rec_rec_simple_field(
1078 rec1, rec2, offsets1, offsets2, index, n);
1107 const ulint* offsets1,
1108 const ulint* offsets2,
1110 ibool nulls_unequal,
1114 ulint* matched_fields,
1118 ulint* matched_bytes)
1123 ulint rec1_n_fields;
1125 const byte* rec1_b_ptr;
1129 ulint rec2_n_fields;
1131 const byte* rec2_b_ptr;
1141 ut_ad(rec1 && rec2 && index);
1142 ut_ad(rec_offs_validate(rec1, index, offsets1));
1143 ut_ad(rec_offs_validate(rec2, index, offsets2));
1150 cur_field = *matched_fields;
1151 cur_bytes = *matched_bytes;
1155 while ((cur_field < rec1_n_fields) && (cur_field < rec2_n_fields)) {
1160 if (dict_index_is_univ(index)) {
1162 mtype = DATA_BINARY;
1172 rec1_b_ptr = rec_get_nth_field(rec1, offsets1,
1173 cur_field, &rec1_f_len);
1174 rec2_b_ptr = rec_get_nth_field(rec2, offsets2,
1175 cur_field, &rec2_f_len);
1177 if (cur_bytes == 0) {
1178 if (cur_field == 0) {
1182 & REC_INFO_MIN_REC_FLAG)) {
1185 & REC_INFO_MIN_REC_FLAG)) {
1189 goto order_resolved;
1191 }
else if (UNIV_UNLIKELY
1193 & REC_INFO_MIN_REC_FLAG)) {
1197 goto order_resolved;
1206 goto order_resolved;
1209 if (rec1_f_len == UNIV_SQL_NULL
1210 || rec2_f_len == UNIV_SQL_NULL) {
1212 if (rec1_f_len == rec2_f_len) {
1215 if (nulls_unequal) {
1220 }
else if (rec2_f_len == UNIV_SQL_NULL) {
1231 goto order_resolved;
1235 if (mtype >= DATA_FLOAT
1236 || (mtype == DATA_BLOB
1237 && 0 == (prtype & DATA_BINARY_TYPE)
1239 != DATA_MYSQL_LATIN1_SWEDISH_CHARSET_COLL)) {
1241 ret = cmp_whole_field(mtype, prtype,
1243 (
unsigned) rec1_f_len,
1245 (
unsigned) rec2_f_len);
1249 goto order_resolved;
1256 rec1_b_ptr = rec1_b_ptr + cur_bytes;
1257 rec2_b_ptr = rec2_b_ptr + cur_bytes;
1261 if (rec2_f_len <= cur_bytes) {
1263 if (rec1_f_len <= cur_bytes) {
1270 if (rec2_byte == ULINT_UNDEFINED) {
1273 goto order_resolved;
1276 rec2_byte = *rec2_b_ptr;
1279 if (rec1_f_len <= cur_bytes) {
1282 if (rec1_byte == ULINT_UNDEFINED) {
1285 goto order_resolved;
1288 rec1_byte = *rec1_b_ptr;
1291 if (rec1_byte == rec2_byte) {
1299 if (mtype <= DATA_CHAR
1300 || (mtype == DATA_BLOB
1301 && !(prtype & DATA_BINARY_TYPE))) {
1307 if (rec1_byte < rec2_byte) {
1309 goto order_resolved;
1310 }
else if (rec1_byte > rec2_byte) {
1312 goto order_resolved;
1327 ut_ad(cur_bytes == 0);
1334 ut_ad((ret >= - 1) && (ret <= 1));
1336 *matched_fields = cur_field;
1337 *matched_bytes = cur_bytes;
1353 cmp_debug_dtuple_rec_with_match(
1362 ulint* matched_fields)
1370 const byte* dtuple_f_data;
1373 const byte* rec_f_data;
1377 ut_ad(dtuple && rec && matched_fields);
1379 ut_ad(rec_offs_validate(rec, NULL, offsets));
1383 ut_ad(*matched_fields <= n_cmp);
1386 cur_field = *matched_fields;
1388 if (cur_field == 0) {
1391 & REC_INFO_MIN_REC_FLAG)) {
1394 & REC_INFO_MIN_REC_FLAG);
1396 goto order_resolved;
1403 goto order_resolved;
1409 while (cur_field < n_cmp) {
1414 dtuple_field = dtuple_get_nth_field(dtuple, cur_field);
1417 = dfield_get_type(dtuple_field);
1419 mtype = type->
mtype;
1423 dtuple_f_data =
static_cast<const byte*
>(
1424 dfield_get_data(dtuple_field));
1428 rec_f_data = rec_get_nth_field(rec, offsets,
1429 cur_field, &rec_f_len);
1436 goto order_resolved;
1439 ret =
cmp_data_data(mtype, prtype, dtuple_f_data, dtuple_f_len,
1440 rec_f_data, rec_f_len);
1442 goto order_resolved;
1451 ut_ad((ret >= - 1) && (ret <= 1));
1453 *matched_fields = cur_field;