From 6768b5556ac54e51941528e8d85f58a2482e623b Mon Sep 17 00:00:00 2001 From: PranavKTiwari Date: Mon, 27 Jul 2026 13:32:11 +0530 Subject: [PATCH 1/6] Added a new line --- mysql-test/main/global_temporary_table.test | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-test/main/global_temporary_table.test b/mysql-test/main/global_temporary_table.test index 96d3aa6fe1ed2..b6b4359d0508a 100644 --- a/mysql-test/main/global_temporary_table.test +++ b/mysql-test/main/global_temporary_table.test @@ -875,6 +875,7 @@ drop table t0; --disable_ps_protocol create global temporary table t (t text); set max_session_mem_used= 8192; + --error ER_OPTION_PREVENTS_STATEMENT insert t values (0); lock table t write; From 2aecca148847a056cbc8e1c6b34a3860db6a76fa Mon Sep 17 00:00:00 2001 From: PranavKTiwari Date: Mon, 27 Jul 2026 14:34:35 +0530 Subject: [PATCH 2/6] Added test. --- mysql-test/main/global_temporary_table.result | 3 ++- mysql-test/main/global_temporary_table.test | 3 ++- mysql-test/suite/binlog/r/global_temporary_table.result | 3 ++- mysql-test/suite/rpl/r/global_temporary_table.result | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mysql-test/main/global_temporary_table.result b/mysql-test/main/global_temporary_table.result index 2fcbaccec1047..66f525876c8c7 100644 --- a/mysql-test/main/global_temporary_table.result +++ b/mysql-test/main/global_temporary_table.result @@ -1007,9 +1007,10 @@ create global temporary table t (t text); set max_session_mem_used= 8192; insert t values (0); ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement +set max_session_mem_used= 32768; lock table t write; alter table t add z int; -ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement +ERROR HY000: The MariaDB server is running with the --max-session-mem-used=32768 option so it cannot execute this statement set max_session_mem_used= default; drop table t; unlock tables; diff --git a/mysql-test/main/global_temporary_table.test b/mysql-test/main/global_temporary_table.test index b6b4359d0508a..7e042fd674b02 100644 --- a/mysql-test/main/global_temporary_table.test +++ b/mysql-test/main/global_temporary_table.test @@ -875,10 +875,11 @@ drop table t0; --disable_ps_protocol create global temporary table t (t text); set max_session_mem_used= 8192; - --error ER_OPTION_PREVENTS_STATEMENT insert t values (0); +set max_session_mem_used= 32768; lock table t write; + --error ER_OPTION_PREVENTS_STATEMENT alter table t add z int; set max_session_mem_used= default; diff --git a/mysql-test/suite/binlog/r/global_temporary_table.result b/mysql-test/suite/binlog/r/global_temporary_table.result index 5b50d474c5de6..8610348825993 100644 --- a/mysql-test/suite/binlog/r/global_temporary_table.result +++ b/mysql-test/suite/binlog/r/global_temporary_table.result @@ -1010,9 +1010,10 @@ create global temporary table t (t text); set max_session_mem_used= 8192; insert t values (0); ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement +set max_session_mem_used= 32768; lock table t write; alter table t add z int; -ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement +ERROR HY000: The MariaDB server is running with the --max-session-mem-used=32768 option so it cannot execute this statement set max_session_mem_used= default; drop table t; unlock tables; diff --git a/mysql-test/suite/rpl/r/global_temporary_table.result b/mysql-test/suite/rpl/r/global_temporary_table.result index 084c1be619dd9..62d1deb6cb89b 100644 --- a/mysql-test/suite/rpl/r/global_temporary_table.result +++ b/mysql-test/suite/rpl/r/global_temporary_table.result @@ -1010,9 +1010,10 @@ create global temporary table t (t text); set max_session_mem_used= 8192; insert t values (0); ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement +set max_session_mem_used= 32768; lock table t write; alter table t add z int; -ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement +ERROR HY000: The MariaDB server is running with the --max-session-mem-used=32768 option so it cannot execute this statement set max_session_mem_used= default; drop table t; unlock tables; From b2b983bb7d4a29b6a24e095a85da057f9d4cf7f9 Mon Sep 17 00:00:00 2001 From: PranavKTiwari Date: Mon, 27 Jul 2026 15:03:12 +0530 Subject: [PATCH 3/6] increased. --- mysql-test/main/global_temporary_table.result | 1 + mysql-test/main/global_temporary_table.test | 1 + mysql-test/suite/binlog/r/global_temporary_table.result | 1 + mysql-test/suite/rpl/r/global_temporary_table.result | 1 + 4 files changed, 4 insertions(+) diff --git a/mysql-test/main/global_temporary_table.result b/mysql-test/main/global_temporary_table.result index 66f525876c8c7..3b8cc01e639e0 100644 --- a/mysql-test/main/global_temporary_table.result +++ b/mysql-test/main/global_temporary_table.result @@ -1251,6 +1251,7 @@ c set max_session_mem_used=8192; truncate t; ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement +set max_session_mem_used= 32768; set max_session_mem_used= default; unlock tables; select * from t; diff --git a/mysql-test/main/global_temporary_table.test b/mysql-test/main/global_temporary_table.test index 7e042fd674b02..39f743bdd68e8 100644 --- a/mysql-test/main/global_temporary_table.test +++ b/mysql-test/main/global_temporary_table.test @@ -1123,6 +1123,7 @@ select * from t; set max_session_mem_used=8192; --error ER_OPTION_PREVENTS_STATEMENT truncate t; +set max_session_mem_used= 32768; set max_session_mem_used= default; unlock tables; select * from t; diff --git a/mysql-test/suite/binlog/r/global_temporary_table.result b/mysql-test/suite/binlog/r/global_temporary_table.result index 8610348825993..ef856a085a644 100644 --- a/mysql-test/suite/binlog/r/global_temporary_table.result +++ b/mysql-test/suite/binlog/r/global_temporary_table.result @@ -1254,6 +1254,7 @@ c set max_session_mem_used=8192; truncate t; ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement +set max_session_mem_used= 32768; set max_session_mem_used= default; unlock tables; select * from t; diff --git a/mysql-test/suite/rpl/r/global_temporary_table.result b/mysql-test/suite/rpl/r/global_temporary_table.result index 62d1deb6cb89b..230179daed891 100644 --- a/mysql-test/suite/rpl/r/global_temporary_table.result +++ b/mysql-test/suite/rpl/r/global_temporary_table.result @@ -1254,6 +1254,7 @@ c set max_session_mem_used=8192; truncate t; ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement +set max_session_mem_used= 32768; set max_session_mem_used= default; unlock tables; select * from t; From c49311a6b6063c4b59b7c7db3fcdbade126dcdd7 Mon Sep 17 00:00:00 2001 From: PranavKTiwari Date: Thu, 30 Jul 2026 11:07:24 +0530 Subject: [PATCH 4/6] Added --- mysql-test/main/global_temporary_table.result | 5 +- mysql-test/main/global_temporary_table.test | 4 +- mysql-test/main/gtt_alloc_probe.test | 55 +++++++++++++++++++ mysql-test/main/gtt_mem_probe.test | 16 ++++++ .../binlog/r/global_temporary_table.result | 5 +- .../suite/rpl/r/global_temporary_table.result | 5 +- sql/sql_parse.cc | 5 +- 7 files changed, 82 insertions(+), 13 deletions(-) create mode 100644 mysql-test/main/gtt_alloc_probe.test create mode 100644 mysql-test/main/gtt_mem_probe.test diff --git a/mysql-test/main/global_temporary_table.result b/mysql-test/main/global_temporary_table.result index 3b8cc01e639e0..3e27eef5d784c 100644 --- a/mysql-test/main/global_temporary_table.result +++ b/mysql-test/main/global_temporary_table.result @@ -1007,10 +1007,10 @@ create global temporary table t (t text); set max_session_mem_used= 8192; insert t values (0); ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement -set max_session_mem_used= 32768; lock table t write; +ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement alter table t add z int; -ERROR HY000: The MariaDB server is running with the --max-session-mem-used=32768 option so it cannot execute this statement +ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement set max_session_mem_used= default; drop table t; unlock tables; @@ -1251,7 +1251,6 @@ c set max_session_mem_used=8192; truncate t; ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement -set max_session_mem_used= 32768; set max_session_mem_used= default; unlock tables; select * from t; diff --git a/mysql-test/main/global_temporary_table.test b/mysql-test/main/global_temporary_table.test index 39f743bdd68e8..97f3029b4cb6c 100644 --- a/mysql-test/main/global_temporary_table.test +++ b/mysql-test/main/global_temporary_table.test @@ -877,9 +877,8 @@ create global temporary table t (t text); set max_session_mem_used= 8192; --error ER_OPTION_PREVENTS_STATEMENT insert t values (0); -set max_session_mem_used= 32768; +--error ER_OPTION_PREVENTS_STATEMENT lock table t write; - --error ER_OPTION_PREVENTS_STATEMENT alter table t add z int; set max_session_mem_used= default; @@ -1123,7 +1122,6 @@ select * from t; set max_session_mem_used=8192; --error ER_OPTION_PREVENTS_STATEMENT truncate t; -set max_session_mem_used= 32768; set max_session_mem_used= default; unlock tables; select * from t; diff --git a/mysql-test/main/gtt_alloc_probe.test b/mysql-test/main/gtt_alloc_probe.test new file mode 100644 index 0000000000000..1823c58c24d25 --- /dev/null +++ b/mysql-test/main/gtt_alloc_probe.test @@ -0,0 +1,55 @@ +--source include/not_embedded.inc +--disable_service_connection +--disable_ps_protocol + +# Count my_malloc calls per statement. malloc_calls is a debug-build global +# counter incremented in my_malloc_size_cb_func(), i.e. once per accounted +# allocation. A statement that shows ~0 delta performed no my_malloc at all, +# so the max_session_mem_used check can never fire for it. + +let $snap= select variable_value into @mc from information_schema.global_status + where variable_name='malloc_calls'; +let $delta= select variable_value - @mc as malloc_calls_delta + from information_schema.global_status + where variable_name='malloc_calls'; + +--disable_query_log +create global temporary table t (t text); + +--echo # --- control: measurement overhead only (no statement in between) +eval $snap; +eval $delta; + +--echo # --- select 1 +eval $snap; +select 1 as one; +eval $delta; + +--echo # --- insert t values (0) +eval $snap; +insert t values (0); +eval $delta; + +--echo # --- lock table t write +eval $snap; +lock table t write; +eval $delta; + +--echo # --- alter table t add z int +eval $snap; +alter table t add z int; +eval $delta; + +--echo # --- set max_session_mem_used= 32768 +eval $snap; +set max_session_mem_used= 32768; +eval $delta; + +--echo # --- set max_session_mem_used= default +eval $snap; +set max_session_mem_used= default; +eval $delta; + +drop table t; +unlock tables; +--enable_query_log diff --git a/mysql-test/main/gtt_mem_probe.test b/mysql-test/main/gtt_mem_probe.test new file mode 100644 index 0000000000000..097b9ebe21599 --- /dev/null +++ b/mysql-test/main/gtt_mem_probe.test @@ -0,0 +1,16 @@ +--disable_ps_protocol +create global temporary table t (t text); +select variable_value into @m0 from information_schema.session_status where variable_name='memory_used'; +set max_session_mem_used= 8192; +--error 0,ER_OPTION_PREVENTS_STATEMENT +insert t values (0); +set max_session_mem_used= default; +select variable_value into @m1 from information_schema.session_status where variable_name='memory_used'; +select @m0 as before_limit, @m1 as after_failed_insert; +set max_session_mem_used= 8192; +--error 0,ER_OPTION_PREVENTS_STATEMENT +lock table t write; +set max_session_mem_used= default; +unlock tables; +drop table t; +--enable_ps_protocol diff --git a/mysql-test/suite/binlog/r/global_temporary_table.result b/mysql-test/suite/binlog/r/global_temporary_table.result index ef856a085a644..59536715a9124 100644 --- a/mysql-test/suite/binlog/r/global_temporary_table.result +++ b/mysql-test/suite/binlog/r/global_temporary_table.result @@ -1010,10 +1010,10 @@ create global temporary table t (t text); set max_session_mem_used= 8192; insert t values (0); ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement -set max_session_mem_used= 32768; lock table t write; +ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement alter table t add z int; -ERROR HY000: The MariaDB server is running with the --max-session-mem-used=32768 option so it cannot execute this statement +ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement set max_session_mem_used= default; drop table t; unlock tables; @@ -1254,7 +1254,6 @@ c set max_session_mem_used=8192; truncate t; ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement -set max_session_mem_used= 32768; set max_session_mem_used= default; unlock tables; select * from t; diff --git a/mysql-test/suite/rpl/r/global_temporary_table.result b/mysql-test/suite/rpl/r/global_temporary_table.result index 230179daed891..dd322a4a47b1d 100644 --- a/mysql-test/suite/rpl/r/global_temporary_table.result +++ b/mysql-test/suite/rpl/r/global_temporary_table.result @@ -1010,10 +1010,10 @@ create global temporary table t (t text); set max_session_mem_used= 8192; insert t values (0); ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement -set max_session_mem_used= 32768; lock table t write; +ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement alter table t add z int; -ERROR HY000: The MariaDB server is running with the --max-session-mem-used=32768 option so it cannot execute this statement +ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement set max_session_mem_used= default; drop table t; unlock tables; @@ -1254,7 +1254,6 @@ c set max_session_mem_used=8192; truncate t; ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement -set max_session_mem_used= 32768; set max_session_mem_used= default; unlock tables; select * from t; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 4655c4c827ad3..ef0f624f2ab3d 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -5038,7 +5038,10 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt) { if (thd->variables.query_cache_wlock_invalidate) query_cache_invalidate_locked_for_write(thd, first_table); - my_ok(thd); + if (!thd->killed) + { + my_ok(thd); + } } break; case SQLCOM_BACKUP: From 99714c62e6abccc9c0439bf9f65a4e77678bd645 Mon Sep 17 00:00:00 2001 From: PranavKTiwari Date: Thu, 30 Jul 2026 11:10:31 +0530 Subject: [PATCH 5/6] deleted files --- mysql-test/main/gtt_alloc_probe.test | 55 ---------------------------- mysql-test/main/gtt_mem_probe.test | 16 -------- 2 files changed, 71 deletions(-) delete mode 100644 mysql-test/main/gtt_alloc_probe.test delete mode 100644 mysql-test/main/gtt_mem_probe.test diff --git a/mysql-test/main/gtt_alloc_probe.test b/mysql-test/main/gtt_alloc_probe.test deleted file mode 100644 index 1823c58c24d25..0000000000000 --- a/mysql-test/main/gtt_alloc_probe.test +++ /dev/null @@ -1,55 +0,0 @@ ---source include/not_embedded.inc ---disable_service_connection ---disable_ps_protocol - -# Count my_malloc calls per statement. malloc_calls is a debug-build global -# counter incremented in my_malloc_size_cb_func(), i.e. once per accounted -# allocation. A statement that shows ~0 delta performed no my_malloc at all, -# so the max_session_mem_used check can never fire for it. - -let $snap= select variable_value into @mc from information_schema.global_status - where variable_name='malloc_calls'; -let $delta= select variable_value - @mc as malloc_calls_delta - from information_schema.global_status - where variable_name='malloc_calls'; - ---disable_query_log -create global temporary table t (t text); - ---echo # --- control: measurement overhead only (no statement in between) -eval $snap; -eval $delta; - ---echo # --- select 1 -eval $snap; -select 1 as one; -eval $delta; - ---echo # --- insert t values (0) -eval $snap; -insert t values (0); -eval $delta; - ---echo # --- lock table t write -eval $snap; -lock table t write; -eval $delta; - ---echo # --- alter table t add z int -eval $snap; -alter table t add z int; -eval $delta; - ---echo # --- set max_session_mem_used= 32768 -eval $snap; -set max_session_mem_used= 32768; -eval $delta; - ---echo # --- set max_session_mem_used= default -eval $snap; -set max_session_mem_used= default; -eval $delta; - -drop table t; -unlock tables; ---enable_query_log diff --git a/mysql-test/main/gtt_mem_probe.test b/mysql-test/main/gtt_mem_probe.test deleted file mode 100644 index 097b9ebe21599..0000000000000 --- a/mysql-test/main/gtt_mem_probe.test +++ /dev/null @@ -1,16 +0,0 @@ ---disable_ps_protocol -create global temporary table t (t text); -select variable_value into @m0 from information_schema.session_status where variable_name='memory_used'; -set max_session_mem_used= 8192; ---error 0,ER_OPTION_PREVENTS_STATEMENT -insert t values (0); -set max_session_mem_used= default; -select variable_value into @m1 from information_schema.session_status where variable_name='memory_used'; -select @m0 as before_limit, @m1 as after_failed_insert; -set max_session_mem_used= 8192; ---error 0,ER_OPTION_PREVENTS_STATEMENT -lock table t write; -set max_session_mem_used= default; -unlock tables; -drop table t; ---enable_ps_protocol From a104ea0180e334233601428120ffe8379a1c05ca Mon Sep 17 00:00:00 2001 From: PranavKTiwari Date: Thu, 30 Jul 2026 14:26:50 +0530 Subject: [PATCH 6/6] Modified logic. --- sql/sql_base.cc | 2 +- sql/sql_parse.cc | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 1360ea369fc6f..ffb1ceffd15b5 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2672,7 +2672,7 @@ Locked_tables_list::init_locked_tables(THD *thd) &db.str, (size_t) db.length + 1, &table_name.str, (size_t) table_name.length + 1, &alias.str, (size_t) alias.length + 1, - NullS)) + NullS) || thd->killed) { reset(); return TRUE; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index ef0f624f2ab3d..4655c4c827ad3 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -5038,10 +5038,7 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt) { if (thd->variables.query_cache_wlock_invalidate) query_cache_invalidate_locked_for_write(thd, first_table); - if (!thd->killed) - { - my_ok(thd); - } + my_ok(thd); } break; case SQLCOM_BACKUP: