various cleanups

This commit is contained in:
Michael Widenius 2016-06-25 20:55:43 +02:00 committed by Sergei Golubchik
parent db7edfed17
commit 2fe8dd0f90
22 changed files with 148 additions and 159 deletions

View File

@ -1027,7 +1027,7 @@ static void init_connection_thd(struct st_connection *cn)
cn->has_thread=TRUE; cn->has_thread=TRUE;
} }
#else /*EMBEDDED_LIBRARY*/ #else /* ! EMBEDDED_LIBRARY*/
#define init_connection_thd(X) do { } while(0) #define init_connection_thd(X) do { } while(0)
#define do_send_query(cn,q,q_len) mysql_send_query(cn->mysql, q, q_len) #define do_send_query(cn,q,q_len) mysql_send_query(cn->mysql, q, q_len)

View File

@ -395,7 +395,7 @@ parse_page(
} }
if (per_page_details) { if (per_page_details) {
printf("index %lu page %lu leaf %u n_recs %lu data_bytes %lu" printf("index %lu page %lu leaf %u n_recs %lu data_bytes %lu"
"\n", (ulong) id, page_no, is_leaf, n_recs, data_bytes); "\n", (ulong) id, (ulong) page_no, is_leaf, n_recs, data_bytes);
} }
/* update per-index statistics */ /* update per-index statistics */
{ {

View File

@ -638,7 +638,7 @@ sub command_line_setup () {
if (! -f $glob_scriptname) if (! -f $glob_scriptname)
{ {
mtr_error("Can't find the location for the mysql-test-run script\n" . mtr_error("Can't find the location for the mysql-test-run script\n" .
"Go to to the mysql-test directory and execute the script " . "Go to the mysql-test directory and execute the script " .
"as follows:\n./$glob_scriptname"); "as follows:\n./$glob_scriptname");
} }

View File

@ -9793,7 +9793,7 @@ bool Column_definition::check(THD *thd)
const uint conditional_type_modifiers= AUTO_INCREMENT_FLAG; const uint conditional_type_modifiers= AUTO_INCREMENT_FLAG;
uint sign_len, allowed_type_modifier= 0; uint sign_len, allowed_type_modifier= 0;
ulong max_field_charlength= MAX_FIELD_CHARLENGTH; ulong max_field_charlength= MAX_FIELD_CHARLENGTH;
DBUG_ENTER("Create_field::check"); DBUG_ENTER("Column_definition::check");
/* Initialize data for a computed field */ /* Initialize data for a computed field */
if (vcol_info) if (vcol_info)

View File

@ -747,7 +747,6 @@ static ha_rows find_all_keys(THD *thd, Sort_param *param, SQL_SELECT *select,
sort_form->column_bitmaps_set(&sort_form->tmp_set, &sort_form->tmp_set, sort_form->column_bitmaps_set(&sort_form->tmp_set, &sort_form->tmp_set,
&sort_form->tmp_set); &sort_form->tmp_set);
if (quick_select) if (quick_select)
{ {
if (select->quick->reset()) if (select->quick->reset())

View File

@ -427,7 +427,7 @@ int Item::save_time_in_field(Field *field)
int Item::save_date_in_field(Field *field) int Item::save_date_in_field(Field *field)
{ {
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_date(&ltime, sql_mode_for_dates(current_thd))) if (get_date(&ltime, sql_mode_for_dates(field->table->in_use)))
return set_field_to_null_with_conversions(field, 0); return set_field_to_null_with_conversions(field, 0);
field->set_notnull(); field->set_notnull();
return field->store_time_dec(&ltime, decimals); return field->store_time_dec(&ltime, decimals);
@ -889,7 +889,7 @@ bool Item_field::find_item_in_field_list_processor(uchar *arg)
NOTES NOTES
This is used by filesort to register used fields in a a temporary This is used by filesort to register used fields in a a temporary
column read set or to register used fields in a view column read set or to register used fields in a view or check constraint
*/ */
bool Item_field::register_field_in_read_map(uchar *arg) bool Item_field::register_field_in_read_map(uchar *arg)
@ -897,9 +897,14 @@ bool Item_field::register_field_in_read_map(uchar *arg)
TABLE *table= (TABLE *) arg; TABLE *table= (TABLE *) arg;
if (field->table == table || !table) if (field->table == table || !table)
bitmap_set_bit(field->table->read_set, field->field_index); bitmap_set_bit(field->table->read_set, field->field_index);
if (field->vcol_info && field->vcol_info->expr_item) if (field->vcol_info && field->vcol_info->expr_item &&
!bitmap_is_set(field->table->vcol_set, field->field_index))
{
/* Ensure that the virtual fields is updated on read or write */
bitmap_set_bit(field->table->vcol_set, field->field_index);
return field->vcol_info->expr_item->walk(&Item::register_field_in_read_map, return field->vcol_info->expr_item->walk(&Item::register_field_in_read_map,
1, arg); 1, arg);
}
return 0; return 0;
} }
@ -1123,6 +1128,7 @@ Item *Item::safe_charset_converter(THD *thd, CHARSET_INFO *tocs)
TODO: we should eventually check all other use cases of change_item_tree(). TODO: we should eventually check all other use cases of change_item_tree().
Perhaps some more potentially dangerous substitution examples exist. Perhaps some more potentially dangerous substitution examples exist.
*/ */
Item *Item_cache::safe_charset_converter(THD *thd, CHARSET_INFO *tocs) Item *Item_cache::safe_charset_converter(THD *thd, CHARSET_INFO *tocs)
{ {
if (!example) if (!example)
@ -1150,6 +1156,7 @@ Item *Item_cache::safe_charset_converter(THD *thd, CHARSET_INFO *tocs)
the latter returns a non-fixed Item, so val_str() crashes afterwards. the latter returns a non-fixed Item, so val_str() crashes afterwards.
Override Item_num method, to return a fixed item. Override Item_num method, to return a fixed item.
*/ */
Item *Item_num::safe_charset_converter(THD *thd, CHARSET_INFO *tocs) Item *Item_num::safe_charset_converter(THD *thd, CHARSET_INFO *tocs)
{ {
/* /*

View File

@ -571,7 +571,6 @@ class Item_num_op :public Item_func_numhybrid
{ {
print_op(str, query_type); print_op(str, query_type);
} }
void fix_length_and_dec(); void fix_length_and_dec();
}; };
@ -2019,7 +2018,6 @@ private:
return false; return false;
} }
}; };

View File

@ -4108,9 +4108,7 @@ static void my_malloc_size_cb_func(long long size, my_bool is_thread_specific)
thd->status_var.global_memory_used+= size; thd->status_var.global_memory_used+= size;
} }
else else
{
update_global_memory_status(size); update_global_memory_status(size);
}
} }
} }

View File

@ -7206,8 +7206,8 @@ ER_INVALID_NTILE_ARGUMENT
ER_EXPRESSION_IS_TOO_BIG ER_EXPRESSION_IS_TOO_BIG
eng "%s expression is too big for '%s'" eng "%s expression is too big for '%s'"
ER_ERROR_EVALUATING_EXPRESSION ER_ERROR_EVALUATING_EXPRESSION
eng "Got an error evaluating stored expression %`.192s" eng "Got an error evaluating stored expression %`s"
ER_CALCULATING_DEFAULT_VALUE ER_CALCULATING_DEFAULT_VALUE
eng "Got an error when calculating default value for '%s'" eng "Got an error when calculating default value for %`s"
ER_EXPRESSION_REFERS_TO_UNINIT_FIELD 01000 ER_EXPRESSION_REFERS_TO_UNINIT_FIELD 01000
eng "Expression for field %`-.64s is refering to uninitialized field %`-.64s" eng "Expression for field %`-.64s is refering to uninitialized field %`s"

View File

@ -163,7 +163,7 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list,
- Run a normal repair using the new index file and the old data file - Run a normal repair using the new index file and the old data file
*/ */
if (table->s->frm_version != FRM_VER_TRUE_VARCHAR && if (table->s->frm_version < FRM_VER_TRUE_VARCHAR &&
table->s->varchar_fields) table->s->varchar_fields)
{ {
error= send_check_errmsg(thd, table_list, "repair", error= send_check_errmsg(thd, table_list, "repair",

View File

@ -7728,7 +7728,7 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
table_arg->auto_increment_field_not_null= FALSE; table_arg->auto_increment_field_not_null= FALSE;
f.rewind(); f.rewind();
} }
else if (thd->lex->unit.insert_table_with_stored_vcol) else
vcol_table= thd->lex->unit.insert_table_with_stored_vcol; vcol_table= thd->lex->unit.insert_table_with_stored_vcol;
while ((fld= f++)) while ((fld= f++))
@ -7796,6 +7796,7 @@ void switch_to_nullable_trigger_fields(List<Item> &items, TABLE *table)
{ {
Field** field= table->field_to_fill(); Field** field= table->field_to_fill();
/* True if we have NOT NULL fields and BEFORE triggers */
if (field != table->field) if (field != table->field)
{ {
List_iterator_fast<Item> it(items); List_iterator_fast<Item> it(items);
@ -7888,7 +7889,8 @@ static bool not_null_fields_have_null_values(TABLE *table)
*/ */
bool bool
fill_record_n_invoke_before_triggers(THD *thd, TABLE *table, List<Item> &fields, fill_record_n_invoke_before_triggers(THD *thd, TABLE *table,
List<Item> &fields,
List<Item> &values, bool ignore_errors, List<Item> &values, bool ignore_errors,
enum trg_event_type event) enum trg_event_type event)
{ {
@ -7899,15 +7901,16 @@ fill_record_n_invoke_before_triggers(THD *thd, TABLE *table, List<Item> &fields,
event == TRG_EVENT_UPDATE); event == TRG_EVENT_UPDATE);
if (!result && triggers) if (!result && triggers)
result= triggers->process_triggers(thd, event, TRG_ACTION_BEFORE, TRUE) || {
not_null_fields_have_null_values(table); if (triggers->process_triggers(thd, event, TRG_ACTION_BEFORE,
TRUE) ||
not_null_fields_have_null_values(table))
return TRUE;
/* /*
Re-calculate virtual fields to cater for cases when base columns are Re-calculate virtual fields to cater for cases when base columns are
updated by the triggers. updated by the triggers.
*/ */
if (!result && triggers)
{
List_iterator_fast<Item> f(fields); List_iterator_fast<Item> f(fields);
Item *fld; Item *fld;
Item_field *item_field; Item_field *item_field;
@ -7915,7 +7918,7 @@ fill_record_n_invoke_before_triggers(THD *thd, TABLE *table, List<Item> &fields,
{ {
fld= (Item_field*)f++; fld= (Item_field*)f++;
item_field= fld->field_for_view_update(); item_field= fld->field_for_view_update();
if (item_field && item_field->field && table && 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, result= update_virtual_fields(thd, table,
@ -7930,6 +7933,7 @@ fill_record_n_invoke_before_triggers(THD *thd, TABLE *table, List<Item> &fields,
/** /**
Fill the field buffer of a table with the values of an Item list Fill the field buffer of a table with the values of an Item list
All fields are given a value
@param thd thread handler @param thd thread handler
@param table_arg the table that is being modified @param table_arg the table that is being modified
@ -8005,7 +8009,8 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
goto err; goto err;
field->set_explicit_default(value); field->set_explicit_default(value);
} }
/* Update virtual fields*/ /* There is no default fields to update, as all fields are updated */
/* Update virtual fields */
thd->abort_on_warning= FALSE; thd->abort_on_warning= FALSE;
if (table->vfield && if (table->vfield &&
update_virtual_fields(thd, table, update_virtual_fields(thd, table,
@ -8065,7 +8070,8 @@ 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, result= update_virtual_fields(thd, table,
table->triggers ? VCOL_UPDATE_ALL : table->triggers ?
VCOL_UPDATE_ALL :
VCOL_UPDATE_FOR_WRITE); VCOL_UPDATE_FOR_WRITE);
} }
return result; return result;

View File

@ -1494,7 +1494,7 @@ public:
ha_rows cuted_fields, sent_row_count, examined_row_count; ha_rows cuted_fields, sent_row_count, examined_row_count;
ulonglong client_capabilities; ulonglong client_capabilities;
ulong query_plan_flags; ulong query_plan_flags;
uint in_sub_stmt; uint in_sub_stmt; /* 0, SUB_STMT_TRIGGER or SUB_STMT_FUNCTION */
bool enable_slow_log; bool enable_slow_log;
bool last_insert_id_used; bool last_insert_id_used;
SAVEPOINT *savepoints; SAVEPOINT *savepoints;

View File

@ -860,15 +860,14 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
thd->abort_on_warning= !ignore && thd->is_strict_mode(); thd->abort_on_warning= !ignore && thd->is_strict_mode();
table->reset_default_fields();
table->prepare_triggers_for_insert_stmt_or_event(); table->prepare_triggers_for_insert_stmt_or_event();
table->mark_columns_needed_for_insert(); table->mark_columns_needed_for_insert();
if (table_list->prepare_where(thd, 0, TRUE) || if (table_list->prepare_where(thd, 0, TRUE) ||
table_list->prepare_check_option(thd)) table_list->prepare_check_option(thd))
error= 1; error= 1;
table->reset_default_fields();
switch_to_nullable_trigger_fields(fields, table); switch_to_nullable_trigger_fields(fields, table);
switch_to_nullable_trigger_fields(update_fields, table); switch_to_nullable_trigger_fields(update_fields, table);
switch_to_nullable_trigger_fields(update_values, table); switch_to_nullable_trigger_fields(update_values, table);
@ -2411,6 +2410,7 @@ TABLE *Delayed_insert::get_local_table(THD* client_thd)
/* Copy the TABLE object. */ /* Copy the TABLE object. */
copy= new (copy_tmp) TABLE; copy= new (copy_tmp) TABLE;
*copy= *table; *copy= *table;
/* We don't need to change the file handler here */ /* We don't need to change the file handler here */
/* Assign the pointers for the field pointers array and the record. */ /* Assign the pointers for the field pointers array and the record. */
field= copy->field= (Field**) (copy + 1); field= copy->field= (Field**) (copy + 1);

View File

@ -3073,10 +3073,11 @@ CHARSET_INFO* get_sql_field_charset(Create_field *sql_field,
@param column_definitions The list of column definitions, in the physical @param column_definitions The list of column definitions, in the physical
order in which they appear in the table. order in which they appear in the table.
*/ */
void promote_first_timestamp_column(List<Create_field> *column_definitions) void promote_first_timestamp_column(List<Create_field> *column_definitions)
{ {
List_iterator<Create_field> it(*column_definitions); List_iterator_fast<Create_field> it(*column_definitions);
Create_field *column_definition; Create_field *column_definition;
while ((column_definition= it++) != NULL) while ((column_definition= it++) != NULL)
@ -3124,8 +3125,8 @@ static void check_duplicate_key(THD *thd,
if (!key->key_create_info.check_for_duplicate_indexes || key->generated) if (!key->key_create_info.check_for_duplicate_indexes || key->generated)
return; return;
List_iterator<Key> key_list_iterator(*key_list); List_iterator_fast<Key> key_list_iterator(*key_list);
List_iterator<Key_part_spec> key_column_iterator(key->columns); List_iterator_fast<Key_part_spec> key_column_iterator(key->columns);
Key *k; Key *k;
while ((k= key_list_iterator++)) while ((k= key_list_iterator++))
@ -3149,7 +3150,7 @@ static void check_duplicate_key(THD *thd,
Check that the keys have identical columns in the same order. Check that the keys have identical columns in the same order.
*/ */
List_iterator<Key_part_spec> k_column_iterator(k->columns); List_iterator_fast<Key_part_spec> k_column_iterator(k->columns);
bool all_columns_are_identical= true; bool all_columns_are_identical= true;
@ -3227,7 +3228,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
KEY_PART_INFO *key_part_info; KEY_PART_INFO *key_part_info;
int field_no,dup_no; int field_no,dup_no;
int select_field_pos,auto_increment=0; int select_field_pos,auto_increment=0;
List_iterator<Create_field> it(alter_info->create_list); List_iterator_fast<Create_field> it(alter_info->create_list);
List_iterator<Create_field> it2(alter_info->create_list); List_iterator<Create_field> it2(alter_info->create_list);
uint total_uneven_bit_length= 0; uint total_uneven_bit_length= 0;
int select_field_count= C_CREATE_SELECT(create_table_mode); int select_field_count= C_CREATE_SELECT(create_table_mode);

View File

@ -95,8 +95,8 @@ bool compare_record(const TABLE *table)
/* /*
The storage engine has read all columns, so it's safe to compare all bits The storage engine has read all columns, so it's safe to compare all bits
including those not in the write_set. This is cheaper than the field-by-field including those not in the write_set. This is cheaper than the
comparison done above. field-by-field comparison done above.
*/ */
if (table->s->can_cmp_whole_record) if (table->s->can_cmp_whole_record)
return cmp_record(table,record[1]); return cmp_record(table,record[1]);
@ -371,7 +371,7 @@ int mysql_update(THD *thd,
switch_to_nullable_trigger_fields(fields, table); switch_to_nullable_trigger_fields(fields, table);
switch_to_nullable_trigger_fields(values, table); switch_to_nullable_trigger_fields(values, table);
/* Apply the IN=>EXISTS transformation to all subqueries and optimize them. */ /* Apply the IN=>EXISTS transformation to all subqueries and optimize them */
if (select_lex->optimize_unflattened_subqueries(false)) if (select_lex->optimize_unflattened_subqueries(false))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);

View File

@ -1011,12 +1011,12 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
uint len; uint len;
uint ext_key_parts= 0; uint ext_key_parts= 0;
plugin_ref se_plugin= 0; plugin_ref se_plugin= 0;
keyinfo= &first_keyinfo;
share->ext_key_parts= 0;
MEM_ROOT *old_root= thd->mem_root; MEM_ROOT *old_root= thd->mem_root;
Virtual_column_info **table_check_constraints; Virtual_column_info **table_check_constraints;
DBUG_ENTER("TABLE_SHARE::init_from_binary_frm_image"); DBUG_ENTER("TABLE_SHARE::init_from_binary_frm_image");
keyinfo= &first_keyinfo;
share->ext_key_parts= 0;
thd->mem_root= &share->mem_root; thd->mem_root= &share->mem_root;
if (write && write_frm_image(frm_image, frm_length)) if (write && write_frm_image(frm_image, frm_length))
@ -1025,6 +1025,16 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
if (frm_length < FRM_HEADER_SIZE + FRM_FORMINFO_SIZE) if (frm_length < FRM_HEADER_SIZE + FRM_FORMINFO_SIZE)
goto err; goto err;
share->frm_version= frm_image[2];
/*
Check if .frm file created by MySQL 5.0. In this case we want to
display CHAR fields as CHAR and not as VARCHAR.
We do it this way as we want to keep the old frm version to enable
MySQL 4.1 to read these files.
*/
if (share->frm_version == FRM_VER_TRUE_VARCHAR -1 && frm_image[33] == 5)
share->frm_version= FRM_VER_TRUE_VARCHAR;
new_field_pack_flag= frm_image[27]; new_field_pack_flag= frm_image[27];
new_frm_ver= (frm_image[2] - FRM_VER); new_frm_ver= (frm_image[2] - FRM_VER);
field_pack_length= new_frm_ver < 2 ? 11 : 17; field_pack_length= new_frm_ver < 2 ? 11 : 17;
@ -1113,16 +1123,6 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
if (forminfo + FRM_FORMINFO_SIZE >= frm_image_end) if (forminfo + FRM_FORMINFO_SIZE >= frm_image_end)
goto err; goto err;
share->frm_version= frm_image[2];
/*
Check if .frm file created by MySQL 5.0. In this case we want to
display CHAR fields as CHAR and not as VARCHAR.
We do it this way as we want to keep the old frm version to enable
MySQL 4.1 to read these files.
*/
if (share->frm_version == FRM_VER_TRUE_VARCHAR -1 && frm_image[33] == 5)
share->frm_version= FRM_VER_TRUE_VARCHAR;
#ifdef WITH_PARTITION_STORAGE_ENGINE #ifdef WITH_PARTITION_STORAGE_ENGINE
if (frm_image[61] && !share->default_part_plugin) if (frm_image[61] && !share->default_part_plugin)
{ {
@ -1563,7 +1563,6 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
Field::geometry_type geom_type= Field::GEOM_GEOMETRY; Field::geometry_type geom_type= Field::GEOM_GEOMETRY;
LEX_STRING comment; LEX_STRING comment;
Virtual_column_info *vcol_info= 0; Virtual_column_info *vcol_info= 0;
bool fld_stored_in_db= TRUE;
uint gis_length, gis_decimals, srid= 0; uint gis_length, gis_decimals, srid= 0;
if (new_frm_ver >= 3) if (new_frm_ver >= 3)
@ -1621,6 +1620,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
{ {
DBUG_ASSERT(interval_nr); // Expect non-null expression DBUG_ASSERT(interval_nr); // Expect non-null expression
/* /*
MariaDB version 10.0 version.
The interval_id byte in the .frm file stores the length of the The interval_id byte in the .frm file stores the length of the
expression statement for a virtual column. expression statement for a virtual column.
*/ */
@ -1669,11 +1669,13 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
Get virtual column data stored in the .frm file as follows: Get virtual column data stored in the .frm file as follows:
byte 1 = 1 | 2 byte 1 = 1 | 2
byte 2 = sql_type byte 2 = sql_type
byte 3 = flags (as of now, 0 - no flags, 1 - field is physically stored) byte 3 = flags (as of now, 0 - no flags,
[byte 4] = optional interval_id for sql_type (only if byte 1 == 2) 1 - field is physically stored)
[byte 4] = optional interval_id for sql_type (if byte 1 == 2)
next byte ... = virtual column expression (text data) next byte ... = virtual column expression (text data)
*/ */
vcol_info= new Virtual_column_info();
vcol_info= new (&share->mem_root) Virtual_column_info();
bool opt_interval_id= (uint)vcol_screen_pos[0] == 2; bool opt_interval_id= (uint)vcol_screen_pos[0] == 2;
field_type= (enum_field_types) (uchar) vcol_screen_pos[1]; field_type= (enum_field_types) (uchar) vcol_screen_pos[1];
if (opt_interval_id) if (opt_interval_id)
@ -1681,7 +1683,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
else if ((uint)vcol_screen_pos[0] != 1) else if ((uint)vcol_screen_pos[0] != 1)
goto err; goto err;
fld_stored_in_db= (bool) (uint) vcol_screen_pos[2]; vcol_info->stored_in_db= (bool) (uint) vcol_screen_pos[2];
vcol_expr_length= vcol_info_length - vcol_expr_length= vcol_info_length -
(uint)(FRM_VCOL_OLD_HEADER_SIZE(opt_interval_id)); (uint)(FRM_VCOL_OLD_HEADER_SIZE(opt_interval_id));
if (!(vcol_info->expr_str.str= if (!(vcol_info->expr_str.str=
@ -1791,14 +1793,9 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
if (!reg_field) // Not supported field type if (!reg_field) // Not supported field type
goto err; goto err;
reg_field->field_index= i; reg_field->field_index= i;
reg_field->comment=comment; reg_field->comment=comment;
reg_field->vcol_info= vcol_info; reg_field->vcol_info= vcol_info;
if (vcol_info)
reg_field->vcol_info->stored_in_db= fld_stored_in_db;
else
DBUG_ASSERT(fld_stored_in_db == true);
if (field_type == MYSQL_TYPE_BIT && !f_bit_as_char(pack_flag)) if (field_type == MYSQL_TYPE_BIT && !f_bit_as_char(pack_flag))
{ {
null_bits_are_used= 1; null_bits_are_used= 1;
@ -2406,7 +2403,6 @@ int TABLE_SHARE::init_from_sql_statement_string(THD *thd, bool write,
handlerton *hton= plugin_hton(db_plugin); handlerton *hton= plugin_hton(db_plugin);
LEX_CUSTRING frm= {0,0}; LEX_CUSTRING frm= {0,0};
LEX_STRING db_backup= { thd->db, thd->db_length }; LEX_STRING db_backup= { thd->db, thd->db_length };
DBUG_ENTER("TABLE_SHARE::init_from_sql_statement_string"); DBUG_ENTER("TABLE_SHARE::init_from_sql_statement_string");
/* /*
@ -2517,12 +2513,9 @@ void TABLE_SHARE::free_frm_image(const uchar *frm)
@brief @brief
Perform semantic analysis of the defining expression for a virtual column Perform semantic analysis of the defining expression for a virtual column
@param @param thd The thread object
thd The thread object @param table The table containing the virtual column
@param @param field Field if this is a DEFAULT or AS, otherwise NULL
table The table containing the virtual column
@param
vcol_field The virtual field whose defining expression is to be analyzed
@param vcol The Virtual_column object @param vcol The Virtual_column object
@ -2631,19 +2624,13 @@ end:
@brief @brief
Unpack the definition of a virtual column from its linear representation Unpack the definition of a virtual column from its linear representation
@param @param thd The thread object
thd The thread object @param mem_root Where to allocate memory
@param @param table The table containing the virtual column
mem_root The mem_root object where to allocated memory @param vcol The Virtual_column object
@param @param field Field if this is a DEFAULT or AS, otherwise NULL
table The table containing the virtual column @param[out] error_reported Flag to inform the caller that no
@param other error messages are to be generated
field The field for the virtual
@param
vcol_expr The string representation of the defining expression
@param[out]
error_reported The flag to inform the caller that no other error
messages are to be generated
@details @details
@ -2705,16 +2692,13 @@ Virtual_column_info *unpack_vcol_info_from_frm(THD *thd,
(char*) parse_vcol_keyword.str, (char*) parse_vcol_keyword.str,
parse_vcol_keyword.length); parse_vcol_keyword.length);
str_len= parse_vcol_keyword.length; str_len= parse_vcol_keyword.length;
memcpy(vcol_expr_str + str_len, "(", 1); vcol_expr_str[str_len++]= '(';
str_len++;
memcpy(vcol_expr_str + str_len, memcpy(vcol_expr_str + str_len,
(char*) vcol_expr->str, (char*) vcol_expr->str,
vcol_expr->length); vcol_expr->length);
str_len+= vcol_expr->length; str_len+= vcol_expr->length;
memcpy(vcol_expr_str + str_len, ")", 1); vcol_expr_str[str_len++]= ')';
str_len++; vcol_expr_str[str_len++]= 0;
memcpy(vcol_expr_str + str_len, "\0", 1);
str_len++;
if (parser_state.init(thd, vcol_expr_str, str_len)) if (parser_state.init(thd, vcol_expr_str, str_len))
goto err; goto err;
@ -6517,9 +6501,6 @@ void TABLE::mark_virtual_columns_for_write(bool insert_fl)
Field **vfield_ptr, *tmp_vfield; Field **vfield_ptr, *tmp_vfield;
bool bitmap_updated= FALSE; bool bitmap_updated= FALSE;
if (!vfield)
return;
for (vfield_ptr= vfield; *vfield_ptr; vfield_ptr++) for (vfield_ptr= vfield; *vfield_ptr; vfield_ptr++)
{ {
tmp_vfield= *vfield_ptr; tmp_vfield= *vfield_ptr;
@ -7249,10 +7230,11 @@ bool is_simple_order(ORDER *order)
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
stores them in the table record buffer. stores them in the table record buffer.
If vcol_update_mode is set to VCOL_UPDATE_ALL then all virtual column are If vcol_update_mode is set to VCOL_UPDATE_ALL then all virtual column are
computed. Otherwise, only fields from vcol_set are computed: all of them, computed.
if vcol_update_mode is set to VCOL_UPDATE_FOR_WRITE, and, only those with If vcol_update_mode is set to VCOL_UPDATE_FOR_WRITE then all
the stored_in_db flag set to false, if vcol_update_mode is equal to fields that are set in vcol_set are updated.
VCOL_UPDATE_FOR_READ. If vcol_update_mode is set to VCOL_UPDATE_FOR_READ then all
fields that are set in vcol_set and are not stored are updated.
@retval @retval
0 Success 0 Success
@ -7277,7 +7259,8 @@ int update_virtual_fields(THD *thd, TABLE *table,
DBUG_ASSERT(vcol_info); DBUG_ASSERT(vcol_info);
DBUG_ASSERT(vcol_info->expr_item); DBUG_ASSERT(vcol_info->expr_item);
if ((bitmap_is_set(table->vcol_set, vfield->field_index) && if ((bitmap_is_set(table->vcol_set, vfield->field_index) &&
(vcol_update_mode == VCOL_UPDATE_FOR_WRITE || !vcol_info->stored_in_db)) || (vcol_update_mode == VCOL_UPDATE_FOR_WRITE ||
!vcol_info->stored_in_db)) ||
vcol_update_mode == VCOL_UPDATE_ALL) vcol_update_mode == VCOL_UPDATE_ALL)
{ {
/* Compute the actual value of the virtual fields */ /* Compute the actual value of the virtual fields */
@ -7317,34 +7300,34 @@ int update_virtual_fields(THD *thd, TABLE *table,
int TABLE::update_default_fields(bool update_command, bool ignore_errors) int TABLE::update_default_fields(bool update_command, bool ignore_errors)
{ {
DBUG_ENTER("update_default_fields"); DBUG_ENTER("update_default_fields");
Field **dfield_ptr, *dfield; Field **field_ptr;
int res= 0; int res= 0;
DBUG_ASSERT(default_field); DBUG_ASSERT(default_field);
in_use->reset_arena_for_cached_items(expr_arena); in_use->reset_arena_for_cached_items(expr_arena);
/* Iterate over fields with default functions in the table */ /* Iterate over fields with default functions in the table */
for (dfield_ptr= default_field; *dfield_ptr ; dfield_ptr++) for (field_ptr= default_field; *field_ptr ; field_ptr++)
{ {
dfield= (*dfield_ptr); Field *field= (*field_ptr);
/* /*
If an explicit default value for a filed overrides the default, If an explicit default value for a field overrides the default,
do not update the field with its automatic default value. do not update the field with its automatic default value.
*/ */
if (!dfield->has_explicit_value()) if (!field->has_explicit_value())
{ {
if (!update_command) if (!update_command)
{ {
if (dfield->default_value) if (field->default_value)
res|= (dfield->default_value->expr_item->save_in_field(dfield, 0) < 0); res|= (field->default_value->expr_item->save_in_field(field, 0) < 0);
else else
res|= dfield->evaluate_insert_default_function(); res|= field->evaluate_insert_default_function();
} }
else else
res|= dfield->evaluate_update_default_function(); res|= field->evaluate_update_default_function();
if (!ignore_errors && res) if (!ignore_errors && res)
{ {
my_error(ER_CALCULATING_DEFAULT_VALUE, MYF(0), dfield->field_name); my_error(ER_CALCULATING_DEFAULT_VALUE, MYF(0), field->field_name);
break; break;
} }
res= 0; res= 0;

View File

@ -700,7 +700,6 @@ struct TABLE_SHARE
*/ */
const File_parser *view_def; const File_parser *view_def;
/* /*
Cache for row-based replication table share checks that does not Cache for row-based replication table share checks that does not
need to be repeated. Possible values are: -1 when cache value is need to be repeated. Possible values are: -1 when cache value is

View File

@ -768,8 +768,7 @@ static size_t packed_fields_length(List<Create_field> &create_fields)
length+= strlen(field->field_name)+1; length+= strlen(field->field_name)+1;
length+= field->comment.length; length+= field->comment.length;
} }
length++; length+= 2;
length++;
DBUG_RETURN(length); DBUG_RETURN(length);
} }
@ -910,7 +909,6 @@ static bool pack_fields(uchar **buff_arg, List<Create_field> &create_fields,
*buff++= sep; *buff++= sep;
} }
*buff++= 0; *buff++= 0;
} }
} }
} }

View File

@ -82,7 +82,7 @@ alter table t1 add key d(d,a) clustering=yes, add key b(b) clustering=yes;
explain select * from t1 where c > "0"; explain select * from t1 where c > "0";
select * from t1 where c > "0"; select * from t1 where c > "0";
--replace_column 7 NULL 9 NULL; --replace_column 4 index 7 NULL 9 NULL;
explain select * from t1 where b > "0"; explain select * from t1 where b > "0";
select * from t1 where b > "0"; select * from t1 where b > "0";