summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorDaniel Black <daniel@mariadb.org>2022-03-25 15:06:56 +1100
committerDaniel Black <daniel@mariadb.org>2022-03-25 15:06:56 +1100
commit88ce8a3d8be0346b325bc4da75894cd15e255857 (patch)
tree1e827eb908eaa737225017627beafa2b6d8e9959 /sql
parentf6fcf827b379fc069563d1896850fbfcebaa983e (diff)
parent13b97880bd8f6901225a1f8d6ff2eb6ba9303ceb (diff)
downloadmariadb-git-88ce8a3d8be0346b325bc4da75894cd15e255857.tar.gz
Merge 10.7 into 10.8
Diffstat (limited to 'sql')
-rw-r--r--sql/ha_partition.cc85
-rw-r--r--sql/ha_partition.h3
-rw-r--r--sql/mysqld.cc7
-rw-r--r--sql/share/errmsg-utf8.txt48
-rw-r--r--sql/slave.cc24
-rw-r--r--sql/sql_class.cc52
-rw-r--r--sql/sql_class.h4
-rw-r--r--sql/sql_parse.cc18
-rw-r--r--sql/sql_table.cc20
-rw-r--r--sql/sys_vars.cc4
-rw-r--r--sql/table.cc17
-rw-r--r--sql/temporary_tables.cc8
-rw-r--r--sql/unireg.h16
13 files changed, 226 insertions, 80 deletions
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index 40c00945bec..453446eb85d 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -3198,11 +3198,12 @@ err1:
@retval true Failure
*/
-bool ha_partition::setup_engine_array(MEM_ROOT *mem_root)
+bool ha_partition::setup_engine_array(MEM_ROOT *mem_root,
+ handlerton* first_engine)
{
uint i;
uchar *buff;
- handlerton **engine_array, *first_engine;
+ handlerton **engine_array;
enum legacy_db_type db_type, first_db_type;
DBUG_ASSERT(!m_file);
@@ -3212,11 +3213,8 @@ bool ha_partition::setup_engine_array(MEM_ROOT *mem_root)
DBUG_RETURN(true);
buff= (uchar *) (m_file_buffer + PAR_ENGINES_OFFSET);
- first_db_type= (enum legacy_db_type) buff[0];
- first_engine= ha_resolve_by_legacy_type(ha_thd(), first_db_type);
- if (!first_engine)
- goto err;
+ first_db_type= (enum legacy_db_type) buff[0];
if (!(m_engine_array= (plugin_ref*)
alloc_root(&m_mem_root, m_tot_parts * sizeof(plugin_ref))))
goto err;
@@ -3257,6 +3255,75 @@ err:
}
+handlerton *ha_partition::get_def_part_engine(const char *name)
+{
+ if (table_share)
+ {
+ if (table_share->default_part_plugin)
+ return plugin_data(table_share->default_part_plugin, handlerton *);
+ }
+ else
+ {
+ // DROP TABLE, for example
+ char buff[FN_REFLEN];
+ File file;
+ MY_STAT state;
+ uchar *frm_image= 0;
+ handlerton *hton= 0;
+ bool use_legacy_type= false;
+
+ fn_format(buff, name, "", reg_ext, MY_APPEND_EXT);
+
+ file= mysql_file_open(key_file_frm, buff, O_RDONLY | O_SHARE, MYF(0));
+ if (file < 0)
+ return NULL;
+
+ if (mysql_file_fstat(file, &state, MYF(MY_WME)))
+ goto err;
+ if (state.st_size <= 64)
+ goto err;
+ if (!(frm_image= (uchar*)my_malloc(key_memory_Partition_share,
+ state.st_size, MYF(MY_WME))))
+ goto err;
+ if (mysql_file_read(file, frm_image, state.st_size, MYF(MY_NABP)))
+ goto err;
+
+ if (frm_image[64] != '/')
+ {
+ const uchar *e2= frm_image + 64;
+ const uchar *e2end = e2 + uint2korr(frm_image + 4);
+ if (e2end > frm_image + state.st_size)
+ goto err;
+ while (e2 + 3 < e2end)
+ {
+ uchar type= *e2++;
+ size_t length= extra2_read_len(&e2, e2end);
+ if (!length)
+ goto err;
+ if (type == EXTRA2_DEFAULT_PART_ENGINE)
+ {
+ LEX_CSTRING name= { (char*)e2, length };
+ plugin_ref plugin= ha_resolve_by_name(ha_thd(), &name, false);
+ if (plugin)
+ hton= plugin_data(plugin, handlerton *);
+ goto err;
+ }
+ e2+= length;
+ }
+ }
+ use_legacy_type= true;
+err:
+ my_free(frm_image);
+ mysql_file_close(file, MYF(0));
+ if (!use_legacy_type)
+ return hton;
+ }
+
+ return ha_resolve_by_legacy_type(ha_thd(),
+ (enum legacy_db_type)m_file_buffer[PAR_ENGINES_OFFSET]);
+}
+
+
/**
Get info about partition engines and their names from the .par file
@@ -3284,7 +3351,11 @@ bool ha_partition::get_from_handler_file(const char *name, MEM_ROOT *mem_root,
if (read_par_file(name))
DBUG_RETURN(true);
- if (!is_clone && setup_engine_array(mem_root))
+ handlerton *default_engine= get_def_part_engine(name);
+ if (!default_engine)
+ DBUG_RETURN(true);
+
+ if (!is_clone && setup_engine_array(mem_root, default_engine))
DBUG_RETURN(true);
DBUG_RETURN(false);
diff --git a/sql/ha_partition.h b/sql/ha_partition.h
index 14f68b36c0b..dd14cd7a6d4 100644
--- a/sql/ha_partition.h
+++ b/sql/ha_partition.h
@@ -590,8 +590,9 @@ private:
And one method to read it in.
*/
bool create_handler_file(const char *name);
- bool setup_engine_array(MEM_ROOT *mem_root);
+ bool setup_engine_array(MEM_ROOT *mem_root, handlerton *first_engine);
bool read_par_file(const char *name);
+ handlerton *get_def_part_engine(const char *name);
bool get_from_handler_file(const char *name, MEM_ROOT *mem_root,
bool is_clone);
bool new_handlers_from_part_info(MEM_ROOT *mem_root);
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 27432489a00..9a333c856c9 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -3675,13 +3675,18 @@ static void my_malloc_size_cb_func(long long size, my_bool is_thread_specific)
/* Ensure we don't get called here again */
char buf[50], *buf2;
thd->set_killed(KILL_QUERY);
- my_snprintf(buf, sizeof(buf), "--max-thread-mem-used=%llu",
+ my_snprintf(buf, sizeof(buf), "--max-session-mem-used=%llu",
thd->variables.max_mem_used);
if ((buf2= (char*) thd->alloc(256)))
{
my_snprintf(buf2, 256, ER_THD(thd, ER_OPTION_PREVENTS_STATEMENT), buf);
thd->set_killed(KILL_QUERY, ER_OPTION_PREVENTS_STATEMENT, buf2);
}
+ else
+ {
+ thd->set_killed(KILL_QUERY, ER_OPTION_PREVENTS_STATEMENT,
+ "--max-session-mem-used");
+ }
}
DBUG_ASSERT((longlong) thd->status_var.local_memory_used >= 0 ||
!debug_assert_on_not_freed_memory);
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index 64bfe1aefb9..0806cdb43de 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -2234,30 +2234,30 @@ ER_NO_SUCH_THREAD
swe "Finns ingen tråd med id %lu"
ukr "Невідомий ідентифікатор гілки: %lu"
ER_KILL_DENIED_ERROR
- cze "Nejste vlastníkem threadu %lu"
- dan "Du er ikke ejer af tråden %lu"
- nla "U bent geen bezitter van thread %lu"
- eng "You are not owner of thread %lu"
- est "Ei ole lõime %lu omanik"
- fre "Vous n'êtes pas propriétaire de la tâche no: %lu"
- ger "Sie sind nicht Eigentümer von Thread %lu"
- greek "Δεν είσθε owner του thread %lu"
- hindi "आप थ्रेड %lu के OWNER नहीं हैं"
- hun "A %lu thread-nek mas a tulajdonosa"
- ita "Utente non proprietario del thread %lu"
- jpn "スレッド %lu のオーナーではありません。"
- kor "쓰레드(Thread) %lu의 소유자가 아닙니다."
- nor "Du er ikke eier av tråden %lu"
- norwegian-ny "Du er ikkje eigar av tråd %lu"
- pol "Nie jeste? wła?cicielem w?tku %lu"
- por "Você não é proprietário da 'thread' %lu"
- rum "Nu sinteti proprietarul threadului %lu"
- rus "Вы не являетесь владельцем потока %lu"
- serbian "Vi niste vlasnik thread-a %lu"
- slo "Nie ste vlastníkom vlákna %lu"
- spa "No eres el propietario del hilo (thread) %lu"
- swe "Du är inte ägare till tråd %lu"
- ukr "Ви не володар гілки %lu"
+ cze "Nejste vlastníkem threadu %lld"
+ dan "Du er ikke ejer af tråden %lld"
+ nla "U bent geen bezitter van thread %lld"
+ eng "You are not owner of thread %lld"
+ est "Ei ole lõime %lld omanik"
+ fre "Vous n'êtes pas propriétaire de la tâche no: %lld"
+ ger "Sie sind nicht Eigentümer von Thread %lld"
+ greek "Δεν είσθε owner του thread %lld"
+ hindi "आप थ्रेड %lld के OWNER नहीं हैं"
+ hun "A %lld thread-nek mas a tulajdonosa"
+ ita "Utente non proprietario del thread %lld"
+ jpn "スレッド %lld のオーナーではありません。"
+ kor "쓰레드(Thread) %lld의 소유자가 아닙니다."
+ nor "Du er ikke eier av tråden %lld"
+ norwegian-ny "Du er ikkje eigar av tråd %lld"
+ pol "Nie jeste? wła?cicielem w?tku %lld"
+ por "Você não é proprietário da 'thread' %lld"
+ rum "Nu sinteti proprietarul threadului %lld"
+ rus "Вы не являетесь владельцем потока %lld"
+ serbian "Vi niste vlasnik thread-a %lld"
+ slo "Nie ste vlastníkom vlákna %lld"
+ spa "No eres el propietario del hilo (thread) %lld"
+ swe "Du är inte ägare till tråd %lld"
+ ukr "Ви не володар гілки %lld"
ER_NO_TABLES_USED
cze "Nejsou použity žádné tabulky"
dan "Ingen tabeller i brug"
diff --git a/sql/slave.cc b/sql/slave.cc
index 3b03eed1741..23a35c5805f 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -6241,13 +6241,13 @@ static int queue_event(Master_info* mi, const uchar *buf, ulong event_len)
bool is_rows_event= false;
/*
The flag has replicate_same_server_id semantics and is raised to accept
- a same-server-id event on the semisync slave, for both the gtid and legacy
- connection modes.
- Such events can appear as result of this server recovery so the event
- was created there and replicated elsewhere right before the crash. At recovery
- it could be evicted from the server's binlog.
- */
- bool do_accept_own_server_id= false;
+ a same-server-id event group by the gtid strict mode semisync slave.
+ Own server-id events can appear as result of this server crash-recovery:
+ the transaction was created on this server then being master, got replicated
+ elsewhere right before the crash before commit;
+ finally at recovery the transaction gets evicted from the server's binlog.
+ */
+ bool do_accept_own_server_id;
/*
FD_q must have been prepared for the first R_a event
inside get_master_version_and_clock()
@@ -6336,6 +6336,8 @@ static int queue_event(Master_info* mi, const uchar *buf, ulong event_len)
dbug_rows_event_count = 0;
};);
#endif
+ s_id= uint4korr(buf + SERVER_ID_OFFSET);
+
mysql_mutex_lock(&mi->data_lock);
switch (buf[EVENT_TYPE_OFFSET]) {
@@ -6795,6 +6797,7 @@ static int queue_event(Master_info* mi, const uchar *buf, ulong event_len)
++mi->events_queued_since_last_gtid;
inc_pos= event_len;
+
}
break;
/*
@@ -6937,6 +6940,10 @@ static int queue_event(Master_info* mi, const uchar *buf, ulong event_len)
break;
}
+ do_accept_own_server_id= (s_id == global_system_variables.server_id
+ && rpl_semi_sync_slave_enabled && opt_gtid_strict_mode
+ && mi->using_gtid != Master_info::USE_GTID_NO);
+
/*
Integrity of Rows- event group check.
A sequence of Rows- events must end with STMT_END_F flagged one.
@@ -6982,7 +6989,6 @@ static int queue_event(Master_info* mi, const uchar *buf, ulong event_len)
*/
mysql_mutex_lock(log_lock);
- s_id= uint4korr(buf + SERVER_ID_OFFSET);
/*
Write the event to the relay log, unless we reconnected in the middle
of an event group and now need to skip the initial part of the group that
@@ -7028,7 +7034,7 @@ static int queue_event(Master_info* mi, const uchar *buf, ulong event_len)
else
if ((s_id == global_system_variables.server_id &&
!(mi->rli.replicate_same_server_id ||
- (do_accept_own_server_id= rpl_semi_sync_slave_enabled))) ||
+ do_accept_own_server_id)) ||
event_that_should_be_ignored(buf) ||
/*
the following conjunction deals with IGNORE_SERVER_IDS, if set
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 9737083e900..bf6efd9fd52 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -2354,6 +2354,58 @@ bool THD::convert_string(LEX_STRING *to, CHARSET_INFO *to_cs,
/*
+ Reinterpret a binary string to a character string
+
+ @param[OUT] to The result will be written here,
+ either the original string as is,
+ or a newly alloced fixed string with
+ some zero bytes prepended.
+ @param cs The destination character set
+ @param str The binary string
+ @param length The length of the binary string
+
+ @return false on success
+ @return true on error
+*/
+
+bool THD::reinterpret_string_from_binary(LEX_CSTRING *to, CHARSET_INFO *cs,
+ const char *str, size_t length)
+{
+ /*
+ When reinterpreting from binary to tricky character sets like
+ UCS2, UTF16, UTF32, we may need to prepend some zero bytes.
+ This is possible in scenarios like this:
+ SET COLLATION_CONNECTION=utf32_general_ci, CHARACTER_SET_CLIENT=binary;
+ This code is similar to String::copy_aligned().
+ */
+ size_t incomplete= length % cs->mbminlen; // Bytes in an incomplete character
+ if (incomplete)
+ {
+ size_t zeros= cs->mbminlen - incomplete;
+ size_t aligned_length= zeros + length;
+ char *dst= (char*) alloc(aligned_length + 1);
+ if (!dst)
+ {
+ to->str= NULL; // Safety
+ to->length= 0;
+ return true;
+ }
+ bzero(dst, zeros);
+ memcpy(dst + zeros, str, length);
+ dst[aligned_length]= '\0';
+ to->str= dst;
+ to->length= aligned_length;
+ }
+ else
+ {
+ to->str= str;
+ to->length= length;
+ }
+ return check_string_for_wellformedness(to->str, to->length, cs);
+}
+
+
+/*
Convert a string between two character sets.
dstcs and srccs cannot be &my_charset_bin.
*/
diff --git a/sql/sql_class.h b/sql/sql_class.h
index ab04e17fdfd..829c938d077 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -4162,6 +4162,8 @@ public:
bool convert_string(LEX_STRING *to, CHARSET_INFO *to_cs,
const char *from, size_t from_length,
CHARSET_INFO *from_cs);
+ bool reinterpret_string_from_binary(LEX_CSTRING *to, CHARSET_INFO *to_cs,
+ const char *from, size_t from_length);
bool convert_string(LEX_CSTRING *to, CHARSET_INFO *to_cs,
const char *from, size_t from_length,
CHARSET_INFO *from_cs)
@@ -4178,6 +4180,8 @@ public:
{
if (!simple_copy_is_possible)
return unlikely(convert_string(to, tocs, from->str, from->length, fromcs));
+ if (fromcs == &my_charset_bin)
+ return reinterpret_string_from_binary(to, tocs, from->str, from->length);
*to= *from;
return false;
}
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index fe2307a2e91..77c55e3daf3 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -9391,15 +9391,17 @@ sql_kill_user(THD *thd, LEX_USER *user, killed_state state)
{
uint error;
ha_rows rows;
- if (likely(!(error= kill_threads_for_user(thd, user, state, &rows))))
- my_ok(thd, rows);
- else
+ switch (error= kill_threads_for_user(thd, user, state, &rows))
{
- /*
- This is probably ER_OUT_OF_RESOURCES, but in the future we may
- want to write the name of the user we tried to kill
- */
- my_error(error, MYF(0), user->host.str, user->user.str);
+ case 0:
+ my_ok(thd, rows);
+ break;
+ case ER_KILL_DENIED_ERROR:
+ my_error(error, MYF(0), (long long) thd->thread_id);
+ break;
+ case ER_OUT_OF_RESOURCES:
+ default:
+ my_error(error, MYF(0));
}
}
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 8b3d1a6aefc..55f732669af 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -2038,17 +2038,13 @@ bool quick_rm_table(THD *thd, handlerton *base, const LEX_CSTRING *db,
const char *table_path)
{
char path[FN_REFLEN + 1];
+ const size_t pathmax = sizeof(path) - 1 - reg_ext_length;
int error= 0;
DBUG_ENTER("quick_rm_table");
size_t path_length= table_path ?
- (strxnmov(path, sizeof(path) - 1, table_path, reg_ext, NullS) - path) :
- build_table_filename(path, sizeof(path)-1, db->str, table_name->str,
- reg_ext, flags);
- if (!(flags & NO_FRM_RENAME))
- if (mysql_file_delete(key_file_frm, path, MYF(0)))
- error= 1; /* purecov: inspected */
- path[path_length - reg_ext_length]= '\0'; // Remove reg_ext
+ (strxnmov(path, pathmax, table_path, NullS) - path) :
+ build_table_filename(path, pathmax, db->str, table_name->str, "", flags);
if ((flags & (NO_HA_TABLE | NO_PAR_TABLE)) == NO_HA_TABLE)
{
handler *file= get_new_handler((TABLE_SHARE*) 0, thd->mem_root, base);
@@ -2058,8 +2054,14 @@ bool quick_rm_table(THD *thd, handlerton *base, const LEX_CSTRING *db,
delete file;
}
if (!(flags & (FRM_ONLY|NO_HA_TABLE)))
- if (ha_delete_table(thd, base, path, db, table_name, 0) > 0)
- error= 1;
+ error|= ha_delete_table(thd, base, path, db, table_name, 0) > 0;
+
+ if (!(flags & NO_FRM_RENAME))
+ {
+ memcpy(path + path_length, reg_ext, reg_ext_length + 1);
+ if (mysql_file_delete(key_file_frm, path, MYF(0)))
+ error= 1; /* purecov: inspected */
+ }
if (likely(error == 0))
{
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index 2174f8be2e7..789d95be1be 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -5142,7 +5142,7 @@ static Sys_var_have Sys_have_symlink(
# ifdef __SANITIZE_ADDRESS__
# ifdef WITH_UBSAN
-# define SANITIZER_MODE "ASAN+UBSAN"
+# define SANITIZER_MODE "ASAN,UBSAN"
# else
# define SANITIZER_MODE "ASAN"
# endif
@@ -6700,7 +6700,7 @@ static Sys_var_ulong Sys_log_tc_size(
DEFAULT(my_getpagesize() * 6), BLOCK_SIZE(my_getpagesize()));
#endif
-static Sys_var_ulonglong Sys_max_thread_mem(
+static Sys_var_ulonglong Sys_max_session_mem_used(
"max_session_mem_used", "Amount of memory a single user session "
"is allowed to allocate. This limits the value of the "
"session variable MEM_USED", SESSION_VAR(max_mem_used),
diff --git a/sql/table.cc b/sql/table.cc
index a683a78ff49..481baf96eeb 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -1553,21 +1553,6 @@ bool TABLE_SHARE::init_period_from_extra2(period_info_t *period,
}
-static size_t extra2_read_len(const uchar **extra2, const uchar *extra2_end)
-{
- size_t length= *(*extra2)++;
- if (length)
- return length;
-
- if ((*extra2) + 2 >= extra2_end)
- return 0;
- length= uint2korr(*extra2);
- (*extra2)+= 2;
- if (length < 256 || *extra2 + length > extra2_end)
- return 0;
- return length;
-}
-
static
bool read_extra2_section_once(const uchar *extra2, size_t len, LEX_CUSTRING *section)
{
@@ -1867,7 +1852,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
if (frm_image[61] && !share->default_part_plugin)
{
enum legacy_db_type db_type= (enum legacy_db_type) (uint) frm_image[61];
- share->default_part_plugin= ha_lock_engine(NULL, ha_checktype(thd, db_type));
+ share->default_part_plugin= ha_lock_engine(NULL, ha_checktype(thd, db_type, 1));
if (!share->default_part_plugin)
goto err;
}
diff --git a/sql/temporary_tables.cc b/sql/temporary_tables.cc
index c582bf70e30..73f1f9f7a99 100644
--- a/sql/temporary_tables.cc
+++ b/sql/temporary_tables.cc
@@ -698,9 +698,7 @@ bool THD::rm_temporary_table(handlerton *base, const char *path)
char frm_path[FN_REFLEN + 1];
strxnmov(frm_path, sizeof(frm_path) - 1, path, reg_ext, NullS);
- if (mysql_file_delete(key_file_frm, frm_path,
- MYF(MY_WME | MY_IGNORE_ENOENT)))
- error= true;
+
if (base->drop_table(base, path) > 0)
{
error= true;
@@ -708,6 +706,10 @@ bool THD::rm_temporary_table(handlerton *base, const char *path)
path, my_errno);
}
+ if (mysql_file_delete(key_file_frm, frm_path,
+ MYF(MY_WME | MY_IGNORE_ENOENT)))
+ error= true;
+
DBUG_RETURN(error);
}
diff --git a/sql/unireg.h b/sql/unireg.h
index 0edb0a50ebd..01c1a5a284e 100644
--- a/sql/unireg.h
+++ b/sql/unireg.h
@@ -192,6 +192,22 @@ enum extra2_index_flags {
EXTRA2_IGNORED_KEY
};
+
+static inline size_t extra2_read_len(const uchar **extra2, const uchar *end)
+{
+ size_t length= *(*extra2)++;
+ if (length)
+ return length;
+
+ if ((*extra2) + 2 >= end)
+ return 0;
+ length= uint2korr(*extra2);
+ (*extra2)+= 2;
+ if (length < 256 || *extra2 + length > end)
+ return 0;
+ return length;
+}
+
LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING &table,
HA_CREATE_INFO *create_info,
List<Create_field> &create_fields,