Commit 17ab02f4 authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: on update default now

* remove one level of virtual functions
* remove redundant checks
* remove an if() as the value is always known at compilation time

don't pretend that "DEFAULT expr" and "ON UPDATE DEFAULT NOW"
are "basically the same thing"
parent ef00ac4c
......@@ -992,14 +992,6 @@ class Field: public Value_source
}
bool set_explicit_default(Item *value);
/**
Evaluates the @c UPDATE default function, if one exists, and stores the
result in the record buffer. If no such function exists for the column,
or the function is not valid for the column's data type, invoking this
function has no effect.
*/
virtual int evaluate_update_default_function() { return 0; }
virtual bool binary() const { return 1; }
virtual bool zero_pack() const { return 1; }
virtual enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
......@@ -2519,13 +2511,6 @@ class Field_timestamp :public Field_temporal {
void sql_type(String &str) const;
bool zero_pack() const { return 0; }
int set_time();
int evaluate_update_default_function()
{
int res= 0;
if (has_update_default_function())
res= set_time();
return res;
}
/* Get TIMESTAMP field value as seconds since begging of Unix Epoch */
virtual my_time_t get_timestamp(const uchar *pos, ulong *sec_part) const;
my_time_t get_timestamp(ulong *sec_part) const
......@@ -2954,13 +2939,6 @@ class Field_datetime :public Field_temporal_with_date {
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
{ return Field_datetime::get_TIME(ltime, ptr, fuzzydate); }
int set_time();
int evaluate_update_default_function()
{
int res= 0;
if (has_update_default_function())
res= set_time();
return res;
}
uchar *pack(uchar* to, const uchar *from,
uint max_length __attribute__((unused)))
{
......
......@@ -8072,7 +8072,7 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
}
if (!update && table_arg->default_field &&
table_arg->update_default_fields(0, ignore_errors))
table_arg->update_default_fields(ignore_errors))
goto err;
/* Update virtual fields */
if (table_arg->vfield &&
......@@ -8317,7 +8317,7 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
all_fields_have_values &= field->set_explicit_default(value);
}
if (!all_fields_have_values && table->default_field &&
table->update_default_fields(0, ignore_errors))
table->update_default_fields(ignore_errors))
goto err;
/* Update virtual fields */
thd->abort_on_warning= FALSE;
......
......@@ -1796,10 +1796,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
be updated as if this is an UPDATE.
*/
if (different_records && table->default_field)
{
if (table->update_default_fields(1, info->ignore))
goto err;
}
table->evaluate_update_default_function();
/* CHECK OPTION for VIEW ... ON DUPLICATE KEY UPDATE ... */
res= info->table_list->view_check_option(table->in_use, info->ignore);
......@@ -3762,7 +3759,7 @@ int select_insert::send_data(List<Item> &values)
thd->count_cuted_fields= CHECK_FIELD_WARN; // Calculate cuted fields
store_values(values);
if (table->default_field && table->update_default_fields(0, info.ignore))
if (table->default_field && table->update_default_fields(info.ignore))
DBUG_RETURN(1);
thd->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
if (thd->is_error())
......
......@@ -9455,7 +9455,7 @@ do_continue:;
/* Check that we can call default functions with default field values */
altered_table->reset_default_fields();
if (altered_table->default_field &&
altered_table->update_default_fields(0, 1))
altered_table->update_default_fields(true))
goto err_new_table_cleanup;
// Ask storage engine whether to use copy or in-place
......@@ -10138,7 +10138,7 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
}
prev_insert_id= to->file->next_insert_id;
if (to->default_field)
to->update_default_fields(0, ignore);
to->update_default_fields(ignore);
if (to->vfield)
to->update_virtual_fields(to->file, VCOL_UPDATE_FOR_WRITE);
......
......@@ -761,11 +761,8 @@ int mysql_update(THD *thd,
if (!can_compare_record || compare_record(table))
{
if (table->default_field && table->update_default_fields(1, ignore))
{
error= 1;
break;
}
if (table->default_field)
table->evaluate_update_default_function();
if ((res= table_list->view_check_option(thd, ignore)) !=
VIEW_CHECK_OK)
{
......@@ -2156,8 +2153,8 @@ int multi_update::send_data(List<Item> &not_used_values)
{
int error;
if (table->default_field && table->update_default_fields(1, ignore))
DBUG_RETURN(1);
if (table->default_field)
table->evaluate_update_default_function();
if ((error= cur_table->view_check_option(thd, ignore)) !=
VIEW_CHECK_OK)
......@@ -2482,9 +2479,8 @@ int multi_update::do_updates()
if (!can_compare_record || compare_record(table))
{
int error;
if (table->default_field &&
(error= table->update_default_fields(1, ignore)))
goto err2;
if (table->default_field)
table->evaluate_update_default_function();
if (table->vfield &&
table->update_virtual_fields(table->file, VCOL_UPDATE_FOR_WRITE))
goto err2;
......
......@@ -7736,7 +7736,7 @@ int TABLE::update_virtual_field(Field *vf)
ignore_errors == 0. If set then an error was generated.
*/
int TABLE::update_default_fields(bool update_command, bool ignore_errors)
int TABLE::update_default_fields(bool ignore_errors)
{
Query_arena backup_arena;
Field **field_ptr;
......@@ -7756,14 +7756,9 @@ int TABLE::update_default_fields(bool update_command, bool ignore_errors)
*/
if (!field->has_explicit_value())
{
if (!update_command)
{
if (field->default_value &&
(field->default_value->flags || field->flags & BLOB_FLAG))
res|= (field->default_value->expr->save_in_field(field, 0) < 0);
}
else
res|= field->evaluate_update_default_function();
if (field->default_value &&
(field->default_value->flags || field->flags & BLOB_FLAG))
res|= (field->default_value->expr->save_in_field(field, 0) < 0);
if (!ignore_errors && res)
{
my_error(ER_CALCULATING_DEFAULT_VALUE, MYF(0), field->field_name);
......@@ -7776,6 +7771,21 @@ int TABLE::update_default_fields(bool update_command, bool ignore_errors)
DBUG_RETURN(res);
}
void TABLE::evaluate_update_default_function()
{
DBUG_ENTER("TABLE::evaluate_update_default_function");
if (s->has_update_default_function)
for (Field **field_ptr= default_field; *field_ptr ; field_ptr++)
{
Field *field= (*field_ptr);
if (!field->has_explicit_value() && field->has_update_default_function())
field->set_time();
}
DBUG_VOID_RETURN;
}
/**
Reset markers that fields are being updated
*/
......
......@@ -1453,7 +1453,8 @@ struct TABLE
ulong actual_key_flags(KEY *keyinfo);
int update_virtual_field(Field *vf);
int update_virtual_fields(handler *h, enum_vcol_update_mode update_mode);
int update_default_fields(bool update, bool ignore_errors);
int update_default_fields(bool ignore_errors);
void evaluate_update_default_function();
void reset_default_fields();
inline ha_rows stat_records() { return used_stat_records; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment