mirror of
https://github.com/MariaDB/server.git
synced 2025-07-21 21:22:27 +03:00
re-fix vcols on demand, not always for every SELECT
This commit is contained in:
@ -5219,6 +5219,8 @@ 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 (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY &&
|
||||
!outer_fixed && !thd->lex->in_sum_func &&
|
||||
thd->lex->current_select->cur_pos_in_select_list != UNDEF_POS &&
|
||||
@ -8231,6 +8233,7 @@ bool Item_default_value::fix_fields(THD *thd, Item **items)
|
||||
set_field(def_field);
|
||||
if (field->default_value)
|
||||
{
|
||||
fix_session_vcol_expr_for_read(thd, field, field->default_value);
|
||||
if (thd->mark_used_columns != MARK_COLUMNS_NONE)
|
||||
field->default_value->expr_item->walk(&Item::register_field_in_read_map, 1, 0);
|
||||
IF_DBUG(def_field->is_stat_field=1,); // a hack to fool ASSERT_COLUMN_MARKED_FOR_WRITE_OR_COMPUTED
|
||||
|
@ -4697,7 +4697,8 @@ static bool fix_all_session_vcol_exprs(THD *thd, TABLE_LIST *tables)
|
||||
table= table->next_global)
|
||||
{
|
||||
TABLE *t= table->table;
|
||||
if (!table->placeholder() && t->s->vcols_need_refixing)
|
||||
if (!table->placeholder() && t->s->vcols_need_refixing &&
|
||||
table->lock_type >= TL_WRITE_ALLOW_WRITE)
|
||||
{
|
||||
if (table->security_ctx)
|
||||
thd->security_ctx= table->security_ctx;
|
||||
@ -4711,7 +4712,6 @@ static bool fix_all_session_vcol_exprs(THD *thd, TABLE_LIST *tables)
|
||||
fix_session_vcol_expr(thd, (*df)->default_value))
|
||||
goto err;
|
||||
|
||||
if (table->lock_type >= TL_WRITE_ALLOW_WRITE)
|
||||
for (Virtual_column_info **cc= t->check_constraints; cc && *cc; cc++)
|
||||
if (fix_session_vcol_expr(thd, (*cc)))
|
||||
goto err;
|
||||
|
25
sql/table.cc
25
sql/table.cc
@ -2543,7 +2543,11 @@ static bool fix_vcol_expr(THD *thd, Virtual_column_info *vcol)
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
/** rerun fix_fields for vcols that returns time- or session- dependent values
|
||||
|
||||
@note this is done for all vcols for INSERT/UPDATE/DELETE,
|
||||
and only as needed for SELECTs.
|
||||
*/
|
||||
bool fix_session_vcol_expr(THD *thd, Virtual_column_info *vcol)
|
||||
{
|
||||
DBUG_ENTER("fix_session_vcol_expr");
|
||||
@ -2556,6 +2560,27 @@ bool fix_session_vcol_expr(THD *thd, Virtual_column_info *vcol)
|
||||
}
|
||||
|
||||
|
||||
/** invoke fix_session_vcol_expr for a vcol
|
||||
|
||||
@note this is called for generated column or a DEFAULT expression from
|
||||
their corresponding fix_fields on SELECT.
|
||||
*/
|
||||
bool fix_session_vcol_expr_for_read(THD *thd, Field *field,
|
||||
Virtual_column_info *vcol)
|
||||
{
|
||||
DBUG_ENTER("fix_session_vcol_expr_for_read");
|
||||
TABLE_LIST *tl= field->table->pos_in_table_list;
|
||||
if (!tl || tl->lock_type >= TL_WRITE_ALLOW_WRITE)
|
||||
DBUG_RETURN(0);
|
||||
Security_context *save_security_ctx= thd->security_ctx;
|
||||
if (tl->security_ctx)
|
||||
thd->security_ctx= tl->security_ctx;
|
||||
bool res= fix_session_vcol_expr(thd, vcol);
|
||||
thd->security_ctx= save_security_ctx;
|
||||
DBUG_RETURN(res);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@brief
|
||||
Perform semantic analysis of the defining expression for a virtual column
|
||||
|
@ -2620,6 +2620,8 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,
|
||||
uint ha_open_flags, TABLE *outparam,
|
||||
bool is_create_table);
|
||||
bool fix_session_vcol_expr(THD *thd, Virtual_column_info *vcol);
|
||||
bool fix_session_vcol_expr_for_read(THD *thd, Field *field,
|
||||
Virtual_column_info *vcol);
|
||||
Virtual_column_info *unpack_vcol_info_from_frm(THD *thd, MEM_ROOT *mem_root,
|
||||
TABLE *table,
|
||||
Field *field,
|
||||
|
Reference in New Issue
Block a user