diff options
author | Jan Lindström <jan.lindstrom@mariadb.com> | 2018-05-07 17:20:39 +0300 |
---|---|---|
committer | Jan Lindström <jan.lindstrom@mariadb.com> | 2018-05-07 17:20:39 +0300 |
commit | e1ffb66449efa44e99d51c2a01c51d1623342d62 (patch) | |
tree | 7ce4e13ba915e8a6a0d50cc1adf7beacc8514a36 /sql | |
parent | 648cf7176cc95f697abd8b94e860c74768680298 (diff) | |
parent | 42fac3241368ad72f8cfef2b8521269e6c173558 (diff) | |
download | mariadb-git-e1ffb66449efa44e99d51c2a01c51d1623342d62.tar.gz |
Merge tag 'mariadb-10.0.35' into 10.0-galera
Diffstat (limited to 'sql')
38 files changed, 311 insertions, 205 deletions
diff --git a/sql/contributors.h b/sql/contributors.h index 7369dcd141d..a0d05af3fa6 100644 --- a/sql/contributors.h +++ b/sql/contributors.h @@ -41,13 +41,12 @@ struct show_table_contributors_st show_table_contributors[]= { {"Alibaba Cloud", "https://www.alibabacloud.com/", "Platinum Sponsor of the MariaDB Foundation"}, {"Tencent Cloud", "https://cloud.tencent.com", "Platinum Sponsor of the MariaDB Foundation"}, {"Microsoft", "https://microsoft.com/", "Platinum Sponsor of the MariaDB Foundation"}, - {"MariaDB Corporation", "https://mariadb.com", "Founding member, Gold Sponsor of the MariaDB Foundation"}, + {"MariaDB Corporation", "https://mariadb.com", "Founding member, Platinum Sponsor of the MariaDB Foundation"}, {"Visma", "https://visma.com", "Gold Sponsor of the MariaDB Foundation"}, {"DBS", "https://dbs.com", "Gold Sponsor of the MariaDB Foundation"}, {"IBM", "https://www.ibm.com", "Gold Sponsor of the MariaDB Foundation"}, {"Nexedi", "https://www.nexedi.com", "Silver Sponsor of the MariaDB Foundation"}, {"Acronis", "http://www.acronis.com", "Silver Sponsor of the MariaDB Foundation"}, - {"Auttomattic", "https://automattic.com", "Bronze Sponsor of the MariaDB Foundation"}, {"Verkkokauppa.com", "https://www.verkkokauppa.com", "Bronze Sponsor of the MariaDB Foundation"}, {"Virtuozzo", "https://virtuozzo.com", "Bronze Sponsor of the MariaDB Foundation"}, {"Tencent Game DBA", "http://tencentdba.com/about", "Bronze Sponsor of the MariaDB Foundation"}, diff --git a/sql/field.cc b/sql/field.cc index c36fff06a07..a9a7d54929b 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -5330,6 +5330,13 @@ static void calc_datetime_days_diff(MYSQL_TIME *ltime, long days) ltime->second) * 1000000LL + ltime->second_part); unpack_time(timediff, ltime); + /* + unpack_time() broke down hours into ltime members hour,day,month. + Mix them back to ltime->hour using the same factors + that pack_time()/unpack_time() use (i.e. 32 for month). + */ + ltime->hour+= (ltime->month * 32 + ltime->day) * 24; + ltime->month= ltime->day= 0; } ltime->time_type= MYSQL_TIMESTAMP_TIME; } diff --git a/sql/handler.cc b/sql/handler.cc index fc8bb53f35d..128043a8d80 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1,5 +1,5 @@ /* Copyright (c) 2000, 2016, Oracle and/or its affiliates. - Copyright (c) 2009, 2016, MariaDB + Copyright (c) 2009, 2018, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -790,7 +790,9 @@ static my_bool closecon_handlerton(THD *thd, plugin_ref plugin, */ void ha_close_connection(THD* thd) { - plugin_foreach(thd, closecon_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, 0); + plugin_foreach_with_mask(thd, closecon_handlerton, + MYSQL_STORAGE_ENGINE_PLUGIN, + PLUGIN_IS_DELETED|PLUGIN_IS_READY, 0); } static my_bool kill_handlerton(THD *thd, plugin_ref plugin, @@ -4354,18 +4356,6 @@ handler::check_if_supported_inplace_alter(TABLE *altered_table, DBUG_RETURN(HA_ALTER_INPLACE_NOT_SUPPORTED); } - -/* - Default implementation to support in-place alter table - and old online add/drop index API -*/ - -void handler::notify_table_changed() -{ - ha_create_partitioning_metadata(table->s->path.str, NULL, CHF_INDEX_FLAG); -} - - void Alter_inplace_info::report_unsupported_error(const char *not_supported, const char *try_instead) { @@ -4464,7 +4454,6 @@ handler::ha_create_partitioning_metadata(const char *name, const char *old_name, DBUG_ASSERT(m_lock_type == F_UNLCK || (!old_name && strcmp(name, table_share->path.str))); - mark_trx_read_write(); return create_partitioning_metadata(name, old_name, action_flag); } diff --git a/sql/handler.h b/sql/handler.h index 2c46368869c..44754e58cf0 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -3723,7 +3723,7 @@ protected: @note No errors are allowed during notify_table_changed(). */ - virtual void notify_table_changed(); + virtual void notify_table_changed() { } public: /* End of On-line/in-place ALTER TABLE interface. */ diff --git a/sql/item.cc b/sql/item.cc index 5f8cf6c80f7..5d413c38dd0 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -548,6 +548,7 @@ Item::Item(): in_rollup= 0; decimals= 0; max_length= 0; with_subselect= 0; + with_param= 0; cmp_context= IMPOSSIBLE_RESULT; /* Initially this item is not attached to any JOIN_TAB. */ join_tab_idx= MAX_TABLES; @@ -594,6 +595,7 @@ Item::Item(THD *thd, Item *item): null_value(item->null_value), unsigned_flag(item->unsigned_flag), with_sum_func(item->with_sum_func), + with_param(item->with_param), with_field(item->with_field), fixed(item->fixed), is_autogenerated_name(item->is_autogenerated_name), @@ -1475,6 +1477,9 @@ bool Item_sp_variable::fix_fields(THD *thd, Item **) max_length= it->max_length; decimals= it->decimals; unsigned_flag= it->unsigned_flag; + with_param= 1; + if (thd->lex->current_select->master_unit()->item) + thd->lex->current_select->master_unit()->item->with_param= 1; fixed= 1; collation.set(it->collation.collation, it->collation.derivation); @@ -7220,6 +7225,7 @@ void Item_ref::set_properties() split_sum_func() doesn't try to change the reference. */ with_sum_func= (*ref)->with_sum_func; + with_param= (*ref)->with_param; with_field= (*ref)->with_field; unsigned_flag= (*ref)->unsigned_flag; fixed= 1; @@ -7667,6 +7673,7 @@ Item_cache_wrapper::Item_cache_wrapper(Item *item_arg) decimals= orig_item->decimals; collation.set(orig_item->collation); with_sum_func= orig_item->with_sum_func; + with_param= orig_item->with_param; with_field= orig_item->with_field; unsigned_flag= orig_item->unsigned_flag; name= item_arg->name; diff --git a/sql/item.h b/sql/item.h index 7856328a33b..b111d74057c 100644 --- a/sql/item.h +++ b/sql/item.h @@ -669,6 +669,7 @@ public: bool null_value; /* if item is null */ bool unsigned_flag; bool with_sum_func; /* True if item contains a sum func */ + bool with_param; /* True if contains an SP parameter */ /** True if any item except Item_sum_func contains a field. Set during parsing. */ diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index d1c62859d20..410d58bdc29 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1571,6 +1571,7 @@ bool Item_in_optimizer::fix_left(THD *thd) } eval_not_null_tables(NULL); with_sum_func= args[0]->with_sum_func; + with_param= args[0]->with_param || args[1]->with_param; with_field= args[0]->with_field; if ((const_item_cache= args[0]->const_item())) { @@ -1620,6 +1621,7 @@ bool Item_in_optimizer::fix_fields(THD *thd, Item **ref) with_subselect= 1; with_sum_func= with_sum_func || args[1]->with_sum_func; with_field= with_field || args[1]->with_field; + with_param= args[0]->with_param || args[1]->with_param; used_tables_cache|= args[1]->used_tables(); const_item_cache&= args[1]->const_item(); fixed= 1; @@ -2171,6 +2173,7 @@ void Item_func_interval::fix_length_and_dec() used_tables_cache|= row->used_tables(); not_null_tables_cache= row->not_null_tables(); with_sum_func= with_sum_func || row->with_sum_func; + with_param= with_param || row->with_param; with_field= with_field || row->with_field; const_item_cache&= row->const_item(); } @@ -4401,6 +4404,7 @@ Item_cond::fix_fields(THD *thd, Item **ref) List_iterator<Item> li(list); Item *item; uchar buff[sizeof(char*)]; // Max local vars in function + bool is_and_cond= functype() == Item_func::COND_AND_FUNC; not_null_tables_cache= used_tables_cache= 0; const_item_cache= 1; @@ -4462,26 +4466,33 @@ Item_cond::fix_fields(THD *thd, Item **ref) (item= *li.ref())->check_cols(1)) return TRUE; /* purecov: inspected */ used_tables_cache|= item->used_tables(); - if (item->const_item()) + if (item->const_item() && !item->with_param && + !item->is_expensive() && !cond_has_datetime_is_null(item)) { - if (!item->is_expensive() && !cond_has_datetime_is_null(item) && - item->val_int() == 0) + if (item->val_int() == is_and_cond && top_level()) { /* - This is "... OR false_cond OR ..." + a. This is "... AND true_cond AND ..." + In this case, true_cond has no effect on cond_and->not_null_tables() + b. This is "... OR false_cond/null cond OR ..." In this case, false_cond has no effect on cond_or->not_null_tables() */ } else { /* - This is "... OR const_cond OR ..." + a. This is "... AND false_cond/null_cond AND ..." + The whole condition is FALSE/UNKNOWN. + b. This is "... OR const_cond OR ..." In this case, cond_or->not_null_tables()=0, because the condition const_cond might evaluate to true (regardless of whether some tables were NULL-complemented). */ + not_null_tables_cache= (table_map) 0; and_tables_cache= (table_map) 0; } + if (thd->is_error()) + return TRUE; } else { @@ -4493,6 +4504,7 @@ Item_cond::fix_fields(THD *thd, Item **ref) } with_sum_func= with_sum_func || item->with_sum_func; + with_param= with_param || item->with_param; with_field= with_field || item->with_field; with_subselect|= item->has_subquery(); if (item->maybe_null) @@ -4509,30 +4521,36 @@ bool Item_cond::eval_not_null_tables(uchar *opt_arg) { Item *item; + bool is_and_cond= functype() == Item_func::COND_AND_FUNC; List_iterator<Item> li(list); not_null_tables_cache= (table_map) 0; and_tables_cache= ~(table_map) 0; while ((item=li++)) { table_map tmp_table_map; - if (item->const_item()) + if (item->const_item() && !item->with_param && + !item->is_expensive() && !cond_has_datetime_is_null(item)) { - if (!item->is_expensive() && !cond_has_datetime_is_null(item) && - item->val_int() == 0) + if (item->val_int() == is_and_cond && top_level()) { /* - This is "... OR false_cond OR ..." + a. This is "... AND true_cond AND ..." + In this case, true_cond has no effect on cond_and->not_null_tables() + b. This is "... OR false_cond/null cond OR ..." In this case, false_cond has no effect on cond_or->not_null_tables() */ } else { /* - This is "... OR const_cond OR ..." + a. This is "... AND false_cond/null_cond AND ..." + The whole condition is FALSE/UNKNOWN. + b. This is "... OR const_cond OR ..." In this case, cond_or->not_null_tables()=0, because the condition - some_cond_or might be true regardless of what tables are - NULL-complemented. + const_cond might evaluate to true (regardless of whether some tables + were NULL-complemented). */ + not_null_tables_cache= (table_map) 0; and_tables_cache= (table_map) 0; } } diff --git a/sql/item_func.cc b/sql/item_func.cc index cf49612feb4..914bfa47652 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -220,6 +220,7 @@ Item_func::fix_fields(THD *thd, Item **ref) maybe_null=1; with_sum_func= with_sum_func || item->with_sum_func; + with_param= with_param || item->with_param; with_field= with_field || item->with_field; used_tables_cache|= item->used_tables(); const_item_cache&= item->const_item(); diff --git a/sql/item_func.h b/sql/item_func.h index b0ba87b4bd0..813bcf0d023 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -90,6 +90,7 @@ public: args= tmp_arg; args[0]= a; with_sum_func= a->with_sum_func; + with_param= a->with_param; with_field= a->with_field; } Item_func(Item *a,Item *b): @@ -98,6 +99,7 @@ public: args= tmp_arg; args[0]= a; args[1]= b; with_sum_func= a->with_sum_func || b->with_sum_func; + with_param= a->with_param || b->with_param; with_field= a->with_field || b->with_field; } Item_func(Item *a,Item *b,Item *c): @@ -109,6 +111,7 @@ public: arg_count= 3; args[0]= a; args[1]= b; args[2]= c; with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func; + with_param= a->with_param || b->with_param || c->with_param; with_field= a->with_field || b->with_field || c->with_field; } } @@ -122,6 +125,8 @@ public: args[0]= a; args[1]= b; args[2]= c; args[3]= d; with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func || d->with_sum_func; + with_param= a->with_param || b->with_param || + c->with_param || d->with_param; with_field= a->with_field || b->with_field || c->with_field || d->with_field; } @@ -135,6 +140,8 @@ public: args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e; with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func || d->with_sum_func || e->with_sum_func ; + with_param= a->with_param || b->with_param || + c->with_param || d->with_param || e->with_param; with_field= a->with_field || b->with_field || c->with_field || d->with_field || e->with_field; } diff --git a/sql/item_row.cc b/sql/item_row.cc index c07ea612850..30afedb6cc9 100644 --- a/sql/item_row.cc +++ b/sql/item_row.cc @@ -126,6 +126,7 @@ bool Item_row::fix_fields(THD *thd, Item **ref) with_sum_func= with_sum_func || item->with_sum_func; with_field= with_field || item->with_field; with_subselect|= item->with_subselect; + with_param|= item->with_param; } fixed= 1; return FALSE; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index c0d60d7ef8b..e0bd3cc2195 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -379,7 +379,7 @@ String *Item_func_aes_encrypt::val_str(String *str2) DBUG_ASSERT(fixed == 1); char key_buff[80]; String tmp_key_value(key_buff, sizeof(key_buff), system_charset_info); - String *sptr= args[0]->val_str(&str_value); // String to encrypt + String *sptr= args[0]->val_str(&tmp_value); // String to encrypt String *key= args[1]->val_str(&tmp_key_value); // key int aes_length; if (sptr && key) // we need both arguments to be not NULL @@ -418,7 +418,7 @@ String *Item_func_aes_decrypt::val_str(String *str) String *sptr, *key; DBUG_ENTER("Item_func_aes_decrypt::val_str"); - sptr= args[0]->val_str(&str_value); // String to decrypt + sptr= args[0]->val_str(&tmp_value); // String to decrypt key= args[1]->val_str(&tmp_key_value); // Key if (sptr && key) // Need to have both arguments not NULL { @@ -630,138 +630,84 @@ String *Item_func_decode_histogram::val_str(String *str) /////////////////////////////////////////////////////////////////////////////// +/* + Realloc the result buffer. + NOTE: We should be prudent in the initial allocation unit -- the + size of the arguments is a function of data distribution, which + can be any. Instead of overcommitting at the first row, we grow + the allocated amount by the factor of 2. This ensures that no + more than 25% of memory will be overcommitted on average. + + @param IN/OUT str - the result string + @param IN length - new total space required in "str" + @retval false - on success + @retval true - on error +*/ + +bool Item_func_concat::realloc_result(String *str, uint length) const +{ + if (str->alloced_length() >= length) + return false; // Alloced space is big enough, nothing to do. + + if (str->alloced_length() == 0) + return str->alloc(length); + + /* + Item_func_concat::val_str() makes sure the result length does not grow + higher than max_allowed_packet. So "length" is limited to 1G here. + We can't say anything about the current value of str->alloced_length(), + as str was initially set by args[0]->val_str(str). + So multiplication by 2 can overflow, if args[0] for some reasons + did not limit the result to max_alloced_packet. But it's not harmful, + "str" will be realloced exactly to "length" bytes in case of overflow. + */ + uint new_length= MY_MAX(str->alloced_length() * 2, length); + return str->realloc(new_length); +} + + /** Concatenate args with the following premises: If only one arg (which is ok), return value of arg; - Don't reallocate val_str() if not absolute necessary. */ String *Item_func_concat::val_str(String *str) { DBUG_ASSERT(fixed == 1); - String *res,*res2,*use_as_buff; - uint i; - bool is_const= 0; + THD *thd= current_thd; + String *res; null_value=0; - if (!(res=args[0]->val_str(str))) + if (!(res= args[0]->val_str(str))) goto null; - use_as_buff= &tmp_value; - /* Item_subselect in --ps-protocol mode will state it as a non-const */ - is_const= args[0]->const_item() || !args[0]->used_tables(); - for (i=1 ; i < arg_count ; i++) - { - if (res->length() == 0) - { - if (!(res=args[i]->val_str(str))) - goto null; - /* - CONCAT accumulates its result in the result of its the first - non-empty argument. Because of this we need is_const to be - evaluated only for it. - */ - is_const= args[i]->const_item() || !args[i]->used_tables(); - } - else - { - if (!(res2=args[i]->val_str(use_as_buff))) - goto null; - if (res2->length() == 0) - continue; - if (res->length()+res2->length() > - current_thd->variables.max_allowed_packet) - { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_WARN_ALLOWED_PACKET_OVERFLOWED, - ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(), - current_thd->variables.max_allowed_packet); - goto null; - } - if (!is_const && res->alloced_length() >= res->length()+res2->length()) - { // Use old buffer - res->append(*res2); - } - else if (str->alloced_length() >= res->length()+res2->length()) - { - if (str->ptr() == res2->ptr()) - str->replace(0,0,*res); - else - { - str->copy(*res); - str->append(*res2); - } - res= str; - use_as_buff= &tmp_value; - } - else if (res == &tmp_value) - { - if (res->append(*res2)) // Must be a blob - goto null; - } - else if (res2 == &tmp_value) - { // This can happend only 1 time - if (tmp_value.replace(0,0,*res)) - goto null; - res= &tmp_value; - use_as_buff=str; // Put next arg here - } - else if (tmp_value.is_alloced() && res2->ptr() >= tmp_value.ptr() && - res2->ptr() <= tmp_value.ptr() + tmp_value.alloced_length()) - { - /* - This happens really seldom: - In this case res2 is sub string of tmp_value. We will - now work in place in tmp_value to set it to res | res2 - */ - /* Chop the last characters in tmp_value that isn't in res2 */ - tmp_value.length((uint32) (res2->ptr() - tmp_value.ptr()) + - res2->length()); - /* Place res2 at start of tmp_value, remove chars before res2 */ - if (tmp_value.replace(0,(uint32) (res2->ptr() - tmp_value.ptr()), - *res)) - goto null; - res= &tmp_value; - use_as_buff=str; // Put next arg here - } - else - { // Two big const strings - /* - NOTE: We should be prudent in the initial allocation unit -- the - size of the arguments is a function of data distribution, which - can be any. Instead of overcommitting at the first row, we grow - the allocated amount by the factor of 2. This ensures that no - more than 25% of memory will be overcommitted on average. - */ - - uint concat_len= res->length() + res2->length(); - - if (tmp_value.alloced_length() < concat_len) - { - if (tmp_value.alloced_length() == 0) - { - if (tmp_value.alloc(concat_len)) - goto null; - } - else - { - uint new_len = MY_MAX(tmp_value.alloced_length() * 2, concat_len); - if (tmp_value.realloc(new_len)) - goto null; - } - } + if (res != str) + str->copy(res->ptr(), res->length(), res->charset()); - if (tmp_value.copy(*res) || tmp_value.append(*res2)) - goto null; - - res= &tmp_value; - use_as_buff=str; - } - is_const= 0; + for (uint i= 1 ; i < arg_count ; i++) + { + uint concat_len; + if (!(res= args[i]->val_str(&tmp_value))) + goto null; + if (res->length() == 0) + continue; + if ((concat_len= str->length() + res->length()) > + thd->variables.max_allowed_packet) + { + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_WARN_ALLOWED_PACKET_OVERFLOWED, + ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(), + thd->variables.max_allowed_packet); + goto null; } + DBUG_ASSERT(!res->uses_buffer_owned_by(str)); + DBUG_ASSERT(!str->uses_buffer_owned_by(res)); + if (realloc_result(str, concat_len) || str->append(*res)) + goto null; } - res->set_charset(collation.collation); - return res; + + str->set_charset(collation.collation); + return str; null: null_value=1; diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index c851728c9fa..2b8c55b48e6 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -134,19 +134,30 @@ public: }; -class Item_func_aes_encrypt :public Item_str_func +class Item_aes_crypt :public Item_str_func +{ +protected: + String tmp_value; +public: + Item_aes_crypt(Item *a, Item *b) + :Item_str_func(a, b) {} +}; + +class Item_func_aes_encrypt :public Item_aes_crypt { public: - Item_func_aes_encrypt(Item *a, Item *b) :Item_str_func(a,b) {} + Item_func_aes_encrypt(Item *a, Item *b): + Item_aes_crypt(a, b) {} String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "aes_encrypt"; } }; -class Item_func_aes_decrypt :public Item_str_func +class Item_func_aes_decrypt :public Item_aes_crypt { public: - Item_func_aes_decrypt(Item *a, Item *b) :Item_str_func(a,b) {} + Item_func_aes_decrypt(Item *a, Item *b): + Item_aes_crypt(a,b) {} String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "aes_decrypt"; } @@ -156,6 +167,7 @@ public: class Item_func_concat :public Item_str_func { String tmp_value; + bool realloc_result(String *str, uint length) const; public: Item_func_concat(List<Item> &list) :Item_str_func(list) {} Item_func_concat(Item *a,Item *b) :Item_str_func(a,b) {} diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index f56b5f6e707..a8dfdff9809 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -2070,7 +2070,10 @@ Item_in_subselect::create_single_in_to_exists_cond(JOIN *join, } else { - Item *item= (Item*) select_lex->item_list.head()->real_item(); + Item *item= (Item*) select_lex->item_list.head(); + if (item->type() != REF_ITEM || + ((Item_ref*)item)->ref_type() != Item_ref::VIEW_REF) + item= item->real_item(); if (select_lex->table_list.elements) { diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 7b017cd810a..fae3f2344df 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -1181,6 +1181,7 @@ Item_sum_num::fix_fields(THD *thd, Item **ref) return TRUE; set_if_bigger(decimals, args[i]->decimals); with_subselect|= args[i]->with_subselect; + with_param|= args[i]->with_param; } result_field=0; max_length=float_length(decimals); @@ -1212,6 +1213,7 @@ Item_sum_hybrid::fix_fields(THD *thd, Item **ref) return TRUE; decimals=item->decimals; with_subselect= args[0]->with_subselect; + with_param= args[0]->with_param; switch (hybrid_type= item->result_type()) { case INT_RESULT: @@ -3443,6 +3445,7 @@ Item_func_group_concat::fix_fields(THD *thd, Item **ref) args[i]->check_cols(1)) return TRUE; with_subselect|= args[i]->with_subselect; + with_param|= args[i]->with_param; } /* skip charset aggregation for order columns */ diff --git a/sql/item_xmlfunc.cc b/sql/item_xmlfunc.cc index c7fd923b0ae..c12f5fd3e87 100644 --- a/sql/item_xmlfunc.cc +++ b/sql/item_xmlfunc.cc @@ -2634,7 +2634,7 @@ void Item_xml_str_func::fix_length_and_dec() bool Item_xml_str_func::fix_fields(THD *thd, Item **ref) { - String *xp, tmp; + String *xp; MY_XPATH xpath; int rc; @@ -2662,7 +2662,13 @@ bool Item_xml_str_func::fix_fields(THD *thd, Item **ref) return true; } - if (!(xp= args[1]->val_str(&tmp))) + /* + Get the XPath query text from args[1] and cache it in m_xpath_query. + Its fragments will be referenced by items created during my_xpath_parse(), + e.g. by Item_nodeset_func_axisbyname::node_name. + */ + if (!(xp= args[1]->val_str(&m_xpath_query)) || + (xp != &m_xpath_query && m_xpath_query.copy(*xp))) return false; // Will return NULL my_xpath_init(&xpath); xpath.cs= collation.collation; diff --git a/sql/item_xmlfunc.h b/sql/item_xmlfunc.h index 637f505e12e..e0356d367bd 100644 --- a/sql/item_xmlfunc.h +++ b/sql/item_xmlfunc.h @@ -67,6 +67,7 @@ protected: return parse(res, cache); } }; + String m_xpath_query; // XPath query text Item *nodeset_func; XML xml; bool get_xml(XML *xml, bool cache= false) diff --git a/sql/log_event.cc b/sql/log_event.cc index e799f37ddae..52df9fc5f84 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -7972,7 +7972,12 @@ int User_var_log_event::do_apply_event(rpl_group_info *rgi) } if (!(charset= get_charset(charset_number, MYF(MY_WME)))) + { + rgi->rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, + ER_THD(thd, ER_SLAVE_FATAL_ERROR), + "Invalid character set for User var event"); DBUG_RETURN(1); + } LEX_STRING user_var_name; user_var_name.str= name; user_var_name.length= name_len; @@ -7987,12 +7992,26 @@ int User_var_log_event::do_apply_event(rpl_group_info *rgi) { switch (type) { case REAL_RESULT: + if (val_len != 8) + { + rgi->rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, + ER_THD(thd, ER_SLAVE_FATAL_ERROR), + "Invalid variable length at User var event"); + return 1; + } float8get(real_val, val); it= new Item_float(real_val, 0); val= (char*) &real_val; // Pointer to value in native format val_len= 8; break; case INT_RESULT: + if (val_len != 8) + { + rgi->rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, + ER_THD(thd, ER_SLAVE_FATAL_ERROR), + "Invalid variable length at User var event"); + return 1; + } int_val= (longlong) uint8korr(val); it= new Item_int(int_val); val= (char*) &int_val; // Pointer to value in native format @@ -8000,6 +8019,13 @@ int User_var_log_event::do_apply_event(rpl_group_info *rgi) break; case DECIMAL_RESULT: { + if (val_len < 3) + { + rgi->rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, + ER_THD(thd, ER_SLAVE_FATAL_ERROR), + "Invalid variable length at User var event"); + return 1; + } Item_decimal *dec= new Item_decimal((uchar*) val+2, val[0], val[1]); it= dec; val= (char *)dec->val_decimal(NULL); @@ -9518,6 +9544,14 @@ Rows_log_event::Rows_log_event(const char *buf, uint event_len, DBUG_PRINT("debug", ("Reading from %p", ptr_after_width)); m_width = net_field_length(&ptr_after_width); DBUG_PRINT("debug", ("m_width=%lu", m_width)); + + /* Avoid reading out of buffer */ + if (ptr_after_width + (m_width + 7) / 8 > (uchar*)buf + event_len) + { + m_cols.bitmap= NULL; + DBUG_VOID_RETURN; + } + /* if my_bitmap_init fails, catched in is_valid() */ if (likely(!my_bitmap_init(&m_cols, m_width <= sizeof(m_bitbuf)*8 ? m_bitbuf : NULL, diff --git a/sql/log_event_old.cc b/sql/log_event_old.cc index 34c586510a3..4d15f231c40 100644 --- a/sql/log_event_old.cc +++ b/sql/log_event_old.cc @@ -1330,6 +1330,13 @@ Old_rows_log_event::Old_rows_log_event(const char *buf, uint event_len, DBUG_PRINT("debug", ("Reading from %p", ptr_after_width)); m_width = net_field_length(&ptr_after_width); DBUG_PRINT("debug", ("m_width=%lu", m_width)); + /* Avoid reading out of buffer */ + if (ptr_after_width + m_width > (uchar *)buf + event_len) + { + m_cols.bitmap= NULL; + DBUG_VOID_RETURN; + } + /* if my_bitmap_init fails, catched in is_valid() */ if (likely(!my_bitmap_init(&m_cols, m_width <= sizeof(m_bitbuf)*8 ? m_bitbuf : NULL, diff --git a/sql/mysqld.cc b/sql/mysqld.cc index f558b78104f..d90fa9c0c76 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -551,7 +551,7 @@ bool max_user_connections_checking=0; Limit of the total number of prepared statements in the server. Is necessary to protect the server against out-of-memory attacks. */ -ulong max_prepared_stmt_count; +uint max_prepared_stmt_count; /** Current total number of prepared statements in the server. This number is exact, and therefore may not be equal to the difference between @@ -562,7 +562,7 @@ ulong max_prepared_stmt_count; two different connections, this counts as two distinct prepared statements. */ -ulong prepared_stmt_count=0; +uint prepared_stmt_count=0; ulong thread_id=1L,current_pid; ulong slow_launch_threads = 0; uint sync_binlog_period= 0, sync_relaylog_period= 0, diff --git a/sql/mysqld.h b/sql/mysqld.h index 3bb9f35077e..73718abd582 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -178,7 +178,7 @@ extern ulong slave_trans_retries; extern uint slave_net_timeout; extern int max_user_connections; extern ulong what_to_log,flush_time; -extern ulong max_prepared_stmt_count, prepared_stmt_count; +extern uint max_prepared_stmt_count, prepared_stmt_count; extern ulong open_files_limit; extern ulonglong binlog_cache_size, binlog_stmt_cache_size; extern ulonglong max_binlog_cache_size, max_binlog_stmt_cache_size; diff --git a/sql/net_serv.cc b/sql/net_serv.cc index 90a5da6a927..225b6d9542e 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -58,9 +58,11 @@ #ifdef EXTRA_DEBUG #define EXTRA_DEBUG_fprintf fprintf #define EXTRA_DEBUG_fflush fflush +#define EXTRA_DEBUG_ASSERT DBUG_ASSERT #else static void inline EXTRA_DEBUG_fprintf(...) {} static int inline EXTRA_DEBUG_fflush(...) { return 0; } +#define EXTRA_DEBUG_ASSERT(X) do {} while(0) #endif #ifdef MYSQL_SERVER #define MYSQL_SERVER_my_error my_error @@ -1071,7 +1073,7 @@ packets_out_of_order: ("Packets out of order (Found: %d, expected %u)", (int) net->buff[net->where_b + 3], net->pkt_nr)); - DBUG_ASSERT(0); + EXTRA_DEBUG_ASSERT(0); /* We don't make noise server side, since the client is expected to break the protocol for e.g. --send LOAD DATA .. LOCAL where diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index a9e21e67f13..d8ecdc9a2ee 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -3730,21 +3730,29 @@ bool setup_sj_materialization_part1(JOIN_TAB *sjm_tab) SJ_MATERIALIZATION_INFO *sjm= emb_sj_nest->sj_mat_info; THD *thd= tab->join->thd; /* First the calls come to the materialization function */ - //List<Item> &item_list= emb_sj_nest->sj_subq_pred->unit->first_select()->item_list; - + DBUG_ASSERT(sjm->is_used); /* Set up the table to write to, do as select_union::create_result_table does */ sjm->sjm_table_param.init(); sjm->sjm_table_param.bit_fields_as_long= TRUE; - //List_iterator<Item> it(item_list); SELECT_LEX *subq_select= emb_sj_nest->sj_subq_pred->unit->first_select(); - Item **p_item= subq_select->ref_pointer_array; - Item **p_end= p_item + subq_select->item_list.elements; - //while((right_expr= it++)) - for(;p_item != p_end; p_item++) - sjm->sjm_table_cols.push_back(*p_item); + List_iterator<Item> it(subq_select->item_list); + Item *item; + while((item= it++)) + { + /* + This semi-join replaced the subquery (subq_select) and so on + re-executing it will not be prepared. To use the Items from its + select list we have to prepare (fix_fields) them + */ + if (!item->fixed && item->fix_fields(thd, it.ref())) + DBUG_RETURN(TRUE); + item= *(it.ref()); // it can be changed by fix_fields + DBUG_ASSERT(!item->name_length || item->name_length == strlen(item->name)); + sjm->sjm_table_cols.push_back(item, thd->mem_root); + } sjm->sjm_table_param.field_count= subq_select->item_list.elements; sjm->sjm_table_param.force_not_null_cols= TRUE; diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 4958473c73d..19611758ee0 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -5577,8 +5577,8 @@ ER_SP_NO_AGGREGATE 42000 eng "AGGREGATE is not supported for stored functions" ger "AGGREGATE wird bei gespeicherten Funktionen nicht unterstützt" ER_MAX_PREPARED_STMT_COUNT_REACHED 42000 - eng "Can't create more than max_prepared_stmt_count statements (current value: %lu)" - ger "Kann nicht mehr Anweisungen als max_prepared_stmt_count erzeugen (aktueller Wert: %lu)" + eng "Can't create more than max_prepared_stmt_count statements (current value: %u)" + ger "Kann nicht mehr Anweisungen als max_prepared_stmt_count erzeugen (aktueller Wert: %u)" ER_VIEW_RECURSIVE eng "`%-.192s`.`%-.192s` contains view recursion" ger "`%-.192s`.`%-.192s` enthält View-Rekursion" diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc index a35e28ee421..bb0f83a7c47 100644 --- a/sql/sql_admin.cc +++ b/sql/sql_admin.cc @@ -238,7 +238,7 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list, if (thd->locked_tables_list.locked_tables()) { - if (thd->locked_tables_list.reopen_tables(thd)) + if (thd->locked_tables_list.reopen_tables(thd, false)) goto end; /* Restore the table in the table list with the new opened table */ table_list->table= pos_in_locked_tables->table; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index e2607dea28f..2a5f698e148 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -572,7 +572,7 @@ err_with_reopen: old locks. This should always succeed (unless some external process has removed the tables) */ - thd->locked_tables_list.reopen_tables(thd); + thd->locked_tables_list.reopen_tables(thd, false); /* Since downgrade_lock() won't do anything with shared metadata lock it is much simpler to go through all open tables rather @@ -2873,7 +2873,8 @@ void Locked_tables_list::unlink_from_list(THD *thd, If mode is not LTM_LOCK_TABLES, we needn't do anything. Moreover, outside this mode pos_in_locked_tables value is not trustworthy. */ - if (thd->locked_tables_mode != LTM_LOCK_TABLES) + if (thd->locked_tables_mode != LTM_LOCK_TABLES && + thd->locked_tables_mode != LTM_PRELOCKED_UNDER_LOCK_TABLES) return; /* @@ -2977,7 +2978,7 @@ unlink_all_closed_tables(THD *thd, MYSQL_LOCK *lock, size_t reopen_count) */ bool -Locked_tables_list::reopen_tables(THD *thd) +Locked_tables_list::reopen_tables(THD *thd, bool need_reopen) { Open_table_context ot_ctx(thd, MYSQL_OPEN_REOPEN); size_t reopen_count= 0; @@ -2988,8 +2989,20 @@ Locked_tables_list::reopen_tables(THD *thd) for (TABLE_LIST *table_list= m_locked_tables; table_list; table_list= table_list->next_global) { - if (table_list->table) /* The table was not closed */ - continue; + if (need_reopen) + { + if (!table_list->table || !table_list->table->needs_reopen()) + continue; + /* no need to remove the table from the TDC here, thus (TABLE*)1 */ + close_all_tables_for_name(thd, table_list->table->s, + HA_EXTRA_NOT_USED, (TABLE*)1); + DBUG_ASSERT(table_list->table == NULL); + } + else + { + if (table_list->table) /* The table was not closed */ + continue; + } /* Links into thd->open_tables upon success */ if (open_table(thd, table_list, thd->mem_root, &ot_ctx)) diff --git a/sql/sql_class.h b/sql/sql_class.h index 394575191e4..2fb67933725 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1625,7 +1625,7 @@ public: void unlink_all_closed_tables(THD *thd, MYSQL_LOCK *lock, size_t reopen_count); - bool reopen_tables(THD *thd); + bool reopen_tables(THD *thd, bool need_reopen); bool restore_lock(THD *thd, TABLE_LIST *dst_table_list, TABLE *table, MYSQL_LOCK *lock); void add_back_last_deleted_lock(TABLE_LIST *dst_table_list); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index f60134b6162..c353c50d8c0 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -5600,6 +5600,10 @@ finish: lex->unit.cleanup(); + /* close/reopen tables that were marked to need reopen under LOCK TABLES */ + if (! thd->lex->requires_prelocking()) + thd->locked_tables_list.reopen_tables(thd, true); + if (! thd->in_sub_stmt) { if (thd->killed != NOT_KILLED) diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 81c47472bf9..3e12f4e64f0 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -4713,7 +4713,12 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info, DBUG_RETURN(TRUE); } - thd->work_part_info= thd->lex->part_info; + /* + One of these is done in handle_if_exists_option(): + thd->work_part_info= thd->lex->part_info; + or + thd->work_part_info= NULL; + */ if (thd->work_part_info && !(thd->work_part_info= thd->work_part_info->get_clone())) @@ -6553,7 +6558,7 @@ static void alter_partition_lock_handling(ALTER_PARTITION_PARAM_TYPE *lpt) thd->set_stmt_da(&tmp_stmt_da); } - if (thd->locked_tables_list.reopen_tables(thd)) + if (thd->locked_tables_list.reopen_tables(thd, false)) sql_print_warning("We failed to reacquire LOCKs in ALTER TABLE"); if (stmt_da) @@ -6757,7 +6762,7 @@ err_exclusive_lock: thd->set_stmt_da(&tmp_stmt_da); } - if (thd->locked_tables_list.reopen_tables(thd)) + if (thd->locked_tables_list.reopen_tables(thd, false)) sql_print_warning("We failed to reacquire LOCKs in ALTER TABLE"); if (stmt_da) diff --git a/sql/sql_partition_admin.cc b/sql/sql_partition_admin.cc index 56c9c5bf3bf..e067f584960 100644 --- a/sql/sql_partition_admin.cc +++ b/sql/sql_partition_admin.cc @@ -645,7 +645,7 @@ bool Sql_cmd_alter_table_exchange_partition:: better to keep master/slave in consistent state. Alternative would be to try to revert the exchange operation and issue error. */ - (void) thd->locked_tables_list.reopen_tables(thd); + (void) thd->locked_tables_list.reopen_tables(thd, false); if ((error= write_bin_log(thd, TRUE, thd->query(), thd->query_length()))) { diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index b1ffa90dd2f..bd0877b3def 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1,6 +1,6 @@ /* Copyright (c) 2005, 2018, Oracle and/or its affiliates. - Copyright (c) 2010, 2018, MariaDB + Copyright (c) 2010, 2018, MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/sql/sql_select.cc b/sql/sql_select.cc index fd8ff6eb016..1f15d5bcec0 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1143,9 +1143,6 @@ TODO: make view to decide if it is possible to write to WHERE directly or make S eval_select_list_used_tables(); - if (optimize_constant_subqueries()) - DBUG_RETURN(1); - table_count= select_lex->leaf_tables.elements; if (setup_ftfuncs(select_lex)) /* should be after having->fix_fields */ @@ -1207,6 +1204,9 @@ TODO: make view to decide if it is possible to write to WHERE directly or make S thd->restore_active_arena(arena, &backup); } + if (optimize_constant_subqueries()) + DBUG_RETURN(1); + if (setup_jtbm_semi_joins(this, join_list, &conds)) DBUG_RETURN(1); @@ -11476,13 +11476,15 @@ void JOIN_TAB::cleanup() } else { + TABLE_LIST *tmp= table->pos_in_table_list; end_read_record(&read_record); - table->pos_in_table_list->jtbm_subselect->cleanup(); + tmp->jtbm_subselect->cleanup(); /* The above call freed the materializedd temptable. Set it to NULL so that we don't attempt to touch it if JOIN_TAB::cleanup() is invoked multiple times (it may be) */ + tmp->table= NULL; table=NULL; } DBUG_VOID_RETURN; diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index 70080a6b4f1..ce320e87a4f 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -2475,7 +2475,7 @@ int collect_statistics_for_index(THD *thd, TABLE *table, uint index) DBUG_ENTER("collect_statistics_for_index"); /* No statistics for FULLTEXT indexes. */ - if (key_info->flags & HA_FULLTEXT) + if (key_info->flags & (HA_FULLTEXT|HA_SPATIAL)) DBUG_RETURN(rc); Index_prefix_calc index_prefix_calc(table, key_info); @@ -2944,18 +2944,19 @@ bool statistics_for_tables_is_needed(THD *thd, TABLE_LIST *tables) return FALSE; /* - Do not read statistics for any query over non-user tables. - If the query references some statistical tables, but not all - of them, reading the statistics may lead to a deadlock - */ + Do not read statistics for any query that explicity involves + statistical tables, failure to to do so we may end up + in a deadlock. + */ + for (TABLE_LIST *tl= tables; tl; tl= tl->next_global) { if (!tl->is_view_or_derived() && tl->table) { TABLE_SHARE *table_share= tl->table->s; if (table_share && - (table_share->table_category != TABLE_CATEGORY_USER || - table_share->tmp_table != NO_TMP_TABLE)) + table_share->table_category != TABLE_CATEGORY_USER + && is_stat_table(tl->db, tl->alias)) return FALSE; } } @@ -3634,6 +3635,15 @@ double get_column_range_cardinality(Field *field, if (!col_stats) return tab_records; + /* + Use statistics for a table only when we have actually read + the statistics from the stat tables. For example due to + chances of getting a deadlock we disable reading statistics for + a table. + */ + + if (!table->stats_is_read) + return tab_records; double col_nulls= tab_records * col_stats->get_nulls_ratio(); @@ -3840,3 +3850,20 @@ double Histogram::point_selectivity(double pos, double avg_sel) return sel; } +/* + Check whether the table is one of the persistent statistical tables. +*/ +bool is_stat_table(const char *db, const char *table) +{ + DBUG_ASSERT(db && table); + + if (!memcmp(db, stat_tables_db_name.str, stat_tables_db_name.length)) + { + for (uint i= 0; i < STATISTICS_TABLES; i ++) + { + if (!memcmp(table, stat_table_name[i].str, stat_table_name[i].length)) + return true; + } + } + return false; +}
\ No newline at end of file diff --git a/sql/sql_statistics.h b/sql/sql_statistics.h index 8e5f8107849..20b2eb66449 100644 --- a/sql/sql_statistics.h +++ b/sql/sql_statistics.h @@ -107,6 +107,7 @@ double get_column_range_cardinality(Field *field, key_range *min_endp, key_range *max_endp, uint range_flag); +bool is_stat_table(const char *db, const char *table); class Histogram { diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 07d3bb71be6..bafd5706346 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4204,7 +4204,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, /* Give warnings for not supported table options */ #if defined(WITH_ARIA_STORAGE_ENGINE) extern handlerton *maria_hton; - if (file->ht != maria_hton) + if (file->partition_ht() != maria_hton) #endif if (create_info->transactional) push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, @@ -5071,7 +5071,7 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table, This should always work as we have a meta lock on the table. */ thd->locked_tables_list.add_back_last_deleted_lock(pos_in_locked_tables); - if (thd->locked_tables_list.reopen_tables(thd)) + if (thd->locked_tables_list.reopen_tables(thd, false)) { thd->locked_tables_list.unlink_all_closed_tables(thd, NULL, 0); result= 1; @@ -5476,7 +5476,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, This should always work as we have a meta lock on the table. */ thd->locked_tables_list.add_back_last_deleted_lock(pos_in_locked_tables); - if (thd->locked_tables_list.reopen_tables(thd)) + if (thd->locked_tables_list.reopen_tables(thd, false)) { thd->locked_tables_list.unlink_all_closed_tables(thd, NULL, 0); res= 1; // We got an error @@ -6072,6 +6072,7 @@ remove_key_no_warn: #ifdef WITH_PARTITION_STORAGE_ENGINE partition_info *tab_part_info= table->part_info; + thd->work_part_info= thd->lex->part_info; if (tab_part_info && thd->lex->check_exists) { /* ALTER TABLE ADD PARTITION IF NOT EXISTS */ @@ -6090,7 +6091,7 @@ remove_key_no_warn: ER_SAME_NAME_PARTITION, ER(ER_SAME_NAME_PARTITION), pe->partition_name); alter_info->flags&= ~Alter_info::ALTER_ADD_PARTITION; - thd->lex->part_info= NULL; + thd->work_part_info= NULL; break; } } @@ -7313,7 +7314,7 @@ static bool mysql_inplace_alter_table(THD *thd, HA_EXTRA_PREPARE_FOR_RENAME : HA_EXTRA_NOT_USED, NULL); - if (thd->locked_tables_list.reopen_tables(thd)) + if (thd->locked_tables_list.reopen_tables(thd, false)) thd->locked_tables_list.unlink_all_closed_tables(thd, NULL, 0); /* QQ; do something about metadata locks ? */ } @@ -9320,7 +9321,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, end_inplace: - if (thd->locked_tables_list.reopen_tables(thd)) + if (thd->locked_tables_list.reopen_tables(thd, false)) goto err_with_mdl_after_alter; THD_STAGE_INFO(thd, stage_end); diff --git a/sql/sql_time.cc b/sql/sql_time.cc index 1bd68e89ecb..a618f751e65 100644 --- a/sql/sql_time.cc +++ b/sql/sql_time.cc @@ -960,6 +960,8 @@ bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, ltime->day= 0; return 0; } + else if (ltime->neg) + goto invalid_date; if (int_type != INTERVAL_DAY) ltime->time_type= MYSQL_TIMESTAMP_DATETIME; // Return full date diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index ec75fc2da12..34875824e2e 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -582,7 +582,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) Ignore the return value for now. It's better to keep master/slave in consistent state. */ - if (thd->locked_tables_list.reopen_tables(thd)) + if (thd->locked_tables_list.reopen_tables(thd, false)) thd->clear_error(); /* diff --git a/sql/sql_truncate.cc b/sql/sql_truncate.cc index 259f2ad78e3..7fc5192e42d 100644 --- a/sql/sql_truncate.cc +++ b/sql/sql_truncate.cc @@ -503,7 +503,7 @@ bool Sql_cmd_truncate_table::truncate_table(THD *thd, TABLE_LIST *table_ref) */ error= dd_recreate_table(thd, table_ref->db, table_ref->table_name); - if (thd->locked_tables_mode && thd->locked_tables_list.reopen_tables(thd)) + if (thd->locked_tables_mode && thd->locked_tables_list.reopen_tables(thd, false)) thd->locked_tables_list.unlink_all_closed_tables(thd, NULL, 0); /* No need to binlog a failed truncate-by-recreate. */ @@ -576,4 +576,3 @@ bool Sql_cmd_truncate_table::execute(THD *thd) my_ok(thd); DBUG_RETURN(res); } - diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 3194122f463..2348cb4d45d 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -1953,11 +1953,11 @@ static Sys_var_ulong Sys_max_long_data_size( BLOCK_SIZE(1)); static PolyLock_mutex PLock_prepared_stmt_count(&LOCK_prepared_stmt_count); -static Sys_var_ulong Sys_max_prepared_stmt_count( +static Sys_var_uint Sys_max_prepared_stmt_count( "max_prepared_stmt_count", "Maximum number of prepared statements in the server", GLOBAL_VAR(max_prepared_stmt_count), CMD_LINE(REQUIRED_ARG), - VALID_RANGE(0, 1024*1024), DEFAULT(16382), BLOCK_SIZE(1), + VALID_RANGE(0, UINT_MAX32), DEFAULT(16382), BLOCK_SIZE(1), &PLock_prepared_stmt_count); static Sys_var_ulong Sys_max_sort_length( @@ -3080,7 +3080,7 @@ static bool fix_table_open_cache(sys_var *, THD *, enum_var_type) static Sys_var_ulong Sys_table_cache_size( "table_open_cache", "The number of cached open tables", GLOBAL_VAR(tc_size), CMD_LINE(REQUIRED_ARG), - VALID_RANGE(1, 512*1024), DEFAULT(TABLE_OPEN_CACHE_DEFAULT), + VALID_RANGE(1, 1024*1024), DEFAULT(TABLE_OPEN_CACHE_DEFAULT), BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(fix_table_open_cache)); |