diff --git a/sql/field.cc b/sql/field.cc index 2418d692c72e9..8b30c6a71ed0f 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -10653,7 +10653,7 @@ bool Column_definition::check(THD *thd) { DBUG_ASSERT(vcol_info->expr); vcol_info->set_handler(type_handler()); - if (check_expression(vcol_info, &field_name, vcol_info->stored_in_db + if (check_expression(vcol_info, &field_name, vcol_info->is_stored() ? VCOL_GENERATED_STORED : VCOL_GENERATED_VIRTUAL)) DBUG_RETURN(TRUE); } diff --git a/sql/field.h b/sql/field.h index 0a875ca100b37..e6f66280ed1f8 100644 --- a/sql/field.h +++ b/sql/field.h @@ -586,7 +586,6 @@ class Virtual_column_info: public Sql_alloc, public: /* Flag indicating that the field is physically stored in the database */ - bool stored_in_db; bool utf8; /* Already in utf8 */ bool automatic_name; bool if_not_exists; @@ -598,7 +597,7 @@ class Virtual_column_info: public Sql_alloc, Virtual_column_info() :Type_handler_hybrid_field_type(&type_handler_null), vcol_type((enum_vcol_info_type)VCOL_TYPE_NONE), - in_partitioning_expr(FALSE), stored_in_db(FALSE), + in_partitioning_expr(FALSE), utf8(TRUE), automatic_name(FALSE), expr(NULL), flags(0) { name.str= NULL; @@ -627,11 +626,8 @@ class Virtual_column_info: public Sql_alloc, } bool is_stored() const { - return stored_in_db; - } - void set_stored_in_db_flag(bool stored) - { - stored_in_db= stored; + /* after reading the row vcol value is already in the buffer */ + return vcol_type == VCOL_GENERATED_STORED; } bool is_in_partitioning_expr() const { @@ -1433,7 +1429,7 @@ class Field: public Value_source null_bit= static_cast(p_null_bit); } - bool stored_in_db() const { return !vcol_info || vcol_info->stored_in_db; } + bool stored_in_db() const { return !vcol_info || vcol_info->is_stored(); } bool check_vcol_sql_mode_dependency(THD *, vcol_init_mode mode) const; virtual sql_mode_t value_depends_on_sql_mode() const @@ -5423,7 +5419,7 @@ class Column_definition: public Sql_alloc, bool check(THD *thd); bool validate_check_constraint(THD *thd); - bool stored_in_db() const { return !vcol_info || vcol_info->stored_in_db; } + bool stored_in_db() const { return !vcol_info || vcol_info->is_stored(); } ha_storage_media field_storage_type() const { diff --git a/sql/item.h b/sql/item.h index 60755abc61711..4ebfcfa88d8ed 100644 --- a/sql/item.h +++ b/sql/item.h @@ -7821,7 +7821,7 @@ bool fix_escape_item(THD *thd, Item *escape_item, String *tmp_str, inline bool Virtual_column_info::is_equal(const Virtual_column_info* vcol) const { return type_handler() == vcol->type_handler() - && stored_in_db == vcol->is_stored() + && is_stored() == vcol->is_stored() && expr->eq(vcol->expr, true); } diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 8b8ecf526ba92..d5a5c93d46bf9 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2227,7 +2227,7 @@ int show_create_table_ex(THD *thd, TABLE_LIST *table_list, packet->append(STRING_WITH_LEN(" GENERATED ALWAYS AS (")); packet->append(str); packet->append(STRING_WITH_LEN(")")); - if (field->vcol_info->stored_in_db) + if (field->vcol_info->is_stored()) packet->append(STRING_WITH_LEN(" STORED")); else packet->append(STRING_WITH_LEN(" VIRTUAL")); @@ -6269,7 +6269,7 @@ static int get_schema_column_record(THD *thd, TABLE_LIST *tables, table->field[21]->set_notnull(); table->field[20]->store(STRING_WITH_LEN("ALWAYS"), cs); - if (field->vcol_info->stored_in_db) + if (field->vcol_info->is_stored()) buf.set(STRING_WITH_LEN("STORED GENERATED"), cs); else buf.set(STRING_WITH_LEN("VIRTUAL GENERATED"), cs); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 173ae9396b0c4..6ed7e9cbe75f0 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2605,7 +2605,7 @@ static Create_field * add_hash_field(THD * thd, List *create_list, cf->invisible= INVISIBLE_FULL; cf->pack_flag|= FIELDFLAG_MAYBE_NULL; cf->vcol_info= new (thd->mem_root) Virtual_column_info(); - cf->vcol_info->stored_in_db= false; + cf->vcol_info->set_vcol_type(VCOL_GENERATED_VIRTUAL); uint num= 1; LEX_CSTRING field_name; field_name.str= (char *)thd->alloc(LONG_HASH_FIELD_NAME_LENGTH); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index d76f98acefeee..78b6362f5fa7a 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -5980,19 +5980,19 @@ opt_generated_always: vcol_opt_specifier: /* empty */ { - Lex->last_field->vcol_info->set_stored_in_db_flag(FALSE); + Lex->last_field->vcol_info->set_vcol_type(VCOL_GENERATED_VIRTUAL); } | VIRTUAL_SYM { - Lex->last_field->vcol_info->set_stored_in_db_flag(FALSE); + Lex->last_field->vcol_info->set_vcol_type(VCOL_GENERATED_VIRTUAL); } | PERSISTENT_SYM { - Lex->last_field->vcol_info->set_stored_in_db_flag(TRUE); + Lex->last_field->vcol_info->set_vcol_type(VCOL_GENERATED_STORED); } | STORED_SYM { - Lex->last_field->vcol_info->set_stored_in_db_flag(TRUE); + Lex->last_field->vcol_info->set_vcol_type(VCOL_GENERATED_STORED); } ; diff --git a/sql/table.cc b/sql/table.cc index e6b3313817c36..33d38041f5fc4 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1192,7 +1192,7 @@ bool parse_vcol_defs(THD *thd, MEM_ROOT *mem_root, TABLE *table, open_table_error(table->s, OPEN_FRM_CORRUPTED, 1); goto end; } - type= (*field_ptr)->vcol_info->stored_in_db + type= (*field_ptr)->vcol_info->is_stored() ? VCOL_GENERATED_STORED : VCOL_GENERATED_VIRTUAL; expr_length= uint2korr(pos+1); if (table->s->mysql_version > 50700 && table->s->mysql_version < 100000) @@ -2489,7 +2489,6 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, else if ((uint)vcol_screen_pos[0] != 1) goto err; bool stored= vcol_screen_pos[2] & 1; - vcol_info->stored_in_db= stored; vcol_info->set_vcol_type(stored ? VCOL_GENERATED_STORED : VCOL_GENERATED_VIRTUAL); uint vcol_expr_length= vcol_info_length - (uint)(FRM_VCOL_OLD_HEADER_SIZE(opt_interval_id)); @@ -2570,7 +2569,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, uint vcol_info_length= uint2korr(vcol_screen_pos + 1); if (!vcol_info_length) // Expect non-empty expression goto err; - vcol_info->stored_in_db= vcol_screen_pos[3]; + vcol_info->set_vcol_type(vcol_screen_pos[3] ? VCOL_GENERATED_STORED : VCOL_GENERATED_VIRTUAL); vcol_info->utf8= 0; vcol_screen_pos+= vcol_info_length + MYSQL57_GCOL_HEADER_SIZE;; share->virtual_fields++; @@ -2670,7 +2669,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, } #endif - if (mysql57_null_bits && vcol_info && !vcol_info->stored_in_db) + if (mysql57_null_bits && vcol_info && !vcol_info->is_stored()) { swap_variables(uchar*, null_pos, mysql57_vcol_null_pos); swap_variables(uint, null_bit_pos, mysql57_vcol_null_bit_pos); @@ -2727,7 +2726,6 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, { reg_field->default_value= new (&share->mem_root) Virtual_column_info(); reg_field->default_value->set_vcol_type(VCOL_DEFAULT); - reg_field->default_value->stored_in_db= 1; share->default_expressions++; } @@ -2766,7 +2764,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, if (vcol_info) { vcol_info->name= reg_field->field_name; - if (mysql57_null_bits && !vcol_info->stored_in_db) + if (mysql57_null_bits && !vcol_info->is_stored()) { /* MySQL 5.7 has null bits last */ swap_variables(uchar*, null_pos, mysql57_vcol_null_pos); @@ -3341,13 +3339,11 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, break; } case VCOL_GENERATED_STORED: - vcol_info->stored_in_db= 1; DBUG_ASSERT(!reg_field->vcol_info); reg_field->vcol_info= vcol_info; share->virtual_fields++; break; case VCOL_DEFAULT: - vcol_info->stored_in_db= 1; DBUG_ASSERT(!reg_field->default_value); reg_field->default_value= vcol_info; share->default_expressions++; @@ -4014,7 +4010,6 @@ unpack_vcol_info_from_frm(THD *thd, TABLE *table, } vcol_storage.vcol_info->set_vcol_type(vcol->get_vcol_type()); - vcol_storage.vcol_info->stored_in_db= vcol->stored_in_db; vcol_storage.vcol_info->name= vcol->name; vcol_storage.vcol_info->utf8= vcol->utf8; if (!vcol_storage.vcol_info->fix_and_check_expr(thd, table)) @@ -8005,7 +8000,7 @@ bool TABLE::mark_virtual_columns_for_write(bool insert_fl tmp_vfield= *vfield_ptr; if (bitmap_is_set(write_set, tmp_vfield->field_index)) bitmap_updated|= mark_virtual_column_with_deps(tmp_vfield); - else if (tmp_vfield->vcol_info->stored_in_db || + else if (tmp_vfield->vcol_info->is_stored() || (tmp_vfield->flags & (PART_KEY_FLAG | FIELD_IN_PART_FUNC_FLAG | PART_INDIRECT_KEY_FLAG))) { @@ -8036,7 +8031,7 @@ bool TABLE::check_virtual_columns_marked_for_read() { Field *tmp_vfield= *vfield_ptr; if (bitmap_is_set(read_set, tmp_vfield->field_index) && - !tmp_vfield->vcol_info->stored_in_db) + !tmp_vfield->vcol_info->is_stored()) return TRUE; } } @@ -8063,7 +8058,7 @@ bool TABLE::check_virtual_columns_marked_for_write() { Field *tmp_vfield= *vfield_ptr; if (bitmap_is_set(write_set, tmp_vfield->field_index) && - tmp_vfield->vcol_info->stored_in_db) + tmp_vfield->vcol_info->is_stored()) return TRUE; } } @@ -8193,7 +8188,7 @@ void TABLE::remember_blob_values(String *blob_storage) for (vfield_ptr= vfield; *vfield_ptr; vfield_ptr++) { if ((*vfield_ptr)->type() == MYSQL_TYPE_BLOB && - !(*vfield_ptr)->vcol_info->stored_in_db) + !(*vfield_ptr)->vcol_info->is_stored()) { Field_blob *blob= ((Field_blob*) *vfield_ptr); memcpy((void*) blob_storage, (void*) &blob->value, sizeof(blob->value)); @@ -8216,7 +8211,7 @@ void TABLE::restore_blob_values(String *blob_storage) for (vfield_ptr= vfield; *vfield_ptr; vfield_ptr++) { if ((*vfield_ptr)->type() == MYSQL_TYPE_BLOB && - !(*vfield_ptr)->vcol_info->stored_in_db) + !(*vfield_ptr)->vcol_info->is_stored()) { Field_blob *blob= ((Field_blob*) *vfield_ptr); blob->value.free(); @@ -9041,7 +9036,7 @@ int TABLE::update_virtual_fields(handler *h, enum_vcol_update_mode update_mode) bool update= 0, swap_values= 0; switch (update_mode) { case VCOL_UPDATE_FOR_READ: - update= (!vcol_info->stored_in_db && + update= (!vcol_info->is_stored() && bitmap_is_set(read_set, vf->field_index)); swap_values= 1; break; @@ -9050,7 +9045,7 @@ int TABLE::update_virtual_fields(handler *h, enum_vcol_update_mode update_mode) update= bitmap_is_set(read_set, vf->field_index); break; case VCOL_UPDATE_FOR_REPLACE: - update= ((!vcol_info->stored_in_db && + update= ((!vcol_info->is_stored() && (vf->flags & (PART_KEY_FLAG | PART_INDIRECT_KEY_FLAG)) && bitmap_is_set(read_set, vf->field_index)) || update_all_columns); @@ -9070,7 +9065,7 @@ int TABLE::update_virtual_fields(handler *h, enum_vcol_update_mode update_mode) case VCOL_UPDATE_INDEXED: case VCOL_UPDATE_INDEXED_FOR_UPDATE: /* Read indexed fields that was not updated in VCOL_UPDATE_FOR_READ */ - update= (!vcol_info->stored_in_db && + update= (!vcol_info->is_stored() && (vf->flags & (PART_KEY_FLAG | PART_INDIRECT_KEY_FLAG)) && !bitmap_is_set(read_set, vf->field_index)); swap_values= 1; diff --git a/sql/unireg.cc b/sql/unireg.cc index e6f52cd953e81..783c273f8b7c8 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -802,7 +802,7 @@ static bool pack_vcols(String *buf, List &create_fields, { if (field->vcol_info && field->vcol_info->expr) if (pack_expression(buf, field->vcol_info, field_nr, - field->vcol_info->stored_in_db + field->vcol_info->is_stored() ? VCOL_GENERATED_STORED : VCOL_GENERATED_VIRTUAL)) return 1; if (field->has_default_expression() && !field->has_default_now_unireg_check()) diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index b1b1e8fd57e82..4057c3ea8599d 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -730,7 +730,7 @@ static int compute_vcols(MI_INFO *info, uchar *record, int keynum) for (; kp < end; kp++) { Field *f= table->field[kp->fieldnr - 1]; - if (f->vcol_info && !f->vcol_info->stored_in_db) + if (f->vcol_info && !f->vcol_info->is_stored()) table->update_virtual_field(f, false); } mysql_mutex_unlock(&info->s->intern_lock);