summaryrefslogtreecommitdiff
path: root/sql/key.cc
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2013-05-07 13:05:09 +0200
committerSergei Golubchik <sergii@pisem.net>2013-05-07 13:05:09 +0200
commitb381cf843c841151f96541b19bd753cd3bbae326 (patch)
treedfc377a1dfbd4d2044a0b799ff5ed6411c7e864f /sql/key.cc
parentd4be9e7bc0cfd5ddd444ecc64daa4166597ca2eb (diff)
parente5055e22f1f311fa48457cfcc97b72e93a37329f (diff)
downloadmariadb-git-b381cf843c841151f96541b19bd753cd3bbae326.tar.gz
mysql-5.5.31 merge
Diffstat (limited to 'sql/key.cc')
-rw-r--r--sql/key.cc112
1 files changed, 70 insertions, 42 deletions
diff --git a/sql/key.cc b/sql/key.cc
index dd7818119c8..0d3db2d5bf5 100644
--- a/sql/key.cc
+++ b/sql/key.cc
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
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
@@ -335,6 +335,70 @@ bool key_cmp_if_same(TABLE *table,const uchar *key,uint idx,uint key_length)
return 0;
}
+
+/**
+ Unpack a field and append it.
+
+ @param[inout] to String to append the field contents to.
+ @param field Field to unpack.
+ @param rec Record which contains the field data.
+ @param max_length Maximum length of field to unpack
+ or 0 for unlimited.
+ @param prefix_key The field is used as a prefix key.
+*/
+
+void field_unpack(String *to, Field *field, const uchar *rec, uint max_length,
+ bool prefix_key)
+{
+ String tmp;
+ DBUG_ENTER("field_unpack");
+ if (!max_length)
+ max_length= field->pack_length();
+ if (field)
+ {
+ if (field->is_null())
+ {
+ to->append(STRING_WITH_LEN("NULL"));
+ DBUG_VOID_RETURN;
+ }
+ CHARSET_INFO *cs= field->charset();
+ field->val_str(&tmp);
+ /*
+ For BINARY(N) strip trailing zeroes to make
+ the error message nice-looking
+ */
+ if (field->binary() && field->type() == MYSQL_TYPE_STRING && tmp.length())
+ {
+ const char *tmp_end= tmp.ptr() + tmp.length();
+ while (tmp_end > tmp.ptr() && !*--tmp_end) ;
+ tmp.length(tmp_end - tmp.ptr() + 1);
+ }
+ if (cs->mbmaxlen > 1 && prefix_key)
+ {
+ /*
+ Prefix key, multi-byte charset.
+ For the columns of type CHAR(N), the above val_str()
+ call will return exactly "key_part->length" bytes,
+ which can break a multi-byte characters in the middle.
+ Align, returning not more than "char_length" characters.
+ */
+ uint charpos, char_length= max_length / cs->mbmaxlen;
+ if ((charpos= my_charpos(cs, tmp.ptr(),
+ tmp.ptr() + tmp.length(),
+ char_length)) < tmp.length())
+ tmp.length(charpos);
+ }
+ if (max_length < field->pack_length())
+ tmp.length(min(tmp.length(),max_length));
+ ErrConvString err(&tmp);
+ to->append(err.ptr());
+ }
+ else
+ to->append(STRING_WITH_LEN("???"));
+ DBUG_VOID_RETURN;
+}
+
+
/*
unpack key-fields from record to some buffer.
@@ -352,8 +416,6 @@ bool key_cmp_if_same(TABLE *table,const uchar *key,uint idx,uint key_length)
void key_unpack(String *to,TABLE *table,uint idx)
{
KEY_PART_INFO *key_part,*key_part_end;
- Field *field;
- String tmp;
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
DBUG_ENTER("key_unpack");
@@ -369,47 +431,13 @@ 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;
- }
- }
- if ((field=key_part->field))
- {
- CHARSET_INFO *cs= field->charset();
- field->val_str(&tmp);
- /*
- For BINARY(N) strip trailing zeroes to make
- the error message nice-looking
- */
- if (field->binary() && field->type() == MYSQL_TYPE_STRING && tmp.length())
- {
- const char *tmp_end= tmp.ptr() + tmp.length();
- while (tmp_end > tmp.ptr() && !*--tmp_end) ;
- tmp.length(tmp_end - tmp.ptr() + 1);
- }
- if (cs->mbmaxlen > 1 && (key_part->key_part_flag & HA_PART_KEY_SEG))
- {
- /*
- Prefix key, multi-byte charset.
- For the columns of type CHAR(N), the above val_str()
- call will return exactly "key_part->length" bytes,
- which can break a multi-byte characters in the middle.
- Align, returning not more than "char_length" characters.
- */
- uint charpos, char_length= key_part->length / cs->mbmaxlen;
- if ((charpos= my_charpos(cs, tmp.ptr(),
- tmp.ptr() + tmp.length(),
- char_length)) < tmp.length())
- tmp.length(charpos);
+ to->append(STRING_WITH_LEN("NULL"));
+ continue;
}
- if (key_part->length < field->pack_length())
- tmp.length(min(tmp.length(),key_part->length));
- ErrConvString err(&tmp);
- to->append(err.ptr());
}
- else
- to->append(STRING_WITH_LEN("???"));
- }
+ field_unpack(to, key_part->field, table->record[0], key_part->length,
+ test(key_part->key_part_flag & HA_PART_KEY_SEG));
+ }
dbug_tmp_restore_column_map(table->read_set, old_map);
DBUG_VOID_RETURN;
}