Skip to content

Commit 7f9b3ea

Browse files
FooBarriorvuvova
authored andcommitted
pass ptr into more Field methods
1 parent 6334b57 commit 7f9b3ea

File tree

4 files changed

+76
-47
lines changed

4 files changed

+76
-47
lines changed

sql/field.cc

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7530,12 +7530,13 @@ uint Field_string::max_packed_col_length(uint max_length)
75307530
}
75317531

75327532

7533-
uint Field_string::get_key_image(uchar *buff, uint length, imagetype type_arg)
7533+
uint Field_string::get_key_image(uchar *buff, uint length, const uchar *ptr_arg,
7534+
imagetype type_arg) const
75347535
{
7535-
size_t bytes= field_charset()->charpos((char*) ptr,
7536-
(char*) ptr + field_length,
7536+
size_t bytes= field_charset()->charpos((char*) ptr_arg,
7537+
(char*) ptr_arg + field_length,
75377538
length / mbmaxlen());
7538-
memcpy(buff, ptr, bytes);
7539+
memcpy(buff, ptr_arg, bytes);
75397540
if (bytes < length)
75407541
field_charset()->fill((char*) buff + bytes,
75417542
length - bytes,
@@ -7915,18 +7916,19 @@ uint Field_varstring::max_packed_col_length(uint max_length)
79157916
return (max_length > 255 ? 2 : 1)+max_length;
79167917
}
79177918

7919+
void Field_varstring::val_str_from_ptr(String *val, const uchar *ptr) const
7920+
{
7921+
val->set((const char*) get_data(ptr), get_length(ptr), field_charset());
7922+
}
7923+
79187924
uint Field_varstring::get_key_image(uchar *buff, uint length,
7919-
imagetype type_arg)
7925+
const uchar *ptr_arg,
7926+
imagetype type_arg) const
79207927
{
79217928
String val;
7922-
uint local_char_length;
7923-
my_bitmap_map *old_map;
7924-
7925-
old_map= dbug_tmp_use_all_columns(table, table->read_set);
7926-
val_str(&val, &val);
7927-
dbug_tmp_restore_column_map(table->read_set, old_map);
7929+
val_str_from_ptr(&val, ptr_arg);
79287930

7929-
local_char_length= val.charpos(length / mbmaxlen());
7931+
uint local_char_length= val.charpos(length / mbmaxlen());
79307932
if (local_char_length < val.length())
79317933
val.length(local_char_length);
79327934
/* Key is always stored with 2 bytes */
@@ -8172,6 +8174,11 @@ int Field_varstring_compressed::store(const char *from, size_t length,
81728174
return rc;
81738175
}
81748176

8177+
void Field_varstring_compressed::val_str_from_ptr(String *val, const uchar *ptr) const
8178+
{
8179+
uncompress(val, val, get_data(ptr), get_length(ptr));
8180+
}
8181+
81758182

81768183
String *Field_varstring_compressed::val_str(String *val_buffer, String *val_ptr)
81778184
{
@@ -8499,10 +8506,11 @@ int Field_blob::cmp_binary(const uchar *a_ptr, const uchar *b_ptr,
84998506

85008507
/* The following is used only when comparing a key */
85018508

8502-
uint Field_blob::get_key_image_itRAW(uchar *buff, uint length)
8509+
uint Field_blob::get_key_image_itRAW(const uchar *ptr_arg, uchar *buff,
8510+
uint length) const
85038511
{
8504-
size_t blob_length= get_length(ptr);
8505-
uchar *blob= get_ptr();
8512+
size_t blob_length= get_length(ptr_arg);
8513+
const uchar *blob= get_ptr(ptr_arg);
85068514
size_t local_char_length= length / mbmaxlen();
85078515
local_char_length= field_charset()->charpos(blob, blob + blob_length,
85088516
local_char_length);
@@ -8670,9 +8678,7 @@ void Field_blob::sql_type(String &res) const
86708678

86718679
uchar *Field_blob::pack(uchar *to, const uchar *from, uint max_length)
86728680
{
8673-
uchar *save= ptr;
8674-
ptr= (uchar*) from;
8675-
uint32 length=get_length(); // Length of from string
8681+
uint32 length=get_length(from, packlength); // Length of from string
86768682

86778683
/*
86788684
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)
86868692
*/
86878693
if (length > 0)
86888694
{
8689-
from= get_ptr();
8695+
from= get_ptr(from);
86908696
memcpy(to+packlength, from,length);
86918697
}
8692-
ptr=save; // Restore org row pointer
86938698
return to+packlength+length;
86948699
}
86958700

@@ -9706,11 +9711,12 @@ int Field_bit::cmp_offset(my_ptrdiff_t row_offset)
97069711
}
97079712

97089713

9709-
uint Field_bit::get_key_image(uchar *buff, uint length, imagetype type_arg)
9714+
uint Field_bit::get_key_image(uchar *buff, uint length, const uchar *ptr_arg, imagetype type_arg) const
97109715
{
97119716
if (bit_len)
97129717
{
9713-
uchar bits= get_rec_bits(bit_ptr, bit_ofs, bit_len);
9718+
const uchar *bit_ptr_for_arg= ptr_arg + (bit_ptr - ptr);
9719+
uchar bits= get_rec_bits(bit_ptr_for_arg, bit_ofs, bit_len);
97149720
*buff++= bits;
97159721
length--;
97169722
}

sql/field.h

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,8 +1463,11 @@ class Field: public Value_source
14631463
if (null_ptr)
14641464
null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*);
14651465
}
1466-
virtual void get_image(uchar *buff, uint length, CHARSET_INFO *cs)
1467-
{ memcpy(buff,ptr,length); }
1466+
void get_image(uchar *buff, uint length, CHARSET_INFO *cs) const
1467+
{ get_image(buff, length, ptr, cs); }
1468+
virtual void get_image(uchar *buff, uint length,
1469+
const uchar *ptr_arg, CHARSET_INFO *cs) const
1470+
{ memcpy(buff,ptr_arg,length); }
14681471
virtual void set_image(const uchar *buff,uint length, CHARSET_INFO *cs)
14691472
{ memcpy(ptr,buff,length); }
14701473

@@ -1495,9 +1498,11 @@ class Field: public Value_source
14951498
Number of copied bytes (excluding padded zero bytes -- see above).
14961499
*/
14971500

1498-
virtual uint get_key_image(uchar *buff, uint length, imagetype type_arg)
1501+
uint get_key_image(uchar *buff, uint length, imagetype type_arg) const
1502+
{ return get_key_image(buff, length, ptr, type_arg); }
1503+
virtual uint get_key_image(uchar *buff, uint length, const uchar *ptr_arg, imagetype type_arg) const
14991504
{
1500-
get_image(buff, length, &my_charset_bin);
1505+
get_image(buff, length, ptr_arg, &my_charset_bin);
15011506
return length;
15021507
}
15031508
virtual void set_key_image(const uchar *buff,uint length)
@@ -3993,7 +3998,8 @@ class Field_string :public Field_longstr {
39933998
bool has_charset() const override { return charset() != &my_charset_bin; }
39943999
Field *make_new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type)
39954000
override;
3996-
uint get_key_image(uchar *buff,uint length, imagetype type) override;
4001+
uint get_key_image(uchar *buff, uint length,
4002+
const uchar *ptr_arg, imagetype type) const override;
39974003
sql_mode_t value_depends_on_sql_mode() const override;
39984004
sql_mode_t can_handle_sql_mode_dependency_on_store() const override;
39994005
void print_key_value(String *out, uint32 length) override;
@@ -4003,13 +4009,21 @@ class Field_string :public Field_longstr {
40034009

40044010
class Field_varstring :public Field_longstr {
40054011
public:
4006-
uchar *get_data() const
4012+
const uchar *get_data() const
40074013
{
4008-
return ptr + length_bytes;
4014+
return get_data(ptr);
4015+
}
4016+
const uchar *get_data(const uchar *ptr_arg) const
4017+
{
4018+
return ptr_arg + length_bytes;
40094019
}
40104020
uint get_length() const
40114021
{
4012-
return length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
4022+
return get_length(ptr);
4023+
}
4024+
uint get_length(const uchar *ptr_arg) const
4025+
{
4026+
return length_bytes == 1 ? (uint) *ptr_arg : uint2korr(ptr_arg);
40134027
}
40144028
protected:
40154029
void store_length(uint32 number)
@@ -4019,6 +4033,7 @@ class Field_varstring :public Field_longstr {
40194033
else
40204034
int2store(ptr, number);
40214035
}
4036+
virtual void val_str_from_ptr(String *val, const uchar *ptr) const;
40224037
public:
40234038
/*
40244039
The maximum space available in a Field_varstring, in bytes. See
@@ -4090,7 +4105,8 @@ class Field_varstring :public Field_longstr {
40904105
return cmp_max(a, b, ~0U);
40914106
}
40924107
void sort_string(uchar *buff,uint length) override;
4093-
uint get_key_image(uchar *buff,uint length, imagetype type) override;
4108+
uint get_key_image(uchar *buff, uint length,
4109+
const uchar *ptr_arg, imagetype type) const override;
40944110
void set_key_image(const uchar *buff,uint length) override;
40954111
void sql_type(String &str) const override;
40964112
void sql_rpl_type(String*) const override;
@@ -4142,6 +4158,7 @@ class Field_varstring_compressed: public Field_varstring {
41424158
{ return compression_method_ptr; }
41434159
private:
41444160
Compression_method *compression_method_ptr;
4161+
void val_str_from_ptr(String *val, const uchar *ptr) const override;
41454162
int store(const char *to, size_t length, CHARSET_INFO *charset) override;
41464163
using Field_str::store;
41474164
String *val_str(String *, String *) override;
@@ -4260,7 +4277,7 @@ class Field_blob :public Field_longstr {
42604277

42614278
static void do_copy_blob(Copy_field *copy);
42624279
static void do_conv_blob(Copy_field *copy);
4263-
uint get_key_image_itRAW(uchar *buff, uint length);
4280+
uint get_key_image_itRAW(const uchar *ptr_arg, uchar *buff, uint length) const;
42644281
public:
42654282
Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
42664283
enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg,
@@ -4427,11 +4444,11 @@ class Field_blob :public Field_longstr {
44274444
uint32 get_length(const uchar *ptr, uint packlength) const;
44284445
uint32 get_length(const uchar *ptr_arg) const
44294446
{ return get_length(ptr_arg, this->packlength); }
4430-
inline uchar *get_ptr() const { return get_ptr(0); }
4431-
inline uchar *get_ptr(my_ptrdiff_t row_offset) const
4447+
inline uchar *get_ptr() const { return get_ptr(ptr); }
4448+
inline uchar *get_ptr(const uchar *ptr_arg) const
44324449
{
44334450
uchar *s;
4434-
memcpy(&s, ptr + packlength + row_offset, sizeof(uchar*));
4451+
memcpy(&s, ptr_arg + packlength, sizeof(uchar*));
44354452
return s;
44364453
}
44374454
inline void set_ptr(uchar *length, uchar *data)
@@ -4450,10 +4467,11 @@ class Field_blob :public Field_longstr {
44504467
set_ptr_offset(0, length, data);
44514468
}
44524469
int copy_value(Field_blob *from);
4453-
uint get_key_image(uchar *buff, uint length, imagetype type) override
4470+
uint get_key_image(uchar *buff, uint length,
4471+
const uchar *ptr_arg, imagetype type) const override
44544472
{
44554473
DBUG_ASSERT(type == itRAW);
4456-
return get_key_image_itRAW(buff, length);
4474+
return get_key_image_itRAW(ptr_arg, buff, length);
44574475
}
44584476
void set_key_image(const uchar *buff,uint length) override;
44594477
Field *new_key_field(MEM_ROOT *root, TABLE *new_table,
@@ -4559,7 +4577,8 @@ class Field_blob_compressed: public Field_blob {
45594577
compression methods or compression levels.
45604578
*/
45614579

4562-
uint get_key_image(uchar *, uint, imagetype) override
4580+
uint get_key_image(uchar *buff, uint length,
4581+
const uchar *ptr_arg, imagetype type_arg) const override
45634582
{ DBUG_ASSERT(0); return 0; }
45644583
void set_key_image(const uchar *, uint) override
45654584
{ DBUG_ASSERT(0); }
@@ -4846,15 +4865,17 @@ class Field_bit :public Field {
48464865
{
48474866
return pos_in_interval_val_real(min, max);
48484867
}
4849-
void get_image(uchar *buff, uint length, CHARSET_INFO *) override
4850-
{ get_key_image(buff, length, itRAW); }
4868+
void get_image(uchar *buff, uint length,
4869+
const uchar *ptr_arg, CHARSET_INFO *cs) const override
4870+
{ get_key_image(buff, length, ptr_arg, itRAW); }
48514871
void set_image(const uchar *buff,uint length, CHARSET_INFO *cs) override
48524872
{ Field_bit::store((char *) buff, length, cs); }
4853-
uint get_key_image(uchar *buff, uint length, imagetype type) override;
4873+
uint get_key_image(uchar *buff, uint length,
4874+
const uchar *ptr_arg, imagetype type) const override;
48544875
void set_key_image(const uchar *buff, uint length) override
48554876
{ Field_bit::store((char*) buff, length, &my_charset_bin); }
48564877
void sort_string(uchar *buff, uint length) override
4857-
{ get_key_image(buff, length, itRAW); }
4878+
{ get_key_image(buff, length, ptr, itRAW); }
48584879
uint32 pack_length() const override
48594880
{ return (uint32) (field_length + 7) / 8; }
48604881
uint32 pack_length_in_rec() const override { return bytes_in_rec; }

sql/sql_type_geom.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -943,16 +943,17 @@ bool Field_geom::load_data_set_null(THD *thd)
943943
}
944944

945945

946-
uint Field_geom::get_key_image(uchar *buff,uint length, imagetype type_arg)
946+
uint Field_geom::get_key_image(uchar *buff,uint length, const uchar *ptr_arg,
947+
imagetype type_arg) const
947948
{
948949
if (type_arg == itMBR)
949950
{
950951
LEX_CSTRING tmp;
951-
tmp.str= (const char *) get_ptr();
952-
tmp.length= get_length(ptr);
952+
tmp.str= (const char *) get_ptr(ptr_arg);
953+
tmp.length= get_length(ptr_arg);
953954
return Geometry::get_key_image_itMBR(tmp, buff, length);
954955
}
955-
return Field_blob::get_key_image_itRAW(buff, length);
956+
return Field_blob::get_key_image_itRAW(ptr_arg, buff, length);
956957
}
957958

958959
Binlog_type_info Field_geom::binlog_type_info() const

sql/sql_type_geom.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ class Field_geom :public Field_blob
412412
represented differently, but we need to support it either way.
413413
*/
414414
uint32 key_length() const override{ return packlength; }
415-
uint get_key_image(uchar *buff,uint length, imagetype type_arg) override;
415+
uint get_key_image(uchar *buff,uint length,
416+
const uchar *ptr_arg, imagetype type_arg) const override;
416417

417418
/**
418419
Non-nullable GEOMETRY types cannot have defaults,

0 commit comments

Comments
 (0)