Skip to content

Commit 078e7be

Browse files
committed
Bug#30520809: CHANGE FIELD_TYPED_ARRAY TO USE A PROPER
RECORD BUFFER FOR DATA CONVERSION Change Field_typed_array to use one record buffer rather than two separate buffers for null and actual values. This makes it easier to later convert Field to use offset values rather than record pointers. Refactoring only, no changes of behavior. Change-Id: I6120dc154b94e85015fde50455346fb1eaa9fc29
1 parent 0527aea commit 078e7be

File tree

4 files changed

+24
-38
lines changed

4 files changed

+24
-38
lines changed

sql/field.cc

+15-25
Original file line numberDiff line numberDiff line change
@@ -9703,17 +9703,9 @@ bool Field::is_part_of_actual_key(THD *thd, uint cur_index,
97039703

97049704
Field_typed_array::Field_typed_array(const Field_typed_array &other)
97059705
: Field_json(other),
9706-
m_conv_field(other.m_conv_field),
97079706
m_elt_type(other.m_elt_type),
97089707
m_elt_decimals(other.m_elt_decimals),
9709-
m_elt_charset(other.m_elt_charset) {
9710-
/*
9711-
When conv_field is null the field is cloned from share and isn't
9712-
attached to any table yet (this will happen later).
9713-
*/
9714-
// DBUG_ASSERT(!m_conv_field);
9715-
m_conv_field = nullptr;
9716-
}
9708+
m_elt_charset(other.m_elt_charset) {}
97179709

97189710
Field_typed_array::Field_typed_array(
97199711
enum_field_types elt_type, bool elt_is_unsigned, size_t elt_length,
@@ -9722,7 +9714,6 @@ Field_typed_array::Field_typed_array(
97229714
uint blob_pack_length, const CHARSET_INFO *cs)
97239715
: Field_json(ptr_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
97249716
field_name_arg, share, blob_pack_length),
9725-
m_conv_field(nullptr),
97269717
m_elt_type(elt_type),
97279718
m_elt_decimals(elt_decimals),
97289719
m_elt_charset(cs) {
@@ -9892,7 +9883,6 @@ type_conversion_status Field_typed_array::store_array(const Json_wrapper *data,
98929883
}
98939884

98949885
void Field_typed_array::init(TABLE *table_arg) {
9895-
uint fld_length = field_length;
98969886
Field::init(table_arg);
98979887

98989888
switch (type()) {
@@ -9908,22 +9898,22 @@ void Field_typed_array::init(TABLE *table_arg) {
99089898
default:
99099899
// Shouldn't happen
99109900
DBUG_ASSERT(0); /* purecov: inspected */
9911-
99129901
return;
99139902
}
9903+
99149904
// Create field for data conversion
99159905
m_conv_field = ::make_field(
99169906
// Allocate conversion field in table's mem_root
99179907
&table_arg->mem_root,
9918-
nullptr, // TABLE_SHARE, not needed
9919-
nullptr, // data buffer, isn't allocated yet
9920-
fld_length, // field_length
9921-
&null_byte, 0, // null_pos, nul_bit
9922-
real_type(), // field_type
9908+
nullptr, // TABLE_SHARE, not needed
9909+
nullptr, // data buffer, isn't allocated yet
9910+
field_length, // field_length
9911+
nullptr, 0, // null_pos, nul_bit
9912+
real_type(), // field_type
99239913
m_elt_charset,
99249914
Field::GEOM_GEOMETRY, // geom type
99259915
Field::NONE, // auto_flags
9926-
nullptr, // itervals aren't supported in array
9916+
nullptr, // intervals aren't supported in array
99279917
field_name, is_nullable(),
99289918
false, // zerofill is meaningless with JSON
99299919
unsigned_flag, m_elt_decimals,
@@ -9932,27 +9922,27 @@ void Field_typed_array::init(TABLE *table_arg) {
99329922
{}, // srid
99339923
false // is_array
99349924
);
9935-
if (!m_conv_field ||
9936-
!(m_conv_buf = static_cast<uchar *>(
9937-
table_arg->mem_root.Alloc(m_conv_field->pack_length()))))
9938-
return; /* purecov: inspected */
9925+
if (m_conv_field == nullptr) return;
9926+
uchar *buf =
9927+
table_arg->mem_root.ArrayAlloc<uchar>(m_conv_field->pack_length() + 1);
9928+
if (buf == nullptr) return;
99399929
if (type() == MYSQL_TYPE_NEWDECIMAL)
99409930
(down_cast<Field_new_decimal *>(m_conv_field))->set_keep_precision(true);
9941-
m_conv_field->move_field(m_conv_buf);
9931+
m_conv_field->move_field(buf + 1, buf, 0);
99429932
// Allow conv_field to use table->in_use
99439933
m_conv_field->table = table;
99449934
m_conv_field->field_index = field_index;
99459935
m_conv_field->table_name = table_name;
99469936
}
99479937

9948-
const char *Field_typed_array::get_index_name() {
9938+
const char *Field_typed_array::get_index_name() const {
99499939
uint key = part_of_key.get_first_set();
99509940
DBUG_ASSERT(key != MY_BIT_NONE);
99519941
return table->s->key_info[key].name;
99529942
}
99539943

99549944
size_t Field_typed_array::make_sort_key(Json_wrapper *wr, uchar *to,
9955-
size_t length) {
9945+
size_t length) const {
99569946
#ifndef DBUG_OFF
99579947
switch (wr->type()) {
99589948
case enum_json_type::J_ERROR:

sql/field.h

+7-11
Original file line numberDiff line numberDiff line change
@@ -4239,11 +4239,7 @@ class Field_json : public Field_blob {
42394239

42404240
class Field_typed_array final : public Field_json {
42414241
/// Conversion field
4242-
Field *m_conv_field;
4243-
/// Null byte for conv_field
4244-
uchar null_byte;
4245-
/// conversion field's buffer
4246-
uchar *m_conv_buf;
4242+
Field *m_conv_field{nullptr};
42474243
/// The array element's real type.
42484244
enum_field_types m_elt_type;
42494245
/// Element's decimals
@@ -4354,7 +4350,7 @@ class Field_typed_array final : public Field_json {
43544350
false conversion succeeded
43554351
*/
43564352
bool coerce_json_value(const Json_wrapper *wr, bool no_error,
4357-
Json_wrapper *coerced);
4353+
Json_wrapper *coerced) const;
43584354

43594355
/**
43604356
Get name of the index defined over this field.
@@ -4366,8 +4362,8 @@ class Field_typed_array final : public Field_json {
43664362
@returns
43674363
name of the index defined over the field.
43684364
*/
4369-
const char *get_index_name();
4370-
virtual uint32 get_length_bytes() const override {
4365+
const char *get_index_name() const;
4366+
uint32 get_length_bytes() const override {
43714367
DBUG_ASSERT(m_elt_type == MYSQL_TYPE_VARCHAR);
43724368
return field_length > 255 ? 2 : 1;
43734369
}
@@ -4387,7 +4383,7 @@ class Field_typed_array final : public Field_json {
43874383
@returns
43884384
actual sort key length
43894385
*/
4390-
size_t make_sort_key(Json_wrapper *wr, uchar *to, size_t length);
4386+
size_t make_sort_key(Json_wrapper *wr, uchar *to, size_t length) const;
43914387
/**
43924388
Save the field metadata for typed array fields.
43934389
@@ -4401,8 +4397,8 @@ class Field_typed_array final : public Field_json {
44014397
44024398
@returns number of bytes written to metadata_ptr
44034399
*/
4404-
virtual int do_save_field_metadata(uchar *metadata_ptr) const override;
4405-
virtual uint pack_length_from_metadata(uint) const override {
4400+
int do_save_field_metadata(uchar *metadata_ptr) const override;
4401+
uint pack_length_from_metadata(uint) const override {
44064402
return pack_length_no_ptr();
44074403
}
44084404
void sql_type(String &str) const final override;

sql/item_json_func.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3780,7 +3780,7 @@ Field *Item_func_array_cast::tmp_table_field(TABLE *table) {
37803780
true Otherwise
37813781
*/
37823782
bool Field_typed_array::coerce_json_value(const Json_wrapper *wr, bool no_error,
3783-
Json_wrapper *coerced) {
3783+
Json_wrapper *coerced) const {
37843784
Json_wrapper saved;
37853785
THD *thd = table->in_use;
37863786
// Save JSON value to the conversion field

sql/sql_bitmap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class Bitmap<64> {
189189
return buf;
190190
}
191191
ulonglong to_ulonglong() const { return map; }
192-
uint get_first_set() {
192+
uint get_first_set() const {
193193
for (uint i = 0; i < ALL_BITS; i++)
194194
if (map & (1ULL << i)) return i;
195195
return MY_BIT_NONE;

0 commit comments

Comments
 (0)