summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorVicențiu Ciorbaru <vicentiu@mariadb.org>2018-04-10 17:43:18 +0300
committerVicențiu Ciorbaru <vicentiu@mariadb.org>2018-04-10 17:43:18 +0300
commit45e6d0aebf023acb50671f82b87e6de5d1e78f5e (patch)
treec6079a18e158706a0a877d1b522ceb851d6055b5 /sql
parentf5cb66fb97101bc0f17ff879025fd7146c032cbc (diff)
parent2e91eb7547dfc7c9a999568bd8245832bbcfefaa (diff)
downloadmariadb-git-45e6d0aebf023acb50671f82b87e6de5d1e78f5e.tar.gz
Merge branch '10.1' into 10.2
Diffstat (limited to 'sql')
-rw-r--r--sql/contributors.h3
-rw-r--r--sql/item_strfunc.cc2
-rw-r--r--sql/item_strfunc.h6
-rw-r--r--sql/mysqld.cc96
-rw-r--r--sql/mysqld.h2
-rw-r--r--sql/set_var.h10
-rw-r--r--sql/share/errmsg-utf8.txt4
-rw-r--r--sql/sql_const.h2
-rw-r--r--sql/sql_parse.cc34
-rw-r--r--sql/sql_statistics.cc23
-rw-r--r--sql/sql_yacc.yy5
-rw-r--r--sql/sys_vars.cc8
-rw-r--r--sql/table.h1
13 files changed, 120 insertions, 76 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/item_strfunc.cc b/sql/item_strfunc.cc
index b2317caf61e..7d7614171b5 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -317,7 +317,7 @@ String *Item_aes_crypt::val_str(String *str2)
{
DBUG_ASSERT(fixed == 1);
StringBuffer<80> user_key_buf;
- String *sptr= args[0]->val_str(&str_value);
+ String *sptr= args[0]->val_str(&tmp_value);
String *user_key= args[1]->val_str(&user_key_buf);
uint32 aes_length;
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 3723f4eb5f4..4372855ccf5 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -213,6 +213,7 @@ class Item_aes_crypt :public Item_str_binary_checksum_func
protected:
int what;
+ String tmp_value;
public:
Item_aes_crypt(THD *thd, Item *a, Item *b)
:Item_str_binary_checksum_func(thd, a, b) {}
@@ -222,8 +223,8 @@ public:
class Item_func_aes_encrypt :public Item_aes_crypt
{
public:
- Item_func_aes_encrypt(THD *thd, Item *a, Item *b):
- Item_aes_crypt(thd, a, b) {}
+ Item_func_aes_encrypt(THD *thd, Item *a, Item *b)
+ :Item_aes_crypt(thd, a, b) {}
void fix_length_and_dec();
const char *func_name() const { return "aes_encrypt"; }
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
@@ -1383,6 +1384,7 @@ public:
DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
fix_char_length(MY_UUID_STRING_LENGTH);
}
+ table_map used_tables() const { return RAND_TABLE_BIT; }
const char *func_name() const{ return "uuid"; }
String *val_str(String *);
bool check_vcol_func_processor(void *arg)
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 1c4fcaeca20..99cad2c0423 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -115,7 +115,7 @@
#include <poll.h>
#endif
-#include <my_systemd.h>
+#include <my_service_manager.h>
#define mysqld_charset &my_charset_latin1
@@ -547,7 +547,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
@@ -558,7 +558,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;
my_thread_id global_thread_id= 0;
ulong current_pid;
ulong slow_launch_threads = 0;
@@ -4393,11 +4393,20 @@ static int init_common_variables()
/* connections and databases needs lots of files */
{
- uint files, wanted_files, max_open_files;
+ uint files, wanted_files, max_open_files, min_tc_size, extra_files,
+ min_connections;
+ ulong org_max_connections, org_tc_size;
+ /* Number of files reserved for temporary files */
+ extra_files= 30;
+ min_connections= 10;
/* MyISAM requires two file handles per table. */
- wanted_files= (10 + max_connections + extra_max_connections +
+ wanted_files= (extra_files + max_connections + extra_max_connections +
tc_size * 2);
+ min_tc_size= MY_MIN(tc_size, TABLE_OPEN_CACHE_MIN);
+ org_max_connections= max_connections;
+ org_tc_size= tc_size;
+
/*
We are trying to allocate no less than max_connections*5 file
handles (i.e. we are trying to set the limit so that they will
@@ -4409,44 +4418,49 @@ static int init_common_variables()
requested (value of wanted_files).
*/
max_open_files= MY_MAX(MY_MAX(wanted_files,
- (max_connections + extra_max_connections)*5),
- open_files_limit);
+ (max_connections + extra_max_connections)*5),
+ open_files_limit);
files= my_set_max_open_files(max_open_files);
+ SYSVAR_AUTOSIZE_IF_CHANGED(open_files_limit, files, ulong);
- if (files < wanted_files)
- {
- if (!open_files_limit || IS_SYSVAR_AUTOSIZE(&open_files_limit))
- {
- /*
- If we have requested too much file handles than we bring
- max_connections in supported bounds.
- */
- SYSVAR_AUTOSIZE(max_connections,
- (ulong) MY_MIN(files-10-TABLE_OPEN_CACHE_MIN*2, max_connections));
- /*
- Decrease tc_size according to max_connections, but
- not below TABLE_OPEN_CACHE_MIN. Outer MY_MIN() ensures that we
- never increase tc_size automatically (that could
- happen if max_connections is decreased above).
- */
- SYSVAR_AUTOSIZE(tc_size,
- (ulong) MY_MIN(MY_MAX((files - 10 - max_connections) / 2,
- TABLE_OPEN_CACHE_MIN), tc_size));
- DBUG_PRINT("warning",
- ("Changed limits: max_open_files: %u max_connections: %ld table_cache: %ld",
- files, max_connections, tc_size));
- if (global_system_variables.log_warnings > 1)
- sql_print_warning("Changed limits: max_open_files: %u max_connections: %ld table_cache: %ld",
- files, max_connections, tc_size);
- }
- else if (global_system_variables.log_warnings)
- sql_print_warning("Could not increase number of max_open_files to more than %u (request: %u)", files, wanted_files);
- }
- SYSVAR_AUTOSIZE(open_files_limit, files);
- }
+ if (files < wanted_files && global_system_variables.log_warnings)
+ sql_print_warning("Could not increase number of max_open_files to more than %u (request: %u)", files, wanted_files);
+
+ /*
+ If we have requested too much file handles than we bring
+ max_connections in supported bounds. Still leave at least
+ 'min_connections' connections
+ */
+ SYSVAR_AUTOSIZE_IF_CHANGED(max_connections,
+ (ulong) MY_MAX(MY_MIN(files- extra_files-
+ min_tc_size*2,
+ max_connections),
+ min_connections),
+ ulong);
+ /*
+ Decrease tc_size according to max_connections, but
+ not below min_tc_size. Outer MY_MIN() ensures that we
+ never increase tc_size automatically (that could
+ happen if max_connections is decreased above).
+ */
+ SYSVAR_AUTOSIZE_IF_CHANGED(tc_size,
+ (ulong) MY_MIN(MY_MAX((files - extra_files -
+ max_connections) / 2,
+ min_tc_size),
+ tc_size), ulong);
+ DBUG_PRINT("warning",
+ ("Current limits: max_open_files: %u max_connections: %ld table_cache: %ld",
+ files, max_connections, tc_size));
+ if (global_system_variables.log_warnings > 1 &&
+ (max_connections < org_max_connections ||
+ tc_size < org_tc_size))
+ sql_print_warning("Changed limits: max_open_files: %u max_connections: %lu (was %lu) table_cache: %lu (was %lu)",
+ files, max_connections, org_max_connections,
+ tc_size, org_tc_size);
+ }
/*
- Max_connections is now set.
+ Max_connections and tc_cache are now set.
Now we can fix other variables depending on this variable.
*/
@@ -6579,7 +6593,7 @@ void handle_connections_sockets()
#endif
sd_notify(0, "READY=1\n"
- "STATUS=Taking your SQL requests now...");
+ "STATUS=Taking your SQL requests now...\n");
DBUG_PRINT("general",("Waiting for connections."));
MAYBE_BROKEN_SYSCALL;
@@ -6781,7 +6795,7 @@ void handle_connections_sockets()
create_new_thread(connect);
}
sd_notify(0, "STOPPING=1\n"
- "STATUS=Shutdown in progress");
+ "STATUS=Shutdown in progress\n");
DBUG_VOID_RETURN;
}
diff --git a/sql/mysqld.h b/sql/mysqld.h
index d13fdd193ef..74e4f1ecb43 100644
--- a/sql/mysqld.h
+++ b/sql/mysqld.h
@@ -208,7 +208,7 @@ extern uint slave_net_timeout;
extern int max_user_connections;
extern volatile ulong cached_thread_count;
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/set_var.h b/sql/set_var.h
index 97dc3b5ba51..7a48e319466 100644
--- a/sql/set_var.h
+++ b/sql/set_var.h
@@ -399,6 +399,16 @@ int sql_set_variables(THD *thd, List<set_var_base> *var_list, bool free);
set_sys_var_value_origin(&VAR, sys_var::AUTO); \
} while(0)
+#define SYSVAR_AUTOSIZE_IF_CHANGED(VAR,VAL,TYPE) \
+ do { \
+ TYPE tmp= (VAL); \
+ if (VAR != tmp) \
+ { \
+ VAR= (VAL); \
+ set_sys_var_value_origin(&VAR, sys_var::AUTO); \
+ } \
+ } while(0)
+
void set_sys_var_value_origin(void *ptr, enum sys_var::where here);
enum sys_var::where get_sys_var_value_origin(void *ptr);
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index 4285f5cffa5..0bb1974b6cd 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -5749,8 +5749,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_const.h b/sql/sql_const.h
index c91992a9029..7395ae3c08a 100644
--- a/sql/sql_const.h
+++ b/sql/sql_const.h
@@ -126,7 +126,7 @@
#define MAX_ACCEPT_RETRY 10 // Test accept this many times
#define MAX_FIELDS_BEFORE_HASH 32
#define USER_VARS_HASH_SIZE 16
-#define TABLE_OPEN_CACHE_MIN 400
+#define TABLE_OPEN_CACHE_MIN 200
#define TABLE_OPEN_CACHE_DEFAULT 2000
#define TABLE_DEF_CACHE_DEFAULT 400
/**
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 33039847cb7..5edf92f2a96 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1341,22 +1341,27 @@ bool do_command(THD *thd)
command= fetch_command(thd, packet);
#ifdef WITH_WSREP
- /*
- Bail out if DB snapshot has not been installed.
- */
- if (thd->variables.wsrep_on && !thd->wsrep_applier &&
- (!wsrep_ready || wsrep_reject_queries != WSREP_REJECT_NONE) &&
- (server_command_flags[command] & CF_SKIP_WSREP_CHECK) == 0)
+ if (WSREP(thd))
{
- thd->protocol->end_statement();
+ /*
+ Bail out if DB snapshot has not been installed.
+ */
+ if (!thd->wsrep_applier &&
+ (!wsrep_ready || wsrep_reject_queries != WSREP_REJECT_NONE) &&
+ (server_command_flags[command] & CF_SKIP_WSREP_CHECK) == 0)
+ {
+ my_message(ER_UNKNOWN_COM_ERROR,
+ "WSREP has not yet prepared node for application use", MYF(0));
+ thd->protocol->end_statement();
- /* Performance Schema Interface instrumentation end. */
- MYSQL_END_STATEMENT(thd->m_statement_psi, thd->get_stmt_da());
- thd->m_statement_psi= NULL;
- thd->m_digest= NULL;
+ /* Performance Schema Interface instrumentation end. */
+ MYSQL_END_STATEMENT(thd->m_statement_psi, thd->get_stmt_da());
+ thd->m_statement_psi= NULL;
+ thd->m_digest= NULL;
- return_value= FALSE;
- goto out;
+ return_value= FALSE;
+ goto out;
+ }
}
#endif
@@ -3156,8 +3161,7 @@ mysql_execute_command(THD *thd)
* allow SET and SHOW queries and reads from information schema
* and dirty reads (if configured)
*/
- if (thd->variables.wsrep_on &&
- !thd->wsrep_applier &&
+ if (!thd->wsrep_applier &&
!(wsrep_ready && wsrep_reject_queries == WSREP_REJECT_NONE) &&
!(thd->variables.wsrep_dirty_reads &&
(sql_command_flags[lex->sql_command] & CF_CHANGES_DATA) == 0) &&
diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc
index 5a9bf08d99b..5badcad3492 100644
--- a/sql/sql_statistics.cc
+++ b/sql/sql_statistics.cc
@@ -3083,18 +3083,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;
}
}
@@ -3770,6 +3771,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();
@@ -3993,4 +4003,3 @@ bool is_stat_table(const char *db, const char *table)
}
return false;
}
-
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 112cf9877b4..b2088b0e640 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -15174,6 +15174,11 @@ option_value_no_option_type:
| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
{
struct sys_var_with_base tmp= $4;
+ if (tmp.var == trg_new_row_fake_var)
+ {
+ my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), 3, "NEW");
+ MYSQL_YYABORT;
+ }
/* Lookup if necessary: must be a system variable. */
if (tmp.var == NULL)
{
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index a640bc40f85..c3d786af945 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -1414,7 +1414,7 @@ static bool fix_max_connections(sys_var *self, THD *thd, enum_var_type type)
static Sys_var_ulong Sys_max_connections(
"max_connections", "The number of simultaneous clients allowed",
PARSED_EARLY GLOBAL_VAR(max_connections), CMD_LINE(REQUIRED_ARG),
- VALID_RANGE(1, 100000),
+ VALID_RANGE(10, 100000),
DEFAULT(MAX_CONNECTIONS_DEFAULT), BLOCK_SIZE(1), NO_MUTEX_GUARD,
NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(fix_max_connections));
@@ -2142,11 +2142,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_recursive_iterations(
@@ -3224,7 +3224,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, 1024*1024), DEFAULT(TABLE_OPEN_CACHE_DEFAULT),
+ VALID_RANGE(10, 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));
diff --git a/sql/table.h b/sql/table.h
index f77f9fcf9ec..7af45b9f169 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -2334,6 +2334,7 @@ struct TABLE_LIST
DBUG_PRINT("enter", ("Alias: '%s' Unit: %p",
(alias ? alias : "<NULL>"),
get_unit()));
+ derived= get_unit();
derived_type= ((derived_type & (derived ? DTYPE_MASK : DTYPE_VIEW)) |
DTYPE_TABLE | DTYPE_MATERIALIZE);
set_check_materialized();