summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/trigger.result44
-rw-r--r--mysql-test/t/trigger.test40
-rw-r--r--sql/item_subselect.cc3
3 files changed, 85 insertions, 2 deletions
diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result
index 479778deca3..9cf769983c6 100644
--- a/mysql-test/r/trigger.result
+++ b/mysql-test/r/trigger.result
@@ -2134,3 +2134,47 @@ i
2
drop table t1,t2;
End of 5.2 tests.
+#
+# BUG #910083: materialized subquery in a trigger
+#
+SET @save_optimizer_switch=@@optimizer_switch;
+SET optimizer_switch='materialization=on';
+CREATE TABLE t1 (a int);
+CREATE TABLE t2 (b int);
+CREATE TRIGGER tr AFTER UPDATE ON t1 FOR EACH ROW
+UPDATE t2 SET b = (SELECT COUNT(a) FROM t1);
+INSERT INTO t1
+VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9);
+INSERT INTO t2
+VALUES (0),(0),(0),(0),(0),(0),(0),(0),(0);
+UPDATE t1 SET a = 3;
+SELECT COUNT(*) FROM t1;
+COUNT(*)
+9
+SELECT * FROM t2;
+b
+9
+9
+9
+9
+9
+9
+9
+9
+9
+UPDATE t1 SET a = 2;
+SELECT * FROM t2;
+b
+9
+9
+9
+9
+9
+9
+9
+9
+9
+SET optimizer_switch=@save_optimizer_switch;
+DROP TRIGGER tr;
+DROP TABLE t1, t2;
+End of 5.3 tests.
diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test
index 8d84330ec44..4b261c9f023 100644
--- a/mysql-test/t/trigger.test
+++ b/mysql-test/t/trigger.test
@@ -2434,3 +2434,43 @@ select * from t2;
drop table t1,t2;
--echo End of 5.2 tests.
+
+--echo #
+--echo # BUG #910083: materialized subquery in a trigger
+--echo #
+
+SET @save_optimizer_switch=@@optimizer_switch;
+SET optimizer_switch='materialization=on';
+
+CREATE TABLE t1 (a int);
+CREATE TABLE t2 (b int);
+
+CREATE TRIGGER tr AFTER UPDATE ON t1 FOR EACH ROW
+ UPDATE t2 SET b = (SELECT COUNT(a) FROM t1);
+
+INSERT INTO t1
+ VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+INSERT INTO t2
+ VALUES (0),(0),(0),(0),(0),(0),(0),(0),(0);
+
+send
+ UPDATE t1 SET a = 3;
+
+connect(con1,localhost,root,,);
+ SELECT COUNT(*) FROM t1;
+disconnect con1;
+
+connection default;
+reap;
+SELECT * FROM t2;
+UPDATE t1 SET a = 2;
+SELECT * FROM t2;
+
+SET optimizer_switch=@save_optimizer_switch;
+
+DROP TRIGGER tr;
+DROP TABLE t1, t2;
+
+--echo End of 5.3 tests.
+
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 48522f8a70f..699c6e11cc1 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -211,8 +211,7 @@ bool Item_subselect::fix_fields(THD *thd_param, Item **ref)
bool res;
DBUG_ASSERT(fixed == 0);
- /* There is no reason to get a different THD. */
- DBUG_ASSERT(thd == thd_param);
+ engine->set_thd((thd= thd_param));
if (!done_first_fix_fields)
{
done_first_fix_fields= TRUE;