From a441a569157bf75303e3f9f485211c4b5d4f6129 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Wed, 20 Oct 2021 19:53:49 +0300 Subject: Fix comment --- sql/sql_explain.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql') diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index ec58145bada..16d5daee5c7 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -1735,7 +1735,7 @@ void Explain_table_access::print_explain_json(Explain_query *query, /* - Elements in this array match members of enum Extra_tag, defined in + Elements in this array match members of enum explain_extra_tag, defined in sql_explain.h */ -- cgit v1.2.1 From d22c8cae00f7a7517c9b8228efbb543037c23c97 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 25 Oct 2021 10:48:24 +0200 Subject: compilation fixes for sys-devel/gcc-11.2.0:11 --- sql/item_timefunc.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'sql') diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index a40c2e18b91..fd5ab057b8b 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2832,7 +2832,6 @@ bool Item_func_timediff::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) DBUG_ASSERT(fixed == 1); int l_sign= 1; MYSQL_TIME l_time1,l_time2,l_time3; - ErrConvTime str(&l_time3); /* the following may be true in, for example, date_add(timediff(...), ... */ if (fuzzy_date & TIME_NO_ZERO_IN_DATE) -- cgit v1.2.1 From efedf3da68aa0c0a70e0686d9b92c9d0924df098 Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Wed, 20 Oct 2021 14:53:01 +0400 Subject: MDEV-22711 Assertion `nr != 0' failed in handler::update_auto_increment. DBUG_ASSERT removed as the AUTO INCREMENT can actually be 0 when the SET insert_id= 0; was done. --- sql/sys_vars.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'sql') diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index f231f49a667..bd4b2fbb062 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -4064,12 +4064,16 @@ static Sys_var_session_special Sys_identity( */ static bool update_insert_id(THD *thd, set_var *var) { - if (!var->value) - { - my_error(ER_NO_DEFAULT, MYF(0), var->var->name.str); - return true; - } - thd->force_one_auto_inc_interval(var->save_result.ulonglong_value); + /* + If we set the insert_id to the DEFAULT or 0 + it means we 'reset' it so it's value doesn't + affect the INSERT. + */ + if (!var->value || + var->save_result.ulonglong_value == 0) + thd->auto_inc_intervals_forced.empty(); + else + thd->force_one_auto_inc_interval(var->save_result.ulonglong_value); return false; } @@ -4077,6 +4081,8 @@ static ulonglong read_insert_id(THD *thd) { return thd->auto_inc_intervals_forced.minimum(); } + + static Sys_var_session_special Sys_insert_id( "insert_id", "The value to be used by the following INSERT " "or ALTER TABLE statement when inserting an AUTO_INCREMENT value", -- cgit v1.2.1 From 6211c35549338c07b766a3671dc0714140a26915 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 19 Oct 2021 11:06:32 +0200 Subject: MDEV-23391 Crash/assertion CREATE OR REPLACE TABLE AS SELECT under LOCK TABLE Happens with Innodb engine. Move unlock_locked_table() past drop_open_table(), and rollback current statement, so that we can actually unlock the table. Anything else results in assertions, in drop, or unlock, or in close_table. --- sql/sql_insert.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'sql') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 718682f767e..13dbbaed539 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -4708,12 +4708,6 @@ void select_create::abort_result_set() /* possible error of writing binary log is ignored deliberately */ (void) thd->binlog_flush_pending_rows_event(TRUE, TRUE); - if (create_info->table_was_deleted) - { - /* Unlock locked table that was dropped by CREATE */ - thd->locked_tables_list.unlock_locked_table(thd, - create_info->mdl_ticket); - } if (table) { bool tmp_table= table->s->tmp_table; @@ -4751,5 +4745,13 @@ void select_create::abort_result_set() tmp_table); } } + + if (create_info->table_was_deleted) + { + /* Unlock locked table that was dropped by CREATE. */ + (void) trans_rollback_stmt(thd); + thd->locked_tables_list.unlock_locked_table(thd, create_info->mdl_ticket); + } + DBUG_VOID_RETURN; } -- cgit v1.2.1 From d062b69037fd83123337d038508e55e00adbc3cd Mon Sep 17 00:00:00 2001 From: Diego Dupin Date: Tue, 26 Oct 2021 11:01:11 +0200 Subject: MDEV-26868: Session tracking flag in OK_PACKET Take into account client capabilities. --- sql/protocol.cc | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'sql') diff --git a/sql/protocol.cc b/sql/protocol.cc index 1bffcfb3bdb..613668b39a5 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -218,8 +218,6 @@ net_send_ok(THD *thd, NET *net= &thd->net; StringBuffer store; - bool state_changed= false; - bool error= FALSE; DBUG_ENTER("net_send_ok"); @@ -246,6 +244,11 @@ net_send_ok(THD *thd, /* last insert id */ store.q_net_store_length(id); + /* if client has not session tracking capability, don't send state change flag*/ + if (!(thd->client_capabilities & CLIENT_SESSION_TRACK)) { + server_status &= ~SERVER_SESSION_STATE_CHANGED; + } + if (thd->client_capabilities & CLIENT_PROTOCOL_41) { DBUG_PRINT("info", @@ -266,21 +269,17 @@ net_send_ok(THD *thd, } thd->get_stmt_da()->set_overwrite_status(true); - state_changed= - (thd->client_capabilities & CLIENT_SESSION_TRACK) && - (server_status & SERVER_SESSION_STATE_CHANGED); - - if (state_changed || (message && message[0])) + if ((server_status & SERVER_SESSION_STATE_CHANGED) || (message && message[0])) { DBUG_ASSERT(safe_strlen(message) <= MYSQL_ERRMSG_SIZE); store.q_net_store_data((uchar*) safe_str(message), safe_strlen(message)); } - if (unlikely(state_changed)) + if (unlikely(server_status & SERVER_SESSION_STATE_CHANGED)) { store.set_charset(thd->variables.collation_database); - thd->session_tracker.store(thd, &store); + thd->server_status&= ~SERVER_SESSION_STATE_CHANGED; } DBUG_ASSERT(store.length() <= MAX_PACKET_LENGTH); @@ -289,8 +288,6 @@ net_send_ok(THD *thd, if (!error && (!skip_flush || is_eof)) error= net_flush(net); - thd->server_status&= ~SERVER_SESSION_STATE_CHANGED; - thd->get_stmt_da()->set_overwrite_status(false); DBUG_PRINT("info", ("OK sent, so no more error sending allowed")); -- cgit v1.2.1 From 2ed148c8d7b0133ecd17377587facadc7e76e9e8 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Wed, 27 Oct 2021 10:50:15 +0400 Subject: MDEV-25402 Assertion `!str || str != Ptr' failed in String::copy The assert inside String::copy() prevents copying from from "str" if its own String::Ptr also points to the same memory. The idea of the assert is that copy() performs memory reallocation, and this reallocation can free (and thus invalidate) the memory pointed by Ptr, which can lead to further copying from a freed memory. The assert was incomplete: copy() can free the memory pointed by its Ptr only if String::alloced is true! If the String is not alloced, it is still safe to copy even from the location pointed by Ptr. This scenario demonstrates a safe copy(): const char *tmp= "123"; String str1(tmp, 3); String str2(tmp, 3); // This statement is safe: str2.copy(str1->ptr(), str1->length(), str1->charset(), cs_to, &errors); Inside the copy() the parameter "str" is equal to String::Ptr in this example. But it's still ok to reallocate the memory for str2, because str2 was a constant before the copy() call. Thus reallocation does not make the memory pointed by str1->ptr() invalid. Adjusting the assert condition to allow copying for constant strings. --- sql/sql_string.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql') diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 4e0c7aea84b..ff6b2163630 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -379,7 +379,7 @@ bool String::copy(const char *str, uint32 arg_length, { uint32 offset; - DBUG_ASSERT(!str || str != Ptr); + DBUG_ASSERT(!str || str != Ptr || !alloced); if (!needs_conversion(arg_length, from_cs, to_cs, &offset)) { -- cgit v1.2.1