Commit ca5e2429 authored by Marko Mäkelä's avatar Marko Mäkelä

Move non_pk_col_map from dict_table_t to dict_instant_t

parent 45db2ff5
...@@ -1206,21 +1206,18 @@ void dict_index_t::reconstruct_fields() ...@@ -1206,21 +1206,18 @@ void dict_index_t::reconstruct_fields()
memcpy(temp_fields, fields, n_pk_fields * sizeof(dict_field_t)); memcpy(temp_fields, fields, n_pk_fields * sizeof(dict_field_t));
ulint old_field_no = n_pk_fields; for (unsigned i = n_pk_fields, o = i, j = 0; i < n_fields; i++) {
ulint j = 0; unsigned col_no = table->instant->non_pk_col_map[
i - n_pk_fields];
for (ulint i = n_pk_fields; i < n_fields; i++) {
ulint col_no = table->non_pk_col_map[i - n_pk_fields];
if (col_no == 0) { if (col_no == 0) {
/* Dropped Column */ /* Dropped Column */
temp_fields[i].col = &table->instant->dropped[j++]; temp_fields[i].col = &table->instant->dropped[j++];
ut_ad(i == unsigned(temp_fields[i].col->ind)); ut_ad(i == unsigned(temp_fields[i].col->ind));
} else { } else {
field = fields[old_field_no++]; field = fields[o++];
temp_fields[i].col = &table->cols[col_no - 1]; temp_fields[i].col = &table->cols[col_no - 1];
temp_fields[i].name = dict_table_get_col_name( temp_fields[i].name = dict_table_get_col_name(
table, dict_col_get_no( table, dict_col_get_no(temp_fields[i].col));
temp_fields[i].col));
temp_fields[i].fixed_len = field.fixed_len; temp_fields[i].fixed_len = field.fixed_len;
temp_fields[i].prefix_len = field.prefix_len; temp_fields[i].prefix_len = field.prefix_len;
} }
...@@ -1248,7 +1245,7 @@ void dict_index_t::remove_instant() ...@@ -1248,7 +1245,7 @@ void dict_index_t::remove_instant()
n_core_fields = n_fields; n_core_fields = n_fields;
n_core_null_bytes = UT_BITS_IN_BYTES(n_nullable); n_core_null_bytes = UT_BITS_IN_BYTES(n_nullable);
table->non_pk_col_map = NULL; table->instant = NULL;
return; return;
} }
...@@ -1292,7 +1289,6 @@ void dict_index_t::remove_instant() ...@@ -1292,7 +1289,6 @@ void dict_index_t::remove_instant()
n_nullable = n_null; n_nullable = n_null;
n_core_null_bytes = UT_BITS_IN_BYTES(n_null); n_core_null_bytes = UT_BITS_IN_BYTES(n_null);
table->instant = NULL; table->instant = NULL;
table->non_pk_col_map = NULL;
} }
/** Adjust clustered index metadata for instant ADD/DROP COLUMN. /** Adjust clustered index metadata for instant ADD/DROP COLUMN.
...@@ -1393,32 +1389,6 @@ inline void dict_index_t::instant_op_field( ...@@ -1393,32 +1389,6 @@ inline void dict_index_t::instant_op_field(
n_nullable = n_null; n_nullable = n_null;
} }
/** Build non primary fields to column number in the table. */
void dict_table_t::build_non_pk_map()
{
dict_index_t* index = dict_table_get_first_index(this);
ulint num_non_pk =
index->n_fields - (index->n_uniq + DATA_N_SYS_COLS - 1);
non_pk_col_map = static_cast<ulint*>(mem_heap_zalloc(
heap, num_non_pk * sizeof *non_pk_col_map));
unsigned last_sys_field = index->n_uniq + DATA_ROLL_PTR;
ulint j = 0;
for (ulint i = last_sys_field; i < index->n_fields; i++) {
dict_field_t* field = dict_index_get_nth_field(index, i);
if (!field->col->is_dropped()) {
non_pk_col_map[j] =
dict_index_get_nth_col_no(index, i) + 1;
}
j++;
}
}
/** Read the metadata blob and fill the non primary fields, /** Read the metadata blob and fill the non primary fields,
non-drop nullable fields and fill the drop columns in the vector. non-drop nullable fields and fill the drop columns in the vector.
...@@ -1457,7 +1427,7 @@ byte* dict_table_t::construct_metadata_blob( ...@@ -1457,7 +1427,7 @@ byte* dict_table_t::construct_metadata_blob(
unsigned* len) unsigned* len)
{ {
dict_index_t* clust_index = dict_table_get_first_index(this); dict_index_t* clust_index = dict_table_get_first_index(this);
unsigned num_pk_fields = clust_index->n_uniq + DATA_ROLL_PTR; unsigned num_pk_fields = clust_index->n_uniq + 2;
unsigned num_non_pk_fields = clust_index->n_fields - num_pk_fields; unsigned num_non_pk_fields = clust_index->n_fields - num_pk_fields;
*len = INSTANT_NON_PK_FIELDS_LEN *len = INSTANT_NON_PK_FIELDS_LEN
...@@ -1470,11 +1440,10 @@ byte* dict_table_t::construct_metadata_blob( ...@@ -1470,11 +1440,10 @@ byte* dict_table_t::construct_metadata_blob(
byte* field_data = data + INSTANT_NON_PK_FIELDS_LEN; byte* field_data = data + INSTANT_NON_PK_FIELDS_LEN;
for (ulint i = 0; i < num_non_pk_fields; i++) { for (ulint i = 0; i < num_non_pk_fields; i++) {
unsigned col_no = non_pk_col_map[i]; unsigned col_no = instant->non_pk_col_map[i]
col_no <<= INSTANT_FIELD_COL_NO_SHIFT; << INSTANT_FIELD_COL_NO_SHIFT;
for (ulint j = 0; col_no == 0 && j < instant->n_dropped; for (ulint j = 0; col_no == 0 && j < instant->n_dropped; j++) {
j++) {
if (instant->dropped[j].ind == i + num_pk_fields) { if (instant->dropped[j].ind == i + num_pk_fields) {
col_no |= INSTANT_DROP_COL_FIXED; col_no |= INSTANT_DROP_COL_FIXED;
break; break;
...@@ -1497,11 +1466,12 @@ void dict_table_t::construct_dropped_columns(const byte* data) ...@@ -1497,11 +1466,12 @@ void dict_table_t::construct_dropped_columns(const byte* data)
unsigned num_non_pk_fields = mach_read_from_4(data); unsigned num_non_pk_fields = mach_read_from_4(data);
dict_index_t* clust_index = dict_table_get_first_index(this); dict_index_t* clust_index = dict_table_get_first_index(this);
non_pk_col_map = static_cast<ulint*>(mem_heap_zalloc( unsigned* non_pk_col_map = static_cast<unsigned*>(
heap, num_non_pk_fields * sizeof *non_pk_col_map)); mem_heap_zalloc(heap,
num_non_pk_fields * sizeof *non_pk_col_map));
const byte* field_data = data + INSTANT_NON_PK_FIELDS_LEN; const byte* field_data = data + INSTANT_NON_PK_FIELDS_LEN;
std::vector<ulint> fixed_dcols; std::vector<unsigned> fixed_dcols;
unsigned n_dropped_cols = 0; unsigned n_dropped_cols = 0;
for (unsigned i = 0; i < num_non_pk_fields; i++) { for (unsigned i = 0; i < num_non_pk_fields; i++) {
...@@ -1522,9 +1492,10 @@ void dict_table_t::construct_dropped_columns(const byte* data) ...@@ -1522,9 +1492,10 @@ void dict_table_t::construct_dropped_columns(const byte* data)
dict_col_t* dropped_cols = static_cast<dict_col_t*>(mem_heap_zalloc( dict_col_t* dropped_cols = static_cast<dict_col_t*>(mem_heap_zalloc(
heap, n_dropped_cols * sizeof(dict_col_t))); heap, n_dropped_cols * sizeof(dict_col_t)));
instant = new (mem_heap_alloc(heap, sizeof instant)) dict_instant_t(); instant = new (mem_heap_alloc(heap, sizeof *instant)) dict_instant_t();
instant->n_dropped = n_dropped_cols; instant->n_dropped = n_dropped_cols;
instant->dropped = dropped_cols; instant->dropped = dropped_cols;
instant->non_pk_col_map = non_pk_col_map;
unsigned j = 0; unsigned j = 0;
for (unsigned i = 0; i < n_dropped_cols; i++) { for (unsigned i = 0; i < n_dropped_cols; i++) {
...@@ -1603,7 +1574,7 @@ inline void dict_table_t::fill_dropped_column( ...@@ -1603,7 +1574,7 @@ inline void dict_table_t::fill_dropped_column(
n_t_cols -= n_newly_drop; n_t_cols -= n_newly_drop;
if (!instant) { if (!instant) {
instant = new (mem_heap_alloc(heap, sizeof *instant)) instant = new (mem_heap_zalloc(heap, sizeof *instant))
dict_instant_t(); dict_instant_t();
} }
...@@ -1698,7 +1669,28 @@ void dict_table_t::instant_op_column( ...@@ -1698,7 +1669,28 @@ void dict_table_t::instant_op_column(
index->instant_op_field(*dict_table_get_first_index(&table), index->instant_op_field(*dict_table_get_first_index(&table),
n_newly_add, n_newly_drop, col_map); n_newly_add, n_newly_drop, col_map);
build_non_pk_map(); if (instant || n_newly_drop || n_dropped()) {
unsigned num_non_pk = index->n_fields - (index->n_uniq + 2);
unsigned* non_pk_col_map = static_cast<unsigned*>(
mem_heap_zalloc(heap, num_non_pk
* sizeof *non_pk_col_map));
for (unsigned i = index->n_uniq + 2, j = 0;
i < index->n_fields; i++) {
if (!dict_index_get_nth_col(index, i)->is_dropped()) {
non_pk_col_map[j] =
dict_index_get_nth_col_no(index, i) + 1;
}
j++;
}
if (!instant) {
instant = new (mem_heap_zalloc(heap, sizeof *instant))
dict_instant_t();
}
instant->non_pk_col_map = non_pk_col_map;
}
while ((index = dict_table_get_next_index(index)) != NULL) { while ((index = dict_table_get_next_index(index)) != NULL) {
if (index->to_be_dropped) { if (index->to_be_dropped) {
...@@ -1715,7 +1707,7 @@ void dict_table_t::instant_op_column( ...@@ -1715,7 +1707,7 @@ void dict_table_t::instant_op_column(
GEN_CLUST_INDEX instead of PRIMARY KEY), GEN_CLUST_INDEX instead of PRIMARY KEY),
but not DB_TRX_ID,DB_ROLL_PTR. */ but not DB_TRX_ID,DB_ROLL_PTR. */
DBUG_ASSERT(field.col >= old_cols); DBUG_ASSERT(field.col >= old_cols);
size_t n = col_map[(field.col - old_cols)]; ulint n = col_map[field.col - old_cols];
field.col = &cols[n]; field.col = &cols[n];
DBUG_ASSERT(!field.col->is_virtual()); DBUG_ASSERT(!field.col->is_virtual());
field.name = field.col->name(*this); field.name = field.col->name(*this);
......
...@@ -1574,6 +1574,8 @@ struct dict_instant_t ...@@ -1574,6 +1574,8 @@ struct dict_instant_t
unsigned n_dropped; unsigned n_dropped;
/** Dropped columns */ /** Dropped columns */
dict_col_t* dropped; dict_col_t* dropped;
/** Mapping the non-pk field to column of the table. */
unsigned* non_pk_col_map;
}; };
/** These are used when MySQL FRM and InnoDB data dictionary are /** These are used when MySQL FRM and InnoDB data dictionary are
...@@ -1732,9 +1734,6 @@ struct dict_table_t { ...@@ -1732,9 +1734,6 @@ struct dict_table_t {
ut_ad(fk_checks > 0); ut_ad(fk_checks > 0);
} }
/** Build the mapping of non-pk to column in the table. */
void build_non_pk_map();
/** Id of the table. */ /** Id of the table. */
table_id_t id; table_id_t id;
...@@ -2098,9 +2097,6 @@ struct dict_table_t { ...@@ -2098,9 +2097,6 @@ struct dict_table_t {
It is protected by lock_sys.mutex. */ It is protected by lock_sys.mutex. */
ulint n_rec_locks; ulint n_rec_locks;
/** Mapping the non-pk field to column of the table. */
ulint* non_pk_col_map;
private: private:
/** Count of how many handles are opened to this table. Dropping of the /** Count of how many handles are opened to this table. Dropping of the
table is NOT allowed until this count gets to zero. MySQL does NOT table is NOT allowed until this count gets to zero. MySQL does NOT
......
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