summaryrefslogtreecommitdiff
path: root/sql/key.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/key.cc')
-rw-r--r--sql/key.cc48
1 files changed, 25 insertions, 23 deletions
diff --git a/sql/key.cc b/sql/key.cc
index 700bf6a05a6..414c3392cff 100644
--- a/sql/key.cc
+++ b/sql/key.cc
@@ -16,11 +16,14 @@
/* Functions to handle keys and fields in forms */
+#include <my_global.h>
#include "sql_priv.h"
-#include "unireg.h" // REQUIRED: by includes later
#include "key.h" // key_rec_cmp
#include "field.h" // Field
+using std::min;
+using std::max;
+
/*
Search after a key that starts with 'field'
@@ -79,7 +82,7 @@ int find_ref_key(KEY *key, uint key_count, uchar *record, Field *field,
KEY_PART_INFO *key_part;
*key_length=0;
for (j=0, key_part=key_info->key_part ;
- j < key_info->key_parts ;
+ j < key_info->user_defined_key_parts ;
j++, key_part++)
{
if (key_part->offset == fieldpos &&
@@ -125,8 +128,8 @@ void key_copy(uchar *to_key, uchar *from_record, KEY *key_info,
{
if (key_part->null_bit)
{
- *to_key++= test(from_record[key_part->null_offset] &
- key_part->null_bit);
+ *to_key++= MY_TEST(from_record[key_part->null_offset] &
+ key_part->null_bit);
key_length--;
if (to_key[-1])
{
@@ -134,7 +137,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(key_length, (uint) key_part->store_length-1);
+ length= min<uint>(key_length, key_part->store_length-1);
if (with_zerofill)
bzero((char*) to_key, length);
continue;
@@ -144,7 +147,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(key_length, key_part->length);
+ length= min<uint>(key_length, key_part->length);
uint bytes= key_part->field->get_key_image(to_key, length, Field::itRAW);
if (with_zerofill && bytes < length)
bzero((char*) to_key + bytes, length - bytes);
@@ -152,7 +155,7 @@ void key_copy(uchar *to_key, uchar *from_record, KEY *key_info,
}
else
{
- length= min(key_length, key_part->length);
+ length= min<uint>(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);
@@ -204,7 +207,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(key_length, (uint) key_part->store_length-1);
+ length= min<uint>(key_length, key_part->store_length-1);
continue;
}
}
@@ -246,7 +249,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(key_length, key_part->length);
+ length= min<uint>(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);
@@ -255,7 +258,7 @@ void key_restore(uchar *to_record, uchar *from_key, KEY *key_info,
}
else
{
- length= min(key_length, key_part->length);
+ length= min<uint>(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);
@@ -299,8 +302,8 @@ bool key_cmp_if_same(TABLE *table,const uchar *key,uint idx,uint key_length)
if (key_part->null_bit)
{
- if (*key != test(table->record[0][key_part->null_offset] &
- key_part->null_bit))
+ if (*key != MY_TEST(table->record[0][key_part->null_offset] &
+ key_part->null_bit))
return 1;
if (*key)
continue;
@@ -412,18 +415,17 @@ void field_unpack(String *to, Field *field, const uchar *rec, uint max_length,
@param
table Table to use
@param
- idx Key number
+ key Key
*/
-void key_unpack(String *to,TABLE *table,uint idx)
+void key_unpack(String *to, TABLE *table, KEY *key)
{
- KEY_PART_INFO *key_part,*key_part_end;
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
DBUG_ENTER("key_unpack");
to->length(0);
- for (key_part=table->key_info[idx].key_part,key_part_end=key_part+
- table->key_info[idx].key_parts ;
+ KEY_PART_INFO *key_part_end= key->key_part + key->user_defined_key_parts;
+ for (KEY_PART_INFO *key_part= key->key_part;
key_part < key_part_end;
key_part++)
{
@@ -433,12 +435,12 @@ void key_unpack(String *to,TABLE *table,uint idx)
{
if (table->record[0][key_part->null_offset] & key_part->null_bit)
{
- to->append(STRING_WITH_LEN("NULL"));
- continue;
+ to->append(STRING_WITH_LEN("NULL"));
+ continue;
}
}
field_unpack(to, key_part->field, table->record[0], key_part->length,
- test(key_part->key_part_flag & HA_PART_KEY_SEG));
+ MY_TEST(key_part->key_part_flag & HA_PART_KEY_SEG));
}
dbug_tmp_restore_column_map(table->read_set, old_map);
DBUG_VOID_RETURN;
@@ -576,7 +578,7 @@ int key_rec_cmp(void *key_p, uchar *first_rec, uchar *second_rec)
/* loop over all given keys */
do
{
- key_parts= key_info->key_parts;
+ key_parts= key_info->user_defined_key_parts;
key_part= key_info->key_part;
key_part_num= 0;
@@ -588,8 +590,8 @@ int key_rec_cmp(void *key_p, uchar *first_rec, uchar *second_rec)
if (key_part->null_bit)
{
/* The key_part can contain NULL values */
- bool first_is_null= field->is_null_in_record_with_offset(first_diff);
- bool sec_is_null= field->is_null_in_record_with_offset(sec_diff);
+ bool first_is_null= field->is_real_null(first_diff);
+ bool sec_is_null= field->is_real_null(sec_diff);
/*
NULL is smaller then everything so if first is NULL and the other
not then we know that we should return -1 and for the opposite