1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-17 12:02:09 +03:00

cleanup: TABLE::update_virtual_fields

Make update_virtual_fields() a method of TABLE, to be consistent
with TABLE::update_default_fields().
This commit is contained in:
Sergei Golubchik
2016-11-07 21:47:48 +01:00
parent 8b6c0542db
commit 9a3ec79b53
12 changed files with 43 additions and 48 deletions

View File

@ -785,7 +785,7 @@ static ha_rows find_all_keys(THD *thd, Sort_param *param, SQL_SELECT *select,
if ((error= select->quick->get_next())) if ((error= select->quick->get_next()))
break; break;
if (!error && sort_form->vfield) if (!error && sort_form->vfield)
update_virtual_fields(thd, sort_form); sort_form->update_virtual_fields(VCOL_UPDATE_FOR_READ);
file->position(sort_form->record[0]); file->position(sort_form->record[0]);
DBUG_EXECUTE_IF("debug_filesort", dbug_print_record(sort_form, TRUE);); DBUG_EXECUTE_IF("debug_filesort", dbug_print_record(sort_form, TRUE););
} }
@ -794,7 +794,7 @@ static ha_rows find_all_keys(THD *thd, Sort_param *param, SQL_SELECT *select,
{ {
error= file->ha_rnd_next(sort_form->record[0]); error= file->ha_rnd_next(sort_form->record[0]);
if (!error && sort_form->vfield) if (!error && sort_form->vfield)
update_virtual_fields(thd, sort_form); sort_form->update_virtual_fields(VCOL_UPDATE_FOR_READ);
if (!flag) if (!flag)
{ {
my_store_ptr(ref_pos,ref_length,record); // Position to row my_store_ptr(ref_pos,ref_length,record); // Position to row

View File

@ -7837,7 +7837,7 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
/* Update virtual fields */ /* Update virtual fields */
thd->abort_on_warning= FALSE; thd->abort_on_warning= FALSE;
if (vcol_table && vcol_table->vfield && if (vcol_table && vcol_table->vfield &&
update_virtual_fields(thd, vcol_table, VCOL_UPDATE_FOR_WRITE)) vcol_table->update_virtual_fields(VCOL_UPDATE_FOR_WRITE))
goto err; goto err;
thd->abort_on_warning= save_abort_on_warning; thd->abort_on_warning= save_abort_on_warning;
thd->no_errors= save_no_errors; thd->no_errors= save_no_errors;
@ -7988,7 +7988,7 @@ fill_record_n_invoke_before_triggers(THD *thd, TABLE *table,
if (item_field && table->vfield) if (item_field && table->vfield)
{ {
DBUG_ASSERT(table == item_field->field->table); DBUG_ASSERT(table == item_field->field->table);
result= update_virtual_fields(thd, table, VCOL_UPDATE_FOR_WRITE); result= table->update_virtual_fields(VCOL_UPDATE_FOR_WRITE);
} }
} }
} }
@ -8081,7 +8081,7 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
/* Update virtual fields */ /* Update virtual fields */
thd->abort_on_warning= FALSE; thd->abort_on_warning= FALSE;
if (table->vfield && if (table->vfield &&
update_virtual_fields(thd, table, VCOL_UPDATE_FOR_WRITE)) table->update_virtual_fields(VCOL_UPDATE_FOR_WRITE))
goto err; goto err;
thd->abort_on_warning= abort_on_warning_saved; thd->abort_on_warning= abort_on_warning_saved;
DBUG_RETURN(thd->is_error()); DBUG_RETURN(thd->is_error());
@ -8135,7 +8135,7 @@ fill_record_n_invoke_before_triggers(THD *thd, TABLE *table, Field **ptr,
{ {
DBUG_ASSERT(table == (*ptr)->table); DBUG_ASSERT(table == (*ptr)->table);
if (table->vfield) if (table->vfield)
result= update_virtual_fields(thd, table, VCOL_UPDATE_FOR_WRITE); result= table->update_virtual_fields(VCOL_UPDATE_FOR_WRITE);
} }
return result; return result;

View File

@ -288,8 +288,6 @@ TABLE *find_table_for_mdl_upgrade(THD *thd, const char *db,
const char *table_name, const char *table_name,
bool no_error); bool no_error);
int update_virtual_fields(THD *thd, TABLE *table,
enum enum_vcol_update_mode vcol_update_mode= VCOL_UPDATE_FOR_READ);
int dynamic_column_error_message(enum_dyncol_func_result rc); int dynamic_column_error_message(enum_dyncol_func_result rc);
/* open_and_lock_tables with optional derived handling */ /* open_and_lock_tables with optional derived handling */

View File

@ -561,7 +561,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
{ {
explain->tracker.on_record_read(); explain->tracker.on_record_read();
if (table->vfield) if (table->vfield)
update_virtual_fields(thd, table, VCOL_UPDATE_FOR_READ_WRITE); table->update_virtual_fields(VCOL_UPDATE_FOR_READ_WRITE);
thd->inc_examined_row_count(1); thd->inc_examined_row_count(1);
// thd->is_error() is tested to disallow delete row on error // thd->is_error() is tested to disallow delete row on error
if (!select || select->skip_record(thd) > 0) if (!select || select->skip_record(thd) > 0)

View File

@ -931,7 +931,7 @@ retry:
} }
/* Generate values for virtual fields */ /* Generate values for virtual fields */
if (table->vfield) if (table->vfield)
update_virtual_fields(thd, table); table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
if (cond && !cond->val_int()) if (cond && !cond->val_int())
{ {
if (thd->is_error()) if (thd->is_error())

View File

@ -3383,7 +3383,7 @@ int JOIN_TAB_SCAN::next()
{ {
join_tab->tracker->r_rows++; join_tab->tracker->r_rows++;
if (table->vfield) if (table->vfield)
update_virtual_fields(thd, table); table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
} }
while (!err && select && (skip_rc= select->skip_record(thd)) <= 0) while (!err && select && (skip_rc= select->skip_record(thd)) <= 0)
@ -3399,7 +3399,7 @@ int JOIN_TAB_SCAN::next()
{ {
join_tab->tracker->r_rows++; join_tab->tracker->r_rows++;
if (table->vfield) if (table->vfield)
update_virtual_fields(thd, table); table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
} }
} }
@ -3924,7 +3924,7 @@ int JOIN_TAB_SCAN_MRR::next()
(uchar *) (*ptr) <= cache->end_pos); (uchar *) (*ptr) <= cache->end_pos);
*/ */
if (join_tab->table->vfield) if (join_tab->table->vfield)
update_virtual_fields(join->thd, join_tab->table); join_tab->table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
} }
return rc; return rc;
} }

View File

@ -18444,7 +18444,7 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
join_tab->tracker->r_rows++; join_tab->tracker->r_rows++;
if (join_tab->table->vfield) if (join_tab->table->vfield)
update_virtual_fields(join->thd, join_tab->table); join_tab->table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
if (select_cond) if (select_cond)
{ {
@ -18897,7 +18897,7 @@ join_read_system(JOIN_TAB *tab)
return -1; return -1;
} }
if (table->vfield) if (table->vfield)
update_virtual_fields(tab->join->thd, table); table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
store_record(table,record[1]); store_record(table,record[1]);
} }
else if (!table->status) // Only happens with left join else if (!table->status) // Only happens with left join
@ -18944,7 +18944,7 @@ join_read_const(JOIN_TAB *tab)
return -1; return -1;
} }
if (table->vfield) if (table->vfield)
update_virtual_fields(tab->join->thd, table); table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
store_record(table,record[1]); store_record(table,record[1]);
} }
else if (!(table->status & ~STATUS_NULL_ROW)) // Only happens with left join else if (!(table->status & ~STATUS_NULL_ROW)) // Only happens with left join

View File

@ -9789,7 +9789,7 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
break; break;
} }
if (from->vfield) if (from->vfield)
update_virtual_fields(thd, from); from->update_virtual_fields(VCOL_UPDATE_FOR_READ);
if (++thd->progress.counter >= time_to_report_progress) if (++thd->progress.counter >= time_to_report_progress)
{ {
time_to_report_progress+= MY_HOW_OFTEN_TO_WRITE/10; time_to_report_progress+= MY_HOW_OFTEN_TO_WRITE/10;
@ -9819,7 +9819,7 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
if (to->default_field) if (to->default_field)
to->update_default_fields(0, ignore); to->update_default_fields(0, ignore);
if (to->vfield) if (to->vfield)
update_virtual_fields(thd, to, VCOL_UPDATE_FOR_WRITE); to->update_virtual_fields(VCOL_UPDATE_FOR_WRITE);
/* This will set thd->is_error() if fatal failure */ /* This will set thd->is_error() if fatal failure */
if (to->verify_constraints(ignore) == VIEW_CHECK_SKIP) if (to->verify_constraints(ignore) == VIEW_CHECK_SKIP)

View File

@ -619,7 +619,7 @@ int mysql_update(THD *thd,
{ {
explain->buf_tracker.on_record_read(); explain->buf_tracker.on_record_read();
if (table->vfield) if (table->vfield)
update_virtual_fields(thd, table, VCOL_UPDATE_FOR_READ_WRITE); table->update_virtual_fields(VCOL_UPDATE_FOR_READ_WRITE);
thd->inc_examined_row_count(1); thd->inc_examined_row_count(1);
if (!select || (error= select->skip_record(thd)) > 0) if (!select || (error= select->skip_record(thd)) > 0)
{ {
@ -736,7 +736,7 @@ int mysql_update(THD *thd,
{ {
explain->tracker.on_record_read(); explain->tracker.on_record_read();
if (table->vfield) if (table->vfield)
update_virtual_fields(thd, table, VCOL_UPDATE_FOR_READ_WRITE); table->update_virtual_fields(VCOL_UPDATE_FOR_READ_WRITE);
thd->inc_examined_row_count(1); thd->inc_examined_row_count(1);
if (!select || select->skip_record(thd) > 0) if (!select || select->skip_record(thd) > 0)
{ {
@ -2407,7 +2407,7 @@ int multi_update::do_updates()
(error= table->update_default_fields(1, ignore))) (error= table->update_default_fields(1, ignore)))
goto err2; goto err2;
if (table->vfield && if (table->vfield &&
update_virtual_fields(thd, table, VCOL_UPDATE_FOR_WRITE)) table->update_virtual_fields(VCOL_UPDATE_FOR_WRITE))
goto err2; goto err2;
if ((error= cur_table->view_check_option(thd, ignore)) != if ((error= cur_table->view_check_option(thd, ignore)) !=
VIEW_CHECK_OK) VIEW_CHECK_OK)

View File

@ -7262,9 +7262,7 @@ bool is_simple_order(ORDER *order)
/* /*
@brief Compute values for virtual columns used in query @brief Compute values for virtual columns used in query
@param thd Thread handle @param update_mode Specifies what virtual column are computed
@param table The TABLE object
@param vcol_update_mode Specifies what virtual column are computed
@details @details
The function computes the values of the virtual columns of the table and The function computes the values of the virtual columns of the table and
@ -7276,52 +7274,50 @@ bool is_simple_order(ORDER *order)
>0 Error occurred when storing a virtual field value >0 Error occurred when storing a virtual field value
*/ */
int update_virtual_fields(THD *thd, TABLE *table, int TABLE::update_virtual_fields(enum_vcol_update_mode update_mode)
enum enum_vcol_update_mode vcol_update_mode)
{ {
DBUG_ENTER("update_virtual_fields"); DBUG_ENTER("TABLE::update_virtual_fields");
Field **vfield_ptr, *vfield; Field **vfield_ptr, *vf;
DBUG_ASSERT(table); DBUG_ASSERT(vfield);
DBUG_ASSERT(table->vfield);
thd->reset_arena_for_cached_items(table->expr_arena); in_use->reset_arena_for_cached_items(expr_arena);
/* Iterate over virtual fields in the table */ /* Iterate over virtual fields in the table */
for (vfield_ptr= table->vfield; *vfield_ptr; vfield_ptr++) for (vfield_ptr= vfield; *vfield_ptr; vfield_ptr++)
{ {
vfield= (*vfield_ptr); vf= (*vfield_ptr);
Virtual_column_info *vcol_info= vfield->vcol_info; Virtual_column_info *vcol_info= vf->vcol_info;
DBUG_ASSERT(vcol_info); DBUG_ASSERT(vcol_info);
DBUG_ASSERT(vcol_info->expr_item); DBUG_ASSERT(vcol_info->expr_item);
bool update; bool update;
switch (vcol_update_mode) { switch (update_mode) {
case VCOL_UPDATE_FOR_READ_WRITE: case VCOL_UPDATE_FOR_READ_WRITE:
if (table->triggers) if (triggers)
{ {
update= true; update= true;
break; break;
} }
case VCOL_UPDATE_FOR_READ: case VCOL_UPDATE_FOR_READ:
update= !vcol_info->stored_in_db update= !vcol_info->stored_in_db
&& bitmap_is_set(table->vcol_set, vfield->field_index); && bitmap_is_set(vcol_set, vf->field_index);
break; break;
case VCOL_UPDATE_FOR_WRITE: case VCOL_UPDATE_FOR_WRITE:
update= table->triggers || bitmap_is_set(table->vcol_set, vfield->field_index); update= triggers || bitmap_is_set(vcol_set, vf->field_index);
break; break;
} }
if (update) if (update)
{ {
/* Compute the actual value of the virtual fields */ /* Compute the actual value of the virtual fields */
vcol_info->expr_item->save_in_field(vfield, 0); vcol_info->expr_item->save_in_field(vf, 0);
DBUG_PRINT("info", ("field '%s' - updated", vfield->field_name)); DBUG_PRINT("info", ("field '%s' - updated", vf->field_name));
} }
else else
{ {
DBUG_PRINT("info", ("field '%s' - skipped", vfield->field_name)); DBUG_PRINT("info", ("field '%s' - skipped", vf->field_name));
} }
} }
thd->reset_arena_for_cached_items(0); in_use->reset_arena_for_cached_items(0);
DBUG_RETURN(0); DBUG_RETURN(0);
} }

View File

@ -1421,6 +1421,7 @@ public:
uint actual_n_key_parts(KEY *keyinfo); uint actual_n_key_parts(KEY *keyinfo);
ulong actual_key_flags(KEY *keyinfo); ulong actual_key_flags(KEY *keyinfo);
int update_virtual_fields(enum_vcol_update_mode update_mode);
int update_default_fields(bool update, bool ignore_errors); int update_default_fields(bool update, bool ignore_errors);
void reset_default_fields(); void reset_default_fields();
inline ha_rows stat_records() { return used_stat_records; } inline ha_rows stat_records() { return used_stat_records; }

View File

@ -194,7 +194,7 @@ int oqgraph3::cursor::restore_position()
} }
if (table.vfield) if (table.vfield)
update_virtual_fields(table.in_use, &table); table.update_virtual_fields(VCOL_UPDATE_FOR_READ);
table.file->position(table.record[0]); table.file->position(table.record[0]);
@ -207,7 +207,7 @@ int oqgraph3::cursor::restore_position()
} }
if (table.vfield) if (table.vfield)
update_virtual_fields(table.in_use, &table); table.update_virtual_fields(VCOL_UPDATE_FOR_READ);
if ((_origid && vertex_id(_graph->_source->val_int()) != *_origid) || if ((_origid && vertex_id(_graph->_source->val_int()) != *_origid) ||
(_destid && vertex_id(_graph->_target->val_int()) != *_destid)) (_destid && vertex_id(_graph->_target->val_int()) != *_destid))
@ -232,7 +232,7 @@ int oqgraph3::cursor::restore_position()
} }
if (table.vfield) if (table.vfield)
update_virtual_fields(table.in_use, &table); table.update_virtual_fields(VCOL_UPDATE_FOR_READ);
} }
_graph->_cursor= this; _graph->_cursor= this;
@ -311,7 +311,7 @@ int oqgraph3::cursor::seek_next()
} }
if (table.vfield) if (table.vfield)
update_virtual_fields(table.in_use, &table); table.update_virtual_fields(VCOL_UPDATE_FOR_READ);
_graph->_stale= true; _graph->_stale= true;
if ((_origid && vertex_id(_graph->_source->val_int()) != *_origid) || if ((_origid && vertex_id(_graph->_source->val_int()) != *_origid) ||
@ -346,7 +346,7 @@ int oqgraph3::cursor::seek_prev()
} }
if (table.vfield) if (table.vfield)
update_virtual_fields(table.in_use, &table); table.update_virtual_fields(VCOL_UPDATE_FOR_READ);
_graph->_stale= true; _graph->_stale= true;
if ((_origid && vertex_id(_graph->_source->val_int()) != *_origid) || if ((_origid && vertex_id(_graph->_source->val_int()) != *_origid) ||
@ -508,7 +508,7 @@ int oqgraph3::cursor::seek_to(
} }
if (table.vfield) if (table.vfield)
update_virtual_fields(table.in_use, &table); table.update_virtual_fields(VCOL_UPDATE_FOR_READ);
if ((_origid && vertex_id(_graph->_source->val_int()) != *_origid) || if ((_origid && vertex_id(_graph->_source->val_int()) != *_origid) ||
(_destid && vertex_id(_graph->_target->val_int()) != *_destid)) (_destid && vertex_id(_graph->_target->val_int()) != *_destid))