From 4eb8e51c269eb9447d3765a6e4deba0dc68dfa37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Wed, 30 Nov 2022 13:10:52 +0200 Subject: Merge 10.4 into 10.5 --- sql/handler.cc | 2 +- sql/slave.cc | 6 +++--- sql/sql_const.h | 2 +- sql/sql_delete.cc | 4 ++++ sql/sql_parse.cc | 4 +++- sql/table.cc | 1 + sql/wsrep_mysqld.cc | 16 +++++++++++++++- sql/wsrep_mysqld.h | 1 + sql/wsrep_thd.cc | 3 +-- sql/wsrep_var.cc | 9 ++++++++- 10 files changed, 38 insertions(+), 10 deletions(-) (limited to 'sql') diff --git a/sql/handler.cc b/sql/handler.cc index 5942eca6698..49f49002eff 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -4211,7 +4211,7 @@ void handler::print_error(int error, myf errflag) break; case HA_ERR_AUTOINC_ERANGE: textno= error; - my_error(textno, errflag, table->next_number_field->field_name.str, + my_error(textno, errflag, table->found_next_number_field->field_name.str, table->in_use->get_stmt_da()->current_row_for_warning()); DBUG_VOID_RETURN; break; diff --git a/sql/slave.cc b/sql/slave.cc index 33a382edc47..715fa8cd69e 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -7281,9 +7281,9 @@ static int connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi, mi->ssl_ca[0]?mi->ssl_ca:0, mi->ssl_capath[0]?mi->ssl_capath:0, mi->ssl_cipher[0]?mi->ssl_cipher:0); - mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, - &mi->ssl_verify_server_cert); - mysql_options(mysql, MYSQL_OPT_SSL_CRLPATH, + mysql_options(mysql, MYSQL_OPT_SSL_CRL, + mi->ssl_crl[0] ? mi->ssl_crl : 0); + mysql_options(mysql, MYSQL_OPT_SSL_CRLPATH, mi->ssl_crlpath[0] ? mi->ssl_crlpath : 0); mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &mi->ssl_verify_server_cert); diff --git a/sql/sql_const.h b/sql/sql_const.h index 3f053a1606d..b2548b4ef8c 100644 --- a/sql/sql_const.h +++ b/sql/sql_const.h @@ -29,7 +29,7 @@ /* extra 4+4 bytes for slave tmp tables */ #define MAX_DBKEY_LENGTH (NAME_LEN*2+1+1+4+4) #define MAX_ALIAS_NAME 256 -#define MAX_FIELD_NAME 34 /* Max colum name length +2 */ +#define MAX_FIELD_NAME (NAME_LEN+1) /* Max colum name length +1 */ #define MAX_SYS_VAR_LENGTH 32 #define MAX_KEY MAX_INDEXES /* Max used keys */ #define MAX_REF_PARTS 32 /* Max parts used as ref */ diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 4c359955dbe..e628ce60d2d 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -693,6 +693,10 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, { table->use_all_columns(); table->rpl_write_set= table->write_set; + // Initialize autoinc. + // We don't set next_number_field here, as it is handled manually. + if (table->found_next_number_field) + table->file->info(HA_STATUS_AUTO); } else { diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index faaab33a589..64be8f937e5 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1158,7 +1158,7 @@ static bool wsrep_tables_accessible_when_detached(const TABLE_LIST *tables) if (get_table_category(&db, &tn) < TABLE_CATEGORY_INFORMATION) return false; } - return true; + return tables != NULL; } static bool wsrep_command_no_result(char command) @@ -3758,6 +3758,8 @@ mysql_execute_command(THD *thd) (sql_command_flags[lex->sql_command] & CF_CHANGES_DATA) == 0) && !wsrep_tables_accessible_when_detached(all_tables) && lex->sql_command != SQLCOM_SET_OPTION && + lex->sql_command != SQLCOM_CHANGE_DB && + !(lex->sql_command == SQLCOM_SELECT && !all_tables) && !wsrep_is_show_query(lex->sql_command)) { my_message(ER_UNKNOWN_COM_ERROR, diff --git a/sql/table.cc b/sql/table.cc index c99608c6cde..7da22a058ab 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -8913,6 +8913,7 @@ int TABLE::update_generated_fields() res= found_next_number_field->set_default(); if (likely(!res)) res= file->update_auto_increment(); + next_number_field= NULL; } if (likely(!res) && vfield) diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index 3e3b7ec5150..3205b2dfa21 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -127,6 +127,7 @@ ulong wsrep_trx_fragment_unit= WSREP_FRAG_BYTES; ulong wsrep_SR_store_type= WSREP_SR_STORE_TABLE; uint wsrep_ignore_apply_errors= 0; +std::atomic wsrep_thread_create_failed; /* * End configuration options @@ -3143,7 +3144,7 @@ int wsrep_create_trigger_query(THD *thd, uchar** buf, size_t* buf_len) void* start_wsrep_THD(void *arg) { - THD *thd; + THD *thd= NULL; Wsrep_thd_args* thd_args= (Wsrep_thd_args*) arg; @@ -3174,6 +3175,7 @@ void* start_wsrep_THD(void *arg) mysql_thread_set_psi_id(thd->thread_id); thd->thr_create_utime= microsecond_interval_timer(); + DBUG_EXECUTE_IF("wsrep_simulate_failed_connection_1", goto error; ); // /* handle_one_connection() is normally the only way a thread would @@ -3280,6 +3282,18 @@ void* start_wsrep_THD(void *arg) error: WSREP_ERROR("Failed to create/initialize system thread"); + if (thd) + { + close_connection(thd, ER_OUT_OF_RESOURCES); + statistic_increment(aborted_connects, &LOCK_status); + server_threads.erase(thd); + delete thd; + my_thread_end(); + } + delete thd_args; + // This will signal error to wsrep_slave_threads_update + wsrep_thread_create_failed.store(true, std::memory_order_relaxed); + /* Abort if its the first applier/rollbacker thread. */ if (!mysqld_server_initialized) unireg_abort(1); diff --git a/sql/wsrep_mysqld.h b/sql/wsrep_mysqld.h index 2437a823df4..2061802afbd 100644 --- a/sql/wsrep_mysqld.h +++ b/sql/wsrep_mysqld.h @@ -90,6 +90,7 @@ extern bool wsrep_new_cluster; extern bool wsrep_gtid_mode; extern my_bool wsrep_strict_ddl; extern uint32 wsrep_gtid_domain_id; +extern std::atomic wsrep_thread_create_failed; enum enum_wsrep_reject_types { WSREP_REJECT_NONE, /* nothing rejected */ diff --git a/sql/wsrep_thd.cc b/sql/wsrep_thd.cc index 915c7bbb5a5..fbca4a76b66 100644 --- a/sql/wsrep_thd.cc +++ b/sql/wsrep_thd.cc @@ -23,8 +23,7 @@ #include "rpl_rli.h" #include "log_event.h" #include "sql_parse.h" -#include "mysqld.h" // start_wsrep_THD(); -#include "wsrep_applier.h" // start_wsrep_THD(); +#include "wsrep_mysqld.h" // start_wsrep_THD(); #include "mysql/service_wsrep.h" #include "debug_sync.h" #include "slave.h" diff --git a/sql/wsrep_var.cc b/sql/wsrep_var.cc index ff687975d0a..f6a7e25b945 100644 --- a/sql/wsrep_var.cc +++ b/sql/wsrep_var.cc @@ -801,18 +801,25 @@ bool wsrep_slave_threads_update (sys_var *self, THD* thd, enum_var_type type) if (wsrep_slave_count_change > 0) { WSREP_DEBUG("Creating %d applier threads, total %ld", wsrep_slave_count_change, wsrep_slave_threads); + wsrep_thread_create_failed.store(false, std::memory_order_relaxed); res= wsrep_create_appliers(wsrep_slave_count_change, true); mysql_mutex_unlock(&LOCK_global_system_variables); mysql_mutex_unlock(&LOCK_wsrep_slave_threads); // Thread creation and execution is asyncronous, therefore we need // wait them to be started or error produced - while (wsrep_running_applier_threads != (ulong)wsrep_slave_threads) + while (wsrep_running_applier_threads != (ulong)wsrep_slave_threads && + !wsrep_thread_create_failed.load(std::memory_order_relaxed)) { my_sleep(1000); } mysql_mutex_lock(&LOCK_global_system_variables); + if (wsrep_thread_create_failed.load(std::memory_order_relaxed)) { + wsrep_slave_threads= wsrep_running_applier_threads; + return true; + } + WSREP_DEBUG("Running %lu applier threads", wsrep_running_applier_threads); wsrep_slave_count_change = 0; } -- cgit v1.2.1 From 072b3668ca6ef3c32817536e3f9f922f8cda6175 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 29 Nov 2022 15:19:37 +1100 Subject: MDEV-28206: SIGSEGV in Item_field::fix_fields when using LEAD...OVER thd->lex->in_sum_func->max_arg_level cannot be set to a bigger value of select->nest_level if select is null. --- sql/item.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'sql') diff --git a/sql/item.cc b/sql/item.cc index 91bc175ca13..a63ac1f1119 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -6114,6 +6114,7 @@ bool Item_field::fix_fields(THD *thd, Item **reference) if (!thd->lex->current_select->no_wrap_view_item && thd->lex->in_sum_func && + select && thd->lex == select->parent_lex && thd->lex->in_sum_func->nest_level == select->nest_level) -- cgit v1.2.1 From e0dbec1ce38688e25cab3720044d6e7e676381f6 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 2 Dec 2022 18:21:52 +0300 Subject: MDEV-29129: Performance regression starting in 10.6: select order by limit ... The cause of regression was handling for ROWNUM() function. For queries like SELECT ROWNUM() FROM ... ORDER BY ... ROWNUM() should be computed before the ORDER BY. The computation was moved to be before the ORDER BY for any entries in the select list that had RAND_TABLE_BIT set. This had a negative impact on queries in form: SELECT sp_func() FROM t1 ORDER BY ... LIMIT n where sp_func() is NOT declared as DETERMINISTIC (and so has RAND_TABLE_BIT set). The fix is to require evaluation for sorting only for the ROWNUM() function. Functions that just have RAND_TABLE_BIT() can be computed after ORDER BY ... LIMIT is applied. (think about a possible index that satisfies the ORDER BY clause. In that case, the the rows would be read in the needed order and we would stop after reading LIMIT rows, achieving the same effect). --- sql/sql_base.cc | 2 ++ sql/sql_lex.cc | 2 ++ sql/sql_lex.h | 3 +++ sql/sql_select.cc | 4 +--- sql/sql_select.h | 5 ----- 5 files changed, 8 insertions(+), 8 deletions(-) (limited to 'sql') diff --git a/sql/sql_base.cc b/sql/sql_base.cc index dfca2500d6d..5de9782fd09 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -7738,6 +7738,8 @@ bool setup_fields(THD *thd, Ref_ptr_array ref_pointer_array, thd->lex->current_select->select_list_tables|= item->used_tables(); thd->lex->used_tables|= item->used_tables(); thd->lex->current_select->cur_pos_in_select_list++; + + thd->lex->current_select->rownum_in_field_list |= item->with_rownum_func(); } thd->lex->current_select->is_item_list_lookup= save_is_item_list_lookup; thd->lex->current_select->cur_pos_in_select_list= UNDEF_POS; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 520982f93b6..b743141598f 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -3002,6 +3002,8 @@ void st_select_lex::init_query() prep_leaf_list_state= UNINIT; bzero((char*) expr_cache_may_be_used, sizeof(expr_cache_may_be_used)); select_list_tables= 0; + rownum_in_field_list= 0; + window_specs.empty(); window_funcs.empty(); tvc= 0; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index e4fe1465c57..82453ad8259 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1344,6 +1344,9 @@ public: */ table_map select_list_tables; + /* Set to 1 if any field in field list has ROWNUM() */ + bool rownum_in_field_list; + /* namp of nesting SELECT visibility (for aggregate functions check) */ nesting_map name_visibility_map; table_map with_dep; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 60b2641e670..446f6e83b0d 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -434,7 +434,6 @@ void JOIN::init(THD *thd_arg, List &fields_arg, no_order= 0; simple_order= 0; simple_group= 0; - rand_table_in_field_list= 0; ordered_index_usage= ordered_index_void; need_distinct= 0; skip_sort_order= 0; @@ -1434,7 +1433,6 @@ JOIN::prepare(TABLE_LIST *tables_init, COND *conds_init, uint og_num, &all_fields, &select_lex->pre_fix, 1)) DBUG_RETURN(-1); thd->lex->current_select->context_analysis_place= save_place; - rand_table_in_field_list= select_lex->select_list_tables & RAND_TABLE_BIT; if (setup_without_group(thd, ref_ptrs, tables_list, select_lex->leaf_tables, fields_list, @@ -14807,7 +14805,7 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond, and some wrong results so better to leave the code as it was related to ROLLUP. */ - *simple_order= !join->rand_table_in_field_list; + *simple_order= !join->select_lex->rownum_in_field_list; if (join->only_const_tables()) return change_list ? 0 : first_order; // No need to sort diff --git a/sql/sql_select.h b/sql/sql_select.h index c9e0fa25421..3332bc78b6c 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1420,11 +1420,6 @@ public: GROUP/ORDER BY. */ bool simple_order, simple_group; - /* - Set to 1 if any field in field list has RAND_TABLE set. For example if - if one uses RAND() or ROWNUM() in field list - */ - bool rand_table_in_field_list; /* ordered_index_usage is set if an ordered index access -- cgit v1.2.1