1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

cleanup: remove vcol_info->stored_in_db

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
This commit is contained in:
Sergei Golubchik
2022-11-27 17:03:29 +01:00
parent 9545eb969e
commit 275684d8fe
9 changed files with 28 additions and 37 deletions

View File

@@ -10653,7 +10653,7 @@ bool Column_definition::check(THD *thd)
{ {
DBUG_ASSERT(vcol_info->expr); DBUG_ASSERT(vcol_info->expr);
vcol_info->set_handler(type_handler()); 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)) ? VCOL_GENERATED_STORED : VCOL_GENERATED_VIRTUAL))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }

View File

@@ -586,7 +586,6 @@ private:
public: public:
/* Flag indicating that the field is physically stored in the database */ /* Flag indicating that the field is physically stored in the database */
bool stored_in_db;
bool utf8; /* Already in utf8 */ bool utf8; /* Already in utf8 */
bool automatic_name; bool automatic_name;
bool if_not_exists; bool if_not_exists;
@@ -598,7 +597,7 @@ public:
Virtual_column_info() Virtual_column_info()
:Type_handler_hybrid_field_type(&type_handler_null), :Type_handler_hybrid_field_type(&type_handler_null),
vcol_type((enum_vcol_info_type)VCOL_TYPE_NONE), 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) utf8(TRUE), automatic_name(FALSE), expr(NULL), flags(0)
{ {
name.str= NULL; name.str= NULL;
@@ -627,11 +626,8 @@ public:
} }
bool is_stored() const bool is_stored() const
{ {
return stored_in_db; /* after reading the row vcol value is already in the buffer */
} return vcol_type == VCOL_GENERATED_STORED;
void set_stored_in_db_flag(bool stored)
{
stored_in_db= stored;
} }
bool is_in_partitioning_expr() const bool is_in_partitioning_expr() const
{ {
@@ -1433,7 +1429,7 @@ public:
null_bit= static_cast<uchar>(p_null_bit); 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; bool check_vcol_sql_mode_dependency(THD *, vcol_init_mode mode) const;
virtual sql_mode_t value_depends_on_sql_mode() const virtual sql_mode_t value_depends_on_sql_mode() const
@@ -5423,7 +5419,7 @@ public:
bool check(THD *thd); bool check(THD *thd);
bool validate_check_constraint(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 ha_storage_media field_storage_type() const
{ {

View File

@@ -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 inline bool Virtual_column_info::is_equal(const Virtual_column_info* vcol) const
{ {
return type_handler() == vcol->type_handler() return type_handler() == vcol->type_handler()
&& stored_in_db == vcol->is_stored() && is_stored() == vcol->is_stored()
&& expr->eq(vcol->expr, true); && expr->eq(vcol->expr, true);
} }

View File

@@ -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(STRING_WITH_LEN(" GENERATED ALWAYS AS ("));
packet->append(str); packet->append(str);
packet->append(STRING_WITH_LEN(")")); packet->append(STRING_WITH_LEN(")"));
if (field->vcol_info->stored_in_db) if (field->vcol_info->is_stored())
packet->append(STRING_WITH_LEN(" STORED")); packet->append(STRING_WITH_LEN(" STORED"));
else else
packet->append(STRING_WITH_LEN(" VIRTUAL")); 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[21]->set_notnull();
table->field[20]->store(STRING_WITH_LEN("ALWAYS"), cs); 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); buf.set(STRING_WITH_LEN("STORED GENERATED"), cs);
else else
buf.set(STRING_WITH_LEN("VIRTUAL GENERATED"), cs); buf.set(STRING_WITH_LEN("VIRTUAL GENERATED"), cs);

View File

@@ -2605,7 +2605,7 @@ static Create_field * add_hash_field(THD * thd, List<Create_field> *create_list,
cf->invisible= INVISIBLE_FULL; cf->invisible= INVISIBLE_FULL;
cf->pack_flag|= FIELDFLAG_MAYBE_NULL; cf->pack_flag|= FIELDFLAG_MAYBE_NULL;
cf->vcol_info= new (thd->mem_root) Virtual_column_info(); 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; uint num= 1;
LEX_CSTRING field_name; LEX_CSTRING field_name;
field_name.str= (char *)thd->alloc(LONG_HASH_FIELD_NAME_LENGTH); field_name.str= (char *)thd->alloc(LONG_HASH_FIELD_NAME_LENGTH);

View File

@@ -5980,19 +5980,19 @@ opt_generated_always:
vcol_opt_specifier: vcol_opt_specifier:
/* empty */ /* 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 | 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 | 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 | STORED_SYM
{ {
Lex->last_field->vcol_info->set_stored_in_db_flag(TRUE); Lex->last_field->vcol_info->set_vcol_type(VCOL_GENERATED_STORED);
} }
; ;

View File

@@ -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); open_table_error(table->s, OPEN_FRM_CORRUPTED, 1);
goto end; goto end;
} }
type= (*field_ptr)->vcol_info->stored_in_db type= (*field_ptr)->vcol_info->is_stored()
? VCOL_GENERATED_STORED : VCOL_GENERATED_VIRTUAL; ? VCOL_GENERATED_STORED : VCOL_GENERATED_VIRTUAL;
expr_length= uint2korr(pos+1); expr_length= uint2korr(pos+1);
if (table->s->mysql_version > 50700 && table->s->mysql_version < 100000) 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) else if ((uint)vcol_screen_pos[0] != 1)
goto err; goto err;
bool stored= vcol_screen_pos[2] & 1; 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); vcol_info->set_vcol_type(stored ? VCOL_GENERATED_STORED : VCOL_GENERATED_VIRTUAL);
uint vcol_expr_length= vcol_info_length - uint vcol_expr_length= vcol_info_length -
(uint)(FRM_VCOL_OLD_HEADER_SIZE(opt_interval_id)); (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); uint vcol_info_length= uint2korr(vcol_screen_pos + 1);
if (!vcol_info_length) // Expect non-empty expression if (!vcol_info_length) // Expect non-empty expression
goto err; 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_info->utf8= 0;
vcol_screen_pos+= vcol_info_length + MYSQL57_GCOL_HEADER_SIZE;; vcol_screen_pos+= vcol_info_length + MYSQL57_GCOL_HEADER_SIZE;;
share->virtual_fields++; share->virtual_fields++;
@@ -2670,7 +2669,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
} }
#endif #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(uchar*, null_pos, mysql57_vcol_null_pos);
swap_variables(uint, null_bit_pos, mysql57_vcol_null_bit_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= new (&share->mem_root) Virtual_column_info();
reg_field->default_value->set_vcol_type(VCOL_DEFAULT); reg_field->default_value->set_vcol_type(VCOL_DEFAULT);
reg_field->default_value->stored_in_db= 1;
share->default_expressions++; share->default_expressions++;
} }
@@ -2766,7 +2764,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
if (vcol_info) if (vcol_info)
{ {
vcol_info->name= reg_field->field_name; 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 */ /* MySQL 5.7 has null bits last */
swap_variables(uchar*, null_pos, mysql57_vcol_null_pos); 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; break;
} }
case VCOL_GENERATED_STORED: case VCOL_GENERATED_STORED:
vcol_info->stored_in_db= 1;
DBUG_ASSERT(!reg_field->vcol_info); DBUG_ASSERT(!reg_field->vcol_info);
reg_field->vcol_info= vcol_info; reg_field->vcol_info= vcol_info;
share->virtual_fields++; share->virtual_fields++;
break; break;
case VCOL_DEFAULT: case VCOL_DEFAULT:
vcol_info->stored_in_db= 1;
DBUG_ASSERT(!reg_field->default_value); DBUG_ASSERT(!reg_field->default_value);
reg_field->default_value= vcol_info; reg_field->default_value= vcol_info;
share->default_expressions++; 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->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->name= vcol->name;
vcol_storage.vcol_info->utf8= vcol->utf8; vcol_storage.vcol_info->utf8= vcol->utf8;
if (!vcol_storage.vcol_info->fix_and_check_expr(thd, table)) 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; tmp_vfield= *vfield_ptr;
if (bitmap_is_set(write_set, tmp_vfield->field_index)) if (bitmap_is_set(write_set, tmp_vfield->field_index))
bitmap_updated|= mark_virtual_column_with_deps(tmp_vfield); 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 | (tmp_vfield->flags & (PART_KEY_FLAG | FIELD_IN_PART_FUNC_FLAG |
PART_INDIRECT_KEY_FLAG))) PART_INDIRECT_KEY_FLAG)))
{ {
@@ -8036,7 +8031,7 @@ bool TABLE::check_virtual_columns_marked_for_read()
{ {
Field *tmp_vfield= *vfield_ptr; Field *tmp_vfield= *vfield_ptr;
if (bitmap_is_set(read_set, tmp_vfield->field_index) && 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; return TRUE;
} }
} }
@@ -8063,7 +8058,7 @@ bool TABLE::check_virtual_columns_marked_for_write()
{ {
Field *tmp_vfield= *vfield_ptr; Field *tmp_vfield= *vfield_ptr;
if (bitmap_is_set(write_set, tmp_vfield->field_index) && 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; return TRUE;
} }
} }
@@ -8193,7 +8188,7 @@ void TABLE::remember_blob_values(String *blob_storage)
for (vfield_ptr= vfield; *vfield_ptr; vfield_ptr++) for (vfield_ptr= vfield; *vfield_ptr; vfield_ptr++)
{ {
if ((*vfield_ptr)->type() == MYSQL_TYPE_BLOB && 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); Field_blob *blob= ((Field_blob*) *vfield_ptr);
memcpy((void*) blob_storage, (void*) &blob->value, sizeof(blob->value)); 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++) for (vfield_ptr= vfield; *vfield_ptr; vfield_ptr++)
{ {
if ((*vfield_ptr)->type() == MYSQL_TYPE_BLOB && 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); Field_blob *blob= ((Field_blob*) *vfield_ptr);
blob->value.free(); 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; bool update= 0, swap_values= 0;
switch (update_mode) { switch (update_mode) {
case VCOL_UPDATE_FOR_READ: case VCOL_UPDATE_FOR_READ:
update= (!vcol_info->stored_in_db && update= (!vcol_info->is_stored() &&
bitmap_is_set(read_set, vf->field_index)); bitmap_is_set(read_set, vf->field_index));
swap_values= 1; swap_values= 1;
break; 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); update= bitmap_is_set(read_set, vf->field_index);
break; break;
case VCOL_UPDATE_FOR_REPLACE: 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)) && (vf->flags & (PART_KEY_FLAG | PART_INDIRECT_KEY_FLAG)) &&
bitmap_is_set(read_set, vf->field_index)) || bitmap_is_set(read_set, vf->field_index)) ||
update_all_columns); 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:
case VCOL_UPDATE_INDEXED_FOR_UPDATE: case VCOL_UPDATE_INDEXED_FOR_UPDATE:
/* Read indexed fields that was not updated in VCOL_UPDATE_FOR_READ */ /* 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)) && (vf->flags & (PART_KEY_FLAG | PART_INDIRECT_KEY_FLAG)) &&
!bitmap_is_set(read_set, vf->field_index)); !bitmap_is_set(read_set, vf->field_index));
swap_values= 1; swap_values= 1;

View File

@@ -802,7 +802,7 @@ static bool pack_vcols(String *buf, List<Create_field> &create_fields,
{ {
if (field->vcol_info && field->vcol_info->expr) if (field->vcol_info && field->vcol_info->expr)
if (pack_expression(buf, field->vcol_info, field_nr, 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)) ? VCOL_GENERATED_STORED : VCOL_GENERATED_VIRTUAL))
return 1; return 1;
if (field->has_default_expression() && !field->has_default_now_unireg_check()) if (field->has_default_expression() && !field->has_default_now_unireg_check())

View File

@@ -730,7 +730,7 @@ static int compute_vcols(MI_INFO *info, uchar *record, int keynum)
for (; kp < end; kp++) for (; kp < end; kp++)
{ {
Field *f= table->field[kp->fieldnr - 1]; 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); table->update_virtual_field(f, false);
} }
mysql_mutex_unlock(&info->s->intern_lock); mysql_mutex_unlock(&info->s->intern_lock);