Commit 6242036f authored by Igor Babaev's avatar Igor Babaev

MDEV-15940 Crash when using CURSOR with VALUES()

The function st_select_lex_unit::get_column_types() should
take into account that a unit may contain only a table
value constructor and nothing more.
parent c39f8a80
...@@ -2071,3 +2071,24 @@ ERROR HY000: Field reference 'b' can't be used in table value constructor ...@@ -2071,3 +2071,24 @@ ERROR HY000: Field reference 'b' can't be used in table value constructor
select * from (values (1), (t1.b), (2)) as new_tvc; select * from (values (1), (t1.b), (2)) as new_tvc;
ERROR HY000: Field reference 't1.b' can't be used in table value constructor ERROR HY000: Field reference 't1.b' can't be used in table value constructor
drop table t1; drop table t1;
#
# MDEV-MDEV-15940: cursor over TVC
#
BEGIN NOT ATOMIC
DECLARE v INT;
DECLARE cur CURSOR FOR VALUES(7);
OPEN cur;
FETCH cur INTO v;
SELECT v;
END;
|
v
7
BEGIN NOT ATOMIC
DECLARE v INT DEFAULT 0;
FOR a IN (VALUES (7)) DO SET v = v + 1; END FOR;
SELECT v;
END;
|
v
1
...@@ -1044,3 +1044,27 @@ select * from (values (1), (b), (2)) as new_tvc; ...@@ -1044,3 +1044,27 @@ select * from (values (1), (b), (2)) as new_tvc;
select * from (values (1), (t1.b), (2)) as new_tvc; select * from (values (1), (t1.b), (2)) as new_tvc;
drop table t1; drop table t1;
--echo #
--echo # MDEV-MDEV-15940: cursor over TVC
--echo #
DELIMITER |;
BEGIN NOT ATOMIC
DECLARE v INT;
DECLARE cur CURSOR FOR VALUES(7);
OPEN cur;
FETCH cur INTO v;
SELECT v;
END;
|
BEGIN NOT ATOMIC
DECLARE v INT DEFAULT 0;
FOR a IN (VALUES (7)) DO SET v = v + 1; END FOR;
SELECT v;
END;
|
DELIMITER ;|
...@@ -1874,7 +1874,7 @@ bool st_select_lex_unit::change_result(select_result_interceptor *new_result, ...@@ -1874,7 +1874,7 @@ bool st_select_lex_unit::change_result(select_result_interceptor *new_result,
List<Item> *st_select_lex_unit::get_column_types(bool for_cursor) List<Item> *st_select_lex_unit::get_column_types(bool for_cursor)
{ {
SELECT_LEX *sl= first_select(); SELECT_LEX *sl= first_select();
bool is_procedure= MY_TEST(sl->join->procedure); bool is_procedure= !sl->tvc && sl->join->procedure ;
if (is_procedure) if (is_procedure)
{ {
......
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