1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

Merge 10.4 into 10.5

This commit is contained in:
Marko Mäkelä
2020-03-23 10:50:14 +02:00
22 changed files with 76 additions and 75 deletions

View File

@@ -41,6 +41,7 @@
/* That one is necessary for defines of OPTION_NO_FOREIGN_KEY_CHECKS etc */
#include "sql_priv.h"
#include "sql_basic_types.h"
#include <atomic>
#include "log_event.h"
#include "compat56.h"
#include "sql_common.h"

View File

@@ -518,6 +518,10 @@ test.t1 check status OK
DROP TABLE t1;
SET GLOBAL innodb_purge_rseg_truncate_frequency = @saved_frequency;
# End of 10.2 tests
CREATE TABLE t1 (a GEOMETRY, INDEX(a(8)),
FOREIGN KEY (a) REFERENCES x (xx)) ENGINE=InnoDB;
ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
# End of 10.4 tests
#
# MDEV-20729 Fix REFERENCES constraint in column definition
#

View File

@@ -498,6 +498,14 @@ SET GLOBAL innodb_purge_rseg_truncate_frequency = @saved_frequency;
--echo # End of 10.2 tests
# MDEV-21792 Server aborts upon attempt to create foreign key on spatial field
# Fail to create foreign key for spatial fields
--error ER_CANT_CREATE_TABLE
CREATE TABLE t1 (a GEOMETRY, INDEX(a(8)),
FOREIGN KEY (a) REFERENCES x (xx)) ENGINE=InnoDB;
-- echo # End of 10.4 tests
--echo #
--echo # MDEV-20729 Fix REFERENCES constraint in column definition
--echo #

View File

@@ -474,9 +474,9 @@ static int ha_finish_errors(void)
return 0;
}
static volatile int32 need_full_discover_for_existence= 0;
static volatile int32 engines_with_discover_file_names= 0;
static volatile int32 engines_with_discover= 0;
static Atomic_counter<int32> need_full_discover_for_existence(0);
static Atomic_counter<int32> engines_with_discover_file_names(0);
static Atomic_counter<int32> engines_with_discover(0);
static int full_discover_for_existence(handlerton *, const char *, const char *)
{ return 0; }
@@ -498,13 +498,13 @@ static int hton_ext_based_table_discovery(handlerton *hton, LEX_CSTRING *db,
static void update_discovery_counters(handlerton *hton, int val)
{
if (hton->discover_table_existence == full_discover_for_existence)
my_atomic_add32(&need_full_discover_for_existence, val);
need_full_discover_for_existence+= val;
if (hton->discover_table_names && hton->tablefile_extensions[0])
my_atomic_add32(&engines_with_discover_file_names, val);
engines_with_discover_file_names+= val;
if (hton->discover_table)
my_atomic_add32(&engines_with_discover, val);
engines_with_discover+= val;
}
int ha_finalize_handlerton(st_plugin_int *plugin)

View File

@@ -479,7 +479,7 @@ ulonglong test_flags;
ulonglong query_cache_size=0;
ulong query_cache_limit=0;
ulong executed_events=0;
query_id_t global_query_id;
Atomic_counter<query_id_t> global_query_id;
ulong aborted_threads, aborted_connects, aborted_connects_preauth;
ulong delayed_insert_timeout, delayed_insert_limit, delayed_queue_size;
ulong delayed_insert_threads, delayed_insert_writes, delayed_rows_in_use;
@@ -7631,7 +7631,7 @@ SHOW_VAR status_vars[]= {
{"Subquery_cache_miss", (char*) &subquery_cache_miss, SHOW_LONG},
{"Table_locks_immediate", (char*) &locks_immediate, SHOW_LONG},
{"Table_locks_waited", (char*) &locks_waited, SHOW_LONG},
{"Table_open_cache_active_instances", (char*) &tc_active_instances, SHOW_UINT},
{"Table_open_cache_active_instances", (char*) &show_tc_active_instances, SHOW_SIMPLE_FUNC},
{"Table_open_cache_hits", (char*) offsetof(STATUS_VAR, table_open_cache_hits), SHOW_LONGLONG_STATUS},
{"Table_open_cache_misses", (char*) offsetof(STATUS_VAR, table_open_cache_misses), SHOW_LONGLONG_STATUS},
{"Table_open_cache_overflows", (char*) offsetof(STATUS_VAR, table_open_cache_overflows), SHOW_LONGLONG_STATUS},

View File

@@ -23,7 +23,6 @@
#include "sql_bitmap.h" /* Bitmap */
#include "my_decimal.h" /* my_decimal */
#include "mysql_com.h" /* SERVER_VERSION_LENGTH */
#include "my_atomic.h"
#include "my_counter.h"
#include "mysql/psi/mysql_file.h" /* MYSQL_FILE */
#include "mysql/psi/mysql_socket.h" /* MYSQL_SOCKET */
@@ -892,17 +891,17 @@ enum enum_query_type
/* query_id */
extern query_id_t global_query_id;
extern Atomic_counter<query_id_t> global_query_id;
/* increment query_id and return it. */
inline __attribute__((warn_unused_result)) query_id_t next_query_id()
{
return my_atomic_add64_explicit(&global_query_id, 1, MY_MEMORY_ORDER_RELAXED);
return global_query_id++;
}
inline query_id_t get_query_id()
{
return my_atomic_load64_explicit(&global_query_id, MY_MEMORY_ORDER_RELAXED);
return global_query_id;
}
/* increment global_thread_id and return it. */

View File

@@ -258,7 +258,7 @@ rpl_slave_state::rpl_slave_state()
rpl_slave_state::~rpl_slave_state()
{
free_gtid_pos_tables((struct gtid_pos_table *)gtid_pos_tables);
free_gtid_pos_tables(gtid_pos_tables.load(std::memory_order_relaxed));
truncate_hash();
my_hash_free(&hash);
delete_dynamic(&gtid_sort_array);
@@ -499,21 +499,18 @@ gtid_check_rpl_slave_state_table(TABLE *table)
void
rpl_slave_state::select_gtid_pos_table(THD *thd, LEX_CSTRING *out_tablename)
{
struct gtid_pos_table *list, *table_entry, *default_entry;
/*
See comments on rpl_slave_state::gtid_pos_tables for rules around proper
access to the list.
*/
list= (struct gtid_pos_table *)
my_atomic_loadptr_explicit(&gtid_pos_tables, MY_MEMORY_ORDER_ACQUIRE);
auto list= gtid_pos_tables.load(std::memory_order_acquire);
Ha_trx_info *ha_info;
uint count = 0;
for (ha_info= thd->transaction.all.ha_list; ha_info; ha_info= ha_info->next())
{
void *trx_hton= ha_info->ht();
table_entry= list;
auto table_entry= list;
if (!ha_info->is_trx_read_write() || trx_hton == binlog_hton)
continue;
@@ -567,9 +564,8 @@ rpl_slave_state::select_gtid_pos_table(THD *thd, LEX_CSTRING *out_tablename)
already active in the transaction, or if there is no current transaction
engines available, we return the default gtid_slave_pos table.
*/
default_entry= (struct gtid_pos_table *)
my_atomic_loadptr_explicit(&default_gtid_pos_table, MY_MEMORY_ORDER_ACQUIRE);
*out_tablename= default_entry->table_name;
*out_tablename=
default_gtid_pos_table.load(std::memory_order_acquire)->table_name;
/* Record in status that we failed to find a suitable gtid_pos table. */
if (count > 0)
{
@@ -823,14 +819,11 @@ rpl_slave_state::gtid_grab_pending_delete_list()
LEX_CSTRING *
rpl_slave_state::select_gtid_pos_table(void *hton)
{
struct gtid_pos_table *table_entry;
/*
See comments on rpl_slave_state::gtid_pos_tables for rules around proper
access to the list.
*/
table_entry= (struct gtid_pos_table *)
my_atomic_loadptr_explicit(&gtid_pos_tables, MY_MEMORY_ORDER_ACQUIRE);
auto table_entry= gtid_pos_tables.load(std::memory_order_acquire);
while (table_entry)
{
@@ -842,9 +835,7 @@ rpl_slave_state::select_gtid_pos_table(void *hton)
table_entry= table_entry->next;
}
table_entry= (struct gtid_pos_table *)
my_atomic_loadptr_explicit(&default_gtid_pos_table, MY_MEMORY_ORDER_ACQUIRE);
return &table_entry->table_name;
return &default_gtid_pos_table.load(std::memory_order_acquire)->table_name;
}
@@ -1443,13 +1434,10 @@ void
rpl_slave_state::set_gtid_pos_tables_list(rpl_slave_state::gtid_pos_table *new_list,
rpl_slave_state::gtid_pos_table *default_entry)
{
gtid_pos_table *old_list;
mysql_mutex_assert_owner(&LOCK_slave_state);
old_list= (struct gtid_pos_table *)gtid_pos_tables;
my_atomic_storeptr_explicit(&gtid_pos_tables, new_list, MY_MEMORY_ORDER_RELEASE);
my_atomic_storeptr_explicit(&default_gtid_pos_table, default_entry,
MY_MEMORY_ORDER_RELEASE);
auto old_list= gtid_pos_tables.load(std::memory_order_relaxed);
gtid_pos_tables.store(new_list, std::memory_order_release);
default_gtid_pos_table.store(default_entry, std::memory_order_release);
free_gtid_pos_tables(old_list);
}
@@ -1458,8 +1446,8 @@ void
rpl_slave_state::add_gtid_pos_table(rpl_slave_state::gtid_pos_table *entry)
{
mysql_mutex_assert_owner(&LOCK_slave_state);
entry->next= (struct gtid_pos_table *)gtid_pos_tables;
my_atomic_storeptr_explicit(&gtid_pos_tables, entry, MY_MEMORY_ORDER_RELEASE);
entry->next= gtid_pos_tables.load(std::memory_order_relaxed);
gtid_pos_tables.store(entry, std::memory_order_release);
}

View File

@@ -18,7 +18,7 @@
#include "hash.h"
#include "queues.h"
#include <atomic>
/* Definitions for MariaDB global transaction ID (GTID). */
@@ -219,13 +219,10 @@ struct rpl_slave_state
The list can be read without lock by an SQL driver thread or worker thread
by reading the gtid_pos_tables pointer atomically with acquire semantics,
to ensure that it will see the correct next pointer of a new head element.
The type is struct gtid_pos_table *, but needs to be void * to allow using
my_atomic operations without violating C strict aliasing semantics.
*/
void * volatile gtid_pos_tables;
std::atomic<gtid_pos_table*> gtid_pos_tables;
/* The default entry in gtid_pos_tables, mysql.gtid_slave_pos. */
void * volatile default_gtid_pos_table;
std::atomic<gtid_pos_table*> default_gtid_pos_table;
bool loaded;
rpl_slave_state();

View File

@@ -2023,10 +2023,9 @@ find_gtid_slave_pos_tables(THD *thd)
However we can add new entries, and warn about any tables that
disappeared, but may still be visible to running SQL threads.
*/
rpl_slave_state::gtid_pos_table *old_entry, *new_entry, **next_ptr_ptr;
old_entry= (rpl_slave_state::gtid_pos_table *)
rpl_global_gtid_slave_state->gtid_pos_tables;
rpl_slave_state::gtid_pos_table *new_entry, **next_ptr_ptr;
auto old_entry= rpl_global_gtid_slave_state->
gtid_pos_tables.load(std::memory_order_relaxed);
while (old_entry)
{
new_entry= cb_data.table_list;
@@ -2048,8 +2047,8 @@ find_gtid_slave_pos_tables(THD *thd)
while (new_entry)
{
/* Check if we already have a table with this storage engine. */
old_entry= (rpl_slave_state::gtid_pos_table *)
rpl_global_gtid_slave_state->gtid_pos_tables;
old_entry= rpl_global_gtid_slave_state->
gtid_pos_tables.load(std::memory_order_relaxed);
while (old_entry)
{
if (new_entry->table_hton == old_entry->table_hton)

View File

@@ -399,8 +399,8 @@ handle_gtid_pos_auto_create_request(THD *thd, void *hton)
/* Find the entry for the table to auto-create. */
mysql_mutex_lock(&rpl_global_gtid_slave_state->LOCK_slave_state);
entry= (rpl_slave_state::gtid_pos_table *)
rpl_global_gtid_slave_state->gtid_pos_tables;
entry= rpl_global_gtid_slave_state->
gtid_pos_tables.load(std::memory_order_relaxed);
while (entry)
{
if (entry->table_hton == hton &&
@@ -436,8 +436,8 @@ handle_gtid_pos_auto_create_request(THD *thd, void *hton)
/* Now enable the entry for the auto-created table. */
mysql_mutex_lock(&rpl_global_gtid_slave_state->LOCK_slave_state);
entry= (rpl_slave_state::gtid_pos_table *)
rpl_global_gtid_slave_state->gtid_pos_tables;
entry= rpl_global_gtid_slave_state->
gtid_pos_tables.load(std::memory_order_relaxed);
while (entry)
{
if (entry->table_hton == hton &&

View File

@@ -56,7 +56,7 @@
ulong tdc_size; /**< Table definition cache threshold for LRU eviction. */
ulong tc_size; /**< Table cache threshold for LRU eviction. */
uint32 tc_instances;
uint32 tc_active_instances= 1;
static std::atomic<uint32_t> tc_active_instances(1);
static std::atomic<bool> tc_contention_warning_reported;
/** Data collections. */
@@ -162,7 +162,7 @@ struct Table_cache_instance
overhead on TABLE object release. All other table cache mutex acquistions
are considered out of hot path and are not instrumented either.
*/
void lock_and_check_contention(uint32 n_instances, uint32 instance)
void lock_and_check_contention(uint32_t n_instances, uint32_t instance)
{
if (mysql_mutex_trylock(&LOCK_table_cache))
{
@@ -171,11 +171,10 @@ struct Table_cache_instance
{
if (n_instances < tc_instances)
{
if (my_atomic_cas32_weak_explicit((int32*) &tc_active_instances,
(int32*) &n_instances,
(int32) n_instances + 1,
MY_MEMORY_ORDER_RELAXED,
MY_MEMORY_ORDER_RELAXED))
if (tc_active_instances.
compare_exchange_weak(n_instances, n_instances + 1,
std::memory_order_relaxed,
std::memory_order_relaxed))
{
sql_print_information("Detected table cache mutex contention at instance %d: "
"%d%% waits. Additional table cache instance "
@@ -353,8 +352,8 @@ void tc_purge()
void tc_add_table(THD *thd, TABLE *table)
{
uint32 i= thd->thread_id % my_atomic_load32_explicit((int32*) &tc_active_instances,
MY_MEMORY_ORDER_RELAXED);
uint32_t i=
thd->thread_id % tc_active_instances.load(std::memory_order_relaxed);
TABLE *LRU_table= 0;
TDC_element *element= table->s->tdc;
@@ -407,10 +406,8 @@ void tc_add_table(THD *thd, TABLE *table)
TABLE *tc_acquire_table(THD *thd, TDC_element *element)
{
uint32 n_instances=
my_atomic_load32_explicit((int32*) &tc_active_instances,
MY_MEMORY_ORDER_RELAXED);
uint32 i= thd->thread_id % n_instances;
uint32_t n_instances= tc_active_instances.load(std::memory_order_relaxed);
uint32_t i= thd->thread_id % n_instances;
TABLE *table;
tc[i].lock_and_check_contention(n_instances, i);
@@ -1279,3 +1276,14 @@ int tdc_iterate(THD *thd, my_hash_walk_action action, void *argument,
}
return res;
}
int show_tc_active_instances(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{
var->type= SHOW_UINT;
var->value= buff;
*(reinterpret_cast<uint32_t*>(buff))=
tc_active_instances.load(std::memory_order_relaxed);
return 0;
}

View File

@@ -68,7 +68,6 @@ enum enum_tdc_remove_table_type
extern ulong tdc_size;
extern ulong tc_size;
extern uint32 tc_instances;
extern uint32 tc_active_instances;
extern bool tdc_init(void);
extern void tdc_start_shutdown(void);
@@ -91,6 +90,8 @@ extern int tdc_iterate(THD *thd, my_hash_walk_action action, void *argument,
bool no_dups= false);
extern uint tc_records(void);
int show_tc_active_instances(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope);
extern void tc_purge();
extern void tc_add_table(THD *thd, TABLE *table);
extern void tc_release_table(TABLE *table);

View File

@@ -2032,7 +2032,8 @@ dict_index_add_to_cache(
> field->col->max_prefix) {
/* Set the max_prefix value based on the
prefix_len. */
ut_ad(field->prefix_len % field->col->mbmaxlen == 0);
ut_ad(field->col->is_binary()
|| field->prefix_len % field->col->mbmaxlen == 0);
field->col->max_prefix = field->prefix_len;
}
ut_ad(field->col->ord_part == 1);

View File

@@ -734,6 +734,9 @@ public:
| CHAR_COLL_MASK << 16
| DATA_LONG_TRUE_VARCHAR));
}
/** @return whether the column values are comparable by memcmp() */
inline bool is_binary() const { return prtype & DATA_BINARY_TYPE; }
};
/** Index information put in a list of virtual column structure. Index

View File

@@ -30,7 +30,6 @@ Created 12/15/2009 Jimmy Yang
#define srv0mon_h
#include "univ.i"
#include "my_atomic.h"
#ifndef __STDC_LIMIT_MACROS
/* Required for FreeBSD so that INT64_MAX is defined. */

View File

@@ -470,7 +470,6 @@ static ulonglong flush_start= 0;
#define TRANSLOG_CLSN_LEN_BITS 0xC0 /* Mask to get compressed LSN length */
#include <my_atomic.h>
/* an array that maps id of a MARIA_SHARE to this MARIA_SHARE */
static MARIA_SHARE **id_to_share= NULL;

View File

@@ -23,7 +23,6 @@
#include <my_global.h>
#include <my_sys.h>
#include <my_atomic.h>
#include <lf.h>
#include "../lockman.h"

View File

@@ -23,7 +23,6 @@
#include <my_global.h>
#include <my_sys.h>
#include <my_atomic.h>
#include <lf.h>
#include "../lockman.h"
#include "../tablockman.h"

View File

@@ -23,7 +23,6 @@
#include <my_global.h>
#include <my_sys.h>
#include <my_atomic.h>
#include <lf.h>
#include "../tablockman.h"

View File

@@ -17,7 +17,6 @@
#include <my_global.h>
#include <my_sys.h>
#include <my_atomic.h>
#include <lf.h>
#include <m_string.h>
#include "../trnman.h"

View File

@@ -27,7 +27,6 @@
#include "sql_plugin.h"
#include "my_pthread.h"
#include "my_atomic.h"
#include "ha_perfschema.h"
#include "pfs_engine_table.h"
#include "pfs_column_values.h"

View File

@@ -16,7 +16,6 @@
#include <my_global.h>
#include <my_sys.h>
#include <my_atomic.h>
#include <tap.h>
volatile uint32 bad;