Skip to content

Commit

Permalink
MDEV-24176 Preparations
Browse files Browse the repository at this point in the history
1. moved fix_vcol_exprs() call to open_table()

mysql_alter_table() doesn't do lock_tables() so it cannot win from
fix_vcol_exprs() from there. Tests affected: main.default_session

2. Vanilla cleanups and comments.
  • Loading branch information
midenok committed Apr 18, 2022
1 parent 7498978 commit c02ebf3
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 115 deletions.
4 changes: 4 additions & 0 deletions sql/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,10 @@ class Virtual_column_info: public Sql_alloc
{
in_partitioning_expr= TRUE;
}
bool fix_expr(THD *thd);
bool fix_session_expr(THD *thd);
bool fix_session_expr_for_read(THD *thd, Field *field);
bool fix_and_check_expr(THD *thd, TABLE *table);
inline bool is_equal(const Virtual_column_info* vcol) const;
inline void print(String*);
};
Expand Down
8 changes: 5 additions & 3 deletions sql/item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6376,8 +6376,9 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
}
#endif
fixed= 1;
if (field->vcol_info)
fix_session_vcol_expr_for_read(thd, field, field->vcol_info);
if (field->vcol_info &&
field->vcol_info->fix_session_expr_for_read(thd, field))
goto error;
if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY &&
!outer_fixed && !thd->lex->in_sum_func &&
select &&
Expand Down Expand Up @@ -9503,7 +9504,8 @@ bool Item_default_value::fix_fields(THD *thd, Item **items)
Even if DEFAULT() do not read tables fields, the default value
expression can do it.
*/
fix_session_vcol_expr_for_read(thd, def_field, def_field->default_value);
if (def_field->default_value->fix_session_expr_for_read(thd, def_field))
goto error;
if (should_mark_column(thd->column_usage))
def_field->default_value->expr->update_used_tables();
def_field->move_field(newptr+1, def_field->maybe_null() ? newptr : 0, 1);
Expand Down
6 changes: 6 additions & 0 deletions sql/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -2924,6 +2924,12 @@ class Item_ident :public Item_result_field
const char *db_name;
const char *table_name;
LEX_CSTRING field_name;
/*
NOTE: came from TABLE::alias_name_used and this is only a hint! It works
only in need_correct_ident() condition. On other cases it is FALSE even if
table_name is alias! It cannot be TRUE in these cases, lots of spaghetti
logic depends on that.
*/
bool alias_name_used; /* true if item was resolved against alias */
/*
Cached value of index for this field in table->field array, used by prep.
Expand Down
71 changes: 32 additions & 39 deletions sql/sql_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2040,6 +2040,9 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
table_list->updatable= 1; // It is not derived table nor non-updatable VIEW
table_list->table= table;

if (table->vcol_fix_exprs(thd))
goto err_lock;

#ifdef WITH_PARTITION_STORAGE_ENGINE
if (unlikely(table->part_info))
{
Expand Down Expand Up @@ -5290,52 +5293,44 @@ static void mark_real_tables_as_free_for_reuse(TABLE_LIST *table_list)
}
}

int TABLE::fix_vcol_exprs(THD *thd)
bool TABLE::vcol_fix_exprs(THD *thd)
{
if (pos_in_table_list->placeholder() || !s->vcols_need_refixing ||
pos_in_table_list->lock_type < TL_WRITE_ALLOW_WRITE)
return false;

DBUG_ASSERT(pos_in_table_list != thd->lex->first_not_own_table());

bool result= true;
Security_context *save_security_ctx= thd->security_ctx;
Query_arena *stmt_backup= thd->stmt_arena;
if (thd->stmt_arena->is_conventional())
thd->stmt_arena= expr_arena;

if (pos_in_table_list->security_ctx)
thd->security_ctx= pos_in_table_list->security_ctx;


for (Field **vf= vfield; vf && *vf; vf++)
if (fix_session_vcol_expr(thd, (*vf)->vcol_info))
return 1;
if ((*vf)->vcol_info->fix_session_expr(thd))
goto end;

for (Field **df= default_field; df && *df; df++)
if ((*df)->default_value &&
fix_session_vcol_expr(thd, (*df)->default_value))
return 1;
(*df)->default_value->fix_session_expr(thd))
goto end;

for (Virtual_column_info **cc= check_constraints; cc && *cc; cc++)
if (fix_session_vcol_expr(thd, (*cc)))
return 1;

return 0;
}


static bool fix_all_session_vcol_exprs(THD *thd, TABLE_LIST *tables)
{
Security_context *save_security_ctx= thd->security_ctx;
TABLE_LIST *first_not_own= thd->lex->first_not_own_table();
DBUG_ENTER("fix_session_vcol_expr");
if ((*cc)->fix_session_expr(thd))
goto end;

int error= 0;
for (TABLE_LIST *table= tables; table && table != first_not_own && !error;
table= table->next_global)
{
TABLE *t= table->table;
if (!table->placeholder() && t->s->vcols_need_refixing &&
table->lock_type >= TL_WRITE_ALLOW_WRITE)
{
Query_arena *stmt_backup= thd->stmt_arena;
if (thd->stmt_arena->is_conventional())
thd->stmt_arena= t->expr_arena;
if (table->security_ctx)
thd->security_ctx= table->security_ctx;
result= false;

error= t->fix_vcol_exprs(thd);
end:
thd->security_ctx= save_security_ctx;
thd->stmt_arena= stmt_backup;

thd->security_ctx= save_security_ctx;
thd->stmt_arena= stmt_backup;
}
}
DBUG_RETURN(error);
return result;
}


Expand Down Expand Up @@ -5500,9 +5495,7 @@ bool lock_tables(THD *thd, TABLE_LIST *tables, uint count,
}
}

bool res= fix_all_session_vcol_exprs(thd, tables);
if (!res)
res= thd->decide_logging_format(tables);
const bool res= thd->decide_logging_format(tables);

DBUG_RETURN(res);
}
Expand Down
13 changes: 0 additions & 13 deletions sql/sql_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5548,7 +5548,6 @@ that are reorganised.
my_error(ER_ROW_IS_REFERENCED, MYF(0));
goto err;
}
tab_part_info->num_parts-= num_parts_dropped;
}
else if (alter_info->partition_flags & ALTER_PARTITION_REBUILD)
{
Expand Down Expand Up @@ -6214,8 +6213,6 @@ static bool mysql_drop_partitions(ALTER_PARTITION_PARAM_TYPE *lpt)
char path[FN_REFLEN+1];
partition_info *part_info= lpt->table->part_info;
List_iterator<partition_element> part_it(part_info->partitions);
uint i= 0;
uint remove_count= 0;
int error;
DBUG_ENTER("mysql_drop_partitions");

Expand All @@ -6230,16 +6227,6 @@ static bool mysql_drop_partitions(ALTER_PARTITION_PARAM_TYPE *lpt)
lpt->table->file->print_error(error, MYF(0));
DBUG_RETURN(TRUE);
}
do
{
partition_element *part_elem= part_it++;
if (part_elem->part_state == PART_IS_DROPPED)
{
part_it.remove();
remove_count++;
}
} while (++i < part_info->num_parts);
part_info->num_parts-= remove_count;
DBUG_RETURN(FALSE);
}

Expand Down
Loading

0 comments on commit c02ebf3

Please sign in to comment.