Commit 7450cb7f authored by Sergei Golubchik's avatar Sergei Golubchik

re-fix vcols on demand, not always for every SELECT

parent cd51c7fb
...@@ -5219,6 +5219,8 @@ bool Item_field::fix_fields(THD *thd, Item **reference) ...@@ -5219,6 +5219,8 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
} }
#endif #endif
fixed= 1; 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 && if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY &&
!outer_fixed && !thd->lex->in_sum_func && !outer_fixed && !thd->lex->in_sum_func &&
thd->lex->current_select->cur_pos_in_select_list != UNDEF_POS && 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) ...@@ -8231,6 +8233,7 @@ bool Item_default_value::fix_fields(THD *thd, Item **items)
set_field(def_field); set_field(def_field);
if (field->default_value) if (field->default_value)
{ {
fix_session_vcol_expr_for_read(thd, field, field->default_value);
if (thd->mark_used_columns != MARK_COLUMNS_NONE) if (thd->mark_used_columns != MARK_COLUMNS_NONE)
field->default_value->expr_item->walk(&Item::register_field_in_read_map, 1, 0); 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 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) ...@@ -4697,7 +4697,8 @@ static bool fix_all_session_vcol_exprs(THD *thd, TABLE_LIST *tables)
table= table->next_global) table= table->next_global)
{ {
TABLE *t= table->table; 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) if (table->security_ctx)
thd->security_ctx= 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) ...@@ -4711,7 +4712,6 @@ static bool fix_all_session_vcol_exprs(THD *thd, TABLE_LIST *tables)
fix_session_vcol_expr(thd, (*df)->default_value)) fix_session_vcol_expr(thd, (*df)->default_value))
goto err; goto err;
if (table->lock_type >= TL_WRITE_ALLOW_WRITE)
for (Virtual_column_info **cc= t->check_constraints; cc && *cc; cc++) for (Virtual_column_info **cc= t->check_constraints; cc && *cc; cc++)
if (fix_session_vcol_expr(thd, (*cc))) if (fix_session_vcol_expr(thd, (*cc)))
goto err; goto err;
......
...@@ -2543,7 +2543,11 @@ static bool fix_vcol_expr(THD *thd, Virtual_column_info *vcol) ...@@ -2543,7 +2543,11 @@ static bool fix_vcol_expr(THD *thd, Virtual_column_info *vcol)
DBUG_RETURN(0); 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) bool fix_session_vcol_expr(THD *thd, Virtual_column_info *vcol)
{ {
DBUG_ENTER("fix_session_vcol_expr"); DBUG_ENTER("fix_session_vcol_expr");
...@@ -2556,6 +2560,27 @@ bool fix_session_vcol_expr(THD *thd, Virtual_column_info *vcol) ...@@ -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 @brief
Perform semantic analysis of the defining expression for a virtual column 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, ...@@ -2620,6 +2620,8 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,
uint ha_open_flags, TABLE *outparam, uint ha_open_flags, TABLE *outparam,
bool is_create_table); bool is_create_table);
bool fix_session_vcol_expr(THD *thd, Virtual_column_info *vcol); 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, Virtual_column_info *unpack_vcol_info_from_frm(THD *thd, MEM_ROOT *mem_root,
TABLE *table, TABLE *table,
Field *field, Field *field,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment