Commit 1efda582 authored by Marko Mäkelä's avatar Marko Mäkelä

Replace innobase_is_v_fld() with Field::stored_in_db()

The macro innobase_is_v_fld() turns out to be equivalent with
the opposite of Field::stored_in_db(). Remove the macro and
invoke the member function directly.

innodb_base_col_setup_for_stored(): Simplify a condition to only
check Field::vcol_info.

innobase_create_index_def(): Replace some redundant code with
DBUG_ASSERT().
parent 9471dbaf
......@@ -5986,7 +5986,7 @@ innobase_build_v_templ(
Field* field = table->field[i];
/* Build template for virtual columns */
if (innobase_is_v_fld(field)) {
if (!field->stored_in_db()) {
#ifdef UNIV_DEBUG
const char* name;
......@@ -7475,7 +7475,7 @@ build_template_needs_field(
{
const Field* field = table->field[i];
if (innobase_is_v_fld(field) && omits_virtual_cols(*table->s)) {
if (!field->stored_in_db() && omits_virtual_cols(*table->s)) {
return NULL;
}
......@@ -7555,7 +7555,7 @@ build_template_field(
templ = prebuilt->mysql_template + prebuilt->n_template++;
UNIV_MEM_INVALID(templ, sizeof *templ);
templ->is_virtual = innobase_is_v_fld(field);
templ->is_virtual = !field->stored_in_db();
if (!templ->is_virtual) {
templ->col_no = i;
......@@ -7799,7 +7799,7 @@ ha_innobase::build_template(
/* Push down an index condition or an end_range check. */
for (ulint i = 0; i < n_fields; i++) {
const Field* field = table->field[i];
const bool is_v = innobase_is_v_fld(field);
const bool is_v = !field->stored_in_db();
if (is_v && skip_virtual) {
num_v++;
continue;
......@@ -7939,7 +7939,7 @@ ha_innobase::build_template(
for (ulint i = 0; i < n_fields; i++) {
mysql_row_templ_t* templ;
const Field* field = table->field[i];
const bool is_v = innobase_is_v_fld(field);
const bool is_v = !field->stored_in_db();
if (is_v && skip_virtual) {
num_v++;
continue;
......@@ -7989,7 +7989,7 @@ ha_innobase::build_template(
for (ulint i = 0; i < n_fields; i++) {
const Field* field = table->field[i];
const bool is_v = innobase_is_v_fld(field);
const bool is_v = !field->stored_in_db();
if (whole_row) {
if (is_v && skip_virtual) {
......@@ -8533,7 +8533,7 @@ calc_row_difference(
for (uint i = 0; i < table->s->fields; i++) {
field = table->field[i];
const bool is_virtual = innobase_is_v_fld(field);
const bool is_virtual = !field->stored_in_db();
if (is_virtual && skip_virtual) {
continue;
}
......@@ -8907,7 +8907,7 @@ wsrep_calc_row_hash(
byte true_byte=1;
const Field* field = table->field[i];
if (innobase_is_v_fld(field)) {
if (!field->stored_in_db()) {
continue;
}
......@@ -10986,10 +10986,8 @@ innodb_base_col_setup_for_stored(
for (uint i= 0; i < field->table->s->fields; ++i) {
const Field* base_field = field->table->field[i];
if (!innobase_is_s_fld(base_field)
&& !innobase_is_v_fld(base_field)
&& bitmap_is_set(&field->table->tmp_set,
i)) {
if (!base_field->vcol_info
&& bitmap_is_set(&field->table->tmp_set, i)) {
ulint z;
for (z = 0; z < table->n_cols; z++) {
const char* name = dict_table_get_col_name(
......@@ -11367,17 +11365,16 @@ create_index(
key->user_defined_key_parts);
for (ulint i = 0; i < key->user_defined_key_parts; i++) {
KEY_PART_INFO* key_part = key->key_part + i;
const Field* field = key->key_part[i].field;
/* We do not support special (Fulltext or Spatial)
index on virtual columns */
if (innobase_is_v_fld(key_part->field)) {
if (!field->stored_in_db()) {
ut_ad(0);
DBUG_RETURN(HA_ERR_UNSUPPORTED);
}
dict_mem_index_add_field(
index, key_part->field->field_name, 0);
dict_mem_index_add_field(index, field->field_name, 0);
}
DBUG_RETURN(convert_error_code_to_mysql(
......@@ -11465,7 +11462,7 @@ create_index(
field_lengths[i] = key_part->length;
if (innobase_is_v_fld(key_part->field)) {
if (!key_part->field->stored_in_db()) {
index->type |= DICT_VIRTUAL;
}
......@@ -12502,19 +12499,17 @@ create_table_info_t::gcols_in_fulltext_or_spatial()
{
for (ulint i = 0; i < m_form->s->keys; i++) {
const KEY* key = m_form->key_info + i;
if (key->flags & (HA_SPATIAL | HA_FULLTEXT)) {
for (ulint j = 0; j < key->user_defined_key_parts; j++) {
const KEY_PART_INFO* key_part = key->key_part + j;
/* We do not support special (Fulltext or
Spatial) index on virtual columns */
if (innobase_is_v_fld(key_part->field)) {
my_error(ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN, MYF(0));
return true;
}
if (!(key->flags & (HA_SPATIAL | HA_FULLTEXT))) {
continue;
}
for (ulint j = 0; j < key->user_defined_key_parts; j++) {
/* We do not support special (Fulltext or
Spatial) index on virtual columns */
if (!key->key_part[j].field->stored_in_db()) {
my_error(ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN, MYF(0));
return true;
}
}
}
return false;
}
......@@ -12820,7 +12815,7 @@ create_table_info_t::create_table_update_dict()
}
if (const Field* ai = m_form->found_next_number_field) {
ut_ad(!innobase_is_v_fld(ai));
ut_ad(ai->stored_in_db());
ib_uint64_t autoinc = m_create_info->auto_increment_value;
......
......@@ -846,10 +846,8 @@ innodb_base_col_setup_for_stored(
const Field* field,
dict_s_col_t* s_col);
/** whether this is a stored column */
/** whether this is a stored generated column */
#define innobase_is_s_fld(field) ((field)->vcol_info && (field)->stored_in_db())
/** whether this is a computed virtual column */
#define innobase_is_v_fld(field) ((field)->vcol_info && !(field)->stored_in_db())
/** Always normalize table name to lower case on Windows */
#ifdef _WIN32
......
......@@ -485,7 +485,7 @@ check_v_col_in_order(
cf_it.rewind();
while (const Create_field* new_field = cf_it++) {
if (!innobase_is_v_fld(new_field)) {
if (new_field->stored_in_db()) {
continue;
}
......@@ -517,8 +517,6 @@ check_v_col_in_order(
continue;
}
ut_ad(innobase_is_v_fld(field));
if (field->flags & FIELD_IS_DROPPED) {
continue;
}
......@@ -859,7 +857,7 @@ ha_innobase::check_if_supported_inplace_alter(
online = false;
}
if (innobase_is_v_fld(key_part->field)) {
if (!key_part->field->stored_in_db()) {
/* Do not support adding index on newly added
virtual column, while there is also a drop
virtual column in the same clause */
......@@ -1288,7 +1286,7 @@ innobase_find_equiv_index(
/* Any index on virtual columns cannot be used
for reference constaint */
if (innobase_is_v_fld(key_part.field)) {
if (!key_part.field->stored_in_db()) {
goto no_match;
}
......@@ -1864,21 +1862,15 @@ innobase_fields_to_mysql(
for (uint i = 0; i < n_fields; i++) {
Field* field = table->field[i];
ulint ipos;
ulint col_n;
ulint prefix_col;
field->reset();
if (innobase_is_v_fld(field)) {
col_n = num_v;
num_v++;
} else {
col_n = i - num_v;
}
const bool is_v = !field->stored_in_db();
const ulint col_n = is_v ? num_v++ : i - num_v;
ipos = dict_index_get_nth_col_or_prefix_pos(
index, col_n, true, innobase_is_v_fld(field),
&prefix_col);
index, col_n, true, is_v, &prefix_col);
if (ipos == ULINT_UNDEFINED
|| dfield_is_ext(&fields[ipos])
......@@ -1924,7 +1916,7 @@ innobase_row_to_mysql(
field->reset();
if (innobase_is_v_fld(field)) {
if (!field->stored_in_db()) {
/* Virtual column are not stored in InnoDB table, so
skip it */
num_v++;
......@@ -2150,7 +2142,7 @@ innobase_create_index_field_def(
: key_part->field;
for (ulint i = 0; i < key_part->fieldnr; i++) {
if (innobase_is_v_fld(altered_table->field[i])) {
if (!altered_table->field[i]->stored_in_db()) {
num_v++;
}
}
......@@ -2158,11 +2150,9 @@ innobase_create_index_field_def(
col_type = get_innobase_type_from_mysql_type(
&is_unsigned, field);
if (innobase_is_v_fld(field)) {
index_field->is_v_col = true;
if ((index_field->is_v_col = !field->stored_in_db())) {
index_field->col_no = num_v;
} else {
index_field->is_v_col = false;
index_field->col_no = key_part->fieldnr - num_v;
}
......@@ -2264,24 +2254,15 @@ innobase_create_index_def(
/* Need to count the virtual fields before this spatial
indexed field */
for (ulint i = 0; i < key->key_part->fieldnr; i++) {
if (innobase_is_v_fld(altered_table->field[i])) {
num_v++;
}
num_v += !altered_table->field[i]->stored_in_db();
}
index->fields[0].col_no = key->key_part[0].fieldnr - num_v;
index->fields[0].prefix_len = 0;
index->fields[0].is_v_col = false;
if (innobase_is_v_fld(key->key_part[0].field)) {
/* Currently, the spatial index cannot be created
on virtual columns. It is blocked in server
layer */
ut_ad(0);
index->fields[0].is_v_col = true;
} else {
index->fields[0].is_v_col = false;
}
/* Currently, the spatial index cannot be created
on virtual columns. It is blocked in the SQL layer. */
DBUG_ASSERT(key->key_part[0].field->stored_in_db());
} else {
index->ind_type = (key->flags & HA_NOSAME) ? DICT_UNIQUE : 0;
}
......@@ -2329,7 +2310,7 @@ innobase_fts_check_doc_id_col(
for (i = 0; i < n_cols; i++) {
const Field* field = altered_table->field[i];
if (innobase_is_v_fld(field)) {
if (!field->stored_in_db()) {
(*num_v)++;
}
......@@ -2345,7 +2326,7 @@ innobase_fts_check_doc_id_col(
|| field->pack_length() != 8
|| field->real_maybe_null()
|| !(field->flags & UNSIGNED_FLAG)
|| innobase_is_v_fld(field)) {
|| !field->stored_in_db()) {
my_error(ER_INNODB_FT_WRONG_DOCID_COLUMN, MYF(0),
field->field_name);
} else {
......@@ -3082,17 +3063,12 @@ innobase_build_col_map(
}
while (const Create_field* new_field = cf_it++) {
bool is_v = false;
if (innobase_is_v_fld(new_field)) {
is_v = true;
}
bool is_v = !new_field->stored_in_db();
ulint num_old_v = 0;
for (uint old_i = 0; table->field[old_i]; old_i++) {
const Field* field = table->field[old_i];
if (innobase_is_v_fld(field)) {
if (!field->stored_in_db()) {
if (is_v && new_field->field == field) {
col_map[old_table->n_cols + num_v]
= num_old_v;
......@@ -3236,14 +3212,12 @@ innobase_get_col_names(
ulint num_v = 0;
DBUG_ASSERT(i < altered_table->s->fields);
if (innobase_is_v_fld(new_field)) {
if (!new_field->stored_in_db()) {
continue;
}
for (uint old_i = 0; table->field[old_i]; old_i++) {
if (innobase_is_v_fld(table->field[old_i])) {
num_v++;
}
num_v += !table->field[old_i]->stored_in_db();
if (new_field->field == table->field[old_i]) {
cols[old_i - num_v] = new_field->field_name;
......@@ -3528,7 +3502,7 @@ innobase_check_gis_columns(
const KEY_PART_INFO& key_part = key.key_part[0];
/* Does not support spatial index on virtual columns */
if (innobase_is_v_fld(key_part.field)) {
if (!key_part.field->stored_in_db()) {
DBUG_RETURN(DB_UNSUPPORTED);
}
......@@ -3629,7 +3603,7 @@ prepare_inplace_add_virtual(
&is_unsigned, field);
if (!innobase_is_v_fld(field)) {
if (field->stored_in_db()) {
continue;
}
......@@ -4268,7 +4242,7 @@ innodb_v_adjust_idx_col(
/* Found the field in the new table */
while (const Create_field* new_field = cf_it++) {
if (!innobase_is_v_fld(new_field)) {
if (new_field->stored_in_db()) {
continue;
}
......@@ -4288,7 +4262,7 @@ innodb_v_adjust_idx_col(
ut_a(0);
}
ut_ad(innobase_is_v_fld(field));
ut_ad(!field->stored_in_db());
num_v = 0;
......@@ -4302,9 +4276,7 @@ innodb_v_adjust_idx_col(
break;
}
if (innobase_is_v_fld(old_table->field[old_i])) {
num_v++;
}
num_v += !old_table->field[old_i]->stored_in_db();
}
ut_ad(col_found);
......@@ -4577,10 +4549,10 @@ prepare_inplace_alter_table_dict(
for (uint i = 0; i < altered_table->s->fields; i++) {
const Field* field = altered_table->field[i];
if (innobase_is_v_fld(field)) {
if (!field->stored_in_db()) {
n_v_cols++;
} else {
n_cols++;
n_cols++;
}
}
......@@ -4632,7 +4604,7 @@ prepare_inplace_alter_table_dict(
&is_unsigned, field);
ulint charset_no;
ulint col_len;
bool is_virtual = innobase_is_v_fld(field);
const bool is_virtual = !field->stored_in_db();
/* we assume in dtype_form_prtype() that this
fits in two bytes */
......@@ -4717,7 +4689,7 @@ prepare_inplace_alter_table_dict(
dict_v_col_t* v_col;
const Field* field = altered_table->field[i];
if (!innobase_is_v_fld(field)) {
if (!!field->stored_in_db()) {
continue;
}
v_col = dict_table_get_nth_v_col(
......@@ -5471,7 +5443,7 @@ alter_fill_stored_column(
Field* field = altered_table->field[i];
dict_s_col_t s_col;
if (!innobase_is_v_fld(field)) {
if (field->stored_in_db()) {
stored_col_no++;
}
......@@ -5721,7 +5693,7 @@ ha_innobase::prepare_inplace_alter_table(
MySQL should have checked these already.
We want to allow renaming of c1 to c2, c2 to c1. */
for (j = 0; j < table->s->fields; j++) {
if (!innobase_is_v_fld(table->field[j])) {
if (table->field[j]->stored_in_db()) {
s += strlen(s) + 1;
}
}
......@@ -6267,10 +6239,7 @@ ha_innobase::prepare_inplace_alter_table(
autoinc_col_max_value = innobase_get_int_col_max_value(field);
}
found_col:
if (innobase_is_v_fld(new_field)) {
++num_v;
}
num_v += !new_field->stored_in_db();
i++;
}
......@@ -7172,13 +7141,13 @@ innobase_rename_columns_try(
& Alter_inplace_info::ALTER_COLUMN_NAME);
for (Field** fp = table->field; *fp; fp++, i++) {
bool is_virtual = innobase_is_v_fld(*fp);
const bool is_virtual = !(*fp)->stored_in_db();
if (!((*fp)->flags & FIELD_IS_RENAMED)) {
goto processed_field;
}
cf_it.rewind();
while (Create_field* cf = cf_it++) {
if (cf->field == *fp) {
ulint col_n = is_virtual
......@@ -7331,19 +7300,10 @@ innobase_enlarge_columns_try(
ha_alter_info->alter_info->create_list);
ulint i = 0;
ulint num_v = 0;
bool is_v;
for (Field** fp = table->field; *fp; fp++, i++) {
ulint idx;
if (innobase_is_v_fld(*fp)) {
is_v = true;
idx = num_v;
num_v++;
} else {
idx = i - num_v;
is_v = false;
}
const bool is_v = !(*fp)->stored_in_db();
ulint idx = is_v ? num_v++ : i - num_v;
cf_it.rewind();
while (Create_field* cf = cf_it++) {
......@@ -7389,7 +7349,7 @@ innobase_rename_or_enlarge_columns_cache(
ulint num_v = 0;
for (Field** fp = table->field; *fp; fp++, i++) {
bool is_virtual = innobase_is_v_fld(*fp);
const bool is_virtual = !(*fp)->stored_in_db();
cf_it.rewind();
while (Create_field* cf = cf_it++) {
......
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