summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/sp.result28
-rw-r--r--mysql-test/t/mysql_client_test-master.opt1
-rw-r--r--mysql-test/t/mysql_client_test_comp-master.opt1
-rw-r--r--mysql-test/t/sp.test42
-rw-r--r--sql/sql_select.cc4
-rw-r--r--tests/mysql_client_test.c53
6 files changed, 127 insertions, 2 deletions
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result
index 25675a11f4a..4a905553fba 100644
--- a/mysql-test/r/sp.result
+++ b/mysql-test/r/sp.result
@@ -8501,4 +8501,32 @@ b-c
0
drop procedure p1|
drop function f1|
+#
+# MDEV-24827: MariaDB 10.5.5 crash (sig 11) during a SELECT
+#
+CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT);
+CREATE TABLE t2 (c1 INT PRIMARY KEY, c2 INT, KEY idx_c2(c2));
+INSERT INTO t1 (c1, c2) SELECT seq, seq FROM seq_1_to_10000;
+INSERT INTO t2 (c1, c2) SELECT seq, seq FROM seq_1_to_20000;
+CREATE OR REPLACE PROCEDURE p1()
+begin
+DECLARE done INT DEFAULT FALSE;
+DECLARE a INT;
+DECLARE cur1 CURSOR FOR
+SELECT t2.c1 AS c1 FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1
+WHERE EXISTS (SELECT 1 FROM t1 WHERE c2 = -1) ORDER BY c1;
+DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
+OPEN cur1;
+read_loop: LOOP
+FETCH cur1 INTO a;
+IF done THEN
+LEAVE read_loop;
+END IF;
+END LOOP;
+CLOSE cur1;
+END $
+CALL p1();
+DROP PROCEDURE p1;
+DROP TABLE t1;
+DROP TABLE t2;
#End of 10.2 tests
diff --git a/mysql-test/t/mysql_client_test-master.opt b/mysql-test/t/mysql_client_test-master.opt
index fcaf2b69fbc..478e62e308f 100644
--- a/mysql-test/t/mysql_client_test-master.opt
+++ b/mysql-test/t/mysql_client_test-master.opt
@@ -2,3 +2,4 @@
--general-log-file=$MYSQLTEST_VARDIR/log/master.log
--log-output=FILE,TABLE
--max-allowed-packet=32000000
+--sequence=on
diff --git a/mysql-test/t/mysql_client_test_comp-master.opt b/mysql-test/t/mysql_client_test_comp-master.opt
index 783093c900b..aa8a3382d09 100644
--- a/mysql-test/t/mysql_client_test_comp-master.opt
+++ b/mysql-test/t/mysql_client_test_comp-master.opt
@@ -1,2 +1,3 @@
--loose-enable-performance-schema
--max-allowed-packet=32000000
+--sequence=on
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index 40a1e873ab9..fbd97739a65 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -1,4 +1,6 @@
--source include/have_partition.inc
+--source include/have_sequence.inc
+
#
# Basic stored PROCEDURE tests
#
@@ -10044,5 +10046,45 @@ drop procedure p1|
drop function f1|
delimiter ;|
+--echo #
+--echo # MDEV-24827: MariaDB 10.5.5 crash (sig 11) during a SELECT
+--echo #
+
+CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT);
+CREATE TABLE t2 (c1 INT PRIMARY KEY, c2 INT, KEY idx_c2(c2));
+
+INSERT INTO t1 (c1, c2) SELECT seq, seq FROM seq_1_to_10000;
+INSERT INTO t2 (c1, c2) SELECT seq, seq FROM seq_1_to_20000;
+
+--delimiter $
+
+CREATE OR REPLACE PROCEDURE p1()
+begin
+ DECLARE done INT DEFAULT FALSE;
+ DECLARE a INT;
+
+ DECLARE cur1 CURSOR FOR
+ SELECT t2.c1 AS c1 FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1
+ WHERE EXISTS (SELECT 1 FROM t1 WHERE c2 = -1) ORDER BY c1;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
+
+ OPEN cur1;
+ read_loop: LOOP
+ FETCH cur1 INTO a;
+ IF done THEN
+ LEAVE read_loop;
+ END IF;
+ END LOOP;
+ CLOSE cur1;
+END $
+
+--delimiter ;
+
+CALL p1();
+
+DROP PROCEDURE p1;
+DROP TABLE t1;
+DROP TABLE t2;
--echo #End of 10.2 tests
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index a7e2ac4e374..abdc79c1bf3 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -12914,8 +12914,6 @@ return_zero_rows(JOIN *join, select_result *result, List<TABLE_LIST> &tables,
DBUG_RETURN(0);
}
- join->join_free();
-
if (send_row)
{
/*
@@ -12962,6 +12960,8 @@ return_zero_rows(JOIN *join, select_result *result, List<TABLE_LIST> &tables,
if (!send_error)
result->send_eof(); // Should be safe
}
+ join->join_free();
+
DBUG_RETURN(0);
}
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index ac9c06ac94b..acd9b61327b 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -19962,6 +19962,58 @@ static void test_mdev_26145()
myquery(rc);
}
+static void test_mdev24827()
+{
+ int rc;
+ MYSQL_STMT *stmt;
+ unsigned long cursor = CURSOR_TYPE_READ_ONLY;
+
+ myheader("test_mdev24827");
+
+ rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "DROP TABLE IF EXISTS t2");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT)");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "CREATE TABLE t2 (c1 INT PRIMARY KEY, c2 INT, "
+ "KEY idx_c2(c2))");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "INSERT INTO t1 (c1, c2) "
+ "SELECT seq, seq FROM seq_1_to_10000");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "INSERT INTO t2 (c1, c2) "
+ "SELECT seq, seq FROM seq_1_to_20000");
+ myquery(rc);
+
+ const char* query=
+ "SELECT t2.c1 AS c1 FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1 "
+ "WHERE EXISTS (SELECT 1 FROM t1 WHERE c2 = -1) ORDER BY c1";
+
+ stmt= mysql_stmt_init(mysql);
+ check_stmt(stmt);
+
+ rc= mysql_stmt_prepare(stmt, query, strlen(query));
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, &cursor);
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ rc= mysql_query(mysql, "DROP TABLE t1");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "DROP TABLE t2");
+ myquery(rc);
+}
+
#ifndef EMBEDDED_LIBRARY
#define MDEV19838_MAX_PARAM_COUNT 32
#define MDEV19838_FIELDS_COUNT 17
@@ -20112,6 +20164,7 @@ static void test_mdev19838()
#endif // EMBEDDED_LIBRARY
static struct my_tests_st my_tests[]= {
+ { "test_mdev24827", test_mdev24827 },
{ "test_mdev_26145", test_mdev_26145 },
{ "disable_query_logs", disable_query_logs },
{ "test_view_sp_list_fields", test_view_sp_list_fields },