From 0dd12b4f2a72245a0fb491685c172a7b0e48cbc5 Mon Sep 17 00:00:00 2001
From: Igor Babaev <igor@askmonty.org>
Date: Thu, 14 Mar 2019 17:41:35 -0700
Subject: MDEV-18896 Crash in convert_join_subqueries_to_semijoins

If an IN-subquery is used in a table-less select the current code
should never consider it as candidate for semi-join optimizations.
Yet the function check_and_do_in_subquery_rewrites() improperly
checked the property "to be a table-less select". As a result
such select in IN subquery was used in INSERT .. SELECT then
the IN subquery by mistake was registered as a semi-join subquery
and convert_subq_to_sj() was called for it. However the code of
this function does not assume that the parent select of the subquery
could be a table-less select.
---
 mysql-test/t/subselect_sj.test | 10 ++++++++++
 1 file changed, 10 insertions(+)

(limited to 'mysql-test/t')

diff --git a/mysql-test/t/subselect_sj.test b/mysql-test/t/subselect_sj.test
index 0a35a61ecd3..aabb21b4245 100644
--- a/mysql-test/t/subselect_sj.test
+++ b/mysql-test/t/subselect_sj.test
@@ -2869,6 +2869,16 @@ EXECUTE stmt;
 drop view v3;
 drop table t1,t2,t3;
 
+--echo #
+--echo # MDEV-18896: IN subquery in WHERE of a table-less query used for INSERT
+--echo #
+
+create table t1 (a1 varchar(25));
+create table t2 (a2 varchar(25)) ;
+insert into t1 select 'xxx' from dual where 'xxx' in (select a2 from t2);
+
+drop table t1,t2;
+
 --echo # End of 5.5 test
 
 # The following command must be the last one the file 
-- 
cgit v1.2.1