[packages/mysql/MYSQL_8_0] Rel 5. Backport October 2026 CPU (Ubuntu) and November 2026 CSPU

arekm arekm at pld-linux.org
Fri Nov 27 23:28:56 CET 2026


commit a77312db85a4628dda1ed3e56296a0b40e0fdd42
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Fri Nov 27 23:28:23 2026 +0100

    Rel 5. Backport October 2026 CPU (Ubuntu) and November 2026 CSPU
    
    Fixes CVE-2026-127428, CVE-2026-114953, CVE-2026-114952,
    CVE-2026-114951, CVE-2026-114950, CVE-2026-114949, CVE-2026-101803,
    CVE-2026-101802, CVE-2026-101801, CVE-2026-101800, CVE-2026-101799,
    CVE-2026-101798, CVE-2026-101797, CVE-2026-101796, CVE-2026-101795,
    CVE-2026-101794, CVE-2026-101789, CVE-2026-101788, CVE-2026-101787,
    CVE-2026-101785, CVE-2026-101784, CVE-2026-101781, CVE-2026-101780,
    CVE-2026-101778, CVE-2026-101776, CVE-2026-101775, CVE-2026-101774,
    CVE-2026-101773, CVE-2026-101772, CVE-2026-101771, CVE-2026-101770,
    CVE-2026-101766, CVE-2026-101762, CVE-2026-101761, CVE-2026-101760,
    CVE-2026-101754, CVE-2026-101751, CVE-2026-101750, CVE-2026-101748,
    CVE-2026-101747, CVE-2026-101733, CVE-2026-101732, CVE-2026-101731,
    CVE-2026-101730, CVE-2026-101729, CVE-2026-101728, CVE-2026-101727,
    CVE-2026-101726, CVE-2026-101725, CVE-2026-101724, CVE-2026-101721,
    CVE-2026-101679, CVE-2026-101627, CVE-2026-101624, CVE-2026-101623,
    CVE-2026-101622, CVE-2026-101621, CVE-2026-101619, CVE-2026-101618,
    CVE-2026-101617, CVE-2026-101616, CVE-2026-101615, CVE-2026-101614,
    CVE-2026-101613, CVE-2026-101612, CVE-2026-101611, CVE-2026-101610,
    CVE-2026-101609, CVE-2026-101608, CVE-2026-101607.

 mysql-2026-10-cpu.patch  | 17262 +++++++++++++++++++++++++++++++++++++++++++++
 mysql-2026-11-cspu.patch |   225 +
 mysql.spec               |    17 +-
 3 files changed, 17498 insertions(+), 6 deletions(-)
---
diff --git a/mysql.spec b/mysql.spec
index d912c2e..87cff86 100644
--- a/mysql.spec
+++ b/mysql.spec
@@ -38,7 +38,7 @@ Summary(zh_CN.UTF-8):	MySQL数据库服务器
 Name:		mysql%{majorver}
 # keep stable (and not "innovation") line here
 Version:	8.0.46
-Release:	4
+Release:	5
 License:	GPL v2 + MySQL FOSS License Exception
 Group:		Applications/Databases
 #Source0Download: https://dev.mysql.com/downloads/mysql/8.0.html#downloads
@@ -73,11 +73,14 @@ Patch24:	mysql-cmake.patch
 Patch25:	mysql-readline.patch
 
 Patch26:	mysqldumpslow-clusters.patch
-# 8.0 is EOL upstream, so post-8.0.46 security fixes come from Ubuntu
+# 8.0 is EOL upstream, so post-8.0.46 security fixes come from Ubuntu or
+# are backported from 8.4
 Patch27:	mysql-CVE-2026-46862.patch
 Patch28:	mysql-CVE-2026-46863.patch
 Patch29:	mysql-2026-07-cpu.patch
 Patch30:	mysql-old-server-auth.patch
+Patch31:	mysql-2026-10-cpu.patch
+Patch32:	mysql-2026-11-cspu.patch
 URL:		https://www.mysql.com/products/community/
 BuildRequires:	bison >= 1.875
 %{?with_system_boost:BuildRequires:	boost-devel >= 1.77.0}
@@ -134,7 +137,7 @@ Provides:	user(mysql)
 Obsoletes:	MySQL < 3.22.27
 Obsoletes:	mysql-server < 4
 Conflicts:	logrotate < 3.8.0
-BuildRoot:	%{tmpdir}/mysql-%{version}-root-%(id -u -n)
+BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
 
 %define		_libexecdir	%{_sbindir}
 %define		_localstatedir	/var/lib/%{name}
@@ -318,9 +321,9 @@ Summary:	Shared libraries for MySQL
 Summary(pl.UTF-8):	Biblioteki współdzielone MySQL
 Group:		Libraries
 Requires:	zlib >= 1.2.12
+Suggests:	%{name}-client-plugins = %{version}-%{release}
 Obsoletes:	libmysql10 < 4
 Obsoletes:	mysql-doc < 4.1.12
-Suggests:	%{name}-client-plugins = %{version}-%{release}
 
 %description libs
 Shared libraries for MySQL.
@@ -354,11 +357,11 @@ Group:		Development/Libraries
 Requires:	%{name}-libs = %{version}-%{release}
 %{?with_ssl:Requires:	openssl-devel >= 1.1.1}
 Requires:	zlib-devel >= 1.2.12
+Provides:	mysql-devel = %{version}-%{release}
 Obsoletes:	MySQL-devel < 3.22.27
 Obsoletes:	libmysql10-devel < 4
-Obsoletes:	webscalesql-devel
-Provides:	mysql-devel = %{version}-%{release}
 Obsoletes:	mysql-devel < %{version}-%{release}
+Obsoletes:	webscalesql-devel
 
 %description devel
 This package contains the development header files and other files
@@ -516,6 +519,8 @@ Ten pakiet zawiera standardowego demona MySQL NDB CPC.
 %patch -P28 -p1
 %patch -P29 -p1
 %patch -P30 -p1
+%patch -P31 -p1
+%patch -P32 -p1
 
 #%%patch -P26 -p1
 
diff --git a/mysql-2026-10-cpu.patch b/mysql-2026-10-cpu.patch
new file mode 100644
index 0000000..92a0b21
--- /dev/null
+++ b/mysql-2026-10-cpu.patch
@@ -0,0 +1,17262 @@
+Oracle's October 2026 Critical Patch Update, backported to 8.0. 8.0 reached
+End of Life with 8.0.46 in April 2026, so upstream published these fixes
+only for 8.4 and newer.
+Taken from Ubuntu's mysql-8.0 source package (debian/patches), version
+8.0.46-0ubuntu0.24.04.5.
+
+Covers:
+  CVE-2026-101607 CVE-2026-101608 CVE-2026-101609 CVE-2026-101610 CVE-2026-101611
+  CVE-2026-101612 CVE-2026-101613 CVE-2026-101614 CVE-2026-101615 CVE-2026-101616
+  CVE-2026-101617 CVE-2026-101618 CVE-2026-101619 CVE-2026-101621 CVE-2026-101622
+  CVE-2026-101623 CVE-2026-101624 CVE-2026-101627 CVE-2026-101679 CVE-2026-101721
+  CVE-2026-101724 CVE-2026-101725 CVE-2026-101726 CVE-2026-101727 CVE-2026-101728
+  CVE-2026-101729 CVE-2026-101730 CVE-2026-101731 CVE-2026-101732 CVE-2026-101733
+  CVE-2026-101747 CVE-2026-101748 CVE-2026-101750 CVE-2026-101751 CVE-2026-101754
+  CVE-2026-101760 CVE-2026-101761 CVE-2026-101762 CVE-2026-101766 CVE-2026-101770
+  CVE-2026-101771 CVE-2026-101772 CVE-2026-101773 CVE-2026-101774 CVE-2026-101775
+  CVE-2026-101776 CVE-2026-101778 CVE-2026-101780 CVE-2026-101781 CVE-2026-101784
+  CVE-2026-101785 CVE-2026-101787 CVE-2026-101788 CVE-2026-101789 CVE-2026-101794
+  CVE-2026-101795 CVE-2026-101796 CVE-2026-101797 CVE-2026-101798 CVE-2026-101799
+  CVE-2026-101800 CVE-2026-101801 CVE-2026-101802 CVE-2026-101803
+
+--- a/client/mysqlbinlog.cc
++++ b/client/mysqlbinlog.cc
+@@ -106,20 +106,38 @@ class Database_rewrite {
+     Database_rewrite &m_event_rewriter;
+ 
+     /**
+-      Expands the buffer if needed.
++      Expands the buffer if needed. If the requested size exceeds the capacity,
++      reallocates the buffer and returns a pointer, a capacity, and whether it
++      was successful or not.
++
++      On error, returns the same buffer and same capacity as were passed as
++      parameters.
++
++      @param buffer the buffer to resize
++      @param capacity the capacity of the buffer
++      @param size the minimum size required for the buffer
++
++      @return A tuple containing the buffer pointer, the buffer capacity, and an
++      error indicator. If an error occurs, the returned buffer pointer and
++      capacity are identical to the input values and remain unmodified. On
++      success, the buffer is reallocated only if the requested size exceeds the
++      current capacity. In that case, the returned tuple contains the new buffer
++      pointer and its updated capacity. If the requested size does not exceed
++      the current capacity, no reallocation is performed. The original buffer
++      pointer and capacity are returned unchanged, and no error is reported.
+     */
+     std::tuple<unsigned char *, std::size_t, bool> reserve(
+         unsigned char *buffer, std::size_t capacity, std::size_t size) {
+-      if (size > capacity) {
+-        auto outsize{size};
+-        outsize = round(((size + BINLOG_CHECKSUM_LEN) / 1024.0) + 1) * 1024;
+-        buffer = (unsigned char *)realloc(buffer, outsize);
+-        if (!buffer) {
+-          return std::make_tuple(nullptr, 0, true);
+-        }
+-        return std::make_tuple(buffer, outsize, false);
+-      } else
+-        return std::make_tuple(buffer, capacity, false);
++      if (size <= capacity) return std::make_tuple(buffer, capacity, false);
++
++      const auto new_capacity = static_cast<std::size_t>(
++          round(((size + BINLOG_CHECKSUM_LEN) / 1024.0) + 1) * 1024);
++      auto *new_buffer =
++          static_cast<unsigned char *>(realloc(buffer, new_capacity));
++
++      if (new_buffer == nullptr) return std::make_tuple(buffer, capacity, true);
++
++      return std::make_tuple(new_buffer, new_capacity, false);
+     }
+ 
+     class Buffer_realloc_manager {
+@@ -135,6 +153,23 @@ class Database_rewrite {
+       void release() { m_buffer = nullptr; }
+     };
+ 
++    /**
++      This member function shall decompress the events in the payload passed as
++      an argument, rewrite their database names, and recompress them.
++
++      @param compression_type the compression type of the payload
++      @param orig_payload the buffer holding the compressed events
++      @param orig_payload_size the size of the data in the buffer
++      @param fde the format description event that will be used to decode events
++
++      @return A tuple that contains a pointer to the buffer with the data
++      rewritten and recompressed, the buffer capacity, the data size within the
++      buffer, the size of the rewritten uncompressed data, and whether there was
++      an error (false on success, true otherwise). If there was an error, the
++      last field of the tuple is set to true, the buffer pointer is set to
++      nullptr, the capacity is set to 0, and the compressed and uncompressed
++      data sizes are also set to 0.
++    */
+     Rewrite_payload_result rewrite_inner_events(
+         binary_log::transaction::compression::type compression_type,
+         const char *orig_payload, std::size_t orig_payload_size,
+@@ -232,7 +267,16 @@ class Database_rewrite {
+       @param buffer_capacity the capacity of the buffer.
+       @param fde The format description event to decode this event.
+ 
+-      @return a tuple with the result of the rewrite.
++      @return A tuple containing:
++        - a pointer to the buffer holding the rewritten and recompressed
++          payload,
++        - the buffer capacity,
++        - the size of the valid data in the buffer, and
++        - an error indicator.
++
++      If an error occurs, the error indicator is `true`, the returned buffer
++      pointer and capacity are unchanged from the input values, and the returned
++      data size is equal to the buffer capacity.
+      */
+     Rewrite_result rewrite_transaction_payload(
+         unsigned char *buffer, std::size_t buffer_capacity,
+@@ -245,23 +289,23 @@ class Database_rewrite {
+       auto orig_payload_size{tpe.get_payload_size()};
+       auto orig_payload_compression_type{tpe.get_compression_type()};
+ 
+-      unsigned char *rewritten_payload{nullptr};
+-      std::size_t rewritten_payload_size{0};
+-      std::size_t rewritten_payload_capacity{0};
+-      std::size_t rewritten_payload_uncompressed_size{0};
+-
+-      auto rewrite_payload_res{false};
+       auto has_crc{fde.footer()->checksum_alg ==
+                    binary_log::BINLOG_CHECKSUM_ALG_CRC32};
+ 
+       // Rewrite its contents as needed
+-      std::tie(rewritten_payload, rewritten_payload_capacity,
+-               rewritten_payload_size, rewritten_payload_uncompressed_size,
+-               rewrite_payload_res) =
++      auto [rewritten_payload, rewritten_payload_capacity,
++            rewritten_payload_size, rewritten_payload_uncompressed_size,
++            rewrite_payload_res] =
+           rewrite_inner_events(orig_payload_compression_type, orig_payload,
+                                orig_payload_size, fde);
++      // either there is no error or if there is an error rewritten payload
++      // is always a null pointer
++      assert(!rewrite_payload_res || rewritten_payload == nullptr);
++      auto cleanup_guard =
++          create_scope_guard([payload = rewritten_payload] { free(payload); });
+ 
+-      if (rewrite_payload_res) return Rewrite_result{nullptr, 0, 0, true};
++      if (rewrite_payload_res)
++        return Rewrite_result{buffer, buffer_capacity, buffer_capacity, true};
+ 
+       // create a new TPE with the new buffer
+       binary_log::Transaction_payload_event new_tpe(
+@@ -274,16 +318,22 @@ class Database_rewrite {
+           binary_log::codecs::Factory::build_codec(tpe.header()->type_code);
+       uchar tpe_buffer[binary_log::Transaction_payload_event::
+                            max_payload_data_header_length];
+-      auto result = codec->encode(new_tpe, tpe_buffer, sizeof(tpe_buffer));
+-      if (result.second == true) return Rewrite_result{nullptr, 0, 0, true};
++      const auto [encoded_size, encoding_error] =
++          codec->encode(new_tpe, tpe_buffer, sizeof(tpe_buffer));
++      if (encoding_error)
++        return Rewrite_result{buffer, buffer_capacity, buffer_capacity, true};
+ 
+       // Now adjust the event buffer itself
+-      auto new_data_size = result.first + rewritten_payload_size;
++      auto new_data_size = encoded_size + rewritten_payload_size;
+       auto new_event_size = LOG_EVENT_HEADER_LEN + new_data_size;
+       if (has_crc) new_event_size += BINLOG_CHECKSUM_LEN;
+-      if (new_event_size > buffer_capacity)
+-        buffer = (unsigned char *)my_realloc(PSI_NOT_INSTRUMENTED, buffer,
+-                                             new_event_size, MYF(0));
++      if (new_event_size > buffer_capacity) {
++        auto *new_buffer = static_cast<unsigned char *>(
++            my_realloc(PSI_NOT_INSTRUMENTED, buffer, new_event_size, MYF(0)));
++        if (new_buffer == nullptr)
++          return Rewrite_result{buffer, buffer_capacity, buffer_capacity, true};
++        buffer = new_buffer;
++      }
+ 
+       // now write everything into the event buffer
+       auto ptr = buffer;
+@@ -293,17 +343,13 @@ class Database_rewrite {
+       ptr += LOG_EVENT_HEADER_LEN;
+ 
+       // add the new tpe header
+-      memmove(ptr, tpe_buffer, result.first);
+-      ptr += result.first;
++      memmove(ptr, tpe_buffer, encoded_size);
++      ptr += encoded_size;
+ 
+       // add the new payload
+       memmove(ptr, rewritten_payload, rewritten_payload_size);
+       ptr += rewritten_payload_size;
+ 
+-      // now can free the new payload, as we have moved it to the
+-      // event buffer
+-      free(rewritten_payload);
+-
+       // recalculate checksum
+       if (has_crc) {
+         ha_checksum crc{0};
+@@ -487,16 +533,18 @@ class Database_rewrite {
+     delta = to.size() - from.size();
+     // need to reallocate
+     if ((delta + data_size) > buffer_capacity) {
+-      the_buffer_capacity = buffer_capacity + delta;
+-      the_buffer = (unsigned char *)my_realloc(PSI_NOT_INSTRUMENTED, buffer,
+-                                               the_buffer_capacity, MYF(0));
++      const auto new_capacity = buffer_capacity + delta;
++      auto *new_buffer = static_cast<unsigned char *>(
++          my_realloc(PSI_NOT_INSTRUMENTED, buffer, new_capacity, MYF(0)));
+       /* purecov: begin inspected */
+-      if (!the_buffer) {
++      if (new_buffer == nullptr) {
+         // OOM
+         error = true;
+         goto end;
+       }
+       /* purecov: end */
++      the_buffer = new_buffer;
++      the_buffer_capacity = new_capacity;
+     }
+ 
+     // adjust the size of the event
+@@ -2581,6 +2629,61 @@ err:
+ static uint get_dump_flags() { return stop_never ? 0 : BINLOG_DUMP_NON_BLOCK; }
+ 
+ /**
++  Checks whether a rotate event file name can be used for raw output.
++
++  Raw mode uses rotate events to choose the next output file. Accept only a
++  plain log file name with the same length as the rotate event metadata.
++
++  @param rev Rotate event containing the next log file name.
++
++  @retval true  The rotate event contains a valid raw log file name.
++  @retval false The file name is missing or not suitable for raw output.
++*/
++static bool is_raw_log_file_name_valid(const Rotate_log_event &rev) {
++  const char *log_file_name = rev.new_log_ident;
++
++  if (log_file_name == nullptr || rev.ident_len == 0) {
++    return false;
++  }
++  const size_t log_file_name_length = strlen(log_file_name);
++  if (log_file_name_length != rev.ident_len ||
++      dirname_length(log_file_name) != 0 || !strcmp(log_file_name, ".") ||
++      !strcmp(log_file_name, FN_PARENTDIR)) {
++    return false;
++  }
++
++  return true;
++}
++
++/**
++  Constructs the local file name used for raw output from a rotate event.
++
++  @param[out] to     Destination buffer.
++  @param[in] to_size Destination buffer size.
++  @param[in] prefix  Optional raw output prefix.
++  @param[in] rev     Rotate event containing the next log file name.
++
++  @retval false File name was constructed successfully.
++  @retval true  File name validation or formatting failed.
++*/
++static bool make_raw_log_file_name(char *to, size_t to_size, const char *prefix,
++                                   const Rotate_log_event &rev) {
++  if (!is_raw_log_file_name_valid(rev)) {
++    error("Invalid log file name in rotate event.");
++    return true;
++  }
++
++  const int length = snprintf(
++      to, to_size, "%s%s", prefix == nullptr ? "" : prefix, rev.new_log_ident);
++  if (length < 0 || static_cast<size_t>(length) >= to_size) {
++    error("Could not construct log file name from rotate event.");
++    return true;
++  }
++
++  return false;
++}
++
++/**
+   Callback function for mysql_binlog_open().
+ 
+   Sets gtid data in the command packet.
+@@ -2777,11 +2880,9 @@ static Exit_status dump_remote_log_entri
+           soon.
+         */
+         if (raw_mode) {
+-          if (output_file != nullptr) {
+-            snprintf(log_file_name, sizeof(log_file_name), "%s%s", output_file,
+-                     rev->new_log_ident);
+-          } else {
+-            my_stpcpy(log_file_name, rev->new_log_ident);
++          if (make_raw_log_file_name(log_file_name, sizeof(log_file_name),
++                                     output_file, *rev)) {
++            return ERROR_STOP;
+           }
+         }
+ 
+--- a/client/mysqldump.cc
++++ b/client/mysqldump.cc
+@@ -92,8 +92,8 @@
+ 
+ #define MYSQL_UNIVERSAL_CLIENT_CHARSET "utf8mb4"
+ 
+-/* Maximum number of fields per table */
+-#define MAX_FIELDS 4000
++/* Maximum number of fields per table. Keep in sync with sql/sql_const.h. */
++#define MAX_FIELDS 4096
+ 
+ /* One year in seconds */
+ #define LONG_TIMEOUT (3600UL * 24UL * 365UL)
+@@ -683,8 +683,18 @@ static int init_dumping_tables(char *);
+ static int init_dumping(char *, int init_func(char *));
+ static int dump_databases(char **);
+ static int dump_all_databases();
+-static char *quote_name(char *name, char *buff, bool force);
+-static const char *quote_name(const char *name, char *buff, bool force);
++static char *quote_name(char *name, char *buff, size_t buff_size, bool force);
++template <size_t BufferSize>
++static char *quote_name(char *name, char (&buff)[BufferSize], bool force) {
++  return quote_name(name, buff, BufferSize, force);
++}
++template <size_t BufferSize>
++static const char *quote_name(const char *name, char (&buff)[BufferSize],
++                              bool force) {
++  return quote_name(const_cast<char *>(name), buff, BufferSize, force);
++}
++static void check_identifier_length(const char *identifier,
++                                    const char *identifier_type);
+ char check_if_ignore_table(const char *table_name, char *table_type);
+ bool is_infoschema_db(const char *db);
+ static char *primary_key_fields(const char *table_name);
+@@ -1808,6 +1818,7 @@ static bool test_if_special_chars(const
+ 
+   name                 Unquoted string containing that which will be quoted
+   buff                 The buffer that contains the quoted value, also returned
++  buff_size            Size of buff in bytes
+   force                Flag to make it ignore 'test_if_special_chars'
+ 
+   Returns
+@@ -1815,23 +1826,69 @@ static bool test_if_special_chars(const
+   buff                 quoted string
+ 
+ */
+-static char *quote_name(char *name, char *buff, bool force) {
++static char *quote_name(char *name, char *buff, size_t buff_size, bool force) {
+   char *to = buff;
+   char qtype = ansi_quotes_mode ? '"' : '`';
+ 
++  DBUG_EXECUTE_IF("mysqldump_oversized_quoted_identifier", {
++    static char oversized_identifier[NAME_LEN + 2];
++    memset(oversized_identifier, qtype, sizeof(oversized_identifier) - 1);
++    oversized_identifier[sizeof(oversized_identifier) - 1] = 0;
++    name = oversized_identifier;
++  });
++
++  if (name == nullptr) {
++    die(EX_CONSCHECK, "Cannot quote a NULL identifier");
++    return nullptr;
++  }
++
+   if (!force && !opt_quoted && !test_if_special_chars(name)) return name;
++
++  if (buff_size < 3) {
++    die(EX_CONSCHECK, "Buffer is too small to quote an identifier");
++    return nullptr;
++  }
++
++  size_t remaining = buff_size;
+   *to++ = qtype;
++  --remaining;
+   while (*name) {
+-    if (*name == qtype) *to++ = qtype;
++    const size_t quoted_char_size = (*name == qtype) ? 2 : 1;
++    /* Reserve two bytes for the closing quote and terminating null. */
++    if (remaining < quoted_char_size + 2) {
++      die(EX_CONSCHECK, "Identifier is too long to quote safely");
++      return nullptr;
++    }
++    if (*name == qtype) {
++      *to++ = qtype;
++      --remaining;
++    }
+     *to++ = *name++;
++    --remaining;
+   }
+   to[0] = qtype;
+   to[1] = 0;
+   return buff;
+ } /* quote_name */
+ 
+-static const char *quote_name(const char *name, char *buff, bool force) {
+-  return quote_name(const_cast<char *>(name), buff, force);
++static void check_identifier_length(const char *identifier,
++                                    const char *identifier_type) {
++  if (identifier == nullptr)
++    die(EX_CONSCHECK, "%s name is NULL", identifier_type);
++  DBUG_EXECUTE_IF("mysqldump_oversized_identifier", {
++    static char oversized_identifier[NAME_LEN + 2];
++    memset(oversized_identifier, 'x', sizeof(oversized_identifier) - 1);
++    oversized_identifier[sizeof(oversized_identifier) - 1] = 0;
++    identifier = oversized_identifier;
++  });
++  /**
++    MYSQL_ROW text fields are null-terminated by the client library. NAME_LEN
++    is an encoded byte limit (NAME_CHAR_LEN * SYSTEM_CHARSET_MBMAXLEN), so
++    strlen() intentionally validates bytes rather than characters.
++  */
++  if (strlen(identifier) > NAME_LEN)
++    die(EX_CONSCHECK, "%s name exceeds the maximum length of %d bytes",
++        identifier_type, NAME_LEN);
+ }
+ 
+ /*
+@@ -1856,17 +1913,63 @@ static const char *quote_name(const char
+     Example: "t\1" => "t\\\\1"
+ 
+ */
+-static char *quote_for_like(const char *name, char *buff) {
++static constexpr size_t MAX_ESCAPED_LIKE_IDENTIFIER_SIZE = NAME_LEN * 4 + 3;
++
++template <size_t BufferSize>
++static char *quote_for_like(const char *name, char (&buff)[BufferSize]) {
+   char *to = buff;
++  size_t remaining = BufferSize;
++
++  if constexpr (BufferSize == MAX_ESCAPED_LIKE_IDENTIFIER_SIZE) {
++    DBUG_EXECUTE_IF("mysqldump_maximum_like_identifier", {
++      static char maximum_identifier[NAME_LEN + 1];
++      memset(maximum_identifier, '\\', sizeof(maximum_identifier) - 1);
++      maximum_identifier[sizeof(maximum_identifier) - 1] = 0;
++      name = maximum_identifier;
++    });
++
++    DBUG_EXECUTE_IF("mysqldump_oversized_like_identifier", {
++      static char oversized_identifier[NAME_LEN + 2];
++      memset(oversized_identifier, '\\', sizeof(oversized_identifier) - 1);
++      oversized_identifier[sizeof(oversized_identifier) - 1] = 0;
++      name = oversized_identifier;
++    });
++  }
++
++  if (name == nullptr) {
++    die(EX_CONSCHECK, "Cannot quote a NULL identifier");
++    return nullptr;
++  }
++
++  if (remaining < 3) {
++    die(EX_CONSCHECK, "Buffer is too small to quote an identifier for LIKE");
++    return nullptr;
++  }
++
+   *to++ = '\'';
++  --remaining;
+   while (*name) {
++    size_t quoted_char_size = 1;
++    if (*name == '\\')
++      quoted_char_size = 4;
++    else if (*name == '\'' || *name == '_' || *name == '%')
++      quoted_char_size = 2;
++    /* Reserve two bytes for the closing quote and terminating null. */
++    if (remaining < quoted_char_size + 2) {
++      die(EX_CONSCHECK, "Identifier is too long to quote safely for LIKE");
++      return nullptr;
++    }
+     if (*name == '\\') {
+       *to++ = '\\';
+       *to++ = '\\';
+       *to++ = '\\';
+-    } else if (*name == '\'' || *name == '_' || *name == '%')
++      remaining -= 3;
++    } else if (*name == '\'' || *name == '_' || *name == '%') {
+       *to++ = '\\';
++      --remaining;
++    }
+     *to++ = *name++;
++    --remaining;
+   }
+   to[0] = '\'';
+   to[1] = 0;
+@@ -2778,11 +2881,13 @@ static inline bool is_innodb_stats_table
+     table_type   - table type, e.g. "MyISAM" or "InnoDB", but also "VIEW"
+     ignore_flag  - what we must particularly ignore - see IGNORE_ defines above
+     real_columns - Contains one byte per column, 0 means unused, 1 is used
+-                   Generated columns are marked as unused
++                   Generated columns are marked as unused. It has MAX_FIELDS
++                   entries; tables exceeding that limit are rejected.
+     column_list  - Contains column list when table has invisible columns.
+ 
+   RETURN
+-    number of fields in table, 0 if error
++    Number of fields in the table, or 0 if a query fails or the table has
++    MAX_FIELDS or more columns.
+ */
+ 
+ static uint get_table_structure(const char *table, char *db, char *table_type,
+@@ -2792,7 +2897,7 @@ static uint get_table_structure(const ch
+   uint64_t num_fields;
+   const char *result_table, *opt_quoted_table;
+   const char *insert_option;
+-  char name_buff[NAME_LEN + 3], table_buff[NAME_LEN * 2 + 3];
++  char name_buff[NAME_LEN * 2 + 3], table_buff[NAME_LEN * 2 + 3];
+   char table_buff2[NAME_LEN * 2 + 3], query_buff[QUERY_LENGTH];
+   const char *show_fields_stmt =
+       "SELECT `COLUMN_NAME` AS `Field`, "
+@@ -3096,6 +3201,14 @@ static uint get_table_structure(const ch
+ 
+     colno = 0;
+     while ((row = mysql_fetch_row(result))) {
++      DBUG_EXECUTE_IF("mysqldump_too_many_columns", colno = MAX_FIELDS;);
++      if (colno >= MAX_FIELDS) {
++        mysql_free_result(result);
++        die(EX_CONSCHECK, "Table '%s' has more than %d columns.", table,
++            MAX_FIELDS);
++        return 0;
++      }
++
+       if (row[SHOW_EXTRA]) {
+         real_columns[colno] =
+             (strcmp(row[SHOW_EXTRA], "STORED GENERATED") != 0 &&
+@@ -3216,6 +3329,13 @@ static uint get_table_structure(const ch
+     while ((row = mysql_fetch_row(result))) {
+       ulong *lengths = mysql_fetch_lengths(result);
+ 
++      if (colno >= MAX_FIELDS) {
++        mysql_free_result(result);
++        die(EX_CONSCHECK, "Table '%s' has more than %d columns.", table,
++            MAX_FIELDS);
++        return 0;
++      }
++
+       if (row[SHOW_EXTRA]) {
+         real_columns[colno] =
+             (strcmp(row[SHOW_EXTRA], "STORED GENERATED") != 0 &&
+@@ -3332,13 +3452,16 @@ static uint get_table_structure(const ch
+ 
+       /* Get MySQL specific create options */
+       if (create_options) {
+-        char show_name_buff[NAME_LEN * 2 + 2 + 24];
++        char show_name_buff[MAX_ESCAPED_LIKE_IDENTIFIER_SIZE];
++        char show_table_status_query[sizeof("show table status like ") +
++                                     MAX_ESCAPED_LIKE_IDENTIFIER_SIZE];
+ 
+-        /* Check memory for quote_for_like() */
+-        snprintf(buff, sizeof(buff), "show table status like %s",
++        snprintf(show_table_status_query, sizeof(show_table_status_query),
++                 "show table status like %s",
+                  quote_for_like(table, show_name_buff));
+ 
+-        if (mysql_query_with_error_report(mysql, &result, buff)) {
++        if (mysql_query_with_error_report(mysql, &result,
++                                          show_table_status_query)) {
+           if (mysql_errno(mysql) != ER_PARSE_ERROR) { /* If old MySQL version */
+             verbose_msg(
+                 "-- Warning: Couldn't get status information for "
+@@ -3398,6 +3521,8 @@ static void dump_trigger_old(FILE *sql_f
+ 
+   DBUG_TRACE;
+ 
++  check_identifier_length((*show_trigger_row)[0], "Trigger");
++
+   if (opt_xml) {
+     print_xml_comment(sql_file, strlen(xml_msg), xml_msg);
+     check_io(sql_file);
+@@ -3526,7 +3651,7 @@ static int dump_trigger(FILE *sql_file,
+ */
+ 
+ static int dump_triggers_for_table(char *table_name, char *db_name) {
+-  char name_buff[NAME_LEN * 4 + 3];
++  char name_buff[MAX_ESCAPED_LIKE_IDENTIFIER_SIZE];
+   char query_buff[QUERY_LENGTH];
+   bool old_ansi_quotes_mode = ansi_quotes_mode;
+   MYSQL_RES *show_triggers_rs;
+@@ -3568,6 +3693,7 @@ static int dump_triggers_for_table(char
+     print_xml_tag(sql_file, "\t", "\n", "triggers", "name=", table_name, NullS);
+ 
+   while ((row = mysql_fetch_row(show_triggers_rs))) {
++    check_identifier_length(row[0], "Trigger");
+     snprintf(query_buff, sizeof(query_buff), "SHOW CREATE TRIGGER %s",
+              quote_name(row[0], name_buff, true));
+ 
+@@ -3779,7 +3905,7 @@ static char *alloc_query_str(size_t size
+ 
+ static void dump_table(char *table, char *db) {
+   char ignore_flag;
+-  char buf[240], table_buff[NAME_LEN + 3];
++  char buf[240], table_buff[NAME_LEN * 2 + 3];
+   DYNAMIC_STRING query_string;
+   DYNAMIC_STRING extended_row;
+   char table_type[NAME_LEN];
+@@ -3795,6 +3921,9 @@ static void dump_table(char *table, char
+   DBUG_TRACE;
+   char *order_by = nullptr;
+ 
++  check_identifier_length(table, "Table");
++  check_identifier_length(db, "Database");
++
+   /*
+     Make sure you get the create table info before the following check for
+     --no-data flag below. Otherwise, the create table info won't be printed.
+@@ -3973,7 +4102,8 @@ static void dump_table(char *table, char
+     }
+ 
+     verbose_msg("-- Retrieving rows...\n");
+-    if (mysql_num_fields(res) != num_fields) {
++    const uint result_num_fields = mysql_num_fields(res);
++    if (result_num_fields != num_fields || result_num_fields > MAX_FIELDS) {
+       fprintf(stderr, "%s: Error in field count for table: %s !  Aborting.\n",
+               my_progname, result_table);
+       error = EX_CONSCHECK;
+@@ -4019,7 +4149,7 @@ static void dump_table(char *table, char
+         check_io(md_result_file);
+       }
+ 
+-      for (i = 0; i < mysql_num_fields(res); i++) {
++      for (i = 0; i < result_num_fields; i++) {
+         int is_blob;
+         ulong length = lengths[i];
+ 
+@@ -4255,7 +4385,10 @@ static char *getTableName(int reset) {
+   if (!res) {
+     if (!(res = mysql_list_tables(mysql, NullS))) return (nullptr);
+   }
+-  if ((row = mysql_fetch_row(res))) return ((char *)row[0]);
++  if ((row = mysql_fetch_row(res))) {
++    check_identifier_length(row[0], "Table");
++    return ((char *)row[0]);
++  }
+ 
+   if (reset)
+     mysql_data_seek(res, 0); /* We want to read again */
+@@ -4772,6 +4905,7 @@ static int dump_all_tables_in_db(char *d
+ 
+   DBUG_TRACE;
+ 
++  check_identifier_length(database, "Database");
+   afterdot = my_stpcpy(hash_key, database);
+   *afterdot++ = '.';
+ 
+@@ -4927,6 +5061,7 @@ static bool dump_all_views_in_db(char *d
+   char hash_key[2 * NAME_LEN + 2]; /* "db.tablename" */
+   char *afterdot;
+ 
++  check_identifier_length(database, "Database");
+   afterdot = my_stpcpy(hash_key, database);
+   *afterdot++ = '.';
+ 
+@@ -4987,12 +5122,10 @@ static char *get_actual_table_name(const
+   char *name = nullptr;
+   MYSQL_RES *table_res;
+   MYSQL_ROW row;
+-  char query[4 * NAME_LEN];
+-  char show_name_buff[FN_REFLEN];
++  char query[sizeof("SHOW TABLES LIKE ") + MAX_ESCAPED_LIKE_IDENTIFIER_SIZE];
++  char show_name_buff[MAX_ESCAPED_LIKE_IDENTIFIER_SIZE];
+   DBUG_TRACE;
+ 
+-  /* Check memory for quote_for_like() */
+-  assert(2 * sizeof(old_table_name) < sizeof(show_name_buff));
+   snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
+            quote_for_like(old_table_name, show_name_buff));
+ 
+@@ -5008,6 +5141,7 @@ static char *get_actual_table_name(const
+       */
+       row = mysql_fetch_row(table_res);
+       lengths = mysql_fetch_lengths(table_res);
++      check_identifier_length(row[0], "Table");
+       name = strmake_root(root, row[0], lengths[0]);
+     }
+     mysql_free_result(table_res);
+@@ -5440,13 +5574,13 @@ static void print_value(FILE *file, MYSQ
+ 
+ char check_if_ignore_table(const char *table_name, char *table_type) {
+   char result = IGNORE_NONE;
+-  char buff[FN_REFLEN + 80], show_name_buff[FN_REFLEN];
++  char buff[sizeof("show table status like ") +
++            MAX_ESCAPED_LIKE_IDENTIFIER_SIZE];
++  char show_name_buff[MAX_ESCAPED_LIKE_IDENTIFIER_SIZE];
+   MYSQL_RES *res = nullptr;
+   MYSQL_ROW row;
+   DBUG_TRACE;
+ 
+-  /* Check memory for quote_for_like() */
+-  assert(2 * sizeof(table_name) < sizeof(show_name_buff));
+   snprintf(buff, sizeof(buff), "show table status like %s",
+            quote_for_like(table_name, show_name_buff));
+   if (mysql_query_with_error_report(mysql, &res, buff)) {
+--- a/cmake/sasl.cmake
++++ b/cmake/sasl.cmake
+@@ -127,21 +127,11 @@ MACRO(FIND_SYSTEM_SASL)
+   ENDIF()
+ ENDMACRO(FIND_SYSTEM_SASL)
+ 
+-# Lookup and copy all plugins
+-#   lib/sasl2/libanonymous.so
+-#   lib/sasl2/libcrammd5.so
+-#   lib/sasl2/libdigestmd5.so
+-#   lib/sasl2/libgs2.so
++# Lookup and copy plugins used by authentication_ldap_sasl
+ #   lib/sasl2/libgssapiv2.so
+-#   lib/sasl2/libplain.so
+ #   lib/sasl2/libscram.so
+ SET(CUSTOM_SASL_PLUGINS
+-  anonymous
+-  crammd5
+-  digestmd5
+-  gs2
+   gssapiv2
+-  plain
+   scram
+   )
+ 
+@@ -197,13 +187,20 @@ MACRO(FIND_CUSTOM_SASL)
+         NO_SYSTEM_ENVIRONMENT_PATH
+         )
+       IF(NOT ${VAR_NAME})
+-        MESSAGE(FATAL_ERROR
++        MESSAGE(WARNING
+         "Could not find plugin lib${SASL_PLUGIN}.so in ${WITH_SASL}/lib/sasl2")
+       ENDIF()
+     ENDFOREACH()
+-    # SCRAM library found, setting SCRAM_LIB_CONFIGURED to 1.
+-    # SCRAM_LIB_CONFIGURED will be used to construct supported SASL methods.
+-    SET(SCRAM_LIB_CONFIGURED 1)
++    IF(NOT SASL_CUSTOM_PLUGIN_gssapiv2 AND NOT SASL_CUSTOM_PLUGIN_scram)
++      MESSAGE(FATAL_ERROR
++        "Could not find any SASL plugin used by authentication_ldap_sasl "
++        "in ${WITH_SASL}/lib/sasl2")
++    ENDIF()
++    IF(SASL_CUSTOM_PLUGIN_scram)
++      # SCRAM library found, setting SCRAM_LIB_CONFIGURED to 1.
++      # SCRAM_LIB_CONFIGURED will be used to construct supported SASL methods.
++      SET(SCRAM_LIB_CONFIGURED 1)
++    ENDIF()
+   ENDIF()
+ 
+   IF(SASL_INCLUDE_DIR)
+@@ -284,9 +281,11 @@ MACRO(MYSQL_CHECK_SASL_DLLS)
+     # On el6, the main library does not depend on krb5, but some plugins do.
+     FOREACH(SASL_PLUGIN ${CUSTOM_SASL_PLUGINS})
+       SET(VAR_NAME "SASL_CUSTOM_PLUGIN_${SASL_PLUGIN}")
+-      FIND_OBJECT_DEPENDENCIES(${${VAR_NAME}} PLUGIN_DEPS)
+-      MESSAGE(STATUS "SASL_PLUGIN ${SASL_PLUGIN} DEPENDS ON ${PLUGIN_DEPS}")
+-      LIST(APPEND SASL_DEPENDS_ON ${PLUGIN_DEPS})
++      IF(${VAR_NAME})
++        FIND_OBJECT_DEPENDENCIES(${${VAR_NAME}} PLUGIN_DEPS)
++        MESSAGE(STATUS "SASL_PLUGIN ${SASL_PLUGIN} DEPENDS ON ${PLUGIN_DEPS}")
++        LIST(APPEND SASL_DEPENDS_ON ${PLUGIN_DEPS})
++      ENDIF()
+     ENDFOREACH()
+     LIST(REMOVE_DUPLICATES SASL_DEPENDS_ON)
+ 
+@@ -313,11 +312,6 @@ MACRO(MYSQL_CHECK_SASL_DLLS)
+           COPIED_LIBRARY_NAME COPIED_TARGET_NAME
+           )
+         ADD_DEPENDENCIES(${sasl_target} ${COPIED_TARGET_NAME})
+-      ELSEIF(SASL_WITHOUT_KERBEROS)
+-        # This should be FATAL_ERROR
+-      ELSE()
+-        MESSAGE(FATAL_ERROR
+-        "Could not find plugin lib${SASL_PLUGIN}.so in ${WITH_SASL}/lib/sasl2")
+       ENDIF()
+     ENDFOREACH()
+   ENDIF()
+--- a/components/audit_api_message_emit/audit_api_message_emit.cc
++++ b/components/audit_api_message_emit/audit_api_message_emit.cc
+@@ -390,7 +390,10 @@ class String_error_handler : public IErr
+   */
+   String_error_handler(char *buffer, size_t size,
+                        unsigned long *out_size = nullptr)
+-      : m_buffer(buffer), m_size(size), m_out_size(out_size) {}
++      : m_buffer(buffer), m_size(size), m_out_size(out_size) {
++    assert(m_buffer);
++    assert(m_size > 0);
++  }
+ 
+   /**
+     Copy message into the buffer.
+@@ -401,9 +404,9 @@ class String_error_handler : public IErr
+       MY_ATTRIBUTE((format(printf, 2, 3))) {
+     va_list va;
+     va_start(va, message);
+-    int copied = vsnprintf(m_buffer, m_size - 1, message, va);
++    const int copied = std::clamp(vsnprintf(m_buffer, m_size, message, va), 0,
++                                  static_cast<int>(m_size) - 1);
+     va_end(va);
+-    m_buffer[copied] = '\0';
+ 
+     if (m_out_size != nullptr) *m_out_size = static_cast<unsigned long>(copied);
+   }
+@@ -504,9 +507,15 @@ static char *emit(UDF_INIT *initid [[may
+       val.value_type = MYSQL_AUDIT_MESSAGE_VALUE_TYPE_STR;
+       val.value.str.str = arguments[1];
+       val.value.str.length = arg_lengths[1];
+-    } else if (arg_res == 1) {
++    } else if (arg_res == 1 && arguments[1] != nullptr) {
+       val.value_type = MYSQL_AUDIT_MESSAGE_VALUE_TYPE_NUM;
+       val.value.num = *reinterpret_cast<long long *>(arguments[1]);
++    } else {
++      assert(arg_res == 1);
++      /* A numeric NULL value is written as a NULL string. */
++      val.value_type = MYSQL_AUDIT_MESSAGE_VALUE_TYPE_STR;
++      val.value.str.str = nullptr;
++      val.value.str.length = 0;
+     }
+ 
+     key_values[key] = val;
+--- a/components/example/test_backup_lock_service.cc
++++ b/components/example/test_backup_lock_service.cc
+@@ -25,8 +25,6 @@
+ #include <mysql/components/service_implementation.h>
+ #include <mysql/components/services/backup_lock_service.h>
+ 
+-#include <stdio.h>
+-
+ extern REQUIRES_SERVICE_PLACEHOLDER(mysql_backup_lock);
+ 
+ /**
+@@ -35,11 +33,15 @@ extern REQUIRES_SERVICE_PLACEHOLDER(mysq
+   @return Operation status
+     @retval 0  Success
+     @retval !=0  Failure
+-*/
++ */
+ 
+ mysql_service_status_t test_backup_lock_service_init() {
+-  return mysql_service_mysql_backup_lock->acquire(
++  const bool acquire_failed = mysql_service_mysql_backup_lock->acquire(
+       nullptr, BACKUP_LOCK_SERVICE_DEFAULT, 100);
++  if (acquire_failed) return 1;
++
++  const bool release_failed = mysql_service_mysql_backup_lock->release(nullptr);
++  return release_failed ? 1 : 0;
+ }
+ 
+ /**
+@@ -48,10 +50,12 @@ mysql_service_status_t test_backup_lock_
+   @return Operation status
+     @retval 0  Success
+     @retval !=0  Failure
+-*/
++ */
+ 
+ mysql_service_status_t test_backup_lock_service_deinit() {
+-  return mysql_service_mysql_backup_lock->release(nullptr);
++  // The backup lock is released during initialization so that acquisition and
++  // release use the same THD.
++  return 0;
+ }
+ 
+ /* An empty list as no service is provided. */
+--- a/components/mysqlbackup/backup_page_tracker.cc
++++ b/components/mysqlbackup/backup_page_tracker.cc
+@@ -40,6 +40,37 @@
+ // defined in mysqlbackup component definition
+ extern char *mysqlbackup_backup_id;
+ 
++/**
++  Validate that a UDF argument list contains the expected number of
++  integer-valued arguments and that each argument has a non-null value
++  pointer.
++
++  This guards UDFs against typed SQL NULL inputs such as
++  `CAST(NULL AS SIGNED)`, which may report `INT_RESULT` in
++  `args->arg_type[]` while still providing a null entry in `args->args[]`.
++
++  @param args       UDF argument descriptor supplied by the server.
++  @param arg_count  Expected number of integer arguments.
++
++  @retval true   The argument list is invalid.
++  @retval false  The argument list is valid.
++*/
++static bool has_invalid_udf_int_args(UDF_ARGS *args, unsigned int arg_count) {
++  if (args->arg_count != arg_count) return true;
++
++  for (unsigned int index = 0; index < arg_count; ++index) {
++    /*
++      Typed SQL NULL values can have INT_RESULT type while args->args[index] is
++      null. Validate the value pointer before any UDF argument dereference.
++    */
++    if (args->arg_type[index] != INT_RESULT || args->args[index] == nullptr) {
++      return true;
++    }
++  }
++
++  return false;
++}
++
+ // Page track system variables
+ bool Backup_page_tracker::m_receive_changed_page_data = false;
+ char *Backup_page_tracker::m_changed_pages_file = nullptr;
+@@ -216,7 +247,7 @@ long long Backup_page_tracker::set_page_
+     return (-1);
+   }
+ 
+-  if (args->arg_count != 1 || args->arg_type[0] != INT_RESULT) {
++  if (has_invalid_udf_int_args(args, 1)) {
+     return (-1);
+   }
+ 
+@@ -312,8 +343,7 @@ long long Backup_page_tracker::page_trac
+     return (-1);
+   }
+ 
+-  if (args->arg_count != 2 || args->arg_type[0] != INT_RESULT ||
+-      args->arg_type[1] != INT_RESULT) {
++  if (has_invalid_udf_int_args(args, 2)) {
+     return (-1);
+   }
+   uint64_t changed_page_count = 0;
+@@ -368,8 +398,7 @@ long long Backup_page_tracker::page_trac
+     return (-1);
+   }
+ 
+-  if (args->arg_count != 2 || args->arg_type[0] != INT_RESULT ||
+-      args->arg_type[1] != INT_RESULT) {
++  if (has_invalid_udf_int_args(args, 2)) {
+     return (-1);
+   }
+ 
+@@ -482,6 +511,10 @@ long long Backup_page_tracker::page_trac
+     return -1;
+   }
+ 
++  if (has_invalid_udf_int_args(args, 1)) {
++    return -1;
++  }
++
+   uint64_t lsn = *((long long *)args->args[0]);
+   int retval =
+       mysql_service_mysql_page_track->purge(thd, PAGE_TRACK_SE_INNODB, &lsn);
+--- a/components/query_attributes/query_attributes.cc
++++ b/components/query_attributes/query_attributes.cc
+@@ -93,7 +93,7 @@ static bool mysql_query_attribute_string
+ 
+   if (args->arg_type[0] != STRING_RESULT) {
+     strcpy(message, "mysql_query_attribute_string() expects a string argument");
+-    return false;
++    return true;
+   }
+   initid->maybe_null = true;
+   initid->max_length = query_attribute_value_max_length;
+@@ -103,7 +103,7 @@ static bool mysql_query_attribute_string
+           const_cast<char *>(query_attribute_return_charset))) {
+     strcpy(message,
+            "mysql_query_attribute_string() failed to set result charset");
+-    return false;
++    return true;
+   }
+ 
+   if (mysql_service_mysql_udf_metadata->argument_set(
+@@ -111,7 +111,7 @@ static bool mysql_query_attribute_string
+           const_cast<char *>(query_attribute_return_charset))) {
+     strcpy(message,
+            "mysql_query_attribute_string() failed to set result charset");
+-    return false;
++    return true;
+   }
+ 
+   initid->ptr = reinterpret_cast<char *>(
+--- a/libbinlogevents/export/binary_log_funcs.h
++++ b/libbinlogevents/export/binary_log_funcs.h
+@@ -29,6 +29,7 @@
+ #ifndef BINARY_LOG_FUNCS_INCLUDED
+ #define BINARY_LOG_FUNCS_INCLUDED
+ 
++#include <stddef.h>
+ #include <stdint.h>
+ #include "field_types.h"  // enum_field_types
+ 
+@@ -56,6 +57,32 @@ unsigned int my_timestamp_binary_length(
+ uint32_t calc_field_size(unsigned char col, const unsigned char *master_data,
+                          unsigned int metadata);
+ 
++enum enum_calc_field_size_status {
++  CALC_FIELD_SIZE_OK = 0,
++  CALC_FIELD_SIZE_TRUNCATED = 1,
++  CALC_FIELD_SIZE_INVALID_TYPE = 2
++};
++
++/**
++  This helper function calculates the size in bytes of a particular field in a
++  row type event, after checking that all bytes read from master_data fit in
++  the available input.
++
++  @param col Field type code
++  @param master_data The field data
++  @param metadata The field metadata
++  @param available Number of bytes available from master_data
++  @param field_size The size in bytes of the field, on success
++
++  @retval CALC_FIELD_SIZE_OK The field size was calculated successfully.
++  @retval CALC_FIELD_SIZE_TRUNCATED The field length prefix or value exceeds
++          the available input.
++  @retval CALC_FIELD_SIZE_INVALID_TYPE The field type or metadata is invalid.
++*/
++enum enum_calc_field_size_status calc_field_size_checked(
++    unsigned char col, const unsigned char *master_data, unsigned int metadata,
++    size_t available, uint32_t *field_size);
++
+ /**
+    Compute the maximum display length of a field.
+ 
+--- a/libbinlogevents/src/binary_log_funcs.cpp
++++ b/libbinlogevents/src/binary_log_funcs.cpp
+@@ -31,6 +31,7 @@
+ #include <stdint.h>
+ #include <string.h>
+ #include <climits>
++#include <cstddef>
+ #include <cstring>
+ 
+ /**
+@@ -209,9 +210,37 @@ int decimal_binary_size(int precision, i
+          frac0 * sizeof(uint32_t) + dig2bytes[frac0x];
+ }
+ 
+-uint32_t calc_field_size(unsigned char col, const unsigned char *master_data,
+-                         unsigned int metadata) {
++static enum_calc_field_size_status read_field_length(
++    const unsigned char *master_data, uint32_t length_bytes, size_t available,
++    bool check_bounds, uint32_t *length) {
++  if (check_bounds && available < length_bytes)
++    return CALC_FIELD_SIZE_TRUNCATED;
++
++  if (length_bytes == 1) {
++    *length = *master_data;
++    return CALC_FIELD_SIZE_OK;
++  }
++
++  uint32_t temp = 0;
++  memcpy(&temp, master_data, length_bytes);
++  *length = le32toh(temp);
++  return CALC_FIELD_SIZE_OK;
++}
++
++static enum_calc_field_size_status add_to_field_length(uint32_t add,
++                                                       bool check_bounds,
++                                                       uint32_t *length) {
++  if (check_bounds && *length > UINT32_MAX - add)
++    return CALC_FIELD_SIZE_TRUNCATED;
++  *length += add;
++  return CALC_FIELD_SIZE_OK;
++}
++
++static enum_calc_field_size_status calc_field_size_internal(
++    unsigned char col, const unsigned char *master_data, unsigned int metadata,
++    size_t available, bool check_bounds, uint32_t *field_size) {
+   uint32_t length = 0;
++  enum_calc_field_size_status status = CALC_FIELD_SIZE_OK;
+ 
+   switch ((col)) {
+     case MYSQL_TYPE_NEWDECIMAL:
+@@ -242,14 +271,12 @@ uint32_t calc_field_size(unsigned char c
+         length = max_display_length_for_field(MYSQL_TYPE_STRING, metadata) > 255
+                      ? 2
+                      : 1;
+-
+-        if (length == 1)
+-          length += *master_data;
+-        else {
+-          uint32_t temp = 0;
+-          memcpy(&temp, master_data, 2);
+-          length = length + le32toh(temp);
+-        }
++        uint32_t data_length = 0;
++        status = read_field_length(master_data, length, available, check_bounds,
++                                   &data_length);
++        if (status != CALC_FIELD_SIZE_OK) return status;
++        status = add_to_field_length(data_length, check_bounds, &length);
++        if (status != CALC_FIELD_SIZE_OK) return status;
+       }
+       break;
+     }
+@@ -334,13 +361,12 @@ uint32_t calc_field_size(unsigned char c
+     }
+     case MYSQL_TYPE_VARCHAR: {
+       length = metadata > 255 ? 2 : 1;
+-      if (length == 1)
+-        length += (uint32_t)*master_data;
+-      else {
+-        uint32_t temp = 0;
+-        memcpy(&temp, master_data, 2);
+-        length = length + le32toh(temp);
+-      }
++      uint32_t data_length = 0;
++      status = read_field_length(master_data, length, available, check_bounds,
++                                 &data_length);
++      if (status != CALC_FIELD_SIZE_OK) return status;
++      status = add_to_field_length(data_length, check_bounds, &length);
++      if (status != CALC_FIELD_SIZE_OK) return status;
+       break;
+     }
+     case MYSQL_TYPE_TINY_BLOB:
+@@ -357,30 +383,44 @@ uint32_t calc_field_size(unsigned char c
+       */
+       switch (metadata) {
+         case 1:
+-          length = *master_data;
+-          break;
+         case 2:
+-          memcpy(&length, master_data, 2);
+-          length = le32toh(length);
+-          break;
+         case 3:
+-          memcpy(&length, master_data, 3);
+-          length = le32toh(length);
+-          break;
+         case 4:
+-          memcpy(&length, master_data, 4);
+-          length = le32toh(length);
++          status = read_field_length(master_data, metadata, available,
++                                     check_bounds, &length);
++          if (status != CALC_FIELD_SIZE_OK) return status;
+           break;
+         default:
+           BAPI_ASSERT(0);  // Should not come here
++          if (check_bounds) return CALC_FIELD_SIZE_INVALID_TYPE;
+           break;
+       }
+ 
+-      length += metadata;
++      status = add_to_field_length(metadata, check_bounds, &length);
++      if (status != CALC_FIELD_SIZE_OK) return status;
+       break;
+     }
+     default:
++      if (check_bounds) return CALC_FIELD_SIZE_INVALID_TYPE;
+       length = UINT_MAX;
+   }
++  if (check_bounds && length > available) return CALC_FIELD_SIZE_TRUNCATED;
++  *field_size = length;
++  return CALC_FIELD_SIZE_OK;
++}
++
++uint32_t calc_field_size(unsigned char col, const unsigned char *master_data,
++                         unsigned int metadata) {
++  uint32_t length = 0;
++  (void)calc_field_size_internal(col, master_data, metadata, 0, false, &length);
+   return length;
+ }
++
++enum enum_calc_field_size_status calc_field_size_checked(
++    unsigned char col, const unsigned char *master_data, unsigned int metadata,
++    size_t available, uint32_t *field_size) {
++  if (field_size == nullptr) return CALC_FIELD_SIZE_INVALID_TYPE;
++  *field_size = 0;
++  return calc_field_size_internal(col, master_data, metadata, available, true,
++                                  field_size);
++}
+--- a/libbinlogevents/src/statement_events.cpp
++++ b/libbinlogevents/src/statement_events.cpp
+@@ -408,14 +408,14 @@ int Query_event::fill_data_buf(Log_event
+ 
+ User_var_event::User_var_event(const char *buf,
+                                const Format_description_event *fde)
+-    : Binary_log_event(&buf, fde) {
++    : Binary_log_event(&buf, fde), name(nullptr) {
+   BAPI_ENTER("User_var_event::User_var_event(const char*, ...)");
+   READER_TRY_INITIALIZATION;
+   READER_ASSERT_POSITION(fde->common_header_len);
+   READER_TRY_CALL(forward, fde->post_header_len[USER_VAR_EVENT - 1]);
+ 
+   READER_TRY_SET(name_len, read<uint32_t>);
+-  if (name_len == 0) READER_THROW("Invalid name length");
++  if (name_len == 0 || name_len > NAME_LEN) READER_THROW("Invalid name length");
+   name = READER_CALL(strndup<const char *>, name_len);
+   READER_TRY_SET(is_null, read<uint8_t>);
+ 
+--- a/libbinlogstandalone/src/CMakeLists.txt
++++ b/libbinlogstandalone/src/CMakeLists.txt
+@@ -22,6 +22,7 @@
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+ 
+ SET(REPLICATION_SOURCES
++  ${CMAKE_SOURCE_DIR}/libbinlogevents/src/binary_log_funcs.cpp
+   ${CMAKE_SOURCE_DIR}/libbinlogevents/src/binlog_event.cpp
+   ${CMAKE_SOURCE_DIR}/libbinlogevents/src/buffer/grow_calculator.cpp
+   ${CMAKE_SOURCE_DIR}/libbinlogevents/src/buffer/grow_constraint.cpp
+--- a/libmysql/authentication_fido/fido_assertion.cc
++++ b/libmysql/authentication_fido/fido_assertion.cc
+@@ -29,10 +29,46 @@
+ #include "fido_assertion.h"
+ #include "fido_common.h"
+ 
++#include <cstdint>
++#include <limits>
++
+ #include "mysql_com.h" /* CHALLENGE_LENGTH */
+ 
+ using namespace std;
+ 
++namespace {
++size_t fido_net_field_length_size(const unsigned char *pos) {
++  if (*pos <= 251) return 1;
++  if (*pos == 252) return 3;
++  if (*pos == 253) return 4;
++  return 9;
++}
++
++bool read_length_encoded_data(const unsigned char **pos,
++                              const unsigned char *end,
++                              const unsigned char **data, size_t *len,
++                              size_t min_len, size_t max_len) {
++  if (*pos >= end) return true;
++
++  const size_t length_size = fido_net_field_length_size(*pos);
++  if (static_cast<size_t>(end - *pos) < length_size) return true;
++
++  auto *mutable_pos = const_cast<unsigned char *>(*pos);
++  const uint64_t decoded_len = net_field_length_ll(&mutable_pos);
++  if (decoded_len == static_cast<uint64_t>(NULL_LENGTH) ||
++      decoded_len < min_len || decoded_len > max_len)
++    return true;
++
++  if (static_cast<uint64_t>(end - mutable_pos) < decoded_len) return true;
++
++  *data = mutable_pos;
++  *len = static_cast<size_t>(decoded_len);
++  mutable_pos += *len;
++  *pos = mutable_pos;
++  return false;
++}
++}  // namespace
++
+ /**
+   Construcutor to allocate memory for performing assertion (authentication)
+ */
+@@ -49,37 +85,37 @@ fido_prepare_assert::~fido_prepare_asser
+   name and set it in fido_assert_t.
+ 
+   @param [in] challenge       buffer holding the server challenge
++  @param [in] challenge_len   length of the server challenge
+ 
+   @retval false received challenge was valid
+   @retval true  received challenge was corrupt
+ */
+-bool fido_prepare_assert::parse_challenge(const unsigned char *challenge) {
+-  char *str = nullptr;
+-  unsigned char *to = const_cast<unsigned char *>(challenge);
+-  /* length of challenge should be 32 bytes */
+-  unsigned long len = net_field_length_ll(&to);
+-  if (len != CHALLENGE_LENGTH) goto err;
+-  /* extract challenge */
+-  set_scramble(to, len);
+-
+-  to += len;
+-  /* length of relying party ID */
+-  len = net_field_length_ll(&to);
+-  /* Length of relying party ID should not be > 255 */
+-  if (len > 255) goto err;
+-  /* extract relying party ID */
+-  str = new (std::nothrow) char[len + 1];
+-  memcpy(str, to, len);
+-  str[len] = 0;
+-  set_rp_id(str);
+-  delete[] str;
+-
+-  to += len;
+-  /* length of cred ID */
+-  len = net_field_length_ll(&to);
+-  /* extract cred ID */
+-  set_cred_id(to, len);
+-  to += len;
++bool fido_prepare_assert::parse_challenge(const unsigned char *challenge,
++                                          size_t challenge_len) {
++  if (!challenge) return true;
++
++  const unsigned char *to = challenge;
++  const unsigned char *end = challenge + challenge_len;
++  const unsigned char *data = nullptr;
++  size_t len = 0;
++
++  if (read_length_encoded_data(&to, end, &data, &len, CHALLENGE_LENGTH,
++                               CHALLENGE_LENGTH))
++    goto err;
++  set_scramble(data, len);
++
++  if (read_length_encoded_data(&to, end, &data, &len, 0,
++                               RELYING_PARTY_ID_LENGTH))
++    goto err;
++  {
++    string str(reinterpret_cast<const char *>(data), len);
++    set_rp_id(str.c_str());
++  }
++
++  if (read_length_encoded_data(&to, end, &data, &len, 0,
++                               numeric_limits<size_t>::max()))
++    goto err;
++  set_cred_id(data, len);
+ 
+   return false;
+ 
+@@ -140,20 +176,28 @@ end:
+ 
+   @param [out] challenge_res     buffer to signed challenge
+   @param [out] challenge_res_len length of signed challenge
++
++  @retval false success
++  @retval true  allocation failed
+ */
+-void fido_prepare_assert::get_signed_challenge(unsigned char **challenge_res,
++bool fido_prepare_assert::get_signed_challenge(unsigned char **challenge_res,
+                                                size_t &challenge_res_len) {
+   unsigned long authdata_len = get_authdata_len();
+   unsigned long sig_len = get_signature_len();
+   challenge_res_len = net_length_size(authdata_len) + net_length_size(sig_len) +
+                       authdata_len + sig_len;
+   *challenge_res = new (std::nothrow) unsigned char[challenge_res_len];
++  if (!*challenge_res) {
++    challenge_res_len = 0;
++    return true;
++  }
+   unsigned char *pos = *challenge_res;
+   pos = net_store_length(pos, authdata_len);
+   memcpy(pos, get_authdata_ptr(), authdata_len);
+   pos += authdata_len;
+   pos = net_store_length(pos, sig_len);
+   memcpy(pos, get_signature_ptr(), sig_len);
++  return false;
+ }
+ 
+ /**
+@@ -162,7 +206,8 @@ void fido_prepare_assert::get_signed_cha
+   @param [in] scramble   buffer holding random salt
+   @param [in] len        length of salt
+ */
+-void fido_prepare_assert::set_scramble(unsigned char *scramble, size_t len) {
++void fido_prepare_assert::set_scramble(const unsigned char *scramble,
++                                       size_t len) {
+   fido_assert_set_clientdata_hash(m_assert, scramble, len);
+ }
+ 
+@@ -172,7 +217,7 @@ void fido_prepare_assert::set_scramble(u
+   @param [in] cred   buffer holding credential ID
+   @param [in] len    length of credential ID
+ */
+-void fido_prepare_assert::set_cred_id(unsigned char *cred, size_t len) {
++void fido_prepare_assert::set_cred_id(const unsigned char *cred, size_t len) {
+   fido_assert_allow_cred(m_assert, cred, len);
+ }
+ 
+@@ -224,8 +269,9 @@ size_t fido_prepare_assert::get_signatur
+ /**
+   Helper method to prepare all context required to perform assertion.
+ */
+-bool fido_assertion::prepare_assert(const unsigned char *challenge) {
+-  return m_fido_prepare_assert.parse_challenge(challenge);
++bool fido_assertion::prepare_assert(const unsigned char *challenge,
++                                    size_t challenge_len) {
++  return m_fido_prepare_assert.parse_challenge(challenge, challenge_len);
+ }
+ 
+ /**
+@@ -241,7 +287,8 @@ bool fido_assertion::sign_challenge() {
+ /**
+   Helper method to prepare challenge response to be passed to server
+ */
+-void fido_assertion::get_signed_challenge(unsigned char **challenge_res,
++bool fido_assertion::get_signed_challenge(unsigned char **challenge_res,
+                                           size_t &challenge_res_len) {
+-  m_fido_prepare_assert.get_signed_challenge(challenge_res, challenge_res_len);
++  return m_fido_prepare_assert.get_signed_challenge(challenge_res,
++                                                    challenge_res_len);
+ }
+--- a/libmysql/authentication_fido/fido_assertion.h
++++ b/libmysql/authentication_fido/fido_assertion.h
+@@ -39,16 +39,16 @@ class fido_prepare_assert {
+  public:
+   fido_prepare_assert();
+   ~fido_prepare_assert();
+-  bool parse_challenge(const unsigned char *challenge);
++  bool parse_challenge(const unsigned char *challenge, size_t challenge_len);
+   bool sign_challenge();
+-  void get_signed_challenge(unsigned char **challenge_res,
++  bool get_signed_challenge(unsigned char **challenge_res,
+                             size_t &challenge_res_len);
+ 
+  private:
+   /* set client data has */
+-  void set_scramble(unsigned char *scramble, size_t len);
++  void set_scramble(const unsigned char *scramble, size_t len);
+   /* set credential ID */
+-  void set_cred_id(unsigned char *cred, size_t len);
++  void set_cred_id(const unsigned char *cred, size_t len);
+   /* set relying party ID */
+   void set_rp_id(const char *rp_id);
+ 
+@@ -73,13 +73,13 @@ class fido_prepare_assert {
+ */
+ class fido_assertion {
+  public:
+-  bool prepare_assert(const unsigned char *challenge);
++  bool prepare_assert(const unsigned char *challenge, size_t challenge_len);
+   bool sign_challenge();
+-  void get_signed_challenge(unsigned char **challenge_res,
++  bool get_signed_challenge(unsigned char **challenge_res,
+                             size_t &challenge_res_len);
+ 
+  private:
+   fido_prepare_assert m_fido_prepare_assert;
+ };
+ 
+-#endif  // FIDO_ASSERTION_H_
+\ No newline at end of file
++#endif  // FIDO_ASSERTION_H_
+--- a/libmysql/authentication_fido/fido_client_plugin.cc
++++ b/libmysql/authentication_fido/fido_client_plugin.cc
+@@ -139,6 +139,7 @@ static int fido_auth_client(MYSQL_PLUGIN
+ 
+   /** Get the challenge from the MySQL server. */
+   server_challenge_len = vio->read_packet(vio, &server_challenge);
++  if (server_challenge_len < 0) return true;
+   if (server_challenge_len == 0) {
+     /*
+       an empty packet means registration step is pending, thus for now allow
+@@ -161,12 +162,16 @@ static int fido_auth_client(MYSQL_PLUGIN
+ #endif
+   {
+     fido_assertion *fa = new fido_assertion();
+-    if (fa->prepare_assert(server_challenge) || fa->sign_challenge()) {
++    if (fa->prepare_assert(server_challenge, server_challenge_len) ||
++        fa->sign_challenge()) {
+       delete fa;
+       return true;
+     }
+     /* copy signed challenge into buff */
+-    fa->get_signed_challenge(&buff, length);
++    if (fa->get_signed_challenge(&buff, length)) {
++      delete fa;
++      return true;
++    }
+     /* send signed challenge to fido server plugin */
+     vio->write_packet(vio, buff, length);
+     delete fa;
+--- a/libmysql/libmysql.cc
++++ b/libmysql/libmysql.cc
+@@ -2622,9 +2622,16 @@ bool STDCALL mysql_stmt_send_long_data(M
+   and no-conversion fetching.
+ */
+ 
+-static void read_binary_time(MYSQL_TIME *tm, uchar **pos) {
++static bool read_binary_time(MYSQL_TIME *tm, uchar **pos) {
+   /* net_field_length will set pos to the first byte of data */
+   uint length = net_field_length(pos);
++  DBUG_EXECUTE_IF("simulate_malformed_binary_time_length", { length = 1; });
++
++  if (!(length == 0 || length == 8 || length == 12)) {
++    set_zero_time(tm, MYSQL_TIMESTAMP_TIME);
++    *pos += length;
++    return true;
++  }
+ 
+   if (length) {
+     uchar *to = *pos;
+@@ -2646,11 +2653,21 @@ static void read_binary_time(MYSQL_TIME
+     *pos += length;
+   } else
+     set_zero_time(tm, MYSQL_TIMESTAMP_TIME);
++
++  return false;
+ }
+ 
+-static void read_binary_datetime(MYSQL_TIME *tm, uchar **pos) {
++static bool read_binary_datetime(MYSQL_TIME *tm, uchar **pos) {
+   uint length = net_field_length(pos);
+ 
++  DBUG_EXECUTE_IF("simulate_malformed_binary_datetime_length", { length = 1; });
++
++  if (!(length == 0 || length == 4 || length == 7 || length == 11)) {
++    set_zero_time(tm, MYSQL_TIMESTAMP_DATETIME);
++    *pos += length;
++    return true;
++  }
++
+   if (length) {
+     uchar *to = *pos;
+ 
+@@ -2671,11 +2688,21 @@ static void read_binary_datetime(MYSQL_T
+     *pos += length;
+   } else
+     set_zero_time(tm, MYSQL_TIMESTAMP_DATETIME);
++
++  return false;
+ }
+ 
+-static void read_binary_date(MYSQL_TIME *tm, uchar **pos) {
++static bool read_binary_date(MYSQL_TIME *tm, uchar **pos) {
+   uint length = net_field_length(pos);
+ 
++  DBUG_EXECUTE_IF("simulate_malformed_binary_date_length", { length = 1; });
++
++  if (!(length == 0 || length == 4)) {
++    set_zero_time(tm, MYSQL_TIMESTAMP_DATE);
++    *pos += length;
++    return true;
++  }
++
+   if (length) {
+     uchar *to = *pos;
+     tm->year = (uint)sint2korr(to);
+@@ -2690,6 +2717,8 @@ static void read_binary_date(MYSQL_TIME
+     *pos += length;
+   } else
+     set_zero_time(tm, MYSQL_TIMESTAMP_DATE);
++
++  return false;
+ }
+ 
+ /*
+@@ -3201,14 +3230,20 @@ static void fetch_result_with_conversion
+     case MYSQL_TYPE_DATE: {
+       MYSQL_TIME tm;
+ 
+-      read_binary_date(&tm, row);
++      if (read_binary_date(&tm, row)) {
++        *param->error = true;
++        break;
++      }
+       fetch_datetime_with_conversion(param, field, &tm);
+       break;
+     }
+     case MYSQL_TYPE_TIME: {
+       MYSQL_TIME tm;
+ 
+-      read_binary_time(&tm, row);
++      if (read_binary_time(&tm, row)) {
++        *param->error = true;
++        break;
++      }
+       fetch_datetime_with_conversion(param, field, &tm);
+       break;
+     }
+@@ -3216,7 +3251,10 @@ static void fetch_result_with_conversion
+     case MYSQL_TYPE_TIMESTAMP: {
+       MYSQL_TIME tm;
+ 
+-      read_binary_datetime(&tm, row);
++      if (read_binary_datetime(&tm, row)) {
++        *param->error = true;
++        break;
++      }
+       fetch_datetime_with_conversion(param, field, &tm);
+       break;
+     }
+@@ -3305,22 +3343,22 @@ static void fetch_result_double(MYSQL_BI
+ static void fetch_result_time(MYSQL_BIND *param,
+                               MYSQL_FIELD *field [[maybe_unused]],
+                               uchar **row) {
+-  MYSQL_TIME *tm = (MYSQL_TIME *)param->buffer;
+-  read_binary_time(tm, row);
++  auto *tm = (MYSQL_TIME *)param->buffer;
++  *param->error = read_binary_time(tm, row);
+ }
+ 
+ static void fetch_result_date(MYSQL_BIND *param,
+                               MYSQL_FIELD *field [[maybe_unused]],
+                               uchar **row) {
+-  MYSQL_TIME *tm = (MYSQL_TIME *)param->buffer;
+-  read_binary_date(tm, row);
++  auto *tm = (MYSQL_TIME *)param->buffer;
++  *param->error = read_binary_date(tm, row);
+ }
+ 
+ static void fetch_result_datetime(MYSQL_BIND *param,
+                                   MYSQL_FIELD *field [[maybe_unused]],
+                                   uchar **row) {
+-  MYSQL_TIME *tm = (MYSQL_TIME *)param->buffer;
+-  read_binary_datetime(tm, row);
++  auto *tm = (MYSQL_TIME *)param->buffer;
++  *param->error = read_binary_datetime(tm, row);
+ }
+ 
+ static void fetch_result_bin(MYSQL_BIND *param,
+--- /dev/null
++++ b/mysql-test/extra/rpl_tests/rpl_gtid_xa_second_phase_recover_after_gtid_action_crash.inc
+@@ -0,0 +1,163 @@
++# Common test body for XA COMMIT/XA ROLLBACK crash recovery after the
++# before-GTID state-update actions ran and before GTID state update itself.
++#
++# Parameters:
++# $replica_has_binlog
++#   1 when the replica runs with binary logging enabled, 0 otherwise.
++
++if ($replica_has_binlog == '') {
++  --die ERROR IN TEST: replica_has_binlog must be set
++}
++
++--source include/have_binlog_format_row.inc
++--source include/not_valgrind.inc
++--source include/have_debug.inc
++--source include/have_debug_sync.inc
++--source include/master-slave.inc
++
++if ($replica_has_binlog == 0) {
++  --source include/rpl_connection_slave.inc
++  CALL mtr.add_suppression("You need to use --log-bin to make --binlog-format work");
++}
++
++--source include/rpl_connection_master.inc
++--let $xid_data = xid_setup
++--let $xid = `SELECT CONCAT("X'", LOWER(HEX('$xid_data')), "',X'',1")`
++--source extra/xa_crash_safe_tests/setup.inc
++--source include/sync_slave_sql_with_master.inc
++
++--source include/rpl_connection_master1.inc
++--let $xid_data = xid_commit
++--let $xid = `SELECT CONCAT("X'", LOWER(HEX('$xid_data')), "',X'',1")`
++--eval XA START $xid
++INSERT INTO t1 VALUES (1);
++--eval XA END $xid
++--eval XA PREPARE $xid
++
++--source include/rpl_connection_master.inc
++--source include/sync_slave_sql_with_master.inc
++--let $expected_prepared_xa_count = 1
++--source extra/xa_crash_safe_tests/assert_xa_recover.inc
++--let $before_gtid_executed = `SELECT @@GLOBAL.gtid_executed`
++--source include/rpl_connection_master.inc
++--let $source_gtid_executed_before_second_phase = `SELECT @@GLOBAL.gtid_executed`
++
++--let $auxiliary_connection = slave
++--let $statement_connection = master1
++--let $statement = XA COMMIT $xid
++--let $sync_point = after_call_actions_before_gtid_state_update
++--source include/execute_to_conditional_timestamp_sync_point.inc
++
++--source include/rpl_connection_slave.inc
++--let $expected_prepared_xa_count = 0
++--source extra/xa_crash_safe_tests/assert_xa_recover.inc
++--error ER_XAER_DUPID
++--eval XA START $xid
++
++--source include/rpl_connection_master.inc
++--let $source_gtid_executed_after_second_phase = `SELECT @@GLOBAL.gtid_executed`
++--let $second_phase_gtid = `SELECT GTID_SUBTRACT('$source_gtid_executed_after_second_phase', '$source_gtid_executed_before_second_phase')`
++--let $assert_text = XA second-phase GTID must be non-empty
++--let $assert_cond = "$second_phase_gtid" != ""
++--source include/assert.inc
++
++--source include/rpl_connection_slave.inc
++--source include/dbug_crash_safe.inc
++
++if ($replica_has_binlog == 0) {
++  --let $restart_parameters=restart:--skip-replica-start --skip-log-bin --log-replica-updates=0
++}
++if ($replica_has_binlog == 1) {
++  --let $restart_parameters=restart:--skip-replica-start
++}
++--source include/start_mysqld.inc
++--let $rpl_server_number= 2
++--source include/rpl_reconnect.inc
++
++--source include/rpl_connection_slave.inc
++--let $after_gtid_executed = `SELECT @@GLOBAL.gtid_executed`
++--let $assert_text = GTID_EXECUTED has been updated after XA COMMIT recovery
++--let $assert_cond = "$before_gtid_executed" != "$after_gtid_executed"
++--source include/assert.inc
++--let $assert_text = GTID_EXECUTED contains the recovered XA COMMIT GTID
++--let $has_second_phase_gtid = `SELECT GTID_SUBSET('$second_phase_gtid', @@GLOBAL.gtid_executed)`
++--let $assert_cond = "$has_second_phase_gtid" = "1"
++--source include/assert.inc
++
++--let $expected_prepared_xa_count = 0
++--source extra/xa_crash_safe_tests/assert_xa_recover.inc
++
++--let $expected_row_count = 2
++--source extra/xa_crash_safe_tests/assert_row_count.inc
++
++--source include/start_slave.inc
++
++--source include/rpl_connection_master1.inc
++--let $xid_data = xid_rollback
++--let $xid = `SELECT CONCAT("X'", LOWER(HEX('$xid_data')), "',X'',1")`
++--eval XA START $xid
++INSERT INTO t1 VALUES (3);
++--eval XA END $xid
++--eval XA PREPARE $xid
++
++--source include/rpl_connection_master.inc
++--source include/sync_slave_sql_with_master.inc
++--let $expected_prepared_xa_count = 1
++--source extra/xa_crash_safe_tests/assert_xa_recover.inc
++--let $before_gtid_executed = `SELECT @@GLOBAL.gtid_executed`
++--source include/rpl_connection_master.inc
++--let $source_gtid_executed_before_second_phase = `SELECT @@GLOBAL.gtid_executed`
++
++--let $auxiliary_connection = slave
++--let $statement_connection = master1
++--let $statement = XA ROLLBACK $xid
++--let $sync_point = after_call_actions_before_gtid_state_update
++--source include/execute_to_conditional_timestamp_sync_point.inc
++
++--source include/rpl_connection_slave.inc
++--let $expected_prepared_xa_count = 0
++--source extra/xa_crash_safe_tests/assert_xa_recover.inc
++--error ER_XAER_DUPID
++--eval XA START $xid
++
++--source include/rpl_connection_master.inc
++--let $source_gtid_executed_after_second_phase = `SELECT @@GLOBAL.gtid_executed`
++--let $second_phase_gtid = `SELECT GTID_SUBTRACT('$source_gtid_executed_after_second_phase', '$source_gtid_executed_before_second_phase')`
++--let $assert_text = XA second-phase GTID must be non-empty
++--let $assert_cond = "$second_phase_gtid" != ""
++--source include/assert.inc
++
++--source include/rpl_connection_slave.inc
++--source include/dbug_crash_safe.inc
++
++if ($replica_has_binlog == 0) {
++  --let $restart_parameters=restart:--skip-replica-start --skip-log-bin --log-replica-updates=0
++}
++if ($replica_has_binlog == 1) {
++  --let $restart_parameters=restart:--skip-replica-start
++}
++--source include/start_mysqld.inc
++--let $rpl_server_number= 2
++--source include/rpl_reconnect.inc
++
++--source include/rpl_connection_slave.inc
++--let $after_gtid_executed = `SELECT @@GLOBAL.gtid_executed`
++--let $assert_text = GTID_EXECUTED has been updated after XA ROLLBACK recovery
++--let $assert_cond = "$before_gtid_executed" != "$after_gtid_executed"
++--source include/assert.inc
++--let $assert_text = GTID_EXECUTED contains the recovered XA ROLLBACK GTID
++--let $has_second_phase_gtid = `SELECT GTID_SUBSET('$second_phase_gtid', @@GLOBAL.gtid_executed)`
++--let $assert_cond = "$has_second_phase_gtid" = "1"
++--source include/assert.inc
++
++--let $expected_prepared_xa_count = 0
++--source extra/xa_crash_safe_tests/assert_xa_recover.inc
++
++--let $expected_row_count = 2
++--source extra/xa_crash_safe_tests/assert_row_count.inc
++
++--source include/start_slave.inc
++
++--source include/rpl_connection_master.inc
++DROP TABLE t1;
++--source include/rpl_end.inc
+--- a/mysql-test/extra/xa_crash_safe_tests/setup.inc
++++ b/mysql-test/extra/xa_crash_safe_tests/setup.inc
+@@ -23,6 +23,7 @@
+ # - mysql-test/t/xa_prepare_failure_before_prepare_2nd_phase.test
+ # - mysql-test/t/xa_prepare_failure_before_prepare_in_engines.test
+ # - mysql-test/t/xa_prepare_failure_before_prepare_tc.test
++# - mysql-test/t/xa_prepare_recover_after_gtid_action_crash.test
+ # - mysql-test/t/xa_rollback_failure_before_gtid_externalization.test
+ # - mysql-test/t/xa_rollback_failure_before_rollback_engines.test
+ # - mysql-test/t/xa_rollback_failure_before_rollback_tc.test
+@@ -78,10 +79,14 @@
+ # - mysql-test/suite/rpl_gtid/t/rpl_gtid_xa_commit_one_phase_failure_before_gtid_externalization.test
+ # - mysql-test/suite/rpl_gtid/t/rpl_gtid_xa_commit_one_phase_failure_before_prepare_in_engines.test
+ # - mysql-test/suite/rpl_gtid/t/rpl_gtid_xa_commit_one_phase_failure_before_write_binlog.test
++# - mysql-test/suite/rpl_gtid/t/rpl_gtid_xa_second_phase_recover_after_gtid_action_crash.test
++# - mysql-test/suite/rpl_gtid/t/rpl_gtid_xa_second_phase_recover_after_gtid_action_crash_nobinlog.test
+ # - mysql-test/suite/rpl_gtid/t/rpl_gtid_xa_prepare_failure_before_gtid_externalization.test
+ # - mysql-test/suite/rpl_gtid/t/rpl_gtid_xa_prepare_failure_before_prepare_2nd_phase.test
+ # - mysql-test/suite/rpl_gtid/t/rpl_gtid_xa_prepare_failure_before_prepare_in_engines.test
+ # - mysql-test/suite/rpl_gtid/t/rpl_gtid_xa_prepare_failure_before_write_binlog.test
++# - mysql-test/suite/rpl_gtid/t/rpl_gtid_xa_prepare_recover_after_gtid_action_crash.test
++# - mysql-test/suite/rpl_gtid/t/rpl_gtid_xa_prepare_recover_after_gtid_action_crash_nobinlog.test
+ # - mysql-test/suite/rpl_gtid/t/rpl_gtid_xa_rollback_failure_after_rotate.test
+ # - mysql-test/suite/rpl_gtid/t/rpl_gtid_xa_rollback_failure_before_gtid_externalization.test
+ # - mysql-test/suite/rpl_gtid/t/rpl_gtid_xa_rollback_failure_before_rollback_engines.test
+--- a/mysql-test/include/trigger_function_lock_compare.inc
++++ b/mysql-test/include/trigger_function_lock_compare.inc
+@@ -128,9 +128,11 @@ while ($isolation_levels)
+             --let $need_locks_data=1
+             # wait a little to not cause furious spinning and allow for release of latches on page, if any
+             --sleep 1
+-            # Try to bring back the pages into buffer pool using a non-locking SELECT, if they were missing
++            # Try to bring back the pages into buffer pool using non-locking
++            # scans of both indexes, if they were missing.
+             --disable_result_log
+-            SELECT * FROM t1;
++            SELECT id FROM t1 FORCE INDEX(PRIMARY);
++            SELECT val FROM t1 FORCE INDEX(idx_val);
+             --enable_result_log
+           }
+         }
+--- a/mysql-test/include/wait_for_xa_prepared_count.inc
++++ /dev/null
+@@ -1,59 +0,0 @@
+-# ==== Purpose ====
+-#
+-# Wait until the number of prepared XA transactions equals the given number.
+-# The number of prepared XA transactions is given by the size of the result set
+-# for XA RECOVER.
+-#
+-# Note: When the server executes XA PREPARE, it externalizes the XID after the
+-# GTID. Therefore, a test that uses e.g. sync_to_replica.inc to wait until the
+-# replica has applied an XA PREPARE transaction, may not immediately observe the
+-# XID. So, for example, a subsequent XA COMMIT on the replica may fail because
+-# it does not find the XID. To solve this problem use this script to wait for
+-# the XID to be externalized.
+-#
+-# ==== Usage ====
+-#
+-# --let $xa_prepared_count = INTEGER
+-# [--let $slave_timeout = SECONDS]
+-# --source include/wait_for_xa_prepared_count.inc
+-#
+-# $xa_prepared_count
+-#   The expected line count return by `XA RECOVER`
+-#
+-# $slave_timeout
+-#   The number of seconds to wait until failing with timeout. Defaults to 300.
+-#   We use this name in order to be compatible with include/rpl/wait_for_*.inc,
+-#   so that users that need to set a timeout for any wait in their test can use
+-#   a single variable.
+-
+---let $include_filename = wait_for_xa_prepared_count.inc
+---source include/begin_include_file.inc
+-
+---let $_wfxpc_timeout = $slave_timeout
+-if (!$_wfxpc_timeout) {
+-  --let $_wfxpc_timeout = 300
+-}
+---let $ten = 10
+---expr $_wfxpc_remaining_iterations = $_wfxpc_timeout * $ten
+-
+-while ($_wfxpc_remaining_iterations) {
+-  --let $statement = XA RECOVER
+-  --let $column = data
+-  --source include/get_row_count.inc
+-  if ($row_count == $xa_prepared_count) {
+-    --let $_wfxpc_remaining_iterations = 0
+-  }
+-  if ($row_count != $xa_prepared_count) {
+-    --sleep 0.1
+-    --dec $_wfxpc_remaining_iterations
+-    if ($_wfxpc_remaining_iterations == 0) {
+-      --source include/show_rpl_debug_info.inc
+-      --echo Timeout after $_wfxpc_timeout seconds in wait_for_xa_prepared_count.inc
+-      --echo Expected $xa_prepared_count prepared transactions, but this is what we have:
+-      XA RECOVER;
+-    }
+-  }
+-}
+-
+---let $include_filename = wait_for_xa_prepared_count.inc
+---source include/end_include_file.inc
+--- a/mysql-test/r/component_backup_lock_service.result
++++ b/mysql-test/r/component_backup_lock_service.result
+@@ -1,17 +1,31 @@
++#
++# Bug#39838521: TEST_BACKUP_LOCK_SERVICE COMPONENT GETS STUCK ON UNINSTALL
++#
+ INSTALL COMPONENT "file://component_test_backup_lock_service";
+-# The component component_test_backup_lock_service acquires BACKUP LOCK
+-# during its initialization. Check that BACKUP LOCK has been really acquired.
++# The component component_test_backup_lock_service acquires and releases
++# BACKUP LOCK during its initialization. Check that BACKUP LOCK has
++# been really released.
+ SELECT object_type, object_schema, object_name, lock_type, lock_duration, lock_status
+ FROM performance_schema.metadata_locks WHERE object_type = 'BACKUP LOCK';
+ object_type	object_schema	object_name	lock_type	lock_duration	lock_status
+-BACKUP LOCK	NULL	NULL	SHARED	EXPLICIT	GRANTED
+-# Stop component.
++# Stop component from another session.
++SET SESSION lock_wait_timeout=1;
+ UNINSTALL COMPONENT "file://component_test_backup_lock_service";
+-# The component component_test_backup_lock_service releases BACKUP LOCK
+-# during its unloading. Check that BACKUP LOCK has been really released.
++# Check that BACKUP LOCK has not leaked after unloading.
+ SELECT object_schema, object_name, lock_type, lock_duration, lock_status
+ FROM performance_schema.metadata_locks WHERE object_type = 'BACKUP LOCK';
+ object_schema	object_name	lock_type	lock_duration	lock_status
++# Verify that deinitialization does not release a BACKUP LOCK owned by
++# the uninstalling session.
++INSTALL COMPONENT "file://component_test_backup_lock_service";
++LOCK INSTANCE FOR BACKUP;
++UNINSTALL COMPONENT "file://component_test_backup_lock_service";
++SELECT lock_type, lock_duration, lock_status
++FROM performance_schema.metadata_locks
++WHERE object_type = 'BACKUP LOCK' AND lock_type = 'SHARED';
++lock_type	lock_duration	lock_status
++SHARED	EXPLICIT	GRANTED
++UNLOCK INSTANCE;
+ #
+ # Bug#33087212: COMPONENT COMPONENT_TEST_BACKUP_LOCK_SERVICE CAUSES
+ # CRASH AT SHUTDOWN.
+@@ -23,9 +37,7 @@ INSTALL COMPONENT 'file://component_test
+ # restart the server.
+ INSTALL COMPONENT 'file://component_test_backup_lock_service';
+ ERROR HY000: Cannot load component from specified URN: 'file://component_test_backup_lock_service'.
+-# Check for the presence of BACKUP LOCK. There should not be one
+-# since the lock is not re-acquired when the component is reloaded
+-# as part of boot.
++# Check for the presence of BACKUP LOCK. There should not be one.
+ SELECT object_schema, object_name, lock_type, lock_duration, lock_status
+ FROM performance_schema.metadata_locks WHERE object_type = 'BACKUP LOCK';
+ object_schema	object_name	lock_type	lock_duration	lock_status
+--- a/mysql-test/r/derived.result
++++ b/mysql-test/r/derived.result
+@@ -4734,3 +4734,47 @@ Cat2	5
+ Cat2	7
+ NULL	NULL
+ DROP TABLE t1;
++#
++# Bug#36492739: When CTE table is materialized, automatically-created
++#               keys cannot be found
++#
++# A CTE referenced from two query blocks (outer SELECT + scalar subquery)
++# gets two auto-generated keys with the same name in TABLE_SHARE. When
++# the tmp table spills to InnoDB on disk, the name-based index lookup
++# picks the wrong index.
++#
++SET max_heap_table_size = 16384;
++SET tmp_table_size = 1024;
++SET internal_tmp_mem_storage_engine = MEMORY;
++CREATE TABLE t1 (a INTEGER, b INTEGER, c INTEGER, f json);
++CREATE TABLE t2 (a INTEGER, d INTEGER, e INTEGER);
++INSERT INTO t1 VALUES
++(1, 1, 10, '{"name":"John Smith","sku":"20223","price":23.95,"shipTo":{"name":"Jane Smith","address":"123 Maple Street","city":"Pretendville","state":"NY","zip":"12345"},"billTo":{"name":"John Smith","address":"123 Maple Street","city":"Pretendville","state":"NY","zip":"12345"}}'),
++(1, 2, 20, '{"name":"John Smith","sku":"20223","price":23.95,"shipTo":{"name":"Jane Smith","address":"123 Maple Street","city":"Pretendville","state":"NY","zip":"12345"},"billTo":{"name":"John Smith","address":"123 Maple Street","city":"Pretendville","state":"NY","zip":"12345"}}'),
++(1, 3, 30, '{"name":"John Smith","sku":"20223","price":23.95,"shipTo":{"name":"Jane Smith","address":"123 Maple Street","city":"Pretendville","state":"NY","zip":"12345"},"billTo":{"name":"John Smith","address":"123 Maple Street","city":"Pretendville","state":"NY","zip":"12345"}}'),
++(2, 1, 40, '{"name":"Alice Brown","sku":"54321","price":199.95,"shipTo":{"name":"Bob Brown","address":"456 Oak Lane","city":"Pretendville","state":"HI","zip":"98999"},"billTo":{"name":"Alice Brown","address":"456 Oak Lane","city":"Pretendville","state":"HI","zip":"98999"}}'),
++(2, 2, 50, '{"name":"Alice Brown","sku":"54321","price":199.95,"shipTo":{"name":"Bob Brown","address":"456 Oak Lane","city":"Pretendville","state":"HI","zip":"98999"},"billTo":{"name":"Alice Brown","address":"456 Oak Lane","city":"Pretendville","state":"HI","zip":"98999"}}'),
++(2, 3, 60, '{"name":"Alice Brown","sku":"54321","price":199.95,"shipTo":{"name":"Bob Brown","address":"456 Oak Lane","city":"Pretendville","state":"HI","zip":"98999"},"billTo":{"name":"Alice Brown","address":"456 Oak Lane","city":"Pretendville","state":"HI","zip":"98999"}}');
++INSERT INTO t2 VALUES (1, 6, 60), (2, 6, 60), (3, 6, 60);
++ANALYZE TABLE t1, t2;
++Table	Op	Msg_type	Msg_text
++test.t1	analyze	status	OK
++test.t2	analyze	status	OK
++# Expect 5 rows, second column = 60 for all rows.
++WITH cte AS
++(SELECT SUM(c) AS c, SUM(b) AS b, a, f
++FROM t1
++GROUP BY a, f)
++SELECT t2.a, (SELECT MIN(c) FROM cte AS cte2 WHERE t2.d = cte2.b)
++FROM t2 LEFT JOIN cte AS cte1 ON t2.a = cte1.a
++LEFT JOIN t2 AS tx ON tx.e = cte1.c;
++a	(SELECT MIN(c) FROM cte AS cte2 WHERE t2.d = cte2.b)
++1	60
++1	60
++1	60
++2	60
++3	60
++DROP TABLE t1, t2;
++SET max_heap_table_size = DEFAULT;
++SET tmp_table_size = DEFAULT;
++SET internal_tmp_mem_storage_engine = DEFAULT;
+--- a/mysql-test/r/hypergraph_bugs.result
++++ b/mysql-test/r/hypergraph_bugs.result
+@@ -553,3 +553,73 @@ EXPLAIN
+     -> Table scan on t2  (rows=6) (actual rows=6 loops=1)
+ 
+ DROP TABLE t2;
++#
++# Bug#36578613: Hypergraph result difference when querying I_S.TABLES
++#
++CREATE TABLE t(x INT, y LONGTEXT);
++INSERT INTO t VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e'), (6, 'f');
++ANALYZE TABLE t;
++Table	Op	Msg_type	Msg_text
++test.t	analyze	status	OK
++EXPLAIN FORMAT=TREE SELECT DISTINCT t1.x, t1.y
++FROM t AS t1, t AS t2 WHERE t1.x = t2.x
++ORDER BY -t1.x;
++EXPLAIN
++-> Sort row IDs: -(t1.x)
++    -> Sort row IDs with duplicate removal: t1.x, t1.y
++        -> Inner hash join (t1.x = t2.x)
++            -> Table scan on t1
++            -> Hash
++                -> Table scan on t2
++
++SELECT DISTINCT t1.x, t1.y
++FROM t AS t1, t AS t2 WHERE t1.x = t2.x
++ORDER BY -t1.x;
++x	y
++6	f
++5	e
++4	d
++3	c
++2	b
++1	a
++DROP TABLE t;
++#
++# Bug#36678321: Hypergraph: Sort-ahead doesn't provide row IDs to later
++#               sort that needs them.
++#
++CREATE TABLE t1(int_col1 INT, int_col2 INT);
++INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6);
++CREATE TABLE t2 (int_col_key INT, longtext_col LONGTEXT, KEY (int_col_key));
++INSERT INTO t2
++WITH RECURSIVE src(n) AS (
++SELECT 1 UNION ALL SELECT n + 1 FROM src WHERE n < 50
++)
++SELECT n, n FROM src;
++INSERT INTO t2 SELECT * FROM t2;
++INSERT INTO t2 SELECT * FROM t2;
++ANALYZE TABLE t1, t2;
++Table	Op	Msg_type	Msg_text
++test.t1	analyze	status	OK
++test.t2	analyze	status	OK
++EXPLAIN FORMAT=TREE SELECT SQL_BIG_RESULT DISTINCT t1.int_col2
++FROM t1, t2 WHERE t1.int_col1 = t2.int_col_key
++ORDER BY ANY_VALUE(t2.longtext_col);
++EXPLAIN
++-> Sort row IDs: any_value(t2.longtext_col)
++    -> Remove duplicates from input grouped on t1.int_col2
++        -> Nested loop inner join
++            -> Sort row IDs: t1.int_col2
++                -> Table scan on t1
++            -> Index lookup on t2 using int_col_key (int_col_key=t1.int_col1)
++
++SELECT SQL_BIG_RESULT DISTINCT t1.int_col2
++FROM t1, t2 WHERE t1.int_col1 = t2.int_col_key
++ORDER BY ANY_VALUE(t2.longtext_col);
++int_col2
++1
++2
++3
++4
++5
++6
++DROP TABLE t1, t2;
+--- a/mysql-test/r/loadxml.result
++++ b/mysql-test/r/loadxml.result
+@@ -169,3 +169,12 @@ a	p	s
+ 7	NULL	A<L>Z
+ DROP TABLE t1;
+ #
++# LOAD XML CDATA prefix backtracking
++#
++CREATE TABLE t1 (a VARCHAR(100));
++LOAD XML INFILE 'MYSQLTEST_VARDIR/tmp/loadxml-cdata-prefix.dat' INTO TABLE t1;;
++SELECT * FROM t1;
++a
++NULL
++DROP TABLE t1;
++#
+--- a/mysql-test/r/lock_backup.result
++++ b/mysql-test/r/lock_backup.result
+@@ -51,8 +51,6 @@ connection con1;
+ SELECT info, state FROM INFORMATION_SCHEMA.PROCESSLIST WHERE id = default_con_id;
+ info	state
+ CREATE TABLE t2 (a INT)	Waiting for backup lock
+-Warnings:
+-Warning	1287	'INFORMATION_SCHEMA.PROCESSLIST' is deprecated and will be removed in a future release. Please use performance_schema.processlist instead
+ UNLOCK INSTANCE;
+ connection con2;
+ # Show that default connection is still waiting until Backup Lock be released
+@@ -60,8 +58,6 @@ connection con2;
+ SELECT info, state FROM INFORMATION_SCHEMA.PROCESSLIST WHERE id = default_con_id;
+ info	state
+ CREATE TABLE t2 (a INT)	Waiting for backup lock
+-Warnings:
+-Warning	1287	'INFORMATION_SCHEMA.PROCESSLIST' is deprecated and will be removed in a future release. Please use performance_schema.processlist instead
+ UNLOCK INSTANCE;
+ # Waiting until connection default acquire Backup Lock and resume execution
+ connection default;
+--- a/mysql-test/r/mysqlbinlog_hexdump.result
++++ b/mysql-test/r/mysqlbinlog_hexdump.result
+@@ -76,7 +76,11 @@ BEGIN
+ # 000001a6 85 2f c6 4e   0e   01 00 00 00   19 00 00 00   bf 01 00 00   00 00
+ # 000001b9 01 00 00 00 32 01                                |....2.|
+ # 	User_var
++/*!\C utf8mb3 *//*!*/;
++SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
+ SET @`2`:=NULL/*!*/;
++/*!\C utf8mb3 *//*!*/;
++SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/;
+ #111118 13:12:21 server id 1  end_log_pos 552 
+ # Position  Timestamp   Type   Source ID        Size      Source Pos    Flags 
+ # 000001bf 85 2f c6 4e   02   01 00 00 00   69 00 00 00   28 02 00 00   00 00
+--- /dev/null
++++ b/mysql-test/r/partition_exchange_check_constraints.result
+@@ -0,0 +1,161 @@
++#
++# Bug#39634208 EXCHANGE PARTITION validates destination CHECK constraints
++#
++CREATE TABLE t_part (
++a INT,
++CONSTRAINT t_part_chk CHECK (a > 0)
++)
++PARTITION BY RANGE (a) (
++PARTITION p0 VALUES LESS THAN (100),
++PARTITION p1 VALUES LESS THAN MAXVALUE
++);
++CREATE TABLE t_swap (
++a INT,
++CONSTRAINT t_swap_chk CHECK (a > 50)
++);
++INSERT INTO t_part PARTITION (p0) VALUES (10), (20);
++ALTER TABLE t_part EXCHANGE PARTITION p0 WITH TABLE t_swap;
++ERROR HY000: Check constraint 't_swap_chk' is violated.
++ALTER TABLE t_part EXCHANGE PARTITION p0 WITH TABLE t_swap WITHOUT VALIDATION;
++ERROR HY000: Check constraint 't_swap_chk' is violated.
++SELECT * FROM t_part PARTITION (p0) ORDER BY a;
++a
++10
++20
++SELECT * FROM t_swap ORDER BY a;
++a
++DROP TABLE t_part, t_swap;
++# Different virtual generated column expressions are incompatible.
++CREATE TABLE t_part (
++a INT,
++b INT GENERATED ALWAYS AS (a - 1) VIRTUAL,
++INDEX idx_b (b)
++)
++PARTITION BY RANGE (a) (
++PARTITION p0 VALUES LESS THAN MAXVALUE
++);
++CREATE TABLE t_swap (
++a INT,
++b INT GENERATED ALWAYS AS (a + 1) VIRTUAL,
++INDEX idx_b (b)
++);
++INSERT INTO t_swap (a) VALUES (0);
++ALTER TABLE t_part EXCHANGE PARTITION p0 WITH TABLE t_swap;
++ERROR HY000: Tables have different definitions
++SELECT * FROM t_part PARTITION (p0) ORDER BY a;
++a	b
++SELECT * FROM t_swap ORDER BY a;
++a	b
++0	1
++DROP TABLE t_part, t_swap;
++# Different stored generated column expressions are incompatible.
++CREATE TABLE t_part (
++a INT,
++b INT GENERATED ALWAYS AS (a - 1) STORED,
++CONSTRAINT b_positive CHECK (b > 0)
++)
++PARTITION BY RANGE (a) (
++PARTITION p0 VALUES LESS THAN MAXVALUE
++);
++CREATE TABLE t_swap (
++a INT,
++b INT GENERATED ALWAYS AS (a + 1) STORED
++);
++INSERT INTO t_swap (a) VALUES (5);
++ALTER TABLE t_part EXCHANGE PARTITION p0 WITH TABLE t_swap;
++ERROR HY000: Tables have different definitions
++SELECT * FROM t_part PARTITION (p0) ORDER BY a;
++a	b
++SELECT * FROM t_swap ORDER BY a;
++a	b
++5	6
++DROP TABLE t_part, t_swap;
++# Matching virtual and stored generated columns can be exchanged.
++CREATE TABLE t_part (
++a INT,
++b INT GENERATED ALWAYS AS (a + 1) VIRTUAL,
++c INT GENERATED ALWAYS AS (a + 2) STORED,
++CONSTRAINT t_part_chk CHECK (b > 0)
++)
++PARTITION BY RANGE (a) (
++PARTITION p0 VALUES LESS THAN MAXVALUE
++);
++CREATE TABLE t_swap (
++a INT,
++b INT GENERATED ALWAYS AS (a + 1) VIRTUAL,
++c INT GENERATED ALWAYS AS (a + 2) STORED,
++CONSTRAINT t_swap_chk CHECK (c < 20)
++);
++INSERT INTO t_part PARTITION (p0) (a) VALUES (3);
++INSERT INTO t_swap (a) VALUES (7);
++ALTER TABLE t_part EXCHANGE PARTITION p0 WITH TABLE t_swap;
++SELECT * FROM t_part PARTITION (p0) ORDER BY a;
++a	b	c
++7	8	9
++SELECT * FROM t_swap ORDER BY a;
++a	b	c
++3	4	5
++DROP TABLE t_part, t_swap;
++# Both directions satisfy their destination CHECK constraints.
++CREATE TABLE t_part (
++a INT,
++CONSTRAINT t_part_chk CHECK (a > 0)
++)
++PARTITION BY RANGE (a) (
++PARTITION p0 VALUES LESS THAN (100),
++PARTITION p1 VALUES LESS THAN MAXVALUE
++);
++CREATE TABLE t_swap (
++a INT,
++CONSTRAINT t_swap_chk CHECK (a > 50)
++);
++INSERT INTO t_part PARTITION (p0) VALUES (60);
++INSERT INTO t_swap VALUES (70);
++ALTER TABLE t_part EXCHANGE PARTITION p0 WITH TABLE t_swap;
++SELECT * FROM t_part PARTITION (p0) ORDER BY a;
++a
++70
++SELECT * FROM t_swap ORDER BY a;
++a
++60
++DROP TABLE t_part, t_swap;
++CREATE TABLE t_part (
++a INT,
++CONSTRAINT t_part_chk CHECK (a > 50)
++)
++PARTITION BY RANGE (a) (
++PARTITION p0 VALUES LESS THAN (100),
++PARTITION p1 VALUES LESS THAN MAXVALUE
++);
++CREATE TABLE t_swap (
++a INT,
++CONSTRAINT t_swap_chk CHECK (a > 0)
++);
++INSERT INTO t_swap VALUES (10), (20);
++ALTER TABLE t_part EXCHANGE PARTITION p0 WITH TABLE t_swap;
++ERROR HY000: Check constraint 't_part_chk' is violated.
++DROP TABLE t_part, t_swap;
++# Both exchange directions violate their destination CHECK constraints.
++CREATE TABLE t_part (
++a INT,
++CONSTRAINT t_part_chk CHECK (a > 0)
++)
++PARTITION BY RANGE (a) (
++PARTITION p0 VALUES LESS THAN (200),
++PARTITION p1 VALUES LESS THAN MAXVALUE
++);
++CREATE TABLE t_swap (
++a INT,
++CONSTRAINT t_swap_chk CHECK (a < 100)
++);
++INSERT INTO t_part PARTITION (p0) VALUES (150);
++INSERT INTO t_swap VALUES (-1);
++ALTER TABLE t_part EXCHANGE PARTITION p0 WITH TABLE t_swap;
++ERROR HY000: Check constraint 't_part_chk' is violated.
++SELECT * FROM t_part PARTITION (p0) ORDER BY a;
++a
++150
++SELECT * FROM t_swap ORDER BY a;
++a
++-1
++DROP TABLE t_part, t_swap;
+--- a/mysql-test/r/subquery_scalar_to_derived_correlated.result
++++ b/mysql-test/r/subquery_scalar_to_derived_correlated.result
+@@ -333,7 +333,7 @@ l_quantity < (select 0.9 * avg(l_quantit
+ from l where l_pkey = p_pkey);
+ id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+ 1	PRIMARY	l	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
+-1	PRIMARY	<derived2>	NULL	ref	<auto_key2>	<auto_key2>	5	test.l.l_pkey	2	33.33	Using where
++1	PRIMARY	<derived2>	NULL	ref	<auto_key0>	<auto_key0>	5	test.l.l_pkey	2	33.33	Using where
+ 1	PRIMARY	p	NULL	eq_ref	PRIMARY	PRIMARY	4	test.l.l_pkey	1	100.00	Using index
+ 2	DERIVED	l	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using temporary
+ Warnings:
+--- a/mysql-test/r/subquery_table_to_derived.result
++++ b/mysql-test/r/subquery_table_to_derived.result
+@@ -57,7 +57,7 @@ EXPLAIN SELECT * FROM t1 ot
+ WHERE ot.b<0 OR EXISTS(SELECT * FROM t2 it WHERE ot.a=it.a+1);
+ id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+ 1	PRIMARY	ot	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
+-1	PRIMARY	<derived2>	NULL	ref	<auto_key1>	<auto_key1>	9	test.ot.a	2	100.00	Using where
++1	PRIMARY	<derived2>	NULL	ref	<auto_key0>	<auto_key0>	9	test.ot.a	2	100.00	Using where
+ 2	DERIVED	it	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Using temporary
+ Warnings:
+ Note	1276	Field or reference 'test.ot.a' of SELECT #2 was resolved in SELECT #1
+@@ -71,7 +71,7 @@ EXPLAIN SELECT * FROM t1 ot
+ WHERE ot.b<0 OR EXISTS(SELECT it.b FROM t2 it WHERE ot.a=it.a+1);
+ id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+ 1	PRIMARY	ot	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
+-1	PRIMARY	<derived2>	NULL	ref	<auto_key1>	<auto_key1>	9	test.ot.a	2	100.00	Using where
++1	PRIMARY	<derived2>	NULL	ref	<auto_key0>	<auto_key0>	9	test.ot.a	2	100.00	Using where
+ 2	DERIVED	it	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Using temporary
+ Warnings:
+ Note	1276	Field or reference 'test.ot.a' of SELECT #2 was resolved in SELECT #1
+@@ -85,7 +85,7 @@ EXPLAIN SELECT * FROM t1 ot
+ WHERE ot.b<0 OR EXISTS(SELECT it.b,ot.b FROM t2 it WHERE ot.a=it.a+1);
+ id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+ 1	PRIMARY	ot	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
+-1	PRIMARY	<derived2>	NULL	ref	<auto_key1>	<auto_key1>	9	test.ot.a	2	100.00	Using where
++1	PRIMARY	<derived2>	NULL	ref	<auto_key0>	<auto_key0>	9	test.ot.a	2	100.00	Using where
+ 2	DERIVED	it	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Using temporary
+ Warnings:
+ Note	1276	Field or reference 'test.ot.b' of SELECT #2 was resolved in SELECT #1
+--- a/mysql-test/r/user_var-binlog.result
++++ b/mysql-test/r/user_var-binlog.result
+@@ -50,7 +50,11 @@ SET @@session.collation_database=DEFAULT
+ /*!80011 SET @@session.default_collation_for_utf8mb4=255*//*!*/;
+ BEGIN
+ /*!*/;
++/*!\C utf8mb3 *//*!*/;
++SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
+ SET @`a b`:=_utf8mb4 0x68656C6C6F COLLATE `utf8mb4_0900_ai_ci`/*!*/;
++/*!\C utf8mb4 *//*!*/;
++SET @@session.character_set_client=255,@@session.collation_connection=255,@@session.collation_server=255/*!*/;
+ use `test`/*!*/;
+ SET TIMESTAMP=#/*!*/;
+ INSERT INTO t1 VALUES(@`a b`)
+@@ -65,8 +69,16 @@ SET @@SESSION.GTID_NEXT= '#'/*!*/;
+ SET TIMESTAMP=#/*!*/;
+ BEGIN
+ /*!*/;
++/*!\C utf8mb3 *//*!*/;
++SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
+ SET @`var1`:=_utf8mb4 0x273B616161 COLLATE `utf8mb4_0900_ai_ci`/*!*/;
++/*!\C utf8mb4 *//*!*/;
++SET @@session.character_set_client=255,@@session.collation_connection=255,@@session.collation_server=255/*!*/;
++/*!\C utf8mb3 *//*!*/;
++SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
+ SET @`var2`:=_binary 0x61 COLLATE `binary`/*!*/;
++/*!\C utf8mb4 *//*!*/;
++SET @@session.character_set_client=255,@@session.collation_connection=255,@@session.collation_server=255/*!*/;
+ SET TIMESTAMP=#/*!*/;
+ insert into t1 values (@var1),(@var2)
+ /*!*/;
+--- a/mysql-test/r/xa_prepared_binlog_off.result
++++ b/mysql-test/r/xa_prepared_binlog_off.result
+@@ -138,115 +138,175 @@ ERROR XAE07: XAER_RMFAIL: The command ca
+ XA COMMIT 'trx1unprepared';
+ ERROR XAE04: XAER_NOTA: Unknown XID
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_0';
+ INSERT INTO t SET a=0;
+ XA END     'trx_0';
+ XA PREPARE 'trx_0';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_1';
+ INSERT INTO t SET a=1;
+ XA END     'trx_1';
+ XA PREPARE 'trx_1';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_2';
+ INSERT INTO t SET a=2;
+ XA END     'trx_2';
+ XA PREPARE 'trx_2';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_3';
+ INSERT INTO t SET a=3;
+ XA END     'trx_3';
+ XA PREPARE 'trx_3';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_4';
+ INSERT INTO t SET a=4;
+ XA END     'trx_4';
+ XA PREPARE 'trx_4';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_5';
+ INSERT INTO t SET a=5;
+ XA END     'trx_5';
+ XA PREPARE 'trx_5';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_6';
+ INSERT INTO t SET a=6;
+ XA END     'trx_6';
+ XA PREPARE 'trx_6';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_7';
+ INSERT INTO t SET a=7;
+ XA END     'trx_7';
+ XA PREPARE 'trx_7';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_8';
+ INSERT INTO t SET a=8;
+ XA END     'trx_8';
+ XA PREPARE 'trx_8';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_9';
+ INSERT INTO t SET a=9;
+ XA END     'trx_9';
+ XA PREPARE 'trx_9';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_10';
+ INSERT INTO t SET a=10;
+ XA END     'trx_10';
+ XA PREPARE 'trx_10';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_11';
+ INSERT INTO t SET a=11;
+ XA END     'trx_11';
+ XA PREPARE 'trx_11';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_12';
+ INSERT INTO t SET a=12;
+ XA END     'trx_12';
+ XA PREPARE 'trx_12';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_13';
+ INSERT INTO t SET a=13;
+ XA END     'trx_13';
+ XA PREPARE 'trx_13';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_14';
+ INSERT INTO t SET a=14;
+ XA END     'trx_14';
+ XA PREPARE 'trx_14';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_15';
+ INSERT INTO t SET a=15;
+ XA END     'trx_15';
+ XA PREPARE 'trx_15';
+ KILL CONNECTION CONN_ID;
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_16';
+ INSERT INTO t SET a=16;
+ XA END     'trx_16';
+ XA PREPARE 'trx_16';
+ KILL CONNECTION CONN_ID;
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_17';
+ INSERT INTO t SET a=17;
+ XA END     'trx_17';
+ XA PREPARE 'trx_17';
+ KILL CONNECTION CONN_ID;
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_18';
+ INSERT INTO t SET a=18;
+ XA END     'trx_18';
+ XA PREPARE 'trx_18';
+ KILL CONNECTION CONN_ID;
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_19';
+ INSERT INTO t SET a=19;
+ XA END     'trx_19';
+@@ -518,115 +578,175 @@ ERROR XAE07: XAER_RMFAIL: The command ca
+ XA COMMIT 'trx1unprepared';
+ ERROR XAE04: XAER_NOTA: Unknown XID
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_0';
+ INSERT INTO t SET a=0;
+ XA END     'trx_0';
+ XA PREPARE 'trx_0';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_1';
+ INSERT INTO t SET a=1;
+ XA END     'trx_1';
+ XA PREPARE 'trx_1';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_2';
+ INSERT INTO t SET a=2;
+ XA END     'trx_2';
+ XA PREPARE 'trx_2';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_3';
+ INSERT INTO t SET a=3;
+ XA END     'trx_3';
+ XA PREPARE 'trx_3';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_4';
+ INSERT INTO t SET a=4;
+ XA END     'trx_4';
+ XA PREPARE 'trx_4';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_5';
+ INSERT INTO t SET a=5;
+ XA END     'trx_5';
+ XA PREPARE 'trx_5';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_6';
+ INSERT INTO t SET a=6;
+ XA END     'trx_6';
+ XA PREPARE 'trx_6';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_7';
+ INSERT INTO t SET a=7;
+ XA END     'trx_7';
+ XA PREPARE 'trx_7';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_8';
+ INSERT INTO t SET a=8;
+ XA END     'trx_8';
+ XA PREPARE 'trx_8';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_9';
+ INSERT INTO t SET a=9;
+ XA END     'trx_9';
+ XA PREPARE 'trx_9';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_10';
+ INSERT INTO t SET a=10;
+ XA END     'trx_10';
+ XA PREPARE 'trx_10';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_11';
+ INSERT INTO t SET a=11;
+ XA END     'trx_11';
+ XA PREPARE 'trx_11';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_12';
+ INSERT INTO t SET a=12;
+ XA END     'trx_12';
+ XA PREPARE 'trx_12';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_13';
+ INSERT INTO t SET a=13;
+ XA END     'trx_13';
+ XA PREPARE 'trx_13';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_14';
+ INSERT INTO t SET a=14;
+ XA END     'trx_14';
+ XA PREPARE 'trx_14';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_15';
+ INSERT INTO t SET a=15;
+ XA END     'trx_15';
+ XA PREPARE 'trx_15';
+ KILL CONNECTION CONN_ID;
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_16';
+ INSERT INTO t SET a=16;
+ XA END     'trx_16';
+ XA PREPARE 'trx_16';
+ KILL CONNECTION CONN_ID;
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_17';
+ INSERT INTO t SET a=17;
+ XA END     'trx_17';
+ XA PREPARE 'trx_17';
+ KILL CONNECTION CONN_ID;
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_18';
+ INSERT INTO t SET a=18;
+ XA END     'trx_18';
+ XA PREPARE 'trx_18';
+ KILL CONNECTION CONN_ID;
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_19';
+ INSERT INTO t SET a=19;
+ XA END     'trx_19';
+--- /dev/null
++++ b/mysql-test/r/xa_prepare_recover_after_gtid_action_crash.result
+@@ -0,0 +1,30 @@
++include/only_with_option.inc [GLOBAL.log_bin = 0]
++include/only_with_option.inc [GLOBAL.gtid_mode = 'ON']
++include/suppress_messages.inc
++# Connection 1 suppresses message <Found .* prepared XA transactions>.
++# Connection 1 suppresses message <.*Checksum mismatch in datafile.*>.
++CREATE TABLE t1 (c1 INT PRIMARY KEY);
++XA START X'78696431',X'',1;
++INSERT INTO t1 VALUES (2);
++XA END X'78696431',X'',1;
++XA PREPARE X'78696431',X'',1;
++XA COMMIT X'78696431',X'',1;
++RESET MASTER;
++SET @@SESSION.gtid_next = '72e9b9d8-8a89-11ec-8f56-6f896ffede71:1';
++XA START X'78696431',X'',1;
++INSERT INTO t1 VALUES (1);
++XA END X'78696431',X'',1;
++include/execute_to_conditional_timestamp_sync_point.inc [after_call_actions_before_gtid_state_update]
++XA PREPARE X'78696431',X'',1;
++SET SESSION debug = '+d,crash_now_safe';
++ERROR HY000: Lost connection to MySQL server during query
++ERROR HY000: Lost connection to MySQL server during query
++# restart
++include/assert.inc [Found 1 log message(s) for "Successfully prepared 1 XA transaction"]
++include/assert.inc [1 XA transaction(s) in PREPARED state]
++include/assert.inc [XA transaction X'78696431',X'',1 is in PREPARED state]
++include/assert.inc [GTID_EXECUTED contains the recovered XA PREPARE GTID]
++include/assert.inc [Table 'test.t1' record count must be 1]
++XA ROLLBACK X'78696431',X'',1;
++DROP TABLE t1;
++RESET MASTER;
+--- /dev/null
++++ b/mysql-test/r/xa_prepare_recover_before_gtid_externalization.result
+@@ -0,0 +1,18 @@
++include/only_with_option.inc [GLOBAL.log_bin = 0]
++RESET MASTER;
++CREATE TABLE t1 (a INT);
++SET @@SESSION.xa_detach_on_prepare = ON;
++SET GTID_NEXT = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1';
++XA START 'xa_prepare_nobinlog';
++INSERT INTO t1 VALUES (1);
++XA END 'xa_prepare_nobinlog';
++include/execute_to_conditional_timestamp_sync_point.inc [after_call_actions_before_gtid_state_update]
++XA PREPARE 'xa_prepare_nobinlog';
++include/assert.inc [1 XA transaction(s) in PREPARED state]
++include/assert.inc [GTID_EXECUTED does not contain the XA PREPARE GTID yet]
++include/execute_from_conditional_timestamp_sync_point.inc [1 at after_call_actions_before_gtid_state_update]
++include/assert.inc [GTID_EXECUTED contains the XA PREPARE GTID]
++SET GTID_NEXT = AUTOMATIC;
++XA ROLLBACK 'xa_prepare_nobinlog';
++DROP TABLE t1;
++RESET MASTER;
+--- a/mysql-test/r/xml.result
++++ b/mysql-test/r/xml.result
+@@ -645,6 +645,11 @@ set names utf8mb4;
+ select ExtractValue('<tag1><![CDATA[test]]></tag1>','/tag1');
+ ExtractValue('<tag1><![CDATA[test]]></tag1>','/tag1')
+ test
++select ExtractValue('0123456789AB<![CDATA[','/');
++ExtractValue('0123456789AB<![CDATA[','/')
++NULL
++Warnings:
++Warning	1525	Incorrect XML value: 'parse error at line 1 pos 22: unexpected END-OF-INPUT'
+ select extractValue('<a>a','/a');
+ extractValue('<a>a','/a')
+ NULL
+--- /dev/null
++++ b/mysql-test/suite/auth_sec/r/partial_revokes_bug38921524.result
+@@ -0,0 +1,31 @@
++CREATE ROLE administrator;
++GRANT SELECT, CREATE TEMPORARY TABLES, CREATE USER ON *.*
++TO administrator WITH GRANT OPTION;
++GRANT CREATE TEMPORARY TABLES ON sys.* TO administrator WITH GRANT OPTION;
++REVOKE CREATE TEMPORARY TABLES ON mysql.* FROM administrator;
++CREATE USER test_user@'127.0.0.1', test_user@'%';
++GRANT administrator TO test_user@'127.0.0.1' WITH ADMIN OPTION;
++SET ROLE administrator;
++GRANT CREATE TEMPORARY TABLES ON sys.* TO test_user@'127.0.0.1';
++GRANT CREATE TEMPORARY TABLES ON *.* TO test_user@'%';
++REVOKE CREATE TEMPORARY TABLES ON sys.* FROM test_user@'%';
++GRANT SELECT ON *.* TO test_user@'%';
++SHOW GRANTS FOR test_user@'%';
++Grants for test_user@%
++GRANT SELECT, CREATE TEMPORARY TABLES ON *.* TO `test_user`@`%`
++REVOKE CREATE TEMPORARY TABLES ON `mysql`.* FROM `test_user`@`%`
++REVOKE CREATE TEMPORARY TABLES ON `sys`.* FROM `test_user`@`%`
++DROP USER test_user@'127.0.0.1', test_user@'%';
++CREATE USER test_user@'%', test_user@'192.0.2.1';
++GRANT administrator TO test_user@'%' WITH ADMIN OPTION;
++SET ROLE administrator;
++GRANT CREATE TEMPORARY TABLES ON *.* TO test_user@'192.0.2.1';
++REVOKE CREATE TEMPORARY TABLES ON sys.* FROM test_user@'192.0.2.1';
++GRANT SELECT ON *.* TO test_user@'192.0.2.1';
++SHOW GRANTS FOR test_user@'192.0.2.1';
++Grants for test_user at 192.0.2.1
++GRANT SELECT, CREATE TEMPORARY TABLES ON *.* TO `test_user`@`192.0.2.1`
++REVOKE CREATE TEMPORARY TABLES ON `mysql`.* FROM `test_user`@`192.0.2.1`
++REVOKE CREATE TEMPORARY TABLES ON `sys`.* FROM `test_user`@`192.0.2.1`
++DROP USER test_user@'%', test_user@'192.0.2.1';
++DROP ROLE administrator;
+--- /dev/null
++++ b/mysql-test/suite/auth_sec/t/partial_revokes_bug38921524.combinations
+@@ -0,0 +1,4 @@
++[name_resolve]
++
++[skip_name_resolve]
++skip-name-resolve
+--- /dev/null
++++ b/mysql-test/suite/auth_sec/t/partial_revokes_bug38921524.test
+@@ -0,0 +1,59 @@
++# Bug#38921524: Granting a privilege fails with ERROR 3901
++
++--source include/count_sessions.inc
++
++--disable_query_log
++let $saved_partial_revokes = `SELECT @@global.partial_revokes`;
++SET GLOBAL partial_revokes = ON;
++--enable_query_log
++
++CREATE ROLE administrator;
++GRANT SELECT, CREATE TEMPORARY TABLES, CREATE USER ON *.*
++  TO administrator WITH GRANT OPTION;
++GRANT CREATE TEMPORARY TABLES ON sys.* TO administrator WITH GRANT OPTION;
++REVOKE CREATE TEMPORARY TABLES ON mysql.* FROM administrator;
++
++# Current account has an IP host, while the target account has a wildcard host.
++CREATE USER test_user@'127.0.0.1', test_user@'%';
++GRANT administrator TO test_user@'127.0.0.1' WITH ADMIN OPTION;
++
++--connect(test_user_con, 127.0.0.1, test_user)
++SET ROLE administrator;
++GRANT CREATE TEMPORARY TABLES ON sys.* TO test_user@'127.0.0.1';
++GRANT CREATE TEMPORARY TABLES ON *.* TO test_user@'%';
++REVOKE CREATE TEMPORARY TABLES ON sys.* FROM test_user@'%';
++
++# The active role and test_user at 127.0.0.1 have CREATE TEMPORARY TABLES on
++# sys.*, but test_user@% does not. The lookup must use the grantee host rather
++# than the current security context or the grantor connection's IP.
++GRANT SELECT ON *.* TO test_user@'%';
++SHOW GRANTS FOR test_user@'%';
++
++--connection default
++--disconnect test_user_con
++DROP USER test_user@'127.0.0.1', test_user@'%';
++
++# Current account has a wildcard host, while the target account has an IP host.
++CREATE USER test_user@'%', test_user@'192.0.2.1';
++GRANT administrator TO test_user@'%' WITH ADMIN OPTION;
++
++--connect(test_user_con, 127.0.0.1, test_user)
++SET ROLE administrator;
++GRANT CREATE TEMPORARY TABLES ON *.* TO test_user@'192.0.2.1';
++REVOKE CREATE TEMPORARY TABLES ON sys.* FROM test_user@'192.0.2.1';
++
++# Do not mistake the wildcard current account or its active role for the
++# IP-host grantee when hostname resolution is enabled or disabled.
++GRANT SELECT ON *.* TO test_user@'192.0.2.1';
++SHOW GRANTS FOR test_user@'192.0.2.1';
++
++--connection default
++--disconnect test_user_con
++DROP USER test_user@'%', test_user@'192.0.2.1';
++DROP ROLE administrator;
++
++--disable_query_log
++eval SET GLOBAL partial_revokes = $saved_partial_revokes;
++--enable_query_log
++
++--source include/wait_until_count_sessions.inc
+--- a/mysql-test/suite/binlog/r/binlog_xa_prepared_disconnect.result
++++ b/mysql-test/suite/binlog/r/binlog_xa_prepared_disconnect.result
+@@ -139,115 +139,175 @@ ERROR XAE07: XAER_RMFAIL: The command ca
+ XA COMMIT 'trx1unprepared';
+ ERROR XAE04: XAER_NOTA: Unknown XID
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_0';
+ INSERT INTO t SET a=0;
+ XA END     'trx_0';
+ XA PREPARE 'trx_0';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_1';
+ INSERT INTO t SET a=1;
+ XA END     'trx_1';
+ XA PREPARE 'trx_1';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_2';
+ INSERT INTO t SET a=2;
+ XA END     'trx_2';
+ XA PREPARE 'trx_2';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_3';
+ INSERT INTO t SET a=3;
+ XA END     'trx_3';
+ XA PREPARE 'trx_3';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_4';
+ INSERT INTO t SET a=4;
+ XA END     'trx_4';
+ XA PREPARE 'trx_4';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_5';
+ INSERT INTO t SET a=5;
+ XA END     'trx_5';
+ XA PREPARE 'trx_5';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_6';
+ INSERT INTO t SET a=6;
+ XA END     'trx_6';
+ XA PREPARE 'trx_6';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_7';
+ INSERT INTO t SET a=7;
+ XA END     'trx_7';
+ XA PREPARE 'trx_7';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_8';
+ INSERT INTO t SET a=8;
+ XA END     'trx_8';
+ XA PREPARE 'trx_8';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_9';
+ INSERT INTO t SET a=9;
+ XA END     'trx_9';
+ XA PREPARE 'trx_9';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_10';
+ INSERT INTO t SET a=10;
+ XA END     'trx_10';
+ XA PREPARE 'trx_10';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_11';
+ INSERT INTO t SET a=11;
+ XA END     'trx_11';
+ XA PREPARE 'trx_11';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_12';
+ INSERT INTO t SET a=12;
+ XA END     'trx_12';
+ XA PREPARE 'trx_12';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_13';
+ INSERT INTO t SET a=13;
+ XA END     'trx_13';
+ XA PREPARE 'trx_13';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_14';
+ INSERT INTO t SET a=14;
+ XA END     'trx_14';
+ XA PREPARE 'trx_14';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_15';
+ INSERT INTO t SET a=15;
+ XA END     'trx_15';
+ XA PREPARE 'trx_15';
+ KILL CONNECTION CONN_ID;
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_16';
+ INSERT INTO t SET a=16;
+ XA END     'trx_16';
+ XA PREPARE 'trx_16';
+ KILL CONNECTION CONN_ID;
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_17';
+ INSERT INTO t SET a=17;
+ XA END     'trx_17';
+ XA PREPARE 'trx_17';
+ KILL CONNECTION CONN_ID;
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_18';
+ INSERT INTO t SET a=18;
+ XA END     'trx_18';
+ XA PREPARE 'trx_18';
+ KILL CONNECTION CONN_ID;
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_19';
+ INSERT INTO t SET a=19;
+ XA END     'trx_19';
+@@ -519,115 +579,175 @@ ERROR XAE07: XAER_RMFAIL: The command ca
+ XA COMMIT 'trx1unprepared';
+ ERROR XAE04: XAER_NOTA: Unknown XID
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_0';
+ INSERT INTO t SET a=0;
+ XA END     'trx_0';
+ XA PREPARE 'trx_0';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_1';
+ INSERT INTO t SET a=1;
+ XA END     'trx_1';
+ XA PREPARE 'trx_1';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_2';
+ INSERT INTO t SET a=2;
+ XA END     'trx_2';
+ XA PREPARE 'trx_2';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_3';
+ INSERT INTO t SET a=3;
+ XA END     'trx_3';
+ XA PREPARE 'trx_3';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_4';
+ INSERT INTO t SET a=4;
+ XA END     'trx_4';
+ XA PREPARE 'trx_4';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_5';
+ INSERT INTO t SET a=5;
+ XA END     'trx_5';
+ XA PREPARE 'trx_5';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_6';
+ INSERT INTO t SET a=6;
+ XA END     'trx_6';
+ XA PREPARE 'trx_6';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_7';
+ INSERT INTO t SET a=7;
+ XA END     'trx_7';
+ XA PREPARE 'trx_7';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_8';
+ INSERT INTO t SET a=8;
+ XA END     'trx_8';
+ XA PREPARE 'trx_8';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_9';
+ INSERT INTO t SET a=9;
+ XA END     'trx_9';
+ XA PREPARE 'trx_9';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_10';
+ INSERT INTO t SET a=10;
+ XA END     'trx_10';
+ XA PREPARE 'trx_10';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_11';
+ INSERT INTO t SET a=11;
+ XA END     'trx_11';
+ XA PREPARE 'trx_11';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_12';
+ INSERT INTO t SET a=12;
+ XA END     'trx_12';
+ XA PREPARE 'trx_12';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_13';
+ INSERT INTO t SET a=13;
+ XA END     'trx_13';
+ XA PREPARE 'trx_13';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_14';
+ INSERT INTO t SET a=14;
+ XA END     'trx_14';
+ XA PREPARE 'trx_14';
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_15';
+ INSERT INTO t SET a=15;
+ XA END     'trx_15';
+ XA PREPARE 'trx_15';
+ KILL CONNECTION CONN_ID;
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_16';
+ INSERT INTO t SET a=16;
+ XA END     'trx_16';
+ XA PREPARE 'trx_16';
+ KILL CONNECTION CONN_ID;
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_17';
+ INSERT INTO t SET a=17;
+ XA END     'trx_17';
+ XA PREPARE 'trx_17';
+ KILL CONNECTION CONN_ID;
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_18';
+ INSERT INTO t SET a=18;
+ XA END     'trx_18';
+ XA PREPARE 'trx_18';
+ KILL CONNECTION CONN_ID;
+ SET @@binlog_format = 'STATEMENT';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ SET @@binlog_format = 'ROW';
++Warnings:
++Warning	1287	'@@binlog_format' is deprecated and will be removed in a future release.
+ XA START   'trx_19';
+ INSERT INTO t SET a=19;
+ XA END     'trx_19';
+--- /dev/null
++++ b/mysql-test/suite/binlog/t/binlog_xa_prepared_disconnect-master.opt
+@@ -0,0 +1 @@
++--xa-detach-on-prepare=OFF
+--- a/mysql-test/suite/binlog_gtid/r/binlog_gtid_stm_ctype_ucs.result
++++ b/mysql-test/suite/binlog_gtid/r/binlog_gtid_stm_ctype_ucs.result
+@@ -40,7 +40,11 @@ SET @@session.collation_database=DEFAULT
+ /*!80011 SET @@session.default_collation_for_utf8mb4=255*//*!*/;
+ BEGIN
+ /*!*/;
++/*!\C utf8mb3 *//*!*/;
++SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
+ SET @`v`:=_ucs2 0x006100620063 COLLATE `ucs2_general_ci`/*!*/;
++/*!\C utf8mb4 *//*!*/;
++SET @@session.character_set_client=255,@@session.collation_connection=255,@@session.collation_server=255/*!*/;
+ use `test`/*!*/;
+ SET TIMESTAMP=#/*!*/;
+ insert into t2 values (@v)
+--- /dev/null
++++ b/mysql-test/suite/binlog_gtid/r/binlog_gtid_xa_prepare_recover_before_gtid_externalization_no_order.result
+@@ -0,0 +1,18 @@
++RESET MASTER;
++include/assert.inc [binlog_order_commits is disabled]
++CREATE TABLE t1 (a INT);
++SET @@SESSION.xa_detach_on_prepare = ON;
++SET GTID_NEXT = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1';
++XA START 'xa_prepare_no_order';
++INSERT INTO t1 VALUES (1);
++XA END 'xa_prepare_no_order';
++include/execute_to_conditional_timestamp_sync_point.inc [after_call_actions_before_gtid_state_update]
++XA PREPARE 'xa_prepare_no_order';
++include/assert.inc [1 XA transaction(s) in PREPARED state]
++include/assert.inc [GTID_EXECUTED does not contain the XA PREPARE GTID yet]
++include/execute_from_conditional_timestamp_sync_point.inc [1 at after_call_actions_before_gtid_state_update]
++include/assert.inc [GTID_EXECUTED contains the XA PREPARE GTID]
++SET GTID_NEXT = AUTOMATIC;
++XA ROLLBACK 'xa_prepare_no_order';
++DROP TABLE t1;
++RESET MASTER;
+--- /dev/null
++++ b/mysql-test/suite/binlog_gtid/r/binlog_gtid_xa_prepare_recover_before_gtid_externalization.result
+@@ -0,0 +1,30 @@
++RESET MASTER;
++CREATE TABLE t1 (a INT);
++SET @@SESSION.xa_detach_on_prepare = ON;
++SET GTID_NEXT = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1';
++XA START 'xa_prepare_detach_on';
++INSERT INTO t1 VALUES (1);
++XA END 'xa_prepare_detach_on';
++include/execute_to_conditional_timestamp_sync_point.inc [after_call_actions_before_gtid_state_update]
++XA PREPARE 'xa_prepare_detach_on';
++include/assert.inc [1 XA transaction(s) in PREPARED state]
++include/assert.inc [GTID_EXECUTED does not contain the XA PREPARE GTID yet]
++include/execute_from_conditional_timestamp_sync_point.inc [1 at after_call_actions_before_gtid_state_update]
++include/assert.inc [GTID_EXECUTED contains the XA PREPARE GTID]
++SET GTID_NEXT = AUTOMATIC;
++XA ROLLBACK 'xa_prepare_detach_on';
++SET @@SESSION.xa_detach_on_prepare = OFF;
++SET GTID_NEXT = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:2';
++XA START 'xa_prepare_detach_off';
++INSERT INTO t1 VALUES (2);
++XA END 'xa_prepare_detach_off';
++include/execute_to_conditional_timestamp_sync_point.inc [after_call_actions_before_gtid_state_update]
++XA PREPARE 'xa_prepare_detach_off';
++include/assert.inc [1 XA transaction(s) in PREPARED state]
++include/assert.inc [GTID_EXECUTED does not contain the XA PREPARE GTID yet]
++include/execute_from_conditional_timestamp_sync_point.inc [1 at after_call_actions_before_gtid_state_update]
++include/assert.inc [GTID_EXECUTED contains the XA PREPARE GTID]
++SET GTID_NEXT = AUTOMATIC;
++XA ROLLBACK 'xa_prepare_detach_off';
++DROP TABLE t1;
++RESET MASTER;
+--- /dev/null
++++ b/mysql-test/suite/binlog_gtid/r/binlog_gtid_xa_second_phase_action_lifetime.result
+@@ -0,0 +1,56 @@
++CREATE TABLE t1 (a INT);
++#
++# Attached XA COMMIT without a GTID update
++#
++SET SESSION xa_detach_on_prepare=OFF;
++SET SESSION sql_log_bin=0;
++XA START 'old_commit';
++INSERT INTO t1 VALUES (1);
++XA END 'old_commit';
++XA PREPARE 'old_commit';
++XA COMMIT 'old_commit';
++SET SESSION sql_log_bin=1;
++XA START 'after_commit';
++INSERT INTO t1 VALUES (2);
++XA END 'after_commit';
++XA PREPARE 'after_commit';
++include/assert.inc [XA COMMIT action did not affect the next XA transaction]
++XA ROLLBACK 'after_commit';
++#
++# Attached XA ROLLBACK without a GTID update
++#
++SET SESSION sql_log_bin=0;
++XA START 'old_rollback';
++INSERT INTO t1 VALUES (3);
++XA END 'old_rollback';
++XA PREPARE 'old_rollback';
++XA ROLLBACK 'old_rollback';
++SET SESSION sql_log_bin=1;
++XA START 'after_rollback';
++INSERT INTO t1 VALUES (4);
++XA END 'after_rollback';
++XA PREPARE 'after_rollback';
++include/assert.inc [XA ROLLBACK action did not affect the next XA transaction]
++XA ROLLBACK 'after_rollback';
++#
++# Detached XA COMMIT and ROLLBACK without a GTID update
++#
++SET SESSION xa_detach_on_prepare=ON;
++SET SESSION sql_log_bin=0;
++XA START 'detached_commit';
++INSERT INTO t1 VALUES (5);
++XA END 'detached_commit';
++XA PREPARE 'detached_commit';
++XA COMMIT 'detached_commit';
++SET SESSION sql_log_bin=1;
++INSERT INTO t1 VALUES (6);
++SET SESSION sql_log_bin=0;
++XA START 'detached_rollback';
++INSERT INTO t1 VALUES (7);
++XA END 'detached_rollback';
++XA PREPARE 'detached_rollback';
++XA ROLLBACK 'detached_rollback';
++SET SESSION sql_log_bin=1;
++INSERT INTO t1 VALUES (8);
++DROP TABLE t1;
++RESET MASTER;
+--- /dev/null
++++ b/mysql-test/suite/binlog_gtid/r/binlog_gtid_xa_second_phase_recover_before_gtid_externalization.result
+@@ -0,0 +1,32 @@
++RESET MASTER;
++CREATE TABLE t1 (a INT);
++SET @@SESSION.xa_detach_on_prepare = ON;
++XA START 'xa_commit';
++INSERT INTO t1 VALUES (1);
++XA END 'xa_commit';
++XA PREPARE 'xa_commit';
++SET GTID_NEXT = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1';
++include/execute_to_conditional_timestamp_sync_point.inc [after_call_actions_before_gtid_state_update]
++XA COMMIT 'xa_commit';
++include/assert.inc [No XA transactions in PREPARED state]
++include/assert.inc [GTID_EXECUTED does not contain the XA COMMIT GTID yet]
++include/execute_from_conditional_timestamp_sync_point.inc [1 at after_call_actions_before_gtid_state_update]
++include/assert.inc [GTID_EXECUTED contains the XA COMMIT GTID]
++SET GTID_NEXT = AUTOMATIC;
++XA START 'xa_rollback';
++INSERT INTO t1 VALUES (2);
++XA END 'xa_rollback';
++XA PREPARE 'xa_rollback';
++SET GTID_NEXT = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:2';
++include/execute_to_conditional_timestamp_sync_point.inc [after_call_actions_before_gtid_state_update]
++XA ROLLBACK 'xa_rollback';
++include/assert.inc [No XA transactions in PREPARED state]
++include/assert.inc [GTID_EXECUTED does not contain the XA ROLLBACK GTID yet]
++include/execute_from_conditional_timestamp_sync_point.inc [1 at after_call_actions_before_gtid_state_update]
++include/assert.inc [GTID_EXECUTED contains the XA ROLLBACK GTID]
++SET GTID_NEXT = AUTOMATIC;
++SELECT * FROM t1;
++a
++1
++DROP TABLE t1;
++RESET MASTER;
+--- /dev/null
++++ b/mysql-test/suite/binlog_gtid/t/binlog_gtid_xa_prepare_recover_before_gtid_externalization_no_order-master.opt
+@@ -0,0 +1 @@
++--binlog-order-commits=OFF
+--- /dev/null
++++ b/mysql-test/suite/binlog_gtid/t/binlog_gtid_xa_prepare_recover_before_gtid_externalization_no_order.test
+@@ -0,0 +1,70 @@
++# ==== Purpose ====
++#
++# Verify that XA PREPARE updates XA RECOVER before its GTID becomes visible
++# when binlog_order_commits is disabled.
++#
++# ==== Requirements ====
++#
++# R1. The test should exercise the GTID update path used when ordered binary
++#     log commits are disabled.
++# R2. While XA PREPARE is paused before GTID externalization, XA RECOVER
++#     should list the prepared XID.
++# R3. The XA PREPARE GTID should not be visible while paused, but should
++#     become visible after XA PREPARE completes.
++#
++# ==== References ====
++#
++# Bug#35872823: XA RECOVER may miss XID after XA PREPARE GTID is visible
++
++--source include/have_debug.inc
++--source include/have_debug_sync.inc
++--source include/have_binlog_format_row.inc
++
++RESET MASTER;
++--let $assert_text = binlog_order_commits is disabled
++--let $binlog_order_commits = `SELECT @@GLOBAL.binlog_order_commits`
++--let $assert_cond = "$binlog_order_commits" = "0"
++--source include/assert.inc
++
++CREATE TABLE t1 (a INT);
++
++--connect(con1,localhost,root,,)
++--connection con1
++SET @@SESSION.xa_detach_on_prepare = ON;
++--let $prepare_gtid = aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1
++--eval SET GTID_NEXT = '$prepare_gtid'
++XA START 'xa_prepare_no_order';
++INSERT INTO t1 VALUES (1);
++XA END 'xa_prepare_no_order';
++
++--connection default
++--let $auxiliary_connection = default
++--let $statement_connection = con1
++--let $statement = XA PREPARE 'xa_prepare_no_order'
++--let $sync_point = after_call_actions_before_gtid_state_update
++--source include/execute_to_conditional_timestamp_sync_point.inc
++
++--let $expected_prepared_xa_count = 1
++--source extra/xa_crash_safe_tests/assert_xa_recover.inc
++--let $assert_text = GTID_EXECUTED does not contain the XA PREPARE GTID yet
++--let $has_gtid = `SELECT GTID_SUBSET('$prepare_gtid', @@GLOBAL.gtid_executed)`
++--let $assert_cond = "$has_gtid" = "0"
++--source include/assert.inc
++
++--let $reap_statement_connection = 1
++--source include/execute_from_conditional_timestamp_sync_point.inc
++--let $reap_statement_connection = 0
++--let $assert_text = GTID_EXECUTED contains the XA PREPARE GTID
++--let $has_gtid = `SELECT GTID_SUBSET('$prepare_gtid', @@GLOBAL.gtid_executed)`
++--let $assert_cond = "$has_gtid" = "1"
++--source include/assert.inc
++
++--connection con1
++SET GTID_NEXT = AUTOMATIC;
++--connection default
++XA ROLLBACK 'xa_prepare_no_order';
++
++--disconnect con1
++--connection default
++DROP TABLE t1;
++RESET MASTER;
+--- /dev/null
++++ b/mysql-test/suite/binlog_gtid/t/binlog_gtid_xa_prepare_recover_before_gtid_externalization.test
+@@ -0,0 +1,97 @@
++# ==== Purpose ====
++#
++# Verify that XA PREPARE updates XA RECOVER before its GTID becomes visible.
++#
++# ==== Requirements ====
++#
++# R1. While XA PREPARE is paused before GTID externalization, XA RECOVER
++#     should list the prepared XID.
++# R2. The requirement should hold for both xa_detach_on_prepare modes.
++# R3. The XA PREPARE GTID should not be visible while paused, but should
++#     become visible after XA PREPARE completes.
++#
++# ==== References ====
++#
++# Bug#35872823: XA RECOVER may miss XID after XA PREPARE GTID is visible
++
++--source include/have_debug.inc
++--source include/have_debug_sync.inc
++--source include/have_binlog_format_row.inc
++
++RESET MASTER;
++CREATE TABLE t1 (a INT);
++
++--connect(con1,localhost,root,,)
++--connection con1
++SET @@SESSION.xa_detach_on_prepare = ON;
++--let $prepare_gtid = aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1
++--eval SET GTID_NEXT = '$prepare_gtid'
++XA START 'xa_prepare_detach_on';
++INSERT INTO t1 VALUES (1);
++XA END 'xa_prepare_detach_on';
++
++--connection default
++--let $auxiliary_connection = default
++--let $statement_connection = con1
++--let $statement = XA PREPARE 'xa_prepare_detach_on'
++--let $sync_point = after_call_actions_before_gtid_state_update
++--source include/execute_to_conditional_timestamp_sync_point.inc
++
++--let $expected_prepared_xa_count = 1
++--source extra/xa_crash_safe_tests/assert_xa_recover.inc
++--let $assert_text = GTID_EXECUTED does not contain the XA PREPARE GTID yet
++--let $has_gtid = `SELECT GTID_SUBSET('$prepare_gtid', @@GLOBAL.gtid_executed)`
++--let $assert_cond = "$has_gtid" = "0"
++--source include/assert.inc
++
++--let $reap_statement_connection = 1
++--source include/execute_from_conditional_timestamp_sync_point.inc
++--let $reap_statement_connection = 0
++--let $assert_text = GTID_EXECUTED contains the XA PREPARE GTID
++--let $has_gtid = `SELECT GTID_SUBSET('$prepare_gtid', @@GLOBAL.gtid_executed)`
++--let $assert_cond = "$has_gtid" = "1"
++--source include/assert.inc
++
++--connection con1
++SET GTID_NEXT = AUTOMATIC;
++--connection default
++XA ROLLBACK 'xa_prepare_detach_on';
++
++--connection con1
++SET @@SESSION.xa_detach_on_prepare = OFF;
++--let $prepare_gtid = aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:2
++--eval SET GTID_NEXT = '$prepare_gtid'
++XA START 'xa_prepare_detach_off';
++INSERT INTO t1 VALUES (2);
++XA END 'xa_prepare_detach_off';
++
++--connection default
++--let $auxiliary_connection = default
++--let $statement_connection = con1
++--let $statement = XA PREPARE 'xa_prepare_detach_off'
++--let $sync_point = after_call_actions_before_gtid_state_update
++--source include/execute_to_conditional_timestamp_sync_point.inc
++
++--let $expected_prepared_xa_count = 1
++--source extra/xa_crash_safe_tests/assert_xa_recover.inc
++--let $assert_text = GTID_EXECUTED does not contain the XA PREPARE GTID yet
++--let $has_gtid = `SELECT GTID_SUBSET('$prepare_gtid', @@GLOBAL.gtid_executed)`
++--let $assert_cond = "$has_gtid" = "0"
++--source include/assert.inc
++
++--let $reap_statement_connection = 1
++--source include/execute_from_conditional_timestamp_sync_point.inc
++--let $reap_statement_connection = 0
++--let $assert_text = GTID_EXECUTED contains the XA PREPARE GTID
++--let $has_gtid = `SELECT GTID_SUBSET('$prepare_gtid', @@GLOBAL.gtid_executed)`
++--let $assert_cond = "$has_gtid" = "1"
++--source include/assert.inc
++
++--connection con1
++SET GTID_NEXT = AUTOMATIC;
++XA ROLLBACK 'xa_prepare_detach_off';
++
++--disconnect con1
++--connection default
++DROP TABLE t1;
++RESET MASTER;
+--- /dev/null
++++ b/mysql-test/suite/binlog_gtid/t/binlog_gtid_xa_second_phase_action_lifetime.test
+@@ -0,0 +1,103 @@
++#
++# ==== PURPOSE ====
++#
++# This test checks that an XA second-phase before-GTID action does not survive
++# its statement when no GTID state update is performed.
++#
++# ==== IMPLEMENTATION ====
++#
++# Disable session binlogging so prepared XA COMMIT and ROLLBACK statements
++# finish through the TC log without updating GTID state. Then execute another
++# statement and prepare a new XA transaction on the same session.
++#
++# Test steps:
++#
++# 1. Commit and roll back attached prepared XA transactions without binlogging.
++# 2. Prepare another XA transaction with binlogging enabled after each one.
++# 3. Repeat no-binlog COMMIT and ROLLBACK with detached XA transactions.
++# 4. Execute a binlogged statement after each detached second-phase statement.
++#
++# Test pass conditions:
++#
++# - Each following XA transaction remains visible to XA RECOVER.
++# - No before-GTID action survives into the following statement.
++#
++# ==== REFERENCES ====
++#
++# BUG#36505659: XA RECOVER may list XID after GTID for XA COMMIT or
++# XA ROLLBACK is visible.
++#
++
++--source include/have_binlog_format_row.inc
++
++CREATE TABLE t1 (a INT);
++
++--echo #
++--echo # Attached XA COMMIT without a GTID update
++--echo #
++SET SESSION xa_detach_on_prepare=OFF;
++SET SESSION sql_log_bin=0;
++XA START 'old_commit';
++INSERT INTO t1 VALUES (1);
++XA END 'old_commit';
++XA PREPARE 'old_commit';
++XA COMMIT 'old_commit';
++
++# A stale action would run during the following XA PREPARE and hide its XID.
++SET SESSION sql_log_bin=1;
++XA START 'after_commit';
++INSERT INTO t1 VALUES (2);
++XA END 'after_commit';
++XA PREPARE 'after_commit';
++--let $pending_xid = query_get_value(XA RECOVER, data, 1)
++--let $assert_text = XA COMMIT action did not affect the next XA transaction
++--let $assert_cond = "$pending_xid" = "after_commit"
++--source include/assert.inc
++XA ROLLBACK 'after_commit';
++
++--echo #
++--echo # Attached XA ROLLBACK without a GTID update
++--echo #
++SET SESSION sql_log_bin=0;
++XA START 'old_rollback';
++INSERT INTO t1 VALUES (3);
++XA END 'old_rollback';
++XA PREPARE 'old_rollback';
++XA ROLLBACK 'old_rollback';
++
++# A stale action would run during the following XA PREPARE and hide its XID.
++SET SESSION sql_log_bin=1;
++XA START 'after_rollback';
++INSERT INTO t1 VALUES (4);
++XA END 'after_rollback';
++XA PREPARE 'after_rollback';
++--let $pending_xid = query_get_value(XA RECOVER, data, 1)
++--let $assert_text = XA ROLLBACK action did not affect the next XA transaction
++--let $assert_cond = "$pending_xid" = "after_rollback"
++--source include/assert.inc
++XA ROLLBACK 'after_rollback';
++
++--echo #
++--echo # Detached XA COMMIT and ROLLBACK without a GTID update
++--echo #
++SET SESSION xa_detach_on_prepare=ON;
++SET SESSION sql_log_bin=0;
++XA START 'detached_commit';
++INSERT INTO t1 VALUES (5);
++XA END 'detached_commit';
++XA PREPARE 'detached_commit';
++XA COMMIT 'detached_commit';
++SET SESSION sql_log_bin=1;
++INSERT INTO t1 VALUES (6);
++
++SET SESSION sql_log_bin=0;
++XA START 'detached_rollback';
++INSERT INTO t1 VALUES (7);
++XA END 'detached_rollback';
++XA PREPARE 'detached_rollback';
++XA ROLLBACK 'detached_rollback';
++SET SESSION sql_log_bin=1;
++INSERT INTO t1 VALUES (8);
++
++DROP TABLE t1;
++RESET MASTER;
+--- /dev/null
++++ b/mysql-test/suite/binlog_gtid/t/binlog_gtid_xa_second_phase_recover_before_gtid_externalization.test
+@@ -0,0 +1,104 @@
++# ==== Purpose ====
++#
++# Verify that XA COMMIT and XA ROLLBACK update XA RECOVER before their GTIDs
++# become visible.
++#
++# ==== Requirements ====
++#
++# R1. While XA COMMIT is paused before GTID externalization, XA RECOVER
++#     should not list the committed XID.
++# R2. While XA ROLLBACK is paused before GTID externalization, XA RECOVER
++#     should not list the rolled back XID.
++# R3. The second-phase GTID should not be visible while paused, but should
++#     become visible after XA COMMIT or XA ROLLBACK completes.
++#
++# ==== References ====
++#
++# Bug#36505659: XA RECOVER may list XID after GTID for XA COMMIT or
++#               XA ROLLBACK is visible
++
++--source include/have_debug.inc
++--source include/have_debug_sync.inc
++--source include/have_binlog_format_row.inc
++
++RESET MASTER;
++CREATE TABLE t1 (a INT);
++
++--connect(con1,localhost,root,,)
++--connect(con2,localhost,root,,)
++--connection con1
++SET @@SESSION.xa_detach_on_prepare = ON;
++XA START 'xa_commit';
++INSERT INTO t1 VALUES (1);
++XA END 'xa_commit';
++XA PREPARE 'xa_commit';
++
++--connection con2
++--let $commit_gtid = aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1
++--eval SET GTID_NEXT = '$commit_gtid'
++--connection default
++--let $auxiliary_connection = default
++--let $statement_connection = con2
++--let $statement = XA COMMIT 'xa_commit'
++--let $sync_point = after_call_actions_before_gtid_state_update
++--source include/execute_to_conditional_timestamp_sync_point.inc
++
++--let $expected_prepared_xa_count = 0
++--source extra/xa_crash_safe_tests/assert_xa_recover.inc
++--let $assert_text = GTID_EXECUTED does not contain the XA COMMIT GTID yet
++--let $has_gtid = `SELECT GTID_SUBSET('$commit_gtid', @@GLOBAL.gtid_executed)`
++--let $assert_cond = "$has_gtid" = "0"
++--source include/assert.inc
++
++--let $reap_statement_connection = 1
++--source include/execute_from_conditional_timestamp_sync_point.inc
++--let $reap_statement_connection = 0
++--let $assert_text = GTID_EXECUTED contains the XA COMMIT GTID
++--let $has_gtid = `SELECT GTID_SUBSET('$commit_gtid', @@GLOBAL.gtid_executed)`
++--let $assert_cond = "$has_gtid" = "1"
++--source include/assert.inc
++
++--connection con2
++SET GTID_NEXT = AUTOMATIC;
++
++--connection con1
++XA START 'xa_rollback';
++INSERT INTO t1 VALUES (2);
++XA END 'xa_rollback';
++XA PREPARE 'xa_rollback';
++
++--connection con2
++--let $rollback_gtid = aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:2
++--eval SET GTID_NEXT = '$rollback_gtid'
++--connection default
++--let $auxiliary_connection = default
++--let $statement_connection = con2
++--let $statement = XA ROLLBACK 'xa_rollback'
++--let $sync_point = after_call_actions_before_gtid_state_update
++--source include/execute_to_conditional_timestamp_sync_point.inc
++
++--let $expected_prepared_xa_count = 0
++--source extra/xa_crash_safe_tests/assert_xa_recover.inc
++--let $assert_text = GTID_EXECUTED does not contain the XA ROLLBACK GTID yet
++--let $has_gtid = `SELECT GTID_SUBSET('$rollback_gtid', @@GLOBAL.gtid_executed)`
++--let $assert_cond = "$has_gtid" = "0"
++--source include/assert.inc
++
++--let $reap_statement_connection = 1
++--source include/execute_from_conditional_timestamp_sync_point.inc
++--let $reap_statement_connection = 0
++--let $assert_text = GTID_EXECUTED contains the XA ROLLBACK GTID
++--let $has_gtid = `SELECT GTID_SUBSET('$rollback_gtid', @@GLOBAL.gtid_executed)`
++--let $assert_cond = "$has_gtid" = "1"
++--source include/assert.inc
++
++--connection con2
++SET GTID_NEXT = AUTOMATIC;
++
++SELECT * FROM t1;
++
++--disconnect con2
++--disconnect con1
++--connection default
++DROP TABLE t1;
++RESET MASTER;
+--- a/mysql-test/suite/binlog_nogtid/r/binlog_stm_ctype_ucs.result
++++ b/mysql-test/suite/binlog_nogtid/r/binlog_stm_ctype_ucs.result
+@@ -40,7 +40,11 @@ SET @@session.collation_database=DEFAULT
+ /*!80011 SET @@session.default_collation_for_utf8mb4=255*//*!*/;
+ BEGIN
+ /*!*/;
++/*!\C utf8mb3 *//*!*/;
++SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
+ SET @`v`:=_ucs2 0x006100620063 COLLATE `ucs2_general_ci`/*!*/;
++/*!\C utf8mb4 *//*!*/;
++SET @@session.character_set_client=255,@@session.collation_connection=255,@@session.collation_server=255/*!*/;
+ use `test`/*!*/;
+ SET TIMESTAMP=#/*!*/;
+ insert into t2 values (@v)
+--- /dev/null
++++ b/mysql-test/suite/binlog_nogtid/t/binlog_xa_gtid_consistency_violation-master.opt
+@@ -0,0 +1 @@
++--xa-detach-on-prepare=OFF
+--- a/mysql-test/suite/gis/r/geojson_functions.result
++++ b/mysql-test/suite/gis/r/geojson_functions.result
+@@ -4267,3 +4267,36 @@ SELECT JSON_ARRAY(ST_ASGEOJSON(ST_GEOMFR
+ ERROR 22023: Invalid GIS data provided to function st_geomfromtext.
+ SELECT JSON_ARRAY(ST_ASGEOJSON(0x00), 1);
+ ERROR 22023: Invalid GIS data provided to function st_asgeojson.
++#
++# Bug#39616304 ST_ASGEOJSON ON A DEEPLY NESTED GEOMETRYCOLLECTION
++#              CRASHES THE SERVER
++#
++SELECT LENGTH(ST_AsGeoJSON(CONCAT(_binary 0x00000000,
++REPEAT(_binary 0x010700000001000000, 10),
++_binary 0x010700000000000000)));
++LENGTH(ST_AsGeoJSON(CONCAT(_binary 0x00000000,
++REPEAT(_binary 0x010700000001000000, 10),
++_binary 0x010700000000000000)))
++528
++SELECT LENGTH(ST_AsGeoJSON(CONCAT(_binary 0x00000000,
++REPEAT(_binary 0x010700000001000000, 49),
++_binary 0x010700000000000000)));
++LENGTH(ST_AsGeoJSON(CONCAT(_binary 0x00000000,
++REPEAT(_binary 0x010700000001000000, 49),
++_binary 0x010700000000000000)))
++2400
++SELECT LENGTH(ST_AsGeoJSON(CONCAT(_binary 0x00000000,
++REPEAT(_binary 0x010700000001000000, 50),
++_binary 0x010700000000000000)));
++ERROR 22032: The JSON document exceeds the maximum depth.
++SELECT ST_AsGeoJSON(CONCAT(_binary 0x00000000,
++REPEAT(_binary 0x010700000001000000, 120000),
++_binary 0x010700000000000000));
++ERROR 22032: The JSON document exceeds the maximum depth.
++CREATE TABLE t1 (g GEOMETRY);
++INSERT INTO t1 VALUES (CONCAT(_binary 0x00000000,
++REPEAT(_binary 0x010700000001000000, 200),
++_binary 0x010700000000000000));
++SELECT CAST(g AS JSON) FROM t1;
++ERROR 22032: The JSON document exceeds the maximum depth.
++DROP TABLE t1;
+--- a/mysql-test/suite/gis/t/geojson_functions.test
++++ b/mysql-test/suite/gis/t/geojson_functions.test
+@@ -4090,3 +4090,44 @@ SELECT JSON_ARRAY(ST_ASGEOJSON(ST_GEOMFR
+ # Exercise a previously untested error path.
+ --error ER_GIS_INVALID_DATA
+ SELECT JSON_ARRAY(ST_ASGEOJSON(0x00), 1);
++
++--echo #
++--echo # Bug#39616304 ST_ASGEOJSON ON A DEEPLY NESTED GEOMETRYCOLLECTION
++--echo #              CRASHES THE SERVER
++--echo #
++
++# Shallow nesting succeeds.
++SELECT LENGTH(ST_AsGeoJSON(CONCAT(_binary 0x00000000,
++                                  REPEAT(_binary 0x010700000001000000, 10),
++                                  _binary 0x010700000000000000)));
++
++# The two sides of the limit. Each nested GeometryCollection contributes two
++# levels to the GeoJSON document (the object and its "geometries" array), so
++# the deepest input that can be serialized has 49 nested collections plus the
++# empty terminator. This boundary is set by the JSON document depth limit, not
++# by the recursion guard added for this bug, which only takes effect deeper.
++SELECT LENGTH(ST_AsGeoJSON(CONCAT(_binary 0x00000000,
++                                  REPEAT(_binary 0x010700000001000000, 49),
++                                  _binary 0x010700000000000000)));
++
++--error ER_JSON_DOCUMENT_TOO_DEEP
++SELECT LENGTH(ST_AsGeoJSON(CONCAT(_binary 0x00000000,
++                                  REPEAT(_binary 0x010700000001000000, 50),
++                                  _binary 0x010700000000000000)));
++
++# Deep nesting is rejected instead of overflowing the stack. This is the case
++# that exercises the recursion guard: without it the recursion runs to the
++# nesting depth of the input and terminates the server.
++--error ER_JSON_DOCUMENT_TOO_DEEP
++SELECT ST_AsGeoJSON(CONCAT(_binary 0x00000000,
++                           REPEAT(_binary 0x010700000001000000, 120000),
++                           _binary 0x010700000000000000));
++
++# Same recursion path via CAST(<geometry> AS JSON).
++CREATE TABLE t1 (g GEOMETRY);
++INSERT INTO t1 VALUES (CONCAT(_binary 0x00000000,
++                              REPEAT(_binary 0x010700000001000000, 200),
++                              _binary 0x010700000000000000));
++--error ER_JSON_DOCUMENT_TOO_DEEP
++SELECT CAST(g AS JSON) FROM t1;
++DROP TABLE t1;
+--- /dev/null
++++ b/mysql-test/suite/innodb/include/evict_everything_from_buffer_pool_cleanup.inc
+@@ -0,0 +1,6 @@
++#
++# Drop the table prepared by evict_everything_from_buffer_pool_prepare.inc.
++#
++
++UNLOCK TABLES;
++DROP TABLE _big;
+--- /dev/null
++++ b/mysql-test/suite/innodb/include/evict_everything_from_buffer_pool_evict.inc
+@@ -0,0 +1,7 @@
++#
++# Scan the prepared eviction table to push other pages out of the buffer pool.
++#
++
++-- disable_result_log
++SELECT * FROM _big WHERE a = 'find nothing';
++-- enable_result_log
+--- a/mysql-test/suite/innodb/include/evict_everything_from_buffer_pool.inc
++++ b/mysql-test/suite/innodb/include/evict_everything_from_buffer_pool.inc
+@@ -9,24 +9,12 @@
+ 
+ -- echo # Emptying InnoDB buffer pool: begin
+ 
+-CREATE TABLE _big (a TEXT) ENGINE=INNODB;
+ -- let $bp_size = `SELECT @@innodb_buffer_pool_size`
++-- source suite/innodb/include/evict_everything_from_buffer_pool_prepare.inc
+ -- echo # Buffer pool size: $bp_size bytes
+--- let $table_size = `SELECT ROUND($bp_size * 2.0)`
+ -- echo # Creating and dropping a table with size: $table_size bytes
+--- let $row_size = 1024
+--- let $i = `SELECT ROUND($table_size / $row_size)`
<Skipped 13616 lines>
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/mysql.git/commitdiff/a77312db85a4628dda1ed3e56296a0b40e0fdd42



More information about the pld-cvs-commit mailing list