Commit e5b877ce authored by Oleksandr Byelkin's avatar Oleksandr Byelkin

MDEV-11935: Queries in stored procedures with and EXISTS(SELECT * FROM VIEW)...

MDEV-11935: Queries in stored procedures with and EXISTS(SELECT * FROM VIEW) crashes and closes hte conneciton.

Use correct start point even for taken out from subselect items in process of exists2in conversion.
parent fdeeab01
...@@ -7952,3 +7952,41 @@ set global table_open_cache= @tmp_toc; ...@@ -7952,3 +7952,41 @@ set global table_open_cache= @tmp_toc;
set global table_definition_cache= @tmp_tdc; set global table_definition_cache= @tmp_tdc;
drop procedure p1; drop procedure p1;
drop table t1,t2,t3,t4,t5,t6; drop table t1,t2,t3,t4,t5,t6;
#
# MDEV-11935: Queries in stored procedures with and
# EXISTS(SELECT * FROM VIEW) crashes and closes hte conneciton.
#
CREATE TABLE ANY_TABLE (
ENTITY_UID BIGINT NOT NULL
);
CREATE TABLE SECURITY_PATH(
origid BIGINT UNSIGNED NOT NULL,
destid BIGINT UNSIGNED NOT NULL,
KEY (destid)
);
CREATE VIEW ENTITY_ACCESS (
ENTITY_UID,
OWNER_UID
) AS
SELECT SP1.origid,
SP2.destid
FROM SECURITY_PATH SP1
JOIN SECURITY_PATH SP2 ON SP1.destid = SP2.origid
;
CREATE PROCEDURE SP_EXAMPLE_SELECT ()
BEGIN
SELECT *
FROM ANY_TABLE AT1
WHERE EXISTS ( SELECT *
FROM ENTITY_ACCESS EA
WHERE AT1.ENTITY_UID = EA.ENTITY_UID
AND EA.OWNER_UID IS NULL );
END
//
CALL SP_EXAMPLE_SELECT ();
ENTITY_UID
CALL SP_EXAMPLE_SELECT ();
ENTITY_UID
drop procedure SP_EXAMPLE_SELECT;
drop view ENTITY_ACCESS;
drop table ANY_TABLE, SECURITY_PATH;
...@@ -9422,3 +9422,43 @@ drop procedure p1; ...@@ -9422,3 +9422,43 @@ drop procedure p1;
drop table t1,t2,t3,t4,t5,t6; drop table t1,t2,t3,t4,t5,t6;
--echo #
--echo # MDEV-11935: Queries in stored procedures with and
--echo # EXISTS(SELECT * FROM VIEW) crashes and closes hte conneciton.
--echo #
CREATE TABLE ANY_TABLE (
ENTITY_UID BIGINT NOT NULL
);
CREATE TABLE SECURITY_PATH(
origid BIGINT UNSIGNED NOT NULL,
destid BIGINT UNSIGNED NOT NULL,
KEY (destid)
);
CREATE VIEW ENTITY_ACCESS (
ENTITY_UID,
OWNER_UID
) AS
SELECT SP1.origid,
SP2.destid
FROM SECURITY_PATH SP1
JOIN SECURITY_PATH SP2 ON SP1.destid = SP2.origid
;
--delimiter //
CREATE PROCEDURE SP_EXAMPLE_SELECT ()
BEGIN
SELECT *
FROM ANY_TABLE AT1
WHERE EXISTS ( SELECT *
FROM ENTITY_ACCESS EA
WHERE AT1.ENTITY_UID = EA.ENTITY_UID
AND EA.OWNER_UID IS NULL );
END
//
--delimiter ;
CALL SP_EXAMPLE_SELECT ();
CALL SP_EXAMPLE_SELECT ();
drop procedure SP_EXAMPLE_SELECT;
drop view ENTITY_ACCESS;
drop table ANY_TABLE, SECURITY_PATH;
...@@ -6628,7 +6628,7 @@ find_field_in_tables(THD *thd, Item_ident *item, ...@@ -6628,7 +6628,7 @@ find_field_in_tables(THD *thd, Item_ident *item,
if (!table_ref->belong_to_view && if (!table_ref->belong_to_view &&
!table_ref->belong_to_derived) !table_ref->belong_to_derived)
{ {
SELECT_LEX *current_sel= thd->lex->current_select; SELECT_LEX *current_sel= item->context->select_lex;
SELECT_LEX *last_select= table_ref->select_lex; SELECT_LEX *last_select= table_ref->select_lex;
bool all_merged= TRUE; bool all_merged= TRUE;
for (SELECT_LEX *sl= current_sel; sl && sl!=last_select; for (SELECT_LEX *sl= current_sel; sl && sl!=last_select;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment