~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/rem/rem0cmp.c

  • Committer: Eric Day
  • Date: 2009-10-31 21:53:33 UTC
  • mfrom: (1200 staging)
  • mto: This revision was merged to the branch mainline in revision 1202.
  • Revision ID: eday@oddments.org-20091031215333-j94bjoanwmi68p6f
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
*****************************************************************************/
18
18
 
19
 
/***********************************************************************
 
19
/*******************************************************************//**
 
20
@file rem/rem0cmp.c
20
21
Comparison services for records
21
22
 
22
23
Created 7/1/1994 Heikki Tuuri
50
51
has more fields than the other. */
51
52
 
52
53
#ifdef UNIV_DEBUG
53
 
/*****************************************************************
 
54
/*************************************************************//**
54
55
Used in debug checking of cmp_dtuple_... .
55
56
This function is used to compare a data tuple to a physical record. If
56
57
dtuple has n fields then rec must have either m >= n fields, or it must
57
 
differ from dtuple in some of the m fields rec has. */
 
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 */
58
61
static
59
62
int
60
63
cmp_debug_dtuple_rec_with_match(
61
64
/*============================*/
62
 
                                /* out: 1, 0, -1, if dtuple is greater, equal,
63
 
                                less than rec, respectively, when only the
64
 
                                common first fields are compared */
65
 
        const dtuple_t* dtuple, /* in: data tuple */
66
 
        const rec_t*    rec,    /* in: physical record which differs from
 
65
        const dtuple_t* dtuple, /*!< in: data tuple */
 
66
        const rec_t*    rec,    /*!< in: physical record which differs from
67
67
                                dtuple in some of the common fields, or which
68
68
                                has an equal number or more fields than
69
69
                                dtuple */
70
 
        const ulint*    offsets,/* in: array returned by rec_get_offsets() */
71
 
        ulint*          matched_fields);/* in/out: number of already
 
70
        const ulint*    offsets,/*!< in: array returned by rec_get_offsets() */
 
71
        ulint*          matched_fields);/*!< in/out: number of already
72
72
                                completely  matched fields; when function
73
73
                                returns, contains the value for current
74
74
                                comparison */
75
75
#endif /* UNIV_DEBUG */
76
 
#ifndef UNIV_HOTBACKUP
77
 
/*****************************************************************
 
76
/*************************************************************//**
78
77
This function is used to compare two data fields for which the data type
79
78
is such that we must use MySQL code to compare them. The prototype here
80
 
must be a copy of the the one in ha_innobase.cc! */
 
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 */
81
81
extern
82
82
int
83
83
innobase_mysql_cmp(
84
84
/*===============*/
85
 
                                        /* out: 1, 0, -1, if a is greater,
86
 
                                        equal, less than b, respectively */
87
 
        int             mysql_type,     /* in: MySQL type */
88
 
        uint            charset_number, /* in: number of the charset */
89
 
        const unsigned char* a,         /* in: data field */
90
 
        unsigned int    a_length,       /* in: data field length,
91
 
                                        not UNIV_SQL_NULL */
92
 
        const unsigned char* b,         /* in: data field */
93
 
        unsigned int    b_length);      /* in: data field length,
94
 
                                        not UNIV_SQL_NULL */
95
 
#endif /* !UNIV_HOTBACKUP */
96
 
/*************************************************************************
 
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,
 
89
                                        not UNIV_SQL_NULL */
 
90
        const unsigned char* b,         /*!< in: data field */
 
91
        unsigned int    b_length);      /*!< in: data field length,
 
92
                                        not UNIV_SQL_NULL */
 
93
/*********************************************************************//**
97
94
Transforms the character code so that it is ordered appropriately for the
98
95
language. This is only used for the latin1 char set. MySQL does the
99
 
comparisons for other char sets. */
 
96
comparisons for other char sets.
 
97
@return collation order position */
100
98
UNIV_INLINE
101
99
ulint
102
100
cmp_collate(
103
101
/*========*/
104
 
                        /* out: collation order position */
105
 
        ulint   code)   /* in: code of a character stored in database record */
 
102
        ulint   code)   /*!< in: code of a character stored in database record */
106
103
{
107
104
        return((ulint) srv_latin1_ordering[code]);
108
105
}
109
106
 
110
 
/*****************************************************************
111
 
Returns TRUE if two columns are equal for comparison purposes. */
 
107
/*************************************************************//**
 
108
Returns TRUE if two columns are equal for comparison purposes.
 
109
@return TRUE if the columns are considered equal in comparisons */
112
110
UNIV_INTERN
113
111
ibool
114
112
cmp_cols_are_equal(
115
113
/*===============*/
116
 
                                        /* out: TRUE if the columns are
117
 
                                        considered equal in comparisons */
118
 
        const dict_col_t*       col1,   /* in: column 1 */
119
 
        const dict_col_t*       col2,   /* in: column 2 */
 
114
        const dict_col_t*       col1,   /*!< in: column 1 */
 
115
        const dict_col_t*       col2,   /*!< in: column 2 */
120
116
        ibool                   check_charsets)
121
 
                                        /* in: whether to check charsets */
 
117
                                        /*!< in: whether to check charsets */
122
118
{
123
119
        if (dtype_is_non_binary_string_type(col1->mtype, col1->prtype)
124
120
            && dtype_is_non_binary_string_type(col2->mtype, col2->prtype)) {
161
157
        return(col1->mtype != DATA_INT || col1->len == col2->len);
162
158
}
163
159
 
164
 
#ifndef UNIV_HOTBACKUP
165
 
/*****************************************************************
 
160
/*************************************************************//**
166
161
Innobase uses this function to compare two data fields for which the data type
167
 
is such that we must compare whole fields or call MySQL to do the comparison */
 
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 */
168
164
static
169
165
int
170
166
cmp_whole_field(
171
167
/*============*/
172
 
                                        /* out: 1, 0, -1, if a is greater,
173
 
                                        equal, less than b, respectively */
174
 
        ulint           mtype,          /* in: main type */
175
 
        ulint           prtype,         /* in: precise type */
176
 
        const byte*     a,              /* in: data field */
177
 
        unsigned int    a_length,       /* in: data field length,
 
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,
178
172
                                        not UNIV_SQL_NULL */
179
 
        const byte*     b,              /* in: data field */
180
 
        unsigned int    b_length)       /* in: data field length,
 
173
        const byte*     b,              /*!< in: data field */
 
174
        unsigned int    b_length)       /*!< in: data field length,
181
175
                                        not UNIV_SQL_NULL */
182
176
{
183
177
        float           f_1;
288
282
 
289
283
        return(0);
290
284
}
291
 
#endif /* !UNIV_HOTBACKUP */
292
285
 
293
 
/*****************************************************************
 
286
/*************************************************************//**
294
287
This function is used to compare two data fields for which we know the
295
 
data type. */
 
288
data type.
 
289
@return 1, 0, -1, if data1 is greater, equal, less than data2, respectively */
296
290
UNIV_INTERN
297
291
int
298
292
cmp_data_data_slow(
299
293
/*===============*/
300
 
                                /* out: 1, 0, -1, if data1 is greater, equal,
301
 
                                less than data2, respectively */
302
 
        ulint           mtype,  /* in: main type */
303
 
        ulint           prtype, /* in: precise type */
304
 
        const byte*     data1,  /* in: data field (== a pointer to a memory
305
 
                                buffer) */
306
 
        ulint           len1,   /* in: data field length or UNIV_SQL_NULL */
307
 
        const byte*     data2,  /* in: data field (== a pointer to a memory
308
 
                                buffer) */
309
 
        ulint           len2)   /* in: data field length or UNIV_SQL_NULL */
 
294
        ulint           mtype,  /*!< in: main type */
 
295
        ulint           prtype, /*!< in: precise type */
 
296
        const byte*     data1,  /*!< in: data field (== a pointer to a memory
 
297
                                buffer) */
 
298
        ulint           len1,   /*!< in: data field length or UNIV_SQL_NULL */
 
299
        const byte*     data2,  /*!< in: data field (== a pointer to a memory
 
300
                                buffer) */
 
301
        ulint           len2)   /*!< in: data field length or UNIV_SQL_NULL */
310
302
{
311
 
#ifndef UNIV_HOTBACKUP
312
303
        ulint   data1_byte;
313
304
        ulint   data2_byte;
314
305
        ulint   cur_bytes;
401
392
                data1++;
402
393
                data2++;
403
394
        }
404
 
#else /* !UNIV_HOTBACKUP */
405
 
        /* This function depends on MySQL code that is not included in
406
 
        InnoDB Hot Backup builds.  Besides, this function should never
407
 
        be called in InnoDB Hot Backup. */
408
 
        ut_error;
409
 
#endif /* !UNIV_HOTBACKUP */
410
395
 
411
396
}
412
397
 
413
 
/*****************************************************************
 
398
/*************************************************************//**
414
399
This function is used to compare a data tuple to a physical record.
415
400
Only dtuple->n_fields_cmp first fields are taken into account for
416
401
the the data tuple! If we denote by n = n_fields_cmp, then rec must
417
402
have either m >= n fields, or it must differ from dtuple in some of
418
403
the m fields rec has. If rec has an externally stored field we do not
419
404
compare it but return with value 0 if such a comparison should be
420
 
made. */
 
405
made.
 
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 */
421
409
UNIV_INTERN
422
410
int
423
411
cmp_dtuple_rec_with_match(
424
412
/*======================*/
425
 
                                /* out: 1, 0, -1, if dtuple is greater, equal,
426
 
                                less than rec, respectively, when only the
427
 
                                common first fields are compared, or
428
 
                                until the first externally stored field in
429
 
                                rec */
430
 
        const dtuple_t* dtuple, /* in: data tuple */
431
 
        const rec_t*    rec,    /* in: physical record which differs from
 
413
        const dtuple_t* dtuple, /*!< in: data tuple */
 
414
        const rec_t*    rec,    /*!< in: physical record which differs from
432
415
                                dtuple in some of the common fields, or which
433
416
                                has an equal number or more fields than
434
417
                                dtuple */
435
 
        const ulint*    offsets,/* in: array returned by rec_get_offsets() */
436
 
        ulint*          matched_fields, /* in/out: number of already completely
 
418
        const ulint*    offsets,/*!< in: array returned by rec_get_offsets() */
 
419
        ulint*          matched_fields, /*!< in/out: number of already completely
437
420
                                matched fields; when function returns,
438
421
                                contains the value for current comparison */
439
 
        ulint*          matched_bytes) /* in/out: number of already matched
 
422
        ulint*          matched_bytes) /*!< in/out: number of already matched
440
423
                                bytes within the first field not completely
441
424
                                matched; when function returns, contains the
442
425
                                value for current comparison */
443
426
{
444
 
#ifndef UNIV_HOTBACKUP
445
427
        const dfield_t* dtuple_field;   /* current field in logical record */
446
428
        ulint           dtuple_f_len;   /* the length of the current field
447
429
                                        in the logical record */
649
631
        *matched_bytes = cur_bytes;
650
632
 
651
633
        return(ret);
652
 
#else /* !UNIV_HOTBACKUP */
653
 
        /* This function depends on MySQL code that is not included in
654
 
        InnoDB Hot Backup builds.  Besides, this function should never
655
 
        be called in InnoDB Hot Backup. */
656
 
        ut_error;
657
 
        return(0);
658
 
#endif /* !UNIV_HOTBACKUP */
659
634
}
660
635
 
661
 
/******************************************************************
662
 
Compares a data tuple to a physical record. */
 
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 */
663
640
UNIV_INTERN
664
641
int
665
642
cmp_dtuple_rec(
666
643
/*===========*/
667
 
                                /* out: 1, 0, -1, if dtuple is greater, equal,
668
 
                                less than rec, respectively; see the comments
669
 
                                for cmp_dtuple_rec_with_match */
670
 
        const dtuple_t* dtuple, /* in: data tuple */
671
 
        const rec_t*    rec,    /* in: physical record */
672
 
        const ulint*    offsets)/* in: array returned by rec_get_offsets() */
 
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() */
673
647
{
674
648
        ulint   matched_fields  = 0;
675
649
        ulint   matched_bytes   = 0;
679
653
                                         &matched_fields, &matched_bytes));
680
654
}
681
655
 
682
 
/******************************************************************
 
656
/**************************************************************//**
683
657
Checks if a dtuple is a prefix of a record. The last field in dtuple
684
 
is allowed to be a prefix of the corresponding field in the record. */
 
658
is allowed to be a prefix of the corresponding field in the record.
 
659
@return TRUE if prefix */
685
660
UNIV_INTERN
686
661
ibool
687
662
cmp_dtuple_is_prefix_of_rec(
688
663
/*========================*/
689
 
                                /* out: TRUE if prefix */
690
 
        const dtuple_t* dtuple, /* in: data tuple */
691
 
        const rec_t*    rec,    /* in: physical record */
692
 
        const ulint*    offsets)/* in: array returned by rec_get_offsets() */
 
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() */
693
667
{
694
668
        ulint   n_fields;
695
669
        ulint   matched_fields  = 0;
719
693
        return(FALSE);
720
694
}
721
695
 
722
 
#ifndef UNIV_HOTBACKUP
723
 
/*****************************************************************
 
696
/*************************************************************//**
724
697
Compare two physical records that contain the same number of columns,
725
 
none of which are stored externally. */
 
698
none of which are stored externally.
 
699
@return 1, 0, -1 if rec1 is greater, equal, less, respectively, than rec2 */
726
700
UNIV_INTERN
727
701
int
728
702
cmp_rec_rec_simple(
729
703
/*===============*/
730
 
                                        /* out: 1, 0 , -1 if rec1 is greater,
731
 
                                        equal, less, respectively, than rec2 */
732
 
        const rec_t*            rec1,   /* in: physical record */
733
 
        const rec_t*            rec2,   /* in: physical record */
734
 
        const ulint*            offsets1,/* in: rec_get_offsets(rec1, index) */
735
 
        const ulint*            offsets2,/* in: rec_get_offsets(rec2, index) */
736
 
        const dict_index_t*     index)  /* in: data dictionary index */
 
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 */
737
709
{
738
 
        ulint           rec1_f_len;     /* length of current field in rec1 */
739
 
        const byte*     rec1_b_ptr;     /* pointer to the current byte
 
710
        ulint           rec1_f_len;     /*!< length of current field in rec1 */
 
711
        const byte*     rec1_b_ptr;     /*!< pointer to the current byte
740
712
                                        in rec1 field */
741
 
        ulint           rec1_byte;      /* value of current byte to be
 
713
        ulint           rec1_byte;      /*!< value of current byte to be
742
714
                                        compared in rec1 */
743
 
        ulint           rec2_f_len;     /* length of current field in rec2 */
744
 
        const byte*     rec2_b_ptr;     /* pointer to the current byte
 
715
        ulint           rec2_f_len;     /*!< length of current field in rec2 */
 
716
        const byte*     rec2_b_ptr;     /*!< pointer to the current byte
745
717
                                        in rec2 field */
746
 
        ulint           rec2_byte;      /* value of current byte to be
 
718
        ulint           rec2_byte;      /*!< value of current byte to be
747
719
                                        compared in rec2 */
748
 
        ulint           cur_field;      /* current field number */
 
720
        ulint           cur_field;      /*!< current field number */
749
721
        ulint           n_uniq;
750
722
 
751
723
        n_uniq = dict_index_get_n_unique(index);
869
841
        /* If we ran out of fields, rec1 was equal to rec2. */
870
842
        return(0);
871
843
}
872
 
#endif /* !UNIV_HOTBACKUP */
873
844
 
874
 
/*****************************************************************
 
845
/*************************************************************//**
875
846
This function is used to compare two physical records. Only the common
876
847
first fields are compared, and if an externally stored field is
877
 
encountered, then 0 is returned. */
 
848
encountered, then 0 is returned.
 
849
@return 1, 0, -1 if rec1 is greater, equal, less, respectively */
878
850
UNIV_INTERN
879
851
int
880
852
cmp_rec_rec_with_match(
881
853
/*===================*/
882
 
                                /* out: 1, 0 , -1 if rec1 is greater, equal,
883
 
                                less, respectively, than rec2; only the common
884
 
                                first fields are compared */
885
 
        const rec_t*    rec1,   /* in: physical record */
886
 
        const rec_t*    rec2,   /* in: physical record */
887
 
        const ulint*    offsets1,/* in: rec_get_offsets(rec1, index) */
888
 
        const ulint*    offsets2,/* in: rec_get_offsets(rec2, index) */
889
 
        dict_index_t*   index,  /* in: data dictionary index */
890
 
        ulint*          matched_fields, /* in/out: number of already completely
 
854
        const rec_t*    rec1,   /*!< in: physical record */
 
855
        const rec_t*    rec2,   /*!< in: physical record */
 
856
        const ulint*    offsets1,/*!< in: rec_get_offsets(rec1, index) */
 
857
        const ulint*    offsets2,/*!< in: rec_get_offsets(rec2, index) */
 
858
        dict_index_t*   index,  /*!< in: data dictionary index */
 
859
        ulint*          matched_fields, /*!< in/out: number of already completely
891
860
                                matched fields; when the function returns,
892
861
                                contains the value the for current
893
862
                                comparison */
894
 
        ulint*          matched_bytes) /* in/out: number of already matched
 
863
        ulint*          matched_bytes) /*!< in/out: number of already matched
895
864
                                bytes within the first field not completely
896
865
                                matched; when the function returns, contains
897
866
                                the value for the current comparison */
898
867
{
899
 
#ifndef UNIV_HOTBACKUP
900
868
        ulint           rec1_n_fields;  /* the number of fields in rec */
901
869
        ulint           rec1_f_len;     /* length of current field in rec */
902
870
        const byte*     rec1_b_ptr;     /* pointer to the current byte
1110
1078
        *matched_bytes = cur_bytes;
1111
1079
 
1112
1080
        return(ret);
1113
 
#else /* !UNIV_HOTBACKUP */
1114
 
        /* This function depends on MySQL code that is not included in
1115
 
        InnoDB Hot Backup builds.  Besides, this function should never
1116
 
        be called in InnoDB Hot Backup. */
1117
 
        ut_error;
1118
 
        return(0);
1119
 
#endif /* !UNIV_HOTBACKUP */
1120
1081
}
1121
1082
 
1122
1083
#ifdef UNIV_DEBUG
1123
 
/*****************************************************************
 
1084
/*************************************************************//**
1124
1085
Used in debug checking of cmp_dtuple_... .
1125
1086
This function is used to compare a data tuple to a physical record. If
1126
1087
dtuple has n fields then rec must have either m >= n fields, or it must
1127
1088
differ from dtuple in some of the m fields rec has. If encounters an
1128
 
externally stored field, returns 0. */
 
1089
externally stored field, returns 0.
 
1090
@return 1, 0, -1, if dtuple is greater, equal, less than rec,
 
1091
respectively, when only the common first fields are compared */
1129
1092
static
1130
1093
int
1131
1094
cmp_debug_dtuple_rec_with_match(
1132
1095
/*============================*/
1133
 
                                /* out: 1, 0, -1, if dtuple is greater, equal,
1134
 
                                less than rec, respectively, when only the
1135
 
                                common first fields are compared */
1136
 
        const dtuple_t* dtuple, /* in: data tuple */
1137
 
        const rec_t*    rec,    /* in: physical record which differs from
 
1096
        const dtuple_t* dtuple, /*!< in: data tuple */
 
1097
        const rec_t*    rec,    /*!< in: physical record which differs from
1138
1098
                                dtuple in some of the common fields, or which
1139
1099
                                has an equal number or more fields than
1140
1100
                                dtuple */
1141
 
        const ulint*    offsets,/* in: array returned by rec_get_offsets() */
1142
 
        ulint*          matched_fields) /* in/out: number of already
 
1101
        const ulint*    offsets,/*!< in: array returned by rec_get_offsets() */
 
1102
        ulint*          matched_fields) /*!< in/out: number of already
1143
1103
                                completely matched fields; when function
1144
1104
                                returns, contains the value for current
1145
1105
                                comparison */