Skip to content

Commit

Permalink
cleanup: remove vcol_info->stored_in_db
Browse files Browse the repository at this point in the history
it was redundant, duplicating vcol_type == VCOL_GENERATED_STORED.

Note that VCOL_DEFAULT is not "stored", "stored vcol" means that after
rnd_next or index_read/etc the field value is already in the record[0]
and does not need to be calculated separately
  • Loading branch information
vuvova committed Aug 15, 2023
1 parent 9545eb9 commit 275684d
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 37 deletions.
2 changes: 1 addition & 1 deletion sql/field.cc
Expand Up @@ -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);
}
Expand Down
14 changes: 5 additions & 9 deletions sql/field.h
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -1433,7 +1429,7 @@ class Field: public Value_source
null_bit= static_cast<uchar>(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
Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion sql/item.h
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions sql/sql_show.cc
Expand Up @@ -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"));
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_table.cc
Expand Up @@ -2605,7 +2605,7 @@ static Create_field * add_hash_field(THD * thd, List<Create_field> *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);
Expand Down
8 changes: 4 additions & 4 deletions sql/sql_yacc.yy
Expand Up @@ -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);
}
;

Expand Down
29 changes: 12 additions & 17 deletions sql/table.cc
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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++;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)))
{
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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));
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion sql/unireg.cc
Expand Up @@ -802,7 +802,7 @@ static bool pack_vcols(String *buf, List<Create_field> &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())
Expand Down
2 changes: 1 addition & 1 deletion storage/myisam/ha_myisam.cc
Expand Up @@ -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);
Expand Down

0 comments on commit 275684d

Please sign in to comment.