|
1 | 1 | /***************************************************************************** |
2 | 2 |
|
3 | 3 | Copyright (c) 1997, 2016, Oracle and/or its affiliates. All Rights Reserved. |
4 | | -Copyright (c) 2016, 2019, MariaDB Corporation. |
| 4 | +Copyright (c) 2016, 2020, MariaDB Corporation. |
5 | 5 |
|
6 | 6 | This program is free software; you can redistribute it and/or modify it under |
7 | 7 | the terms of the GNU General Public License as published by the Free Software |
@@ -63,6 +63,7 @@ UNIV_INTERN my_bool srv_ibuf_disable_background_merge; |
63 | 63 | #include "que0que.h" |
64 | 64 | #include "srv0start.h" /* srv_shutdown_state */ |
65 | 65 | #include "ha_prototypes.h" |
| 66 | +#include "ut0crc32.h" |
66 | 67 | #include "rem0cmp.h" |
67 | 68 |
|
68 | 69 | /*STRUCTURE OF AN INSERT BUFFER RECORD |
@@ -2925,42 +2926,28 @@ ibuf_contract_after_insert( |
2925 | 2926 | } while (size > 0 && sum_sizes < entry_size); |
2926 | 2927 | } |
2927 | 2928 |
|
2928 | | -/*********************************************************************//** |
2929 | | -Determine if an insert buffer record has been encountered already. |
2930 | | -@return TRUE if a new record, FALSE if possible duplicate */ |
2931 | | -static |
2932 | | -ibool |
2933 | | -ibuf_get_volume_buffered_hash( |
2934 | | -/*==========================*/ |
2935 | | -const rec_t* rec,/*!< in: ibuf record in post-4.1 format */ |
2936 | | -const byte* types,/*!< in: fields */ |
2937 | | -const byte* data,/*!< in: start of user record data */ |
2938 | | -ulint comp,/*!< in: 0=ROW_FORMAT=REDUNDANT, |
2939 | | -nonzero=ROW_FORMAT=COMPACT */ |
2940 | | -ulint* hash,/*!< in/out: hash array */ |
2941 | | -ulint size)/*!< in: number of elements in hash array */ |
| 2929 | +/** Determine if a change buffer record has been encountered already. |
| 2930 | +@param rec change buffer record in the MySQL 5.5 format |
| 2931 | +@param hash hash table of encountered records |
| 2932 | +@param size number of elements in hash |
| 2933 | +@retval true if a distinct record |
| 2934 | +@retval false if this may be duplicating an earlier record */ |
| 2935 | +static bool ibuf_get_volume_buffered_hash(const rec_t *rec, ulint *hash, |
| 2936 | + ulint size) |
2942 | 2937 | { |
2943 | | -ulint len; |
2944 | | -ulint fold; |
2945 | | -ulint bitmask; |
2946 | | - |
2947 | | -len = ibuf_rec_get_size( |
2948 | | -rec, types, |
2949 | | -rec_get_n_fields_old(rec) - IBUF_REC_FIELD_USER, comp); |
2950 | | -fold = ut_fold_binary(data, len); |
2951 | | - |
2952 | | -hash += (fold / (CHAR_BIT * sizeof *hash)) % size; |
2953 | | -bitmask = static_cast<ulint>(1) << (fold % (CHAR_BIT * sizeof(*hash))); |
2954 | | - |
2955 | | -if (*hash & bitmask) { |
2956 | | - |
2957 | | -return(FALSE); |
2958 | | -} |
2959 | | - |
2960 | | -/* We have not seen this record yet. Insert it. */ |
2961 | | -*hash |= bitmask; |
2962 | | - |
2963 | | -return(TRUE); |
| 2938 | + ut_ad(rec_get_n_fields_old(rec) > IBUF_REC_FIELD_USER); |
| 2939 | + const ulint start= rec_get_field_start_offs(rec, IBUF_REC_FIELD_USER); |
| 2940 | + const ulint len= rec_get_data_size_old(rec) - start; |
| 2941 | + const uint32_t fold= ut_crc32(rec + start, len); |
| 2942 | + hash+= (fold / (CHAR_BIT * sizeof *hash)) % size; |
| 2943 | + ulint bitmask= static_cast<ulint>(1) << (fold % (CHAR_BIT * sizeof(*hash))); |
| 2944 | + |
| 2945 | + if (*hash & bitmask) |
| 2946 | + return false; |
| 2947 | + |
| 2948 | + /* We have not seen this record yet. Remember it. */ |
| 2949 | + *hash|= bitmask; |
| 2950 | + return true; |
2964 | 2951 | } |
2965 | 2952 |
|
2966 | 2953 | #ifdef UNIV_DEBUG |
@@ -3052,11 +3039,7 @@ ibuf_get_volume_buffered_count_func( |
3052 | 3039 | case IBUF_OP_DELETE_MARK: |
3053 | 3040 | /* There must be a record to delete-mark. |
3054 | 3041 | See if this record has been already buffered. */ |
3055 | | -if (n_recs && ibuf_get_volume_buffered_hash( |
3056 | | - rec, types + IBUF_REC_INFO_SIZE, |
3057 | | - types + len, |
3058 | | - types[IBUF_REC_OFFSET_FLAGS] & IBUF_REC_COMPACT, |
3059 | | - hash, size)) { |
| 3042 | +if (n_recs && ibuf_get_volume_buffered_hash(rec, hash, size)) { |
3060 | 3043 | (*n_recs)++; |
3061 | 3044 | } |
3062 | 3045 |
|
|
0 commit comments