summaryrefslogtreecommitdiff
path: root/mysql-test/t/subselect4.test
diff options
context:
space:
mode:
authorSergei Petrunia <psergey@askmonty.org>2016-12-16 17:08:31 +0300
committerSergei Petrunia <psergey@askmonty.org>2016-12-19 17:57:43 +0300
commit268bb69beaec027b9f713d13316aa78c5c292817 (patch)
tree52b9c90b8ef2a6564e3c87a6ec8468919a26616e /mysql-test/t/subselect4.test
parent19896d4b3ab459d135aee6ee67cb92bce92f9b87 (diff)
downloadmariadb-git-268bb69beaec027b9f713d13316aa78c5c292817.tar.gz
MDEV-7691: Assertion `outer_context || !*from_field || *from_field == not_found_field' ...
The bug occurred when a subquery - has a reference to outside, to grand-parent query or further up - is converted to a semi-join (i.e. merged into its parent). Then the reference to outside had form Item_ref(Item_field(...)). - Conversion to semi-join would call item->fix_after_pullout() for the outside reference. - Item_ref::fix_after_pullout would call Item_field->fix_after_pullout - The Item_field would construct a new Name_resolution_context object This process ignored the fact that the Item_field does not belong to any of the subselects being flattened. The result was crash in the next call to Item_field::fix_fields(), where we would try to use an invalid Name_resolution_context object. Fixed by not creating Name_resolution_context object if the Item_field's context does not belong to the subselect(s) that were flattened.
Diffstat (limited to 'mysql-test/t/subselect4.test')
-rw-r--r--mysql-test/t/subselect4.test41
1 files changed, 41 insertions, 0 deletions
diff --git a/mysql-test/t/subselect4.test b/mysql-test/t/subselect4.test
index b179ead39d7..7a7dd7e492e 100644
--- a/mysql-test/t/subselect4.test
+++ b/mysql-test/t/subselect4.test
@@ -1959,5 +1959,46 @@ SELECT x FROM t1 WHERE id > (SELECT MAX(id) - 1000 FROM t1) ORDER BY x LIMIT 1;
drop table t1;
+--echo #
+--echo # MDEV-7691: Assertion `outer_context || !*from_field || *from_field == not_found_field' ...
+--echo #
+set optimizer_switch=default;
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (4),(6);
+
+CREATE TABLE t2 (b INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (1),(8);
+
+PREPARE stmt FROM "
+SELECT * FROM t2
+HAVING 0 IN (
+ SELECT a FROM t1
+ WHERE a IN (
+ SELECT a FROM t1
+ WHERE b = a
+ )
+)
+";
+
+EXECUTE stmt;
+EXECUTE stmt;
+
+--echo # Alternative test case, without HAVING
+CREATE TABLE t3 (i INT) ENGINE=MyISAM;
+INSERT INTO t3 VALUES (4),(6);
+
+PREPARE stmt FROM "
+SELECT * FROM t3 AS t10
+WHERE EXISTS (
+ SELECT * FROM t3 AS t20 WHERE t10.i IN (
+ SELECT i FROM t3
+ )
+)";
+
+EXECUTE stmt;
+EXECUTE stmt;
+
+drop table t1, t2, t3;
+
SET optimizer_switch= @@global.optimizer_switch;
set @@tmp_table_size= @@global.tmp_table_size;