summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2016-07-25 17:57:31 +0200
committerSergei Golubchik <serg@mariadb.org>2016-08-27 16:59:13 +0200
commit7450cb7f69db801c48f806748e666c393b8d6b81 (patch)
treeae408cffb6225d4bf7c8ceb764c5a86d7ff71034
parentcd51c7fb60e39ae113e6bcf0d029564dd1b391e3 (diff)
downloadmariadb-git-7450cb7f69db801c48f806748e666c393b8d6b81.tar.gz
re-fix vcols on demand, not always for every SELECT
-rw-r--r--sql/item.cc3
-rw-r--r--sql/sql_base.cc4
-rw-r--r--sql/table.cc25
-rw-r--r--sql/table.h2
4 files changed, 32 insertions, 2 deletions
diff --git a/sql/item.cc b/sql/item.cc
index b955457cf32..5da95b05b2f 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -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
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 9d6f1dbed9e..d7812db53bd 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -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;
diff --git a/sql/table.cc b/sql/table.cc
index cfa950f5f9c..ab9a1c07172 100644
--- a/sql/table.cc
+++ b/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
diff --git a/sql/table.h b/sql/table.h
index af3990a6882..68e8cb9069d 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -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,