diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/filesort.cc | 1 | ||||
-rw-r--r-- | sql/ha_partition.cc | 5 | ||||
-rw-r--r-- | sql/ha_sequence.cc | 2 | ||||
-rw-r--r-- | sql/handler.h | 4 | ||||
-rw-r--r-- | sql/item.cc | 4 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 2 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 2 | ||||
-rw-r--r-- | sql/lex.h | 2 | ||||
-rw-r--r-- | sql/log_event.h | 5 | ||||
-rw-r--r-- | sql/log_event_old.cc | 4 | ||||
-rw-r--r-- | sql/mysql_upgrade_service.cc | 2 | ||||
-rw-r--r-- | sql/mysqld.cc | 4 | ||||
-rw-r--r-- | sql/opt_subselect.cc | 2 | ||||
-rw-r--r-- | sql/rpl_mi.cc | 2 | ||||
-rw-r--r-- | sql/session_tracker.cc | 4 | ||||
-rw-r--r-- | sql/share/errmsg-utf8.txt | 4 | ||||
-rw-r--r-- | sql/slave.cc | 38 | ||||
-rw-r--r-- | sql/sp_head.cc | 6 | ||||
-rw-r--r-- | sql/sql_admin.cc | 2 | ||||
-rw-r--r-- | sql/sql_db.cc | 4 | ||||
-rw-r--r-- | sql/sql_delete.cc | 2 | ||||
-rw-r--r-- | sql/sql_derived.cc | 9 | ||||
-rw-r--r-- | sql/sql_insert.cc | 81 | ||||
-rw-r--r-- | sql/sql_join_cache.cc | 2 | ||||
-rw-r--r-- | sql/sql_repl.cc | 4 | ||||
-rw-r--r-- | sql/sql_select.cc | 19 | ||||
-rw-r--r-- | sql/sql_sequence.cc | 7 | ||||
-rw-r--r-- | sql/sql_servers.cc | 4 | ||||
-rw-r--r-- | sql/sql_show.cc | 3 | ||||
-rw-r--r-- | sql/sql_update.cc | 2 | ||||
-rw-r--r-- | sql/sys_vars.cc | 2 | ||||
-rw-r--r-- | sql/table.h | 6 | ||||
-rw-r--r-- | sql/threadpool_common.cc | 2 | ||||
-rw-r--r-- | sql/wsrep_mysqld.cc | 34 |
34 files changed, 223 insertions, 53 deletions
diff --git a/sql/filesort.cc b/sql/filesort.cc index 3f4291cfb1f..2e06905a48e 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -309,6 +309,7 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort, param.max_keys_per_buffer=((param.max_keys_per_buffer * (param.rec_length + sizeof(char*))) / param.rec_length - 1); + set_if_bigger(param.max_keys_per_buffer, 1); maxbuffer--; // Offset from 0 if (merge_many_buff(¶m, (uchar*) sort->get_sort_keys(), diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index c9e12f861af..f6a6dfda6e3 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -564,7 +564,7 @@ bool ha_partition::initialize_partition(MEM_ROOT *mem_root) point. If you do not implement this, the default delete_table() is called from - handler.cc and it will delete all files with the file extentions returned + handler.cc and it will delete all files with the file extensions returned by bas_ext(). Called from handler.cc by delete_table and ha_create_table(). Only used @@ -596,7 +596,7 @@ int ha_partition::delete_table(const char *name) Renames a table from one name to another from alter table call. If you do not implement this, the default rename_table() is called from - handler.cc and it will rename all files with the file extentions returned + handler.cc and it will rename all files with the file extensions returned by bas_ext(). Called from sql_table.cc by mysql_rename_table(). @@ -9265,7 +9265,6 @@ void ha_partition::late_extra_cache(uint partition_id) } if (m_extra_prepare_for_update) { - DBUG_ASSERT(m_extra_cache); (void) file->extra(HA_EXTRA_PREPARE_FOR_UPDATE); } m_extra_cache_part_id= partition_id; diff --git a/sql/ha_sequence.cc b/sql/ha_sequence.cc index beaed6ef7df..22a92c70425 100644 --- a/sql/ha_sequence.cc +++ b/sql/ha_sequence.cc @@ -108,7 +108,7 @@ int ha_sequence::open(const char *name, int mode, uint flags) MY_TEST(flags & HA_OPEN_INTERNAL_TABLE); reset_statistics(); - /* Don't try to read the inital row the call is part of create code */ + /* Don't try to read the initial row the call is part of create code */ if (!(flags & (HA_OPEN_FOR_CREATE | HA_OPEN_FOR_REPAIR))) { if (unlikely((error= table->s->sequence->read_initial_values(table)))) diff --git a/sql/handler.h b/sql/handler.h index bbceb58cb0c..6d675683ada 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1522,9 +1522,9 @@ struct handlerton Used by open_table_error(), by the default rename_table and delete_table handler methods, and by the default discovery implementation. - For engines that have more than one file name extentions (separate + For engines that have more than one file name extensions (separate metadata, index, and/or data files), the order of elements is relevant. - First element of engine file name extentions array should be metadata + First element of engine file name extensions array should be metadata file extention. This is implied by the open_table_error() and the default discovery implementation. diff --git a/sql/item.cc b/sql/item.cc index 900a973071b..925d44a481f 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -2570,7 +2570,7 @@ bool Type_std_attributes::agg_item_set_converter(const DTCollation &coll, @retval clone of the item - 0 if an error occured + 0 if an error occurred */ Item* Item_func_or_sum::build_clone(THD *thd) @@ -2870,7 +2870,7 @@ Item_sp::init_result_field(THD *thd, uint max_length, uint maybe_null, @retval clone of the item - 0 if an error occured + 0 if an error occurred */ Item* Item_ref::build_clone(THD *thd) diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 9110f348a43..7a1d721ca48 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -5201,7 +5201,7 @@ void Item_cond::neg_arguments(THD *thd) @retval clone of the item - 0 if an error occured + 0 if an error occurred */ Item *Item_cond::build_clone(THD *thd) diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 32f05a815db..d31f47e68fd 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2402,7 +2402,7 @@ String *Item_func_sqlerrm::val_str(String *str) system_charset_info); return str; } - str->copy(STRING_WITH_LEN("normal, successful completition"), + str->copy(STRING_WITH_LEN("normal, successful completion"), system_charset_info); return str; } diff --git a/sql/lex.h b/sql/lex.h index ec657ff48df..92ce01a1094 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -23,7 +23,7 @@ #include "lex_symbol.h" SYM_GROUP sym_group_common= {"", ""}; -SYM_GROUP sym_group_geom= {"Spatial extentions", "HAVE_SPATIAL"}; +SYM_GROUP sym_group_geom= {"Spatial extensions", "HAVE_SPATIAL"}; SYM_GROUP sym_group_rtree= {"RTree keys", "HAVE_RTREE_KEYS"}; /* We don't want to include sql_yacc.h into gen_lex_hash */ diff --git a/sql/log_event.h b/sql/log_event.h index 274182af841..df058469225 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -3621,7 +3621,7 @@ public: bool write_data_header(); bool write_data_body(); /* - Cut out Create_file extentions and + Cut out Create_file extensions and write it as Load event - used on the slave */ bool write_base(); @@ -5242,6 +5242,9 @@ bool event_that_should_be_ignored(const char *buf); bool event_checksum_test(uchar *buf, ulong event_len, enum_binlog_checksum_alg alg); enum enum_binlog_checksum_alg get_checksum_alg(const char* buf, ulong len); extern TYPELIB binlog_checksum_typelib; +#ifdef WITH_WSREP +enum Log_event_type wsrep_peak_event(rpl_group_info *rgi, ulonglong* event_size); +#endif /* WITH_WSREP */ /** @} (end of group Replication) diff --git a/sql/log_event_old.cc b/sql/log_event_old.cc index 829a278f215..e01488abbb3 100644 --- a/sql/log_event_old.cc +++ b/sql/log_event_old.cc @@ -835,7 +835,7 @@ int Write_rows_log_event_old::do_after_row_operations(TABLE *table, int error) table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE); /* - reseting the extra with + resetting the extra with table->file->extra(HA_EXTRA_NO_IGNORE_NO_KEY); fires bug#27077 todo: explain or fix @@ -2459,7 +2459,7 @@ Write_rows_log_event_old::do_after_row_operations(const Slave_reporting_capabili m_table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); m_table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE); /* - reseting the extra with + resetting the extra with table->file->extra(HA_EXTRA_NO_IGNORE_NO_KEY); fires bug#27077 todo: explain or fix diff --git a/sql/mysql_upgrade_service.cc b/sql/mysql_upgrade_service.cc index 05e2e970e6c..a10b5bb5162 100644 --- a/sql/mysql_upgrade_service.cc +++ b/sql/mysql_upgrade_service.cc @@ -134,7 +134,7 @@ static void die(const char *fmt, ...) } /* - Stop service that we started, if it was not initally running at + Stop service that we started, if it was not initially running at program start. */ if (initial_service_state != UINT_MAX && initial_service_state != SERVICE_RUNNING) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index e1a7a39df89..96f4dd1095b 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -7988,8 +7988,8 @@ static void usage(void) "\nbecause execution stopped before plugins were initialized."); } - puts("\nTo see what values a running MySQL server is using, type" - "\n'mysqladmin variables' instead of 'mysqld --verbose --help'."); + puts("\nTo see what variables a running MySQL server is using, type" + "\n'mysqladmin variables' instead of 'mysqld --verbose --help'."); } DBUG_VOID_RETURN; } diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index ededfc88988..961bbdaabc8 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -4577,7 +4577,7 @@ SJ_TMP_TABLE::create_sj_weedout_tmp_table(THD *thd) field->reset(); /* Test if there is a default field value. The test for ->ptr is to skip - 'offset' fields generated by initalize_tables + 'offset' fields generated by initialize_tables */ // Initialize the table field: bzero(field->ptr, field->pack_length()); diff --git a/sql/rpl_mi.cc b/sql/rpl_mi.cc index 732edcd5bc6..43a02147496 100644 --- a/sql/rpl_mi.cc +++ b/sql/rpl_mi.cc @@ -1173,7 +1173,7 @@ bool Master_info_index::init_all_master_info() } else { - /* Initialization of Master_info succeded. Add it to HASH */ + /* Initialization of Master_info succeeded. Add it to HASH */ if (global_system_variables.log_warnings > 1) sql_print_information("Initialized Master_info from '%s'", buf_master_info_file); diff --git a/sql/session_tracker.cc b/sql/session_tracker.cc index 5ba0c73e042..e6c380fcb5c 100644 --- a/sql/session_tracker.cc +++ b/sql/session_tracker.cc @@ -814,7 +814,7 @@ bool Transaction_state_tracker::store(THD *thd, String *buf) statement even for a transaction that isn't the first in an ongoing chain. Consider - SET TRANSACTION ISOLATION LEVEL READ UNCOMMITED; + SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; START TRANSACTION READ ONLY, WITH CONSISTENT SNAPSHOT; # work COMMIT AND CHAIN; @@ -822,7 +822,7 @@ bool Transaction_state_tracker::store(THD *thd, String *buf) If we switch away at this point, the replay in the new session needs to be - SET TRANSACTION ISOLATION LEVEL READ UNCOMMITED; + SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; START TRANSACTION READ ONLY; When a transaction ends (COMMIT/ROLLBACK sans CHAIN), all diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 03bd72c41b0..cc635e44f7b 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -7457,7 +7457,7 @@ ER_GIS_UNSUPPORTED_ARGUMENT eng "Calling geometry function %s with unsupported types of arguments." ER_GIS_UNKNOWN_ERROR - eng "Unknown GIS error occured in function %s." + eng "Unknown GIS error occurred in function %s." ER_GIS_UNKNOWN_EXCEPTION eng "Unknown exception caught in GIS function %s." @@ -7871,7 +7871,7 @@ ER_DROP_VERSIONING_SYSTEM_TIME_PARTITION eng "Can not DROP SYSTEM VERSIONING for table %`s partitioned BY SYSTEM_TIME" ER_VERS_DB_NOT_SUPPORTED - eng "System-versioned tables in the %`s database are not suported" + eng "System-versioned tables in the %`s database are not supported" ER_VERS_TRT_IS_DISABLED eng "Transaction registry is disabled" diff --git a/sql/slave.cc b/sql/slave.cc index 1ed701c75a2..d39e17baadc 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -485,6 +485,9 @@ handle_slave_background(void *arg __attribute__((unused))) thd->store_globals(); thd->security_ctx->skip_grants(); thd->set_command(COM_DAEMON); +#ifdef WITH_WSREP + thd->variables.wsrep_on= 0; +#endif thd_proc_info(thd, "Loading slave GTID position from table"); if (rpl_load_gtid_slave_state(thd)) @@ -4727,6 +4730,9 @@ pthread_handler_t handle_slave_io(void *arg) } +#ifdef WITH_WSREP + thd->variables.wsrep_on= 0; +#endif if (DBUG_EVALUATE_IF("failed_slave_start", 1, 0) || repl_semisync_slave.slave_start(mi)) { @@ -7922,7 +7928,39 @@ err: sql_print_error("Error reading relay log event: %s", errmsg); DBUG_RETURN(0); } +#ifdef WITH_WSREP +enum Log_event_type wsrep_peak_event(rpl_group_info *rgi, ulonglong* event_size) +{ + enum Log_event_type ev_type; + + mysql_mutex_lock(&rgi->rli->data_lock); + + unsigned long long event_pos= rgi->event_relay_log_pos; + unsigned long long orig_future_pos= rgi->future_event_relay_log_pos; + unsigned long long future_pos= rgi->future_event_relay_log_pos; + + /* scan the log to read next event and we skip + annotate events. */ + do { + my_b_seek(rgi->rli->cur_log, future_pos); + rgi->rli->event_relay_log_pos= future_pos; + rgi->event_relay_log_pos= future_pos; + Log_event* ev= next_event(rgi, event_size); + ev_type= (ev) ? ev->get_type_code() : UNKNOWN_EVENT; + delete ev; + future_pos+= *event_size; + } while (ev_type == ANNOTATE_ROWS_EVENT || ev_type == XID_EVENT); + + /* scan the log back and re-set the positions to original values */ + rgi->rli->event_relay_log_pos= event_pos; + rgi->event_relay_log_pos= event_pos; + my_b_seek(rgi->rli->cur_log, orig_future_pos); + + mysql_mutex_unlock(&rgi->rli->data_lock); + return ev_type; +} +#endif /* WITH_WSREP */ /* Rotate a relay log (this is used only by FLUSH LOGS; the automatic rotation because of size is simpler because when we do it we already have all relevant diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 9581ded8a12..8631d800001 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -3453,11 +3453,7 @@ sp_lex_keeper::reset_lex_and_exec_core(THD *thd, uint *nextp, Update the state of the active arena if no errors on open_tables stage. */ - if (likely(!res) || likely(!thd->is_error()) || - (thd->get_stmt_da()->sql_errno() != ER_CANT_REOPEN_TABLE && - thd->get_stmt_da()->sql_errno() != ER_NO_SUCH_TABLE && - thd->get_stmt_da()->sql_errno() != ER_NO_SUCH_TABLE_IN_ENGINE && - thd->get_stmt_da()->sql_errno() != ER_UPDATE_TABLE_USED)) + if (likely(!res) || likely(!thd->is_error())) thd->stmt_arena->state= Query_arena::STMT_EXECUTED; /* diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc index 3b15c5a505e..6fdbc14a372 100644 --- a/sql/sql_admin.cc +++ b/sql/sql_admin.cc @@ -175,7 +175,7 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list, /* Check if this is a table type that stores index and data separately, like ISAM or MyISAM. We assume fixed order of engine file name - extentions array. First element of engine file name extentions array + extensions array. First element of engine file name extensions array is meta/index file extention. Second element - data file extention. */ ext= table->file->bas_ext(); diff --git a/sql/sql_db.cc b/sql/sql_db.cc index ddc5234fa01..b2b591464f7 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -50,7 +50,7 @@ #define MAX_DROP_TABLE_Q_LEN 1024 const char *del_exts[]= {".BAK", ".opt", NullS}; -static TYPELIB deletable_extentions= +static TYPELIB deletable_extensions= {array_elements(del_exts)-1,"del_exts", del_exts, NULL}; static bool find_db_tables_and_rm_known_files(THD *, MY_DIR *, const char *, @@ -1140,7 +1140,7 @@ static bool find_db_tables_and_rm_known_files(THD *thd, MY_DIR *dirp, } if (!(extension= strrchr(file->name, '.'))) extension= strend(file->name); - if (find_type(extension, &deletable_extentions, FIND_TYPE_NO_PREFIX) > 0) + if (find_type(extension, &deletable_extensions, FIND_TYPE_NO_PREFIX) > 0) { strxmov(filePath, path, "/", file->name, NullS); /* diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 622b24292f3..f4cad88124f 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -1027,7 +1027,7 @@ int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, DBUG_ASSERT(table_list->table); // conds could be cached from previous SP call - DBUG_ASSERT(!table_list->vers_conditions.is_set() || + DBUG_ASSERT(!table_list->vers_conditions.need_setup() || !*conds || thd->stmt_arena->is_stmt_execute()); if (select_lex->vers_setup_conds(thd, table_list)) DBUG_RETURN(TRUE); diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 3f955c16eb3..8396fd89433 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -741,8 +741,15 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) case SQLCOM_DELETE_MULTI: case SQLCOM_UPDATE: case SQLCOM_UPDATE_MULTI: - if ((res= unit->prepare(derived, derived->derived_result, 0))) + if ((res= first_select->vers_setup_conds(thd, + derived->merge_underlying_list))) goto exit; + if (derived->merge_underlying_list->where) + { + Query_arena_stmt on_stmt_arena(thd); + derived->where= and_items(thd, derived->where, + derived->merge_underlying_list->where); + } default: break; } diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index ad552928e7c..c8f4ac05efc 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2137,11 +2137,15 @@ public: ulong auto_increment_offset; LEX_STRING query; Time_zone *time_zone; + char *user, *host, *ip; + query_id_t query_id; + my_thread_id thread_id; delayed_row(LEX_STRING const query_arg, enum_duplicates dup_arg, bool ignore_arg, bool log_query_arg) : record(0), dup(dup_arg), ignore(ignore_arg), log_query(log_query_arg), - forced_insert_id(0), query(query_arg), time_zone(0) + forced_insert_id(0), query(query_arg), time_zone(0), + user(0), host(0), ip(0) {} ~delayed_row() { @@ -2189,6 +2193,27 @@ public: passed from connection thread to the handler thread. */ MDL_request grl_protection; + my_thread_id orig_thread_id; + void set_default_user() + { + thd.security_ctx->user=(char*) delayed_user; + thd.security_ctx->host=(char*) my_localhost; + thd.security_ctx->ip= NULL; + thd.query_id= 0; + thd.thread_id= orig_thread_id; + } + + void set_user_from_row(const delayed_row *r) + { + if (r) + { + thd.security_ctx->user= r->user; + thd.security_ctx->host= r->host; + thd.security_ctx->ip= r->ip; + thd.query_id= r->query_id; + thd.thread_id= r->thread_id; + } + } Delayed_insert(SELECT_LEX *current_select) :locks_in_memory(0), thd(next_thread_id()), @@ -2196,8 +2221,8 @@ public: status(0), retry(0), handler_thread_initialized(FALSE), group_count(0) { DBUG_ENTER("Delayed_insert constructor"); - thd.security_ctx->user=(char*) delayed_user; - thd.security_ctx->host=(char*) my_localhost; + orig_thread_id= thd.thread_id; + set_default_user(); strmake_buf(thd.security_ctx->priv_user, thd.security_ctx->user); thd.current_tablenr=0; thd.set_command(COM_DELAYED_INSERT); @@ -2693,6 +2718,7 @@ int write_delayed(THD *thd, TABLE *table, enum_duplicates duplic, delayed_row *row= 0; Delayed_insert *di=thd->di; const Discrete_interval *forced_auto_inc; + size_t user_len, host_len, ip_len; DBUG_ENTER("write_delayed"); DBUG_PRINT("enter", ("query = '%s' length %lu", query.str, (ulong) query.length)); @@ -2726,11 +2752,45 @@ int write_delayed(THD *thd, TABLE *table, enum_duplicates duplic, goto err; } + user_len= host_len= ip_len= 0; + row->user= row->host= row->ip= NULL; + if (thd->security_ctx) + { + if (thd->security_ctx->user) + user_len= strlen(thd->security_ctx->user) + 1; + if (thd->security_ctx->host) + host_len= strlen(thd->security_ctx->host) + 1; + if (thd->security_ctx->ip) + ip_len= strlen(thd->security_ctx->ip) + 1; + } /* This can't be THREAD_SPECIFIC as it's freed in delayed thread */ - if (!(row->record= (char*) my_malloc(table->s->reclength, + if (!(row->record= (char*) my_malloc(table->s->reclength + + user_len + host_len + ip_len, MYF(MY_WME)))) goto err; memcpy(row->record, table->record[0], table->s->reclength); + + if (thd->security_ctx) + { + if (thd->security_ctx->user) + { + row->user= row->record + table->s->reclength; + memcpy(row->user, thd->security_ctx->user, user_len); + } + if (thd->security_ctx->host) + { + row->host= row->record + table->s->reclength + user_len; + memcpy(row->host, thd->security_ctx->host, host_len); + } + if (thd->security_ctx->ip) + { + row->ip= row->record + table->s->reclength + user_len + host_len; + memcpy(row->ip, thd->security_ctx->ip, ip_len); + } + } + row->query_id= thd->query_id; + row->thread_id= thd->thread_id; + row->start_time= thd->start_time; row->start_time_sec_part= thd->start_time_sec_part; row->query_start_sec_part_used= thd->query_start_sec_part_used; @@ -3148,6 +3208,7 @@ pthread_handler_t handle_delayed_insert(void *arg) if (di->tables_in_use && ! thd->lock && (!thd->killed || di->stacked_inserts)) { + di->set_user_from_row(di->rows.head()); /* Request for new delayed insert. Lock the table, but avoid to be blocked by a global read lock. @@ -3167,6 +3228,18 @@ pthread_handler_t handle_delayed_insert(void *arg) } if (di->stacked_inserts) { + delayed_row *row; + I_List_iterator<delayed_row> it(di->rows); + while ((row= it++)) + { + if (di->thd.thread_id != row->thread_id) + { + di->set_user_from_row(row); + mysql_audit_external_lock(&di->thd, di->table->s, F_WRLCK); + } + } + di->set_default_user(); + if (di->handle_inserts()) { /* Some fatal error */ diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index 3b051259ad6..3a509b3d750 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -2141,7 +2141,7 @@ enum_nested_loop_state JOIN_CACHE::join_records(bool skip_last) DBUG_ASSERT(!is_key_access()); /* Restore the last record from the join buffer to generate - all extentions for it. + all extensions for it. */ get_record(); } diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 9f7413241b6..202cfaa9ea7 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -3344,7 +3344,7 @@ int reset_slave(THD *thd, Master_info* mi) char fname[FN_REFLEN]; int thread_mask= 0, error= 0; uint sql_errno=ER_UNKNOWN_ERROR; - const char* errmsg= "Unknown error occurred while reseting slave"; + const char* errmsg= "Unknown error occurred while resetting slave"; char master_info_file_tmp[FN_REFLEN]; char relay_log_info_file_tmp[FN_REFLEN]; DBUG_ENTER("reset_slave"); @@ -3951,7 +3951,7 @@ int reset_master(THD* thd, rpl_gtid *init_state, uint32 init_state_len, } #endif /* WITH_WSREP */ bool ret= 0; - /* Temporarily disable master semisync before reseting master. */ + /* Temporarily disable master semisync before resetting master. */ repl_semisync_master.before_reset_master(); ret= mysql_bin_log.reset_logs(thd, 1, init_state, init_state_len, next_log_number); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 337b1d5e02a..a685c948a3d 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1980,7 +1980,20 @@ JOIN::optimize_inner() } } - conds= optimize_cond(this, conds, join_list, FALSE, + bool ignore_on_expr= false; + /* + PS/SP note: on_expr of versioned table can not be reallocated + (see build_equal_items() below) because it can be not rebuilt + at second invocation. + */ + if (!thd->stmt_arena->is_conventional() && thd->mem_root != thd->stmt_arena->mem_root) + for (TABLE_LIST *tbl= tables_list; tbl; tbl= tbl->next_local) + if (tbl->table && tbl->on_expr && tbl->table->versioned()) + { + ignore_on_expr= true; + break; + } + conds= optimize_cond(this, conds, join_list, ignore_on_expr, &cond_value, &cond_equal, OPT_LINK_EQUAL_FIELDS); if (thd->is_error()) @@ -18488,7 +18501,7 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields, /* Test if there is a default field value. The test for ->ptr is to skip - 'offset' fields generated by initalize_tables + 'offset' fields generated by initialize_tables */ if (default_field[i] && default_field[i]->ptr) { @@ -21265,7 +21278,7 @@ join_read_last(JOIN_TAB *tab) { TABLE *table=tab->table; int error= 0; - DBUG_ENTER("join_read_first"); + DBUG_ENTER("join_read_last"); DBUG_ASSERT(table->no_keyread || !table->covering_keys.is_set(tab->index) || diff --git a/sql/sql_sequence.cc b/sql/sql_sequence.cc index 4e8624d6360..035fb1211e6 100644 --- a/sql/sql_sequence.cc +++ b/sql/sql_sequence.cc @@ -487,9 +487,12 @@ int SEQUENCE::read_initial_values(TABLE *table) Doing mysql_lock_tables() may have started a read only transaction. If that happend, it's better that we commit it now, as a lot of code assumes that there is no active stmt transaction directly after - open_tables() + open_tables(). + But we also don't want to commit the stmt transaction while in a + substatement, see MDEV-15977. */ - if (!has_active_transaction && !thd->transaction.stmt.is_empty()) + if (!has_active_transaction && !thd->transaction.stmt.is_empty() && + !thd->in_sub_stmt) trans_commit_stmt(thd); } write_unlock(table); diff --git a/sql/sql_servers.cc b/sql/sql_servers.cc index 8f0f08da075..7913a7d2b9f 100644 --- a/sql/sql_servers.cc +++ b/sql/sql_servers.cc @@ -431,7 +431,7 @@ insert_server_record_into_cache(FOREIGN_SERVER *server) int error=0; DBUG_ENTER("insert_server_record_into_cache"); /* - We succeded in insertion of the server to the table, now insert + We succeeded in insertion of the server to the table, now insert the server to the cache */ DBUG_PRINT("info", ("inserting server %s at %p, length %zd", @@ -686,7 +686,7 @@ delete_server_record_in_cache(LEX_SERVER_OPTIONS *server_options) goto end; } /* - We succeded in deletion of the server to the table, now delete + We succeeded in deletion of the server to the table, now delete the server from the cache */ DBUG_PRINT("info",("deleting server %s length %zd", diff --git a/sql/sql_show.cc b/sql/sql_show.cc index dcfcba0a01e..1cd43cc24ab 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1317,7 +1317,8 @@ mysqld_show_create_get_fields(THD *thd, TABLE_LIST *table_list, goto exit; } else if (lex->table_type == TABLE_TYPE_SEQUENCE && - table_list->table->s->table_type != TABLE_TYPE_SEQUENCE) + (!table_list->table || + table_list->table->s->table_type != TABLE_TYPE_SEQUENCE)) { my_error(ER_NOT_SEQUENCE, MYF(0), table_list->db.str, table_list->table_name.str); diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 8ecac25e162..af09675d917 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -1387,7 +1387,7 @@ bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list, DBUG_ASSERT(table_list->table); // conds could be cached from previous SP call - DBUG_ASSERT(!table_list->vers_conditions.is_set() || + DBUG_ASSERT(!table_list->vers_conditions.need_setup() || !*conds || thd->stmt_arena->is_stmt_execute()); if (select_lex->vers_setup_conds(thd, table_list)) DBUG_RETURN(TRUE); diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index f01757f6163..1c47f652f4c 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -6314,7 +6314,7 @@ static Sys_var_enum Sys_session_track_transaction_info( "Track changes to the transaction attributes. OFF to disable; " "STATE to track just transaction state (Is there an active transaction? " "Does it have any data? etc.); CHARACTERISTICS to track transaction " - "state and report all statements needed to start a transaction with" + "state and report all statements needed to start a transaction with " "the same characteristics (isolation level, read only/read write," "snapshot - but not any work done / data modified within the " "transaction).", diff --git a/sql/table.h b/sql/table.h index 458482315c3..cd9eaaf1e76 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1993,6 +1993,10 @@ struct vers_select_conds_t { return orig_type != SYSTEM_TIME_UNSPECIFIED; } + bool need_setup() const + { + return type != SYSTEM_TIME_UNSPECIFIED && type != SYSTEM_TIME_ALL; + } bool resolve_units(THD *thd); bool eq(const vers_select_conds_t &conds) const; }; @@ -3209,7 +3213,7 @@ public: @param[in] timestamp @param[in] true if we search for a lesser timestamp, false if greater - @retval true if exists, false it not exists or an error occured + @retval true if exists, false it not exists or an error occurred */ bool query(MYSQL_TIME &commit_time, bool backwards); /** diff --git a/sql/threadpool_common.cc b/sql/threadpool_common.cc index 6577472e20b..efcc56d67be 100644 --- a/sql/threadpool_common.cc +++ b/sql/threadpool_common.cc @@ -192,7 +192,7 @@ void tp_callback(TP_connection *c) } else if (threadpool_process_request(thd)) { - /* QUIT or an error occured. */ + /* QUIT or an error occurred. */ goto error; } diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index bef574e07b2..597055c48b1 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -46,7 +46,6 @@ #include <cstdlib> #include <string> #include "log_event.h" -#include <slave.h> #include <sstream> @@ -1646,6 +1645,39 @@ static bool wsrep_can_run_in_toi(THD *thd, const char *db, const char *table, { return false; } + /* + If mariadb master has replicated a CTAS, we should not replicate the create table + part separately as TOI, but to replicate both create table and following inserts + as one write set. + Howver, if CTAS creates empty table, we should replicate the create table alone + as TOI. We have to do relay log event lookup to see if row events follow the + create table event. + */ + if (thd->slave_thread && !(thd->rgi_slave->gtid_ev_flags2 & Gtid_log_event::FL_STANDALONE)) + { + /* this is CTAS, either empty or populated table */ + ulonglong event_size = 0; + enum Log_event_type ev_type= wsrep_peak_event(thd->rgi_slave, &event_size); + switch (ev_type) + { + case QUERY_EVENT: + /* CTAS with empty table, we replicate create table as TOI */ + break; + + case TABLE_MAP_EVENT: + WSREP_DEBUG("replicating CTAS of empty table as TOI"); + // fall through + case WRITE_ROWS_EVENT: + /* CTAS with populated table, we replicate later at commit time */ + WSREP_DEBUG("skipping create table of CTAS replication"); + return false; + + default: + WSREP_WARN("unexpected async replication event: %d", ev_type); + } + return true; + } + /* no next async replication event */ return true; case SQLCOM_CREATE_VIEW: |