summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/trigger.result11
-rw-r--r--mysql-test/t/trigger.test24
-rw-r--r--sql/item.cc3
3 files changed, 37 insertions, 1 deletions
diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result
index e6c8f6a5e2f..24a914663b7 100644
--- a/mysql-test/r/trigger.result
+++ b/mysql-test/r/trigger.result
@@ -2368,3 +2368,14 @@ tr1 1 2016-01-01 10:10:10.33
tr2 2 2016-01-01 10:10:10.99
drop table t1;
set time_zone= @@global.time_zone;
+#
+# MDEV-12992: Increasing memory consumption
+with each invocation of trigger
+#
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1);
+CREATE TABLE t2 (b INT);
+CREATE TRIGGER tr
+AFTER UPDATE ON t1 FOR EACH ROW SELECT (SELECT b FROM t2) INTO @x;
+# Running 20000 queries
+DROP TABLE t1,t2;
diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test
index 83b6966c676..5c65e3dd13b 100644
--- a/mysql-test/t/trigger.test
+++ b/mysql-test/t/trigger.test
@@ -2676,3 +2676,27 @@ select trigger_name, action_order, created from information_schema.triggers
where event_object_table = 't1' and trigger_schema='test';
drop table t1;
set time_zone= @@global.time_zone;
+
+--echo #
+--echo # MDEV-12992: Increasing memory consumption
+--echo with each invocation of trigger
+--echo #
+
+--let $n= 20000
+
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1);
+CREATE TABLE t2 (b INT);
+CREATE TRIGGER tr
+ AFTER UPDATE ON t1 FOR EACH ROW SELECT (SELECT b FROM t2) INTO @x;
+
+--disable_query_log
+--echo # Running $n queries
+while ($n)
+{
+ UPDATE t1 SET a = 2;
+ --dec $n
+}
+--enable_query_log
+
+DROP TABLE t1,t2;
diff --git a/sql/item.cc b/sql/item.cc
index a130cfdc0f2..afdef1ac57c 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -490,7 +490,8 @@ Item::Item(THD *thd):
command => we should check thd->lex->current_select on zero (thd->lex
can be uninitialised)
*/
- if (thd->lex->current_select)
+ if (thd->lex->current_select &&
+ thd->stmt_arena->is_stmt_prepare_or_first_sp_execute())
{
enum_parsing_place place=
thd->lex->current_select->parsing_place;