From 48c7dfee536cb6e937fd0ad71a734d26c13a6bc0 Mon Sep 17 00:00:00 2001 From: Akshat Nehra Date: Mon, 29 Sep 2025 20:42:39 +0000 Subject: [PATCH] Bug#119037 Fix OOM during MySQL upgrade with large number of tables Commit 7c0dda9 introduced a new function called check_table_funs which validates SQL functions in table definitions during database upgrades. However, this function has a unbounded memory usage issue where tables opened for validation are not closed afterward. For databases with large numbers of tables, this causes memory consumption to grow unbounded until the server runs out of memory and is terminated by the OOM killer. This patch fixes the issue by closing each table immediately after its validation is complete by calling close_thread_table. This ensures stable memory usage throughout the upgrade process, allowing successful upgrades of databases with any number of tables. This contribution is under the OCA signed by Amazon and covering submissions to the MySQL project. --- sql/dd/impl/upgrade/server.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sql/dd/impl/upgrade/server.cc b/sql/dd/impl/upgrade/server.cc index 3082524d1a24..4dca0f99ac36 100644 --- a/sql/dd/impl/upgrade/server.cc +++ b/sql/dd/impl/upgrade/server.cc @@ -826,6 +826,10 @@ static bool check_table_funs(THD *thd, std::unique_ptr &schema, // increase global error count if (opt_check_table_funs == CHECK_TABLE_FUN_ABORT) (*error_count)++; } + + // Close table after checking for error to avoid OOM during upgrade + if (thd->open_tables != nullptr) + close_thread_table(thd, &thd->open_tables); } return error_count->has_too_many_errors();