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

Add dict_col_t::same_format()

dict_col_t::same_format(): Check if two columns have the same
data type and compatible length.
parent 7a27db77
...@@ -205,6 +205,15 @@ inline void dict_table_t::prepare_instant(const dict_table_t& old, ...@@ -205,6 +205,15 @@ inline void dict_table_t::prepare_instant(const dict_table_t& old,
DBUG_ASSERT(index.n_fields >= oindex.n_fields); DBUG_ASSERT(index.n_fields >= oindex.n_fields);
DBUG_ASSERT(index.n_fields > oindex.n_fields DBUG_ASSERT(index.n_fields > oindex.n_fields
|| !not_redundant()); || !not_redundant());
#ifdef UNIV_DEBUG
if (index.n_fields == oindex.n_fields) {
ut_ad(!not_redundant());
for (unsigned i = index.n_fields; i--; ) {
ut_ad(index.fields[i].col->same_format(
*oindex.fields[i].col));
}
}
#endif
set_core_fields: set_core_fields:
index.n_core_fields = oindex.n_core_fields; index.n_core_fields = oindex.n_core_fields;
index.n_core_null_bytes = oindex.n_core_null_bytes; index.n_core_null_bytes = oindex.n_core_null_bytes;
...@@ -389,6 +398,8 @@ inline void dict_index_t::instant_add_field(const dict_index_t& instant) ...@@ -389,6 +398,8 @@ inline void dict_index_t::instant_add_field(const dict_index_t& instant)
#ifndef DBUG_OFF #ifndef DBUG_OFF
for (unsigned i = 0; i < n_fields; i++) { for (unsigned i = 0; i < n_fields; i++) {
DBUG_ASSERT(fields[i].same(instant.fields[i])); DBUG_ASSERT(fields[i].same(instant.fields[i]));
DBUG_ASSERT(instant.fields[i].col->same_format(*fields[i]
.col));
/* Instant conversion from NULL to NOT NULL is not allowed. */ /* Instant conversion from NULL to NOT NULL is not allowed. */
DBUG_ASSERT(!fields[i].col->is_nullable() DBUG_ASSERT(!fields[i].col->is_nullable()
|| instant.fields[i].col->is_nullable()); || instant.fields[i].col->is_nullable());
...@@ -5439,13 +5450,10 @@ static bool innobase_instant_try( ...@@ -5439,13 +5450,10 @@ static bool innobase_instant_try(
bool update = old && (!ctx->first_alter_pos bool update = old && (!ctx->first_alter_pos
|| i < ctx->first_alter_pos - 1); || i < ctx->first_alter_pos - 1);
DBUG_ASSERT(!old || !((old->prtype ^ col->prtype) DBUG_ASSERT(!old || col->same_format(*old));
& ~(DATA_NOT_NULL | DATA_VERSIONED)));
if (update if (update
&& old->prtype == d->type.prtype) { && old->prtype == d->type.prtype) {
/* The record is already present in SYS_COLUMNS. */ /* The record is already present in SYS_COLUMNS. */
DBUG_ASSERT(old->mtype == col->mtype);
DBUG_ASSERT(old->len == col->len);
} else if (innodb_insert_sys_columns(user_table->id, i, } else if (innodb_insert_sys_columns(user_table->id, i,
(*af)->field_name.str, (*af)->field_name.str,
d->type.mtype, d->type.mtype,
......
...@@ -684,6 +684,20 @@ struct dict_col_t{ ...@@ -684,6 +684,20 @@ struct dict_col_t{
def_val.len = UNIV_SQL_DEFAULT; def_val.len = UNIV_SQL_DEFAULT;
def_val.data = NULL; def_val.data = NULL;
} }
/** Determine if the columns have the same format
except for is_nullable() and is_versioned().
@param[in] other column to compare to
@return whether the columns have the same format */
bool same_format(const dict_col_t& other) const
{
return mtype == other.mtype
&& len >= other.len
&& mbminlen == other.mbminlen
&& mbmaxlen == other.mbmaxlen
&& !((prtype ^ other.prtype)
& ~(DATA_NOT_NULL | DATA_VERSIONED));
}
}; };
/** Index information put in a list of virtual column structure. Index /** Index information put in a list of virtual column structure. Index
......
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