summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2018-02-08 19:06:25 +0400
committerAlexander Barkov <bar@mariadb.org>2018-02-08 19:06:25 +0400
commit3cad31f2a758f797ef0acac5625d0e007ecbce93 (patch)
tree73c054636c4858b2a51eddf7eaa653746d67524e /sql
parent560b9895d413bdfedda0a0ca871a635858990c05 (diff)
parent5c057b3fef3aa92cfadbd63043799b430132a494 (diff)
downloadmariadb-git-3cad31f2a758f797ef0acac5625d0e007ecbce93.tar.gz
Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext
Diffstat (limited to 'sql')
-rw-r--r--sql/CMakeLists.txt2
-rw-r--r--sql/contributors.h3
-rw-r--r--sql/field.cc4
-rw-r--r--sql/field.h2
-rw-r--r--sql/field_conv.cc6
-rw-r--r--sql/handler.cc14
-rw-r--r--sql/item.cc8
-rw-r--r--sql/item.h8
-rw-r--r--sql/item_cmpfunc.cc45
-rw-r--r--sql/item_cmpfunc.h6
-rw-r--r--sql/item_func.cc8
-rw-r--r--sql/item_strfunc.cc233
-rw-r--r--sql/item_strfunc.h31
-rw-r--r--sql/item_subselect.cc7
-rw-r--r--sql/item_windowfunc.cc5
-rw-r--r--sql/item_xmlfunc.cc10
-rw-r--r--sql/item_xmlfunc.h1
-rw-r--r--sql/key.cc6
-rw-r--r--sql/log_event.cc7
-rw-r--r--sql/mysqld.cc111
-rw-r--r--sql/mysqld.h10
-rw-r--r--sql/net_serv.cc8
-rw-r--r--sql/opt_range.cc2
-rw-r--r--sql/sp.cc1
-rw-r--r--sql/sp_head.cc38
-rw-r--r--sql/sp_head.h3
-rw-r--r--sql/sql_acl.cc12
-rw-r--r--sql/sql_admin.cc3
-rw-r--r--sql/sql_base.cc9
-rw-r--r--sql/sql_cache.cc20
-rw-r--r--sql/sql_class.cc16
-rw-r--r--sql/sql_class.h45
-rw-r--r--sql/sql_cte.cc31
-rw-r--r--sql/sql_cursor.cc2
-rw-r--r--sql/sql_derived.cc22
-rw-r--r--sql/sql_explain.h6
-rw-r--r--sql/sql_insert.cc2
-rw-r--r--sql/sql_join_cache.cc2
-rw-r--r--sql/sql_lex.cc5
-rw-r--r--sql/sql_lex.h17
-rw-r--r--sql/sql_lifo_buffer.h4
-rw-r--r--sql/sql_list.h4
-rw-r--r--sql/sql_parse.cc14
-rw-r--r--sql/sql_partition.cc10
-rw-r--r--sql/sql_plugin.cc5
-rw-r--r--sql/sql_prepare.cc21
-rw-r--r--sql/sql_select.cc77
-rw-r--r--sql/sql_select.h4
-rw-r--r--sql/sql_show.cc2
-rw-r--r--sql/sql_string.h2
-rw-r--r--sql/sql_table.cc11
-rw-r--r--sql/sql_trigger.cc7
-rw-r--r--sql/sql_union.cc16
-rw-r--r--sql/sql_view.cc7
-rw-r--r--sql/table.cc8
-rw-r--r--sql/threadpool_generic.cc3
-rw-r--r--sql/transaction.cc12
-rw-r--r--sql/unireg.cc15
-rw-r--r--sql/wsrep_sst.cc19
-rw-r--r--sql/wsrep_sst.h3
60 files changed, 601 insertions, 414 deletions
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index b3c99cc4788..9c9f3919781 100644
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (c) 2006, 2014, Oracle and/or its affiliates.
-# Copyright (c) 2010, 2016, MariaDB Corporation
+# 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/contributors.h b/sql/contributors.h
index 88a4a088acf..7369dcd141d 100644
--- a/sql/contributors.h
+++ b/sql/contributors.h
@@ -38,8 +38,9 @@ struct show_table_contributors_st {
struct show_table_contributors_st show_table_contributors[]= {
/* MariaDB foundation sponsors, in contribution, size , time order */
{"Booking.com", "https://www.booking.com", "Founding member, Platinum Sponsor of the MariaDB Foundation"},
- {"Alibaba Cloud", "https://intl.aliyun.com", "Platinum Sponsor of the MariaDB Foundation"},
+ {"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"},
{"Visma", "https://visma.com", "Gold Sponsor of the MariaDB Foundation"},
{"DBS", "https://dbs.com", "Gold Sponsor of the MariaDB Foundation"},
diff --git a/sql/field.cc b/sql/field.cc
index f48638d81dc..5325597525b 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -2148,7 +2148,7 @@ uint Field::fill_cache_field(CACHE_FIELD *copy)
{
uint store_length;
copy->str= ptr;
- copy->length= pack_length();
+ copy->length= pack_length_in_rec();
copy->field= this;
if (flags & BLOB_FLAG)
{
@@ -9467,7 +9467,7 @@ int Field_bit::key_cmp(const uchar *str, uint length)
str++;
length--;
}
- return memcmp(ptr, str, length);
+ return memcmp(ptr, str, bytes_in_rec);
}
diff --git a/sql/field.h b/sql/field.h
index 7fb746d7379..bc56ba4db7b 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -637,7 +637,7 @@ public:
DBUG_ASSERT(size < UINT_MAX32);
return thd_alloc(current_thd, (uint) size);
}
- static void operator delete(void *ptr_arg, size_t size) { TRASH(ptr_arg, size); }
+ static void operator delete(void *ptr_arg, size_t size) { TRASH_FREE(ptr_arg, size); }
static void operator delete(void *ptr, MEM_ROOT *mem_root)
{ DBUG_ASSERT(0); }
diff --git a/sql/field_conv.cc b/sql/field_conv.cc
index 932188d56a8..a3c488a637d 100644
--- a/sql/field_conv.cc
+++ b/sql/field_conv.cc
@@ -607,7 +607,7 @@ void Copy_field::set(uchar *to,Field *from)
{
from_ptr=from->ptr;
to_ptr=to;
- from_length=from->pack_length();
+ from_length=from->pack_length_in_rec();
if (from->maybe_null())
{
from_null_ptr=from->null_ptr;
@@ -655,9 +655,9 @@ void Copy_field::set(Field *to,Field *from,bool save)
from_field=from;
to_field=to;
from_ptr=from->ptr;
- from_length=from->pack_length();
+ from_length=from->pack_length_in_rec();
to_ptr= to->ptr;
- to_length=to_field->pack_length();
+ to_length=to_field->pack_length_in_rec();
// set up null handling
from_null_ptr=to_null_ptr=0;
diff --git a/sql/handler.cc b/sql/handler.cc
index 10c2b65bbc0..a7b92fcc769 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -3459,9 +3459,11 @@ void print_keydup_error(TABLE *table, KEY *key, const char *msg, myf errflag)
if (key == NULL)
{
- /* Key is unknown */
- str.copy("", 0, system_charset_info);
- my_printf_error(ER_DUP_ENTRY, msg, errflag, str.c_ptr(), "*UNKNOWN*");
+ /*
+ Key is unknown. Should only happen if storage engine reports wrong
+ duplicate key number.
+ */
+ my_printf_error(ER_DUP_ENTRY, msg, errflag, "", "*UNKNOWN*");
}
else
{
@@ -3561,11 +3563,9 @@ void handler::print_error(int error, myf errflag)
if (table)
{
uint key_nr=get_dup_key(error);
- if ((int) key_nr >= 0)
+ if ((int) key_nr >= 0 && key_nr < table->s->keys)
{
- print_keydup_error(table,
- key_nr == MAX_KEY ? NULL : &table->key_info[key_nr],
- errflag);
+ print_keydup_error(table, &table->key_info[key_nr], errflag);
DBUG_VOID_RETURN;
}
}
diff --git a/sql/item.cc b/sql/item.cc
index d4da3f866d0..55c97e89ea5 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1,6 +1,6 @@
/*
Copyright (c) 2000, 2016, Oracle and/or its affiliates.
- Copyright (c) 2010, 2017, MariaDB Corporation
+ 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
@@ -9153,7 +9153,7 @@ bool Item_ignore_value::send(Protocol *protocol, st_value *buffer)
bool Item_insert_value::eq(const Item *item, bool binary_cmp) const
{
return item->type() == INSERT_VALUE_ITEM &&
- ((Item_default_value *)item)->arg->eq(arg, binary_cmp);
+ ((Item_insert_value *)item)->arg->eq(arg, binary_cmp);
}
@@ -10279,11 +10279,11 @@ const char *dbug_print_item(Item *item)
ulonglong save_option_bits= thd->variables.option_bits;
thd->variables.option_bits &= ~OPTION_QUOTE_SHOW_CREATE;
- item->print(&str ,QT_EXPLAIN);
+ item->print(&str, QT_EXPLAIN);
thd->variables.option_bits= save_option_bits;
- if (str.c_ptr() == buf)
+ if (str.c_ptr_safe() == buf)
return buf;
else
return "Couldn't fit into buffer";
diff --git a/sql/item.h b/sql/item.h
index f4fff4a0418..94f05bc4a7f 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -2,7 +2,7 @@
#define SQL_ITEM_INCLUDED
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates.
- Copyright (c) 2009, 2017, 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
@@ -87,7 +87,11 @@ public:
};
+#ifdef DBUG_OFF
+static inline const char *dbug_print_item(Item *item) { return NULL; }
+#else
const char *dbug_print_item(Item *item);
+#endif
class Virtual_tmp_table;
class sp_head;
@@ -564,7 +568,7 @@ class Item: public Value_source,
public:
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
{ return alloc_root(mem_root, size); }
- static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); }
+ static void operator delete(void *ptr,size_t size) { TRASH_FREE(ptr, size); }
static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM,
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 313bd457313..5846ef094d9 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -1223,6 +1223,7 @@ bool Item_in_optimizer::is_top_level_item()
void Item_in_optimizer::fix_after_pullout(st_select_lex *new_parent,
Item **ref, bool merge)
{
+ DBUG_ASSERT(fixed);
/* This will re-calculate attributes of our Item_in_subselect: */
Item_bool_func::fix_after_pullout(new_parent, ref, merge);
@@ -1246,6 +1247,33 @@ bool Item_in_optimizer::eval_not_null_tables(void *opt_arg)
}
+void Item_in_optimizer::print(String *str, enum_query_type query_type)
+{
+ restore_first_argument();
+ Item_func::print(str, query_type);
+}
+
+
+/**
+ "Restore" first argument before fix_fields() call (after it is harmless).
+
+ @Note: Main pointer to left part of IN/ALL/ANY subselect is subselect's
+ lest_expr (see Item_in_optimizer::fix_left) so changes made during
+ fix_fields will be rolled back there which can make
+ Item_in_optimizer::args[0] unusable on second execution before fix_left()
+ call. This call fix the pointer.
+*/
+
+void Item_in_optimizer::restore_first_argument()
+{
+ if (args[1]->type() == Item::SUBSELECT_ITEM &&
+ ((Item_subselect *)args[1])->is_in_predicate())
+ {
+ args[0]= ((Item_in_subselect *)args[1])->left_expr;
+ }
+}
+
+
bool Item_in_optimizer::fix_left(THD *thd)
{
DBUG_ENTER("Item_in_optimizer::fix_left");
@@ -1419,6 +1447,7 @@ bool Item_in_optimizer::invisible_mode()
Item *Item_in_optimizer::expr_cache_insert_transformer(THD *thd, uchar *unused)
{
DBUG_ENTER("Item_in_optimizer::expr_cache_insert_transformer");
+ DBUG_ASSERT(fixed);
if (invisible_mode())
DBUG_RETURN(this);
@@ -1443,6 +1472,7 @@ Item *Item_in_optimizer::expr_cache_insert_transformer(THD *thd, uchar *unused)
void Item_in_optimizer::get_cache_parameters(List<Item> &parameters)
{
+ DBUG_ASSERT(fixed);
/* Add left expression to the list of the parameters of the subquery */
if (!invisible_mode())
{
@@ -1680,6 +1710,7 @@ Item *Item_in_optimizer::transform(THD *thd, Item_transformer transformer,
{
Item *new_item;
+ DBUG_ASSERT(fixed);
DBUG_ASSERT(!thd->stmt_arena->is_stmt_prepare());
DBUG_ASSERT(arg_count == 2);
@@ -1731,6 +1762,7 @@ Item *Item_in_optimizer::transform(THD *thd, Item_transformer transformer,
bool Item_in_optimizer::is_expensive_processor(void *arg)
{
+ DBUG_ASSERT(fixed);
return args[0]->is_expensive_processor(arg) ||
args[1]->is_expensive_processor(arg);
}
@@ -1738,6 +1770,7 @@ bool Item_in_optimizer::is_expensive_processor(void *arg)
bool Item_in_optimizer::is_expensive()
{
+ DBUG_ASSERT(fixed);
return args[0]->is_expensive() || args[1]->is_expensive();
}
@@ -2680,7 +2713,9 @@ void Item_func_nullif::print(String *str, enum_query_type query_type)
Therefore, after equal field propagation args[0] and args[2] can point
to different items.
*/
- if ((query_type & QT_ITEM_ORIGINAL_FUNC_NULLIF) || args[0] == args[2])
+ if ((query_type & QT_ITEM_ORIGINAL_FUNC_NULLIF) ||
+ (arg_count == 2) ||
+ (args[0] == args[2]))
{
/*
If QT_ITEM_ORIGINAL_FUNC_NULLIF is requested,
@@ -2698,10 +2733,14 @@ void Item_func_nullif::print(String *str, enum_query_type query_type)
- one "a" for comparison
- another "a" for the returned value!
*/
- DBUG_ASSERT(args[0] == args[2] || current_thd->lex->context_analysis_only);
+ DBUG_ASSERT(arg_count == 2 ||
+ args[0] == args[2] || current_thd->lex->context_analysis_only);
str->append(func_name());
str->append('(');
- args[2]->print(str, query_type);
+ if (arg_count == 2)
+ args[0]->print(str, query_type);
+ else
+ args[2]->print(str, query_type);
str->append(',');
args[1]->print(str, query_type);
str->append(')');
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index b4a833d2290..d4908ddf48d 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -378,6 +378,8 @@ public:
void fix_after_pullout(st_select_lex *new_parent, Item **ref, bool merge);
bool invisible_mode();
void reset_cache() { cache= NULL; }
+ virtual void print(String *str, enum_query_type query_type);
+ void restore_first_argument();
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
{ return get_item_copy<Item_in_optimizer>(thd, mem_root, this); }
};
@@ -2478,9 +2480,9 @@ public:
bool arg_is_datetime_notnull_field()
{
Item **args= arguments();
- if (args[0]->type() == Item::FIELD_ITEM)
+ if (args[0]->real_item()->type() == Item::FIELD_ITEM)
{
- Field *field=((Item_field*) args[0])->field;
+ Field *field=((Item_field*) args[0]->real_item())->field;
if (((field->type() == MYSQL_TYPE_DATE) ||
(field->type() == MYSQL_TYPE_DATETIME)) &&
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 7368aebcadf..cced6d70824 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -54,6 +54,7 @@
#include "set_var.h"
#include "debug_sync.h"
#include "sql_base.h"
+#include "sql_cte.h"
#ifdef NO_EMBEDDED_ACCESS_CHECKS
#define sp_restore_security_context(A,B) while (0) {}
@@ -703,6 +704,7 @@ my_decimal *Item_real_func::val_decimal(my_decimal *decimal_value)
}
+#ifdef HAVE_DLOPEN
void Item_udf_func::fix_num_length_and_dec()
{
uint fl_length= 0;
@@ -719,6 +721,7 @@ void Item_udf_func::fix_num_length_and_dec()
max_length= float_length(NOT_FIXED_DEC);
}
}
+#endif
void Item_func::signal_divide_by_null()
@@ -4511,10 +4514,13 @@ bool Item_func_set_user_var::fix_fields(THD *thd, Item **ref)
TABLE_LIST *derived;
for (derived= unit->derived;
derived;
- derived= derived->select_lex->master_unit()->derived)
+ derived= unit->derived)
{
derived->set_materialized_derived();
derived->prohibit_cond_pushdown= true;
+ if (unit->with_element && unit->with_element->is_recursive)
+ break;
+ unit= derived->select_lex->master_unit();
}
}
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index b39fcb78fe9..64fc84a49e8 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -1,6 +1,6 @@
/*
Copyright (c) 2000, 2017, Oracle and/or its affiliates.
- Copyright (c) 2009, 2017, 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
@@ -202,9 +202,9 @@ String *Item_func_sha2::val_str_ascii(String *str)
const char *input_ptr;
size_t input_len;
+ input_string= args[0]->val_str(str);
str->set_charset(&my_charset_bin);
- input_string= args[0]->val_str(str);
if (input_string == NULL)
{
null_value= TRUE;
@@ -545,99 +545,106 @@ 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);
THD *thd= current_thd;
- String *res,*use_as_buff;
- uint i;
- bool is_const= 0;
+ String *res;
null_value=0;
- if (!(res= arg_val_str(0, str, &is_const)))
+ if (!(res= args[0]->val_str(str)))
goto null;
- use_as_buff= &tmp_value;
- for (i=1 ; i < arg_count ; i++)
+
+ if (res != str)
+ str->copy(res->ptr(), res->length(), res->charset());
+
+ for (uint i= 1 ; i < arg_count ; i++)
{
- if (res->length() == 0)
- {
- /*
- 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.
- */
- if (!(res= arg_val_str(i, str, &is_const)))
- goto null;
- }
- else
- {
- const String *res2;
- if (!(res2=args[i]->val_str(use_as_buff)))
- goto null;
- if (res2->length() == 0)
- continue;
- if (!(res= append_value(thd, res, is_const, str, &use_as_buff, res2)))
- goto null;
- is_const= 0;
- }
+ if (!(res= args[i]->val_str(&tmp_value)) ||
+ append_value(thd, str, res))
+ goto null;
}
- res->set_charset(collation.collation);
- return res;
+
+ str->set_charset(collation.collation);
+ return str;
null:
- null_value=1;
+ null_value= true;
return 0;
}
String *Item_func_concat_operator_oracle::val_str(String *str)
{
- THD *thd= current_thd;
DBUG_ASSERT(fixed == 1);
- String *res, *use_as_buff;
+ THD *thd= current_thd;
+ String *res;
uint i;
- bool is_const= false;
- null_value= 0;
+ null_value=0;
// Search first non null argument
for (i= 0; i < arg_count; i++)
{
- if ((res= arg_val_str(i, str, &is_const)))
+ if ((res= args[i]->val_str(str)))
break;
}
if (i == arg_count)
goto null;
- use_as_buff= &tmp_value;
+ if (res != str)
+ str->copy(res->ptr(), res->length(), res->charset());
for (i++ ; i < arg_count ; i++)
{
- if (res->length() == 0)
- {
- // See comments in Item_func_concat::val_str()
- String *tmp;
- if (!(tmp= arg_val_str(i, str, &is_const)))
- continue;
- res= tmp;
- }
- else
- {
- const String *res2;
- if (!(res2= args[i]->val_str(use_as_buff)) || res2->length() == 0)
- continue;
- if (!(res= append_value(thd, res, is_const, str, &use_as_buff, res2)))
- goto null;
- is_const= 0;
- }
+ if (!(res= args[i]->val_str(&tmp_value)) || res->length() == 0)
+ continue;
+ if (append_value(thd, str, res))
+ goto null;
}
- res->set_charset(collation.collation);
- return res;
+
+ str->set_charset(collation.collation);
+ return str;
null:
null_value= true;
@@ -645,115 +652,21 @@ null:
}
-String *Item_func_concat::append_value(THD *thd,
- String *res,
- bool res_is_const,
- String *str,
- String **use_as_buff,
- const String *res2)
+bool Item_func_concat::append_value(THD *thd, String *res, const String *app)
{
- DBUG_ASSERT(res2->length() > 0);
-
- if ((ulong) res->length() + (ulong) res2->length() >
+ uint concat_len;
+ if ((concat_len= res->length() + app->length()) >
thd->variables.max_allowed_packet)
{
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_WARN_ALLOWED_PACKET_OVERFLOWED,
- ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED),
- func_name(),
+ ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(),
thd->variables.max_allowed_packet);
- return NULL;
+ return true;
}
-
- uint32 concat_len= res->length() + res2->length();
-
- if (!res_is_const && res->alloced_length() >= concat_len)
- { // Use old buffer
- return res->append(*res2) ? NULL : res;
- }
-
- if (str->alloced_length() >= concat_len)
- {
- if (str->ptr() == res2->ptr())
- {
- if (str->replace(0, 0, *res))
- return NULL;
- }
- else
- {
- if (str->copy(*res) || str->append(*res2))
- return NULL;
- }
- *use_as_buff= &tmp_value;
- return str;
- }
-
- if (res == &tmp_value)
- {
- if (res->append(*res2)) // Must be a blob
- return NULL;
- return res;
- }
-
- if (res2 == &tmp_value)
- { // This can happend only 1 time
- if (tmp_value.replace(0, 0, *res))
- return NULL;
- *use_as_buff= str; // Put next arg here
- return &tmp_value;
- }
-
- 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))
- return NULL;
- *use_as_buff= str; // Put next arg here
- return &tmp_value;
- }
-
- /*
- 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.
- */
-
- if (tmp_value.alloced_length() < concat_len)
- {
- if (tmp_value.alloced_length() == 0)
- {
- if (tmp_value.alloc(concat_len))
- return NULL;
- }
- else
- {
- uint32 new_len= tmp_value.alloced_length() > INT_MAX32 ?
- UINT_MAX32 - 1 :
- tmp_value.alloced_length() * 2;
- set_if_bigger(new_len, concat_len);
- if (tmp_value.realloc(new_len))
- return NULL;
- }
- }
-
- if (tmp_value.copy(*res) || tmp_value.append(*res2))
- return NULL;
-
- *use_as_buff= str;
- return &tmp_value;
+ DBUG_ASSERT(!res->uses_buffer_owned_by(app));
+ DBUG_ASSERT(!app->uses_buffer_owned_by(res));
+ return realloc_result(res, concat_len) || res->append(*app);
}
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 49f82f7028c..2b7cc1a3aa1 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -244,37 +244,14 @@ class Item_func_concat :public Item_str_func
protected:
String tmp_value;
/*
- Get the i-th argument val_str() and its const_item()
- @param i[IN] - The argument number
- @param str[IN] - The buffer for val_str()
- @param is_const[IN/OUT] - If args[i]->val_str() returned a non-null value,
- then args[i]->const_item() is returned here.
- Otherwise, the value of is_const is not touched.
- @retval - the result of val_str().
- */
- String *arg_val_str(uint i, String *str, bool *is_const)
- {
- String *res= args[i]->val_str(str);
- if (res)
- *is_const= args[i]->const_item();
- return res;
- }
- /*
Append a non-NULL value to the result.
@param [IN] thd - The current thread.
@param [IN/OUT] res - The current val_str() return value.
- @param [IN] res_is_const - If "false", then OK to append to "res"
- @param [IN/OUT] str - The val_str() argument.
- @param [IN] res2 - The value to be appended.
- @param [IN/OUT] use_as_buff - Which buffer to use for the next argument:
- args[next_arg]->val_str(use_as_buff)
+ @param [IN] app - The value to be appended.
+ @retval - false on success, true on error
*/
- String *append_value(THD *thd,
- String *res,
- bool res_is_const,
- String *str,
- String **use_as_buff,
- const String *res2);
+ bool append_value(THD *thd, String *res, const String *app);
+ bool realloc_result(String *str, uint length) const;
public:
Item_func_concat(THD *thd, List<Item> &list): Item_str_func(thd, list) {}
Item_func_concat(THD *thd, Item *a, Item *b): Item_str_func(thd, a, b) {}
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 6d00dcf650e..92691907e7c 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -2125,7 +2125,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)
{
@@ -5494,7 +5497,7 @@ int subselect_hash_sj_engine::exec()
if (has_covering_null_row)
{
- DBUG_ASSERT(count_partial_match_columns = field_count);
+ DBUG_ASSERT(count_partial_match_columns == field_count);
count_pm_keys= 0;
}
else if (has_covering_null_columns)
diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc
index f993276dab3..45688b87730 100644
--- a/sql/item_windowfunc.cc
+++ b/sql/item_windowfunc.cc
@@ -440,5 +440,10 @@ void Item_window_func::print(String *str, enum_query_type query_type)
{
window_func()->print(str, query_type);
str->append(" over ");
+#ifndef DBUG_OFF
+ if (!window_spec) // one can call dbug_print_item() anytime in gdb
+ str->append(window_name);
+ else
+#endif
window_spec->print(str, query_type);
}
diff --git a/sql/item_xmlfunc.cc b/sql/item_xmlfunc.cc
index a69d48e8328..af32bf9a46d 100644
--- a/sql/item_xmlfunc.cc
+++ b/sql/item_xmlfunc.cc
@@ -2734,7 +2734,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;
@@ -2762,7 +2762,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.thd= thd;
diff --git a/sql/item_xmlfunc.h b/sql/item_xmlfunc.h
index 3c071b897e2..d281e076ec8 100644
--- a/sql/item_xmlfunc.h
+++ b/sql/item_xmlfunc.h
@@ -62,6 +62,7 @@ protected:
return parse(res, cache);
}
};
+ String m_xpath_query; // XPath query text
Item *nodeset_func;
XML xml;
bool get_xml(XML *xml_arg, bool cache= false)
diff --git a/sql/key.cc b/sql/key.cc
index 14d29e8b125..6369faff9d0 100644
--- a/sql/key.cc
+++ b/sql/key.cc
@@ -63,7 +63,8 @@ int find_ref_key(KEY *key, uint key_count, uchar *record, Field *field,
i < (int) key_count ;
i++, key_info++)
{
- if (key_info->key_part[0].offset == fieldpos)
+ if (key_info->key_part[0].offset == fieldpos &&
+ key_info->key_part[0].field->type() != MYSQL_TYPE_BIT)
{ /* Found key. Calc keylength */
*key_length= *keypart= 0;
return i; /* Use this key */
@@ -82,7 +83,8 @@ int find_ref_key(KEY *key, uint key_count, uchar *record, Field *field,
j < key_info->user_defined_key_parts ;
j++, key_part++)
{
- if (key_part->offset == fieldpos)
+ if (key_part->offset == fieldpos &&
+ key_part->field->type() != MYSQL_TYPE_BIT)
{
*keypart= j;
return i; /* Use this key */
diff --git a/sql/log_event.cc b/sql/log_event.cc
index c559e8b5b4d..2c75045c94d 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -5324,8 +5324,13 @@ bool test_if_equal_repl_errors(int expected_error, int actual_error)
return 1;
switch (expected_error) {
case ER_DUP_ENTRY:
+ case ER_DUP_ENTRY_WITH_KEY_NAME:
+ case ER_DUP_KEY:
case ER_AUTOINC_READ_FAILED:
- return (actual_error == ER_AUTOINC_READ_FAILED ||
+ return (actual_error == ER_DUP_ENTRY ||
+ actual_error == ER_DUP_ENTRY_WITH_KEY_NAME ||
+ actual_error == ER_DUP_KEY ||
+ actual_error == ER_AUTOINC_READ_FAILED ||
actual_error == HA_ERR_AUTOINC_ERANGE);
case ER_UNKNOWN_TABLE:
return actual_error == ER_IT_IS_A_VIEW;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 831b7b4be5d..c5804c7d315 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -553,7 +553,7 @@ ulong max_prepared_stmt_count;
statements.
*/
ulong prepared_stmt_count=0;
-my_thread_id global_thread_id= 1;
+my_thread_id global_thread_id= 0;
ulong current_pid;
ulong slow_launch_threads = 0;
uint sync_binlog_period= 0, sync_relaylog_period= 0,
@@ -760,6 +760,9 @@ mysql_mutex_t LOCK_stats, LOCK_global_user_client_stats,
/* This protects against changes in master_info_index */
mysql_mutex_t LOCK_active_mi;
+/* This protects connection id.*/
+mysql_mutex_t LOCK_thread_id;
+
/**
The below lock protects access to two global server variables:
max_prepared_stmt_count and prepared_stmt_count. These variables
@@ -927,6 +930,7 @@ PSI_mutex_key key_BINLOG_LOCK_index, key_BINLOG_LOCK_xid_list,
key_LOCK_thread_count, key_LOCK_thread_cache,
key_PARTITION_LOCK_auto_inc;
PSI_mutex_key key_RELAYLOG_LOCK_index;
+PSI_mutex_key key_LOCK_thread_id;
PSI_mutex_key key_LOCK_slave_state, key_LOCK_binlog_state,
key_LOCK_rpl_thread, key_LOCK_rpl_thread_pool, key_LOCK_parallel_entry;
@@ -964,6 +968,7 @@ static PSI_mutex_info all_server_mutexes[]=
{ &key_hash_filo_lock, "hash_filo::lock", 0},
{ &key_LOCK_active_mi, "LOCK_active_mi", PSI_FLAG_GLOBAL},
{ &key_LOCK_connection_count, "LOCK_connection_count", PSI_FLAG_GLOBAL},
+ { &key_LOCK_thread_id, "LOCK_thread_id", PSI_FLAG_GLOBAL},
{ &key_LOCK_crypt, "LOCK_crypt", PSI_FLAG_GLOBAL},
{ &key_LOCK_delayed_create, "LOCK_delayed_create", PSI_FLAG_GLOBAL},
{ &key_LOCK_delayed_insert, "LOCK_delayed_insert", PSI_FLAG_GLOBAL},
@@ -2045,8 +2050,8 @@ pthread_handler_t kill_server_thread(void *arg __attribute__((unused)))
extern "C" sig_handler print_signal_warning(int sig)
{
if (global_system_variables.log_warnings)
- sql_print_warning("Got signal %d from thread %ld", sig,
- (ulong) my_thread_id());
+ sql_print_warning("Got signal %d from thread %u", sig,
+ (uint)my_thread_id());
#ifdef SIGNAL_HANDLER_RESET_ON_DELIVERY
my_sigset(sig,print_signal_warning); /* int. thread system calls */
#endif
@@ -2333,6 +2338,7 @@ static void clean_up_mutexes()
mysql_mutex_destroy(&LOCK_crypt);
mysql_mutex_destroy(&LOCK_user_conn);
mysql_mutex_destroy(&LOCK_connection_count);
+ mysql_mutex_destroy(&LOCK_thread_id);
mysql_mutex_destroy(&LOCK_stats);
mysql_mutex_destroy(&LOCK_global_user_client_stats);
mysql_mutex_destroy(&LOCK_global_table_stats);
@@ -4208,7 +4214,7 @@ static int init_common_variables()
/* TODO: remove this when my_time_t is 64 bit compatible */
if (!IS_TIME_T_VALID_FOR_TIMESTAMP(server_start_time))
{
- sql_print_error("This MySQL server doesn't support dates later then 2038");
+ sql_print_error("This MySQL server doesn't support dates later than 2038");
exit(1);
}
@@ -4700,6 +4706,8 @@ static int init_thread_environment()
&LOCK_short_uuid_generator, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_LOCK_connection_count,
&LOCK_connection_count, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_LOCK_thread_id,
+ &LOCK_thread_id, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_LOCK_stats, &LOCK_stats, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_LOCK_global_user_client_stats,
&LOCK_global_user_client_stats, MY_MUTEX_INIT_FAST);
@@ -8768,7 +8776,7 @@ static int mysql_init_variables(void)
denied_connections= 0;
executed_events= 0;
global_query_id= 1;
- global_thread_id= 1;
+ global_thread_id= 0;
strnmov(server_version, MYSQL_SERVER_VERSION, sizeof(server_version)-1);
threads.empty();
thread_cache.empty();
@@ -10442,3 +10450,96 @@ void init_server_psi_keys(void)
}
#endif /* HAVE_PSI_INTERFACE */
+
+
+/*
+ Connection ID allocation.
+
+ We need to maintain thread_ids in the 32bit range,
+ because this is how it is passed to the client in the protocol.
+
+ The idea is to maintain a id range, initially set to
+ (0,UINT32_MAX). Whenever new id is needed, we increment the
+ lower limit and return its new value.
+
+ On "overflow", if id can not be generated anymore(i.e lower == upper -1),
+ we recalculate the range boundaries.
+ To do that, we first collect thread ids that are in use, by traversing
+ THD list, and find largest region within (0,UINT32_MAX), that is still free.
+
+*/
+
+static my_thread_id thread_id_max= UINT_MAX32;
+
+#include <vector>
+#include <algorithm>
+
+/*
+ Find largest unused thread_id range.
+
+ i.e for every number N within the returned range,
+ there is no existing connection with thread_id equal to N.
+
+ The range is exclusive, lower bound is always >=0 and
+ upper bound <=MAX_UINT32.
+
+ @param[out] low - lower bound for the range
+ @param[out] high - upper bound for the range
+*/
+static void recalculate_thread_id_range(my_thread_id *low, my_thread_id *high)
+{
+ std::vector<my_thread_id> ids;
+
+ // Add sentinels
+ ids.push_back(0);
+ ids.push_back(UINT_MAX32);
+
+ mysql_mutex_lock(&LOCK_thread_count);
+
+ I_List_iterator<THD> it(threads);
+ THD *thd;
+ while ((thd=it++))
+ ids.push_back(thd->thread_id);
+
+ mysql_mutex_unlock(&LOCK_thread_count);
+
+ std::sort(ids.begin(), ids.end());
+ my_thread_id max_gap= 0;
+ for (size_t i= 0; i < ids.size() - 1; i++)
+ {
+ my_thread_id gap= ids[i+1] - ids[i];
+ if (gap > max_gap)
+ {
+ *low= ids[i];
+ *high= ids[i+1];
+ max_gap= gap;
+ }
+ }
+
+ if (max_gap < 2)
+ {
+ /* Can't find free id. This is not really possible,
+ we'd need 2^32 connections for this to happen.*/
+ sql_print_error("Cannot find free connection id.");
+ abort();
+ }
+}
+
+
+my_thread_id next_thread_id(void)
+{
+ my_thread_id retval;
+ DBUG_EXECUTE_IF("thread_id_overflow", global_thread_id= thread_id_max-2;);
+
+ mysql_mutex_lock(&LOCK_thread_id);
+
+ if (unlikely(global_thread_id == thread_id_max - 1))
+ {
+ recalculate_thread_id_range(&global_thread_id, &thread_id_max);
+ }
+
+ retval= ++global_thread_id;
+
+ mysql_mutex_unlock(&LOCK_thread_id);
+ return retval;
+}
diff --git a/sql/mysqld.h b/sql/mysqld.h
index 57698dc5d9b..5c6ad695354 100644
--- a/sql/mysqld.h
+++ b/sql/mysqld.h
@@ -732,15 +732,7 @@ inline query_id_t get_query_id()
}
/* increment global_thread_id and return it. */
-inline __attribute__((warn_unused_result)) my_thread_id next_thread_id()
-{
- return my_atomic_add64_explicit((int64*) &global_thread_id, 1, MY_MEMORY_ORDER_RELAXED);
-}
-
-#if defined(MYSQL_DYNAMIC_PLUGIN) && defined(_WIN32)
-extern "C" my_thread_id next_thread_id_noinline();
-#define next_thread_id() next_thread_id_noinline()
-#endif
+extern __attribute__((warn_unused_result)) my_thread_id next_thread_id(void);
/*
TODO: Replace this with an inline function.
diff --git a/sql/net_serv.cc b/sql/net_serv.cc
index d9d35c5ed3f..7b988fd369b 100644
--- a/sql/net_serv.cc
+++ b/sql/net_serv.cc
@@ -1,5 +1,5 @@
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates.
- Copyright (c) 2012, 2017, MariaDB Corporation
+ Copyright (c) 2012, 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
@@ -58,6 +58,7 @@
#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(...) {}
#ifndef MYSQL_SERVER
@@ -70,6 +71,9 @@ static int inline EXTRA_DEBUG_fflush(...) { return 0; }
static void inline MYSQL_SERVER_my_error(...) {}
#endif
+#ifndef EXTRA_DEBUG_ASSERT
+# define EXTRA_DEBUG_ASSERT(X) do {} while(0)
+#endif
/*
The following handles the differences when this is linked between the
@@ -1085,7 +1089,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_range.cc b/sql/opt_range.cc
index 9c5dbc1c470..e90dbb468f1 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -2074,7 +2074,7 @@ public:
/* Table read plans are allocated on MEM_ROOT and are never deleted */
static void *operator new(size_t size, MEM_ROOT *mem_root)
{ return (void*) alloc_root(mem_root, (uint) size); }
- static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); }
+ static void operator delete(void *ptr,size_t size) { TRASH_FREE(ptr, size); }
static void operator delete(void *ptr, MEM_ROOT *mem_root) { /* Never called */ }
virtual ~TABLE_READ_PLAN() {} /* Remove gcc warning */
diff --git a/sql/sp.cc b/sql/sp.cc
index 12d303ed85a..daf0744c904 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -808,7 +808,6 @@ static sp_head *sp_compile(THD *thd, String *defstr, sql_mode_t sql_mode,
else
{
sp= thd->lex->sphead;
- sp->set_select_number(thd->select_number);
}
thd->pop_internal_handler();
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 6a4e274d00a..bb56c69aa41 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -521,7 +521,7 @@ sp_head::sp_head(const Sp_handler *sph)
m_defstr(null_clex_str),
m_sp_cache_version(0),
m_creation_ctx(0),
- unsafe_flags(0), m_select_number(1),
+ unsafe_flags(0),
m_created(0),
m_modified(0),
m_recursion_level(0),
@@ -670,7 +670,7 @@ sp_head::~sp_head()
thd->lex->sphead= NULL;
lex_end(thd->lex);
delete thd->lex;
- thd->lex= lex;
+ thd->lex= thd->stmt_lex= lex;
}
my_hash_free(&m_sptabs);
@@ -965,12 +965,13 @@ sp_head::execute(THD *thd, bool merge_da_on_success)
backup_arena;
query_id_t old_query_id;
TABLE *old_derived_tables;
- LEX *old_lex;
+ LEX *old_lex, *old_stmt_lex;
Item_change_list old_change_list;
String old_packet;
uint old_server_status;
const uint status_backup_mask= SERVER_STATUS_CURSOR_EXISTS |
SERVER_STATUS_LAST_ROW_SENT;
+ MEM_ROOT *user_var_events_alloc_saved= 0;
Reprepare_observer *save_reprepare_observer= thd->m_reprepare_observer;
Object_creation_ctx *UNINIT_VAR(saved_creation_ctx);
Diagnostics_area *da= thd->get_stmt_da();
@@ -980,19 +981,6 @@ sp_head::execute(THD *thd, bool merge_da_on_success)
if (check_stack_overrun(thd, 7 * STACK_MIN_SIZE, (uchar*)&old_packet))
DBUG_RETURN(TRUE);
- /*
- Normally the counter is not reset between parsing and first execution,
- but it is possible in case of error to have parsing on one CALL and
- first execution (where VIEW will be parsed and added). So we store the
- counter after parsing and restore it before execution just to avoid
- repeating SELECT numbers.
-
- Other problem is that it can be more SELECTs parsed in case of fixing
- error causes previous interruption of the SP. So it is save not just
- assign old value but add it.
- */
- thd->select_number+= m_select_number;
-
/* init per-instruction memroot */
init_sql_alloc(&execute_mem_root, "per_instruction_memroot",
MEM_ROOT_BLOCK_SIZE, 0, MYF(0));
@@ -1082,6 +1070,7 @@ sp_head::execute(THD *thd, bool merge_da_on_success)
do it in each instruction
*/
old_lex= thd->lex;
+ old_stmt_lex= thd->stmt_lex;
/*
We should also save Item tree change list to avoid rollback something
too early in the calling query.
@@ -1162,9 +1151,11 @@ sp_head::execute(THD *thd, bool merge_da_on_success)
Will write this SP statement into binlog separately.
TODO: consider changing the condition to "not inside event union".
*/
- MEM_ROOT *user_var_events_alloc_saved= thd->user_var_events_alloc;
if (thd->locked_tables_mode <= LTM_LOCK_TABLES)
+ {
+ user_var_events_alloc_saved= thd->user_var_events_alloc;
thd->user_var_events_alloc= thd->mem_root;
+ }
sql_digest_state *parent_digest= thd->m_digest;
thd->m_digest= NULL;
@@ -1228,6 +1219,7 @@ sp_head::execute(THD *thd, bool merge_da_on_success)
DBUG_ASSERT(thd->Item_change_list::is_empty());
old_change_list.move_elements_to(thd);
thd->lex= old_lex;
+ thd->stmt_lex= old_stmt_lex;
thd->set_query_id(old_query_id);
DBUG_ASSERT(!thd->derived_tables);
thd->derived_tables= old_derived_tables;
@@ -1333,16 +1325,6 @@ sp_head::execute(THD *thd, bool merge_da_on_success)
m_recursion_level + 1));
m_first_instance->m_first_free_instance= this;
- /*
- This execution of the SP was aborted with an error (e.g. "Table not
- found"). However it might still have consumed some numbers from the
- thd->select_number counter. The next sp->exec() call must not use the
- consumed numbers, so we remember the first free number (We know that
- nobody will use it as this execution has stopped with an error).
- */
- if (err_status)
- set_select_number(thd->select_number);
-
DBUG_RETURN(err_status);
}
@@ -3009,7 +2991,7 @@ sp_lex_keeper::reset_lex_and_exec_core(THD *thd, uint *nextp,
We should not save old value since it is saved/restored in
sp_head::execute() when we are entering/leaving routine.
*/
- thd->lex= m_lex;
+ thd->lex= thd->stmt_lex= m_lex;
thd->set_query_id(next_query_id());
diff --git a/sql/sp_head.h b/sql/sp_head.h
index 9f6d4cd95e5..af1381647f0 100644
--- a/sql/sp_head.h
+++ b/sql/sp_head.h
@@ -240,7 +240,6 @@ private:
*/
uint32 unsafe_flags;
- uint m_select_number;
public:
inline Stored_program_creation_ctx *get_creation_ctx()
{
@@ -823,8 +822,6 @@ public:
sp_pcontext *get_parse_context() { return m_pcont; }
- void set_select_number(uint num) { m_select_number= num; }
-
bool check_execute_access(THD *thd) const;
private:
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index b62e3ae74d2..f2124818687 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -5963,8 +5963,8 @@ static bool merge_role_db_privileges(ACL_ROLE *grantee, const char *dbname,
(that should be merged) are sorted together. The grantee's ACL_DB element
is not necessarily the first and may be not present at all.
*/
- ACL_DB **first= NULL, *UNINIT_VAR(merged);
- ulong UNINIT_VAR(access), update_flags= 0;
+ ACL_DB **first= NULL, *merged= NULL;
+ ulong access= 0, update_flags= 0;
for (ACL_DB **cur= dbs.front(); cur <= dbs.back(); cur++)
{
if (!first || (!dbname && strcmp(cur[0]->db, cur[-1]->db)))
@@ -6169,8 +6169,8 @@ static bool merge_role_table_and_column_privileges(ACL_ROLE *grantee,
}
grants.sort(table_name_sort);
- GRANT_TABLE **first= NULL, *UNINIT_VAR(merged), **cur;
- ulong UNINIT_VAR(privs), UNINIT_VAR(cols), update_flags= 0;
+ GRANT_TABLE **first= NULL, *merged= NULL, **cur;
+ ulong privs= 0, cols= 0, update_flags= 0;
for (cur= grants.front(); cur <= grants.back(); cur++)
{
if (!first ||
@@ -6293,8 +6293,8 @@ static bool merge_role_routine_grant_privileges(ACL_ROLE *grantee,
}
grants.sort(routine_name_sort);
- GRANT_NAME **first= NULL, *UNINIT_VAR(merged);
- ulong UNINIT_VAR(privs);
+ GRANT_NAME **first= NULL, *merged= NULL;
+ ulong privs= 0 ;
for (GRANT_NAME **cur= grants.front(); cur <= grants.back(); cur++)
{
if (!first ||
diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc
index c1c053670af..dd3f2e8abf8 100644
--- a/sql/sql_admin.cc
+++ b/sql/sql_admin.cc
@@ -700,8 +700,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
if (lock_type == TL_WRITE && !table->table->s->tmp_table &&
table->mdl_request.type > MDL_SHARED_WRITE)
{
- if (wait_while_table_is_used(thd, table->table,
- HA_EXTRA_PREPARE_FOR_RENAME))
+ if (wait_while_table_is_used(thd, table->table, HA_EXTRA_NOT_USED))
goto err;
DEBUG_SYNC(thd, "after_admin_flush");
/* Flush entries in the query cache involving this table. */
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 87ef4e0c03d..87a026ee743 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -8481,7 +8481,14 @@ int init_ftfuncs(THD *thd, SELECT_LEX *select_lex, bool no_order)
DBUG_PRINT("info",("Performing FULLTEXT search"));
while ((ifm=li++))
- ifm->init_search(thd, no_order);
+ if (unlikely(!ifm->fixed))
+ /*
+ it mean that clause where was FT function was removed, so we have
+ to remove the function from the list.
+ */
+ li.remove();
+ else
+ ifm->init_search(thd, no_order);
}
return 0;
}
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index dc5b2295b20..b85fb6e5b40 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -1188,7 +1188,11 @@ void Query_cache::end_of_result(THD *thd)
#endif
if (try_lock(thd, Query_cache::WAIT))
+ {
+ if (is_disabled())
+ query_cache_tls->first_query_block= NULL; // do not try again with QC
DBUG_VOID_RETURN;
+ }
query_block= query_cache_tls->first_query_block;
if (query_block)
@@ -1565,6 +1569,8 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
unlock();
+ DEBUG_SYNC(thd, "wait_in_query_cache_store_query");
+
// init_n_lock make query block locked
BLOCK_UNLOCK_WR(query_block);
}
@@ -2570,6 +2576,7 @@ void Query_cache::init()
*/
if (global_system_variables.query_cache_type == 0)
{
+ m_cache_status= DISABLE_REQUEST;
free_cache();
m_cache_status= DISABLED;
}
@@ -2778,13 +2785,17 @@ void Query_cache::make_disabled()
This function frees all resources allocated by the cache. You
have to call init_cache() before using the cache again. This function
- requires the structure_guard_mutex to be locked.
+ requires the cache to be locked (LOCKED_NO_WAIT, lock_and_suspend) or
+ disabling.
*/
void Query_cache::free_cache()
{
DBUG_ENTER("Query_cache::free_cache");
+ DBUG_ASSERT(m_cache_lock_status == LOCKED_NO_WAIT ||
+ m_cache_status == DISABLE_REQUEST);
+
/* Destroy locks */
Query_cache_block *block= queries_blocks;
if (block)
@@ -2792,6 +2803,13 @@ void Query_cache::free_cache()
do
{
Query_cache_query *query= block->query();
+ /*
+ There will not be new requests but some maybe not finished yet,
+ so wait for them by trying lock/unlock
+ */
+ BLOCK_LOCK_WR(block);
+ BLOCK_UNLOCK_WR(block);
+
mysql_rwlock_destroy(&query->lock);
block= block->next;
} while (block != queries_blocks);
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index c5c29e4efbc..1cd9cd19a7b 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -785,6 +785,12 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
init_sql_alloc(&main_mem_root, "THD::main_mem_root",
ALLOC_ROOT_MIN_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC));
+ /*
+ Allocation of user variables for binary logging is always done with main
+ mem root
+ */
+ user_var_events_alloc= mem_root;
+
stmt_arena= this;
thread_stack= 0;
scheduler= thread_scheduler; // Will be fixed later
@@ -2770,6 +2776,9 @@ Item_change_list::check_and_register_item_tree_change(Item **place,
MEM_ROOT *runtime_memroot)
{
Item_change_record *change;
+ DBUG_ENTER("THD::check_and_register_item_tree_change");
+ DBUG_PRINT("enter", ("Register: %p (%p) <- %p (%p)",
+ *place, place, *new_value, new_value));
I_List_iterator<Item_change_record> it(change_list);
while ((change= it++))
{
@@ -2779,6 +2788,7 @@ Item_change_list::check_and_register_item_tree_change(Item **place,
if (change)
nocheck_register_item_tree_change(place, change->old_value,
runtime_memroot);
+ DBUG_VOID_RETURN;
}
@@ -2786,17 +2796,13 @@ void Item_change_list::rollback_item_tree_changes()
{
I_List_iterator<Item_change_record> it(change_list);
Item_change_record *change;
- DBUG_ENTER("rollback_item_tree_changes");
while ((change= it++))
{
- DBUG_PRINT("info", ("revert %p -> %p",
- change->old_value, (*change->place)));
*change->place= change->old_value;
}
/* We can forget about changes memory: it's allocated in runtime memroot */
change_list.empty();
- DBUG_VOID_RETURN;
}
@@ -3725,7 +3731,7 @@ void Statement::set_statement(Statement *stmt)
{
id= stmt->id;
mark_used_columns= stmt->mark_used_columns;
- lex= stmt->lex;
+ stmt_lex= lex= stmt->lex;
query_string= stmt->query_string;
}
diff --git a/sql/sql_class.h b/sql/sql_class.h
index cbd4b26f135..0edf61ce7d5 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -1042,6 +1042,21 @@ public:
LEX_CSTRING name; /* name for named prepared statements */
LEX *lex; // parse tree descriptor
/*
+ LEX which represents current statement (conventional, SP or PS)
+
+ For example during view parsing THD::lex will point to the views LEX and
+ THD::stmt_lex will point to LEX of the statement where the view will be
+ included
+
+ Currently it is used to have always correct select numbering inside
+ statement (LEX::current_select_number) without storing and restoring a
+ global counter which was THD::select_number.
+
+ TODO: make some unified statement representation (now SP has different)
+ to store such data like LEX::current_select_number.
+ */
+ LEX *stmt_lex;
+ /*
Points to the query associated with this statement. It's const, but
we need to declare it char * because all table handlers are written
in C and need to point to it.
@@ -1198,6 +1213,29 @@ typedef struct st_xid_state {
/* Error reported by the Resource Manager (RM) to the Transaction Manager. */
uint rm_error;
XID_cache_element *xid_cache_element;
+
+ /**
+ Check that XA transaction has an uncommitted work. Report an error
+ to the user in case when there is an uncommitted work for XA transaction.
+
+ @return result of check
+ @retval false XA transaction is NOT in state IDLE, PREPARED
+ or ROLLBACK_ONLY.
+ @retval true XA transaction is in state IDLE or PREPARED
+ or ROLLBACK_ONLY.
+ */
+
+ bool check_has_uncommitted_xa() const
+ {
+ if (xa_state == XA_IDLE ||
+ xa_state == XA_PREPARED ||
+ xa_state == XA_ROLLBACK_ONLY)
+ {
+ my_error(ER_XAER_RMFAIL, MYF(0), xa_state_names[xa_state]);
+ return true;
+ }
+ return false;
+ }
} XID_STATE;
void xid_cache_init(void);
@@ -2872,7 +2910,6 @@ public:
uint tmp_table, global_disable_checkpoint;
uint server_status,open_options;
enum enum_thread_type system_thread;
- uint select_number; //number of select (used for EXPLAIN)
/*
Current or next transaction isolation level.
When a connection is established, the value is taken from
@@ -3655,10 +3692,14 @@ public:
void change_item_tree(Item **place, Item *new_value)
{
+ DBUG_ENTER("THD::change_item_tree");
+ DBUG_PRINT("enter", ("Register: %p (%p) <- %p",
+ *place, place, new_value));
/* TODO: check for OOM condition here */
if (!stmt_arena->is_conventional())
nocheck_register_item_tree_change(place, *place, mem_root);
*place= new_value;
+ DBUG_VOID_RETURN;
}
/**
Make change in item tree after checking whether it needs registering
@@ -4537,7 +4578,7 @@ public:
void set_local_lex(sp_lex_local *sublex)
{
DBUG_ASSERT(lex->sphead);
- lex= sublex;
+ lex= stmt_lex= sublex;
/* Reset part of parser state which needs this. */
m_parser_state->m_yacc.reset_before_substatement();
}
diff --git a/sql/sql_cte.cc b/sql/sql_cte.cc
index d2298619f63..2fdd493b45d 100644
--- a/sql/sql_cte.cc
+++ b/sql/sql_cte.cc
@@ -223,7 +223,8 @@ With_element *With_clause::find_table_def(TABLE_LIST *table,
with_elem= with_elem->next)
{
if (my_strcasecmp(system_charset_info, with_elem->query_name->str,
- table->table_name) == 0)
+ table->table_name) == 0 &&
+ !table->is_fqtn)
{
table->set_derived();
return with_elem;
@@ -812,7 +813,7 @@ st_select_lex_unit *With_element::clone_parsed_spec(THD *thd,
goto err;
lex_start(thd);
with_select= &lex->select_lex;
- with_select->select_number= ++thd->select_number;
+ with_select->select_number= ++thd->stmt_lex->current_select_number;
parse_status= parse_sql(thd, &parser_state, 0);
if (parse_status)
goto err;
@@ -988,23 +989,20 @@ bool With_element::is_anchor(st_select_lex *sel)
With_element *st_select_lex::find_table_def_in_with_clauses(TABLE_LIST *table)
{
- st_select_lex_unit *master_unit= NULL;
With_element *found= NULL;
- for (st_select_lex *sl= this;
- sl;
- sl= master_unit->outer_select())
+ st_select_lex_unit *master_unit;
+ st_select_lex *outer_sl;
+ for (st_select_lex *sl= this; sl; sl= outer_sl)
{
- With_element *with_elem= sl->get_with_element();
/*
If sl->master_unit() is the spec of a with element then the search for
a definition was already done by With_element::check_dependencies_in_spec
and it was unsuccesful. Yet for units cloned from the spec it has not
been done yet.
*/
- With_clause *attached_with_clause=sl->get_with_clause();
- if (attached_with_clause &&
- (found= attached_with_clause->find_table_def(table, NULL)))
- break;
+ master_unit= sl->master_unit();
+ outer_sl= master_unit->outer_select();
+ With_element *with_elem= sl->get_with_element();
if (with_elem)
{
With_clause *containing_with_clause= with_elem->get_owner();
@@ -1012,9 +1010,16 @@ With_element *st_select_lex::find_table_def_in_with_clauses(TABLE_LIST *table)
NULL : with_elem;
if ((found= containing_with_clause->find_table_def(table, barrier)))
break;
- sl= sl->master_unit()->outer_select();
+ if (outer_sl && !outer_sl->get_with_element())
+ break;
+ }
+ else
+ {
+ With_clause *attached_with_clause= sl->get_with_clause();
+ if (attached_with_clause &&
+ (found= attached_with_clause->find_table_def(table, NULL)))
+ break;
}
- master_unit= sl->master_unit();
/* Do not look for the table's definition beyond the scope of the view */
if (master_unit->is_view)
break;
diff --git a/sql/sql_cursor.cc b/sql/sql_cursor.cc
index 40eb7046108..99d95c86b2f 100644
--- a/sql/sql_cursor.cc
+++ b/sql/sql_cursor.cc
@@ -215,7 +215,7 @@ void Server_side_cursor::operator delete(void *ptr, size_t size)
MEM_ROOT own_root= *cursor->mem_root;
DBUG_ENTER("Server_side_cursor::operator delete");
- TRASH(ptr, size);
+ TRASH_FREE(ptr, size);
/*
If this cursor has never been opened mem_root is empty. Otherwise
mem_root points to the memory the cursor object was allocated in.
diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc
index 3ed1417e7d0..22bdab685e3 100644
--- a/sql/sql_derived.cc
+++ b/sql/sql_derived.cc
@@ -369,7 +369,11 @@ bool mysql_derived_merge(THD *thd, LEX *lex, TABLE_LIST *derived)
derived->get_unit()));
if (derived->merged)
+ {
+
+ DBUG_PRINT("info", ("Irreversibly merged: exit"));
DBUG_RETURN(FALSE);
+ }
if (dt_select->uncacheable & UNCACHEABLE_RAND)
{
@@ -384,7 +388,6 @@ bool mysql_derived_merge(THD *thd, LEX *lex, TABLE_LIST *derived)
thd->save_prep_leaf_list= TRUE;
arena= thd->activate_stmt_arena_if_needed(&backup); // For easier test
- derived->merged= TRUE;
if (!derived->merged_for_insert ||
(derived->is_multitable() &&
@@ -448,6 +451,7 @@ bool mysql_derived_merge(THD *thd, LEX *lex, TABLE_LIST *derived)
if (parent_lex->join)
parent_lex->join->table_count+= dt_select->join->table_count - 1;
}
+ derived->merged= TRUE;
if (derived->get_unit()->prepared)
{
Item *expr= derived->on_expr;
@@ -745,6 +749,17 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived)
}
unit->derived= derived;
+
+ /*
+ Above cascade call of prepare is important for PS protocol, but after it
+ is called we can check if we really need prepare for this derived
+ */
+ if (derived->merged)
+ {
+ DBUG_PRINT("info", ("Irreversibly merged: exit"));
+ DBUG_RETURN(FALSE);
+ }
+
derived->fill_me= FALSE;
if (!(derived->derived_result= new (thd->mem_root) select_unit(thd)))
@@ -887,6 +902,11 @@ bool mysql_derived_optimize(THD *thd, LEX *lex, TABLE_LIST *derived)
DBUG_PRINT("enter", ("Alias: '%s' Unit: %p",
(derived->alias ? derived->alias : "<NULL>"),
derived->get_unit()));
+ if (derived->merged)
+ {
+ DBUG_PRINT("info", ("Irreversibly merged: exit"));
+ DBUG_RETURN(FALSE);
+ }
lex->current_select= first_select;
diff --git a/sql/sql_explain.h b/sql/sql_explain.h
index fb524263a8e..16781adf0f4 100644
--- a/sql/sql_explain.h
+++ b/sql/sql_explain.h
@@ -207,6 +207,9 @@ public:
Explain_select(MEM_ROOT *root, bool is_analyze) :
Explain_basic_join(root),
+#ifndef DBUG_OFF
+ select_lex(NULL),
+#endif
linkage(UNSPECIFIED_TYPE),
message(NULL),
having(NULL), having_value(Item::COND_UNDEF),
@@ -218,6 +221,9 @@ public:
void add_linkage(Json_writer *writer);
public:
+#ifndef DBUG_OFF
+ SELECT_LEX *select_lex;
+#endif
const char *select_type;
enum sub_select_type linkage;
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 07b03baaf27..e5d2f88a857 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -1,6 +1,6 @@
/*
Copyright (c) 2000, 2016, Oracle and/or its affiliates.
- Copyright (c) 2010, 2017, 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_join_cache.cc b/sql/sql_join_cache.cc
index e6ef8a4be9f..3612cb6cc32 100644
--- a/sql/sql_join_cache.cc
+++ b/sql/sql_join_cache.cc
@@ -393,7 +393,7 @@ void JOIN_CACHE::create_flag_fields()
TABLE *table= tab->table;
/* Create a field for the null bitmap from table if needed */
- if (tab->used_null_fields || tab->used_uneven_bit_fields)
+ if (tab->used_null_fields || tab->used_uneven_bit_fields)
length+= add_flag_field_to_join_cache(table->null_flags,
table->s->null_bytes,
&copy);
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index b8245ce0a09..b958a0b2e16 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -1,5 +1,5 @@
/* Copyright (c) 2000, 2014, Oracle and/or its affiliates.
- Copyright (c) 2009, 2017, 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
@@ -674,6 +674,8 @@ void lex_start(THD *thd)
void LEX::start(THD *thd_arg)
{
DBUG_ENTER("LEX::start");
+ DBUG_PRINT("info", ("This: %p thd_arg->lex: %p thd_arg->stmt_lex: %p",
+ this, thd_arg->lex, thd_arg->stmt_lex));
thd= unit.thd= thd_arg;
@@ -682,6 +684,7 @@ void LEX::start(THD *thd_arg)
context_stack.empty();
unit.init_query();
unit.init_select();
+ current_select_number= 1;
select_lex.linkage= UNSPECIFIED_TYPE;
/* 'parent_lex' is used in init_query() so it must be before it. */
select_lex.parent_lex= this;
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 9b50d28e58d..a0b109d590d 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1,5 +1,5 @@
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates.
- Copyright (c) 2010, 2017, MariaDB Corporation.
+ 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
@@ -577,7 +577,7 @@ public:
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
{ return (void*) alloc_root(mem_root, (uint) size); }
- static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); }
+ static void operator delete(void *ptr,size_t size) { TRASH_FREE(ptr, size); }
static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
// Ensures that at least all members used during cleanup() are initialized.
@@ -852,7 +852,13 @@ public:
Item *cond_pushed_into_having; /* condition pushed into the select's HAVING */
/* Saved values of the WHERE and HAVING clauses*/
Item::cond_result cond_value, having_value;
- /* point on lex in which it was created, used in view subquery detection */
+ /*
+ Point to the LEX in which it was created, used in view subquery detection.
+
+ TODO: make also st_select_lex::parent_stmt_lex (see THD::stmt_lex)
+ and use st_select_lex::parent_lex & st_select_lex::parent_stmt_lex
+ instead of global (from THD) references where it is possible.
+ */
LEX *parent_lex;
enum olap_type olap;
/* FROM clause - points to the beginning of the TABLE_LIST::next_local list. */
@@ -2673,7 +2679,10 @@ struct LEX: public Query_tables_list
DYNAMIC_ARRAY plugins;
plugin_ref plugins_static_buffer[INITIAL_LEX_PLUGIN_LIST_SIZE];
- uint number_of_selects; // valid only for view
+ /** SELECT of CREATE VIEW statement */
+ LEX_STRING create_view_select;
+
+ uint current_select_number; // valid for statment LEX (not view)
/** Start of 'ON table', in trigger statements. */
const char* raw_trg_on_table_name_begin;
diff --git a/sql/sql_lifo_buffer.h b/sql/sql_lifo_buffer.h
index 8fa13c66dd9..17024d15beb 100644
--- a/sql/sql_lifo_buffer.h
+++ b/sql/sql_lifo_buffer.h
@@ -84,7 +84,7 @@ public:
start= start_arg;
end= end_arg;
if (end != start)
- TRASH(start, end - start);
+ TRASH_ALLOC(start, end - start);
reset();
}
@@ -224,7 +224,7 @@ public:
{
DBUG_ASSERT(unused_end >= unused_start);
DBUG_ASSERT(end == unused_start);
- TRASH(unused_start, unused_end - unused_start);
+ TRASH_ALLOC(unused_start, unused_end - unused_start);
end= unused_end;
}
/* Return pointer to start of the memory area that is occupied by the data */
diff --git a/sql/sql_list.h b/sql/sql_list.h
index 111826495f7..4f76c495d3e 100644
--- a/sql/sql_list.h
+++ b/sql/sql_list.h
@@ -44,12 +44,12 @@ public:
{ return alloc_root(mem_root, size); }
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
{ return alloc_root(mem_root, size); }
- static void operator delete(void *ptr, size_t size) { TRASH(ptr, size); }
+ static void operator delete(void *ptr, size_t size) { TRASH_FREE(ptr, size); }
static void operator delete(void *ptr, MEM_ROOT *mem_root)
{ /* never called */ }
static void operator delete[](void *ptr, MEM_ROOT *mem_root)
{ /* never called */ }
- static void operator delete[](void *ptr, size_t size) { TRASH(ptr, size); }
+ static void operator delete[](void *ptr, size_t size) { TRASH_FREE(ptr, size); }
#ifdef HAVE_valgrind
bool dummy_for_valgrind;
inline Sql_alloc() :dummy_for_valgrind(0) {}
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index c073adbceac..f8c09d82bf5 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -7476,7 +7476,12 @@ void THD::reset_for_next_command(bool do_clear_error)
clear_error(1);
thd->free_list= 0;
- thd->select_number= 1;
+ /*
+ We also assign thd->stmt_lex in lex_start(), but during bootstrap this
+ code is executed first.
+ */
+ thd->stmt_lex= &main_lex; thd->stmt_lex->current_select_number= 1;
+ DBUG_PRINT("info", ("Lex %p stmt_lex: %p", thd->lex, thd->stmt_lex));
/*
Those two lines below are theoretically unneeded as
THD::cleanup_after_query() should take care of this already.
@@ -7526,10 +7531,9 @@ void THD::reset_for_next_command(bool do_clear_error)
thd->thread_specific_used= FALSE;
if (opt_bin_log)
- {
reset_dynamic(&thd->user_var_events);
- thd->user_var_events_alloc= thd->mem_root;
- }
+ DBUG_ASSERT(thd->user_var_events_alloc == &thd->main_mem_root);
+
thd->get_stmt_da()->reset_for_next_command();
thd->rand_used= 0;
thd->m_sent_row_count= thd->m_examined_row_count= 0;
@@ -7596,7 +7600,7 @@ mysql_new_select(LEX *lex, bool move_down, SELECT_LEX *select_lex)
{
if (!(select_lex= new (thd->mem_root) SELECT_LEX()))
DBUG_RETURN(1);
- select_lex->select_number= ++thd->select_number;
+ select_lex->select_number= ++thd->stmt_lex->current_select_number;
select_lex->parent_lex= lex; /* Used in init_query. */
select_lex->init_query();
select_lex->init_select();
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index f951a81331b..173a7391e99 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -4431,8 +4431,14 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
!thd->lex->part_info->num_columns)
thd->lex->part_info->num_columns= 1; // to make correct clone
- if ((thd->work_part_info= thd->lex->part_info) &&
- !(thd->work_part_info= thd->lex->part_info->get_clone(thd)))
+ /*
+ 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(thd)))
DBUG_RETURN(TRUE);
/* ALTER_ADMIN_PARTITION is handled in mysql_admin_table */
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index 2b3ee37213a..0a72e3c3d5a 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -488,6 +488,11 @@ static st_plugin_dl *plugin_dl_insert_or_reuse(struct st_plugin_dl *plugin_dl)
sizeof(struct st_plugin_dl));
DBUG_RETURN(tmp);
}
+#else
+static struct st_plugin_dl *plugin_dl_find(const LEX_STRING *)
+{
+ return 0;
+}
#endif /* HAVE_DLOPEN */
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 2fd0f9c0531..52200798cf3 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -167,20 +167,6 @@ public:
uint param_count;
uint last_errno;
uint flags;
- /*
- The value of thd->select_number at the end of the PREPARE phase.
-
- The issue is: each statement execution opens VIEWs, which may cause
- select_lex objects to be created, and select_number values to be assigned.
-
- On the other hand, PREPARE assigns select_number values for triggers and
- subqueries.
-
- In order for select_number values from EXECUTE not to conflict with
- select_number values from PREPARE, we keep the number and set it at each
- execution.
- */
- uint select_number_after_prepare;
char last_error[MYSQL_ERRMSG_SIZE];
my_bool iterations;
my_bool start_param;
@@ -3796,9 +3782,9 @@ void Prepared_statement::cleanup_stmt()
DBUG_ENTER("Prepared_statement::cleanup_stmt");
DBUG_PRINT("enter",("stmt: %p", this));
thd->restore_set_statement_var();
+ thd->rollback_item_tree_changes();
cleanup_items(free_list);
thd->cleanup_after_query();
- thd->rollback_item_tree_changes();
DBUG_VOID_RETURN;
}
@@ -3883,6 +3869,7 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len)
if (! (lex= new (mem_root) st_lex_local))
DBUG_RETURN(TRUE);
+ stmt_lex= lex;
if (set_db(thd->db, thd->db_length))
DBUG_RETURN(TRUE);
@@ -3988,8 +3975,6 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len)
trans_rollback_implicit(thd);
thd->mdl_context.release_transactional_locks();
}
-
- select_number_after_prepare= thd->select_number;
/* Preserve CHANGE MASTER attributes */
lex_end_stage1(lex);
@@ -4126,7 +4111,6 @@ Prepared_statement::execute_loop(String *expanded_query,
*/
DBUG_ASSERT(thd->free_list == NULL);
- thd->select_number= select_number_after_prepare;
/* Check if we got an error when sending long data */
if (state == Query_arena::STMT_ERROR)
{
@@ -4269,7 +4253,6 @@ Prepared_statement::execute_bulk_loop(String *expanded_query,
#ifndef DBUG_OFF
Item *free_list_state= thd->free_list;
#endif
- thd->select_number= select_number_after_prepare;
thd->set_bulk_execution((void *)this);
/* Check if we got an error when sending long data */
if (state == Query_arena::STMT_ERROR)
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index f88db1048ad..6fd161f7160 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.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
@@ -283,6 +283,9 @@ JOIN_TAB *next_depth_first_tab(JOIN* join, JOIN_TAB* tab);
static JOIN_TAB *next_breadth_first_tab(JOIN_TAB *first_top_tab,
uint n_top_tabs_count, JOIN_TAB *tab);
+static bool find_order_in_list(THD *, Ref_ptr_array, TABLE_LIST *, ORDER *,
+ List<Item> &, List<Item> &, bool, bool, bool);
+
static double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s,
table_map rem_tables);
void set_postjoin_aggr_write_func(JOIN_TAB *tab);
@@ -334,7 +337,7 @@ bool dbug_user_var_equals_int(THD *thd, const char *name, int value)
}
return FALSE;
}
-#endif
+#endif
/**
@@ -710,6 +713,9 @@ JOIN::prepare(TABLE_LIST *tables_init,
join_list= &select_lex->top_join_list;
union_part= unit_arg->is_unit_op();
+ // simple check that we got usable conds
+ dbug_print_item(conds);
+
if (select_lex->handle_derived(thd->lex, DT_PREPARE))
DBUG_RETURN(1);
@@ -825,9 +831,15 @@ JOIN::prepare(TABLE_LIST *tables_init,
{
nesting_map save_allow_sum_func= thd->lex->allow_sum_func;
thd->lex->allow_sum_func|= (nesting_map)1 << select_lex->nest_level;
- if (setup_order(thd, ref_ptrs, tables_list, fields_list,
- all_fields, select_lex->order_list.first))
- DBUG_RETURN(-1);
+ thd->where= "order clause";
+ for (ORDER *order= select_lex->order_list.first; order; order= order->next)
+ {
+ /* Don't add the order items to all fields. Just resolve them to ensure
+ the query is valid, we'll drop them immediately after. */
+ if (find_order_in_list(thd, ref_ptrs, tables_list, order,
+ fields_list, all_fields, false, false, false))
+ DBUG_RETURN(-1);
+ }
thd->lex->allow_sum_func= save_allow_sum_func;
select_lex->order_list.empty();
}
@@ -3203,8 +3215,11 @@ bool JOIN::shrink_join_buffers(JOIN_TAB *jt,
ulonglong curr_space,
ulonglong needed_space)
{
+ JOIN_TAB *tab;
JOIN_CACHE *cache;
- for (JOIN_TAB *tab= join_tab+const_tables; tab < jt; tab++)
+ for (tab= first_linear_tab(this, WITHOUT_BUSH_ROOTS, WITHOUT_CONST_TABLES);
+ tab != jt;
+ tab= next_linear_tab(this, tab, WITHOUT_BUSH_ROOTS))
{
cache= tab->cache;
if (cache)
@@ -3341,6 +3356,17 @@ void JOIN::save_explain_data(Explain_query *output, bool can_overwrite,
bool need_tmp_table, bool need_order,
bool distinct)
{
+ /*
+ If there is SELECT in this statemet with the same number it must be the
+ same SELECT
+ */
+ DBUG_ASSERT(select_lex->select_number == UINT_MAX ||
+ select_lex->select_number == INT_MAX ||
+ !output ||
+ !output->get_select(select_lex->select_number) ||
+ output->get_select(select_lex->select_number)->select_lex ==
+ select_lex);
+
if (select_lex->select_number != UINT_MAX &&
select_lex->select_number != INT_MAX /* this is not a UNION's "fake select */ &&
have_query_plan != JOIN::QEP_NOT_PRESENT_YET &&
@@ -10880,7 +10906,7 @@ void JOIN::drop_unused_derived_keys()
tmp_tbl->use_index(tab->ref.key);
if (tmp_tbl->s->keys)
{
- if (tab->ref.key >= 0)
+ if (tab->ref.key >= 0 && tab->ref.key < MAX_KEY)
tab->ref.key= 0;
else
tmp_tbl->s->keys= 0;
@@ -12704,8 +12730,8 @@ static void update_depend_map(JOIN *join)
uint i;
for (i=0 ; i < ref->key_parts ; i++,item++)
depend_map|=(*item)->used_tables();
- ref->depend_map=depend_map & ~OUTER_REF_TABLE_BIT;
depend_map&= ~OUTER_REF_TABLE_BIT;
+ ref->depend_map= depend_map;
for (JOIN_TAB **tab=join->map2table;
depend_map ;
tab++,depend_map>>=1 )
@@ -13109,7 +13135,7 @@ public:
}
static void operator delete(void *ptr __attribute__((unused)),
size_t size __attribute__((unused)))
- { TRASH(ptr, size); }
+ { TRASH_FREE(ptr, size); }
Item *and_level;
Item_bool_func2 *cmp_func;
@@ -16085,9 +16111,10 @@ COND *
Item_func_isnull::remove_eq_conds(THD *thd, Item::cond_result *cond_value,
bool top_level_arg)
{
- if (args[0]->type() == Item::FIELD_ITEM)
+ Item *real_item= args[0]->real_item();
+ if (real_item->type() == Item::FIELD_ITEM)
{
- Field *field= ((Item_field*) args[0])->field;
+ Field *field= ((Item_field*) real_item)->field;
if (((field->type() == MYSQL_TYPE_DATE) ||
(field->type() == MYSQL_TYPE_DATETIME)) &&
@@ -17313,7 +17340,7 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields,
field->set_notnull();
memcpy(field->ptr,
orig_field->ptr_in_record(orig_field->table->s->default_values),
- field->pack_length());
+ field->pack_length_in_rec());
}
}
@@ -22603,7 +22630,10 @@ cp_buffer_from_ref(THD *thd, TABLE *table, TABLE_REF *ref)
SELECT list)
@param[in,out] all_fields All select, group and order by fields
@param[in] is_group_field True if order is a GROUP field, false if
- ORDER by field
+ ORDER by field
+ @param[in] add_to_all_fields If the item is to be added to all_fields and
+ ref_pointer_array, this flag can be set to
+ false to stop the automatic insertion.
@param[in] from_window_spec If true then order is from a window spec
@retval
@@ -22613,9 +22643,11 @@ cp_buffer_from_ref(THD *thd, TABLE *table, TABLE_REF *ref)
*/
static bool
-find_order_in_list(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
+find_order_in_list(THD *thd, Ref_ptr_array ref_pointer_array,
+ TABLE_LIST *tables,
ORDER *order, List<Item> &fields, List<Item> &all_fields,
- bool is_group_field, bool from_window_spec)
+ bool is_group_field, bool add_to_all_fields,
+ bool from_window_spec)
{
Item *order_item= *order->item; /* The item from the GROUP/ORDER caluse. */
Item::Type order_item_type;
@@ -22752,6 +22784,9 @@ find_order_in_list(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables
thd->is_error()))
return TRUE; /* Wrong field. */
+ if (!add_to_all_fields)
+ return FALSE;
+
uint el= all_fields.elements;
/* Add new field to field list. */
all_fields.push_front(order_item, thd->mem_root);
@@ -22780,7 +22815,7 @@ find_order_in_list(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables
*/
int setup_order(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
- List<Item> &fields, List<Item> &all_fields, ORDER *order,
+ List<Item> &fields, List<Item> &all_fields, ORDER *order,
bool from_window_spec)
{
enum_parsing_place context_analysis_place=
@@ -22789,7 +22824,7 @@ int setup_order(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
for (; order; order=order->next)
{
if (find_order_in_list(thd, ref_pointer_array, tables, order, fields,
- all_fields, FALSE, from_window_spec))
+ all_fields, false, true, from_window_spec))
return 1;
if ((*order->item)->with_window_func &&
context_analysis_place != IN_ORDER_BY)
@@ -22848,7 +22883,7 @@ setup_group(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
for (ord= order; ord; ord= ord->next)
{
if (find_order_in_list(thd, ref_pointer_array, tables, ord, fields,
- all_fields, TRUE, from_window_spec))
+ all_fields, true, true, from_window_spec))
return 1;
(*ord->item)->marker= UNDEF_POS; /* Mark found */
if ((*ord->item)->with_sum_func && context_analysis_place == IN_GROUP_BY)
@@ -23173,6 +23208,7 @@ get_sort_by_table(ORDER *a,ORDER *b, List<TABLE_LIST> &tables,
if (!map || (map & (RAND_TABLE_BIT | OUTER_REF_TABLE_BIT)))
DBUG_RETURN(0);
+ map&= ~const_tables;
while ((table= ti++) && !(map & table->table->map)) ;
if (map != table->table->map)
DBUG_RETURN(0); // More than one table
@@ -25155,6 +25191,11 @@ int JOIN::save_explain_data_intern(Explain_query *output,
{
explain= new (output->mem_root) Explain_select(output->mem_root,
thd->lex->analyze_stmt);
+ if (!explain)
+ DBUG_RETURN(1); // EoM
+#ifndef DBUG_OFF
+ explain->select_lex= select_lex;
+#endif
join->select_lex->set_explain_type(true);
explain->select_id= join->select_lex->select_number;
diff --git a/sql/sql_select.h b/sql/sql_select.h
index 3f1fdac96cb..eb78f4216f9 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -1976,7 +1976,7 @@ int report_error(TABLE *table, int error);
int safe_index_read(JOIN_TAB *tab);
int get_quick_record(SQL_SELECT *select);
int setup_order(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
- List<Item> &fields, List <Item> &all_fields, ORDER *order,
+ List<Item> &fields, List <Item> &all_fields, ORDER *order,
bool from_window_spec= false);
int setup_group(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
List<Item> &fields, List<Item> &all_fields, ORDER *order,
@@ -2057,7 +2057,7 @@ public:
@param thd - Current thread.
*/
static void *operator new(size_t size, THD *thd) throw();
- static void operator delete(void *ptr, size_t size) { TRASH(ptr, size); }
+ static void operator delete(void *ptr, size_t size) {TRASH_FREE(ptr, size);}
Virtual_tmp_table(THD *thd)
{
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 919e2871b40..604b228b263 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -2611,7 +2611,7 @@ public:
{ return alloc_root(mem_root, size); }
static void operator delete(void *ptr __attribute__((unused)),
size_t size __attribute__((unused)))
- { TRASH(ptr, size); }
+ { TRASH_FREE(ptr, size); }
my_thread_id thread_id;
uint32 os_thread_id;
diff --git a/sql/sql_string.h b/sql/sql_string.h
index 3908cdff252..98c87f45d8f 100644
--- a/sql/sql_string.h
+++ b/sql/sql_string.h
@@ -185,7 +185,7 @@ public:
{
(void) ptr_arg;
(void) size;
- TRASH(ptr_arg, size);
+ TRASH_FREE(ptr_arg, size);
}
static void operator delete(void *, MEM_ROOT *)
{ /* never called */ }
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 44d507412ec..41d8d8f4603 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -1834,7 +1834,8 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
#endif
/* Write shadow frm file */
lpt->create_info->table_options= lpt->db_options;
- LEX_CUSTRING frm= build_frm_image(lpt->thd, lpt->table_name,
+ LEX_CUSTRING frm= build_frm_image(lpt->thd,
+ lpt->table_name,
lpt->create_info,
lpt->alter_info->create_list,
lpt->key_count, lpt->key_info_buffer,
@@ -5980,6 +5981,7 @@ remove_key:
#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)
{
/* ALTER TABLE ADD PARTITION IF NOT EXISTS */
@@ -6000,7 +6002,7 @@ remove_key:
ER_THD(thd, 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;
}
}
@@ -9887,11 +9889,12 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
if ((int) key_nr >= 0)
{
const char *err_msg= ER_THD(thd, ER_DUP_ENTRY_WITH_KEY_NAME);
- if (key_nr == 0 &&
+ if (key_nr == 0 && to->s->keys > 0 &&
(to->key_info[0].key_part[0].field->flags &
AUTO_INCREMENT_FLAG))
err_msg= ER_THD(thd, ER_DUP_ENTRY_AUTOINCREMENT_CASE);
- print_keydup_error(to, key_nr == MAX_KEY ? NULL :
+ print_keydup_error(to,
+ key_nr >= to->s->keys ? NULL :
&to->key_info[key_nr],
err_msg, MYF(0));
}
diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc
index ebc5b28f598..a919994c90c 100644
--- a/sql/sql_trigger.cc
+++ b/sql/sql_trigger.cc
@@ -1362,11 +1362,12 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
List_iterator_fast<LEX_CSTRING> it_connection_cl_name(trigger_list->connection_cl_names);
List_iterator_fast<LEX_CSTRING> it_db_cl_name(trigger_list->db_cl_names);
List_iterator_fast<ulonglong> it_create_times(trigger_list->create_times);
- LEX *old_lex= thd->lex, lex;
+ LEX *old_lex= thd->lex, *old_stmt_lex= thd->stmt_lex;
+ LEX lex;
sp_rcontext *save_spcont= thd->spcont;
sql_mode_t save_sql_mode= thd->variables.sql_mode;
- thd->lex= &lex;
+ thd->lex= thd->stmt_lex= &lex;
save_db.str= thd->db;
save_db.length= thd->db_length;
@@ -1585,6 +1586,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
}
thd->reset_db(save_db.str, save_db.length);
thd->lex= old_lex;
+ thd->stmt_lex= old_stmt_lex;
thd->spcont= save_spcont;
thd->variables.sql_mode= save_sql_mode;
@@ -1598,6 +1600,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
err_with_lex_cleanup:
lex_end(&lex);
thd->lex= old_lex;
+ thd->stmt_lex= old_stmt_lex;
thd->spcont= save_spcont;
thd->variables.sql_mode= save_sql_mode;
thd->reset_db(save_db.str, save_db.length);
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 47286f1df14..909ef887928 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -1793,22 +1793,6 @@ void st_select_lex_unit::reinit_exec_mechanism()
{
prepared= optimized= optimized_2= executed= 0;
optimize_started= 0;
-#ifndef DBUG_OFF
- if (is_unit_op())
- {
- List_iterator_fast<Item> it(item_list);
- Item *field;
- while ((field= it++))
- {
- /*
- we can't cleanup here, because it broke link to temporary table field,
- but have to drop fixed flag to allow next fix_field of this field
- during re-executing
- */
- field->fixed= 0;
- }
- }
-#endif
if (with_element && with_element->is_recursive)
with_element->reset_recursive_for_exec();
}
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index c5a2555178d..0a13a630487 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -1200,8 +1200,6 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table,
*/
mysql_derived_reinit(thd, NULL, table);
- thd->select_number+= table->view->number_of_selects;
-
DEBUG_SYNC(thd, "after_cached_view_opened");
DBUG_RETURN(0);
}
@@ -1357,7 +1355,7 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table,
lex_start(thd);
view_select= &lex->select_lex;
- view_select->select_number= ++thd->select_number;
+ view_select->select_number= ++thd->stmt_lex->current_select_number;
sql_mode_t saved_mode= thd->variables.sql_mode;
/* switch off modes which can prevent normal parsing of VIEW
@@ -1392,9 +1390,6 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table,
parse_status= parse_sql(thd, & parser_state, table->view_creation_ctx);
- lex->number_of_selects=
- (thd->select_number - view_select->select_number) + 1;
-
/* Restore environment. */
if ((old_lex->sql_command == SQLCOM_SHOW_FIELDS) ||
diff --git a/sql/table.cc b/sql/table.cc
index afd6b14079f..7502a13d5ce 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -1601,9 +1601,10 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
rec_buff_length= ALIGN_SIZE(share->reclength + 1);
share->rec_buff_length= rec_buff_length;
- if (!(record= (uchar *) alloc_root(&share->mem_root,
- rec_buff_length)))
+ if (!(record= (uchar *) alloc_root(&share->mem_root, rec_buff_length)))
goto err; /* purecov: inspected */
+ MEM_NOACCESS(record, rec_buff_length);
+ MEM_UNDEFINED(record, share->reclength);
share->default_values= record;
memcpy(record, frm_image + record_offset, share->reclength);
@@ -3089,6 +3090,7 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,
if (!(record= (uchar*) alloc_root(&outparam->mem_root,
share->rec_buff_length * records)))
goto err; /* purecov: inspected */
+ MEM_NOACCESS(record, share->rec_buff_length * records);
if (records == 0)
{
@@ -3103,6 +3105,8 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,
else
outparam->record[1]= outparam->record[0]; // Safety
}
+ MEM_UNDEFINED(outparam->record[0], share->reclength);
+ MEM_UNDEFINED(outparam->record[1], share->reclength);
if (!(field_ptr = (Field **) alloc_root(&outparam->mem_root,
(uint) ((share->fields+1)*
diff --git a/sql/threadpool_generic.cc b/sql/threadpool_generic.cc
index f6fdd97c6df..400d072df3c 100644
--- a/sql/threadpool_generic.cc
+++ b/sql/threadpool_generic.cc
@@ -1698,10 +1698,9 @@ int TP_pool_generic::set_pool_size(uint size)
if(!success)
{
sql_print_error("io_poll_create() failed, errno=%d\n", errno);
- break;
}
}
- mysql_mutex_unlock(&all_groups[i].mutex);
+ mysql_mutex_unlock(&group->mutex);
if (!success)
{
group_count= i;
diff --git a/sql/transaction.cc b/sql/transaction.cc
index 78cd3047f82..a6db204c45b 100644
--- a/sql/transaction.cc
+++ b/sql/transaction.cc
@@ -611,12 +611,8 @@ bool trans_savepoint(THD *thd, LEX_CSTRING name)
!opt_using_transactions)
DBUG_RETURN(FALSE);
- enum xa_states xa_state= thd->transaction.xid_state.xa_state;
- if (xa_state != XA_NOTR && xa_state != XA_ACTIVE)
- {
- my_error(ER_XAER_RMFAIL, MYF(0), xa_state_names[xa_state]);
+ if (thd->transaction.xid_state.check_has_uncommitted_xa())
DBUG_RETURN(TRUE);
- }
sv= find_savepoint(thd, name);
@@ -691,12 +687,8 @@ bool trans_rollback_to_savepoint(THD *thd, LEX_CSTRING name)
DBUG_RETURN(TRUE);
}
- enum xa_states xa_state= thd->transaction.xid_state.xa_state;
- if (xa_state != XA_NOTR)
- {
- my_error(ER_XAER_RMFAIL, MYF(0), xa_state_names[xa_state]);
+ if (thd->transaction.xid_state.check_has_uncommitted_xa())
DBUG_RETURN(TRUE);
- }
/**
Checking whether it is safe to release metadata locks acquired after
diff --git a/sql/unireg.cc b/sql/unireg.cc
index b49c3cfbb09..1342e4c2b66 100644
--- a/sql/unireg.cc
+++ b/sql/unireg.cc
@@ -1,6 +1,6 @@
/*
Copyright (c) 2000, 2011, Oracle and/or its affiliates.
- Copyright (c) 2009, 2013, Monty Program Ab.
+ 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
@@ -87,7 +87,7 @@ static uchar *extra2_write(uchar *pos, enum extra2_frm_value_type type,
return extra2_write(pos, type, reinterpret_cast<LEX_CSTRING *>(str));
}
-/**
+/*
Create a frm (table definition) file
@param thd Thread handler
@@ -175,7 +175,8 @@ LEX_CUSTRING build_frm_image(THD *thd, const char *table,
DBUG_PRINT("info", ("Options length: %u", options_len));
if (validate_comment_length(thd, &create_info->comment, TABLE_COMMENT_MAXLEN,
- ER_TOO_LONG_TABLE_COMMENT, table))
+ ER_TOO_LONG_TABLE_COMMENT,
+ table))
DBUG_RETURN(frm);
/*
If table comment is longer than TABLE_COMMENT_INLINE_MAXLEN bytes,
@@ -280,6 +281,14 @@ LEX_CUSTRING build_frm_image(THD *thd, const char *table,
DBUG_ASSERT(pos == frm_ptr + uint2korr(fileinfo+6));
key_info_length= pack_keys(pos, keys, key_info, data_offset);
+ if (key_info_length > UINT_MAX16)
+ {
+ my_printf_error(ER_CANT_CREATE_TABLE,
+ "Cannot create table %`s: index information is too long. "
+ "Decrease number of indexes or use shorter index names or shorter comments.",
+ MYF(0), table);
+ goto err;
+ }
int2store(forminfo+2, frm.length - filepos);
int4store(fileinfo+10, frm.length);
diff --git a/sql/wsrep_sst.cc b/sql/wsrep_sst.cc
index 8626cb07196..ba611fed0c7 100644
--- a/sql/wsrep_sst.cc
+++ b/sql/wsrep_sst.cc
@@ -30,9 +30,10 @@
#include <cstdio>
#include <cstdlib>
-char wsrep_defaults_file[FN_REFLEN * 2 + 10 +
- sizeof(WSREP_SST_OPT_CONF) +
- sizeof(WSREP_SST_OPT_EXTRA_CONF)] = {0};
+static char wsrep_defaults_file[FN_REFLEN * 2 + 10 + 30 +
+ sizeof(WSREP_SST_OPT_CONF) +
+ sizeof(WSREP_SST_OPT_CONF_SUFFIX) +
+ sizeof(WSREP_SST_OPT_CONF_EXTRA)] = {0};
// container for real auth string
static const char* sst_auth_real = NULL;
@@ -69,7 +70,11 @@ static void make_wsrep_defaults_file()
if (my_defaults_extra_file)
ptr= strxnmov(ptr, end - ptr,
- WSREP_SST_OPT_EXTRA_CONF, " '", my_defaults_extra_file, "' ", NULL);
+ WSREP_SST_OPT_CONF_EXTRA, " '", my_defaults_extra_file, "' ", NULL);
+
+ if (my_defaults_group_suffix)
+ ptr= strxnmov(ptr, end - ptr,
+ WSREP_SST_OPT_CONF_SUFFIX, " '", my_defaults_group_suffix, "' ", NULL);
}
}
@@ -630,8 +635,8 @@ static ssize_t sst_prepare_other (const char* method,
WSREP_SST_OPT_PARENT" '%d'"
" %s '%s' ",
method, addr_in, mysql_real_data_home,
- wsrep_defaults_file, (int)getpid(),
- binlog_opt, binlog_opt_val);
+ wsrep_defaults_file,
+ (int)getpid(), binlog_opt, binlog_opt_val);
my_free(binlog_opt_val);
if (ret < 0 || ret >= cmd_len)
@@ -913,7 +918,7 @@ static int sst_donate_mysqldump (const char* addr,
WSREP_SST_OPT_PORT" '%d' "
WSREP_SST_OPT_LPORT" '%u' "
WSREP_SST_OPT_SOCKET" '%s' "
- " %s "
+ " '%s' "
WSREP_SST_OPT_GTID" '%s:%lld' "
WSREP_SST_OPT_GTID_DOMAIN_ID" '%d'"
"%s",
diff --git a/sql/wsrep_sst.h b/sql/wsrep_sst.h
index 460046bc4ad..8bf6dc31464 100644
--- a/sql/wsrep_sst.h
+++ b/sql/wsrep_sst.h
@@ -27,7 +27,8 @@
#define WSREP_SST_OPT_AUTH "--auth"
#define WSREP_SST_OPT_DATA "--datadir"
#define WSREP_SST_OPT_CONF "--defaults-file"
-#define WSREP_SST_OPT_EXTRA_CONF "--defaults-extra-file"
+#define WSREP_SST_OPT_CONF_SUFFIX "--defaults-group-suffix"
+#define WSREP_SST_OPT_CONF_EXTRA "--defaults-extra-file"
#define WSREP_SST_OPT_PARENT "--parent"
#define WSREP_SST_OPT_BINLOG "--binlog"