Skip to content

Commit

Permalink
cleanup: TABLE::update_virtual_fields
Browse files Browse the repository at this point in the history
Make update_virtual_fields() a method of TABLE, to be consistent
with TABLE::update_default_fields().
  • Loading branch information
vuvova committed Dec 12, 2016
1 parent 8b6c054 commit 9a3ec79
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 48 deletions.
4 changes: 2 additions & 2 deletions sql/filesort.cc
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ static ha_rows find_all_keys(THD *thd, Sort_param *param, SQL_SELECT *select,
if ((error= select->quick->get_next()))
break;
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]);
DBUG_EXECUTE_IF("debug_filesort", dbug_print_record(sort_form, TRUE););
}
Expand All @@ -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]);
if (!error && sort_form->vfield)
update_virtual_fields(thd, sort_form);
sort_form->update_virtual_fields(VCOL_UPDATE_FOR_READ);
if (!flag)
{
my_store_ptr(ref_pos,ref_length,record); // Position to row
Expand Down
8 changes: 4 additions & 4 deletions sql/sql_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7837,7 +7837,7 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
/* Update virtual fields */
thd->abort_on_warning= FALSE;
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;
thd->abort_on_warning= save_abort_on_warning;
thd->no_errors= save_no_errors;
Expand Down Expand Up @@ -7988,7 +7988,7 @@ fill_record_n_invoke_before_triggers(THD *thd, TABLE *table,
if (item_field && table->vfield)
{
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);
}
}
}
Expand Down Expand Up @@ -8081,7 +8081,7 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
/* Update virtual fields */
thd->abort_on_warning= FALSE;
if (table->vfield &&
update_virtual_fields(thd, table, VCOL_UPDATE_FOR_WRITE))
table->update_virtual_fields(VCOL_UPDATE_FOR_WRITE))
goto err;
thd->abort_on_warning= abort_on_warning_saved;
DBUG_RETURN(thd->is_error());
Expand Down Expand Up @@ -8135,7 +8135,7 @@ fill_record_n_invoke_before_triggers(THD *thd, TABLE *table, Field **ptr,
{
DBUG_ASSERT(table == (*ptr)->table);
if (table->vfield)
result= update_virtual_fields(thd, table, VCOL_UPDATE_FOR_WRITE);
result= table->update_virtual_fields(VCOL_UPDATE_FOR_WRITE);
}
return result;

Expand Down
2 changes: 0 additions & 2 deletions sql/sql_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,6 @@ TABLE *find_table_for_mdl_upgrade(THD *thd, const char *db,
const char *table_name,
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);

/* open_and_lock_tables with optional derived handling */
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_delete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
{
explain->tracker.on_record_read();
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->is_error() is tested to disallow delete row on error
if (!select || select->skip_record(thd) > 0)
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables,
}
/* Generate values for virtual fields */
if (table->vfield)
update_virtual_fields(thd, table);
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
if (cond && !cond->val_int())
{
if (thd->is_error())
Expand Down
6 changes: 3 additions & 3 deletions sql/sql_join_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3383,7 +3383,7 @@ int JOIN_TAB_SCAN::next()
{
join_tab->tracker->r_rows++;
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)
Expand All @@ -3399,7 +3399,7 @@ int JOIN_TAB_SCAN::next()
{
join_tab->tracker->r_rows++;
if (table->vfield)
update_virtual_fields(thd, table);
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
}
}

Expand Down Expand Up @@ -3924,7 +3924,7 @@ int JOIN_TAB_SCAN_MRR::next()
(uchar *) (*ptr) <= cache->end_pos);
*/
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;
}
Expand Down
6 changes: 3 additions & 3 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18444,7 +18444,7 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
join_tab->tracker->r_rows++;

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)
{
Expand Down Expand Up @@ -18897,7 +18897,7 @@ join_read_system(JOIN_TAB *tab)
return -1;
}
if (table->vfield)
update_virtual_fields(tab->join->thd, table);
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
store_record(table,record[1]);
}
else if (!table->status) // Only happens with left join
Expand Down Expand Up @@ -18944,7 +18944,7 @@ join_read_const(JOIN_TAB *tab)
return -1;
}
if (table->vfield)
update_virtual_fields(tab->join->thd, table);
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
store_record(table,record[1]);
}
else if (!(table->status & ~STATUS_NULL_ROW)) // Only happens with left join
Expand Down
4 changes: 2 additions & 2 deletions sql/sql_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9789,7 +9789,7 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
break;
}
if (from->vfield)
update_virtual_fields(thd, from);
from->update_virtual_fields(VCOL_UPDATE_FOR_READ);
if (++thd->progress.counter >= time_to_report_progress)
{
time_to_report_progress+= MY_HOW_OFTEN_TO_WRITE/10;
Expand Down Expand Up @@ -9819,7 +9819,7 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
if (to->default_field)
to->update_default_fields(0, ignore);
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 */
if (to->verify_constraints(ignore) == VIEW_CHECK_SKIP)
Expand Down
6 changes: 3 additions & 3 deletions sql/sql_update.cc
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ int mysql_update(THD *thd,
{
explain->buf_tracker.on_record_read();
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);
if (!select || (error= select->skip_record(thd)) > 0)
{
Expand Down Expand Up @@ -736,7 +736,7 @@ int mysql_update(THD *thd,
{
explain->tracker.on_record_read();
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);
if (!select || select->skip_record(thd) > 0)
{
Expand Down Expand Up @@ -2407,7 +2407,7 @@ int multi_update::do_updates()
(error= table->update_default_fields(1, ignore)))
goto err2;
if (table->vfield &&
update_virtual_fields(thd, table, VCOL_UPDATE_FOR_WRITE))
table->update_virtual_fields(VCOL_UPDATE_FOR_WRITE))
goto err2;
if ((error= cur_table->view_check_option(thd, ignore)) !=
VIEW_CHECK_OK)
Expand Down
38 changes: 17 additions & 21 deletions sql/table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7262,9 +7262,7 @@ bool is_simple_order(ORDER *order)
/*
@brief Compute values for virtual columns used in query

@param thd Thread handle
@param table The TABLE object
@param vcol_update_mode Specifies what virtual column are computed
@param update_mode Specifies what virtual column are computed

@details
The function computes the values of the virtual columns of the table and
Expand All @@ -7276,52 +7274,50 @@ bool is_simple_order(ORDER *order)
>0 Error occurred when storing a virtual field value
*/

int update_virtual_fields(THD *thd, TABLE *table,
enum enum_vcol_update_mode vcol_update_mode)
int TABLE::update_virtual_fields(enum_vcol_update_mode update_mode)
{
DBUG_ENTER("update_virtual_fields");
Field **vfield_ptr, *vfield;
DBUG_ASSERT(table);
DBUG_ASSERT(table->vfield);
DBUG_ENTER("TABLE::update_virtual_fields");
Field **vfield_ptr, *vf;
DBUG_ASSERT(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 */
for (vfield_ptr= table->vfield; *vfield_ptr; vfield_ptr++)
for (vfield_ptr= vfield; *vfield_ptr; vfield_ptr++)
{
vfield= (*vfield_ptr);
Virtual_column_info *vcol_info= vfield->vcol_info;
vf= (*vfield_ptr);
Virtual_column_info *vcol_info= vf->vcol_info;
DBUG_ASSERT(vcol_info);
DBUG_ASSERT(vcol_info->expr_item);

bool update;
switch (vcol_update_mode) {
switch (update_mode) {
case VCOL_UPDATE_FOR_READ_WRITE:
if (table->triggers)
if (triggers)
{
update= true;
break;
}
case VCOL_UPDATE_FOR_READ:
update= !vcol_info->stored_in_db
&& bitmap_is_set(table->vcol_set, vfield->field_index);
&& bitmap_is_set(vcol_set, vf->field_index);
break;
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;
}

if (update)
{
/* Compute the actual value of the virtual fields */
vcol_info->expr_item->save_in_field(vfield, 0);
DBUG_PRINT("info", ("field '%s' - updated", vfield->field_name));
vcol_info->expr_item->save_in_field(vf, 0);
DBUG_PRINT("info", ("field '%s' - updated", vf->field_name));
}
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);
}

Expand Down
1 change: 1 addition & 0 deletions sql/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,7 @@ struct TABLE

uint actual_n_key_parts(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);
void reset_default_fields();
inline ha_rows stat_records() { return used_stat_records; }
Expand Down
12 changes: 6 additions & 6 deletions storage/oqgraph/oqgraph_thunk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ int oqgraph3::cursor::restore_position()
}

if (table.vfield)
update_virtual_fields(table.in_use, &table);
table.update_virtual_fields(VCOL_UPDATE_FOR_READ);

table.file->position(table.record[0]);

Expand All @@ -207,7 +207,7 @@ int oqgraph3::cursor::restore_position()
}

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) ||
(_destid && vertex_id(_graph->_target->val_int()) != *_destid))
Expand All @@ -232,7 +232,7 @@ int oqgraph3::cursor::restore_position()
}

if (table.vfield)
update_virtual_fields(table.in_use, &table);
table.update_virtual_fields(VCOL_UPDATE_FOR_READ);
}

_graph->_cursor= this;
Expand Down Expand Up @@ -311,7 +311,7 @@ int oqgraph3::cursor::seek_next()
}

if (table.vfield)
update_virtual_fields(table.in_use, &table);
table.update_virtual_fields(VCOL_UPDATE_FOR_READ);
_graph->_stale= true;

if ((_origid && vertex_id(_graph->_source->val_int()) != *_origid) ||
Expand Down Expand Up @@ -346,7 +346,7 @@ int oqgraph3::cursor::seek_prev()
}

if (table.vfield)
update_virtual_fields(table.in_use, &table);
table.update_virtual_fields(VCOL_UPDATE_FOR_READ);
_graph->_stale= true;

if ((_origid && vertex_id(_graph->_source->val_int()) != *_origid) ||
Expand Down Expand Up @@ -508,7 +508,7 @@ int oqgraph3::cursor::seek_to(
}

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) ||
(_destid && vertex_id(_graph->_target->val_int()) != *_destid))
Expand Down

0 comments on commit 9a3ec79

Please sign in to comment.