summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2020-07-01 11:39:22 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2020-07-01 11:39:22 +0530
commitfbfb5b5f68a428ec819bc09d14b30cebf660b37b (patch)
tree2f9ea6c946038506544db7fb7f399902867d9889 /mysql-test
parent4a2e7b5368b2c78c5965b74727727053c67b406d (diff)
downloadmariadb-git-fbfb5b5f68a428ec819bc09d14b30cebf660b37b.tar.gz
MDEV-22852: SIGSEGV in sortlength (optimized builds)
The issue here is for a DEPENDENT subquery that has an aggregate function in the ORDER BY clause, is wrapped inside an Item_aggregate_ref. For computation of ORDER BY we need to refer to the temp table field corresponding to this item. But in the function make_sortorder, we were explicitly casting Item_aggrgate_ref to Item_sum, which leads to us not getting the temp table field corresponding to the item.
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/subselect4.result12
-rw-r--r--mysql-test/t/subselect4.test12
2 files changed, 24 insertions, 0 deletions
diff --git a/mysql-test/r/subselect4.result b/mysql-test/r/subselect4.result
index 51f199bd1e9..a718895dc34 100644
--- a/mysql-test/r/subselect4.result
+++ b/mysql-test/r/subselect4.result
@@ -2566,3 +2566,15 @@ SELECT sum(a), t2.a, t2.b FROM t2 HAVING t2.a IN (SELECT t2.b FROM t1);
sum(a) a b
6 1 1
DROP TABLE t1,t2;
+#
+# MDEV-22852: SIGSEGV in sortlength (optimized builds)
+#
+SET @save_optimizer_switch=@@optimizer_switch;
+SET optimizer_switch='subquery_cache=off';
+CREATE TABLE t1 (a INT,b INT);
+INSERT INTO t1 VALUES (0,0),(0,0);
+SELECT (SELECT DISTINCT t1i.b FROM t1 t1i GROUP BY t1i.a ORDER BY MAX(t1o.b)) FROM t1 AS t1o;
+(SELECT DISTINCT t1i.b FROM t1 t1i GROUP BY t1i.a ORDER BY MAX(t1o.b))
+0
+SET @@optimizer_switch= @save_optimizer_switch;
+DROP TABLE t1;
diff --git a/mysql-test/t/subselect4.test b/mysql-test/t/subselect4.test
index 2b3f610d06f..057a4502684 100644
--- a/mysql-test/t/subselect4.test
+++ b/mysql-test/t/subselect4.test
@@ -2101,3 +2101,15 @@ SET @@sql_select_limit= @save_sql_select_limit;
eval EXPLAIN EXTENDED $query;
eval $query;
DROP TABLE t1,t2;
+
+--echo #
+--echo # MDEV-22852: SIGSEGV in sortlength (optimized builds)
+--echo #
+
+SET @save_optimizer_switch=@@optimizer_switch;
+SET optimizer_switch='subquery_cache=off';
+CREATE TABLE t1 (a INT,b INT);
+INSERT INTO t1 VALUES (0,0),(0,0);
+SELECT (SELECT DISTINCT t1i.b FROM t1 t1i GROUP BY t1i.a ORDER BY MAX(t1o.b)) FROM t1 AS t1o;
+SET @@optimizer_switch= @save_optimizer_switch;
+DROP TABLE t1;