From d65e78b5273cd2cb2daf7b0a7bcd0c533bd58d28 Mon Sep 17 00:00:00 2001
From: "dlenev@brandersnatch.localdomain" <>
Date: Mon, 20 Dec 2004 09:55:06 +0300
Subject: [PATCH] Added test which covers nicely recent cleanup in derived
 tables processing.

---
 mysql-test/r/derived.result |  5 +++++
 mysql-test/t/derived.test   | 13 +++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/mysql-test/r/derived.result b/mysql-test/r/derived.result
index ddd8f82de2c..da2bb9081de 100644
--- a/mysql-test/r/derived.result
+++ b/mysql-test/r/derived.result
@@ -330,3 +330,8 @@ SELECT MIN(price) min, MAX(price) max, AVG(price) avg FROM (SELECT SUBSTRING( MA
 min	max	avg
 10.00	10.00	10
 DROP TABLE t1;
+CREATE TABLE t1 (a char(10), b char(10));
+INSERT INTO t1 VALUES ('root','localhost'), ('root','%');
+SELECT * FROM (SELECT (SELECT a.a FROM t1 AS a WHERE a.a = b.a) FROM t1 AS b) AS c;
+ERROR 21000: Subquery returns more than 1 row
+DROP TABLE t1;
diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test
index 64e3fe8929b..d204947b1fa 100644
--- a/mysql-test/t/derived.test
+++ b/mysql-test/t/derived.test
@@ -214,3 +214,16 @@ CREATE TABLE `t1` ( `itemid` int(11) NOT NULL default '0', `grpid` varchar(15) N
 insert into t1 values (128, 'rozn', 2, now(), 10),(128, 'rozn', 1, now(), 10);
 SELECT MIN(price) min, MAX(price) max, AVG(price) avg FROM (SELECT SUBSTRING( MAX(concat(date_,";",price)), 12) price FROM t1 WHERE itemid=128 AND  grpid='rozn' GROUP BY itemid, grpid, vendor) lastprices;
 DROP TABLE t1;
+
+#
+# Test for bug #7413 "Subquery with non-scalar results participating in
+# select list of derived table crashes server" aka "VIEW with sub query can
+# cause the MySQL server to crash". If we have encountered problem during
+# filling of derived table we should report error and perform cleanup
+# properly.
+#
+CREATE TABLE t1 (a char(10), b char(10));
+INSERT INTO t1 VALUES ('root','localhost'), ('root','%');
+--error 1242
+SELECT * FROM (SELECT (SELECT a.a FROM t1 AS a WHERE a.a = b.a) FROM t1 AS b) AS c;
+DROP TABLE t1;
-- 
2.30.9