@@ -1650,7 +1650,7 @@ Field::Field(uchar *ptr_arg, uint32 length_arg, uchar *null_ptr_arg,
16501650 if (!is_nullable ()) set_flag (NOT_NULL_FLAG);
16511651 comment.str = " " ;
16521652 comment.length = 0 ;
1653- field_index = 0 ;
1653+ m_field_index = 0 ;
16541654}
16551655
16561656/* *
@@ -7281,7 +7281,7 @@ const uchar *Field_blob::unpack(uchar *, const uchar *from, uint param_data) {
72817281 param_data > 0 ? param_data & 0xFF : packlength;
72827282 uint32 const length = get_length (from, master_packlength);
72837283 DBUG_DUMP (" packed" , from, length + master_packlength);
7284- bitmap_set_bit (table->write_set , field_index);
7284+ bitmap_set_bit (table->write_set , field_index () );
72857285 Field_blob::store (pointer_cast<const char *>(from) + master_packlength,
72867286 length, field_charset);
72877287 DBUG_DUMP (" field" , ptr, pack_length () /* len bytes + ptr bytes */ );
@@ -8895,7 +8895,7 @@ const uchar *Field_bit::unpack(uchar *to, const uchar *from, uint param_data) {
88958895 */
88968896 if ((from_bit_len > 0 ) && (from_len > 0 ))
88978897 value[new_len - len] = value[new_len - len] & ((1U << from_bit_len) - 1 );
8898- bitmap_set_bit (table->write_set , field_index);
8898+ bitmap_set_bit (table->write_set , field_index () );
88998899 store (value, new_len, system_charset_info);
89008900 return from + len;
89018901}
@@ -9833,10 +9833,17 @@ void Field_typed_array::init(TABLE *table_arg) {
98339833 return ;
98349834 }
98359835
9836+ // Set mem_root for conversion field allocation.
9837+ MEM_ROOT *actual_mem_root =
9838+ (table_arg->s ->table_category == TABLE_CATEGORY_TEMPORARY)
9839+ ? &table_arg->s ->mem_root
9840+ : &table_arg->mem_root ;
98369841 // Create field for data conversion
98379842 Field *conv_field = ::make_field (
9838- // Allocate conversion field in table's mem_root
9839- &table_arg->mem_root ,
9843+ // Allocate conversion field in table's mem_root for non-temp
9844+ // tables. Allocate conversion field in TABLE_SHARE's mem_root
9845+ // for internal temporary tables.
9846+ actual_mem_root,
98409847 nullptr , // TABLE_SHARE, not needed
98419848 nullptr , // data buffer, isn't allocated yet
98429849 field_length, // field_length
@@ -9856,21 +9863,20 @@ void Field_typed_array::init(TABLE *table_arg) {
98569863 );
98579864 if (conv_field == nullptr ) return ;
98589865 uchar *buf =
9859- table_arg-> mem_root . ArrayAlloc <uchar>(conv_field->pack_length () + 1 );
9866+ actual_mem_root-> ArrayAlloc <uchar>(conv_field->pack_length () + 1 );
98609867 if (buf == nullptr ) return ;
98619868 if (type () == MYSQL_TYPE_NEWDECIMAL)
98629869 (down_cast<Field_new_decimal *>(conv_field))->set_keep_precision (true );
98639870 conv_field->move_field (buf + 1 , buf, 0 );
98649871 // Allow conv_field to use table->in_use
98659872 conv_field->table = table;
9866- conv_field->field_index = field_index;
98679873 conv_field->table_name = table_name;
9874+ conv_field->set_field_index (field_index ());
98689875
9869- // Swap arena so that the Item_field is allocated on TABLE::mem_root
9870- // and so it does not end up in THD's item list which will have a different
9871- // lifetime than TABLE::mem_root
9872- Query_arena tmp_arena (&table_arg->mem_root ,
9873- Query_arena::STMT_REGULAR_EXECUTION);
9876+ // Swap arena so that the Item_field is allocated on TABLE::mem_root for
9877+ // non-temp tables and so it does not end up in THD's item list which will
9878+ // have a different lifetime than TABLE::mem_root
9879+ Query_arena tmp_arena (actual_mem_root, Query_arena::STMT_REGULAR_EXECUTION);
98749880 Query_arena backup_arena;
98759881 current_thd->swap_query_arena (tmp_arena, &backup_arena);
98769882 m_conv_item = new Item_field (conv_field);
@@ -9958,6 +9964,11 @@ void Field_typed_array::make_send_field(Send_field *field) const {
99589964 field->type = MYSQL_TYPE_JSON;
99599965}
99609966
9967+ void Field_typed_array::set_field_index (uint16 field_index) {
9968+ Field::set_field_index (field_index);
9969+ if (m_conv_item) m_conv_item->field ->set_field_index (field_index);
9970+ }
9971+
99619972Key_map Field::get_covering_prefix_keys () const {
99629973 if (table == nullptr ) {
99639974 // This function might be called when creating functional indexes. In those
@@ -10137,7 +10148,7 @@ const uchar *Field::unpack_int64(uchar *to, const uchar *from) const {
1013710148
1013810149bool Field_longstr::is_updatable () const {
1013910150 DBUG_ASSERT (table && table->write_set );
10140- return bitmap_is_set (table->write_set , field_index);
10151+ return bitmap_is_set (table->write_set , field_index () );
1014110152}
1014210153
1014310154Field_varstring::Field_varstring (uchar *ptr_arg, uint32 len_arg,
0 commit comments