Skip to content

Commit eb9bce5

Browse files
committed
split fix_vcol_expr()
into "fix" and "check" parts
1 parent ebf1e1d commit eb9bce5

File tree

1 file changed

+45
-43
lines changed

1 file changed

+45
-43
lines changed

sql/table.cc

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,6 +2502,34 @@ void TABLE_SHARE::free_frm_image(const uchar *frm)
25022502
}
25032503

25042504

2505+
static bool fix_vcol_expr(THD *thd, Virtual_column_info *vcol)
2506+
{
2507+
DBUG_ENTER("fix_vcol_expr");
2508+
2509+
const enum enum_mark_columns save_mark_used_columns= thd->mark_used_columns;
2510+
thd->mark_used_columns= MARK_COLUMNS_NONE;
2511+
2512+
const char *save_where= thd->where;
2513+
thd->where= "virtual column function";
2514+
2515+
thd->in_stored_expression= 1;
2516+
2517+
int error= vcol->expr_item->fix_fields(thd, &vcol->expr_item);
2518+
2519+
thd->in_stored_expression= 0;
2520+
thd->mark_used_columns= save_mark_used_columns;
2521+
thd->where= save_where;
2522+
2523+
if (unlikely(error))
2524+
{
2525+
my_error(ER_ERROR_EVALUATING_EXPRESSION, MYF(0), vcol->expr_str);
2526+
DBUG_RETURN(1);
2527+
}
2528+
2529+
DBUG_RETURN(0);
2530+
}
2531+
2532+
25052533
/*
25062534
@brief
25072535
Perform semantic analysis of the defining expression for a virtual column
@@ -2529,53 +2557,38 @@ void TABLE_SHARE::free_frm_image(const uchar *frm)
25292557
FALSE Otherwise
25302558
*/
25312559

2532-
static bool fix_vcol_expr(THD *thd, TABLE *table, Field *field,
2533-
Virtual_column_info *vcol)
2560+
static bool fix_and_check_vcol_expr(THD *thd, TABLE *table, Field *field,
2561+
Virtual_column_info *vcol)
25342562
{
25352563
Item* func_expr= vcol->expr_item;
2536-
bool result= TRUE;
2537-
TABLE_LIST tables;
2538-
int error= 0;
2539-
const char *save_where;
2540-
enum_mark_columns save_mark_used_columns= thd->mark_used_columns;
2541-
DBUG_ENTER("fix_vcol_expr");
2564+
DBUG_ENTER("fix_and_check_vcol_expr");
25422565
DBUG_PRINT("info", ("vcol: %p", vcol));
25432566
DBUG_ASSERT(func_expr);
25442567

2545-
thd->mark_used_columns= MARK_COLUMNS_NONE;
2568+
if (func_expr->fixed)
2569+
DBUG_RETURN(0); // nothing to do
25462570

2547-
save_where= thd->where;
2548-
thd->where= "virtual column function";
2571+
if (fix_vcol_expr(thd, vcol))
2572+
DBUG_RETURN(1);
25492573

2550-
/* Fix fields referenced to by the virtual column function */
2551-
thd->in_stored_expression= 1;
2552-
if (!func_expr->fixed)
2553-
error= func_expr->fix_fields(thd, &vcol->expr_item);
2554-
thd->in_stored_expression= 0;
2574+
if (vcol->flags)
2575+
DBUG_RETURN(0); // already checked, no need to do it again
25552576

2556-
if (unlikely(error))
2557-
{
2558-
DBUG_PRINT("info",
2559-
("Field in virtual column expression does not belong to the table"));
2560-
my_error(ER_ERROR_EVALUATING_EXPRESSION, MYF(0), vcol->expr_str);
2561-
goto end;
2562-
}
25632577
/* fix_fields could've changed the expression */
25642578
func_expr= vcol->expr_item;
25652579

25662580
/* Number of columns will be checked later */
2567-
thd->where= save_where;
25682581
if (unlikely(func_expr->result_type() == ROW_RESULT))
25692582
{
25702583
my_error(ER_ROW_EXPR_FOR_VCOL, MYF(0));
2571-
goto end;
2584+
DBUG_RETURN(1);
25722585
}
25732586

25742587
/* Check that we are not refering to any not yet initialized fields */
25752588
if (field)
25762589
{
25772590
if (func_expr->walk(&Item::check_field_expression_processor, 0, field))
2578-
goto end;
2591+
DBUG_RETURN(1);
25792592
}
25802593

25812594
/*
@@ -2585,12 +2598,12 @@ static bool fix_vcol_expr(THD *thd, TABLE *table, Field *field,
25852598
Item::vcol_func_processor_result res;
25862599
res.errors= 0;
25872600

2588-
error= func_expr->walk(&Item::check_vcol_func_processor, 0, &res);
2601+
int error= func_expr->walk(&Item::check_vcol_func_processor, 0, &res);
25892602
if (error || (res.errors & VCOL_IMPOSSIBLE))
25902603
{ // this can only happen if the frm was corrupted
25912604
my_error(ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED, MYF(0), res.name,
25922605
"???", field ? field->field_name : "?????");
2593-
goto end;
2606+
DBUG_RETURN(1);
25942607
}
25952608
vcol->flags= res.errors;
25962609

@@ -2600,16 +2613,10 @@ static bool fix_vcol_expr(THD *thd, TABLE *table, Field *field,
26002613
if (vcol->stored_in_db && vcol->flags & VCOL_NON_DETERMINISTIC)
26012614
table->s->non_determinstic_insert= 1;
26022615

2603-
result= FALSE;
2604-
2605-
end:
2606-
2607-
thd->mark_used_columns= save_mark_used_columns;
2608-
table->map= 0; //Restore old value
2609-
2610-
DBUG_RETURN(result);
2616+
DBUG_RETURN(0);
26112617
}
26122618

2619+
26132620
/*
26142621
@brief
26152622
Unpack the definition of a virtual column from its linear representation
@@ -2629,7 +2636,7 @@ static bool fix_vcol_expr(THD *thd, TABLE *table, Field *field,
26292636
pointer to this item is placed into in a Virtual_column_info object
26302637
that is created. After this the function performs
26312638
semantic analysis of the item by calling the the function
2632-
fix_vcol_expr(). Since the defining expression is part of the table
2639+
fix_and_check_vcol_expr(). Since the defining expression is part of the table
26332640
definition the item for it is created in table->memroot within the
26342641
special arena TABLE::expr_arena or in the thd memroot for INSERT DELAYED
26352642
@@ -2736,15 +2743,10 @@ Virtual_column_info *unpack_vcol_info_from_frm(THD *thd,
27362743
if (error)
27372744
goto err;
27382745

2739-
/*
2740-
mark if expression will be stored in the table. This is also used by
2741-
fix_vcol_expr() to mark if we are using non deterministic functions.
2742-
*/
27432746
vcol_storage.vcol_info->stored_in_db= vcol->stored_in_db;
27442747
vcol_storage.vcol_info->name= vcol->name;
27452748
vcol_storage.vcol_info->utf8= vcol->utf8;
2746-
/* Validate the Item tree. */
2747-
if (!fix_vcol_expr(thd, table, field, vcol_storage.vcol_info))
2749+
if (!fix_and_check_vcol_expr(thd, table, field, vcol_storage.vcol_info))
27482750
{
27492751
vcol_info= vcol_storage.vcol_info; // Expression ok
27502752
goto end;

0 commit comments

Comments
 (0)