Commit 045510cb authored by Nikita Malyavin's avatar Nikita Malyavin Committed by Sergei Golubchik

fix mroonga: change field's table as well as ptr for ad-hoc // fixes ptr_in_record usage

parent db6f02bb
......@@ -6530,17 +6530,10 @@ int ha_mroonga::wrapper_update_row_index(const uchar *old_data,
grn_id old_record_id;
my_ptrdiff_t ptr_diff = PTR_BYTE_DIFF(old_data, table->record[0]);
for (uint j = 0; j < KEY_N_KEY_PARTS(key_info); j++) {
Field *field = key_info->key_part[j].field;
field->move_field_offset(ptr_diff);
}
error = wrapper_get_record_id((uchar *)old_data, &old_record_id,
"failed to get old record ID "
"for updating from groonga");
for (uint j = 0; j < KEY_N_KEY_PARTS(key_info); j++) {
Field *field = key_info->key_part[j].field;
field->move_field_offset(-ptr_diff);
}
if (error) {
DBUG_RETURN(0);
}
......@@ -6852,8 +6845,6 @@ int ha_mroonga::storage_update_row_index(const uchar *old_data,
GRN_TEXT_INIT(&new_key, 0);
GRN_TEXT_INIT(&new_encoded_key, 0);
my_ptrdiff_t ptr_diff = PTR_BYTE_DIFF(old_data, table->record[0]);
mrn::DebugColumnAccess debug_column_access(table, table->read_set);
uint i;
uint n_keys = table->s->keys;
......@@ -6877,18 +6868,10 @@ int ha_mroonga::storage_update_row_index(const uchar *old_data,
GRN_BULK_REWIND(&old_key);
grn_bulk_space(ctx, &old_key, key_info->key_length);
for (uint j = 0; j < KEY_N_KEY_PARTS(key_info); j++) {
Field *field = key_info->key_part[j].field;
field->move_field_offset(ptr_diff);
}
key_copy((uchar *)(GRN_TEXT_VALUE(&old_key)),
(uchar *)old_data,
key_info,
key_info->key_length);
for (uint j = 0; j < KEY_N_KEY_PARTS(key_info); j++) {
Field *field = key_info->key_part[j].field;
field->move_field_offset(-ptr_diff);
}
GRN_BULK_REWIND(&old_encoded_key);
grn_bulk_reserve(ctx, &old_encoded_key, MRN_MAX_KEY_SIZE);
uint old_encoded_key_length;
......@@ -14841,9 +14824,7 @@ bool ha_mroonga::wrapper_inplace_alter_table(
need_fill_index = true;
}
if (!error && need_fill_index) {
my_ptrdiff_t diff =
PTR_BYTE_DIFF(table->record[0], altered_table->record[0]);
mrn::TableFieldsOffsetMover mover(altered_table, diff);
mrn::FieldTableChanger changer(altered_table, table);
error = wrapper_fill_indexes(ha_thd(), altered_table->key_info,
index_columns, ha_alter_info->key_count);
}
......@@ -14996,9 +14977,7 @@ bool ha_mroonga::storage_inplace_alter_table_add_index(
}
}
if (!error && have_multiple_column_index) {
my_ptrdiff_t diff =
PTR_BYTE_DIFF(table->record[0], altered_table->record[0]);
mrn::TableFieldsOffsetMover mover(altered_table, diff);
mrn::FieldTableChanger changer(altered_table, table);
error = storage_add_index_multiple_columns(altered_table->key_info,
ha_alter_info->key_count,
index_tables,
......@@ -15181,9 +15160,7 @@ bool ha_mroonga::storage_inplace_alter_table_add_column(
bitmap_set_bit(&generated_column_bitmap, field->field_index);
# endif
my_ptrdiff_t diff =
PTR_BYTE_DIFF(table->record[0], altered_table->record[0]);
mrn::TableFieldsOffsetMover mover(altered_table, diff);
mrn::FieldTableChanger changer(altered_table, table);
error = storage_rnd_init(true);
if (error) {
......
......@@ -20,22 +20,28 @@
#include "mrn_table_fields_offset_mover.hpp"
namespace mrn {
TableFieldsOffsetMover::TableFieldsOffsetMover(TABLE *table,
my_ptrdiff_t diff)
: table_(table),
diff_(diff) {
uint n_columns = table_->s->fields;
FieldTableChanger::FieldTableChanger(TABLE *table,
TABLE *new_table)
: old_table_(table),
new_table_(new_table) {
my_ptrdiff_t diff =
PTR_BYTE_DIFF(new_table_->record[0], old_table_->record[0]);
uint n_columns = old_table_->s->fields;
for (uint i = 0; i < n_columns; ++i) {
Field *field = table_->field[i];
field->move_field_offset(diff_);
Field *field = old_table_->field[i];
field->move_field_offset(diff);
field->table = new_table;
}
}
TableFieldsOffsetMover::~TableFieldsOffsetMover() {
uint n_columns = table_->s->fields;
FieldTableChanger::~FieldTableChanger() {
my_ptrdiff_t diff =
PTR_BYTE_DIFF(new_table_->record[0], old_table_->record[0]);
uint n_columns = old_table_->s->fields;
for (uint i = 0; i < n_columns; ++i) {
Field *field = table_->field[i];
field->move_field_offset(-diff_);
Field *field = old_table_->field[i];
field->move_field_offset(-diff);
field->table = old_table_;
}
}
}
......@@ -22,12 +22,12 @@
#include <mrn_mysql.h>
namespace mrn {
class TableFieldsOffsetMover {
class FieldTableChanger {
public:
TableFieldsOffsetMover(TABLE *table, my_ptrdiff_t diff);
~TableFieldsOffsetMover();
FieldTableChanger(TABLE *table, TABLE *new_table);
~FieldTableChanger();
private:
TABLE *table_;
my_ptrdiff_t diff_;
TABLE *old_table_;
TABLE *new_table_;
};
}
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