[packages/mysql/MYSQL_5_7] Rel 4. Backport Percona 5.7.44-48..60 post-EOL fixes
arekm
arekm at pld-linux.org
Mon Nov 2 15:23:13 CET 2026
commit 8670471c4ee390a70934c3ee30adeb1369b8d7dd
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Mon Nov 2 15:20:39 2026 +0100
Rel 4. Backport Percona 5.7.44-48..60 post-EOL fixes
Port 83 fixes Percona carried after the 5.7 EOL, plus PLD fixes for
mysqldump buffer handling; drop unused BuildRequires.
Fixes CVE-2024-20963.
mysql-append-identifier-overread.patch | 18 +
mysql-avg-decimal-scale.patch | 16 +
mysql-blob-prefix-key-field.patch | 78 ++
mysql-broken-utf8-overflow.patch | 138 +++
mysql-btr-merge-backward-scan.patch | 31 +
mysql-btr-pcur-close-leak.patch | 93 ++
mysql-buffer-pool-max-size.patch | 27 +
mysql-client-commands-option.patch | 116 ++
mysql-client-hint-comment.patch | 17 +
mysql-client-system-command-option.patch | 54 +
mysql-client-table-leak.patch | 25 +
mysql-connect-attrs-oob.patch | 30 +
mysql-connection-control-wait.patch | 29 +
mysql-drop-user-acl-cache.patch | 15 +
mysql-dump-comment-buffer-reuse.patch | 21 +
mysql-dump-server-version.patch | 64 ++
mysql-dump-tablespace-escape.patch | 259 +++++
mysql-dump-view-query-escape.patch | 41 +
mysql-fake-rotate-event.patch | 95 ++
mysql-fk-cascade-vcol-crash.patch | 28 +
mysql-fk-cascade-vcol-update.patch | 220 ++++
mysql-fk-pad-col-assert.patch | 54 +
mysql-fts-doc-id-64bit.patch | 745 +++++++++++++
mysql-fts-doc-id-cmp.patch | 313 ++++++
mysql-fts-drop-add-index.patch | 84 ++
mysql-fts-ngram-percent.patch | 120 ++
mysql-fts-optimize-last-word.patch | 134 +++
mysql-fts-self-fk-cascade.patch | 155 +++
mysql-fts-sort-mem-limit.patch | 166 +++
mysql-fts-sync-concurrency.patch | 111 ++
mysql-geofunc-uaf.patch | 35 +
mysql-getopt-help-overrun.patch | 33 +
mysql-gis-temp-bulk-insert.patch | 17 +
mysql-gr-applier-validate.patch | 47 +
mysql-gr-certifier-gtid-set.patch | 220 ++++
mysql-gr-payload-decode.patch | 1545 ++++++++++++++++++++++++++
mysql-gr-snapshot-validate.patch | 104 ++
mysql-greedy-search-no-plan.patch | 25 +
mysql-gtid-executed-crash-save.patch | 57 +
mysql-gtid-interval-length.patch | 164 +++
mysql-heartbeat-validate.patch | 84 ++
mysql-ibuf-restore-pos.patch | 66 ++
mysql-innodb-locks-crash.patch | 24 +
mysql-item-ref-uaf.patch | 44 +
mysql-join-max-tables.patch | 30 +
mysql-lex-end-comment-delimiter.patch | 16 +
mysql-lex-hints-crash.patch | 20 +
mysql-lex-off-by-one.patch | 17 +
mysql-loose-index-scan-results.patch | 22 +
mysql-make-set-pullout.patch | 64 ++
mysql-md5-length.patch | 35 +
mysql-multisource-get-mi-overflow.patch | 16 +
mysql-packed-row-size.patch | 83 ++
mysql-parser-crash.patch | 19 +
mysql-parser-kill-large-query.patch | 85 ++
mysql-plugin-deinit.patch | 85 ++
mysql-privilege-desc-bounds.patch | 14 +
mysql-queued-event-validate.patch | 87 ++
mysql-receiver-event-type.patch | 81 ++
mysql-rewriter-autocommit.patch | 15 +
mysql-rollup-sum-switcher-crash.patch | 87 ++
mysql-row-upd-primary-corrupted.patch | 42 +
mysql-rows-event-width.patch | 30 +
mysql-rtree-shutdown-leak.patch | 15 +
mysql-spatial-deadlock.patch | 84 ++
mysql-spatial-index-optimizer.patch | 37 +
mysql-spatial-inplace-alter-corruption.patch | 25 +
mysql-sql-table-comparator.patch | 15 +
mysql-strfunc-strlen-overflow.patch | 15 +
mysql-subselect-null-name.patch | 18 +
mysql-table-map-meta-bounds.patch | 120 ++
mysql-table-map-name-length.patch | 29 +
mysql-trx-in-innodb-hang.patch | 80 ++
mysql-updatexml-root-copy.patch | 33 +
mysql-user-var-decimal-meta.patch | 115 ++
mysql-varchar-deadlock.patch | 21 +
mysql-vcol-index-corruption.patch | 28 +
mysql-vcol-index-id-32bit.patch | 49 +
mysql-wait-until-gtids-validate.patch | 15 +
mysql-xcom-client-msg-injection.patch | 499 +++++++++
mysql-xml-parse-slash.patch | 45 +
mysql-xplugin-mysql41-auth.patch | 18 +
mysql-xplugin-no-backslash-escapes.patch | 529 +++++++++
mysql.spec | 174 ++-
84 files changed, 8569 insertions(+), 5 deletions(-)
---
diff --git a/mysql.spec b/mysql.spec
index ad839d6..da296e9 100644
--- a/mysql.spec
+++ b/mysql.spec
@@ -36,7 +36,7 @@ Summary(uk.UTF-8): MySQL - швидкий SQL-сервер
Summary(zh_CN.UTF-8): MySQL数据库服务器
Name: mysql
Version: 5.7.44
-Release: 3
+Release: 4
License: GPL v2 + MySQL FOSS License Exception
Group: Applications/Databases
#Source0Download: https://dev.mysql.com/downloads/mysql/5.7.html#downloads
@@ -71,15 +71,97 @@ Patch6: %{name}-cmake.patch
Patch7: %{name}-readline.patch
Patch8: %{name}dumpslow-clusters.patch
Patch9: %{name}-sig_return.patch
+# fixes Percona carried in 5.7.44-48..60 (post-EOL), see each patch
+Patch100: %{name}-md5-length.patch
+Patch101: %{name}-fts-ngram-percent.patch
+Patch102: %{name}-dump-server-version.patch
+Patch103: %{name}-make-set-pullout.patch
+Patch104: %{name}-subselect-null-name.patch
+Patch105: %{name}-loose-index-scan-results.patch
+Patch106: %{name}-gr-certifier-gtid-set.patch
+Patch107: %{name}-trx-in-innodb-hang.patch
+Patch108: %{name}-fts-sync-concurrency.patch
+Patch109: %{name}-plugin-deinit.patch
+Patch110: %{name}-btr-merge-backward-scan.patch
+Patch111: %{name}-gtid-executed-crash-save.patch
+Patch112: %{name}-ibuf-restore-pos.patch
+Patch113: %{name}-avg-decimal-scale.patch
+Patch114: %{name}-item-ref-uaf.patch
+Patch115: %{name}-spatial-index-optimizer.patch
+Patch116: %{name}-connection-control-wait.patch
+Patch117: %{name}-fts-optimize-last-word.patch
+Patch118: %{name}-privilege-desc-bounds.patch
+Patch119: %{name}-client-system-command-option.patch
+Patch120: %{name}-dump-tablespace-escape.patch
+Patch121: %{name}-strfunc-strlen-overflow.patch
+Patch122: %{name}-lex-hints-crash.patch
+Patch123: %{name}-fts-doc-id-cmp.patch
+Patch124: %{name}-updatexml-root-copy.patch
+Patch125: %{name}-client-table-leak.patch
+Patch126: %{name}-fts-drop-add-index.patch
+Patch127: %{name}-row-upd-primary-corrupted.patch
+Patch128: %{name}-fk-cascade-vcol-crash.patch
+Patch129: %{name}-drop-user-acl-cache.patch
+Patch130: %{name}-fts-self-fk-cascade.patch
+Patch131: %{name}-getopt-help-overrun.patch
+Patch132: %{name}-client-hint-comment.patch
+Patch133: %{name}-spatial-inplace-alter-corruption.patch
+Patch134: %{name}-fk-pad-col-assert.patch
+Patch135: %{name}-rollup-sum-switcher-crash.patch
+Patch136: %{name}-sql-table-comparator.patch
+Patch137: %{name}-fts-doc-id-64bit.patch
+Patch138: %{name}-broken-utf8-overflow.patch
+Patch139: %{name}-append-identifier-overread.patch
+Patch140: %{name}-multisource-get-mi-overflow.patch
+Patch141: %{name}-geofunc-uaf.patch
+Patch142: %{name}-dump-view-query-escape.patch
+Patch143: %{name}-btr-pcur-close-leak.patch
+Patch144: %{name}-vcol-index-id-32bit.patch
+Patch145: %{name}-lex-end-comment-delimiter.patch
+Patch146: %{name}-wait-until-gtids-validate.patch
+Patch147: %{name}-client-commands-option.patch
+Patch148: %{name}-blob-prefix-key-field.patch
+Patch149: %{name}-rewriter-autocommit.patch
+Patch150: %{name}-lex-off-by-one.patch
+Patch151: %{name}-vcol-index-corruption.patch
+Patch152: %{name}-buffer-pool-max-size.patch
+Patch153: %{name}-innodb-locks-crash.patch
+Patch154: %{name}-gis-temp-bulk-insert.patch
+Patch155: %{name}-join-max-tables.patch
+Patch156: %{name}-gr-applier-validate.patch
+Patch157: %{name}-gr-snapshot-validate.patch
+Patch158: %{name}-spatial-deadlock.patch
+Patch159: %{name}-varchar-deadlock.patch
+Patch160: %{name}-fts-sort-mem-limit.patch
+Patch161: %{name}-greedy-search-no-plan.patch
+Patch162: %{name}-parser-crash.patch
+Patch163: %{name}-parser-kill-large-query.patch
+Patch164: %{name}-rtree-shutdown-leak.patch
+Patch165: %{name}-connect-attrs-oob.patch
+Patch166: %{name}-xplugin-no-backslash-escapes.patch
+Patch167: %{name}-xplugin-mysql41-auth.patch
+Patch168: %{name}-gr-payload-decode.patch
+Patch169: %{name}-xcom-client-msg-injection.patch
+Patch170: %{name}-xml-parse-slash.patch
+Patch171: %{name}-table-map-name-length.patch
+Patch172: %{name}-user-var-decimal-meta.patch
+Patch173: %{name}-table-map-meta-bounds.patch
+Patch174: %{name}-receiver-event-type.patch
+Patch175: %{name}-gtid-interval-length.patch
+Patch176: %{name}-fake-rotate-event.patch
+Patch177: %{name}-queued-event-validate.patch
+Patch178: %{name}-rows-event-width.patch
+Patch179: %{name}-packed-row-size.patch
+Patch180: %{name}-heartbeat-validate.patch
+Patch181: %{name}-fk-cascade-vcol-update.patch
+Patch182: %{name}-dump-comment-buffer-reuse.patch
URL: http://www.mysql.com/products/community/
-BuildRequires: automake
BuildRequires: bison >= 1.875
%{?with_system_boost:BuildRequires: boost-devel >= 1.59.0}
BuildRequires: cmake >= 2.8.9
BuildRequires: libaio-devel
BuildRequires: libatomic-devel
BuildRequires: libevent-devel
-BuildRequires: libhsclient-devel
BuildRequires: libstdc++-devel >= 5:4.0
BuildRequires: libtirpc-devel >= 1.0.0
%{?with_tcpd:BuildRequires: libwrap-devel}
@@ -88,10 +170,8 @@ BuildRequires: mecab-devel
BuildRequires: ncurses-devel >= 4.2
%{?with_ssl:BuildRequires: openssl-devel >= 0.9.7d}
%{?with_ldap:BuildRequires: openldap-devel}
-BuildRequires: pam-devel
BuildRequires: perl-devel >= 1:5.6.1
%{?with_system_protobuf:BuildRequires: protobuf-devel >= 2.5}
-BuildRequires: python-modules
BuildRequires: readline-devel >= 6.2
BuildRequires: rpcsvc-proto
BuildRequires: rpm-build >= 4.6
@@ -485,6 +565,90 @@ Ten pakiet zawiera standardowego demona MySQL NDB CPC.
%patch -P8 -p1
%patch -P9 -p1
+%patch -P100 -p1
+%patch -P101 -p1
+%patch -P102 -p1
+%patch -P103 -p1
+%patch -P104 -p1
+%patch -P105 -p1
+%patch -P106 -p1
+%patch -P107 -p1
+%patch -P108 -p1
+%patch -P109 -p1
+%patch -P110 -p1
+%patch -P111 -p1
+%patch -P112 -p1
+%patch -P113 -p1
+%patch -P114 -p1
+%patch -P115 -p1
+%patch -P116 -p1
+%patch -P117 -p1
+%patch -P118 -p1
+%patch -P119 -p1
+%patch -P120 -p1
+%patch -P121 -p1
+%patch -P122 -p1
+%patch -P123 -p1
+%patch -P124 -p1
+%patch -P125 -p1
+%patch -P126 -p1
+%patch -P127 -p1
+%patch -P128 -p1
+%patch -P129 -p1
+%patch -P130 -p1
+%patch -P131 -p1
+%patch -P132 -p1
+%patch -P133 -p1
+%patch -P134 -p1
+%patch -P135 -p1
+%patch -P136 -p1
+%patch -P137 -p1
+%patch -P138 -p1
+%patch -P139 -p1
+%patch -P140 -p1
+%patch -P141 -p1
+%patch -P142 -p1
+%patch -P143 -p1
+%patch -P144 -p1
+%patch -P145 -p1
+%patch -P146 -p1
+%patch -P147 -p1
+%patch -P148 -p1
+%patch -P149 -p1
+%patch -P150 -p1
+%patch -P151 -p1
+%patch -P152 -p1
+%patch -P153 -p1
+%patch -P154 -p1
+%patch -P155 -p1
+%patch -P156 -p1
+%patch -P157 -p1
+%patch -P158 -p1
+%patch -P159 -p1
+%patch -P160 -p1
+%patch -P161 -p1
+%patch -P162 -p1
+%patch -P163 -p1
+%patch -P164 -p1
+%patch -P165 -p1
+%patch -P166 -p1
+%patch -P167 -p1
+%patch -P168 -p1
+%patch -P169 -p1
+%patch -P170 -p1
+%patch -P171 -p1
+%patch -P172 -p1
+%patch -P173 -p1
+%patch -P174 -p1
+%patch -P175 -p1
+%patch -P176 -p1
+%patch -P177 -p1
+%patch -P178 -p1
+%patch -P179 -p1
+%patch -P180 -p1
+%patch -P181 -p1
+%patch -P182 -p1
+
# to get these files rebuild
[ -f sql/sql_yacc.cc ] && %{__rm} sql/sql_yacc.cc
[ -f sql/sql_yacc.h ] && %{__rm} sql/sql_yacc.h
diff --git a/mysql-append-identifier-overread.patch b/mysql-append-identifier-overread.patch
new file mode 100644
index 0000000..12e3951
--- /dev/null
+++ b/mysql-append-identifier-overread.patch
@@ -0,0 +1,18 @@
+ASAN: NAME_CONST WITH INVALID IDENTIFIER, HEAP-BUFFER-OVERFLOW
+(Bug#22958632)
+https://github.com/percona/percona-server/commit/b3d19a5392
+https://github.com/mysql/mysql-server/commit/5f3490aea8c
+
+--- mysql-5.7.44.orig/sql/sql_show.cc
++++ mysql-5.7.44/sql/sql_show.cc
+@@ -1281,7 +1281,9 @@ append_identifier(THD *thd, String *packet, const char *name, size_t length,
+ to_length= 1;
+ if (to_length == 1 && chr == static_cast<uchar>(quote_char))
+ packet->append("e_char, 1, system_charset_info);
+- packet->append(to_name, to_length, system_charset_info);
++ packet->append(to_name,
++ std::min(to_length, static_cast<size_t>(name_end - to_name)),
++ system_charset_info);
+ }
+ packet->append("e_char, 1, system_charset_info);
+ }
diff --git a/mysql-avg-decimal-scale.patch b/mysql-avg-decimal-scale.patch
new file mode 100644
index 0000000..bfbf9cc
--- /dev/null
+++ b/mysql-avg-decimal-scale.patch
@@ -0,0 +1,16 @@
+MYSQL SERVER 8.3.0 GLOBAL-BUFFER-OVERFLOW AT 'DECIMAL_BIN_SIZE_INLINE'
+(Bug#36563773)
+https://github.com/percona/percona-server/commit/2a26b295f3
+https://github.com/mysql/mysql-server/commit/2f67801d010
+
+--- mysql-5.7.44.orig/sql/item_sum.cc
++++ mysql-5.7.44/sql/item_sum.cc
+@@ -1727,7 +1727,7 @@ void Item_sum_avg::fix_length_and_dec()
+ decimals,
+ unsigned_flag);
+ f_precision= min(precision+DECIMAL_LONGLONG_DIGITS, DECIMAL_MAX_PRECISION);
+- f_scale= args[0]->decimals;
++ f_scale = min<uint>(args[0]->decimals, f_precision);
+ dec_bin_size= my_decimal_get_binary_size(f_precision, f_scale);
+ }
+ else {
diff --git a/mysql-blob-prefix-key-field.patch b/mysql-blob-prefix-key-field.patch
new file mode 100644
index 0000000..2053fc7
--- /dev/null
+++ b/mysql-blob-prefix-key-field.patch
@@ -0,0 +1,78 @@
+>=5.6.36 SOME RANGE QUERIES STILL CRASH (Bug#31360522, Bug#23481444)
+https://github.com/percona/percona-server/commit/170d346611
+https://github.com/mysql/mysql-server/commit/c51237cec9f
+Fixes a memory leak with prefix index on blob columns
+https://github.com/percona/percona-server/commit/115708f851
+
+--- mysql-5.7.44.orig/sql/sql_partition.cc
++++ mysql-5.7.44/sql/sql_partition.cc
+@@ -833,6 +833,12 @@ static bool handle_list_of_fields(List_iterator<char> it,
+ for (i= 0; i < num_key_parts; i++)
+ {
+ Field *field= table->key_info[primary_key].key_part[i].field;
++ // BLOB/TEXT columns are not allowed in partitioning keys.
++ if (field->flags & BLOB_FLAG)
++ {
++ my_error(ER_BLOB_FIELD_IN_PART_FUNC_ERROR, MYF(0));
++ DBUG_RETURN(TRUE);
++ }
+ field->flags|= GET_FIXED_FIELDS_FLAG;
+ }
+ }
+--- mysql-5.7.44.orig/sql/table.cc
++++ mysql-5.7.44/sql/table.cc
+@@ -3241,8 +3241,15 @@ int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
+ {
+ Field *field= key_part->field= outparam->field[key_part->fieldnr-1];
+
++ /*
++ For spatial indexes, the key parts are assigned the length (4 *
++ sizeof(double)) in mysql_prepare_create_table() and the
++ field->key_length() is set to 0. This makes it appear like a prefixed
++ index. However, prefixed indexes are not allowed on Geometric columns.
++ Hence skipping new field creation for Geometric columns.
++ */
+ if (field->key_length() != key_part->length &&
+- !(field->flags & BLOB_FLAG))
++ field->type() != MYSQL_TYPE_GEOMETRY)
+ {
+ /*
+ We are using only a prefix of the column as a key:
+@@ -3512,6 +3519,37 @@ int closefrm(TABLE *table, bool free_share)
+ error=table->file->ha_close();
+ my_free((void *) table->alias);
+ table->alias= 0;
++
++ /*
++ Iterate through the Table's Key_info and free its key_part->field if the
++ field is of BLOB type.
++
++ When a prefixed key is present, a new Field object is created in
++ open_table_from_share(). These field objects get destroyed when the Table's
++ mem_root is cleared here later. In case of Field_blob objects,
++ Field_blob::value is allocated on the heap. Thus Field_blob objects are
++ freed here in order to destruct the Field_blob::value object.
++ */
++ KEY *key_info= table->key_info;
++ if (key_info)
++ {
++ for (KEY *key_info_end= key_info + table->s->keys; key_info < key_info_end;
++ key_info++)
++ {
++ KEY_PART_INFO *key_part= key_info->key_part;
++ for (KEY_PART_INFO *key_part_end= key_part + key_info->actual_key_parts;
++ key_part < key_part_end; key_part++)
++ {
++ if (key_part->field && (key_part->field->flags & BLOB_FLAG) &&
++ key_part->field->type() != MYSQL_TYPE_GEOMETRY)
++ {
++ delete key_part->field;
++ key_part->field= 0;
++ }
++ }
++ }
++ }
++
+ if (table->field)
+ {
+ for (Field **ptr=table->field ; *ptr ; ptr++)
diff --git a/mysql-broken-utf8-overflow.patch b/mysql-broken-utf8-overflow.patch
new file mode 100644
index 0000000..c999e1d
--- /dev/null
+++ b/mysql-broken-utf8-overflow.patch
@@ -0,0 +1,138 @@
+BUFFER OVERFLOW IN USERVAR,USERNAME,HOSTNAME WITH BROKEN UTF8
+(Bug#27618273, Bug#28787272)
+https://github.com/percona/percona-server/commit/d7b148d154
+https://github.com/mysql/mysql-server/commit/2109aa7ec3a
+
+--- mysql-5.7.44.orig/include/sql_string.h
++++ mysql-5.7.44/include/sql_string.h
+@@ -78,6 +78,8 @@ public:
+ {
+ set(arg.str, arg.length);
+ }
++ Simple_cstring(const LEX_CSTRING arg) { set(arg.str, arg.length); }
++
+ void reset()
+ {
+ set(NULL, 0);
+--- mysql-5.7.44.orig/sql-common/sql_string.cc
++++ mysql-5.7.44/sql-common/sql_string.cc
+@@ -1304,8 +1304,7 @@ size_t bin_to_hex_str(char *to, size_t to_len, char *from, size_t from_len)
+ prefix for a character, i.e. the byte length
+ of that invalid character is undefined.
+
+- @retval true if the whole input byte sequence is a valid character string.
+- The length_error output parameter is undefined.
++ @retval true if the input is invalid.
+
+ @return
+ if the whole input byte sequence is a valid character string
+--- mysql-5.7.44.orig/sql/item.h
++++ mysql-5.7.44/sql/item.h
+@@ -254,6 +254,7 @@ public:
+ Name_string(const char *str, size_t length):
+ Simple_cstring(str, length) {}
+ Name_string(const LEX_STRING str): Simple_cstring(str) {}
++ Name_string(const LEX_CSTRING str) : Simple_cstring(str) {}
+ Name_string(const char *str, size_t length, bool is_null_terminated):
+ Simple_cstring()
+ {
+--- mysql-5.7.44.orig/sql/parse_tree_items.cc
++++ mysql-5.7.44/sql/parse_tree_items.cc
+@@ -189,7 +189,7 @@ bool PTI_expr_with_alias::itemize(Parse_context *pc, Item **res)
+ if (alias.str)
+ {
+ if (pc->thd->lex->sql_command == SQLCOM_CREATE_VIEW &&
+- check_column_name(alias.str))
++ check_column_name(alias))
+ {
+ my_error(ER_WRONG_COLUMN_NAME, MYF(0), alias.str);
+ return true;
+--- mysql-5.7.44.orig/sql/sql_class.h
++++ mysql-5.7.44/sql/sql_class.h
+@@ -5506,7 +5506,7 @@ public:
+ */
+ static user_var_entry *create(THD *thd, const Name_string &name, const CHARSET_INFO *cs)
+ {
+- if (check_column_name(name.ptr()))
++ if (check_column_name(name))
+ {
+ my_error(ER_ILLEGAL_USER_VAR, MYF(0), name.ptr());
+ return NULL;
+--- mysql-5.7.44.orig/sql/sql_table.cc
++++ mysql-5.7.44/sql/sql_table.cc
+@@ -3731,7 +3731,7 @@ mysql_prepare_create_table(THD *thd, const char *error_schema_name,
+ if (!(sql_field->flags & NOT_NULL_FLAG))
+ null_fields++;
+
+- if (check_column_name(sql_field->field_name))
++ if (check_column_name(to_lex_cstring(sql_field->field_name)))
+ {
+ my_error(ER_WRONG_COLUMN_NAME, MYF(0), sql_field->field_name);
+ DBUG_RETURN(TRUE);
+@@ -4479,7 +4479,7 @@ mysql_prepare_create_table(THD *thd, const char *error_schema_name,
+ }
+ }
+ key_info->actual_flags= key_info->flags;
+- if (!key_info->name || check_column_name(key_info->name))
++ if (!key_info->name || check_column_name(to_lex_cstring(key_info->name)))
+ {
+ my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key_info->name);
+ DBUG_RETURN(TRUE);
+--- mysql-5.7.44.orig/sql/sql_view.cc
++++ mysql-5.7.44/sql/sql_view.cc
+@@ -181,7 +181,7 @@ static void make_valid_column_names(LEX *lex)
+ for (List_iterator_fast<Item> it(sl->item_list); (item= it++); column_no++)
+ {
+ if (!item->item_name.is_autogenerated() ||
+- !check_column_name(item->item_name.ptr()))
++ !check_column_name(item->item_name))
+ continue;
+ name_len= my_snprintf(buff, NAME_LEN, "Name_exp_%u", column_no);
+ item->orig_name= item->item_name;
+--- mysql-5.7.44.orig/sql/table.cc
++++ mysql-5.7.44/sql/table.cc
+@@ -4306,19 +4306,20 @@ enum_ident_name_check check_table_name(const char *name, size_t length,
+ }
+
+
+-bool check_column_name(const char *name)
+-{
++bool check_column_name(const Name_string &namestring) {
+ // name length in symbols
+ size_t name_length= 0;
+ bool last_char_is_space= TRUE;
++ const char *name = namestring.ptr();
++ const char *name_end = name + namestring.length();
++ const bool is_multibyte = use_mb(system_charset_info);
+
+ while (*name)
+ {
+ last_char_is_space= my_isspace(system_charset_info, *name);
+- if (use_mb(system_charset_info))
++ if (is_multibyte)
+ {
+- int len=my_ismbchar(system_charset_info, name,
+- name+system_charset_info->mbmaxlen);
++ int len=my_ismbchar(system_charset_info, name, name_end);
+ if (len)
+ {
+ name += len;
+--- mysql-5.7.44.orig/sql/table.h
++++ mysql-5.7.44/sql/table.h
+@@ -57,6 +57,7 @@ struct LEX;
+ typedef int8 plan_idx;
+ class Opt_hints_qb;
+ class Opt_hints_table;
++class Name_string;
+
+ #define store_record(A,B) memcpy((A)->B,(A)->record[0],(size_t) (A)->s->reclength)
+ #define restore_record(A,B) memcpy((A)->record[0],(A)->B,(size_t) (A)->s->reclength)
+@@ -2981,7 +2982,7 @@ void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
+ void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form);
+ enum_ident_name_check check_and_convert_db_name(LEX_STRING *db,
+ bool preserve_lettercase);
+-bool check_column_name(const char *name);
++bool check_column_name(const Name_string &name);
+ enum_ident_name_check check_table_name(const char *name, size_t length,
+ bool check_for_path_chars);
+ int rename_file_ext(const char * from,const char * to,const char * ext);
diff --git a/mysql-btr-merge-backward-scan.patch b/mysql-btr-merge-backward-scan.patch
new file mode 100644
index 0000000..87b612b
--- /dev/null
+++ b/mysql-btr-merge-backward-scan.patch
@@ -0,0 +1,31 @@
+Data inconsistencies when high rate of pages split/merge
+https://github.com/percona/percona-server/commit/9242483661
+
+--- mysql-5.7.44.orig/storage/innobase/btr/btr0btr.cc
++++ mysql-5.7.44/storage/innobase/btr/btr0btr.cc
+@@ -3617,6 +3617,25 @@ retry:
+ goto err_exit;
+ }
+
++ /* When persistent cursor is used to scan over index in backwards
++ direction it stops on infimum record of its current page and releases
++ all latches it has, before switching from the cursor's current page to
++ the previous one. At this point merge from the previous page to cursor's
++ current one might happen. During this merge records from the previous
++ page will be moved over cursor position/infimum record which is used
++ used to continue iteration in optimistic case, making moved records
++ invisible to the scan.
++ We force such cursor to use pessimistic approach of restoring its
++ position/continuing iteration, which is not affected by this problem
++ (as it relies on looking up user record which was visited by cursor
++ right before the infimum) by incrementing modification clock for page
++ being merged into.
++ The forward iteration seems to be unaffected by this problem as it
++ doesn't release latch on the current page before it acquires latch on
++ the next one when cursor switches pages. So merge from the next page
++ to the current one stays blocked. */
++ buf_block_modify_clock_inc(merge_block);
++
+ btr_search_drop_page_hash_index(block);
+
+ #ifdef UNIV_BTR_DEBUG
diff --git a/mysql-btr-pcur-close-leak.patch b/mysql-btr-pcur-close-leak.patch
new file mode 100644
index 0000000..eb6921f
--- /dev/null
+++ b/mysql-btr-pcur-close-leak.patch
@@ -0,0 +1,93 @@
+Forgeting to call btr_pcur_close() leads to memory leak (Bug#37403052)
+https://github.com/percona/percona-server/commit/539202f5a7
+https://github.com/mysql/mysql-server/commit/df130daa135
+
+--- mysql-5.7.44.orig/storage/innobase/ibuf/ibuf0ibuf.cc
++++ mysql-5.7.44/storage/innobase/ibuf/ibuf0ibuf.cc
+@@ -3186,6 +3186,8 @@ ibuf_update_max_tablespace_id(void)
+ max_space_id = mach_read_from_4(field);
+ }
+
++ btr_pcur_close(&pcur);
++
+ ibuf_mtr_commit(&mtr);
+
+ /* printf("Maximum space id in insert buffer %lu\n", max_space_id); */
+--- mysql-5.7.44.orig/storage/innobase/row/row0ins.cc
++++ mysql-5.7.44/storage/innobase/row/row0ins.cc
+@@ -2183,7 +2183,7 @@ row_ins_scan_sec_index_for_duplicate(
+ end_scan:
+ /* Restore old value */
+ dtuple_set_n_fields_cmp(entry, n_fields_cmp);
+-
++ btr_pcur_close(&pcur);
+ DBUG_RETURN(err);
+ }
+
+--- mysql-5.7.44.orig/storage/innobase/row/row0log.cc
++++ mysql-5.7.44/storage/innobase/row/row0log.cc
+@@ -53,6 +53,25 @@ Created 2011-05-26 Marko Makela
+ #include <algorithm>
+ #include <map>
+
++/** RAII interface to B-tree page cursor. Calls btr_pcur_close() on scope exit
++*/
++class Btr_pcur_guard {
++public:
++ /** Attach a pcur to the guard */
++ Btr_pcur_guard(btr_pcur_t *pcur) : m_pcur(pcur) {}
++
++ /** Call cursor close at the time of destruction. */
++ ~Btr_pcur_guard() {
++ if (m_pcur != NULL) {
++ btr_pcur_close(m_pcur);
++ }
++ }
++
++private:
++ /** Btree page cursor object */
++ btr_pcur_t *m_pcur;
++};
++
+ /** Table row modification operations during online table rebuild.
+ Delete-marked records are not copied to the rebuilt table. */
+ enum row_tab_op {
+@@ -1920,6 +1939,9 @@ row_log_table_apply_delete(
+ btr_pcur_open(index, old_pk, PAGE_CUR_LE,
+ BTR_MODIFY_TREE | BTR_LATCH_FOR_DELETE,
+ &pcur, &mtr);
++
++ Btr_pcur_guard pcur_guard(&pcur);
++
+ #ifdef UNIV_DEBUG
+ switch (btr_pcur_get_btr_cur(&pcur)->flag) {
+ case BTR_CUR_DELETE_REF:
+@@ -2073,6 +2095,9 @@ row_log_table_apply_update(
+ mtr.set_named_space(index->space);
+ btr_pcur_open(index, old_pk, PAGE_CUR_LE,
+ BTR_MODIFY_TREE, &pcur, &mtr);
++
++ Btr_pcur_guard pcur_guard(&pcur);
++
+ #ifdef UNIV_DEBUG
+ switch (btr_pcur_get_btr_cur(&pcur)->flag) {
+ case BTR_CUR_DELETE_REF:
+--- mysql-5.7.44.orig/storage/innobase/row/row0mysql.cc
++++ mysql-5.7.44/storage/innobase/row/row0mysql.cc
+@@ -2132,6 +2132,7 @@ row_update_inplace_for_intrinsic(const upd_node_t* node)
+ index, offsets, node->update);
+
+ if (size_changes) {
++ btr_pcur_close(&pcur);
+ mtr_commit(&mtr);
+ return(DB_FAIL);
+ }
+@@ -2143,7 +2144,7 @@ row_update_inplace_for_intrinsic(const upd_node_t* node)
+ the changes */
+
+ mtr.set_modified();
+-
++ btr_pcur_close(&pcur);
+ mtr_commit(&mtr);
+
+ return(DB_SUCCESS);
diff --git a/mysql-buffer-pool-max-size.patch b/mysql-buffer-pool-max-size.patch
new file mode 100644
index 0000000..8a9832d
--- /dev/null
+++ b/mysql-buffer-pool-max-size.patch
@@ -0,0 +1,27 @@
+Startup with an innodb_buffer_pool_size near the address space limit crashed
+on a failed chunk array allocation instead of failing (Bug#37994397); the
+error path releases buf_pool->mutex, the mutex 5.7 holds there.
+https://github.com/percona/percona-server/commit/90905441b2
+https://github.com/mysql/mysql-server/commit/2c6e56c3bd4
+
+--- mysql-5.7.44.orig/storage/innobase/buf/buf0buf.cc
++++ mysql-5.7.44/storage/innobase/buf/buf0buf.cc
+@@ -1761,6 +1761,18 @@ buf_pool_init_instance(
+ buf_pool->chunks =
+ reinterpret_cast<buf_chunk_t*>(ut_zalloc_nokey(
+ buf_pool->n_chunks * sizeof(*chunk)));
++ DBUG_EXECUTE_IF("buf_pool_chunk_alloc_fail", {
++ if (buf_pool->chunks) {
++ ut_free(buf_pool->chunks);
++ }
++ buf_pool->chunks = NULL;
++ });
++ if (buf_pool->chunks == NULL) {
++ ib::error() << "Buffer pool " << instance_no
++ << " : failed to allocate the chunk array.";
++ buf_pool_mutex_exit(buf_pool);
++ return(DB_ERROR);
++ }
+ buf_pool->chunks_old = NULL;
+
+ UT_LIST_INIT(buf_pool->LRU, &buf_page_t::LRU);
diff --git a/mysql-client-commands-option.patch b/mysql-client-commands-option.patch
new file mode 100644
index 0000000..9bb5922
--- /dev/null
+++ b/mysql-client-commands-option.patch
@@ -0,0 +1,116 @@
+Introduce --commands option to mysql client
+https://github.com/percona/percona-server/commit/f6c1df8cf5
+
+--- mysql-5.7.44.orig/client/client_priv.h
++++ mysql-5.7.44/client/client_priv.h
+@@ -115,6 +115,7 @@ enum options_client
+ OPT_TLS_VERSION,
+ OPT_SSL_MODE,
+ OPT_SKIP_MYSQL_SCHEMA,
++ OPT_MYSQL_COMMANDS,
+ /* Add new option above this */
+ OPT_MAX_CLIENT_OPTION
+ };
+--- mysql-5.7.44.orig/client/mysql.cc
++++ mysql-5.7.44/client/mysql.cc
+@@ -158,6 +158,7 @@ static char * opt_mysql_unix_port=0;
+ static char *opt_bind_addr = NULL;
+ static int connect_flag=CLIENT_INTERACTIVE;
+ static my_bool opt_binary_mode= FALSE;
++static bool opt_commands = true;
+ static my_bool opt_connect_expired_password= FALSE;
+ static char *current_host,*current_db,*current_user=0,*opt_password=0,
+ *current_prompt=0, *delimiter_str= 0,
+@@ -1195,7 +1196,7 @@ inline int get_command_index(char cmd_char)
+
+ static int delimiter_index= -1;
+ static int charset_index= -1;
+-static bool real_binary_mode= FALSE;
++static bool disable_commands = false;
+
+ #ifdef _WIN32
+ BOOL windows_ctrl_handler(DWORD fdwCtrlType)
+@@ -1664,6 +1665,9 @@ static struct my_option my_long_options[] =
+ {"column-type-info", OPT_COLUMN_TYPES, "Display column type information.",
+ &column_types_flag, &column_types_flag,
+ 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
++ {"commands", OPT_MYSQL_COMMANDS,
++ "Enable or disable processing of local mysql commands.", &opt_commands,
++ &opt_commands, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
+ {"comments", 'c', "Preserve comments. Send comments to the server."
+ " The default is --skip-comments (discard comments), enable with --comments.",
+ &preserve_comments, &preserve_comments,
+@@ -2218,7 +2222,7 @@ static int read_and_execute(bool interactive)
+ size_t line_length= 0;
+ status.exit_status=1;
+
+- real_binary_mode= !interactive && opt_binary_mode;
++ disable_commands = !interactive && (opt_binary_mode || !opt_commands);
+ for (;;)
+ {
+ /* Reset as SIGINT has already got handled. */
+@@ -2231,7 +2235,7 @@ static int read_and_execute(bool interactive)
+ In that case, we need to double check that we have a valid
+ line before actually setting line_length to read_length.
+ */
+- line= batch_readline(status.line_buff, real_binary_mode);
++ line = batch_readline(status.line_buff, opt_binary_mode);
+ if (line)
+ {
+ line_length= status.line_buff->read_length;
+@@ -2240,7 +2244,7 @@ static int read_and_execute(bool interactive)
+ ASCII 0x00 is not allowed appearing in queries if it is not in binary
+ mode.
+ */
+- if (!real_binary_mode && strlen(line) != line_length)
++ if (!opt_binary_mode && strlen(line) != line_length)
+ {
+ status.exit_status= 1;
+ String msg;
+@@ -2392,11 +2396,11 @@ static int read_and_execute(bool interactive)
+ #endif
+
+ /*
+- If the function is called by 'source' command, it will return to interactive
+- mode, so real_binary_mode should be FALSE. Otherwise, it will exit the
+- program, it is safe to set real_binary_mode to FALSE.
++ If the function is called by 'source' command, it will return to
++ interactive mode, so disable_commands should be false. Otherwise, it will
++ exit the program, it is safe to set disable_commands to false.
+ */
+- real_binary_mode= FALSE;
++ disable_commands = false;
+ return status.exit_status;
+ }
+
+@@ -2428,10 +2432,10 @@ static COMMANDS *find_command(char cmd_char)
+ int index= -1;
+
+ /*
+- In binary-mode, we disallow all mysql commands except '\C'
++ If specified, we disallow all mysql commands except '\C'
+ and DELIMITER.
+ */
+- if (real_binary_mode)
++ if (disable_commands)
+ {
+ if (cmd_char == 'C')
+ index= charset_index;
+@@ -2473,7 +2477,7 @@ static COMMANDS *find_command(char *name)
+ this is not a delimiter command, let add_line() take care of
+ parsing the row and calling find_command().
+ */
+- if ((!real_binary_mode && strstr(name, "\\g")) ||
++ if ((!disable_commands && strstr(name, "\\g")) ||
+ (strstr(name, delimiter) &&
+ !is_delimiter_command(name, DELIMITER_NAME_LEN)))
+ DBUG_RETURN((COMMANDS *) 0);
+@@ -2490,7 +2494,7 @@ static COMMANDS *find_command(char *name)
+ len= (uint) strlen(name);
+
+ int index= -1;
+- if (real_binary_mode)
++ if (disable_commands)
+ {
+ if (is_delimiter_command(name, len))
+ index= delimiter_index;
diff --git a/mysql-client-hint-comment.patch b/mysql-client-hint-comment.patch
new file mode 100644
index 0000000..122c28a
--- /dev/null
+++ b/mysql-client-hint-comment.patch
@@ -0,0 +1,17 @@
+CORE CLIENT CANNOT SEND QUERY WITH NUMBER SIGN OR DOUBLE DASH IN HINT
+COMMENT (Bug#30875669)
+https://github.com/percona/percona-server/commit/8bcb674e17
+
+--- mysql-5.7.44.orig/client/mysql.cc
++++ mysql-5.7.44/client/mysql.cc
+@@ -2673,8 +2673,8 @@ static bool add_line(String &buffer, char *line, size_t line_length,
+ }
+ buffer.length(0);
+ }
+- else if (!*ml_comment && (!*in_string && (inchar == '#' ||
+- (inchar == '-' && pos[1] == '-' &&
++ else if (!*ml_comment && (!*in_string && ss_comment != SSC_HINT && (inchar == '#' ||
++ (inchar == '-' && pos[1] == '-' &&
+ /*
+ The third byte is either whitespace or is the
+ end of the line -- which would occur only
diff --git a/mysql-client-system-command-option.patch b/mysql-client-system-command-option.patch
new file mode 100644
index 0000000..a3b9924
--- /dev/null
+++ b/mysql-client-system-command-option.patch
@@ -0,0 +1,54 @@
+mysqldump blindly trusting SHOW CREATE TABLE leads to arbitrary code
+execution.
+https://github.com/percona/percona-server/commit/51fa3a62d0
+
+--- mysql-5.7.44.orig/client/mysql.cc
++++ mysql-5.7.44/client/mysql.cc
+@@ -371,7 +371,7 @@ static COMMANDS commands[] = {
+ "Execute an SQL script file. Takes a file name as an argument."},
+ { "status", 's', com_status, 0, "Get status information from the server."},
+ #ifdef USE_POPEN
+- { "system", '!', com_shell, 1, "Execute a system shell command."},
++ { "system", '!', com_shell, 1, "Execute a system shell command, if enabled."},
+ #endif
+ { "tee", 'T', com_tee, 1,
+ "Set outfile [to_outfile]. Append everything into given outfile." },
+@@ -1624,6 +1624,10 @@ void window_resize(int sig)
+ }
+ #endif
+
++#ifdef USE_POPEN
++static bool opt_system_command = true;
++#endif
++
+ static struct my_option my_long_options[] =
+ {
+ {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
+@@ -1882,6 +1886,12 @@ static struct my_option my_long_options[] =
+ "test purpose, so it is just built when DEBUG is on.",
+ &opt_build_completion_hash, &opt_build_completion_hash, 0, GET_BOOL,
+ NO_ARG, 0, 0, 0, 0, 0, 0},
++#endif
++#ifdef USE_POPEN
++ {"system-command", 0,
++ "Enable (by default) or disable the system mysql command.",
++ &opt_system_command, &opt_system_command, 0, GET_BOOL, NO_ARG,
++ 1, 0, 0, 0, 0, 0},
+ #endif
+ { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
+ };
+@@ -4570,6 +4580,14 @@ com_shell(String *buffer MY_ATTRIBUTE((unused)),
+ put_info("Usage: \\! shell-command", INFO_ERROR);
+ return -1;
+ }
++
++ if (!opt_system_command) {
++ return put_info(
++ "'system' command received, but the --system-command option is off. "
++ "Skipping.",
++ INFO_ERROR);
++ }
++
+ /*
+ The output of the shell command does not
+ get directed to the pager or the outfile
diff --git a/mysql-client-table-leak.patch b/mysql-client-table-leak.patch
new file mode 100644
index 0000000..dd17e79
--- /dev/null
+++ b/mysql-client-table-leak.patch
@@ -0,0 +1,25 @@
+There is a memory leak defect on line 3960 of the mysql.cc file
+(Bug#36600203)
+https://github.com/percona/percona-server/commit/d03ad650df
+https://github.com/mysql/mysql-server/commit/de82d8ade0a
+
+--- mysql-5.7.44.orig/client/mysql.cc
++++ mysql-5.7.44/client/mysql.cc
+@@ -3943,8 +3943,6 @@ print_table_data(MYSQL_RES *result)
+ bool *num_flag;
+ size_t sz;
+
+- sz= sizeof(bool) * mysql_num_fields(result);
+- num_flag= (bool *) my_safe_alloca(sz, MAX_ALLOCA_SIZE);
+ if (column_types_flag)
+ {
+ print_field_types(result);
+@@ -3952,6 +3950,8 @@ print_table_data(MYSQL_RES *result)
+ return;
+ mysql_field_seek(result,0);
+ }
++ sz= sizeof(bool) * mysql_num_fields(result);
++ num_flag= (bool *) my_safe_alloca(sz, MAX_ALLOCA_SIZE);
+ separator.copy("+",1,charset_info);
+ while ((field = mysql_fetch_field(result)))
+ {
diff --git a/mysql-connect-attrs-oob.patch b/mysql-connect-attrs-oob.patch
new file mode 100644
index 0000000..7b97220
--- /dev/null
+++ b/mysql-connect-attrs-oob.patch
@@ -0,0 +1,30 @@
+MySQL Out-of-Bounds Read (Bug#39116965)
+https://github.com/percona/percona-server/commit/bd96420711
+https://github.com/mysql/mysql-server/commit/5417e736ad9
+
+--- mysql-5.7.44.orig/sql/auth/sql_authentication.cc
++++ mysql-5.7.44/sql/auth/sql_authentication.cc
+@@ -865,10 +865,22 @@ read_client_connect_attrs(char **ptr, size_t *max_bytes_available,
+ {
+ size_t length, length_length;
+ char *ptr_save;
+- /* not enough bytes to hold the length */
++ /* Need one byte to determine the length-encoded field size. */
+ if (*max_bytes_available < 1)
+ return true;
+
++ uchar *pos = (uchar *)*ptr;
++ DBUG_EXECUTE_IF("connect_attrs_too_short_3", *pos = 252;
++ *max_bytes_available = 2;);
++ DBUG_EXECUTE_IF("connect_attrs_too_short_4", *pos = 253;
++ *max_bytes_available = 3;);
++ DBUG_EXECUTE_IF("connect_attrs_too_short_9", *pos = 254;
++ *max_bytes_available = 8;);
++
++ const size_t required_length = (size_t)net_field_length_size(pos);
++ if (*max_bytes_available < required_length)
++ return true;
++
+ /* read the length */
+ ptr_save= *ptr;
+ length= static_cast<size_t>(net_field_length_ll((uchar **) ptr));
diff --git a/mysql-connection-control-wait.patch b/mysql-connection-control-wait.patch
new file mode 100644
index 0000000..801772d
--- /dev/null
+++ b/mysql-connection-control-wait.patch
@@ -0,0 +1,29 @@
+Threads stuck waiting in connection control plugin (Bug#35205358)
+https://github.com/percona/percona-server/commit/0df51ea69e
+https://github.com/mysql/mysql-server/commit/3fc9c6a63a2
+
+--- mysql-5.7.44.orig/plugin/connection_control/connection_delay.cc
++++ mysql-5.7.44/plugin/connection_control/connection_delay.cc
+@@ -587,8 +587,7 @@ namespace connection_control
+
+ /* Finish waiting and deregister wait condition */
+ mysql_mutex_unlock(&connection_delay_mutex);
+- thd_exit_cond(thd, &stage_waiting_in_connection_control_plugin,
+- __func__, __FILE__, __LINE__);
++ thd_exit_cond(thd, &old_stage, __func__, __FILE__, __LINE__);
+
+ /* Cleanup */
+ mysql_mutex_destroy(&connection_delay_mutex);
+@@ -675,6 +674,12 @@ namespace connection_control
+ rd_lock.lock();
+ }
+
++ /*
++ Introduce a delay to check that connection delay status doesn't last
++ longer than configured
++ */
++ DBUG_EXECUTE_IF("delay_after_connection_delay", sleep(2););
++
+ if (connection_event->status)
+ {
+ /*
diff --git a/mysql-drop-user-acl-cache.patch b/mysql-drop-user-acl-cache.patch
new file mode 100644
index 0000000..3d4ed02
--- /dev/null
+++ b/mysql-drop-user-acl-cache.patch
@@ -0,0 +1,15 @@
+db cache is not flushed on DROP USER (Bug#37132323)
+https://github.com/percona/percona-server/commit/b3938045d8
+https://github.com/mysql/mysql-server/commit/dd8b0c5c7d6
+
+--- mysql-5.7.44.orig/sql/auth/sql_user.cc
++++ mysql-5.7.44/sql/auth/sql_user.cc
+@@ -1614,6 +1614,8 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list, bool if_exists)
+
+ /* Rebuild 'acl_check_hosts' since 'acl_users' has been modified */
+ rebuild_check_host();
++ /* Clear privilege cache */
++ acl_cache->clear(1);
+
+ mysql_mutex_unlock(&acl_cache->lock);
+
diff --git a/mysql-dump-comment-buffer-reuse.patch b/mysql-dump-comment-buffer-reuse.patch
new file mode 100644
index 0000000..21c0a77
--- /dev/null
+++ b/mysql-dump-comment-buffer-reuse.patch
@@ -0,0 +1,21 @@
+mysqldump: fix_identifier_with_newline() kept the heap buffer its callers
+free in static variables; the next call wrote into freed memory, e.g.
+--where longer than 64 characters with two or more tables (PLD fix).
+
+--- mysql-5.7.44.orig/client/mysqldump.c
++++ mysql-5.7.44/client/mysqldump.c
+@@ -2263,10 +2263,11 @@ static char const* fix_identifier_with_newline(char const* object_name, my_bool*
+ {
+ const size_t PREFIX_LENGTH= 3; // strlen ("-- ")
+
+- // static buffer for replacement procedure
++ // static buffer for replacement procedure; a heap buffer belongs to the
++ // caller, which frees it, so only the static storage may outlive the call
+ static char storage[NAME_LEN + 1];
+- static char* buffer= storage;
+- static size_t buffer_size= sizeof(storage) - 1;
++ char* buffer= storage;
++ size_t buffer_size= sizeof(storage) - 1;
+ size_t index= 0;
+ size_t required_size= 0;
+
diff --git a/mysql-dump-server-version.patch b/mysql-dump-server-version.patch
new file mode 100644
index 0000000..9b747be
--- /dev/null
+++ b/mysql-dump-server-version.patch
@@ -0,0 +1,64 @@
+Issue in mysqldump (mysql dump utility) (Bug#36248967)
+https://github.com/percona/percona-server/commit/1e86448cd1
+
+--- mysql-5.7.44.orig/client/mysqldump.c
++++ mysql-5.7.44/client/mysqldump.c
+@@ -701,6 +701,39 @@ static void short_usage(void)
+ printf("For more options, use %s --help\n", my_progname);
+ }
+
++static void get_safe_server_info(char *safe_server_info,
++ size_t safe_server_info_len) {
++ const char *server_info = mysql_get_server_info(&mysql_connection);
++ size_t i;
++ if (server_info == NULL) {
++ safe_server_info[0] = 0;
++ return;
++ }
++ DBUG_EXECUTE_IF("server_version_injection_test",
++ {
++ const char *payload= "5.7.0-injection_test\n\\! touch /tmp/xxx";
++ server_info= payload;
++ });
++ for (i = 0; i < safe_server_info_len; ++i) {
++ // End of string.
++ if (server_info[i] == 0)
++ {
++ safe_server_info[i]= 0;
++ return;
++ }
++ // Version may include only alphanumeric and punctuation characters.
++ // Cut off the rest of the string if incorrect character found.
++ if (!(my_isalnum(charset_info, server_info[i]) || my_ispunct(charset_info, server_info[i])))
++ {
++ safe_server_info[i] = 0;
++ fprintf(stderr,
++ "-- Warning: version string returned by server is incorrect.\n");
++ return;
++ }
++ safe_server_info[i]= server_info[i];
++ }
++ safe_server_info[safe_server_info_len - 1] = 0;
++}
+
+ static void write_header(FILE *sql_file, char *db_name)
+ {
+@@ -721,6 +754,8 @@ static void write_header(FILE *sql_file, char *db_name)
+ {
+ my_bool freemem= FALSE;
+ char const* text= fix_identifier_with_newline(db_name, &freemem);
++ char safe_server_info[SERVER_VERSION_LENGTH];
++ get_safe_server_info(safe_server_info, SERVER_VERSION_LENGTH);
+
+ print_comment(sql_file, 0,
+ "-- MySQL dump %s Distrib %s, for %s (%s)\n--\n",
+@@ -736,8 +771,7 @@ static void write_header(FILE *sql_file, char *db_name)
+ print_comment(sql_file, 0,
+ "-- ------------------------------------------------------\n"
+ );
+- print_comment(sql_file, 0, "-- Server version\t%s\n",
+- mysql_get_server_info(&mysql_connection));
++ print_comment(sql_file, 0, "-- Server version\t%s\n", safe_server_info);
+
+ if (opt_set_charset)
+ fprintf(sql_file,
diff --git a/mysql-dump-tablespace-escape.patch b/mysql-dump-tablespace-escape.patch
new file mode 100644
index 0000000..f2e3160
--- /dev/null
+++ b/mysql-dump-tablespace-escape.patch
@@ -0,0 +1,259 @@
+mysqldump --all-tablespaces wrote tablespace, logfile group and engine
+names unescaped, a malicious server could inject SQL or client commands
+into the dump (Bug#36816986, Bug#37607195). PLD addition: a name longer
+than the comment buffer from a malicious server no longer overflows it.
+https://github.com/percona/percona-server/commit/764a43f9ed
+https://github.com/percona/percona-server/commit/be5cb90bf0
+
+--- mysql-5.7.44.orig/client/mysqldump.c
++++ mysql-5.7.44/client/mysqldump.c
+@@ -53,6 +53,7 @@
+ #include <m_string.h>
+ #include <m_ctype.h>
+ #include <hash.h>
++#include <ctype.h>
+ #include <stdarg.h>
+
+ #include "client_priv.h"
+@@ -2327,6 +2328,82 @@ static char const* fix_identifier_with_newline(char const* object_name, my_bool*
+ }
+
+
++/*
++ * fprintf_string:
++ * -- Print the escaped version of the given char* row into the md_result_file.
++ *
++ * @param[in] row the row to be printed
++ * @param[in] row_len length of the row
++ * @param[in] quote quote character, like ' or ` etc.
++ * @param[in] needs_newline whether to print newline after the row
++ *
++ * @retval void
++ *
++ */
++static void fprintf_string(char *row, ulong row_len, char quote,
++ my_bool needs_newline) {
++ // Create the buffer where we'll have sanitized row.
++ char buffer[2048];
++ char *pbuffer;
++ uint64_t curr_row_size;
++ pbuffer = &buffer[0];
++
++ curr_row_size = ((uint64_t)row_len) * 2 + 1;
++
++ // We'll allocate dynamic memory only for huge rows
++ if (curr_row_size > sizeof(buffer))
++ pbuffer = (char *)my_malloc(PSI_NOT_INSTRUMENTED, curr_row_size, MYF(0));
++
++ // Put the sanitized row in the buffer.
++ mysql_real_escape_string_quote(mysql, pbuffer, row, row_len, quote);
++
++ // Opening quote
++ fputc(quote, md_result_file);
++
++ // Print the row to the file.
++ fputs(pbuffer, md_result_file);
++
++ // Closing quote
++ fputc(quote, md_result_file);
++
++ // Add the new line
++ if (needs_newline) fputc('\n', md_result_file);
++
++ // Free the buffer if we have to.
++ if (pbuffer != &buffer[0]) my_free(pbuffer);
++}
++
++/*
++ * is_string_integer:
++ * Check if the given string is a valid integer or not.
++ *
++ * @param[in] str number to be checked
++ * @param[in] str_len length of the string
++ *
++ * @retval TRUE if the string represents an integer
++ * @retval FALSE if the string has non-digit characters
++ */
++static my_bool is_string_integer(const char *str, ulong str_len) {
++ ulong start_index;
++ ulong i;
++
++ // Empty strings are invalid numbers
++ if (str_len == 0) return FALSE;
++
++ start_index = 0;
++
++ // For negative integers, start the index with 1
++ if (str[0] == '-') {
++ if (str_len == 1) return FALSE;
++ start_index = 1;
++ }
++
++ for (i = start_index; i < str_len; i++)
++ if (!isdigit(str[i])) return FALSE;
++
++ return TRUE;
++}
++
+ /*
+ create_delimiter
+ Generate a new (null-terminated) string that does not exist in query
+@@ -4439,6 +4516,7 @@ static int dump_tablespaces(char* ts_where)
+ MYSQL_RES *tableres;
+ char buf[FN_REFLEN];
+ DYNAMIC_STRING sqlbuf;
++ ulong *lengths;
+ int first= 0;
+ /*
+ The following are used for parsing the EXTRA field
+@@ -4499,24 +4577,35 @@ static int dump_tablespaces(char* ts_where)
+ buf[0]= 0;
+ while ((row= mysql_fetch_row(tableres)))
+ {
++ lengths = mysql_fetch_lengths(tableres);
+ if (strcmp(buf, row[0]) != 0)
+ first= 1;
+ if (first)
+ {
++ /*
++ * The print_comment below prints single line comments in the
++ * md_result_file (--). The single line comment is terminated by a new
++ * line, however because of the usage of mysql_real_escape_string_quote,
++ * the new line character will get escaped too in the string, hence
++ * another new line characters are being used at the end of the string
++ * to terminate the single line comment.
++ */
++ mysql_real_escape_string_quote(mysql, buf, row[0],
++ MY_MIN(lengths[0], (sizeof(buf) - 1) / 2),
++ '\'');
+ print_comment(md_result_file, 0, "\n--\n-- Logfile group: %s\n--\n",
+- row[0]);
+-
++ buf);
++ buf[0] = 0;
+ fprintf(md_result_file, "\nCREATE");
+ }
+ else
+ {
+ fprintf(md_result_file, "\nALTER");
+ }
+- fprintf(md_result_file,
+- " LOGFILE GROUP %s\n"
+- " ADD UNDOFILE '%s'\n",
+- row[0],
+- row[1]);
++ fprintf(md_result_file, " LOGFILE GROUP ");
++ fprintf_string(row[0], lengths[0], '`', TRUE);
++ fprintf(md_result_file, " ADD UNDOFILE ");
++ fprintf_string(row[1], lengths[1], '\'', TRUE);
+ if (first)
+ {
+ ubs= strstr(row[5],extra_format);
+@@ -4526,20 +4615,20 @@ static int dump_tablespaces(char* ts_where)
+ endsemi= strstr(ubs,";");
+ if(endsemi)
+ endsemi[0]= '\0';
++ if (!is_string_integer(ubs, (ulong)strlen(ubs))) return 1;
+ fprintf(md_result_file,
+ " UNDO_BUFFER_SIZE %s\n",
+ ubs);
+ }
+- fprintf(md_result_file,
+- " INITIAL_SIZE %s\n"
+- " ENGINE=%s;\n",
+- row[3],
+- row[4]);
++ if (!is_string_integer(row[3], lengths[3])) return 1;
++ fprintf(md_result_file, " INITIAL_SIZE %s\n ENGINE=", row[3]);
++ fprintf_string(row[4], lengths[4], '`', FALSE);
++ fprintf(md_result_file, ";\n");
+ check_io(md_result_file);
+ if (first)
+ {
+ first= 0;
+- strxmov(buf, row[0], NullS);
++ strmake(buf, row[0], sizeof(buf) - 1);
+ }
+ }
+ dynstr_free(&sqlbuf);
+@@ -4566,43 +4655,61 @@ static int dump_tablespaces(char* ts_where)
+ DBUG_RETURN(1);
+ }
+
++ DBUG_EXECUTE_IF("tablespace_injection_test", {
++ mysql_free_result(tableres);
++ mysql_query_with_error_report(
++ mysql, &tableres,
++ "SELECT 'T`N; /*' AS TABLESPACE_NAME, 'FN' AS FILE_NAME, 'LGN' AS "
++ "LOGFILE_GROUP_NAME, 77 AS EXTENT_SIZE, 88 AS INITIAL_SIZE, "
++ "'*/\nsystem touch foo;\n' AS ENGINE");
++ });
++
+ buf[0]= 0;
+ while ((row= mysql_fetch_row(tableres)))
+ {
++ lengths = mysql_fetch_lengths(tableres);
+ if (strcmp(buf, row[0]) != 0)
+ first= 1;
+ if (first)
+ {
+- print_comment(md_result_file, 0, "\n--\n-- Tablespace: %s\n--\n", row[0]);
++ /*
++ * The print_comment below prints single line comments in the
++ * md_result_file (--). The single line comment is terminated by a new
++ * line, however because of the usage of mysql_real_escape_string_quote,
++ * the new line character will get escaped too in the string, hence
++ * another new line characters are being used at the end of the string
++ * to terminate the single line comment.
++ */
++ mysql_real_escape_string_quote(mysql, buf, row[0],
++ MY_MIN(lengths[0], (sizeof(buf) - 1) / 2),
++ '\'');
++ print_comment(md_result_file, 0, "\n--\n-- Tablespace: %s\n--\n", buf);
++ buf[0] = 0;
+ fprintf(md_result_file, "\nCREATE");
+ }
+ else
+ {
+ fprintf(md_result_file, "\nALTER");
+ }
+- fprintf(md_result_file,
+- " TABLESPACE %s\n"
+- " ADD DATAFILE '%s'\n",
+- row[0],
+- row[1]);
+- if (first)
+- {
+- fprintf(md_result_file,
+- " USE LOGFILE GROUP %s\n"
+- " EXTENT_SIZE %s\n",
+- row[2],
+- row[3]);
++ fprintf(md_result_file, " TABLESPACE ");
++ fprintf_string(row[0], lengths[0], '`', TRUE);
++ fprintf(md_result_file, " ADD DATAFILE ");
++ fprintf_string(row[1], lengths[1], '\'', TRUE);
++ if (first) {
++ fprintf(md_result_file, " USE LOGFILE GROUP ");
++ fprintf_string(row[2], lengths[2], '`', TRUE);
++ if (!is_string_integer(row[3], lengths[3])) return 1;
++ fprintf(md_result_file, " EXTENT_SIZE %s\n", row[3]);
+ }
+- fprintf(md_result_file,
+- " INITIAL_SIZE %s\n"
+- " ENGINE=%s;\n",
+- row[4],
+- row[5]);
++ if (!is_string_integer(row[4], lengths[4])) return 1;
++ fprintf(md_result_file, " INITIAL_SIZE %s\n ENGINE=", row[4]);
++ fprintf_string(row[5], lengths[5], '`', FALSE);
++ fprintf(md_result_file, ";\n");
+ check_io(md_result_file);
+ if (first)
+ {
+ first= 0;
+- strxmov(buf, row[0], NullS);
++ strmake(buf, row[0], sizeof(buf) - 1);
+ }
+ }
+
diff --git a/mysql-dump-view-query-escape.patch b/mysql-dump-view-query-escape.patch
new file mode 100644
index 0000000..25e7038
--- /dev/null
+++ b/mysql-dump-view-query-escape.patch
@@ -0,0 +1,41 @@
+Missing string escaping in mysqldump (Bug#37540722)
+https://github.com/percona/percona-server/commit/0ec1728204
+https://github.com/mysql/mysql-server/commit/2fafb0f1573
+
+--- mysql-5.7.44.orig/client/mysqldump.c
++++ mysql-5.7.44/client/mysqldump.c
+@@ -6272,6 +6272,8 @@ static my_bool get_view_structure(char *table, char* db)
+ char *result_table, *opt_quoted_table;
+ char table_buff[NAME_LEN*2+3];
+ char table_buff2[NAME_LEN*2+3];
++ char table_string_buff[NAME_LEN * 2 + 3];
++ char db_string_buff[NAME_LEN * 2 + 3];
+ char query[QUERY_LENGTH];
+ FILE *sql_file= md_result_file;
+ my_bool freemem= FALSE;
+@@ -6285,6 +6287,15 @@ static my_bool get_view_structure(char *table, char* db)
+
+ result_table= quote_name(table, table_buff, 1);
+ opt_quoted_table= quote_name(table, table_buff2, 0);
++ if (((ulong)-1 == mysql_real_escape_string_quote(mysql, table_string_buff,
++ table, strlen(table),
++ '\'')) ||
++ ((ulong)-1 == mysql_real_escape_string_quote(mysql, db_string_buff, db,
++ strlen(db), '\''))) {
++ DB_error(mysql,
++ "when trying to quote table and db names when dumping views.");
++ DBUG_RETURN(1);
++ }
+
+ if (switch_character_set_results(mysql, "binary"))
+ DBUG_RETURN(1);
+@@ -6332,7 +6343,8 @@ static my_bool get_view_structure(char *table, char* db)
+ "SELECT CHECK_OPTION, DEFINER, SECURITY_TYPE, "
+ " CHARACTER_SET_CLIENT, COLLATION_CONNECTION "
+ "FROM information_schema.views "
+- "WHERE table_name=\"%s\" AND table_schema=\"%s\"", table, db);
++ "WHERE table_name=\"%s\" AND table_schema=\"%s\"",
++ table_string_buff, db_string_buff);
+
+ if (mysql_query(mysql, query))
+ {
diff --git a/mysql-fake-rotate-event.patch b/mysql-fake-rotate-event.patch
new file mode 100644
index 0000000..9165f98
--- /dev/null
+++ b/mysql-fake-rotate-event.patch
@@ -0,0 +1,95 @@
+Improve fake Rotate event handling (Bug#39253359)
+https://github.com/percona/percona-server/commit/b2ace1edde
+https://github.com/mysql/mysql-server/commit/ca21b0c3295
+
+--- mysql-5.7.44.orig/sql/rpl_binlog_sender.cc
++++ mysql-5.7.44/sql/rpl_binlog_sender.cc
+@@ -1028,6 +1028,8 @@ int Binlog_sender::fake_rotate_event(const char *next_log_file,
+ size_t event_len = ident_len + LOG_EVENT_HEADER_LEN + Binary_log_event::ROTATE_HEADER_LEN +
+ (event_checksum_on() ? BINLOG_CHECKSUM_LEN : 0);
+
++ DBUG_EXECUTE_IF("binlog_sender_large_rotate_event", event_len = 4096;);
++
+ /* reset transmit packet for the fake rotate event below */
+ if (reset_transmit_packet(0, event_len))
+ DBUG_RETURN(1);
+@@ -1049,6 +1051,13 @@ int Binlog_sender::fake_rotate_event(const char *next_log_file,
+
+ int8store(rotate_header, log_pos);
+ memcpy(rotate_header + Binary_log_event::ROTATE_HEADER_LEN, p, ident_len);
++ DBUG_EXECUTE_IF("binlog_sender_large_rotate_event", {
++ uchar *rotate_payload = rotate_header + Binary_log_event::ROTATE_HEADER_LEN;
++ const size_t rotate_payload_len =
++ event_len - LOG_EVENT_HEADER_LEN - Binary_log_event::ROTATE_HEADER_LEN -
++ (event_checksum_on() ? BINLOG_CHECKSUM_LEN : 0);
++ memset(rotate_payload + ident_len, 'X', rotate_payload_len - ident_len);
++ };);
+
+ if (event_checksum_on())
+ calc_event_checksum(header, event_len);
+--- mysql-5.7.44.orig/sql/rpl_slave.cc
++++ mysql-5.7.44/sql/rpl_slave.cc
+@@ -8404,6 +8404,33 @@ bool queue_event(Master_info* mi,const char* buf, ulong event_len)
+ goto end;
+ case binary_log::ROTATE_EVENT:
+ {
++ const bool is_fake_rotate= uint4korr(&buf[0]) == 0;
++ const bool add_checksum_to_fake_rotate=
++ is_fake_rotate &&
++ checksum_alg == binary_log::BINLOG_CHECKSUM_ALG_OFF &&
++ mi->rli->relay_log.relay_log_checksum_alg !=
++ binary_log::BINLOG_CHECKSUM_ALG_OFF;
++ const bool strip_checksum_from_fake_rotate=
++ is_fake_rotate &&
++ checksum_alg != binary_log::BINLOG_CHECKSUM_ALG_OFF &&
++ mi->rli->relay_log.relay_log_checksum_alg ==
++ binary_log::BINLOG_CHECKSUM_ALG_OFF;
++
++ if ((add_checksum_to_fake_rotate &&
++ event_len > sizeof(rot_buf) - BINLOG_CHECKSUM_LEN) ||
++ (strip_checksum_from_fake_rotate &&
++ (event_len < BINLOG_CHECKSUM_LEN ||
++ event_len - BINLOG_CHECKSUM_LEN > sizeof(rot_buf))))
++ {
++ mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE,
++ ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE),
++ "Received oversized rotate event. Please retry the "
++ "connection. If the problem persists, investigate the "
++ "source of the invalid event and verify the "
++ "master-slave connection.");
++ goto err;
++ }
++
+ Rotate_log_event rev(buf, checksum_alg != binary_log::BINLOG_CHECKSUM_ALG_OFF ?
+ event_len - BINLOG_CHECKSUM_LEN : event_len,
+ mi->get_mi_description_event());
+@@ -8428,12 +8455,10 @@ bool queue_event(Master_info* mi,const char* buf, ulong event_len)
+ to compute checksum for its first FD event for RL
+ the fake Rotate gets checksummed here.
+ */
+- if (uint4korr(&buf[0]) == 0 && checksum_alg ==
+- binary_log::BINLOG_CHECKSUM_ALG_OFF &&
+- mi->rli->relay_log.relay_log_checksum_alg !=
+- binary_log::BINLOG_CHECKSUM_ALG_OFF)
++ if (add_checksum_to_fake_rotate)
+ {
+ ha_checksum rot_crc= checksum_crc32(0L, NULL, 0);
++ assert(event_len <= sizeof(rot_buf) - BINLOG_CHECKSUM_LEN);
+ event_len += BINLOG_CHECKSUM_LEN;
+ memcpy(rot_buf, buf, event_len - BINLOG_CHECKSUM_LEN);
+ int4store(&rot_buf[EVENT_LEN_OFFSET],
+@@ -8456,11 +8481,10 @@ bool queue_event(Master_info* mi,const char* buf, ulong event_len)
+ RSC_2: If NM \and fake Rotate \and slave does not compute checksum
+ the fake Rotate's checksum is stripped off before relay-logging.
+ */
+- if (uint4korr(&buf[0]) == 0 && checksum_alg !=
+- binary_log::BINLOG_CHECKSUM_ALG_OFF &&
+- mi->rli->relay_log.relay_log_checksum_alg ==
+- binary_log::BINLOG_CHECKSUM_ALG_OFF)
++ if (strip_checksum_from_fake_rotate)
+ {
++ assert(event_len >= BINLOG_CHECKSUM_LEN);
++ assert(event_len - BINLOG_CHECKSUM_LEN <= sizeof(rot_buf));
+ event_len -= BINLOG_CHECKSUM_LEN;
+ memcpy(rot_buf, buf, event_len);
+ int4store(&rot_buf[EVENT_LEN_OFFSET],
diff --git a/mysql-fk-cascade-vcol-crash.patch b/mysql-fk-cascade-vcol-crash.patch
new file mode 100644
index 0000000..5aa44d4
--- /dev/null
+++ b/mysql-fk-cascade-vcol-crash.patch
@@ -0,0 +1,28 @@
+ON DELETE CASCADE with generated column crashes in
+innobase_get_computed_value (Bug#33691659)
+https://github.com/percona/percona-server/commit/42f6a0b0e0
+https://github.com/mysql/mysql-server/commit/551288baa7a
+
+--- mysql-5.7.44.orig/storage/innobase/row/row0ins.cc
++++ mysql-5.7.44/storage/innobase/row/row0ins.cc
+@@ -1303,11 +1303,17 @@ row_ins_foreign_check_on_constraint(
+ clust_index, tmp_heap);
+ }
+
+- if (cascade->is_delete && foreign->v_cols != NULL
+- && foreign->v_cols->size() > 0
+- && table->vc_templ == NULL) {
++ /* A cascade delete from the parent table triggers delete on the child
++ table. Before a clustered index record is deleted in the child table,
++ a copy of row is built to remove secondary index records. This copy of
++ the row requires virtual columns to be materialized. Hence, if child
++ table has any virtual columns which are indexed, we have to initialize
++ virtual column template. */
++ if (cascade->is_delete && dict_table_has_indexed_v_cols(table) &&
++ table->vc_templ == NULL) {
+ innobase_init_vc_templ(table);
+ }
++
+ if (node->is_delete
+ ? (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL)
+ : (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL)) {
diff --git a/mysql-fk-cascade-vcol-update.patch b/mysql-fk-cascade-vcol-update.patch
new file mode 100644
index 0000000..fcf87fd
--- /dev/null
+++ b/mysql-fk-cascade-vcol-update.patch
@@ -0,0 +1,220 @@
+ON UPDATE/DELETE SET NULL computed an indexed virtual column from the parent
+row instead of the child's cascade update vector; the index got a wrong
+value and the cascade hit ut_a(!cursor->index->is_committed())
+(Bug#37478594). Percona's 5.7 port without the prebuilt argument of its
+compressed columns.
+https://github.com/percona/percona-server/commit/ecfdc636ef
+https://github.com/mysql/mysql-server/commit/fc4b73f4002
+
+--- mysql-5.7.44.orig/storage/innobase/handler/ha_innodb.cc
++++ mysql-5.7.44/storage/innobase/handler/ha_innodb.cc
+@@ -20795,45 +20795,24 @@ innobase_rename_vc_templ(
+ table->vc_templ->tb_name = t_tbname;
+ }
+
+-/** Get the updated parent field value from the update vector for the
+-given col_no.
+- at param[in] foreign foreign key information
+- at param[in] update updated parent vector.
+- at param[in] col_no base column position of the child table to check
+- at return updated field from the parent update vector, else NULL */
+-dfield_t*
+-innobase_get_field_from_update_vector(
+- dict_foreign_t* foreign,
++/** Get the updated field value from an update vector for the given column
++number.
++ at param[in] table the table that is used for creating update vector
++ at param[in] update the update vector for the table's clustered index
++ at param[in] col_no the number of the non-virtual column in the table
++ at return the field's new value if it's updated, otherwise nullptr */
++static
++const dfield_t *innobase_get_field_from_update_vector(
++ dict_table_t* table,
+ upd_t* update,
+- uint32_t col_no)
+-{
+- dict_table_t* parent_table = foreign->referenced_table;
+- dict_index_t* parent_index = foreign->referenced_index;
+- uint32_t parent_field_no;
+- uint32_t parent_col_no;
+- uint32_t child_col_no;
+-
+- for (uint32_t i = 0; i < foreign->n_fields; i++) {
+- child_col_no = dict_index_get_nth_col_no(
+- foreign->foreign_index, i);
+- if (child_col_no != col_no) {
+- continue;
+- }
+- parent_col_no = dict_index_get_nth_col_no(parent_index, i);
+- parent_field_no = dict_table_get_nth_col_pos(
+- parent_table, parent_col_no);
+-
+- for (uint32_t j = 0; j < update->n_fields; j++) {
+- upd_field_t* parent_ufield
+- = &update->fields[j];
+-
+- if (parent_ufield->field_no == parent_field_no) {
+- return(&parent_ufield->new_val);
+- }
+- }
+- }
+-
+- return (NULL);
++ uint32_t col_no)
++{
++ dict_index_t* clustered_index = dict_table_get_first_index(table);
++ ulint index_field_pos = dict_index_get_nth_col_pos(
++ clustered_index, col_no);
++ const upd_field_t *upd_field = upd_get_field_by_field_no(
++ update, index_field_pos, false);
++ return upd_field ? &upd_field->new_val : NULL;
+ }
+
+ /** Get the computed value by supplying the base column values.
+@@ -20847,8 +20826,9 @@ innobase_get_field_from_update_vector(
+ @param[in,out] mysql_table mysql table object
+ @param[in] old_table during ALTER TABLE, this is the old table
+ or NULL.
+- at param[in] parent_update update vector for the parent row
+- at param[in] foreign foreign key information
++ at param[in] cascade_update update vector for the current table involved in
++ cascade update
++ at param[in] foreign foreign key information [unused]
+ @return the field filled with computed value, or NULL if just want
+ to store the value in passed in "my_rec" */
+ dfield_t*
+@@ -20862,7 +20842,7 @@ innobase_get_computed_value(
+ THD* thd,
+ TABLE* mysql_table,
+ const dict_table_t* old_table,
+- upd_t* parent_update,
++ upd_t* cascade_update,
+ dict_foreign_t* foreign)
+ {
+ byte rec_buf1[REC_VERSION_56_MAX_INDEX_COL_LEN];
+@@ -20880,6 +20860,7 @@ innobase_get_computed_value(
+
+ ut_ad(index->table->vc_templ);
+ ut_ad(thd != NULL);
++ ut_ad(foreign == NULL);
+
+ const mysql_row_templ_t*
+ vctempl = index->table->vc_templ->vtempl[
+@@ -20908,11 +20889,11 @@ innobase_get_computed_value(
+ = index->table->vc_templ->vtempl[col_no];
+ const byte* data;
+
+- if (parent_update != NULL) {
++ if (cascade_update != NULL) {
+ /** Get the updated field from update vector
+- of the parent table. */
+- row_field = innobase_get_field_from_update_vector(
+- foreign, parent_update, col_no);
++ of the table involved in cascade update */
++ row_field = innobase_get_field_from_update_vector(index->table,
++ cascade_update, col_no);
+ }
+
+ if (row_field == NULL) {
+--- mysql-5.7.44.orig/storage/innobase/include/row0mysql.h
++++ mysql-5.7.44/storage/innobase/include/row0mysql.h
+@@ -951,18 +951,6 @@ struct SysIndexCallback {
+ virtual void operator()(mtr_t* mtr, btr_pcur_t* pcur) throw() = 0;
+ };
+
+-/** Get the updated parent field value from the update vector for the
+-given col_no.
+- at param[in] foreign foreign key information
+- at param[in] update updated parent vector.
+- at param[in] col_no base column position of the child table to check
+- at return updated field from the parent update vector, else NULL */
+-dfield_t*
+-innobase_get_field_from_update_vector(
+- dict_foreign_t* foreign,
+- upd_t* update,
+- uint32_t col_no);
+-
+ /** Get the computed value by supplying the base column values.
+ @param[in,out] row the data row
+ @param[in] col virtual column
+@@ -974,8 +962,9 @@ innobase_get_field_from_update_vector(
+ @param[in,out] mysql_table mysql table object
+ @param[in] old_table during ALTER TABLE, this is the old table
+ or NULL.
+- at param[in] parent_update update vector for the parent row
+- at param[in] foreign foreign key information
++ at param[in] cascade_update update vector for the current table involved in
++ cascade update
++ at param[in] foreign foreign key information [unused]
+ @return the field filled with computed value */
+ dfield_t*
+ innobase_get_computed_value(
+@@ -988,7 +977,7 @@ innobase_get_computed_value(
+ THD* thd,
+ TABLE* mysql_table,
+ const dict_table_t* old_table,
+- upd_t* parent_update,
++ upd_t* cascade_update,
+ dict_foreign_t* foreign);
+
+ /** Get the computed value by supplying the base column values.
+--- mysql-5.7.44.orig/storage/innobase/row/row0ins.cc
++++ mysql-5.7.44/storage/innobase/row/row0ins.cc
+@@ -1007,48 +1007,15 @@ row_ins_foreign_fill_virtual(
+ dfield_copy(upd_field->old_v_val, vfield);
+
+ upd_field_set_v_field_no(upd_field, i, index);
+-
+- if (node->is_delete
+- ? (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL)
+- : (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL)) {
+- uint32_t col_match_count =
+- dict_vcol_base_is_foreign_key(col, foreign);
+- if (col_match_count == col->num_base) {
+- /* If all base columns of virtual col are
+- in FK */
+- dfield_set_null(&upd_field->new_val);
+- } else if (col_match_count == 0) {
+- /* If no base column of virtual col is in FK */
+- dfield_copy(&(upd_field->new_val), vfield);
+- } else {
+- /* If at least one base column of virtual col
+- is in FK */
+- for (uint32_t j = 0; j < col->num_base; j++) {
+- dict_col_t *base_col = col->base_col[j];
+- uint32_t col_no = base_col->ind;
+- dfield_t *row_field =
+- innobase_get_field_from_update_vector(
+- foreign, node->update, col_no);
+- if (row_field != NULL) {
+- dfield_set_null(row_field);
+- }
+- }
+- dfield_t *new_vfield = innobase_get_computed_value(
+- update->old_vrow, col, index, &v_heap,
+- update->heap, NULL, thd, NULL,
+- NULL, node->update, foreign);
+- dfield_copy(&(upd_field->new_val), new_vfield);
+- }
+-
+- }
+-
+- if (!node->is_delete
+- && (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE)) {
+-
+- dfield_t* new_vfield = innobase_get_computed_value(
+- update->old_vrow, col, index,
+- &v_heap, update->heap, NULL, thd,
+- NULL, NULL, node->update, foreign);
++ if (!dict_vcol_base_is_foreign_key(col, foreign)) {
++ /* If no base column of virtual col is in FK, the virtual field
++ is not affected by update */
++ dfield_copy(&(upd_field->new_val), vfield);
++ } else {
++ const dfield_t *const new_vfield =
++ innobase_get_computed_value(
++ update->old_vrow, col, index, &v_heap,
++ update->heap, NULL, thd, NULL, NULL, update, NULL);
+
+ if (new_vfield == NULL) {
+ *err = DB_COMPUTE_VALUE_FAILED;
diff --git a/mysql-fk-pad-col-assert.patch b/mysql-fk-pad-col-assert.patch
new file mode 100644
index 0000000..a265a40
--- /dev/null
+++ b/mysql-fk-pad-col-assert.patch
@@ -0,0 +1,54 @@
+FK: assertion failure in row_MySQL_pad_col (Bug#33327093)
+https://github.com/percona/percona-server/commit/5d715bdb96
+https://github.com/mysql/mysql-server/commit/0ac176453bf
+
+--- mysql-5.7.44.orig/storage/innobase/include/data0data.h
++++ mysql-5.7.44/storage/innobase/include/data0data.h
+@@ -595,6 +595,10 @@ struct dfield_t{
+ created.
+ @return the cloned object. */
+ dfield_t* clone(mem_heap_t* heap);
++
++ /** Checks if the field is virtual
++ @return true if virtual else returns false. */
++ bool is_virtual() const { return (type.is_virtual()); }
+ };
+
+ /** Structure for an SQL data tuple of fields (logical record) */
+--- mysql-5.7.44.orig/storage/innobase/include/data0type.h
++++ mysql-5.7.44/storage/innobase/include/data0type.h
+@@ -586,6 +586,8 @@ struct dtype_t{
+ mbminlen=DATA_MBMINLEN(mbminmaxlen);
+ mbmaxlen=DATA_MBMINLEN(mbminmaxlen) */
+ #endif /* !UNIV_HOTBACKUP */
++
++ bool is_virtual() const { return ((prtype & DATA_VIRTUAL) == DATA_VIRTUAL); }
+ };
+
+ #ifndef UNIV_NONINL
+--- mysql-5.7.44.orig/storage/innobase/include/row0upd.h
++++ mysql-5.7.44/storage/innobase/include/row0upd.h
+@@ -459,6 +459,9 @@ struct upd_field_t{
+ #endif /* !UNIV_HOTBACKUP */
+ dfield_t new_val; /*!< new value for the column */
+ dfield_t* old_v_val; /*!< old value for the virtual column */
++
++ bool is_virtual() const { return (new_val.is_virtual()); }
++
+ };
+
+
+--- mysql-5.7.44.orig/storage/innobase/row/row0ins.cc
++++ mysql-5.7.44/storage/innobase/row/row0ins.cc
+@@ -551,6 +551,11 @@ row_ins_cascade_calc_update_vec(
+ const upd_field_t* parent_ufield
+ = &parent_update->fields[j];
+
++ /* Skip if the updated field is virtual */
++ if (parent_ufield->is_virtual()) {
++ continue;
++ }
++
+ if (parent_ufield->field_no == parent_field_no) {
+
+ ulint min_size;
diff --git a/mysql-fts-doc-id-64bit.patch b/mysql-fts-doc-id-64bit.patch
new file mode 100644
index 0000000..9688c80
--- /dev/null
+++ b/mysql-fts-doc-id-64bit.patch
@@ -0,0 +1,745 @@
+[InnoDB] FULLTEXT index limits FTS_DOC_ID to max unsigned 32-bit value
+(Bug#36879147)
+https://github.com/percona/percona-server/commit/69f4e933ac
+https://github.com/mysql/mysql-server/commit/daa02f8852e
+
+--- mysql-5.7.44.orig/storage/innobase/fts/fts0fts.cc
++++ mysql-5.7.44/storage/innobase/fts/fts0fts.cc
+@@ -1279,7 +1279,6 @@ fts_cache_node_add_positions(
+ ulint enc_len;
+ ulint last_pos;
+ byte* ptr_start;
+- ulint doc_id_delta;
+
+ #ifdef UNIV_DEBUG
+ if (cache) {
+@@ -1290,7 +1289,7 @@ fts_cache_node_add_positions(
+ ut_ad(doc_id >= node->last_doc_id);
+
+ /* Calculate the space required to store the ilist. */
+- doc_id_delta = (ulint)(doc_id - node->last_doc_id);
++ const uint64_t doc_id_delta = doc_id - node->last_doc_id;
+ enc_len = fts_get_encoded_len(doc_id_delta);
+
+ last_pos = 0;
+--- mysql-5.7.44.orig/storage/innobase/fts/fts0opt.cc
++++ mysql-5.7.44/storage/innobase/fts/fts0opt.cc
+@@ -1175,7 +1175,7 @@ fts_optimize_encode_node(
+ /* Calculate the space required to store the ilist. */
+ ut_ad(doc_id > node->last_doc_id);
+ doc_id_delta = doc_id - node->last_doc_id;
+- enc_len = fts_get_encoded_len(static_cast<ulint>(doc_id_delta));
++ enc_len = fts_get_encoded_len(doc_id_delta);
+
+ /* Calculate the size of the encoded pos array. */
+ while (*src) {
+@@ -1219,9 +1219,8 @@ fts_optimize_encode_node(
+ src = enc->src_ilist_ptr;
+ dst = node->ilist + node->ilist_size;
+
+- /* Encode the doc id. Cast to ulint, the delta should be small and
+- therefore no loss of precision. */
+- dst += fts_encode_int((ulint) doc_id_delta, dst);
++ /* Encode the doc id. */
++ dst += fts_encode_int(doc_id_delta, dst);
+
+ /* Copy the encoded pos array. */
+ memcpy(dst, src, pos_enc_len);
+@@ -1265,10 +1264,9 @@ fts_optimize_node(
+ while (copied < src_node->ilist_size
+ && dst_node->ilist_size < FTS_ILIST_MAX_SIZE) {
+
+- doc_id_t delta;
+ doc_id_t del_doc_id = FTS_NULL_DOC_ID;
+
+- delta = fts_decode_vlc(&enc->src_ilist_ptr);
++ doc_id_t delta = fts_decode_vlc(&enc->src_ilist_ptr);
+
+ test_again:
+ /* Check whether the doc id is in the delete list, if
+--- mysql-5.7.44.orig/storage/innobase/fts/fts0que.cc
++++ mysql-5.7.44/storage/innobase/fts/fts0que.cc
+@@ -51,6 +51,7 @@ Completed 2011/7/10 Sunny and Jimmy Yang
+ #endif
+
+ #include <iomanip>
++#include <limits>
+ #include <vector>
+
+ #define FTS_ELEM(t, n, i, j) (t[(i) * n + (j)])
+@@ -3155,14 +3156,17 @@ fts_query_find_doc_id(
+ ulint freq = 0;
+ ulint min_pos = 0;
+ ulint last_pos = 0;
+- ulint pos = fts_decode_vlc(&ptr);
++ const uint64_t delta = fts_decode_vlc(&ptr);
+
+ /* Add the delta. */
+- doc_id += pos;
++ doc_id += delta;
+
+ while (*ptr) {
+ ++freq;
+- last_pos += fts_decode_vlc(&ptr);
++ const uint64_t pos_delta = fts_decode_vlc(&ptr);
++ ut_ad(uint64_t(last_pos) + pos_delta <=
++ std::numeric_limits<ulint>::max());
++ last_pos += static_cast<ulint>(pos_delta);
+
+ /* Only if min_pos is not set and the current
+ term exists in a position greater than the
+@@ -3235,15 +3239,15 @@ fts_query_filter_doc_ids(
+ fts_doc_freq_t* doc_freq;
+ fts_match_t* match = NULL;
+ ulint last_pos = 0;
+- ulint pos = fts_decode_vlc(&ptr);
++ const uint64_t delta = fts_decode_vlc(&ptr);
+
+ /* Some sanity checks. */
+ if (doc_id == 0) {
+- ut_a(pos == node->first_doc_id);
++ ut_a(delta == node->first_doc_id);
+ }
+
+ /* Add the delta. */
+- doc_id += pos;
++ doc_id += delta;
+
+ if (calc_doc_count) {
+ word_freq->doc_count++;
+@@ -3273,7 +3277,10 @@ fts_query_filter_doc_ids(
+
+ /* Unpack the positions within the document. */
+ while (*ptr) {
+- last_pos += fts_decode_vlc(&ptr);
++ const uint64_t decoded_pos = fts_decode_vlc(&ptr);
++ ut_ad(uint64_t(last_pos) + decoded_pos
++ <= std::numeric_limits<ulint>::max());
++ last_pos += static_cast<ulint>(decoded_pos);
+
+ /* Collect the matching word positions, for phrase
+ matching later. */
+--- mysql-5.7.44.orig/storage/innobase/handler/i_s.cc
++++ mysql-5.7.44/storage/innobase/handler/i_s.cc
+@@ -3376,13 +3376,15 @@ i_s_fts_index_cache_fill_one_index(
+ ptr = node->ilist;
+
+ while (decoded < node->ilist_size) {
+- ulint pos = fts_decode_vlc(&ptr);
++ const uint64_t delta = fts_decode_vlc(&ptr);
+
+- doc_id += pos;
++ doc_id += delta;
+
+ /* Get position info */
+ while (*ptr) {
+- pos = fts_decode_vlc(&ptr);
++ const uint64_t decoded_pos = fts_decode_vlc(&ptr);
++ ut_ad(decoded_pos <= std::numeric_limits<ulint>::max());
++ const ulint pos = static_cast<ulint>(decoded_pos);
+
+ OK(field_store_string(
+ fields[I_S_FTS_WORD],
+@@ -3757,13 +3759,15 @@ i_s_fts_index_table_fill_one_fetch(
+ ptr = node->ilist;
+
+ while (decoded < node->ilist_size) {
+- ulint pos = fts_decode_vlc(&ptr);
++ const uint64_t delta = fts_decode_vlc(&ptr);
+
+- doc_id += pos;
++ doc_id += delta;
+
+ /* Get position info */
+ while (*ptr) {
+- pos = fts_decode_vlc(&ptr);
++ const uint64_t decoded_pos = fts_decode_vlc(&ptr);
++ ut_ad(decoded_pos <= std::numeric_limits<ulint>::max());
++ const ulint pos = static_cast<ulint>(decoded_pos);
+
+ OK(field_store_string(
+ fields[I_S_FTS_WORD],
+--- mysql-5.7.44.orig/storage/innobase/include/fts0types.h
++++ mysql-5.7.44/storage/innobase/include/fts0types.h
+@@ -34,6 +34,7 @@ Created 2007-03-27 Sunny Bains
+ #ifndef INNOBASE_FTS0TYPES_H
+ #define INNOBASE_FTS0TYPES_H
+
++#include <stdint.h>
+ #include "univ.i"
+ #include "fts0fts.h"
+ #include "fut0fut.h"
+@@ -306,7 +307,7 @@ extern const fts_index_selector_t fts_index_selector[];
+ /******************************************************************//**
+ Decode and return the integer that was encoded using our VLC scheme.*/
+ UNIV_INLINE
+-ulint
++uint64_t
+ fts_decode_vlc(
+ /*===========*/
+ /*!< out: value decoded */
+@@ -330,22 +331,22 @@ fts_string_dup(
+ /******************************************************************//**
+ Return length of val if it were encoded using our VLC scheme. */
+ UNIV_INLINE
+-ulint
++unsigned int
+ fts_get_encoded_len(
+ /*================*/
+ /*!< out: length of value
+ encoded, in bytes */
+- ulint val); /*!< in: value to encode */
++ uint64_t val); /*!< in: value to encode */
+
+ /******************************************************************//**
+ Encode an integer using our VLC scheme and return the length in bytes. */
+ UNIV_INLINE
+-ulint
++unsigned int
+ fts_encode_int(
+ /*===========*/
+ /*!< out: length of value
+ encoded, in bytes */
+- ulint val, /*!< in: value to encode */
++ uint64_t val, /*!< in: value to encode */
+ byte* buf); /*!< in: buffer, must have
+ enough space */
+
+--- mysql-5.7.44.orig/storage/innobase/include/fts0vlc.ic
++++ mysql-5.7.44/storage/innobase/include/fts0vlc.ic
+@@ -34,101 +34,97 @@ Created 2007-03-27 Sunny Bains
+ #ifndef INNOBASE_FTS0VLC_IC
+ #define INNOBASE_FTS0VLC_IC
+
++#include <stddef.h>
++#include <stdint.h>
+ #include "fts0types.h"
+
+ /******************************************************************//**
+ Return length of val if it were encoded using our VLC scheme.
+-FIXME: We will need to be able encode 8 bytes value
+ @return length of value encoded, in bytes */
+ UNIV_INLINE
+-ulint
++unsigned int
+ fts_get_encoded_len(
+ /*================*/
+- ulint val) /* in: value to encode */
++ uint64_t val) /* in: value to encode */
+ {
+- if (val <= 127) {
+- return(1);
+- } else if (val <= 16383) {
+- return(2);
+- } else if (val <= 2097151) {
+- return(3);
+- } else if (val <= 268435455) {
+- return(4);
+- } else {
+- /* Possibly we should care that on 64-bit machines ulint can
+- contain values that we can't encode in 5 bytes, but
+- fts_encode_int doesn't handle them either so it doesn't much
+- matter. */
+-
+- return(5);
+- }
++ unsigned int length = 1;
++ for (;;)
++ {
++ val >>= 7;
++ if (val != 0)
++ {
++ ++length;
++ }
++ else
++ {
++ break;
++ }
++ }
++ return length;
+ }
+
+ /******************************************************************//**
+ Encode an integer using our VLC scheme and return the length in bytes.
+ @return length of value encoded, in bytes */
+ UNIV_INLINE
+-ulint
++unsigned int
+ fts_encode_int(
+ /*===========*/
+- ulint val, /* in: value to encode */
++ uint64_t val, /* in: value to encode */
+ byte* buf) /* in: buffer, must have enough space */
+ {
+- ulint len;
+-
+- if (val <= 127) {
+- *buf = (byte) val;
+-
+- len = 1;
+- } else if (val <= 16383) {
+- *buf++ = (byte)(val >> 7);
+- *buf = (byte)(val & 0x7F);
+-
+- len = 2;
+- } else if (val <= 2097151) {
+- *buf++ = (byte)(val >> 14);
+- *buf++ = (byte)((val >> 7) & 0x7F);
+- *buf = (byte)(val & 0x7F);
+-
+- len = 3;
+- } else if (val <= 268435455) {
+- *buf++ = (byte)(val >> 21);
+- *buf++ = (byte)((val >> 14) & 0x7F);
+- *buf++ = (byte)((val >> 7) & 0x7F);
+- *buf = (byte)(val & 0x7F);
+-
+- len = 4;
+- } else {
+- /* Best to keep the limitations of the 32/64 bit versions
+- identical, at least for the time being. */
+- ut_ad(val <= 4294967295u);
+-
+- *buf++ = (byte)(val >> 28);
+- *buf++ = (byte)((val >> 21) & 0x7F);
+- *buf++ = (byte)((val >> 14) & 0x7F);
+- *buf++ = (byte)((val >> 7) & 0x7F);
+- *buf = (byte)(val & 0x7F);
+-
+- len = 5;
++ const unsigned int max_length = 10;
++ /* skip leading zeros */
++ unsigned int count = max_length - 1;
++ while (count > 0)
++ {
++ /* We split the value into 7 bit batches); so val >= 2^63 need 10 bytes,
++ 2^63 > val >= 2^56 needs 9 bytes, 2^56 > val >= 2^49 needs 8 bytes etc.
++ */
++ if (val >= uint64_t(1) << (count * 7))
++ {
++ break;
++ }
++ --count;
+ }
+
+- /* High-bit on means "last byte in the encoded integer". */
+- *buf |= 0x80;
+-
+- return(len);
++ unsigned int length = count + 1;
++
++ byte *bufptr= buf;
++
++ for (;;)
++ {
++ *bufptr = (byte)((val >> (7 * count)) & 0x7f);
++ if (count == 0)
++ {
++ /* High-bit on means "last byte in the encoded integer". */
++ *bufptr |= 0x80;
++ break;
++ }
++ else
++ {
++ --count;
++ ++bufptr;
++ }
++ }
++
++ ut_ad(length <= max_length);
++ ut_a(bufptr - buf == ptrdiff_t(length) - 1);
++
++ return length;
+ }
+
+ /******************************************************************//**
+ Decode and return the integer that was encoded using our VLC scheme.
+ @return value decoded */
+ UNIV_INLINE
+-ulint
++uint64_t
+ fts_decode_vlc(
+ /*===========*/
+ byte** ptr) /* in: ptr to decode from, this ptr is
+ incremented by the number of bytes decoded */
+ {
+- ulint val = 0;
++ uint64_t val = 0;
+
+ for (;;) {
+ byte b = **ptr;
+@@ -144,7 +140,7 @@ fts_decode_vlc(
+ }
+ }
+
+- return(val);
++ return val;
+ }
+
+ #endif
+--- mysql-5.7.44.orig/unittest/gunit/innodb/CMakeLists.txt
++++ mysql-5.7.44/unittest/gunit/innodb/CMakeLists.txt
+@@ -33,6 +33,7 @@ INCLUDE(${CMAKE_SOURCE_DIR}/storage/innobase/innodb.cmake)
+
+ SET(TESTS
+ #example
++ fts0vlc
+ ha_innodb
+ mem0mem
+ ut0crc32
+new file mode 100644
+--- /dev/null
++++ mysql-5.7.44/unittest/gunit/innodb/fts0vlc-t.cc
+@@ -0,0 +1,352 @@
++/* Copyright (c) 2024, Oracle and/or its affiliates.
++
++ This program is free software; you can redistribute it and/or modify
++ it under the terms of the GNU General Public License, version 2.0,
++ as published by the Free Software Foundation.
++
++ This program is designed to work with certain software (including
++ but not limited to OpenSSL) that is licensed under separate terms,
++ as designated in a particular file or component or in included license
++ documentation. The authors of MySQL hereby grant you an additional
++ permission to link the program and your derivative works with the
++ separately licensed software that they have either included with
++ the program or referenced in the documentation.
++
++ This program is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ GNU General Public License, version 2.0, for more details.
++
++ You should have received a copy of the GNU General Public License
++ along with this program; if not, write to the Free Software
++ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
++
++#include <gtest/gtest.h>
++#include <limits.h>
++#include <stdint.h>
++#include <string.h>
++#include "fts0vlc.ic"
++
++namespace innodb_fts0vlc_unittest {
++
++namespace {
++const uint64_t max_64 = std::numeric_limits<uint64_t>::max();
++}
++
++TEST(fts0vlc, fts_get_encoded_len) {
++ EXPECT_EQ(fts_get_encoded_len(0ULL), 1);
++ EXPECT_EQ(fts_get_encoded_len(127ULL), 1);
++ EXPECT_EQ(fts_get_encoded_len(128ULL), 2);
++ EXPECT_EQ(fts_get_encoded_len((1ULL << 14) - 1), 2);
++ EXPECT_EQ(fts_get_encoded_len(1ULL << 14), 3);
++ EXPECT_EQ(fts_get_encoded_len((1ULL << 21) - 1), 3);
++ EXPECT_EQ(fts_get_encoded_len(1ULL << 21), 4);
++ EXPECT_EQ(fts_get_encoded_len((1ULL << 28) - 1), 4);
++ EXPECT_EQ(fts_get_encoded_len(1ULL << 28), 5);
++
++ /* max 32-bit unsigned integer */
++ EXPECT_EQ(fts_get_encoded_len((1ULL << 32) - 1), 5);
++
++ EXPECT_EQ(fts_get_encoded_len((1ULL << 35) - 1), 5);
++ EXPECT_EQ(fts_get_encoded_len(1ULL << 35), 6);
++ EXPECT_EQ(fts_get_encoded_len((1ULL << 42) - 1), 6);
++ EXPECT_EQ(fts_get_encoded_len(1ULL << 42), 7);
++ EXPECT_EQ(fts_get_encoded_len((1ULL << 49) - 1), 7);
++ EXPECT_EQ(fts_get_encoded_len(1ULL << 49), 8);
++ EXPECT_EQ(fts_get_encoded_len((1ULL << 56) - 1), 8);
++ EXPECT_EQ(fts_get_encoded_len(1ULL << 56), 9);
++ EXPECT_EQ(fts_get_encoded_len((1ULL << 63) - 1), 9);
++ EXPECT_EQ(fts_get_encoded_len(1ULL << 63), 10);
++ EXPECT_EQ(fts_get_encoded_len(max_64), 10);
++}
++
++TEST(fts0vlc, fts_encode_int_decode) {
++ /* Variable-length integer coding packs consecutive groups of 7 bits,
++ starting with most-significant byte, into subsequent bytes of
++ the buffer, using the most-significant bit to mark the end of
++ the encoded sequence
++ */
++
++ byte buf[12];
++ byte *bufptr = buf;
++ const byte filler = 0xa5;
++ memset(buf, filler, sizeof(buf));
++
++ EXPECT_EQ(fts_encode_int(0ULL, bufptr), 1);
++ EXPECT_EQ(bufptr[0], 0x80);
++ EXPECT_EQ(bufptr[1], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), 0ULL);
++ EXPECT_EQ(bufptr, buf + 1);
++
++ EXPECT_EQ(fts_encode_int(10ULL, bufptr), 1);
++ EXPECT_EQ(buf[1], 0x8a);
++ EXPECT_EQ(buf[2], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), 10ULL);
++ EXPECT_EQ(bufptr, buf + 2);
++
++ EXPECT_EQ(fts_encode_int(127ULL, bufptr), 1);
++ EXPECT_EQ(buf[2], 0xff);
++ EXPECT_EQ(buf[3], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), 127ULL);
++ EXPECT_EQ(bufptr, buf + 3);
++
++ EXPECT_EQ(fts_encode_int(128ULL, bufptr), 2);
++ EXPECT_EQ(buf[3], 0x01);
++ EXPECT_EQ(buf[4], 0x80);
++ EXPECT_EQ(buf[5], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), 128ULL);
++ EXPECT_EQ(bufptr, buf + 5);
++
++ EXPECT_EQ(fts_encode_int(130ULL, bufptr), 2);
++ EXPECT_EQ(buf[5], 0x01);
++ EXPECT_EQ(buf[6], 0x82);
++ EXPECT_EQ(buf[7], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), 130ULL);
++ EXPECT_EQ(bufptr, buf + 7);
++
++ EXPECT_EQ(fts_encode_int((1ULL << 14) - 1, bufptr), 2);
++ EXPECT_EQ(buf[7], 0x7f);
++ EXPECT_EQ(buf[8], 0xff);
++ EXPECT_EQ(buf[9], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), (1ULL << 14) - 1);
++ EXPECT_EQ(bufptr, buf + 9);
++
++ EXPECT_EQ(fts_encode_int(1ULL << 14, bufptr), 3);
++ EXPECT_EQ(buf[9], 0x01);
++ EXPECT_EQ(buf[10], 0x00);
++ EXPECT_EQ(buf[11], 0x80);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), 1ULL << 14);
++ EXPECT_EQ(bufptr, buf + 12);
++
++ bufptr = buf;
++ memset(buf, filler, sizeof(buf));
++
++ EXPECT_EQ(fts_encode_int((1ULL << 14) + 256, bufptr), 3);
++ EXPECT_EQ(buf[0], 0x01);
++ EXPECT_EQ(buf[1], 0x02);
++ EXPECT_EQ(buf[2], 0x80);
++ EXPECT_EQ(buf[3], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), (1ULL << 14) + 256);
++ EXPECT_EQ(bufptr, buf + 3);
++
++ EXPECT_EQ(fts_encode_int((1ULL << 21) - 1, bufptr), 3);
++ EXPECT_EQ(buf[3], 0x7f);
++ EXPECT_EQ(buf[4], 0x7f);
++ EXPECT_EQ(buf[5], 0xff);
++ EXPECT_EQ(buf[6], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), (1ULL << 21) - 1);
++ EXPECT_EQ(bufptr, buf + 6);
++
++ EXPECT_EQ(fts_encode_int(1ULL << 21, bufptr), 4);
++ EXPECT_EQ(buf[6], 0x01);
++ EXPECT_EQ(buf[7], 0x00);
++ EXPECT_EQ(buf[8], 0x00);
++ EXPECT_EQ(buf[9], 0x80);
++ EXPECT_EQ(buf[10], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), 1ULL << 21);
++ EXPECT_EQ(bufptr, buf + 10);
++
++ bufptr = buf;
++ memset(buf, filler, sizeof(buf));
++
++ EXPECT_EQ(fts_encode_int((1ULL << 28) - 1, bufptr), 4);
++ EXPECT_EQ(buf[0], 0x7f);
++ EXPECT_EQ(buf[1], 0x7f);
++ EXPECT_EQ(buf[2], 0x7f);
++ EXPECT_EQ(buf[3], 0xff);
++ EXPECT_EQ(buf[4], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), (1ULL << 28) - 1);
++ EXPECT_EQ(bufptr, buf + 4);
++
++ EXPECT_EQ(fts_encode_int(1ULL << 28, bufptr), 5);
++ EXPECT_EQ(buf[4], 0x01);
++ EXPECT_EQ(buf[5], 0x00);
++ EXPECT_EQ(buf[6], 0x00);
++ EXPECT_EQ(buf[7], 0x00);
++ EXPECT_EQ(buf[8], 0x80);
++ EXPECT_EQ(buf[9], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), 1ULL << 28);
++ EXPECT_EQ(bufptr, buf + 9);
++
++ bufptr = buf;
++ memset(buf, filler, sizeof(buf));
++
++ /* maximum 32-bit integer */
++ EXPECT_EQ(fts_encode_int((1ULL << 32) - 1, bufptr), 5);
++ EXPECT_EQ(buf[0], 0x0f);
++ EXPECT_EQ(buf[1], 0x7f);
++ EXPECT_EQ(buf[2], 0x7f);
++ EXPECT_EQ(buf[3], 0x7f);
++ EXPECT_EQ(buf[4], 0xff);
++ EXPECT_EQ(buf[5], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), (1ULL << 32) - 1);
++ EXPECT_EQ(bufptr, buf + 5);
++
++ EXPECT_EQ(fts_encode_int((1ULL << 35) - 1, bufptr), 5);
++ EXPECT_EQ(buf[5], 0x7f);
++ EXPECT_EQ(buf[6], 0x7f);
++ EXPECT_EQ(buf[7], 0x7f);
++ EXPECT_EQ(buf[8], 0x7f);
++ EXPECT_EQ(buf[9], 0xff);
++ EXPECT_EQ(buf[10], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), (1ULL << 35) - 1);
++ EXPECT_EQ(bufptr, buf + 10);
++
++ bufptr = buf;
++ memset(buf, filler, sizeof(buf));
++
++ EXPECT_EQ(fts_encode_int(1ULL << 35, bufptr), 6);
++ EXPECT_EQ(buf[0], 0x01);
++ EXPECT_EQ(buf[1], 0x00);
++ EXPECT_EQ(buf[2], 0x00);
++ EXPECT_EQ(buf[3], 0x00);
++ EXPECT_EQ(buf[4], 0x00);
++ EXPECT_EQ(buf[5], 0x80);
++ EXPECT_EQ(buf[6], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), 1ULL << 35);
++ EXPECT_EQ(bufptr, buf + 6);
++
++ EXPECT_EQ(fts_encode_int((1ULL << 42) - 1, bufptr), 6);
++ EXPECT_EQ(buf[6], 0x7f);
++ EXPECT_EQ(buf[7], 0x7f);
++ EXPECT_EQ(buf[8], 0x7f);
++ EXPECT_EQ(buf[9], 0x7f);
++ EXPECT_EQ(buf[10], 0x7f);
++ EXPECT_EQ(buf[11], 0xff);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), (1ULL << 42) - 1);
++ EXPECT_EQ(bufptr, buf + 12);
++
++ bufptr = buf;
++ memset(buf, filler, sizeof(buf));
++
++ EXPECT_EQ(fts_encode_int(1ULL << 42, bufptr), 7);
++ EXPECT_EQ(buf[0], 0x01);
++ EXPECT_EQ(buf[1], 0x00);
++ EXPECT_EQ(buf[2], 0x00);
++ EXPECT_EQ(buf[3], 0x00);
++ EXPECT_EQ(buf[4], 0x00);
++ EXPECT_EQ(buf[5], 0x00);
++ EXPECT_EQ(buf[6], 0x80);
++ EXPECT_EQ(buf[7], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), 1ULL << 42);
++ EXPECT_EQ(bufptr, buf + 7);
++
++ bufptr = buf;
++ memset(buf, filler, sizeof(buf));
++
++ EXPECT_EQ(fts_encode_int((1ULL << 49) - 1, bufptr), 7);
++ EXPECT_EQ(buf[0], 0x7f);
++ EXPECT_EQ(buf[1], 0x7f);
++ EXPECT_EQ(buf[2], 0x7f);
++ EXPECT_EQ(buf[3], 0x7f);
++ EXPECT_EQ(buf[4], 0x7f);
++ EXPECT_EQ(buf[5], 0x7f);
++ EXPECT_EQ(buf[6], 0xff);
++ EXPECT_EQ(buf[7], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), (1ULL << 49) - 1);
++ EXPECT_EQ(bufptr, buf + 7);
++
++ bufptr = buf;
++ memset(buf, filler, sizeof(buf));
++
++ EXPECT_EQ(fts_encode_int(1ULL << 49, bufptr), 8);
++ EXPECT_EQ(buf[0], 0x01);
++ EXPECT_EQ(buf[1], 0x00);
++ EXPECT_EQ(buf[2], 0x00);
++ EXPECT_EQ(buf[3], 0x00);
++ EXPECT_EQ(buf[4], 0x00);
++ EXPECT_EQ(buf[5], 0x00);
++ EXPECT_EQ(buf[6], 0x00);
++ EXPECT_EQ(buf[7], 0x80);
++ EXPECT_EQ(buf[8], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), 1ULL << 49);
++ EXPECT_EQ(bufptr, buf + 8);
++
++ bufptr = buf;
++ memset(buf, filler, sizeof(buf));
++
++ EXPECT_EQ(fts_encode_int((1ULL << 56) - 1, bufptr), 8);
++ EXPECT_EQ(buf[0], 0x7f);
++ EXPECT_EQ(buf[1], 0x7f);
++ EXPECT_EQ(buf[2], 0x7f);
++ EXPECT_EQ(buf[3], 0x7f);
++ EXPECT_EQ(buf[4], 0x7f);
++ EXPECT_EQ(buf[5], 0x7f);
++ EXPECT_EQ(buf[6], 0x7f);
++ EXPECT_EQ(buf[7], 0xff);
++ EXPECT_EQ(buf[8], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), (1ULL << 56) - 1);
++ EXPECT_EQ(bufptr, buf + 8);
++
++ bufptr = buf;
++ memset(buf, filler, sizeof(buf));
++
++ EXPECT_EQ(fts_encode_int(1ULL << 56, bufptr), 9);
++ EXPECT_EQ(buf[0], 0x01);
++ EXPECT_EQ(buf[1], 0x00);
++ EXPECT_EQ(buf[2], 0x00);
++ EXPECT_EQ(buf[3], 0x00);
++ EXPECT_EQ(buf[4], 0x00);
++ EXPECT_EQ(buf[5], 0x00);
++ EXPECT_EQ(buf[6], 0x00);
++ EXPECT_EQ(buf[7], 0x00);
++ EXPECT_EQ(buf[8], 0x80);
++ EXPECT_EQ(buf[9], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), 1ULL << 56);
++ EXPECT_EQ(bufptr, buf + 9);
++
++ bufptr = buf;
++ memset(buf, filler, sizeof(buf));
++
++ EXPECT_EQ(fts_encode_int((1ULL << 63) - 1, bufptr), 9);
++ EXPECT_EQ(buf[0], 0x7f);
++ EXPECT_EQ(buf[1], 0x7f);
++ EXPECT_EQ(buf[2], 0x7f);
++ EXPECT_EQ(buf[3], 0x7f);
++ EXPECT_EQ(buf[4], 0x7f);
++ EXPECT_EQ(buf[5], 0x7f);
++ EXPECT_EQ(buf[6], 0x7f);
++ EXPECT_EQ(buf[7], 0x7f);
++ EXPECT_EQ(buf[8], 0xff);
++ EXPECT_EQ(buf[9], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), (1ULL << 63) - 1);
++ EXPECT_EQ(bufptr, buf + 9);
++
++ bufptr = buf;
++ memset(buf, filler, sizeof(buf));
++
++ EXPECT_EQ(fts_encode_int(1ULL << 63, bufptr), 10);
++ EXPECT_EQ(buf[0], 0x01);
++ EXPECT_EQ(buf[1], 0x00);
++ EXPECT_EQ(buf[2], 0x00);
++ EXPECT_EQ(buf[3], 0x00);
++ EXPECT_EQ(buf[4], 0x00);
++ EXPECT_EQ(buf[5], 0x00);
++ EXPECT_EQ(buf[6], 0x00);
++ EXPECT_EQ(buf[7], 0x00);
++ EXPECT_EQ(buf[8], 0x00);
++ EXPECT_EQ(buf[9], 0x80);
++ EXPECT_EQ(buf[10], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), 1ULL << 63);
++ EXPECT_EQ(bufptr, buf + 10);
++
++ bufptr = buf;
++ memset(buf, filler, sizeof(buf));
++
++ EXPECT_EQ(fts_encode_int(max_64, bufptr), 10);
++ EXPECT_EQ(buf[0], 0x01);
++ EXPECT_EQ(buf[1], 0x7f);
++ EXPECT_EQ(buf[2], 0x7f);
++ EXPECT_EQ(buf[3], 0x7f);
++ EXPECT_EQ(buf[4], 0x7f);
++ EXPECT_EQ(buf[5], 0x7f);
++ EXPECT_EQ(buf[6], 0x7f);
++ EXPECT_EQ(buf[7], 0x7f);
++ EXPECT_EQ(buf[8], 0x7f);
++ EXPECT_EQ(buf[9], 0xff);
++ EXPECT_EQ(buf[10], filler);
++ EXPECT_EQ(fts_decode_vlc(&bufptr), max_64);
++ EXPECT_EQ(bufptr, buf + 10);
++}
++
++} // namespace innodb_fts0vlc_unittest
diff --git a/mysql-fts-doc-id-cmp.patch b/mysql-fts-doc-id-cmp.patch
new file mode 100644
index 0000000..b3a700b
--- /dev/null
+++ b/mysql-fts-doc-id-cmp.patch
@@ -0,0 +1,313 @@
+FTS_DOC_ID comparison incorrect for large values (Bug#36210202)
+https://github.com/percona/percona-server/commit/d131e82d5c
+
+--- mysql-5.7.44.orig/storage/innobase/fts/fts0fts.cc
++++ mysql-5.7.44/storage/innobase/fts/fts0fts.cc
+@@ -2433,7 +2433,8 @@ fts_trx_table_create(
+ ftt->table = table;
+ ftt->fts_trx = fts_trx;
+
+- ftt->rows = rbt_create(sizeof(fts_trx_row_t), fts_trx_row_doc_id_cmp);
++ ftt->rows = rbt_create(
++ sizeof(fts_trx_row_t), fts_doc_id_field_cmp<fts_trx_row_t>);
+
+ return(ftt);
+ }
+@@ -2457,7 +2458,8 @@ fts_trx_table_clone(
+ ftt->table = ftt_src->table;
+ ftt->fts_trx = ftt_src->fts_trx;
+
+- ftt->rows = rbt_create(sizeof(fts_trx_row_t), fts_trx_row_doc_id_cmp);
++ ftt->rows = rbt_create(
++ sizeof(fts_trx_row_t), fts_doc_id_field_cmp<fts_trx_row_t>);
+
+ /* Copy the rb tree values to the new savepoint. */
+ rbt_merge_uniq(ftt->rows, ftt_src->rows);
+@@ -4067,7 +4069,7 @@ fts_sync_add_deleted_cache(
+
+ ut_a(ib_vector_size(doc_ids) > 0);
+
+- ib_vector_sort(doc_ids, fts_update_doc_id_cmp);
++ ib_vector_sort(doc_ids, fts_doc_id_field_cmp<fts_update_t>);
+
+ info = pars_info_create();
+
+--- mysql-5.7.44.orig/storage/innobase/fts/fts0opt.cc
++++ mysql-5.7.44/storage/innobase/fts/fts0opt.cc
+@@ -1050,7 +1050,7 @@ fts_table_fetch_doc_ids(
+ if (error == DB_SUCCESS) {
+ fts_sql_commit(trx);
+
+- ib_vector_sort(doc_ids->doc_ids, fts_update_doc_id_cmp);
++ ib_vector_sort(doc_ids->doc_ids, fts_doc_id_field_cmp<fts_update_t>);
+ } else {
+ fts_sql_rollback(trx);
+ }
+--- mysql-5.7.44.orig/storage/innobase/fts/fts0que.cc
++++ mysql-5.7.44/storage/innobase/fts/fts0que.cc
+@@ -292,6 +292,9 @@ struct fts_word_freq_t {
+ double idf; /*!< Inverse document frequency */
+ };
+
++static ib_rbt_compare fts_ranking_doc_id_cmp =
++ fts_doc_id_field_cmp<fts_ranking_t>;
++
+ /********************************************************************
+ Callback function to fetch the rows in an FTS INDEX record.
+ @return always TRUE */
+@@ -391,25 +394,7 @@ fts_query_terms_in_document(
+ fts_query_t* query, /*!< in: FTS query state */
+ doc_id_t doc_id, /*!< in: the word to check */
+ ulint* total); /*!< out: total words in document */
+-#endif
+
+-/********************************************************************
+-Compare two fts_doc_freq_t doc_ids.
+- at return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2 */
+-UNIV_INLINE
+-int
+-fts_freq_doc_id_cmp(
+-/*================*/
+- const void* p1, /*!< in: id1 */
+- const void* p2) /*!< in: id2 */
+-{
+- const fts_doc_freq_t* fq1 = (const fts_doc_freq_t*) p1;
+- const fts_doc_freq_t* fq2 = (const fts_doc_freq_t*) p2;
+-
+- return((int) (fq1->doc_id - fq2->doc_id));
+-}
+-
+-#if 0
+ /*******************************************************************//**
+ Print the table used for calculating LCS. */
+ static
+@@ -682,7 +667,7 @@ fts_query_add_word_freq(
+ word_freq.doc_count = 0;
+
+ word_freq.doc_freqs = rbt_create(
+- sizeof(fts_doc_freq_t), fts_freq_doc_id_cmp);
++ sizeof(fts_doc_freq_t), fts_doc_id_field_cmp<fts_doc_freq_t>);
+
+ parent.last = rbt_add_node(
+ query->word_freqs, &parent, &word_freq);
+@@ -4073,7 +4058,7 @@ fts_query(
+ DEBUG_SYNC_C("fts_deleted_doc_ids_append");
+
+ /* Sort the vector so that we can do a binary search over the ids. */
+- ib_vector_sort(query.deleted->doc_ids, fts_update_doc_id_cmp);
++ ib_vector_sort(query.deleted->doc_ids, fts_doc_id_field_cmp<fts_doc_freq_t>);
+
+ /* Convert the query string to lower case before parsing. We own
+ the ut_malloc'ed result and so remember to free it before return. */
+--- mysql-5.7.44.orig/storage/innobase/include/fts0types.h
++++ mysql-5.7.44/storage/innobase/include/fts0types.h
+@@ -303,45 +303,6 @@ struct fts_token_t {
+ /** It's defined in fts/fts0fts.c */
+ extern const fts_index_selector_t fts_index_selector[];
+
+-/******************************************************************//**
+-Compare two fts_trx_row_t instances doc_ids. */
+-UNIV_INLINE
+-int
+-fts_trx_row_doc_id_cmp(
+-/*===================*/
+- /*!< out:
+- < 0 if n1 < n2,
+- 0 if n1 == n2,
+- > 0 if n1 > n2 */
+- const void* p1, /*!< in: id1 */
+- const void* p2); /*!< in: id2 */
+-
+-/******************************************************************//**
+-Compare two fts_ranking_t instances doc_ids. */
+-UNIV_INLINE
+-int
+-fts_ranking_doc_id_cmp(
+-/*===================*/
+- /*!< out:
+- < 0 if n1 < n2,
+- 0 if n1 == n2,
+- > 0 if n1 > n2 */
+- const void* p1, /*!< in: id1 */
+- const void* p2); /*!< in: id2 */
+-
+-/******************************************************************//**
+-Compare two fts_update_t instances doc_ids. */
+-UNIV_INLINE
+-int
+-fts_update_doc_id_cmp(
+-/*==================*/
+- /*!< out:
+- < 0 if n1 < n2,
+- 0 if n1 == n2,
+- > 0 if n1 > n2 */
+- const void* p1, /*!< in: id1 */
+- const void* p2); /*!< in: id2 */
+-
+ /******************************************************************//**
+ Decode and return the integer that was encoded using our VLC scheme.*/
+ UNIV_INLINE
+--- mysql-5.7.44.orig/storage/innobase/include/fts0types.ic
++++ mysql-5.7.44/storage/innobase/include/fts0types.ic
+@@ -57,51 +57,35 @@ fts_string_dup(
+ }
+
+ /******************************************************************//**
+-Compare two fts_trx_row_t doc_ids.
+- at return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2 */
++Compare two doc_ids.
++ @param[in] id1 1st doc_id to compare
++ @param[in] id2 2nd doc_id to compare
++ @return < 0 if id1 < id2, 0 if id1 == id2, > 0 if id1 > id2 */
+ UNIV_INLINE
+ int
+-fts_trx_row_doc_id_cmp(
+-/*===================*/
+- const void* p1, /*!< in: id1 */
+- const void* p2) /*!< in: id2 */
++fts_doc_id_cmp(doc_id_t id1, doc_id_t id2)
+ {
+- const fts_trx_row_t* tr1 = (const fts_trx_row_t*) p1;
+- const fts_trx_row_t* tr2 = (const fts_trx_row_t*) p2;
+-
+- return((int)(tr1->doc_id - tr2->doc_id));
++ if (id1 < id2) {
++ return -1;
++ } else if (id1 > id2) {
++ return 1;
++ } else {
++ return 0;
++ }
+ }
+
+ /******************************************************************//**
+-Compare two fts_ranking_t doc_ids.
+- at return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2 */
+-UNIV_INLINE
+-int
+-fts_ranking_doc_id_cmp(
+-/*===================*/
+- const void* p1, /*!< in: id1 */
+- const void* p2) /*!< in: id2 */
+-{
+- const fts_ranking_t* rk1 = (const fts_ranking_t*) p1;
+- const fts_ranking_t* rk2 = (const fts_ranking_t*) p2;
+-
+- return((int)(rk1->doc_id - rk2->doc_id));
+-}
+-
+-/******************************************************************//**
+-Compare two fts_update_t doc_ids.
+- at return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2 */
+-UNIV_INLINE
+-int
+-fts_update_doc_id_cmp(
+-/*==================*/
+- const void* p1, /*!< in: id1 */
+- const void* p2) /*!< in: id2 */
++Compare doc_ids of 2 objects.
++ @param[in] p1 Pointer to first instance o1 of T
++ @param[in] p2 Pointer to second instance o2 of T
++ @return sign(o1->doc_id - o2->doc_id) */
++template <typename T>
++int fts_doc_id_field_cmp(const void *p1, const void *p2)
+ {
+- const fts_update_t* up1 = (const fts_update_t*) p1;
+- const fts_update_t* up2 = (const fts_update_t*) p2;
++ const T *o1 = static_cast<const T *>(p1);
++ const T *o2 = static_cast<const T *>(p2);
+
+- return((int)(up1->doc_id - up2->doc_id));
++ return fts_doc_id_cmp(o1->doc_id, o2->doc_id);
+ }
+
+ /******************************************************************//**
+--- mysql-5.7.44.orig/unittest/gunit/innodb/CMakeLists.txt
++++ mysql-5.7.44/unittest/gunit/innodb/CMakeLists.txt
+@@ -38,6 +38,7 @@ SET(TESTS
+ ut0crc32
+ ut0mem
+ ut0new
++ ut0rbt
+ )
+
+ IF (MERGE_UNITTESTS)
+new file mode 100644
+--- /dev/null
++++ mysql-5.7.44/unittest/gunit/innodb/ut0rbt-t.cc
+@@ -0,0 +1,75 @@
++/* Copyright (c) 2024, Oracle and/or its affiliates.
++
++ This program is free software; you can redistribute it and/or modify
++ it under the terms of the GNU General Public License, version 2.0,
++ as published by the Free Software Foundation.
++
++ This program is designed to work with certain software (including
++ but not limited to OpenSSL) that is licensed under separate terms,
++ as designated in a particular file or component or in included license
++ documentation. The authors of MySQL hereby grant you an additional
++ permission to link the program and your derivative works with the
++ separately licensed software that they have either included with
++ the program or referenced in the documentation.
++
++ This program is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ GNU General Public License, version 2.0, for more details.
++
++ You should have received a copy of the GNU General Public License
++ along with this program; if not, write to the Free Software
++ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
++
++#include <gtest/gtest.h>
++
++#include "fts0fts.h"
++#include "fts0types.h"
++#include "univ.i"
++#include "ut0rbt.h"
++
++namespace innodb_ut0rbt_unittest {
++
++/* Doc id array for testing with values exceeding 32-bit integer limit */
++const doc_id_t doc_ids[] = {
++ 17574, 89783, 94755, 97537, 101358, 101361,
++ 102587, 103571, 104018, 106821, 108647, 109352,
++ 109379, 110325, 122868, 210682130, 231275441, 234172769,
++ 366236849, 526467159, 1675241735, 1675243405, 1947751899, 1949940363,
++ 2033691953, 2148227299, 2256289791, 2294223591, 2367501260, 2792700091,
++ 2792701220, 2817121627, 2820680352, 2821165664, 3253312130, 3404918378,
++ 3532599429, 3538712078, 3539373037, 3546479309, 3566641838, 3580209634,
++ 3580871267, 3693930556, 3693932734, 3693932983, 3781949558, 3839877411,
++ 3930968983, 4146309172, 4524715523, 4524715525, 4534911119, 4597818456};
++
++const doc_id_t search_doc_id = 1675241735;
++
++namespace {
++struct dummy {
++ doc_id_t doc_id;
++};
++} // namespace
++
++TEST(ut0rbt, fts_doc_id_cmp) {
++ ib_rbt_t *doc_id_rbt = rbt_create(sizeof(dummy), fts_doc_id_field_cmp<dummy>);
++
++ /* Insert doc ids into rbtree. */
++ for (unsigned i = 0; i < sizeof(doc_ids)/sizeof(doc_ids[0]); i++)
++ {
++ const doc_id_t& doc_id = doc_ids[i];
++ ib_rbt_bound_t parent;
++ dummy obj;
++ obj.doc_id = doc_id;
++
++ if (rbt_search(doc_id_rbt, &parent, &obj.doc_id) != 0) {
++ rbt_add_node(doc_id_rbt, &parent, &obj);
++ }
++ }
++
++ /* Check if doc id exists in rbtree */
++ ib_rbt_bound_t parent;
++ EXPECT_EQ(rbt_search(doc_id_rbt, &parent, &search_doc_id), 0);
++
++ rbt_free(doc_id_rbt);
++}
++} // namespace innodb_ut0rbt_unittest
diff --git a/mysql-fts-drop-add-index.patch b/mysql-fts-drop-add-index.patch
new file mode 100644
index 0000000..059dee8
--- /dev/null
+++ b/mysql-fts-drop-add-index.patch
@@ -0,0 +1,84 @@
+FTS cleanup on DROP INDEX issue when adding a FULLTEXT index in same
+transaction (Bug#36559642)
+https://github.com/percona/percona-server/commit/03f112e255
+
+--- mysql-5.7.44.orig/storage/innobase/fts/fts0fts.cc
++++ mysql-5.7.44/storage/innobase/fts/fts0fts.cc
+@@ -811,17 +811,21 @@ fts_drop_index(
+ /*===========*/
+ dict_table_t* table, /*!< in: Table where indexes are dropped */
+ dict_index_t* index, /*!< in: Index to be dropped */
+- trx_t* trx) /*!< in: Transaction for the drop */
++ trx_t* trx, /*!< in: Transaction for the drop */
++ bool adding_another) /*! in: Another FTS index is to be
++ added as part of the same
++ transaction */
+ {
+ ib_vector_t* indexes = table->fts->indexes;
+ dberr_t err = DB_SUCCESS;
+
+ ut_a(indexes);
+
+- if ((ib_vector_size(indexes) == 1
++ const bool last_index = (ib_vector_size(indexes) == 1
+ && (index == static_cast<dict_index_t*>(
+ ib_vector_getp(table->fts->indexes, 0))))
+- || ib_vector_is_empty(indexes)) {
++ || ib_vector_is_empty(indexes);
++ if (last_index && !adding_another) {
+ doc_id_t current_doc_id;
+ doc_id_t first_doc_id;
+
+--- mysql-5.7.44.orig/storage/innobase/handler/handler0alter.cc
++++ mysql-5.7.44/storage/innobase/handler/handler0alter.cc
+@@ -8018,12 +8018,17 @@ commit_cache_norebuild(
+ }
+ }
+
++ bool adding_fts_index = false;
++
+ for (ulint i = 0; i < ctx->num_to_add_index; i++) {
+ dict_index_t* index = ctx->add_index[i];
+ assert(dict_index_get_online_status(index)
+ == ONLINE_INDEX_COMPLETE);
+ assert(!index->is_committed());
+ index->set_committed(true);
++ if (index->type & DICT_FTS) {
++ adding_fts_index = true;
++ }
+ }
+
+ if (ctx->num_to_drop_index) {
+@@ -8070,7 +8075,7 @@ commit_cache_norebuild(
+ || (index->type
+ & DICT_CORRUPT));
+ assert(index->table->fts);
+- fts_drop_index(index->table, index, trx);
++ fts_drop_index(index->table, index, trx, adding_fts_index);
+ }
+
+ dict_index_remove_from_cache(index->table, index);
+@@ -8857,9 +8862,6 @@ foreign_fail:
+
+ if (index->type & DICT_FTS) {
+ assert(index->type == DICT_FTS);
+- /* We reset DICT_TF2_FTS here because the bit
+- is left unset when a drop proceeds the add. */
+- DICT_TF2_FLAG_SET(ctx->new_table, DICT_TF2_FTS);
+ fts_add_index(index, ctx->new_table);
+ }
+ }
+--- mysql-5.7.44.orig/storage/innobase/include/fts0fts.h
++++ mysql-5.7.44/storage/innobase/include/fts0fts.h
+@@ -1046,7 +1046,10 @@ fts_drop_index(
+ /*===========*/
+ dict_table_t* table, /*!< in: Table where indexes are dropped */
+ dict_index_t* index, /*!< in: Index to be dropped */
+- trx_t* trx); /*!< in: Transaction for the drop */
++ trx_t* trx, /*!< in: Transaction for the drop */
++ bool adding_another = false); /*!< in: Another FTS index is
++ to be added as part of
++ the same transaction */
+
+ /****************************************************************//**
+ Rename auxiliary tables for all fts index for a table
diff --git a/mysql-fts-ngram-percent.patch b/mysql-fts-ngram-percent.patch
new file mode 100644
index 0000000..47cec5a
--- /dev/null
+++ b/mysql-fts-ngram-percent.patch
@@ -0,0 +1,120 @@
+fix: Fixed problem with percent character in n-grams
+https://github.com/percona/percona-server/commit/4400b0a9c8
+
+--- mysql-5.7.44.orig/storage/innobase/fts/fts0opt.cc
++++ mysql-5.7.44/storage/innobase/fts/fts0opt.cc
+@@ -490,7 +490,8 @@ fts_index_fetch_nodes(
+ fts_table_t* fts_table, /*!< in: table of the FTS INDEX */
+ const fts_string_t*
+ word, /*!< in: the word to fetch */
+- fts_fetch_t* fetch) /*!< in: fetch callback.*/
++ fts_fetch_t* fetch, /*!< in: fetch callback.*/
++ bool exact_match) /*!< in: exact match.*/
+ {
+ pars_info_t* info;
+ dberr_t error;
+@@ -525,23 +526,26 @@ fts_index_fetch_nodes(
+ *graph = fts_parse_sql(
+ fts_table,
+ info,
+- "DECLARE FUNCTION my_func;\n"
+- "DECLARE CURSOR c IS"
+- " SELECT word, doc_count, first_doc_id, last_doc_id,"
+- " ilist\n"
+- " FROM $table_name\n"
+- " WHERE word LIKE :word\n"
+- " ORDER BY first_doc_id;\n"
+- "BEGIN\n"
+- "\n"
+- "OPEN c;\n"
+- "WHILE 1 = 1 LOOP\n"
+- " FETCH c INTO my_func();\n"
+- " IF c % NOTFOUND THEN\n"
+- " EXIT;\n"
+- " END IF;\n"
+- "END LOOP;\n"
+- "CLOSE c;");
++ mem_heap_printf(
++ info->heap,
++ "DECLARE FUNCTION my_func;\n"
++ "DECLARE CURSOR c IS"
++ " SELECT word, doc_count, first_doc_id,"
++ " last_doc_id, ilist\n"
++ " FROM $table_name\n"
++ " WHERE word %s :word\n"
++ " ORDER BY first_doc_id;\n"
++ "BEGIN\n"
++ "\n"
++ "OPEN c;\n"
++ "WHILE 1 = 1 LOOP\n"
++ " FETCH c INTO my_func();\n"
++ " IF c %% NOTFOUND THEN\n"
++ " EXIT;\n"
++ " END IF;\n"
++ "END LOOP;\n"
++ "CLOSE c;",
++ (exact_match ? "=" : "LIKE")));
+ }
+
+ for (;;) {
+@@ -1819,7 +1823,7 @@ fts_optimize_words(
+ fetch.total_memory = 0;
+ error = fts_index_fetch_nodes(
+ trx, &graph, &optim->fts_index_table, word,
+- &fetch);
++ &fetch, true);
+ ut_ad(fetch.total_memory < fts_result_cache_limit);
+
+ if (error == DB_SUCCESS) {
+--- mysql-5.7.44.orig/storage/innobase/fts/fts0que.cc
++++ mysql-5.7.44/storage/innobase/fts/fts0que.cc
+@@ -1193,7 +1193,8 @@ fts_query_difference(
+ fetch.read_record = fts_query_index_fetch_nodes;
+
+ error = fts_index_fetch_nodes(
+- trx, &graph, &query->fts_index_table, token, &fetch);
++ trx, &graph, &query->fts_index_table, token, &fetch,
++ false);
+
+ /* DB_FTS_EXCEED_RESULT_CACHE_LIMIT passed by 'query->error' */
+ ut_ad(!(query->error != DB_SUCCESS && error != DB_SUCCESS));
+@@ -1317,7 +1318,8 @@ fts_query_intersect(
+ fetch.read_record = fts_query_index_fetch_nodes;
+
+ error = fts_index_fetch_nodes(
+- trx, &graph, &query->fts_index_table, token, &fetch);
++ trx, &graph, &query->fts_index_table, token, &fetch,
++ false);
+
+ /* DB_FTS_EXCEED_RESULT_CACHE_LIMIT passed by 'query->error' */
+ ut_ad(!(query->error != DB_SUCCESS && error != DB_SUCCESS));
+@@ -1437,7 +1439,7 @@ fts_query_union(
+
+ /* Read the nodes from disk. */
+ error = fts_index_fetch_nodes(
+- trx, &graph, &query->fts_index_table, token, &fetch);
++ trx, &graph, &query->fts_index_table, token, &fetch, false);
+
+ /* DB_FTS_EXCEED_RESULT_CACHE_LIMIT passed by 'query->error' */
+ ut_ad(!(query->error != DB_SUCCESS && error != DB_SUCCESS));
+@@ -2810,7 +2812,7 @@ fts_query_phrase_search(
+
+ error = fts_index_fetch_nodes(
+ trx, &graph, &query->fts_index_table,
+- token, &fetch);
++ token, &fetch, false);
+
+ /* DB_FTS_EXCEED_RESULT_CACHE_LIMIT passed by 'query->error' */
+ ut_ad(!(query->error != DB_SUCCESS && error != DB_SUCCESS));
+--- mysql-5.7.44.orig/storage/innobase/include/fts0priv.h
++++ mysql-5.7.44/storage/innobase/include/fts0priv.h
+@@ -308,7 +308,8 @@ fts_index_fetch_nodes(
+ fts_table_t* fts_table, /*!< in: FTS aux table */
+ const fts_string_t*
+ word, /*!< in: the word to fetch */
+- fts_fetch_t* fetch); /*!< in: fetch callback.*/
++ fts_fetch_t* fetch, /*!< in: fetch callback.*/
++ bool exact_match); /*!< in: exact match.*/
+
+ /******************************************************************//**
+ Create a fts_optimizer_word_t instance.
diff --git a/mysql-fts-optimize-last-word.patch b/mysql-fts-optimize-last-word.patch
new file mode 100644
index 0000000..744638f
--- /dev/null
+++ b/mysql-fts-optimize-last-word.patch
@@ -0,0 +1,134 @@
+Double processing of FTS index words with innodb_optimize_fulltext_only
+(Bug#34929814)
+https://github.com/percona/percona-server/commit/641f1f445b
+https://github.com/mysql/mysql-server/commit/66cc7556964
+
+--- mysql-5.7.44.orig/storage/innobase/fts/fts0opt.cc
++++ mysql-5.7.44/storage/innobase/fts/fts0opt.cc
+@@ -576,27 +576,21 @@ fts_index_fetch_nodes(
+ }
+
+ /**********************************************************************//**
+-Read a word */
++Extract a given number of bytes into a buffer */
+ static
+-byte*
+-fts_zip_read_word(
++bool
++fts_zip_extract_bytes(
+ /*==============*/
+ fts_zip_t* zip, /*!< in: Zip state + data */
+- fts_string_t* word) /*!< out: uncompressed word */
++ byte *buf, /*!< out: buffer to be filled */
++ unsigned int size) /*!< in: size of buffer */
+ {
+- short len = 0;
++ bool complete = false;
++ zip->zp->next_out = buf;
++ zip->zp->avail_out = size;
+ void* null = NULL;
+- byte* ptr = word->f_str;
+ int flush = Z_NO_FLUSH;
+
+- /* Either there was an error or we are at the Z_STREAM_END. */
+- if (zip->status != Z_OK) {
+- return(NULL);
+- }
+-
+- zip->zp->next_out = reinterpret_cast<byte*>(&len);
+- zip->zp->avail_out = sizeof(len);
+-
+ while (zip->status == Z_OK && zip->zp->avail_out > 0) {
+
+ /* Finished decompressing block. */
+@@ -635,22 +629,26 @@ fts_zip_read_word(
+
+ switch (zip->status = inflate(zip->zp, flush)) {
+ case Z_OK:
+- if (zip->zp->avail_out == 0 && len > 0) {
+-
+- ut_a(len <= FTS_MAX_WORD_LEN);
+- ptr[len] = 0;
+-
+- zip->zp->next_out = ptr;
+- zip->zp->avail_out = len;
+-
+- word->f_len = len;
+- len = 0;
++ if (zip->zp->avail_out == 0) {
++ complete = true;
+ }
+ break;
+
+- case Z_BUF_ERROR: /* No progress possible. */
+ case Z_STREAM_END:
++ if (zip->zp->avail_out == 0) {
++ complete = true;
++ }
++
++ /* Fallthrough */
++ case Z_BUF_ERROR: /* No progress possible. */
+ inflateEnd(zip->zp);
++ /* All blocks must be freed at end of inflate. */
++ for (ulint i = 0; i < ib_vector_size(zip->blocks); ++i) {
++ if (ib_vector_getp(zip->blocks, i)) {
++ ut_free(ib_vector_getp(zip->blocks, i));
++ ib_vector_set(zip->blocks, i, &null);
++ }
++ }
+ break;
+
+ case Z_STREAM_ERROR:
+@@ -659,21 +657,42 @@ fts_zip_read_word(
+ }
+ }
+
+- /* All blocks must be freed at end of inflate. */
++ return complete;
++}
++
++/**********************************************************************//**
++Read a word */
++static
++bool
++fts_zip_read_word(
++/*==============*/
++ fts_zip_t* zip, /*!< in: Zip state + data */
++ fts_string_t* word) /*!< out: uncompressed word */
++{
++ /* Either there was an error or we are at the Z_STREAM_END. */
+ if (zip->status != Z_OK) {
+- for (ulint i = 0; i < ib_vector_size(zip->blocks); ++i) {
+- if (ib_vector_getp(zip->blocks, i)) {
+- ut_free(ib_vector_getp(zip->blocks, i));
+- ib_vector_set(zip->blocks, i, &null);
+- }
+- }
++ return false;
+ }
+
+- if (ptr != NULL) {
+- ut_ad(word->f_len == strlen((char*) ptr));
++ ushort len = 0;
++
++ const bool have_len =
++ fts_zip_extract_bytes(zip, reinterpret_cast<byte *>(&len), sizeof(len));
++
++ if (!have_len) {
++ return false;
+ }
+
+- return(zip->status == Z_OK || zip->status == Z_STREAM_END ? ptr : NULL);
++ ut_a(len <= FTS_MAX_WORD_LEN);
++
++ word->f_len = len;
++ const bool have_word = fts_zip_extract_bytes(zip, word->f_str, len);
++ ut_ad(have_word);
++
++ word->f_str[len] = 0;
++ ut_ad(word->f_len == strlen((char *)word->f_str));
++
++ return have_word;
+ }
+
+ /**********************************************************************//**
diff --git a/mysql-fts-self-fk-cascade.patch b/mysql-fts-self-fk-cascade.patch
new file mode 100644
index 0000000..60c5428
--- /dev/null
+++ b/mysql-fts-self-fk-cascade.patch
@@ -0,0 +1,155 @@
+InnoDB: Failing assertion: result != FTS_INVALID (Bug#36234681)
+https://github.com/percona/percona-server/commit/e87c07230b
+https://github.com/mysql/mysql-server/commit/a8c96ce81ab
+
+--- mysql-5.7.44.orig/storage/innobase/dict/dict0mem.cc
++++ mysql-5.7.44/storage/innobase/dict/dict0mem.cc
+@@ -1127,6 +1127,32 @@ dict_foreign_set_validate(
+ && dict_foreign_set_validate(table.referenced_set));
+ }
+
++bool dict_foreign_t::is_fts_col_affected() const
++{
++ /* The check is skipped:
++ - if the table has no full text index defined.
++ - if it is a self referential foreign constaint. This is because
++ in the context of cascading DML operation, only the referenced
++ table is relevant for the validation even if the current table
++ has FTS index. */
++ if (!foreign_table->fts || foreign_table == referenced_table) {
++ return false;
++ }
++
++ for (ulint i = 0; i < n_fields; i++)
++ {
++ const dict_col_t* col = dict_index_get_nth_col(
++ foreign_index, i);
++
++ if (dict_table_is_fts_column(foreign_table->fts->indexes,
++ dict_col_get_no(col),
++ dict_col_is_virtual(col)) != ULINT_UNDEFINED) {
++ return true;
++ }
++ }
++ return false;
++}
++
+ std::ostream&
+ operator<< (std::ostream& out, const dict_foreign_t& foreign)
+ {
+--- mysql-5.7.44.orig/storage/innobase/include/dict0mem.h
++++ mysql-5.7.44/storage/innobase/include/dict0mem.h
+@@ -1092,6 +1092,14 @@ struct dict_foreign_t{
+
+ dict_vcol_set* v_cols; /*!< set of virtual columns affected
+ by foreign key constraint. */
++ /** Check whether foreign key constraint contains a column with a full
++ index on it. The function is used in the context of cascading DML
++ operations.
++ @retval true if the column has FTS index on it.
++ @retval false if the FK table has no FTS index or has self referential
++ relationship
++ */
++ bool is_fts_col_affected() const;
+ };
+
+ std::ostream&
+--- mysql-5.7.44.orig/storage/innobase/row/row0ins.cc
++++ mysql-5.7.44/storage/innobase/row/row0ins.cc
+@@ -534,7 +534,7 @@ row_ins_cascade_calc_update_vec(
+
+ n_fields_updated = 0;
+
+- *fts_col_affected = FALSE;
++ *fts_col_affected = foreign->is_fts_col_affected();
+
+ if (table->fts) {
+ doc_id_pos = dict_table_get_nth_col_pos(
+@@ -654,16 +654,6 @@ row_ins_cascade_calc_update_vec(
+ padded_data, min_size);
+ }
+
+- /* Check whether the current column has
+- FTS index on it */
+- if (table->fts
+- && dict_table_is_fts_column(
+- table->fts->indexes,
+- dict_col_get_no(col),
+- dict_col_is_virtual(col))
+- != ULINT_UNDEFINED) {
+- *fts_col_affected = TRUE;
+- }
+
+ /* If Doc ID is updated, check whether the
+ Doc ID is valid */
+@@ -1111,7 +1101,6 @@ row_ins_foreign_check_on_constraint(
+ trx_t* trx;
+ mem_heap_t* tmp_heap = NULL;
+ doc_id_t doc_id = FTS_NULL_DOC_ID;
+- ibool fts_col_affacted = FALSE;
+
+ DBUG_ENTER("row_ins_foreign_check_on_constraint");
+ ut_a(thr);
+@@ -1342,17 +1331,9 @@ row_ins_foreign_check_on_constraint(
+ ufield->exp = NULL;
+ dfield_set_null(&ufield->new_val);
+
+- if (table->fts && dict_table_is_fts_column(
+- table->fts->indexes,
+- dict_index_get_nth_col_no(index, i),
+- dict_col_is_virtual(
+- dict_index_get_nth_col(index, i)))
+- != ULINT_UNDEFINED) {
+- fts_col_affacted = TRUE;
+- }
+ }
+
+- if (fts_col_affacted) {
++ if (foreign->is_fts_col_affected()) {
+ fts_trx_add_op(trx, table, doc_id, FTS_DELETE, NULL);
+ }
+
+@@ -1369,31 +1350,21 @@ row_ins_foreign_check_on_constraint(
+
+ } else if (table->fts && cascade->is_delete) {
+ /* DICT_FOREIGN_ON_DELETE_CASCADE case */
+- for (i = 0; i < foreign->n_fields; i++) {
+- if (table->fts && dict_table_is_fts_column(
+- table->fts->indexes,
+- dict_index_get_nth_col_no(index, i),
+- dict_col_is_virtual(
+- dict_index_get_nth_col(index, i)))
+- != ULINT_UNDEFINED) {
+- fts_col_affacted = TRUE;
+- }
+- }
+-
+- if (fts_col_affacted) {
++ if (foreign->is_fts_col_affected()) {
+ fts_trx_add_op(trx, table, doc_id, FTS_DELETE, NULL);
+ }
+ }
+
+ if (!node->is_delete
+ && (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE)) {
++ ibool fts_col_affected = FALSE;
+
+ /* Build the appropriate update vector which sets changing
+ foreign->n_fields first fields in rec to new values */
+
+ n_to_update = row_ins_cascade_calc_update_vec(
+ node, foreign, tmp_heap,
+- trx, &fts_col_affacted);
++ trx, &fts_col_affected);
+
+
+ if (foreign->v_cols != NULL
+@@ -1434,7 +1405,7 @@ row_ins_foreign_check_on_constraint(
+ }
+
+ /* Mark the old Doc ID as deleted */
+- if (fts_col_affacted) {
++ if (fts_col_affected) {
+ ut_ad(table->fts);
+ fts_trx_add_op(trx, table, doc_id, FTS_DELETE, NULL);
+ }
diff --git a/mysql-fts-sort-mem-limit.patch b/mysql-fts-sort-mem-limit.patch
new file mode 100644
index 0000000..7c68498
--- /dev/null
+++ b/mysql-fts-sort-mem-limit.patch
@@ -0,0 +1,166 @@
+FTS index construction ignores memory limits (Bug#39040226)
+https://github.com/percona/percona-server/commit/b5a78df71f
+https://github.com/mysql/mysql-server/commit/19ac235c84f
+
+--- mysql-5.7.44.orig/storage/innobase/row/row0ftsort.cc
++++ mysql-5.7.44/storage/innobase/row/row0ftsort.cc
+@@ -718,10 +718,15 @@ row_merge_fts_get_next_doc_item(
+ if (*doc_item != NULL) {
+ UT_LIST_REMOVE(psort_info->fts_doc_list, *doc_item);
+
++ /* Mirrors the accounting done in row_merge_buf_add() when
++ the doc_item was enqueued: the allocation there carries a
++ trailing dfield_t copy followed by the field payload so the
++ consumer keeps seeing valid dfield_t/data until it frees the
++ item. */
+ ut_ad(psort_info->memory_used >= sizeof(fts_doc_item_t)
+- + (*doc_item)->field->len);
++ + sizeof(dfield_t) + (*doc_item)->field->len);
+ psort_info->memory_used -= sizeof(fts_doc_item_t)
+- + (*doc_item)->field->len;
++ + sizeof(dfield_t) + (*doc_item)->field->len;
+ }
+
+ mutex_exit(&psort_info->mutex);
+@@ -792,6 +797,15 @@ loop:
+ while (doc_item) {
+ dfield_t* dfield = doc_item->field;
+
++ /* Debug-only hook used to deterministically stall the parallel
++ tokenization consumers so that the producer (scan thread in
++ row_merge_buf_add) is forced into the retry loop that guards
++ FTS_PENDING_DOC_MEMORY_LIMIT. Used by
++ mysql-test/suite/innodb_fts/t/fts_build_mem_limit.test to
++ exercise Bug#39040226 on 5.7. */
++ DBUG_EXECUTE_IF("fts_instrument_sort_slow_consumer",
++ os_thread_sleep(20000););
++
+ last_doc_id = doc_item->doc_id;
+
+ ut_ad (dfield->data != NULL
+--- mysql-5.7.44.orig/storage/innobase/row/row0merge.cc
++++ mysql-5.7.44/storage/innobase/row/row0merge.cc
+@@ -543,9 +543,34 @@ row_merge_buf_add(
+
+ n_fields = dict_index_get_n_fields(index);
+
+- entry = &buf->tuples[buf->n_tuples];
+- field = entry->fields = static_cast<dfield_t*>(
+- mem_heap_alloc(buf->heap, n_fields * sizeof *entry->fields));
++ /* For an FTS index build the per-row mtuple is never stored in
++ buf->tuples: the FTS path below enqueues an fts_doc_item_t on the
++ per-bucket fts_doc_list (drained by the tokenization threads) and
++ returns without incrementing buf->n_tuples. Allocating entry->fields
++ from buf->heap on every scanned row therefore leaks
++ ~n_fields*sizeof(dfield_t) bytes per row into memory/innodb/mem0mem
++ for the entire duration of the FTS build -- on a table with millions
++ of rows this comfortably reaches hundreds of megabytes.
++
++ Use a single stack-local dfield_t for the FTS scratch field instead.
++ The scratch slot is only ever read within the iteration that writes
++ it: the non-doc-id branch copies the field data into the doc_item's
++ own ut_malloc'ed buffer and then continues the loop, while the
++ doc-id branch consumes the slot via dfield_get_len/is_null/is_ext
++ in the same iteration. At line
++ if (index->type & DICT_FTS) { DBUG_RETURN(n_row_added); }
++ below the function returns without reading any slot back, so one
++ scratch dfield_t is sufficient. */
++ dfield_t fts_stack_field;
++
++ if (index->type & DICT_FTS) {
++ entry = NULL;
++ } else {
++ entry = &buf->tuples[buf->n_tuples];
++ field = entry->fields = static_cast<dfield_t*>(
++ mem_heap_alloc(buf->heap,
++ n_fields * sizeof *entry->fields));
++ }
+
+ data_size = 0;
+ extra_size = UT_BITS_IN_BYTES(index->n_nullable);
+@@ -560,6 +585,16 @@ row_merge_buf_add(
+ ulint fixed_len;
+ const dfield_t* row_field;
+
++ /* For the FTS path the scratch dfield_t is only used within
++ the current iteration (see the comment near fts_stack_field
++ above). Re-point `field' at the single stack slot at every
++ iteration so the loop's field++ increment is a harmless
++ no-op for FTS and we don't need a per-field array which would
++ be confusing for someone reading the code. */
++ if (index->type & DICT_FTS) {
++ field = &fts_stack_field;
++ }
++
+ col = ifield->col;
+ if (dict_col_is_virtual(col)) {
+ v_col = reinterpret_cast<const dict_v_col_t*>(col);
+@@ -644,16 +679,33 @@ row_merge_buf_add(
+ continue;
+ }
+
+- ptr = ut_malloc_nokey(sizeof(*doc_item)
+- + field->len);
++ /* Layout of the doc_item allocation:
++ [fts_doc_item_t][dfield_t][field bytes]
++ The embedded dfield_t keeps doc_item->field
++ valid until the consumer frees doc_item, so we
++ no longer have to keep the dfield_t alive in
++ buf->heap (which is what caused the unbounded
++ growth of memory/innodb/mem0mem during FTS
++ builds). */
++ const ulint doc_item_size =
++ sizeof(*doc_item) + sizeof(dfield_t)
++ + field->len;
++
++ ptr = ut_malloc_nokey(doc_item_size);
+
+ doc_item = static_cast<fts_doc_item_t*>(ptr);
++ dfield_t* persistent_field =
++ reinterpret_cast<dfield_t*>(
++ static_cast<byte*>(ptr)
++ + sizeof(*doc_item));
++ *persistent_field = *field;
+ value = static_cast<byte*>(ptr)
+- + sizeof(*doc_item);
++ + sizeof(*doc_item)
++ + sizeof(dfield_t);
+ memcpy(value, field->data, field->len);
+- field->data = value;
++ persistent_field->data = value;
+
+- doc_item->field = field;
++ doc_item->field = persistent_field;
+ doc_item->doc_id = *doc_id;
+
+ bucket = *doc_id % fts_sort_pll_degree;
+@@ -666,17 +718,27 @@ row_merge_buf_add(
+ psort_info[bucket].fts_doc_list,
+ doc_item);
+ psort_info[bucket].memory_used +=
+- sizeof(*doc_item) + field->len;
++ doc_item_size;
+ } else {
+ ut_free(doc_item);
+ }
+
+ mutex_exit(&psort_info[bucket].mutex);
+
+- /* Sleep when memory used exceeds limit*/
++ /* Sleep when memory used exceeds limit. The
++ loop also checks for DDL cancellation on every
++ iteration so a KILL issued against the scan
++ thread is honoured within ~1 ms instead of
++ being delayed by up to max_trial_count
++ milliseconds (i.e. ~10 s per row) when the
++ tokenization consumers are slow or stuck. */
+ while (psort_info[bucket].memory_used
+ > FTS_PENDING_DOC_MEMORY_LIMIT
+ && trial_count++ < max_trial_count) {
++ if (UNIV_UNLIKELY(
++ trx_is_interrupted(trx))) {
++ break;
++ }
+ os_thread_sleep(1000);
+ }
+
diff --git a/mysql-fts-sync-concurrency.patch b/mysql-fts-sync-concurrency.patch
new file mode 100644
index 0000000..8878c37
--- /dev/null
+++ b/mysql-fts-sync-concurrency.patch
@@ -0,0 +1,111 @@
+Inconsistent FTS state in concurrent scenarios (Bug#34929814,
+Bug#36347647)
+https://github.com/percona/percona-server/commit/5da6a5a0f3
+
+--- mysql-5.7.44.orig/storage/innobase/fts/fts0fts.cc
++++ mysql-5.7.44/storage/innobase/fts/fts0fts.cc
+@@ -2777,7 +2777,7 @@ fts_get_next_doc_id(
+ This function fetch the Doc ID from CONFIG table, and compare with
+ the Doc ID supplied. And store the larger one to the CONFIG table.
+ @return DB_SUCCESS if OK */
+-static MY_ATTRIBUTE((nonnull))
++static
+ dberr_t
+ fts_cmp_set_sync_doc_id(
+ /*====================*/
+@@ -2785,18 +2785,22 @@ fts_cmp_set_sync_doc_id(
+ doc_id_t doc_id_cmp, /*!< in: Doc ID to compare */
+ ibool read_only, /*!< in: TRUE if read the
+ synced_doc_id only */
+- doc_id_t* doc_id) /*!< out: larger document id
++ doc_id_t* doc_id, /*!< out: larger document id
+ after comparing "doc_id_cmp"
+ to the one stored in CONFIG
+ table */
++ trx_t* trx = NULL) /*!< in: transaction in which
++ the doc_id is retrieved and
++ stored */
+ {
+- trx_t* trx;
+ pars_info_t* info;
+ dberr_t error;
+ fts_table_t fts_table;
+ que_t* graph = NULL;
+ fts_cache_t* cache = table->fts->cache;
+ char table_name[MAX_FULL_NAME_LEN];
++ bool trx_allocated;
++ trx_savept_t savept;
+ retry:
+ ut_a(table->fts->doc_col != ULINT_UNDEFINED);
+
+@@ -2807,7 +2811,13 @@ retry:
+
+ fts_table.parent = table->name.m_name;
+
+- trx = trx_allocate_for_background();
++ trx_allocated = false;
++ if (trx == NULL) {
++ trx = trx_allocate_for_background();
++ trx_allocated = true;
++ } else {
++ savept = trx_savept_take(trx);
++ }
+
+ trx->op_info = "update the next FTS document id";
+
+@@ -2874,21 +2884,34 @@ retry:
+ func_exit:
+
+ if (error == DB_SUCCESS) {
+- fts_sql_commit(trx);
++ if (trx_allocated) {
++ fts_sql_commit(trx);
++ }
+ } else {
+ *doc_id = 0;
+
+ ib::error() << "(" << ut_strerr(error) << ") while getting"
+ " next doc id.";
+- fts_sql_rollback(trx);
++ if (trx_allocated) {
++ fts_sql_rollback(trx);
++ } else {
++ trx_rollback_to_savepoint(trx, &savept);
++ }
+
+ if (error == DB_DEADLOCK) {
+ os_thread_sleep(FTS_DEADLOCK_RETRY_WAIT);
++ if (trx_allocated) {
++ /* free trx before retry */
++ trx_free_for_background(trx);
++ trx = NULL;
++ }
+ goto retry;
+ }
+ }
+
+- trx_free_for_background(trx);
++ if (trx_allocated) {
++ trx_free_for_background(trx);
++ }
+
+ return(error);
+ }
+@@ -4617,7 +4640,7 @@ fts_sync_commit(
+ /* After each Sync, update the CONFIG table about the max doc id
+ we just sync-ed to index table */
+ error = fts_cmp_set_sync_doc_id(sync->table, sync->max_doc_id, FALSE,
+- &last_doc_id);
++ &last_doc_id, trx);
+
+ /* Get the list of deleted documents that are either in the
+ cache or were headed there but were deleted before the add
+@@ -4637,7 +4660,7 @@ fts_sync_commit(
+ rw_lock_x_unlock(&cache->lock);
+
+ if (error == DB_SUCCESS) {
+-
++ DBUG_EXECUTE_IF("fts_crash_before_commit_sync", { DBUG_SUICIDE(); });
+ fts_sql_commit(trx);
+
+ } else if (error != DB_SUCCESS) {
diff --git a/mysql-geofunc-uaf.patch b/mysql-geofunc-uaf.patch
new file mode 100644
index 0000000..cd76060
--- /dev/null
+++ b/mysql-geofunc-uaf.patch
@@ -0,0 +1,35 @@
+MySQL server heap-use-after-free at int my_mb_wc_utf8_prototype
+(Bug#36593253)
+https://github.com/percona/percona-server/commit/c069e6ec52
+https://github.com/mysql/mysql-server/commit/0491d9b4d93
+
+--- mysql-5.7.44.orig/sql/item_geofunc.cc
++++ mysql-5.7.44/sql/item_geofunc.cc
+@@ -2875,9 +2875,15 @@ String *Item_func_convex_hull::val_str(String *str)
+ // str points to another buffer in next call of this function
+ // (done in post_fix_result), or when str's owner Item_xxx node is destroyed.
+ if (geom->get_type() == Geometry::wkb_point)
++ {
+ str->takeover(*swkb);
+-
+- return str;
++ return str;
++ }
++ // Return a different String pointer than the input argument. This shows our
++ // callers, in particular in_string::set(), that the result is not stored or
++ // maintained by 'str' and may need to be copied.
++ tmp_value.set(str->ptr(), str->length(), &my_charset_bin);
++ return &tmp_value;
+ }
+
+
+--- mysql-5.7.44.orig/sql/item_geofunc.h
++++ mysql-5.7.44/sql/item_geofunc.h
+@@ -461,6 +461,7 @@ public:
+ class Item_func_convex_hull: public Item_geometry_func
+ {
+ BG_result_buf_mgr bg_resbuf_mgr;
++ String tmp_value;
+
+ template <typename Coordsys>
+ bool bg_convex_hull(const Geometry *geom, String *wkb);
diff --git a/mysql-getopt-help-overrun.patch b/mysql-getopt-help-overrun.patch
new file mode 100644
index 0000000..eacb2fd
--- /dev/null
+++ b/mysql-getopt-help-overrun.patch
@@ -0,0 +1,33 @@
+buffer overrun in my_print_help (Bug#36615714)
+https://github.com/percona/percona-server/commit/bf49235811
+https://github.com/mysql/mysql-server/commit/6e08d4427fc
+
+--- mysql-5.7.44.orig/mysys_ssl/my_getopt.cc
++++ mysql-5.7.44/mysys_ssl/my_getopt.cc
+@@ -1488,11 +1488,24 @@ void my_print_help(const struct my_option *options)
+
+ while ((uint) (end - comment) > comment_space)
+ {
+- for (line_end= comment + comment_space; *line_end != ' '; line_end--)
++ bool had_space;
++ // find the last space before the limit to break the comment on
++ for (line_end= comment + comment_space;
++ line_end > comment && *line_end != ' ';
++ line_end--)
+ {}
++ // if no space is found break at the limit - 1 (for the new line)
++ if (line_end == comment && *comment != ' ')
++ {
++ line_end = comment + comment_space - 1;
++ had_space = false;
++ }
++ else
++ had_space = true;
+ for (; comment != line_end; comment++)
+ putchar(*comment);
+- comment++; /* skip the space, as a newline will take it's place now */
++ if (had_space)
++ comment++; /* skip the space, as a newline will take it's place now */
+ putchar('\n');
+ for (col= 0; col < name_space; col++)
+ putchar(' ');
diff --git a/mysql-gis-temp-bulk-insert.patch b/mysql-gis-temp-bulk-insert.patch
new file mode 100644
index 0000000..43735cf
--- /dev/null
+++ b/mysql-gis-temp-bulk-insert.patch
@@ -0,0 +1,17 @@
+Bulk inserts into temporary tables with GIS indexes will inevitably
+cause crashes (Bug#38208188)
+https://github.com/percona/percona-server/commit/2de5d80b4d
+https://github.com/mysql/mysql-server/commit/d338ba09220
+
+--- mysql-5.7.44.orig/storage/innobase/row/row0ins.cc
++++ mysql-5.7.44/storage/innobase/row/row0ins.cc
+@@ -2988,6 +2988,9 @@ row_ins_sec_index_entry_low(
+ rtr_info_update_btr(&cursor, &rtr_info);
+ mtr_start(&mtr);
+ mtr.set_named_space(index->space);
++ if (dict_table_is_temporary(index->table)) {
++ mtr.set_log_mode(MTR_LOG_NO_REDO);
++ }
+ search_mode &= ~BTR_MODIFY_LEAF;
+ search_mode |= BTR_MODIFY_TREE;
+ btr_cur_search_to_nth_level(
diff --git a/mysql-gr-applier-validate.patch b/mysql-gr-applier-validate.patch
new file mode 100644
index 0000000..4f08940
--- /dev/null
+++ b/mysql-gr-applier-validate.patch
@@ -0,0 +1,47 @@
+MySQL Group Replication applier pipeline validations (Bug#38712932)
+https://github.com/percona/percona-server/commit/3c967ac40b
+https://github.com/mysql/mysql-server/commit/1c7b3e6e
+
+--- mysql-5.7.44.orig/rapid/plugin/group_replication/include/pipeline_interfaces.h
++++ mysql-5.7.44/rapid/plugin/group_replication/include/pipeline_interfaces.h
+@@ -330,6 +330,20 @@ private:
+ const char *errmsg = 0;
+
+ uint event_len= uint4korr(((uchar*)(packet->payload)) + EVENT_LEN_OFFSET);
++
++ DBUG_EXECUTE_IF("group_replication_pipeline_force_invalid_event_length",
++ { event_len= packet->len + 1; });
++
++ if (event_len > packet->len)
++ {
++ log_message(MY_ERROR_LEVEL,
++ "Unable to convert a packet into an event on the applier!"
++ " Error: invalid event length."); /* purecov: inspected */
++ delete packet; /* purecov: inspected */
++ packet= NULL; /* purecov: inspected */
++ return 1; /* purecov: inspected */
++ }
++
+ log_event= Log_event::read_log_event((const char*)packet->payload, event_len,
+ &errmsg, format_descriptor, TRUE);
+
+--- mysql-5.7.44.orig/rapid/plugin/group_replication/src/applier.cc
++++ mysql-5.7.44/rapid/plugin/group_replication/src/applier.cc
+@@ -320,6 +320,17 @@ int Applier_module::apply_data_packet(Data_packet *data_packet,
+ {
+ uint event_len= uint4korr(((uchar*)payload) + EVENT_LEN_OFFSET);
+
++ DBUG_EXECUTE_IF("group_replication_applier_force_invalid_event_length",
++ { event_len= data_packet->len + 1; });
++
++ if (event_len > data_packet->len)
++ {
++ log_message(MY_ERROR_LEVEL,
++ "Invalid event length while applying data packet on group "
++ "replication applier pipeline."); /* purecov: inspected */
++ return 1; /* purecov: inspected */
++ }
++
+ Data_packet* new_packet= new Data_packet(payload, event_len);
+ payload= payload + event_len;
+
diff --git a/mysql-gr-certifier-gtid-set.patch b/mysql-gr-certifier-gtid-set.patch
new file mode 100644
index 0000000..306b056
--- /dev/null
+++ b/mysql-gr-certifier-gtid-set.patch
@@ -0,0 +1,220 @@
+Signal 11 seen in Gtid_set::~Gtid_set (Bug#36093405)
+https://github.com/percona/percona-server/commit/fc97c78001
+https://github.com/mysql/mysql-server/commit/6467f70f615
+
+--- mysql-5.7.44.orig/rapid/plugin/group_replication/include/certifier.h
++++ mysql-5.7.44/rapid/plugin/group_replication/include/certifier.h
+@@ -433,7 +433,7 @@ private:
+ /**
+ Is certifier initialized.
+ */
+- bool initialized;
++ int32 initialized;
+
+ /**
+ Variable to store the sidno used for transactions which will be logged
+@@ -540,7 +540,7 @@ private:
+
+ bool inline is_initialized()
+ {
+- return initialized;
++ return my_atomic_load32(&initialized);
+ }
+
+ void clear_certification_info();
+--- mysql-5.7.44.orig/rapid/plugin/group_replication/src/certifier.cc
++++ mysql-5.7.44/rapid/plugin/group_replication/src/certifier.cc
+@@ -255,8 +255,7 @@ int Certifier_broadcast_thread::broadcast_gtid_executed()
+
+
+ Certifier::Certifier()
+- :initialized(false),
+- positive_cert(0), negative_cert(0),
++ :positive_cert(0), negative_cert(0),
+ parallel_applier_last_committed_global(1),
<Skipped 5224 lines>
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/mysql.git/commitdiff/8670471c4ee390a70934c3ee30adeb1369b8d7dd
More information about the pld-cvs-commit
mailing list