646
646
/******************************************************************
647
647
Compares a data tuple to a physical record. */
652
652
/* out: 1, 0, -1, if dtuple is greater, equal,
653
653
less than rec, respectively; see the comments
654
654
for cmp_dtuple_rec_with_match */
655
const dtuple_t* dtuple, /* in: data tuple */
656
const rec_t* rec, /* in: physical record */
655
dtuple_t* dtuple, /* in: data tuple */
656
rec_t* rec, /* in: physical record */
657
657
const ulint* offsets)/* in: array returned by rec_get_offsets() */
659
659
ulint matched_fields = 0;
707
#ifndef UNIV_HOTBACKUP
708
/*****************************************************************
709
Compare two physical records that contain the same number of columns,
710
none of which are stored externally. */
715
/* out: 1, 0 , -1 if rec1 is greater,
716
equal, less, respectively, than rec2 */
717
const rec_t* rec1, /* in: physical record */
718
const rec_t* rec2, /* in: physical record */
719
const ulint* offsets1,/* in: rec_get_offsets(rec1, index) */
720
const ulint* offsets2,/* in: rec_get_offsets(rec2, index) */
721
const dict_index_t* index) /* in: data dictionary index */
723
ulint rec1_f_len; /* length of current field in rec1 */
724
const byte* rec1_b_ptr; /* pointer to the current byte
726
ulint rec1_byte; /* value of current byte to be
728
ulint rec2_f_len; /* length of current field in rec2 */
729
const byte* rec2_b_ptr; /* pointer to the current byte
731
ulint rec2_byte; /* value of current byte to be
733
ulint cur_field; /* current field number */
736
n_uniq = dict_index_get_n_unique(index);
737
ut_ad(rec_offs_n_fields(offsets1) >= n_uniq);
738
ut_ad(rec_offs_n_fields(offsets2) >= n_uniq);
740
ut_ad(rec_offs_comp(offsets1) == rec_offs_comp(offsets2));
742
for (cur_field = 0; cur_field < n_uniq; cur_field++) {
749
const dict_col_t* col
750
= dict_index_get_nth_col(index, cur_field);
753
prtype = col->prtype;
756
ut_ad(!rec_offs_nth_extern(offsets1, cur_field));
757
ut_ad(!rec_offs_nth_extern(offsets2, cur_field));
759
rec1_b_ptr = rec_get_nth_field(rec1, offsets1,
760
cur_field, &rec1_f_len);
761
rec2_b_ptr = rec_get_nth_field(rec2, offsets2,
762
cur_field, &rec2_f_len);
764
if (rec1_f_len == UNIV_SQL_NULL
765
|| rec2_f_len == UNIV_SQL_NULL) {
767
if (rec1_f_len == rec2_f_len) {
771
} else if (rec2_f_len == UNIV_SQL_NULL) {
773
/* We define the SQL null to be the
774
smallest possible value of a field
775
in the alphabetical order */
783
if (mtype >= DATA_FLOAT
784
|| (mtype == DATA_BLOB
785
&& 0 == (prtype & DATA_BINARY_TYPE)
786
&& dtype_get_charset_coll(prtype)
787
!= DATA_MYSQL_LATIN1_SWEDISH_CHARSET_COLL)) {
788
int ret = cmp_whole_field(mtype, prtype,
790
(unsigned) rec1_f_len,
792
(unsigned) rec2_f_len);
800
/* Compare the fields */
801
for (cur_bytes = 0;; cur_bytes++, rec1_b_ptr++, rec2_b_ptr++) {
802
if (rec2_f_len <= cur_bytes) {
804
if (rec1_f_len <= cur_bytes) {
809
rec2_byte = dtype_get_pad_char(mtype, prtype);
811
if (rec2_byte == ULINT_UNDEFINED) {
815
rec2_byte = *rec2_b_ptr;
818
if (rec1_f_len <= cur_bytes) {
819
rec1_byte = dtype_get_pad_char(mtype, prtype);
821
if (rec1_byte == ULINT_UNDEFINED) {
825
rec1_byte = *rec1_b_ptr;
828
if (rec1_byte == rec2_byte) {
829
/* If the bytes are equal, they will remain
830
such even after the collation transformation
836
if (mtype <= DATA_CHAR
837
|| (mtype == DATA_BLOB
838
&& !(prtype & DATA_BINARY_TYPE))) {
840
rec1_byte = cmp_collate(rec1_byte);
841
rec2_byte = cmp_collate(rec2_byte);
844
if (rec1_byte < rec2_byte) {
846
} else if (rec1_byte > rec2_byte) {
854
/* If we ran out of fields, rec1 was equal to rec2. */
857
#endif /* !UNIV_HOTBACKUP */
859
707
/*****************************************************************
860
708
This function is used to compare two physical records. Only the common
861
709
first fields are compared, and if an externally stored field is
862
710
encountered, then 0 is returned. */
865
713
cmp_rec_rec_with_match(
866
714
/*===================*/
867
715
/* out: 1, 0 , -1 if rec1 is greater, equal,
868
716
less, respectively, than rec2; only the common
869
717
first fields are compared */
870
const rec_t* rec1, /* in: physical record */
871
const rec_t* rec2, /* in: physical record */
718
rec_t* rec1, /* in: physical record */
719
rec_t* rec2, /* in: physical record */
872
720
const ulint* offsets1,/* in: rec_get_offsets(rec1, index) */
873
721
const ulint* offsets2,/* in: rec_get_offsets(rec2, index) */
874
722
dict_index_t* index, /* in: data dictionary index */
882
730
the value for the current comparison */
884
732
#ifndef UNIV_HOTBACKUP
885
ulint rec1_n_fields; /* the number of fields in rec */
886
ulint rec1_f_len; /* length of current field in rec */
887
const byte* rec1_b_ptr; /* pointer to the current byte
889
ulint rec1_byte; /* value of current byte to be
891
ulint rec2_n_fields; /* the number of fields in rec */
892
ulint rec2_f_len; /* length of current field in rec */
893
const byte* rec2_b_ptr; /* pointer to the current byte
895
ulint rec2_byte; /* value of current byte to be
897
ulint cur_field; /* current field number */
898
ulint cur_bytes; /* number of already matched
899
bytes in current field */
900
int ret = 0; /* return value */
733
ulint rec1_n_fields; /* the number of fields in rec */
734
ulint rec1_f_len; /* length of current field in rec */
735
byte* rec1_b_ptr; /* pointer to the current byte in rec field */
736
ulint rec1_byte; /* value of current byte to be compared in
738
ulint rec2_n_fields; /* the number of fields in rec */
739
ulint rec2_f_len; /* length of current field in rec */
740
byte* rec2_b_ptr; /* pointer to the current byte in rec field */
741
ulint rec2_byte; /* value of current byte to be compared in
743
ulint cur_field; /* current field number */
744
ulint cur_bytes; /* number of already matched bytes in current
746
int ret = 3333; /* return value */
903
749
ut_ad(rec1 && rec2 && index);
904
750
ut_ad(rec_offs_validate(rec1, index, offsets1));
940
786
if (cur_field == 0) {
941
787
/* Test if rec is the predefined minimum
943
if (UNIV_UNLIKELY(rec_get_info_bits(rec1, comp)
944
& REC_INFO_MIN_REC_FLAG)) {
789
if (rec_get_info_bits(rec1, comp)
790
& REC_INFO_MIN_REC_FLAG) {
946
if (!(rec_get_info_bits(rec2, comp)
947
& REC_INFO_MIN_REC_FLAG)) {
792
if (rec_get_info_bits(rec2, comp)
793
& REC_INFO_MIN_REC_FLAG) {
951
799
goto order_resolved;
953
} else if (UNIV_UNLIKELY
954
(rec_get_info_bits(rec2, comp)
955
& REC_INFO_MIN_REC_FLAG)) {
801
} else if (rec_get_info_bits(rec2, comp)
802
& REC_INFO_MIN_REC_FLAG) {