Commit 8857d57e authored by Marko Mäkelä's avatar Marko Mäkelä

On instant ALTER TABLE, copy the default values to the dictionary cache

dict_table_get_nth_v_col(): Assert that no default value is ever set
on a virtual column. Virtual columns are not handled by the
instant ADD COLUMN mechanism.

ha_innobase_inplace_ctx::commit_instant(): Copy the default values
from instant_table to old_table.
Take deep copy of the dict_table_t::v_cols[].

instant_add_instant_try(): Copy the default values to instant_table.

dict_index_get_nth_field_def(): Define the function in the .h file.

dict_col_t::def_val.data: Change the data type to const void*
to reduce the number of type casts.
parent a1ff0469
......@@ -360,7 +360,7 @@ dict_mem_table_add_v_col(
i, name, heap);
}
v_col = dict_table_get_nth_v_col(table, i);
v_col = &table->v_cols[i];
dict_mem_fill_column_struct(&v_col->m_col, pos, mtype, prtype, len);
v_col->v_pos = i;
......
......@@ -335,6 +335,20 @@ struct ha_innobase_inplace_ctx : public inplace_alter_handler_ctx
mem_heap_dup(old_table->heap, instant_table->cols,
instant_table->n_cols
* sizeof *old_table->cols));
/* Copy the default values to the old_table->heap.
They were allocated in this->heap. */
for (uint i = old_table->n_def - DATA_N_SYS_COLS;
i < instant_table->n_def - DATA_N_SYS_COLS;
i++) {
dict_col_t& col = old_table->cols[i];
ut_ad(col.def_val.len != UNIV_SQL_DEFAULT);
if (const void*& def = col.def_val.data) {
def = mem_heap_dup(old_table->heap, def,
col.def_val.len);
} else {
ut_ad(col.def_val.len == UNIV_SQL_NULL);
}
}
for (uint i = old_table->n_v_def; i--; ) {
UT_DELETE(dict_table_get_nth_v_col(old_table, i)
......@@ -361,6 +375,17 @@ struct ha_innobase_inplace_ctx : public inplace_alter_handler_ctx
old_table->n_v_cols = instant_table->n_v_cols;
instant_table->n_v_def = 0;
for (uint i = old_table->n_v_def; i--; ) {
dict_v_col_t& v = old_table->v_cols[i];
v.base_col = static_cast<dict_col_t**>(
mem_heap_dup(old_table->heap, v.base_col,
v.num_base * sizeof *v.base_col));
for (ulint n = v.num_base; n--; ) {
v.base_col[n] -= instant_table->cols
- old_table->cols;
}
}
dict_index_t* index = dict_table_get_first_index(old_table);
const dict_index_t* new_index = dict_table_get_first_index(
instant_table);
......@@ -4233,7 +4258,15 @@ innobase_add_instant_try(
}
}
ut_ad(!dict_table_get_nth_col(new_table, i)->def_val.data);
ut_ad(dict_table_get_nth_col(new_table, i)->def_val.len
== UNIV_SQL_DEFAULT);
if (!new_field->field) {
dict_col_t* col = dict_table_get_nth_col(new_table, i);
col->def_val.data = dfield_get_data(dfield);
col->def_val.len = dfield_get_len(dfield);
pars_info_t* info = pars_info_create();
pars_info_add_ull_literal(info, "id", user_table->id);
pars_info_add_int4_literal(info, "pos", i);
......
......@@ -1276,11 +1276,20 @@ dict_index_get_nth_col_no(
/** Get the default value of a clustered index field.
@param[in] index clustered index
@param[in] pos field position in the clustered index
@param[out] len length of the default value, in bytes
@return default value */
UNIV_INLINE
@param[out] len length of the value (in bytes), or UNIV_SQL_NULL
@return default value
@retval NULL if the default value is SQL NULL */
inline
const byte*
dict_index_get_nth_field_def(const dict_index_t* index, uint pos, ulint* len);
dict_index_get_nth_field_def(const dict_index_t* index, uint pos, ulint* len)
{
ut_ad(dict_index_is_clust(index));
const dict_col_t* col = dict_index_get_nth_col(index, pos);
ut_ad(col->def_val.len != UNIV_SQL_DEFAULT);
*len = col->def_val.len;
return static_cast<const byte*>(col->def_val.data);
}
/********************************************************************//**
Looks for column n in an index.
......
......@@ -557,8 +557,10 @@ dict_table_get_nth_v_col(
ut_ad(table);
ut_ad(pos < table->n_v_def);
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
return(static_cast<dict_v_col_t*>(table->v_cols) + pos);
dict_v_col_t* vcol = &table->v_cols[pos];
ut_ad(vcol->m_col.def_val.len == UNIV_SQL_DEFAULT);
ut_ad(!vcol->m_col.def_val.data);
return vcol;
}
/********************************************************************//**
......@@ -1279,23 +1281,6 @@ dict_index_get_first_n_field_n_nullable(
return n_nullable;
}
/** Get the default value of a clustered index field.
@param[in] index clustered index
@param[in] pos field position in the clustered index
@param[out] len length of the default value, in bytes
@return default value */
UNIV_INLINE
const byte*
dict_index_get_nth_field_def(const dict_index_t* index, uint pos, ulint* len)
{
ut_ad(dict_index_is_clust(index));
const dict_col_t* col = dict_index_get_nth_col(index, pos);
ut_ad(col->def_val.len != UNIV_SQL_DEFAULT);
*len = col->def_val.len;
return(col->def_val.data);
}
/********************************************************************//**
Returns free space reserved for future updates of records. This is
relevant only in the case of many consecutive inserts, as updates
......
......@@ -623,7 +623,7 @@ struct dict_col_t{
/** Data for instantly added columns */
struct {
/** original default value of instantly added column */
const byte* data;
const void* data;
/** len of data, or UNIV_SQL_DEFAULT if unavailable */
unsigned len;
} def_val;
......
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