Skip to content

Commit

Permalink
Revert "PS-9222 ALTER TABLE ALGORITHM=INSTANT FIX #2"
Browse files Browse the repository at this point in the history
This reverts commit 39e9957.
  • Loading branch information
VarunNagaraju committed Jul 4, 2024
1 parent f43c48d commit da3fb7b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 148 deletions.
44 changes: 0 additions & 44 deletions mysql-test/suite/innodb/r/instant_alter_stored_column_order.result

This file was deleted.

56 changes: 0 additions & 56 deletions mysql-test/suite/innodb/t/instant_alter_stored_column_order.test

This file was deleted.

88 changes: 40 additions & 48 deletions storage/innobase/mtr/mtr0log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -515,28 +515,18 @@ constexpr size_t inst_col_info_size = 6;
@param[in] is_comp true if COMP
@param[in] is_versioned if table has row versions
@param[in] is_instant true if table has INSTANT cols
@param[in] changed_order array indicating fields changed position
@param[out] size_needed total size needed on REDO LOG */
static void log_index_get_size_needed(
const dict_index_t *index, size_t size, uint16_t n, bool is_comp,
bool is_versioned, bool is_instant,
const std::unique_ptr<bool[]> &changed_order, size_t &size_needed) {
auto size_for_versioned_fields = [n,
&changed_order](const dict_index_t *ind) {
static void log_index_get_size_needed(const dict_index_t *index, size_t size,
uint16_t n, bool is_comp,
bool is_versioned, bool is_instant,
size_t &size_needed) {
auto size_for_versioned_fields = [](const dict_index_t *ind) {
size_t _size = 0;
/* 2 bytes for number of columns with version */
_size += 2;

size_t n_versioned_fields = 0;
for (size_t i = 0; i < n; i++) {
dict_field_t *field = ind->get_field(i);
const dict_col_t *col = field->col;
if (col->is_instant_added() || col->is_instant_dropped() ||
changed_order[i]) {
n_versioned_fields += 1;
}
}

size_t n_versioned_fields = ind->table->get_n_instant_add_cols() +
ind->table->get_n_instant_drop_cols();
ut_ad(n_versioned_fields != 0);

_size += n_versioned_fields * inst_col_info_size;
Expand Down Expand Up @@ -654,7 +644,6 @@ static bool close_and_reopen_log(byte *&log_ptr, const byte *&log_start,
const byte *&log_end, mtr_t *&mtr,
size_t &alloc, size_t &total) {
mlog_close(mtr, log_ptr);

ut_a(total > (ulint)(log_ptr - log_start));
total -= log_ptr - log_start;
alloc = total;
Expand Down Expand Up @@ -684,8 +673,7 @@ template <typename F>
@param[in] func callback to check size reopen log buffer */
static bool log_index_fields(const dict_index_t *index, uint16_t n,
bool is_versioned, std::vector<dict_field_t *> &f,
const std::unique_ptr<bool[]> &changed_order,
byte *&log_ptr, F &func) {
bool *changed_order, byte *&log_ptr, F &func) {
/* Write metadata for each field. Log the fields in their logical order. */
for (size_t i = 0; i < n; i++) {
dict_field_t *field = index->get_field(i);
Expand Down Expand Up @@ -811,36 +799,9 @@ bool mlog_open_and_write_index(mtr_t *mtr, const byte *rec,
n = DICT_INDEX_SPATIAL_NODEPTR_SIZE;
}

/* Ordinal position of an existing field can't be changed with INSTANT
algorithm. But when it is combined with ADD/DROP COLUMN, ordinal position
of a filed can be changed. This bool array of size #fields in index,
represents if ordinal position of an existing filed is changed. */

// Move the logic to find columns that changed order before calculating
// the buffer size
std::unique_ptr<bool[]> fields_with_changed_order = nullptr;
if (is_versioned) {
fields_with_changed_order = std::make_unique<bool[]>(n);

uint16_t phy_pos = 0;
for (size_t i = 0; i < n; i++) {
dict_field_t *field = index->get_field(i);
const dict_col_t *col = field->col;

if (col->is_instant_added() || col->is_instant_dropped()) {
continue;
}
if (col->get_col_phy_pos() >= phy_pos) {
phy_pos = col->get_col_phy_pos();
} else {
fields_with_changed_order[i] = true;
}
}
}

size_t size_needed = 0;
log_index_get_size_needed(index, size, n, is_comp, is_versioned, is_instant,
fields_with_changed_order, size_needed);
size_needed);
size_t total = size_needed;
size_t alloc = total;
if (alloc > mtr_buf_t::MAX_DATA_SIZE) {
Expand Down Expand Up @@ -885,10 +846,37 @@ bool mlog_open_and_write_index(mtr_t *mtr, const byte *rec,
return true;
};

/* Ordinal position of an existing field can't be changed with INSTANT
algorithm. But when it is combined with ADD/DROP COLUMN, ordinal position
of a filed can be changed. This bool array of size #fields in index,
represents if ordinal position of an existing filed is changed. */
bool *fields_with_changed_order = nullptr;
if (is_versioned) {
fields_with_changed_order = new bool[n];
memset(fields_with_changed_order, false, (sizeof(bool) * n));

uint16_t phy_pos = 0;
for (size_t i = 0; i < n; i++) {
dict_field_t *field = index->get_field(i);
const dict_col_t *col = field->col;

if (col->is_instant_added() || col->is_instant_dropped()) {
continue;
} else if (col->get_col_phy_pos() >= phy_pos) {
phy_pos = col->get_col_phy_pos();
} else {
fields_with_changed_order[i] = true;
}
}
}

if (is_comp) {
/* Write fields info. */
if (!log_index_fields(index, n, is_versioned, instant_fields_to_log,
fields_with_changed_order, log_ptr, f)) {
if (is_versioned) {
delete[] fields_with_changed_order;
}
return false;
}
} else if (is_versioned) {
Expand All @@ -902,6 +890,10 @@ bool mlog_open_and_write_index(mtr_t *mtr, const byte *rec,
}
}

if (is_versioned) {
delete[] fields_with_changed_order;
}

if (!instant_fields_to_log.empty()) {
ut_ad(is_versioned);
/* Log INSTANT ADD/DROP fields */
Expand Down

0 comments on commit da3fb7b

Please sign in to comment.