Skip to content

Commit c02ebf3

Browse files
committed
MDEV-24176 Preparations
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.
1 parent 7498978 commit c02ebf3

File tree

7 files changed

+110
-115
lines changed

7 files changed

+110
-115
lines changed

sql/field.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,10 @@ class Virtual_column_info: public Sql_alloc
616616
{
617617
in_partitioning_expr= TRUE;
618618
}
619+
bool fix_expr(THD *thd);
620+
bool fix_session_expr(THD *thd);
621+
bool fix_session_expr_for_read(THD *thd, Field *field);
622+
bool fix_and_check_expr(THD *thd, TABLE *table);
619623
inline bool is_equal(const Virtual_column_info* vcol) const;
620624
inline void print(String*);
621625
};

sql/item.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6376,8 +6376,9 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
63766376
}
63776377
#endif
63786378
fixed= 1;
6379-
if (field->vcol_info)
6380-
fix_session_vcol_expr_for_read(thd, field, field->vcol_info);
6379+
if (field->vcol_info &&
6380+
field->vcol_info->fix_session_expr_for_read(thd, field))
6381+
goto error;
63816382
if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY &&
63826383
!outer_fixed && !thd->lex->in_sum_func &&
63836384
select &&
@@ -9503,7 +9504,8 @@ bool Item_default_value::fix_fields(THD *thd, Item **items)
95039504
Even if DEFAULT() do not read tables fields, the default value
95049505
expression can do it.
95059506
*/
9506-
fix_session_vcol_expr_for_read(thd, def_field, def_field->default_value);
9507+
if (def_field->default_value->fix_session_expr_for_read(thd, def_field))
9508+
goto error;
95079509
if (should_mark_column(thd->column_usage))
95089510
def_field->default_value->expr->update_used_tables();
95099511
def_field->move_field(newptr+1, def_field->maybe_null() ? newptr : 0, 1);

sql/item.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,6 +2924,12 @@ class Item_ident :public Item_result_field
29242924
const char *db_name;
29252925
const char *table_name;
29262926
LEX_CSTRING field_name;
2927+
/*
2928+
NOTE: came from TABLE::alias_name_used and this is only a hint! It works
2929+
only in need_correct_ident() condition. On other cases it is FALSE even if
2930+
table_name is alias! It cannot be TRUE in these cases, lots of spaghetti
2931+
logic depends on that.
2932+
*/
29272933
bool alias_name_used; /* true if item was resolved against alias */
29282934
/*
29292935
Cached value of index for this field in table->field array, used by prep.

sql/sql_base.cc

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,9 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
20402040
table_list->updatable= 1; // It is not derived table nor non-updatable VIEW
20412041
table_list->table= table;
20422042

2043+
if (table->vcol_fix_exprs(thd))
2044+
goto err_lock;
2045+
20432046
#ifdef WITH_PARTITION_STORAGE_ENGINE
20442047
if (unlikely(table->part_info))
20452048
{
@@ -5290,52 +5293,44 @@ static void mark_real_tables_as_free_for_reuse(TABLE_LIST *table_list)
52905293
}
52915294
}
52925295

5293-
int TABLE::fix_vcol_exprs(THD *thd)
5296+
bool TABLE::vcol_fix_exprs(THD *thd)
52945297
{
5298+
if (pos_in_table_list->placeholder() || !s->vcols_need_refixing ||
5299+
pos_in_table_list->lock_type < TL_WRITE_ALLOW_WRITE)
5300+
return false;
5301+
5302+
DBUG_ASSERT(pos_in_table_list != thd->lex->first_not_own_table());
5303+
5304+
bool result= true;
5305+
Security_context *save_security_ctx= thd->security_ctx;
5306+
Query_arena *stmt_backup= thd->stmt_arena;
5307+
if (thd->stmt_arena->is_conventional())
5308+
thd->stmt_arena= expr_arena;
5309+
5310+
if (pos_in_table_list->security_ctx)
5311+
thd->security_ctx= pos_in_table_list->security_ctx;
5312+
5313+
52955314
for (Field **vf= vfield; vf && *vf; vf++)
5296-
if (fix_session_vcol_expr(thd, (*vf)->vcol_info))
5297-
return 1;
5315+
if ((*vf)->vcol_info->fix_session_expr(thd))
5316+
goto end;
52985317

52995318
for (Field **df= default_field; df && *df; df++)
53005319
if ((*df)->default_value &&
5301-
fix_session_vcol_expr(thd, (*df)->default_value))
5302-
return 1;
5320+
(*df)->default_value->fix_session_expr(thd))
5321+
goto end;
53035322

53045323
for (Virtual_column_info **cc= check_constraints; cc && *cc; cc++)
5305-
if (fix_session_vcol_expr(thd, (*cc)))
5306-
return 1;
5307-
5308-
return 0;
5309-
}
5310-
5311-
5312-
static bool fix_all_session_vcol_exprs(THD *thd, TABLE_LIST *tables)
5313-
{
5314-
Security_context *save_security_ctx= thd->security_ctx;
5315-
TABLE_LIST *first_not_own= thd->lex->first_not_own_table();
5316-
DBUG_ENTER("fix_session_vcol_expr");
5324+
if ((*cc)->fix_session_expr(thd))
5325+
goto end;
53175326

5318-
int error= 0;
5319-
for (TABLE_LIST *table= tables; table && table != first_not_own && !error;
5320-
table= table->next_global)
5321-
{
5322-
TABLE *t= table->table;
5323-
if (!table->placeholder() && t->s->vcols_need_refixing &&
5324-
table->lock_type >= TL_WRITE_ALLOW_WRITE)
5325-
{
5326-
Query_arena *stmt_backup= thd->stmt_arena;
5327-
if (thd->stmt_arena->is_conventional())
5328-
thd->stmt_arena= t->expr_arena;
5329-
if (table->security_ctx)
5330-
thd->security_ctx= table->security_ctx;
5327+
result= false;
53315328

5332-
error= t->fix_vcol_exprs(thd);
5329+
end:
5330+
thd->security_ctx= save_security_ctx;
5331+
thd->stmt_arena= stmt_backup;
53335332

5334-
thd->security_ctx= save_security_ctx;
5335-
thd->stmt_arena= stmt_backup;
5336-
}
5337-
}
5338-
DBUG_RETURN(error);
5333+
return result;
53395334
}
53405335

53415336

@@ -5500,9 +5495,7 @@ bool lock_tables(THD *thd, TABLE_LIST *tables, uint count,
55005495
}
55015496
}
55025497

5503-
bool res= fix_all_session_vcol_exprs(thd, tables);
5504-
if (!res)
5505-
res= thd->decide_logging_format(tables);
5498+
const bool res= thd->decide_logging_format(tables);
55065499

55075500
DBUG_RETURN(res);
55085501
}

sql/sql_partition.cc

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5548,7 +5548,6 @@ that are reorganised.
55485548
my_error(ER_ROW_IS_REFERENCED, MYF(0));
55495549
goto err;
55505550
}
5551-
tab_part_info->num_parts-= num_parts_dropped;
55525551
}
55535552
else if (alter_info->partition_flags & ALTER_PARTITION_REBUILD)
55545553
{
@@ -6214,8 +6213,6 @@ static bool mysql_drop_partitions(ALTER_PARTITION_PARAM_TYPE *lpt)
62146213
char path[FN_REFLEN+1];
62156214
partition_info *part_info= lpt->table->part_info;
62166215
List_iterator<partition_element> part_it(part_info->partitions);
6217-
uint i= 0;
6218-
uint remove_count= 0;
62196216
int error;
62206217
DBUG_ENTER("mysql_drop_partitions");
62216218

@@ -6230,16 +6227,6 @@ static bool mysql_drop_partitions(ALTER_PARTITION_PARAM_TYPE *lpt)
62306227
lpt->table->file->print_error(error, MYF(0));
62316228
DBUG_RETURN(TRUE);
62326229
}
6233-
do
6234-
{
6235-
partition_element *part_elem= part_it++;
6236-
if (part_elem->part_state == PART_IS_DROPPED)
6237-
{
6238-
part_it.remove();
6239-
remove_count++;
6240-
}
6241-
} while (++i < part_info->num_parts);
6242-
part_info->num_parts-= remove_count;
62436230
DBUG_RETURN(FALSE);
62446231
}
62456232

0 commit comments

Comments
 (0)