diff options
Diffstat (limited to 'sql/key.cc')
-rw-r--r-- | sql/key.cc | 50 |
1 files changed, 18 insertions, 32 deletions
diff --git a/sql/key.cc b/sql/key.cc index 5a1b3573f6f..0eeb256dd87 100644 --- a/sql/key.cc +++ b/sql/key.cc @@ -1,4 +1,5 @@ /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2018, MariaDB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,9 +22,6 @@ #include "key.h" // key_rec_cmp #include "field.h" // Field -using std::min; -using std::max; - /* Search after a key that starts with 'field' @@ -54,8 +52,8 @@ using std::max; int find_ref_key(KEY *key, uint key_count, uchar *record, Field *field, uint *key_length, uint *keypart) { - reg2 int i; - reg3 KEY *key_info; + int i; + KEY *key_info; uint fieldpos; fieldpos= field->offset(record); @@ -137,7 +135,7 @@ void key_copy(uchar *to_key, uchar *from_record, KEY *key_info, Don't copy data for null values The -1 below is to subtract the null byte which is already handled */ - length= min<uint>(key_length, key_part->store_length-1); + length= MY_MIN(key_length, uint(key_part->store_length)-1); if (with_zerofill) bzero((char*) to_key, length); continue; @@ -147,7 +145,7 @@ void key_copy(uchar *to_key, uchar *from_record, KEY *key_info, key_part->key_part_flag & HA_VAR_LENGTH_PART) { key_length-= HA_KEY_BLOB_LENGTH; - length= min<uint>(key_length, key_part->length); + length= MY_MIN(key_length, key_part->length); uint bytes= key_part->field->get_key_image(to_key, length, key_info->flags & HA_SPATIAL ? Field::itMBR : Field::itRAW); if (with_zerofill && bytes < length) @@ -156,7 +154,7 @@ void key_copy(uchar *to_key, uchar *from_record, KEY *key_info, } else { - length= min<uint>(key_length, key_part->length); + length= MY_MIN(key_length, key_part->length); Field *field= key_part->field; CHARSET_INFO *cs= field->charset(); uint bytes= field->get_key_image(to_key, length, Field::itRAW); @@ -179,7 +177,7 @@ void key_copy(uchar *to_key, uchar *from_record, KEY *key_info, @param key_length specifies length of all keyparts that will be restored */ -void key_restore(uchar *to_record, uchar *from_key, KEY *key_info, +void key_restore(uchar *to_record, const uchar *from_key, KEY *key_info, uint key_length) { uint length; @@ -208,7 +206,7 @@ void key_restore(uchar *to_record, uchar *from_key, KEY *key_info, Don't copy data for null bytes The -1 below is to subtract the null byte which is already handled */ - length= min<uint>(key_length, key_part->store_length-1); + length= MY_MIN(key_length, uint(key_part->store_length)-1); continue; } } @@ -250,7 +248,7 @@ void key_restore(uchar *to_record, uchar *from_key, KEY *key_info, my_ptrdiff_t ptrdiff= to_record - field->table->record[0]; field->move_field_offset(ptrdiff); key_length-= HA_KEY_BLOB_LENGTH; - length= min<uint>(key_length, key_part->length); + length= MY_MIN(key_length, key_part->length); old_map= dbug_tmp_use_all_columns(field->table, field->table->write_set); field->set_key_image(from_key, length); dbug_tmp_restore_column_map(field->table->write_set, old_map); @@ -259,7 +257,7 @@ void key_restore(uchar *to_record, uchar *from_key, KEY *key_info, } else { - length= min<uint>(key_length, key_part->length); + length= MY_MIN(key_length, key_part->length); /* skip the byte with 'uneven' bits, if used */ memcpy(to_record + key_part->offset, from_key + used_uneven_bits , (size_t) length - used_uneven_bits); @@ -317,7 +315,7 @@ bool key_cmp_if_same(TABLE *table,const uchar *key,uint idx,uint key_length) return 1; continue; } - length= min((uint) (key_end-key), store_length); + length= MY_MIN((uint) (key_end-key), store_length); if (!(key_part->key_type & (FIELDFLAG_NUMBER+FIELDFLAG_BINARY+ FIELDFLAG_PACK))) { @@ -331,7 +329,7 @@ bool key_cmp_if_same(TABLE *table,const uchar *key,uint idx,uint key_length) } if (cs->coll->strnncollsp(cs, (const uchar*) key, length, - (const uchar*) pos, char_length, 0)) + (const uchar*) pos, char_length)) return 1; continue; } @@ -377,7 +375,7 @@ void field_unpack(String *to, Field *field, const uchar *rec, uint max_length, { const char *tmp_end= tmp.ptr() + tmp.length(); while (tmp_end > tmp.ptr() && !*--tmp_end) ; - tmp.length(tmp_end - tmp.ptr() + 1); + tmp.length((uint32)(tmp_end - tmp.ptr() + 1)); } if (cs->mbmaxlen > 1 && prefix_key) { @@ -395,7 +393,7 @@ void field_unpack(String *to, Field *field, const uchar *rec, uint max_length, tmp.length(charpos); } if (max_length < field->pack_length()) - tmp.length(min(tmp.length(),max_length)); + tmp.length(MY_MIN(tmp.length(),max_length)); ErrConvString err(&tmp); to->append(err.ptr()); } @@ -468,19 +466,8 @@ void key_unpack(String *to, TABLE *table, KEY *key) bool is_key_used(TABLE *table, uint idx, const MY_BITMAP *fields) { - bitmap_clear_all(&table->tmp_set); - table->mark_columns_used_by_index_no_reset(idx, &table->tmp_set); - if (bitmap_is_overlapping(&table->tmp_set, fields)) - return 1; - - /* - If table handler has primary key as part of the index, check that primary - key is not updated - */ - if (idx != table->s->primary_key && table->s->primary_key < MAX_KEY && - (table->file->ha_table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX)) - return is_key_used(table, table->s->primary_key, fields); - return 0; + table->mark_columns_used_by_index(idx, &table->tmp_set); + return bitmap_is_overlapping(&table->tmp_set, fields); } @@ -511,7 +498,7 @@ int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length) if (key_part->null_bit) { /* This key part allows null values; NULL is lower than everything */ - register bool field_is_null= key_part->field->is_null(); + bool field_is_null= key_part->field->is_null(); if (*key) // If range key is null { /* the range is expecting a null value */ @@ -894,8 +881,7 @@ bool key_buf_cmp(KEY *key_info, uint used_key_parts, if (length1 != length2 || cs->coll->strnncollsp(cs, pos1 + pack_length, byte_len1, - pos2 + pack_length, byte_len2, - 1)) + pos2 + pack_length, byte_len2)) return TRUE; key1+= pack_length; key2+= pack_length; } |