Commit 7f9b3ea9 authored by Nikita Malyavin's avatar Nikita Malyavin Committed by Sergei Golubchik

pass ptr into more Field methods

parent 6334b576
...@@ -7530,12 +7530,13 @@ uint Field_string::max_packed_col_length(uint max_length) ...@@ -7530,12 +7530,13 @@ uint Field_string::max_packed_col_length(uint max_length)
} }
uint Field_string::get_key_image(uchar *buff, uint length, imagetype type_arg) uint Field_string::get_key_image(uchar *buff, uint length, const uchar *ptr_arg,
imagetype type_arg) const
{ {
size_t bytes= field_charset()->charpos((char*) ptr, size_t bytes= field_charset()->charpos((char*) ptr_arg,
(char*) ptr + field_length, (char*) ptr_arg + field_length,
length / mbmaxlen()); length / mbmaxlen());
memcpy(buff, ptr, bytes); memcpy(buff, ptr_arg, bytes);
if (bytes < length) if (bytes < length)
field_charset()->fill((char*) buff + bytes, field_charset()->fill((char*) buff + bytes,
length - bytes, length - bytes,
...@@ -7915,18 +7916,19 @@ uint Field_varstring::max_packed_col_length(uint max_length) ...@@ -7915,18 +7916,19 @@ uint Field_varstring::max_packed_col_length(uint max_length)
return (max_length > 255 ? 2 : 1)+max_length; return (max_length > 255 ? 2 : 1)+max_length;
} }
void Field_varstring::val_str_from_ptr(String *val, const uchar *ptr) const
{
val->set((const char*) get_data(ptr), get_length(ptr), field_charset());
}
uint Field_varstring::get_key_image(uchar *buff, uint length, uint Field_varstring::get_key_image(uchar *buff, uint length,
imagetype type_arg) const uchar *ptr_arg,
imagetype type_arg) const
{ {
String val; String val;
uint local_char_length; val_str_from_ptr(&val, ptr_arg);
my_bitmap_map *old_map;
old_map= dbug_tmp_use_all_columns(table, table->read_set);
val_str(&val, &val);
dbug_tmp_restore_column_map(table->read_set, old_map);
local_char_length= val.charpos(length / mbmaxlen()); uint local_char_length= val.charpos(length / mbmaxlen());
if (local_char_length < val.length()) if (local_char_length < val.length())
val.length(local_char_length); val.length(local_char_length);
/* Key is always stored with 2 bytes */ /* Key is always stored with 2 bytes */
...@@ -8172,6 +8174,11 @@ int Field_varstring_compressed::store(const char *from, size_t length, ...@@ -8172,6 +8174,11 @@ int Field_varstring_compressed::store(const char *from, size_t length,
return rc; return rc;
} }
void Field_varstring_compressed::val_str_from_ptr(String *val, const uchar *ptr) const
{
uncompress(val, val, get_data(ptr), get_length(ptr));
}
String *Field_varstring_compressed::val_str(String *val_buffer, String *val_ptr) String *Field_varstring_compressed::val_str(String *val_buffer, String *val_ptr)
{ {
...@@ -8499,10 +8506,11 @@ int Field_blob::cmp_binary(const uchar *a_ptr, const uchar *b_ptr, ...@@ -8499,10 +8506,11 @@ int Field_blob::cmp_binary(const uchar *a_ptr, const uchar *b_ptr,
/* The following is used only when comparing a key */ /* The following is used only when comparing a key */
uint Field_blob::get_key_image_itRAW(uchar *buff, uint length) uint Field_blob::get_key_image_itRAW(const uchar *ptr_arg, uchar *buff,
uint length) const
{ {
size_t blob_length= get_length(ptr); size_t blob_length= get_length(ptr_arg);
uchar *blob= get_ptr(); const uchar *blob= get_ptr(ptr_arg);
size_t local_char_length= length / mbmaxlen(); size_t local_char_length= length / mbmaxlen();
local_char_length= field_charset()->charpos(blob, blob + blob_length, local_char_length= field_charset()->charpos(blob, blob + blob_length,
local_char_length); local_char_length);
...@@ -8670,9 +8678,7 @@ void Field_blob::sql_type(String &res) const ...@@ -8670,9 +8678,7 @@ void Field_blob::sql_type(String &res) const
uchar *Field_blob::pack(uchar *to, const uchar *from, uint max_length) uchar *Field_blob::pack(uchar *to, const uchar *from, uint max_length)
{ {
uchar *save= ptr; uint32 length=get_length(from, packlength); // Length of from string
ptr= (uchar*) from;
uint32 length=get_length(); // Length of from string
/* /*
Store max length, which will occupy packlength bytes. If the max Store max length, which will occupy packlength bytes. If the max
...@@ -8686,10 +8692,9 @@ uchar *Field_blob::pack(uchar *to, const uchar *from, uint max_length) ...@@ -8686,10 +8692,9 @@ uchar *Field_blob::pack(uchar *to, const uchar *from, uint max_length)
*/ */
if (length > 0) if (length > 0)
{ {
from= get_ptr(); from= get_ptr(from);
memcpy(to+packlength, from,length); memcpy(to+packlength, from,length);
} }
ptr=save; // Restore org row pointer
return to+packlength+length; return to+packlength+length;
} }
...@@ -9706,11 +9711,12 @@ int Field_bit::cmp_offset(my_ptrdiff_t row_offset) ...@@ -9706,11 +9711,12 @@ int Field_bit::cmp_offset(my_ptrdiff_t row_offset)
} }
uint Field_bit::get_key_image(uchar *buff, uint length, imagetype type_arg) uint Field_bit::get_key_image(uchar *buff, uint length, const uchar *ptr_arg, imagetype type_arg) const
{ {
if (bit_len) if (bit_len)
{ {
uchar bits= get_rec_bits(bit_ptr, bit_ofs, bit_len); const uchar *bit_ptr_for_arg= ptr_arg + (bit_ptr - ptr);
uchar bits= get_rec_bits(bit_ptr_for_arg, bit_ofs, bit_len);
*buff++= bits; *buff++= bits;
length--; length--;
} }
......
...@@ -1463,8 +1463,11 @@ class Field: public Value_source ...@@ -1463,8 +1463,11 @@ class Field: public Value_source
if (null_ptr) if (null_ptr)
null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*); null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*);
} }
virtual void get_image(uchar *buff, uint length, CHARSET_INFO *cs) void get_image(uchar *buff, uint length, CHARSET_INFO *cs) const
{ memcpy(buff,ptr,length); } { get_image(buff, length, ptr, cs); }
virtual void get_image(uchar *buff, uint length,
const uchar *ptr_arg, CHARSET_INFO *cs) const
{ memcpy(buff,ptr_arg,length); }
virtual void set_image(const uchar *buff,uint length, CHARSET_INFO *cs) virtual void set_image(const uchar *buff,uint length, CHARSET_INFO *cs)
{ memcpy(ptr,buff,length); } { memcpy(ptr,buff,length); }
...@@ -1495,9 +1498,11 @@ class Field: public Value_source ...@@ -1495,9 +1498,11 @@ class Field: public Value_source
Number of copied bytes (excluding padded zero bytes -- see above). Number of copied bytes (excluding padded zero bytes -- see above).
*/ */
virtual uint get_key_image(uchar *buff, uint length, imagetype type_arg) uint get_key_image(uchar *buff, uint length, imagetype type_arg) const
{ return get_key_image(buff, length, ptr, type_arg); }
virtual uint get_key_image(uchar *buff, uint length, const uchar *ptr_arg, imagetype type_arg) const
{ {
get_image(buff, length, &my_charset_bin); get_image(buff, length, ptr_arg, &my_charset_bin);
return length; return length;
} }
virtual void set_key_image(const uchar *buff,uint length) virtual void set_key_image(const uchar *buff,uint length)
...@@ -3993,7 +3998,8 @@ class Field_string :public Field_longstr { ...@@ -3993,7 +3998,8 @@ class Field_string :public Field_longstr {
bool has_charset() const override { return charset() != &my_charset_bin; } bool has_charset() const override { return charset() != &my_charset_bin; }
Field *make_new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type) Field *make_new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type)
override; override;
uint get_key_image(uchar *buff,uint length, imagetype type) override; uint get_key_image(uchar *buff, uint length,
const uchar *ptr_arg, imagetype type) const override;
sql_mode_t value_depends_on_sql_mode() const override; sql_mode_t value_depends_on_sql_mode() const override;
sql_mode_t can_handle_sql_mode_dependency_on_store() const override; sql_mode_t can_handle_sql_mode_dependency_on_store() const override;
void print_key_value(String *out, uint32 length) override; void print_key_value(String *out, uint32 length) override;
...@@ -4003,13 +4009,21 @@ class Field_string :public Field_longstr { ...@@ -4003,13 +4009,21 @@ class Field_string :public Field_longstr {
class Field_varstring :public Field_longstr { class Field_varstring :public Field_longstr {
public: public:
uchar *get_data() const const uchar *get_data() const
{ {
return ptr + length_bytes; return get_data(ptr);
}
const uchar *get_data(const uchar *ptr_arg) const
{
return ptr_arg + length_bytes;
} }
uint get_length() const uint get_length() const
{ {
return length_bytes == 1 ? (uint) *ptr : uint2korr(ptr); return get_length(ptr);
}
uint get_length(const uchar *ptr_arg) const
{
return length_bytes == 1 ? (uint) *ptr_arg : uint2korr(ptr_arg);
} }
protected: protected:
void store_length(uint32 number) void store_length(uint32 number)
...@@ -4019,6 +4033,7 @@ class Field_varstring :public Field_longstr { ...@@ -4019,6 +4033,7 @@ class Field_varstring :public Field_longstr {
else else
int2store(ptr, number); int2store(ptr, number);
} }
virtual void val_str_from_ptr(String *val, const uchar *ptr) const;
public: public:
/* /*
The maximum space available in a Field_varstring, in bytes. See The maximum space available in a Field_varstring, in bytes. See
...@@ -4090,7 +4105,8 @@ class Field_varstring :public Field_longstr { ...@@ -4090,7 +4105,8 @@ class Field_varstring :public Field_longstr {
return cmp_max(a, b, ~0U); return cmp_max(a, b, ~0U);
} }
void sort_string(uchar *buff,uint length) override; void sort_string(uchar *buff,uint length) override;
uint get_key_image(uchar *buff,uint length, imagetype type) override; uint get_key_image(uchar *buff, uint length,
const uchar *ptr_arg, imagetype type) const override;
void set_key_image(const uchar *buff,uint length) override; void set_key_image(const uchar *buff,uint length) override;
void sql_type(String &str) const override; void sql_type(String &str) const override;
void sql_rpl_type(String*) const override; void sql_rpl_type(String*) const override;
...@@ -4142,6 +4158,7 @@ class Field_varstring_compressed: public Field_varstring { ...@@ -4142,6 +4158,7 @@ class Field_varstring_compressed: public Field_varstring {
{ return compression_method_ptr; } { return compression_method_ptr; }
private: private:
Compression_method *compression_method_ptr; Compression_method *compression_method_ptr;
void val_str_from_ptr(String *val, const uchar *ptr) const override;
int store(const char *to, size_t length, CHARSET_INFO *charset) override; int store(const char *to, size_t length, CHARSET_INFO *charset) override;
using Field_str::store; using Field_str::store;
String *val_str(String *, String *) override; String *val_str(String *, String *) override;
...@@ -4260,7 +4277,7 @@ class Field_blob :public Field_longstr { ...@@ -4260,7 +4277,7 @@ class Field_blob :public Field_longstr {
static void do_copy_blob(Copy_field *copy); static void do_copy_blob(Copy_field *copy);
static void do_conv_blob(Copy_field *copy); static void do_conv_blob(Copy_field *copy);
uint get_key_image_itRAW(uchar *buff, uint length); uint get_key_image_itRAW(const uchar *ptr_arg, uchar *buff, uint length) const;
public: public:
Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg,
...@@ -4427,11 +4444,11 @@ class Field_blob :public Field_longstr { ...@@ -4427,11 +4444,11 @@ class Field_blob :public Field_longstr {
uint32 get_length(const uchar *ptr, uint packlength) const; uint32 get_length(const uchar *ptr, uint packlength) const;
uint32 get_length(const uchar *ptr_arg) const uint32 get_length(const uchar *ptr_arg) const
{ return get_length(ptr_arg, this->packlength); } { return get_length(ptr_arg, this->packlength); }
inline uchar *get_ptr() const { return get_ptr(0); } inline uchar *get_ptr() const { return get_ptr(ptr); }
inline uchar *get_ptr(my_ptrdiff_t row_offset) const inline uchar *get_ptr(const uchar *ptr_arg) const
{ {
uchar *s; uchar *s;
memcpy(&s, ptr + packlength + row_offset, sizeof(uchar*)); memcpy(&s, ptr_arg + packlength, sizeof(uchar*));
return s; return s;
} }
inline void set_ptr(uchar *length, uchar *data) inline void set_ptr(uchar *length, uchar *data)
...@@ -4450,10 +4467,11 @@ class Field_blob :public Field_longstr { ...@@ -4450,10 +4467,11 @@ class Field_blob :public Field_longstr {
set_ptr_offset(0, length, data); set_ptr_offset(0, length, data);
} }
int copy_value(Field_blob *from); int copy_value(Field_blob *from);
uint get_key_image(uchar *buff, uint length, imagetype type) override uint get_key_image(uchar *buff, uint length,
const uchar *ptr_arg, imagetype type) const override
{ {
DBUG_ASSERT(type == itRAW); DBUG_ASSERT(type == itRAW);
return get_key_image_itRAW(buff, length); return get_key_image_itRAW(ptr_arg, buff, length);
} }
void set_key_image(const uchar *buff,uint length) override; void set_key_image(const uchar *buff,uint length) override;
Field *new_key_field(MEM_ROOT *root, TABLE *new_table, Field *new_key_field(MEM_ROOT *root, TABLE *new_table,
...@@ -4559,7 +4577,8 @@ class Field_blob_compressed: public Field_blob { ...@@ -4559,7 +4577,8 @@ class Field_blob_compressed: public Field_blob {
compression methods or compression levels. compression methods or compression levels.
*/ */
uint get_key_image(uchar *, uint, imagetype) override uint get_key_image(uchar *buff, uint length,
const uchar *ptr_arg, imagetype type_arg) const override
{ DBUG_ASSERT(0); return 0; } { DBUG_ASSERT(0); return 0; }
void set_key_image(const uchar *, uint) override void set_key_image(const uchar *, uint) override
{ DBUG_ASSERT(0); } { DBUG_ASSERT(0); }
...@@ -4846,15 +4865,17 @@ class Field_bit :public Field { ...@@ -4846,15 +4865,17 @@ class Field_bit :public Field {
{ {
return pos_in_interval_val_real(min, max); return pos_in_interval_val_real(min, max);
} }
void get_image(uchar *buff, uint length, CHARSET_INFO *) override void get_image(uchar *buff, uint length,
{ get_key_image(buff, length, itRAW); } const uchar *ptr_arg, CHARSET_INFO *cs) const override
{ get_key_image(buff, length, ptr_arg, itRAW); }
void set_image(const uchar *buff,uint length, CHARSET_INFO *cs) override void set_image(const uchar *buff,uint length, CHARSET_INFO *cs) override
{ Field_bit::store((char *) buff, length, cs); } { Field_bit::store((char *) buff, length, cs); }
uint get_key_image(uchar *buff, uint length, imagetype type) override; uint get_key_image(uchar *buff, uint length,
const uchar *ptr_arg, imagetype type) const override;
void set_key_image(const uchar *buff, uint length) override void set_key_image(const uchar *buff, uint length) override
{ Field_bit::store((char*) buff, length, &my_charset_bin); } { Field_bit::store((char*) buff, length, &my_charset_bin); }
void sort_string(uchar *buff, uint length) override void sort_string(uchar *buff, uint length) override
{ get_key_image(buff, length, itRAW); } { get_key_image(buff, length, ptr, itRAW); }
uint32 pack_length() const override uint32 pack_length() const override
{ return (uint32) (field_length + 7) / 8; } { return (uint32) (field_length + 7) / 8; }
uint32 pack_length_in_rec() const override { return bytes_in_rec; } uint32 pack_length_in_rec() const override { return bytes_in_rec; }
......
...@@ -943,16 +943,17 @@ bool Field_geom::load_data_set_null(THD *thd) ...@@ -943,16 +943,17 @@ bool Field_geom::load_data_set_null(THD *thd)
} }
uint Field_geom::get_key_image(uchar *buff,uint length, imagetype type_arg) uint Field_geom::get_key_image(uchar *buff,uint length, const uchar *ptr_arg,
imagetype type_arg) const
{ {
if (type_arg == itMBR) if (type_arg == itMBR)
{ {
LEX_CSTRING tmp; LEX_CSTRING tmp;
tmp.str= (const char *) get_ptr(); tmp.str= (const char *) get_ptr(ptr_arg);
tmp.length= get_length(ptr); tmp.length= get_length(ptr_arg);
return Geometry::get_key_image_itMBR(tmp, buff, length); return Geometry::get_key_image_itMBR(tmp, buff, length);
} }
return Field_blob::get_key_image_itRAW(buff, length); return Field_blob::get_key_image_itRAW(ptr_arg, buff, length);
} }
Binlog_type_info Field_geom::binlog_type_info() const Binlog_type_info Field_geom::binlog_type_info() const
......
...@@ -412,7 +412,8 @@ class Field_geom :public Field_blob ...@@ -412,7 +412,8 @@ class Field_geom :public Field_blob
represented differently, but we need to support it either way. represented differently, but we need to support it either way.
*/ */
uint32 key_length() const override{ return packlength; } uint32 key_length() const override{ return packlength; }
uint get_key_image(uchar *buff,uint length, imagetype type_arg) override; uint get_key_image(uchar *buff,uint length,
const uchar *ptr_arg, imagetype type_arg) const override;
/** /**
Non-nullable GEOMETRY types cannot have defaults, Non-nullable GEOMETRY types cannot have defaults,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment