Commit 7a12894d authored by Igor Babaev's avatar Igor Babaev

Fixed the bug mdev12992.

When the SELECT query from a trigger that used a subquery
in its SELECT list was prepared the counter select_n_having_items
was incremented in the constructor Item::Item(THD *thd).
As a result each invocation of the trigger required more and more
memory for the ref_pointer_array for this SELECT.
Made sure that the counter st_select_lex::select_n_having_items
would be incremented only at the first execution of such trigger.
parent b175c41c
......@@ -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;
......@@ -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;
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment