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