summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/ha_partition.cc53
-rw-r--r--sql/item.cc50
-rw-r--r--sql/item_row.cc13
-rw-r--r--sql/mysqld.cc12
-rw-r--r--sql/opt_split.cc2
-rw-r--r--sql/slave.cc2
-rw-r--r--sql/sql_class.cc1
-rw-r--r--sql/sql_connect.cc2
-rw-r--r--sql/sql_select.cc8
-rw-r--r--sql/sql_select.h5
-rw-r--r--sql/sql_show.cc7
-rw-r--r--sql/sql_string.h4
-rw-r--r--sql/sql_table.cc2
-rw-r--r--sql/threadpool.h11
-rw-r--r--sql/threadpool_common.cc3
-rw-r--r--sql/threadpool_generic.cc31
-rw-r--r--sql/threadpool_generic.h4
-rw-r--r--sql/threadpool_win.cc4
18 files changed, 125 insertions, 89 deletions
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index de7f9855499..271355e45d6 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -10094,7 +10094,8 @@ ha_partition::check_if_supported_inplace_alter(TABLE *altered_table,
Alter_inplace_info *ha_alter_info)
{
uint index= 0;
- enum_alter_inplace_result result= HA_ALTER_INPLACE_NO_LOCK;
+ enum_alter_inplace_result result;
+ alter_table_operations orig_ops;
ha_partition_inplace_ctx *part_inplace_ctx;
bool first_is_set= false;
THD *thd= ha_thd();
@@ -10121,33 +10122,35 @@ ha_partition::check_if_supported_inplace_alter(TABLE *altered_table,
if (!part_inplace_ctx->handler_ctx_array)
DBUG_RETURN(HA_ALTER_ERROR);
- /* Set all to NULL, including the terminating one. */
- for (index= 0; index <= m_tot_parts; index++)
- part_inplace_ctx->handler_ctx_array[index]= NULL;
+ do {
+ result= HA_ALTER_INPLACE_NO_LOCK;
+ /* Set all to NULL, including the terminating one. */
+ for (index= 0; index <= m_tot_parts; index++)
+ part_inplace_ctx->handler_ctx_array[index]= NULL;
- ha_alter_info->handler_flags |= ALTER_PARTITIONED;
- for (index= 0; index < m_tot_parts; index++)
- {
- enum_alter_inplace_result p_result=
- m_file[index]->check_if_supported_inplace_alter(altered_table,
- ha_alter_info);
- part_inplace_ctx->handler_ctx_array[index]= ha_alter_info->handler_ctx;
-
- if (index == 0)
+ ha_alter_info->handler_flags |= ALTER_PARTITIONED;
+ orig_ops= ha_alter_info->handler_flags;
+ for (index= 0; index < m_tot_parts; index++)
{
- first_is_set= (ha_alter_info->handler_ctx != NULL);
- }
- else if (first_is_set != (ha_alter_info->handler_ctx != NULL))
- {
- /* Either none or all partitions must set handler_ctx! */
- DBUG_ASSERT(0);
- DBUG_RETURN(HA_ALTER_ERROR);
+ enum_alter_inplace_result p_result=
+ m_file[index]->check_if_supported_inplace_alter(altered_table,
+ ha_alter_info);
+ part_inplace_ctx->handler_ctx_array[index]= ha_alter_info->handler_ctx;
+
+ if (index == 0)
+ first_is_set= (ha_alter_info->handler_ctx != NULL);
+ else if (first_is_set != (ha_alter_info->handler_ctx != NULL))
+ {
+ /* Either none or all partitions must set handler_ctx! */
+ DBUG_ASSERT(0);
+ DBUG_RETURN(HA_ALTER_ERROR);
+ }
+ if (p_result < result)
+ result= p_result;
+ if (result == HA_ALTER_ERROR)
+ break;
}
- if (p_result < result)
- result= p_result;
- if (result == HA_ALTER_ERROR)
- break;
- }
+ } while (orig_ops != ha_alter_info->handler_flags);
ha_alter_info->handler_ctx= part_inplace_ctx;
/*
diff --git a/sql/item.cc b/sql/item.cc
index 89e23173b0e..4c1fe99e222 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1,6 +1,6 @@
/*
Copyright (c) 2000, 2018, Oracle and/or its affiliates.
- Copyright (c) 2010, 2020, MariaDB Corporation
+ Copyright (c) 2010, 2020, 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
@@ -2560,42 +2560,46 @@ bool Type_std_attributes::agg_item_set_converter(const DTCollation &coll,
/**
@brief
Building clone for Item_func_or_sum
-
+
@param thd thread handle
- @param mem_root part of the memory for the clone
+ @param mem_root part of the memory for the clone
@details
- This method gets copy of the current item and also
- build clones for its referencies. For the referencies
- build_copy is called again.
-
- @retval
- clone of the item
- 0 if an error occurred
-*/
+ This method first builds clones of the arguments. If it is successful with
+ buiding the clones then it constructs a copy of this Item_func_or_sum object
+ and attaches to it the built clones of the arguments.
+
+ @return clone of the item
+ @retval 0 on a failure
+*/
Item* Item_func_or_sum::build_clone(THD *thd)
{
- Item_func_or_sum *copy= (Item_func_or_sum *) get_copy(thd);
- if (unlikely(!copy))
- return 0;
+ Item *copy_tmp_args[2]= {0,0};
+ Item **copy_args= copy_tmp_args;
if (arg_count > 2)
{
- copy->args=
- (Item**) alloc_root(thd->mem_root, sizeof(Item*) * arg_count);
- if (unlikely(!copy->args))
+ copy_args= static_cast<Item**>
+ (alloc_root(thd->mem_root, sizeof(Item*) * arg_count));
+ if (unlikely(!copy_args))
return 0;
}
- else if (arg_count > 0)
- copy->args= copy->tmp_arg;
-
-
for (uint i= 0; i < arg_count; i++)
{
Item *arg_clone= args[i]->build_clone(thd);
- if (!arg_clone)
+ if (unlikely(!arg_clone))
return 0;
- copy->args[i]= arg_clone;
+ copy_args[i]= arg_clone;
+ }
+ Item_func_or_sum *copy= static_cast<Item_func_or_sum *>(get_copy(thd));
+ if (unlikely(!copy))
+ return 0;
+ if (arg_count > 2)
+ copy->args= copy_args;
+ else if (arg_count > 0)
+ {
+ copy->args= copy->tmp_arg;
+ memcpy(copy->args, copy_args, sizeof(Item *) * arg_count);
}
return copy;
}
diff --git a/sql/item_row.cc b/sql/item_row.cc
index def1458df1b..767787497ce 100644
--- a/sql/item_row.cc
+++ b/sql/item_row.cc
@@ -1,5 +1,6 @@
/*
Copyright (c) 2002, 2011, Oracle and/or its affiliates.
+ Copyright (c) 2011, 2020, 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
@@ -184,16 +185,20 @@ void Item_row::bring_value()
Item* Item_row::build_clone(THD *thd)
{
- Item_row *copy= (Item_row *) get_copy(thd);
- if (!copy)
+ Item **copy_args= static_cast<Item**>
+ (alloc_root(thd->mem_root, sizeof(Item*) * arg_count));
+ if (unlikely(!copy_args))
return 0;
- copy->args= (Item**) alloc_root(thd->mem_root, sizeof(Item*) * arg_count);
for (uint i= 0; i < arg_count; i++)
{
Item *arg_clone= args[i]->build_clone(thd);
if (!arg_clone)
return 0;
- copy->args[i]= arg_clone;
+ copy_args[i]= arg_clone;
}
+ Item_row *copy= (Item_row *) get_copy(thd);
+ if (unlikely(!copy))
+ return 0;
+ copy->args= copy_args;
return copy;
}
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 9033103cef5..1497296e7cf 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -7425,6 +7425,16 @@ static int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff,
*(int *)buff= tp_get_idle_thread_count();
return 0;
}
+
+
+static int show_threadpool_threads(THD *thd, SHOW_VAR *var, char *buff,
+ enum enum_var_type scope)
+{
+ var->type= SHOW_INT;
+ var->value= buff;
+ *(reinterpret_cast<int*>(buff))= tp_get_thread_count();
+ return 0;
+}
#endif
/*
@@ -7644,7 +7654,7 @@ SHOW_VAR status_vars[]= {
#endif
#ifdef HAVE_POOL_OF_THREADS
{"Threadpool_idle_threads", (char *) &show_threadpool_idle_threads, SHOW_SIMPLE_FUNC},
- {"Threadpool_threads", (char *) &tp_stats.num_worker_threads, SHOW_INT},
+ {"Threadpool_threads", (char *) &show_threadpool_threads, SHOW_SIMPLE_FUNC},
#endif
{"Threads_cached", (char*) &cached_thread_count, SHOW_LONG_NOFLUSH},
{"Threads_connected", (char*) &connection_count, SHOW_INT},
diff --git a/sql/opt_split.cc b/sql/opt_split.cc
index b27a0d757cb..a6031f75a5b 100644
--- a/sql/opt_split.cc
+++ b/sql/opt_split.cc
@@ -966,7 +966,7 @@ SplM_plan_info * JOIN_TAB::choose_best_splitting(double record_count,
The plan for the chosen key has not been found in the cache.
Build a new plan and save info on it in the cache
*/
- table_map all_table_map= (1 << join->table_count) - 1;
+ table_map all_table_map= (((table_map) 1) << join->table_count) - 1;
reset_validity_vars_for_keyuses(best_key_keyuse_ext_start, best_table,
best_key, remaining_tables, true);
choose_plan(join, all_table_map & ~join->const_table_map);
diff --git a/sql/slave.cc b/sql/slave.cc
index 6a014e9bfa4..754c8df3638 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -1,5 +1,5 @@
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates.
- Copyright (c) 2009, 2020, MariaDB Corporation
+ Copyright (c) 2009, 2020, 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_class.cc b/sql/sql_class.cc
index 64f8e99c0c4..d323f7e0004 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -636,6 +636,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
m_current_stage_key(0), m_psi(0),
in_sub_stmt(0), log_all_errors(0),
binlog_unsafe_warning_flags(0),
+ current_stmt_binlog_format(BINLOG_FORMAT_MIXED),
bulk_param(0),
table_map_for_update(0),
m_examined_row_count(0),
diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc
index d5a90089da4..aa9e561a717 100644
--- a/sql/sql_connect.cc
+++ b/sql/sql_connect.cc
@@ -1,6 +1,6 @@
/*
Copyright (c) 2007, 2013, Oracle and/or its affiliates.
- Copyright (c) 2008, 2016, MariaDB
+ Copyright (c) 2008, 2020, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index f7660054b74..f78d2ac544c 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -2964,8 +2964,12 @@ int JOIN::optimize_stage2()
having_is_correlated= MY_TEST(having->used_tables() & OUTER_REF_TABLE_BIT);
tmp_having= having;
- if ((select_lex->options & OPTION_SCHEMA_TABLE))
- optimize_schema_tables_reads(this);
+ if ((select_lex->options & OPTION_SCHEMA_TABLE) &&
+ optimize_schema_tables_reads(this))
+ DBUG_RETURN(TRUE);
+
+ if (unlikely(thd->is_error()))
+ DBUG_RETURN(TRUE);
/*
The loose index scan access method guarantees that all grouping or
diff --git a/sql/sql_select.h b/sql/sql_select.h
index 8b2df74702b..46c84b9df7b 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -2,7 +2,7 @@
#define SQL_SELECT_INCLUDED
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates.
- Copyright (c) 2008, 2017, MariaDB Corporation.
+ Copyright (c) 2008, 2020, 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
@@ -1666,6 +1666,9 @@ public:
void copy_ref_ptr_array(Ref_ptr_array dst_arr, Ref_ptr_array src_arr)
{
DBUG_ASSERT(dst_arr.size() >= src_arr.size());
+ if (src_arr.size() == 0)
+ return;
+
void *dest= dst_arr.array();
const void *src= src_arr.array();
memcpy(dest, src, src_arr.size() * src_arr.element_size());
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 2b1be46b807..78a54f6e5e3 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -8488,7 +8488,6 @@ end:
bool optimize_schema_tables_reads(JOIN *join)
{
THD *thd= join->thd;
- bool result= 0;
DBUG_ENTER("optimize_schema_tables_reads");
JOIN_TAB *tab;
@@ -8523,11 +8522,11 @@ bool optimize_schema_tables_reads(JOIN *join)
*/
cond= tab->cache_select->cond;
}
-
- optimize_for_get_all_tables(thd, table_list, cond);
+ if (optimize_for_get_all_tables(thd, table_list, cond))
+ DBUG_RETURN(TRUE); // Handle OOM
}
}
- DBUG_RETURN(result);
+ DBUG_RETURN(FALSE);
}
diff --git a/sql/sql_string.h b/sql/sql_string.h
index 4eeac0a8a82..37225e17c1e 100644
--- a/sql/sql_string.h
+++ b/sql/sql_string.h
@@ -86,6 +86,10 @@ public:
Well_formed_prefix(CHARSET_INFO *cs, const char *str, size_t length)
:Well_formed_prefix_status(cs, str, str + length, length), m_str(str)
{ }
+ Well_formed_prefix(CHARSET_INFO *cs, LEX_STRING str, size_t nchars)
+ :Well_formed_prefix_status(cs, str.str, str.str + str.length, nchars),
+ m_str(str.str)
+ { }
size_t length() const { return m_source_end_pos - m_str; }
};
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 05d4b450f30..c6c542fd478 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -4454,6 +4454,8 @@ bool validate_comment_length(THD *thd, LEX_CSTRING *comment, size_t max_len,
uint err_code, const char *name)
{
DBUG_ENTER("validate_comment_length");
+ if (comment->length == 0)
+ DBUG_RETURN(false);
size_t tmp_len= system_charset_info->charpos(comment->str,
comment->str + comment->length,
max_len);
diff --git a/sql/threadpool.h b/sql/threadpool.h
index fe77100a82a..742c357dade 100644
--- a/sql/threadpool.h
+++ b/sql/threadpool.h
@@ -1,8 +1,4 @@
-#ifndef THREADPOOL_H_INCLUDED
-#define THREADPOOL_H_INCLUDED
-
-#ifdef HAVE_POOL_OF_THREADS
-/* Copyright (C) 2012 Monty Program Ab
+/* Copyright (C) 2012, 2020, MariaDB
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
@@ -17,6 +13,8 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
+#pragma once
+#ifdef HAVE_POOL_OF_THREADS
#define MAX_THREAD_GROUPS 100000
/* Threadpool parameters */
@@ -50,7 +48,7 @@ extern void tp_timeout_handler(TP_connection *c);
struct TP_STATISTICS
{
/* Current number of worker thread. */
- volatile int32 num_worker_threads;
+ Atomic_counter<uint32_t> num_worker_threads;
};
extern TP_STATISTICS tp_stats;
@@ -163,4 +161,3 @@ struct TP_pool_generic :TP_pool
};
#endif /* HAVE_POOL_OF_THREADS */
-#endif /* THREADPOOL_H_INCLUDED */
diff --git a/sql/threadpool_common.cc b/sql/threadpool_common.cc
index 40b230e5392..b0a5d38d5eb 100644
--- a/sql/threadpool_common.cc
+++ b/sql/threadpool_common.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2012, 2019, MariaDB Corporation.
+/* Copyright (C) 2012, 2020, 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
@@ -23,7 +23,6 @@
#include <sql_audit.h>
#include <debug_sync.h>
#include <threadpool.h>
-#include <my_counter.h>
#ifdef WITH_WSREP
#include "wsrep_trans_observer.h"
diff --git a/sql/threadpool_generic.cc b/sql/threadpool_generic.cc
index 86b039d5319..7aebd217d68 100644
--- a/sql/threadpool_generic.cc
+++ b/sql/threadpool_generic.cc
@@ -92,7 +92,7 @@ static PSI_thread_info thread_list[] =
thread_group_t *all_groups;
static uint group_count;
-static int32 shutdown_group_count;
+static Atomic_counter<uint32_t> shutdown_group_count;
/**
Used for printing "pool blocked" message, see
@@ -106,7 +106,7 @@ struct pool_timer_t
mysql_mutex_t mutex;
mysql_cond_t cond;
volatile uint64 current_microtime;
- volatile uint64 next_timeout_check;
+ std::atomic<uint64_t> next_timeout_check;
int tick_interval;
bool shutdown;
pthread_t timer_thread_id;
@@ -525,7 +525,8 @@ static void* timer_thread(void *param)
my_thread_init();
DBUG_ENTER("timer_thread");
- timer->next_timeout_check= ULONGLONG_MAX;
+ timer->next_timeout_check.store(std::numeric_limits<uint64_t>::max(),
+ std::memory_order_relaxed);
timer->current_microtime= microsecond_interval_timer();
for(;;)
@@ -553,11 +554,12 @@ static void* timer_thread(void *param)
}
/* Check if any client exceeded wait_timeout */
- if (timer->next_timeout_check <= timer->current_microtime)
+ if (timer->next_timeout_check.load(std::memory_order_relaxed) <=
+ timer->current_microtime)
{
/* Reset next timeout check, it will be recalculated below */
- my_atomic_fas64((volatile int64*) &timer->next_timeout_check,
- ULONGLONG_MAX);
+ timer->next_timeout_check.store(std::numeric_limits<uint64_t>::max(),
+ std::memory_order_relaxed);
server_threads.iterate(timeout_check, timer);
}
}
@@ -809,7 +811,7 @@ static void add_thread_count(thread_group_t *thread_group, int32 count)
thread_group->thread_count += count;
/* worker starts out and end in "active" state */
thread_group->active_thread_count += count;
- my_atomic_add32(&tp_stats.num_worker_threads, count);
+ tp_stats.num_worker_threads+= count;
}
@@ -829,7 +831,7 @@ static int create_worker(thread_group_t *thread_group, bool due_to_stall)
int err;
DBUG_ENTER("create_worker");
- if (tp_stats.num_worker_threads >= (int)threadpool_max_threads
+ if (tp_stats.num_worker_threads >= threadpool_max_threads
&& thread_group->thread_count >= 2)
{
err= 1;
@@ -978,7 +980,7 @@ void thread_group_destroy(thread_group_t *thread_group)
}
#endif
- if (my_atomic_add32(&shutdown_group_count, -1) == 1)
+ if (!--shutdown_group_count)
my_free(all_groups);
}
@@ -1331,12 +1333,15 @@ void TP_connection_generic::wait_end()
static void set_next_timeout_check(ulonglong abstime)
{
+ auto old= pool_timer.next_timeout_check.load(std::memory_order_relaxed);
DBUG_ENTER("set_next_timeout_check");
- while(abstime < pool_timer.next_timeout_check)
+ while (abstime < old)
{
- longlong old= (longlong)pool_timer.next_timeout_check;
- my_atomic_cas64((volatile int64*)&pool_timer.next_timeout_check,
- &old, abstime);
+ if (pool_timer.next_timeout_check.
+ compare_exchange_weak(old, abstime,
+ std::memory_order_relaxed,
+ std::memory_order_relaxed))
+ break;
}
DBUG_VOID_RETURN;
}
diff --git a/sql/threadpool_generic.h b/sql/threadpool_generic.h
index 5f923bc0652..64aa67c40d3 100644
--- a/sql/threadpool_generic.h
+++ b/sql/threadpool_generic.h
@@ -1,4 +1,4 @@
-/* Copyright(C) 2019 MariaDB
+/* Copyright(C) 2019, 2020, MariaDB
*
* This program is free software; you can redistribute itand /or modify
* it under the terms of the GNU General Public License as published by
@@ -17,8 +17,8 @@
#include <my_global.h>
#include <sql_plist.h>
#include <my_pthread.h>
-#include <threadpool.h>
#include <mysqld.h>
+#include <threadpool.h>
#include <violite.h>
#ifdef _WIN32
diff --git a/sql/threadpool_win.cc b/sql/threadpool_win.cc
index c9968d48c06..18ffd259fde 100644
--- a/sql/threadpool_win.cc
+++ b/sql/threadpool_win.cc
@@ -306,7 +306,7 @@ void tp_win_callback_prolog()
/* Running in new worker thread*/
FlsSetValue(fls, (void *)1);
statistic_increment(thread_created, &LOCK_status);
- InterlockedIncrement((volatile long *)&tp_stats.num_worker_threads);
+ tp_stats.num_worker_threads++;
my_thread_init();
}
}
@@ -329,7 +329,7 @@ static VOID WINAPI thread_destructor(void *data)
{
if(data)
{
- InterlockedDecrement((volatile long *)&tp_stats.num_worker_threads);
+ tp_stats.num_worker_threads--;
my_thread_end();
}
}