summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorMichael Widenius <monty@mariadb.org>2016-06-25 20:55:43 +0200
committerSergei Golubchik <serg@mariadb.org>2016-06-30 11:43:02 +0200
commit2fe8dd0f90e2bbe0180e30c36ebc9132fcdd4b06 (patch)
tree4d84b1ddb3e0af4660d52c0ac1792e85c652fc0d /sql
parentdb7edfed17efe6bc3684b0fbacc0b0249e4f0fa2 (diff)
downloadmariadb-git-2fe8dd0f90e2bbe0180e30c36ebc9132fcdd4b06.tar.gz
various cleanups
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc2
-rw-r--r--sql/filesort.cc1
-rw-r--r--sql/item.cc15
-rw-r--r--sql/item_func.h4
-rw-r--r--sql/item_strfunc.h2
-rw-r--r--sql/item_sum.h8
-rw-r--r--sql/item_timefunc.h18
-rw-r--r--sql/mysqld.cc2
-rw-r--r--sql/share/errmsg-utf8.txt8
-rw-r--r--sql/sql_admin.cc2
-rw-r--r--sql/sql_base.cc36
-rw-r--r--sql/sql_class.h2
-rw-r--r--sql/sql_insert.cc4
-rw-r--r--sql/sql_table.cc17
-rw-r--r--sql/sql_update.cc6
-rw-r--r--sql/table.cc161
-rw-r--r--sql/table.h1
-rw-r--r--sql/unireg.cc10
18 files changed, 144 insertions, 155 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 7145be366c7..8ad4dbb876e 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -9793,7 +9793,7 @@ bool Column_definition::check(THD *thd)
const uint conditional_type_modifiers= AUTO_INCREMENT_FLAG;
uint sign_len, allowed_type_modifier= 0;
ulong max_field_charlength= MAX_FIELD_CHARLENGTH;
- DBUG_ENTER("Create_field::check");
+ DBUG_ENTER("Column_definition::check");
/* Initialize data for a computed field */
if (vcol_info)
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 82a5c90d0bb..4bfeaf90a68 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -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->tmp_set);
-
if (quick_select)
{
if (select->quick->reset())
diff --git a/sql/item.cc b/sql/item.cc
index 3dba0c42a85..6a3279e6a84 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -427,7 +427,7 @@ int Item::save_time_in_field(Field *field)
int Item::save_date_in_field(Field *field)
{
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);
field->set_notnull();
return field->store_time_dec(&ltime, decimals);
@@ -889,7 +889,7 @@ bool Item_field::find_item_in_field_list_processor(uchar *arg)
NOTES
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)
@@ -897,9 +897,14 @@ bool Item_field::register_field_in_read_map(uchar *arg)
TABLE *table= (TABLE *) arg;
if (field->table == table || !table)
bitmap_set_bit(field->table->read_set, field->field_index);
- if (field->vcol_info && field->vcol_info->expr_item)
- return field->vcol_info->expr_item->walk(&Item::register_field_in_read_map,
+ 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,
1, arg);
+ }
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().
Perhaps some more potentially dangerous substitution examples exist.
*/
+
Item *Item_cache::safe_charset_converter(THD *thd, CHARSET_INFO *tocs)
{
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.
Override Item_num method, to return a fixed item.
*/
+
Item *Item_num::safe_charset_converter(THD *thd, CHARSET_INFO *tocs)
{
/*
diff --git a/sql/item_func.h b/sql/item_func.h
index fa9789fe34d..f975d8c2806 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -571,7 +571,6 @@ class Item_num_op :public Item_func_numhybrid
{
print_op(str, query_type);
}
-
void fix_length_and_dec();
};
@@ -1409,7 +1408,7 @@ public:
return res;
}
void fix_num_length_and_dec();
- void update_used_tables()
+ void update_used_tables()
{
/*
TODO: Make a member in UDF_INIT and return if a UDF is deterministic or
@@ -2019,7 +2018,6 @@ private:
return false;
}
-
};
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 3675707db41..51e2ee85034 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -724,7 +724,7 @@ public:
Item_str_func(thd, list)
{ collation.set(cs); }
String *val_str(String *);
- void fix_length_and_dec()
+ void fix_length_and_dec()
{
max_length= arg_count * 4;
}
diff --git a/sql/item_sum.h b/sql/item_sum.h
index 8fcc4e203bc..7c11205ba5f 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -61,7 +61,7 @@ public:
Aggregator (Item_sum *arg): item_sum(arg) {}
virtual ~Aggregator () {} /* Keep gcc happy */
- enum Aggregator_type { SIMPLE_AGGREGATOR, DISTINCT_AGGREGATOR };
+ enum Aggregator_type { SIMPLE_AGGREGATOR, DISTINCT_AGGREGATOR };
virtual Aggregator_type Aggrtype() = 0;
/**
@@ -411,8 +411,8 @@ public:
*/
inline bool reset_and_add()
{
- aggregator_clear();
- return aggregator_add();
+ aggregator_clear();
+ return aggregator_add();
};
/*
@@ -458,7 +458,7 @@ public:
*/
void make_const ()
{
- used_tables_cache= 0;
+ used_tables_cache= 0;
const_item_cache= true;
}
virtual bool const_during_execution() const { return false; }
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index 7bd3cf58a7a..ee6394dac37 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -49,7 +49,7 @@ public:
Item_func_period_add(THD *thd, Item *a, Item *b): Item_int_func(thd, a, b) {}
longlong val_int();
const char *func_name() const { return "period_add"; }
- void fix_length_and_dec()
+ void fix_length_and_dec()
{
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
}
@@ -76,7 +76,7 @@ public:
Item_func_to_days(THD *thd, Item *a): Item_int_func(thd, a) {}
longlong val_int();
const char *func_name() const { return "to_days"; }
- void fix_length_and_dec()
+ void fix_length_and_dec()
{
decimals=0;
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
@@ -99,7 +99,7 @@ public:
Item_func_to_seconds(THD *thd, Item *a): Item_int_func(thd, a) {}
longlong val_int();
const char *func_name() const { return "to_seconds"; }
- void fix_length_and_dec()
+ void fix_length_and_dec()
{
decimals=0;
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
@@ -132,7 +132,7 @@ public:
Item_func_dayofmonth(THD *thd, Item *a): Item_int_func(thd, a) {}
longlong val_int();
const char *func_name() const { return "dayofmonth"; }
- void fix_length_and_dec()
+ void fix_length_and_dec()
{
decimals=0;
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
@@ -155,7 +155,7 @@ public:
longlong val_int();
double val_real()
{ DBUG_ASSERT(fixed == 1); return (double) Item_func_month::val_int(); }
- String *val_str(String *str)
+ String *val_str(String *str)
{
longlong nr= val_int();
if (null_value)
@@ -166,7 +166,7 @@ public:
const char *func_name() const { return "month"; }
enum Item_result result_type () const { return INT_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
- void fix_length_and_dec()
+ void fix_length_and_dec()
{
decimals= 0;
fix_char_length(2);
@@ -207,7 +207,7 @@ public:
Item_func_dayofyear(THD *thd, Item *a): Item_int_func(thd, a) {}
longlong val_int();
const char *func_name() const { return "dayofyear"; }
- void fix_length_and_dec()
+ void fix_length_and_dec()
{
decimals= 0;
fix_char_length(3);
@@ -291,7 +291,7 @@ public:
Item_func_second(THD *thd, Item *a): Item_int_func(thd, a) {}
longlong val_int();
const char *func_name() const { return "second"; }
- void fix_length_and_dec()
+ void fix_length_and_dec()
{
decimals=0;
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
@@ -1045,7 +1045,7 @@ public:
Item_func_microsecond(THD *thd, Item *a): Item_int_func(thd, a) {}
longlong val_int();
const char *func_name() const { return "microsecond"; }
- void fix_length_and_dec()
+ void fix_length_and_dec()
{
decimals=0;
maybe_null=1;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 5d7c6ef9b2f..7173ee66959 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -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;
}
else
- {
update_global_memory_status(size);
- }
}
}
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index ac1dd9758ea..9bdcf154848 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -4846,7 +4846,7 @@ ER_WARN_USING_OTHER_HANDLER
por "Usando engine de armazenamento %s para tabela '%s'"
spa "Usando motor de almacenamiento %s para tabla '%s'"
swe "Använder handler %s för tabell '%s'"
-ER_CANT_AGGREGATE_2COLLATIONS
+ER_CANT_AGGREGATE_2COLLATIONS
eng "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'"
ger "Unerlaubte Mischung von Sortierreihenfolgen (%s, %s) und (%s, %s) für Operation '%s'"
jpn "照合順序 (%s,%s) と (%s,%s) の混在は操作 '%s' では不正です。"
@@ -7206,8 +7206,8 @@ ER_INVALID_NTILE_ARGUMENT
ER_EXPRESSION_IS_TOO_BIG
eng "%s expression is too big for '%s'"
ER_ERROR_EVALUATING_EXPRESSION
- eng "Got an error evaluating stored expression %`.192s"
+ eng "Got an error evaluating stored expression %`s"
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
- eng "Expression for field %`-.64s is refering to uninitialized field %`-.64s"
+ eng "Expression for field %`-.64s is refering to uninitialized field %`s"
diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc
index 4414f11ecd4..e76e5d830c9 100644
--- a/sql/sql_admin.cc
+++ b/sql/sql_admin.cc
@@ -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
*/
- if (table->s->frm_version != FRM_VER_TRUE_VARCHAR &&
+ if (table->s->frm_version < FRM_VER_TRUE_VARCHAR &&
table->s->varchar_fields)
{
error= send_check_errmsg(thd, table_list, "repair",
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index fbc26846fda..b8638ac5ee5 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -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;
f.rewind();
}
- else if (thd->lex->unit.insert_table_with_stored_vcol)
+ else
vcol_table= thd->lex->unit.insert_table_with_stored_vcol;
while ((fld= f++))
@@ -7796,6 +7796,7 @@ void switch_to_nullable_trigger_fields(List<Item> &items, TABLE *table)
{
Field** field= table->field_to_fill();
+ /* True if we have NOT NULL fields and BEFORE triggers */
if (field != table->field)
{
List_iterator_fast<Item> it(items);
@@ -7888,7 +7889,8 @@ static bool not_null_fields_have_null_values(TABLE *table)
*/
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,
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);
if (!result && triggers)
- result= triggers->process_triggers(thd, event, TRG_ACTION_BEFORE, TRUE) ||
- not_null_fields_have_null_values(table);
-
- /*
- Re-calculate virtual fields to cater for cases when base columns are
- updated by the triggers.
- */
- if (!result && triggers)
{
+ 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
+ updated by the triggers.
+ */
List_iterator_fast<Item> f(fields);
Item *fld;
Item_field *item_field;
@@ -7915,12 +7918,12 @@ fill_record_n_invoke_before_triggers(THD *thd, TABLE *table, List<Item> &fields,
{
fld= (Item_field*)f++;
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);
result= update_virtual_fields(thd, table,
table->triggers ? VCOL_UPDATE_ALL :
- VCOL_UPDATE_FOR_WRITE);
+ VCOL_UPDATE_FOR_WRITE);
}
}
}
@@ -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
+ All fields are given a value
@param thd thread handler
@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;
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;
if (table->vfield &&
update_virtual_fields(thd, table,
@@ -8065,8 +8070,9 @@ 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,
- table->triggers ? VCOL_UPDATE_ALL :
- VCOL_UPDATE_FOR_WRITE);
+ table->triggers ?
+ VCOL_UPDATE_ALL :
+ VCOL_UPDATE_FOR_WRITE);
}
return result;
diff --git a/sql/sql_class.h b/sql/sql_class.h
index c901ae7785a..1cd09bf44fb 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -1494,7 +1494,7 @@ public:
ha_rows cuted_fields, sent_row_count, examined_row_count;
ulonglong client_capabilities;
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 last_insert_id_used;
SAVEPOINT *savepoints;
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index ee6309aff51..7744100e78b 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -860,15 +860,14 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
thd->abort_on_warning= !ignore && thd->is_strict_mode();
+ table->reset_default_fields();
table->prepare_triggers_for_insert_stmt_or_event();
table->mark_columns_needed_for_insert();
-
if (table_list->prepare_where(thd, 0, TRUE) ||
table_list->prepare_check_option(thd))
error= 1;
- table->reset_default_fields();
switch_to_nullable_trigger_fields(fields, table);
switch_to_nullable_trigger_fields(update_fields, 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= new (copy_tmp) TABLE;
*copy= *table;
+
/* We don't need to change the file handler here */
/* Assign the pointers for the field pointers array and the record. */
field= copy->field= (Field**) (copy + 1);
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index a05afb39174..30589b80fe2 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -3073,15 +3073,16 @@ CHARSET_INFO* get_sql_field_charset(Create_field *sql_field,
@param column_definitions The list of column definitions, in the physical
order in which they appear in the table.
- */
+*/
+
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;
while ((column_definition= it++) != NULL)
{
- if (is_timestamp_type(column_definition->sql_type) || // TIMESTAMP
+ if (is_timestamp_type(column_definition->sql_type) || // TIMESTAMP
column_definition->unireg_check == Field::TIMESTAMP_OLD_FIELD) // Legacy
{
if ((column_definition->flags & NOT_NULL_FLAG) != 0 && // NOT NULL,
@@ -3124,8 +3125,8 @@ static void check_duplicate_key(THD *thd,
if (!key->key_create_info.check_for_duplicate_indexes || key->generated)
return;
- List_iterator<Key> key_list_iterator(*key_list);
- List_iterator<Key_part_spec> key_column_iterator(key->columns);
+ List_iterator_fast<Key> key_list_iterator(*key_list);
+ List_iterator_fast<Key_part_spec> key_column_iterator(key->columns);
Key *k;
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.
*/
- 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;
@@ -3227,7 +3228,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
KEY_PART_INFO *key_part_info;
int field_no,dup_no;
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);
uint total_uneven_bit_length= 0;
int select_field_count= C_CREATE_SELECT(create_table_mode);
@@ -3581,7 +3582,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
therefore mark it as unsafe.
*/
if (select_field_count > 0 && auto_increment)
- thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_CREATE_SELECT_AUTOINC);
+ thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_CREATE_SELECT_AUTOINC);
/* Create keys */
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 52162e43643..5c20b72930e 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -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
- including those not in the write_set. This is cheaper than the field-by-field
- comparison done above.
+ including those not in the write_set. This is cheaper than the
+ field-by-field comparison done above.
*/
if (table->s->can_cmp_whole_record)
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(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))
DBUG_RETURN(TRUE);
diff --git a/sql/table.cc b/sql/table.cc
index 038c7c41588..30e4d3c2517 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -358,7 +358,7 @@ TABLE_SHARE *alloc_table_share(const char *db, const char *table_name,
thd thread handle
share Share to fill
key Table_cache_key, as generated from tdc_create_key.
- must start with db name.
+ must start with db name.
key_length Length of key
table_name Table name
path Path to file (possible in lower case) without .frm
@@ -540,7 +540,7 @@ inline bool is_system_table_name(const char *name, uint length)
my_tolower(ci, name[1]) == 'n' &&
my_tolower(ci, name[2]) == 'n' &&
my_tolower(ci, name[3]) == 'o')) ||
-
+
/* mysql.event table */
(my_tolower(ci, name[0]) == 'e' &&
my_tolower(ci, name[1]) == 'v' &&
@@ -715,8 +715,8 @@ static bool create_key_infos(const uchar *strpos, const uchar *frm_image_end,
When in the future we support others schemes of extending of
secondary keys with components of the primary key we'll have
- to change the type of this flag for an enumeration type.
- */
+ to change the type of this flag for an enumeration type.
+ */
for (i=0 ; i < keys ; i++, keyinfo++)
{
@@ -1011,12 +1011,12 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
uint len;
uint ext_key_parts= 0;
plugin_ref se_plugin= 0;
- keyinfo= &first_keyinfo;
- share->ext_key_parts= 0;
MEM_ROOT *old_root= thd->mem_root;
Virtual_column_info **table_check_constraints;
DBUG_ENTER("TABLE_SHARE::init_from_binary_frm_image");
+ keyinfo= &first_keyinfo;
+ share->ext_key_parts= 0;
thd->mem_root= &share->mem_root;
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)
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_frm_ver= (frm_image[2] - FRM_VER);
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)
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
if (frm_image[61] && !share->default_part_plugin)
{
@@ -1150,7 +1150,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
uint cs_new= upgrade_collation(share->mysql_version, cs_org);
if (cs_org != cs_new)
share->incompatible_version|= HA_CREATE_USED_CHARSET;
-
+
share->avg_row_length= uint4korr(frm_image+34);
share->transactional= (ha_choice)
enum_value_with_check(thd, share, "transactional", frm_image[39] & 3, HA_CHOICE_MAX);
@@ -1563,7 +1563,6 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
Field::geometry_type geom_type= Field::GEOM_GEOMETRY;
LEX_STRING comment;
Virtual_column_info *vcol_info= 0;
- bool fld_stored_in_db= TRUE;
uint gis_length, gis_decimals, srid= 0;
if (new_frm_ver >= 3)
@@ -1620,7 +1619,8 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
if ((uchar)field_type == (uchar)MYSQL_TYPE_VIRTUAL)
{
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
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:
byte 1 = 1 | 2
byte 2 = sql_type
- byte 3 = flags (as of now, 0 - no flags, 1 - field is physically stored)
- [byte 4] = optional interval_id for sql_type (only if byte 1 == 2)
+ byte 3 = flags (as of now, 0 - no flags,
+ 1 - field is physically stored)
+ [byte 4] = optional interval_id for sql_type (if byte 1 == 2)
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;
field_type= (enum_field_types) (uchar) vcol_screen_pos[1];
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)
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 -
(uint)(FRM_VCOL_OLD_HEADER_SIZE(opt_interval_id));
if (!(vcol_info->expr_str.str=
@@ -1713,7 +1715,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
/*
Try to choose the best 4.1 type:
- for 4.0 "CHAR(N) BINARY" or "VARCHAR(N) BINARY"
- try to find a binary collation for character set.
+ try to find a binary collation for character set.
- for other types (e.g. BLOB) just use my_charset_bin.
*/
if (!f_is_blob(pack_flag))
@@ -1741,7 +1743,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
TYPELIB *interval= share->intervals + interval_nr - 1;
unhex_type2(interval);
}
-
+
#ifndef TO_BE_DELETED_ON_PRODUCTION
if (field_type == MYSQL_TYPE_NEWDECIMAL && !share->mysql_version)
{
@@ -1791,14 +1793,9 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
if (!reg_field) // Not supported field type
goto err;
-
reg_field->field_index= i;
reg_field->comment=comment;
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))
{
null_bits_are_used= 1;
@@ -1987,7 +1984,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
keyinfo->key_part= new_key_part;
}
}
-
+
/* Fix fulltext keys for old .frm files */
if (share->key_info[key].flags & HA_FULLTEXT)
share->key_info[key].algorithm= HA_KEY_ALG_FULLTEXT;
@@ -2406,7 +2403,6 @@ int TABLE_SHARE::init_from_sql_statement_string(THD *thd, bool write,
handlerton *hton= plugin_hton(db_plugin);
LEX_CUSTRING frm= {0,0};
LEX_STRING db_backup= { thd->db, thd->db_length };
-
DBUG_ENTER("TABLE_SHARE::init_from_sql_statement_string");
/*
@@ -2517,12 +2513,9 @@ void TABLE_SHARE::free_frm_image(const uchar *frm)
@brief
Perform semantic analysis of the defining expression for a virtual column
- @param
- thd The thread object
- @param
- table The table containing the virtual column
- @param
- vcol_field The virtual field whose defining expression is to be analyzed
+ @param thd The thread object
+ @param table The table containing the virtual column
+ @param field Field if this is a DEFAULT or AS, otherwise NULL
@param vcol The Virtual_column object
@@ -2568,7 +2561,7 @@ static bool fix_vcol_expr(THD *thd,
error= func_expr->fix_fields(thd, &vcol->expr_item);
if (unlikely(error))
{
- DBUG_PRINT("info",
+ DBUG_PRINT("info",
("Field in virtual column expression does not belong to the table"));
my_error(ER_ERROR_EVALUATING_EXPRESSION, MYF(0), vcol->expr_str);
goto end;
@@ -2631,19 +2624,13 @@ end:
@brief
Unpack the definition of a virtual column from its linear representation
- @param
- thd The thread object
- @param
- mem_root The mem_root object where to allocated memory
- @param
- table The table containing the virtual column
- @param
- 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
+ @param thd The thread object
+ @param mem_root Where to allocate memory
+ @param table The table containing the virtual column
+ @param vcol The Virtual_column object
+ @param field Field if this is a DEFAULT or AS, otherwise NULL
+ @param[out] error_reported Flag to inform the caller that no
+ other error messages are to be generated
@details
@@ -2705,16 +2692,13 @@ Virtual_column_info *unpack_vcol_info_from_frm(THD *thd,
(char*) parse_vcol_keyword.str,
parse_vcol_keyword.length);
str_len= parse_vcol_keyword.length;
- memcpy(vcol_expr_str + str_len, "(", 1);
- str_len++;
+ vcol_expr_str[str_len++]= '(';
memcpy(vcol_expr_str + str_len,
(char*) vcol_expr->str,
vcol_expr->length);
str_len+= vcol_expr->length;
- memcpy(vcol_expr_str + str_len, ")", 1);
- str_len++;
- memcpy(vcol_expr_str + str_len, "\0", 1);
- str_len++;
+ vcol_expr_str[str_len++]= ')';
+ vcol_expr_str[str_len++]= 0;
if (parser_state.init(thd, vcol_expr_str, str_len))
goto err;
@@ -2732,7 +2716,7 @@ Virtual_column_info *unpack_vcol_info_from_frm(THD *thd,
Query_arena expr_arena(mem_root,
Query_arena::STMT_CONVENTIONAL_EXECUTION);
if (!(vcol_arena= (Query_arena *) alloc_root(mem_root,
- sizeof(Query_arena))))
+ sizeof(Query_arena))))
goto err;
*vcol_arena= expr_arena;
table->expr_arena= vcol_arena;
@@ -2875,7 +2859,7 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,
records++;
if (!(record= (uchar*) alloc_root(&outparam->mem_root,
- share->rec_buff_length * records)))
+ share->rec_buff_length * records)))
goto err; /* purecov: inspected */
if (records == 0)
@@ -2944,7 +2928,7 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,
key_info->key_part= key_part;
key_part_end= key_part + (share->use_ext_keys ? key_info->ext_key_parts :
- key_info->user_defined_key_parts) ;
+ key_info->user_defined_key_parts) ;
for ( ; key_part < key_part_end; key_part++)
{
Field *field= key_part->field= outparam->field[key_part->fieldnr - 1];
@@ -3259,7 +3243,7 @@ partititon_err:
if (share->db_type()->discover_table &&
(ha_err == ENOENT || ha_err == HA_ERR_NO_SUCH_TABLE))
error= OPEN_FRM_DISCOVER;
-
+
goto err;
}
}
@@ -4616,7 +4600,7 @@ bool TABLE_LIST::setup_underlying(THD *thd)
if (!view || (!field_translation && merge_underlying_list))
{
SELECT_LEX *select= get_single_select();
-
+
if (create_field_translation(thd))
DBUG_RETURN(TRUE);
@@ -6486,7 +6470,7 @@ bool TABLE::mark_virtual_col(Field *field)
/*
@brief Mark virtual columns for update/insert commands
-
+
@param insert_fl <-> virtual columns are marked for insert command
@details
@@ -6494,7 +6478,7 @@ bool TABLE::mark_virtual_col(Field *field)
in the vcol_set bitmap.
For an insert command a virtual column is always marked in write_set if
it is a stored column.
- If a virtual column is from write_set it is always marked in vcol_set.
+ If a virtual column is from write_set it is always marked in vcol_set.
If a stored virtual column is not from write_set but it is computed
through columns from write_set it is also marked in vcol_set, and,
besides, it is added to write_set.
@@ -6509,7 +6493,7 @@ bool TABLE::mark_virtual_col(Field *field)
column b will be placed into read_set.
If column c was a virtual column, but not a stored virtual column
then it would not be added to any of the sets. Column b would not
- be added to read_set either.
+ be added to read_set either.
*/
void TABLE::mark_virtual_columns_for_write(bool insert_fl)
@@ -6517,9 +6501,6 @@ void TABLE::mark_virtual_columns_for_write(bool insert_fl)
Field **vfield_ptr, *tmp_vfield;
bool bitmap_updated= FALSE;
- if (!vfield)
- return;
-
for (vfield_ptr= vfield; *vfield_ptr; vfield_ptr++)
{
tmp_vfield= *vfield_ptr;
@@ -6547,7 +6528,7 @@ void TABLE::mark_virtual_columns_for_write(bool insert_fl)
mark_virtual_col(tmp_vfield);
bitmap_updated= TRUE;
}
- }
+ }
}
if (bitmap_updated)
file->column_bitmaps_signal();
@@ -6961,7 +6942,7 @@ void TABLE_LIST::reinit_before_use(THD *thd)
*/
Item_subselect *TABLE_LIST::containing_subselect()
-{
+{
return (select_lex ? select_lex->master_unit()->item : 0);
}
@@ -6991,7 +6972,7 @@ Item_subselect *TABLE_LIST::containing_subselect()
is equivalent to
USE INDEX (i1,i2)
and means "consider only i1 and i2".
-
+
Similarly
USE INDEX () USE INDEX (i1)
is equivalent to
@@ -7000,7 +6981,7 @@ Item_subselect *TABLE_LIST::containing_subselect()
It is OK to have the same index several times, e.g. "USE INDEX (i1,i1)" is
not an error.
-
+
Different kind of hints (USE/FORCE/IGNORE) are processed in the following
order:
1. All indexes in USE (or FORCE) INDEX are added to the mask.
@@ -7243,16 +7224,17 @@ bool is_simple_order(ORDER *order)
@param thd Thread handle
@param table The TABLE object
- @param vcol_update_mode Specifies what virtual column are computed
+ @param vcol_update_mode Specifies what virtual column are computed
@details
The function computes the values of the virtual columns of the table and
stores them in the table record buffer.
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,
- if vcol_update_mode is set to VCOL_UPDATE_FOR_WRITE, and, only those with
- the stored_in_db flag set to false, if vcol_update_mode is equal to
- VCOL_UPDATE_FOR_READ.
+ computed.
+ If vcol_update_mode is set to VCOL_UPDATE_FOR_WRITE then all
+ fields that are set in vcol_set are updated.
+ 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
0 Success
@@ -7277,7 +7259,8 @@ int update_virtual_fields(THD *thd, TABLE *table,
DBUG_ASSERT(vcol_info);
DBUG_ASSERT(vcol_info->expr_item);
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)
{
/* 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)
{
DBUG_ENTER("update_default_fields");
- Field **dfield_ptr, *dfield;
+ Field **field_ptr;
int res= 0;
DBUG_ASSERT(default_field);
in_use->reset_arena_for_cached_items(expr_arena);
/* 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.
*/
- if (!dfield->has_explicit_value())
+ if (!field->has_explicit_value())
{
if (!update_command)
{
- if (dfield->default_value)
- res|= (dfield->default_value->expr_item->save_in_field(dfield, 0) < 0);
+ if (field->default_value)
+ res|= (field->default_value->expr_item->save_in_field(field, 0) < 0);
else
- res|= dfield->evaluate_insert_default_function();
+ res|= field->evaluate_insert_default_function();
}
else
- res|= dfield->evaluate_update_default_function();
+ res|= field->evaluate_update_default_function();
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;
}
res= 0;
diff --git a/sql/table.h b/sql/table.h
index 034930a8988..b217494685b 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -700,7 +700,6 @@ struct TABLE_SHARE
*/
const File_parser *view_def;
-
/*
Cache for row-based replication table share checks that does not
need to be repeated. Possible values are: -1 when cache value is
diff --git a/sql/unireg.cc b/sql/unireg.cc
index c99266dbff1..463822e52e8 100644
--- a/sql/unireg.cc
+++ b/sql/unireg.cc
@@ -604,8 +604,8 @@ static bool pack_header(THD *thd, uchar *forminfo,
MTYP_NOEMPTY_BIT);
no_empty++;
}
- /*
- We mark first TIMESTAMP field with NOW() in DEFAULT or ON UPDATE
+ /*
+ We mark first TIMESTAMP field with NOW() in DEFAULT or ON UPDATE
as auto-update field.
*/
if (field->sql_type == MYSQL_TYPE_TIMESTAMP &&
@@ -768,8 +768,7 @@ static size_t packed_fields_length(List<Create_field> &create_fields)
length+= strlen(field->field_name)+1;
length+= field->comment.length;
}
- length++;
- length++;
+ length+= 2;
DBUG_RETURN(length);
}
@@ -818,7 +817,7 @@ static bool pack_fields(uchar **buff_arg, List<Create_field> &create_fields,
DBUG_ASSERT(field->unireg_check < 256);
buff[10]= (uchar) field->unireg_check;
buff[12]= (uchar) field->interval_id;
- buff[13]= (uchar) field->sql_type;
+ buff[13]= (uchar) field->sql_type;
if (field->sql_type == MYSQL_TYPE_GEOMETRY)
{
buff[11]= 0;
@@ -910,7 +909,6 @@ static bool pack_fields(uchar **buff_arg, List<Create_field> &create_fields,
*buff++= sep;
}
*buff++= 0;
-
}
}
}