1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

MDEV-21998: Server crashes in st_select_lex::add_table_to_list upon mix of KILL and sequences

Continue support the hack of current select equal builtin select if
selects stack is empty even after subselects.
This commit is contained in:
Oleksandr Byelkin
2020-07-24 09:59:38 +02:00
parent fd9ca2a742
commit c6eb21cd87
14 changed files with 67 additions and 44 deletions

View File

@ -1893,4 +1893,12 @@ i
1 1
i i
2 2
#
# MDEV-21998: Server crashes in st_select_lex::add_table_to_list
# upon mix of KILL and sequences
#
KILL ( SELECT 1 ) + LASTVAL(s);
ERROR 42000: KILL does not support subqueries or stored functions
KILL LASTVAL(s);
ERROR 42000: KILL does not support subqueries or stored functions
# End of 10.4 tests # End of 10.4 tests

View File

@ -1677,6 +1677,14 @@ $$
DELIMITER ;$$ DELIMITER ;$$
--echo #
--echo # MDEV-21998: Server crashes in st_select_lex::add_table_to_list
--echo # upon mix of KILL and sequences
--echo #
--error ER_SUBQUERIES_NOT_SUPPORTED
KILL ( SELECT 1 ) + LASTVAL(s);
--error ER_SUBQUERIES_NOT_SUPPORTED
KILL LASTVAL(s);
--echo # End of 10.4 tests --echo # End of 10.4 tests

View File

@ -2285,13 +2285,13 @@ begin
DECLARE foo CONDITION FOR SQLSTATE '12345'; DECLARE foo CONDITION FOR SQLSTATE '12345';
SIGNAL foo SET MYSQL_ERRNO = `65`; /* illegal */ SIGNAL foo SET MYSQL_ERRNO = `65`; /* illegal */
end $$ end $$
ERROR 42S22: Unknown column '65' in 'field list' ERROR 42000: Undeclared variable: 65
create procedure test_signal() create procedure test_signal()
begin begin
DECLARE foo CONDITION FOR SQLSTATE '12345'; DECLARE foo CONDITION FOR SQLSTATE '12345';
SIGNAL foo SET MYSQL_ERRNO = `A`; /* illegal */ SIGNAL foo SET MYSQL_ERRNO = `A`; /* illegal */
end $$ end $$
ERROR 42S22: Unknown column 'A' in 'field list' ERROR 42000: Undeclared variable: A
create procedure test_signal() create procedure test_signal()
begin begin
DECLARE foo CONDITION FOR SQLSTATE '12345'; DECLARE foo CONDITION FOR SQLSTATE '12345';
@ -2342,7 +2342,7 @@ DECLARE foo CONDITION FOR SQLSTATE '12345';
SIGNAL foo SET MYSQL_ERRNO = 1000, SIGNAL foo SET MYSQL_ERRNO = 1000,
MESSAGE_TEXT = `Hello`; MESSAGE_TEXT = `Hello`;
end $$ end $$
ERROR 42S22: Unknown column 'Hello' in 'field list' ERROR 42000: Undeclared variable: Hello
create procedure test_signal() create procedure test_signal()
begin begin
DECLARE foo CONDITION FOR SQLSTATE '12345'; DECLARE foo CONDITION FOR SQLSTATE '12345';

View File

@ -2546,7 +2546,7 @@ end $$
call test_signal $$ call test_signal $$
drop procedure test_signal $$ drop procedure test_signal $$
-- error ER_BAD_FIELD_ERROR -- error ER_SP_UNDECLARED_VAR
create procedure test_signal() create procedure test_signal()
begin begin
DECLARE foo CONDITION FOR SQLSTATE '12345'; DECLARE foo CONDITION FOR SQLSTATE '12345';
@ -2554,7 +2554,7 @@ begin
end $$ end $$
-- error ER_BAD_FIELD_ERROR -- error ER_SP_UNDECLARED_VAR
create procedure test_signal() create procedure test_signal()
begin begin
DECLARE foo CONDITION FOR SQLSTATE '12345'; DECLARE foo CONDITION FOR SQLSTATE '12345';
@ -2616,7 +2616,7 @@ end $$
call test_signal $$ call test_signal $$
drop procedure test_signal $$ drop procedure test_signal $$
-- error ER_BAD_FIELD_ERROR -- error ER_SP_UNDECLARED_VAR
create procedure test_signal() create procedure test_signal()
begin begin
DECLARE foo CONDITION FOR SQLSTATE '12345'; DECLARE foo CONDITION FOR SQLSTATE '12345';

View File

@ -454,7 +454,7 @@ else
set b = a; set b = a;
end if; end if;
end| end|
ERROR 42S22: Unknown column 'aa' in 'field list' ERROR 42000: Undeclared variable: aa
create procedure bug4344() drop procedure bug4344| create procedure bug4344() drop procedure bug4344|
ERROR HY000: Can't drop or alter a PROCEDURE from within another stored routine ERROR HY000: Can't drop or alter a PROCEDURE from within another stored routine
create procedure bug4344() drop function bug4344| create procedure bug4344() drop function bug4344|
@ -1069,7 +1069,7 @@ IF bug13037_foo THEN
SELECT 1; SELECT 1;
END IF; END IF;
END| END|
ERROR 42S22: Unknown column 'bug13037_foo' in 'field list' ERROR 42000: Undeclared variable: bug13037_foo
CREATE PROCEDURE bug13037_p2() CREATE PROCEDURE bug13037_p2()
BEGIN BEGIN
SET @bug13037_foo = bug13037_bar; SET @bug13037_foo = bug13037_bar;

View File

@ -615,7 +615,7 @@ call bug2653_1(1, @b)|
drop procedure bug2653_1| drop procedure bug2653_1|
--error ER_BAD_FIELD_ERROR --error ER_SP_UNDECLARED_VAR
create procedure bug2653_2(a int, out b int) create procedure bug2653_2(a int, out b int)
begin begin
if aa < 0 then if aa < 0 then
@ -1508,7 +1508,7 @@ DROP PROCEDURE IF EXISTS bug13037_p3;
delimiter |; delimiter |;
--error ER_BAD_FIELD_ERROR --error ER_SP_UNDECLARED_VAR
CREATE PROCEDURE bug13037_p1() CREATE PROCEDURE bug13037_p1()
BEGIN BEGIN
IF bug13037_foo THEN IF bug13037_foo THEN

View File

@ -4186,7 +4186,7 @@ select v, isnull(v);
end if; end if;
end; end;
end| end|
ERROR 42S22: Unknown column 'undefined_var' in 'field list' ERROR 42000: Undeclared variable: undefined_var
create procedure bug14643_2() create procedure bug14643_2()
begin begin
declare continue handler for sqlexception select 'boo' as 'Handler'; declare continue handler for sqlexception select 'boo' as 'Handler';
@ -4198,7 +4198,7 @@ select 2;
end case; end case;
select undefined_var; select undefined_var;
end| end|
ERROR 42S22: Unknown column 'undefined_var' in 'field list' ERROR 42000: Undeclared variable: undefined_var
drop procedure if exists bug14304| drop procedure if exists bug14304|
drop table if exists t3, t4| drop table if exists t3, t4|
create table t3(a int primary key auto_increment)| create table t3(a int primary key auto_increment)|
@ -4228,7 +4228,7 @@ create procedure bug14376()
begin begin
declare x int default x; declare x int default x;
end| end|
ERROR 42S22: Unknown column 'x' in 'field list' ERROR 42000: Undeclared variable: x
create procedure bug14376() create procedure bug14376()
begin begin
declare x int default 42; declare x int default 42;
@ -4483,7 +4483,7 @@ select 'no' as 'v';
end if; end if;
select 'done' as 'End'; select 'done' as 'End';
end| end|
ERROR 42S22: Unknown column 'v' in 'field list' ERROR 42000: Undeclared variable: v
create procedure bug14498_2() create procedure bug14498_2()
begin begin
declare continue handler for sqlexception select 'error' as 'Handler'; declare continue handler for sqlexception select 'error' as 'Handler';
@ -4492,7 +4492,7 @@ select 'yes' as 'v';
end while; end while;
select 'done' as 'End'; select 'done' as 'End';
end| end|
ERROR 42S22: Unknown column 'v' in 'field list' ERROR 42000: Undeclared variable: v
create procedure bug14498_3() create procedure bug14498_3()
begin begin
declare continue handler for sqlexception select 'error' as 'Handler'; declare continue handler for sqlexception select 'error' as 'Handler';
@ -4501,7 +4501,7 @@ select 'maybe' as 'v';
until v end repeat; until v end repeat;
select 'done' as 'End'; select 'done' as 'End';
end| end|
ERROR 42S22: Unknown column 'v' in 'field list' ERROR 42000: Undeclared variable: v
create procedure bug14498_4() create procedure bug14498_4()
begin begin
declare continue handler for sqlexception select 'error' as 'Handler'; declare continue handler for sqlexception select 'error' as 'Handler';
@ -4515,7 +4515,7 @@ select '?' as 'v';
end case; end case;
select 'done' as 'End'; select 'done' as 'End';
end| end|
ERROR 42S22: Unknown column 'v' in 'field list' ERROR 42000: Undeclared variable: v
create procedure bug14498_5() create procedure bug14498_5()
begin begin
declare continue handler for sqlexception select 'error' as 'Handler'; declare continue handler for sqlexception select 'error' as 'Handler';
@ -4529,7 +4529,7 @@ select '?' as 'v';
end case; end case;
select 'done' as 'End'; select 'done' as 'End';
end| end|
ERROR 42S22: Unknown column 'v' in 'field list' ERROR 42000: Undeclared variable: v
drop table if exists t3| drop table if exists t3|
drop procedure if exists bug15231_1| drop procedure if exists bug15231_1|
drop procedure if exists bug15231_2| drop procedure if exists bug15231_2|
@ -8403,7 +8403,7 @@ DECLARE name VARCHAR(10);
SET name="hello"; SET name="hello";
call p1(name2); call p1(name2);
END| END|
ERROR 42S22: Unknown column 'name2' in 'field list' ERROR 42000: Undeclared variable: name2
call p2(); call p2();
a a
hello hello

View File

@ -5046,7 +5046,7 @@ drop procedure if exists bug14643_1|
drop procedure if exists bug14643_2| drop procedure if exists bug14643_2|
--enable_warnings --enable_warnings
--error ER_BAD_FIELD_ERROR --error ER_SP_UNDECLARED_VAR
create procedure bug14643_1() create procedure bug14643_1()
begin begin
declare continue handler for sqlexception select 'boo' as 'Handler'; declare continue handler for sqlexception select 'boo' as 'Handler';
@ -5062,7 +5062,7 @@ begin
end; end;
end| end|
--error ER_BAD_FIELD_ERROR --error ER_SP_UNDECLARED_VAR
create procedure bug14643_2() create procedure bug14643_2()
begin begin
declare continue handler for sqlexception select 'boo' as 'Handler'; declare continue handler for sqlexception select 'boo' as 'Handler';
@ -5117,7 +5117,7 @@ drop table t3, t4|
drop procedure if exists bug14376| drop procedure if exists bug14376|
--enable_warnings --enable_warnings
--error ER_BAD_FIELD_ERROR --error ER_SP_UNDECLARED_VAR
create procedure bug14376() create procedure bug14376()
begin begin
declare x int default x; declare x int default x;
@ -5344,7 +5344,7 @@ drop procedure if exists bug14498_4|
drop procedure if exists bug14498_5| drop procedure if exists bug14498_5|
--enable_warnings --enable_warnings
--error ER_BAD_FIELD_ERROR --error ER_SP_UNDECLARED_VAR
create procedure bug14498_1() create procedure bug14498_1()
begin begin
declare continue handler for sqlexception select 'error' as 'Handler'; declare continue handler for sqlexception select 'error' as 'Handler';
@ -5357,7 +5357,7 @@ begin
select 'done' as 'End'; select 'done' as 'End';
end| end|
--error ER_BAD_FIELD_ERROR --error ER_SP_UNDECLARED_VAR
create procedure bug14498_2() create procedure bug14498_2()
begin begin
declare continue handler for sqlexception select 'error' as 'Handler'; declare continue handler for sqlexception select 'error' as 'Handler';
@ -5368,7 +5368,7 @@ begin
select 'done' as 'End'; select 'done' as 'End';
end| end|
--error ER_BAD_FIELD_ERROR --error ER_SP_UNDECLARED_VAR
create procedure bug14498_3() create procedure bug14498_3()
begin begin
declare continue handler for sqlexception select 'error' as 'Handler'; declare continue handler for sqlexception select 'error' as 'Handler';
@ -5379,7 +5379,7 @@ begin
select 'done' as 'End'; select 'done' as 'End';
end| end|
--error ER_BAD_FIELD_ERROR --error ER_SP_UNDECLARED_VAR
create procedure bug14498_4() create procedure bug14498_4()
begin begin
declare continue handler for sqlexception select 'error' as 'Handler'; declare continue handler for sqlexception select 'error' as 'Handler';
@ -5395,7 +5395,7 @@ begin
select 'done' as 'End'; select 'done' as 'End';
end| end|
--error ER_BAD_FIELD_ERROR --error ER_SP_UNDECLARED_VAR
create procedure bug14498_5() create procedure bug14498_5()
begin begin
declare continue handler for sqlexception select 'error' as 'Handler'; declare continue handler for sqlexception select 'error' as 'Handler';
@ -9931,7 +9931,7 @@ BEGIN
call p1(name); call p1(name);
END| END|
--error ER_BAD_FIELD_ERROR --error ER_SP_UNDECLARED_VAR
CREATE OR REPLACE PROCEDURE p3 () CREATE OR REPLACE PROCEDURE p3 ()
BEGIN BEGIN
DECLARE name VARCHAR(10); DECLARE name VARCHAR(10);

View File

@ -1045,7 +1045,7 @@ NULL;
END LOOP; END LOOP;
END; END;
$$ $$
ERROR 42000: Undefined CURSOR: c2 ERROR 42000: Undeclared variable: c2
# Make sure "rec" shadows other declarations outside the loop # Make sure "rec" shadows other declarations outside the loop
CREATE TABLE t1 (a INT, b VARCHAR(10)); CREATE TABLE t1 (a INT, b VARCHAR(10));
INSERT INTO t1 VALUES (10, 'b0'); INSERT INTO t1 VALUES (10, 'b0');

View File

@ -1019,7 +1019,7 @@ LOOP
EXIT WHEN unknown_ident IS NULL; EXIT WHEN unknown_ident IS NULL;
END LOOP; END LOOP;
END$$ END$$
ERROR 42S22: Unknown column 'unknown_ident' in 'field list' ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1 CREATE PROCEDURE p1
AS AS
BEGIN BEGIN
@ -1028,7 +1028,7 @@ LOOP
EXIT label WHEN unknown_ident IS NULL; EXIT label WHEN unknown_ident IS NULL;
END LOOP; END LOOP;
END$$ END$$
ERROR 42S22: Unknown column 'unknown_ident' in 'field list' ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1 CREATE PROCEDURE p1
AS AS
BEGIN BEGIN
@ -1036,7 +1036,7 @@ LOOP
CONTINUE WHEN unknown_ident IS NULL; CONTINUE WHEN unknown_ident IS NULL;
END LOOP; END LOOP;
END$$ END$$
ERROR 42S22: Unknown column 'unknown_ident' in 'field list' ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1 CREATE PROCEDURE p1
AS AS
BEGIN BEGIN
@ -1045,7 +1045,7 @@ LOOP
CONTINUE label WHEN unknown_ident IS NULL; CONTINUE label WHEN unknown_ident IS NULL;
END LOOP; END LOOP;
END$$ END$$
ERROR 42S22: Unknown column 'unknown_ident' in 'field list' ERROR 42000: Undeclared variable: unknown_ident
# #
# MDEV-10583 sql_mode=ORACLE: SQL%ROWCOUNT # MDEV-10583 sql_mode=ORACLE: SQL%ROWCOUNT
# #

View File

@ -1128,7 +1128,7 @@ DELIMITER ;$$
--echo # IN followed by an unknown cursor name --echo # IN followed by an unknown cursor name
DELIMITER $$; DELIMITER $$;
--error ER_SP_CURSOR_MISMATCH --error ER_SP_UNDECLARED_VAR
CREATE PROCEDURE p1 AS CREATE PROCEDURE p1 AS
CURSOR c1 IS SELECT 'test' AS a FROM DUAL; CURSOR c1 IS SELECT 'test' AS a FROM DUAL;
BEGIN BEGIN

View File

@ -1094,7 +1094,7 @@ DROP FUNCTION f1;
--echo # --echo #
DELIMITER $$; DELIMITER $$;
--error ER_BAD_FIELD_ERROR --error ER_SP_UNDECLARED_VAR
CREATE PROCEDURE p1 CREATE PROCEDURE p1
AS AS
BEGIN BEGIN
@ -1106,7 +1106,7 @@ DELIMITER ;$$
DELIMITER $$; DELIMITER $$;
--error ER_BAD_FIELD_ERROR --error ER_SP_UNDECLARED_VAR
CREATE PROCEDURE p1 CREATE PROCEDURE p1
AS AS
BEGIN BEGIN
@ -1119,7 +1119,7 @@ DELIMITER ;$$
DELIMITER $$; DELIMITER $$;
--error ER_BAD_FIELD_ERROR --error ER_SP_UNDECLARED_VAR
CREATE PROCEDURE p1 CREATE PROCEDURE p1
AS AS
BEGIN BEGIN
@ -1131,7 +1131,7 @@ DELIMITER ;$$
DELIMITER $$; DELIMITER $$;
--error ER_BAD_FIELD_ERROR --error ER_SP_UNDECLARED_VAR
CREATE PROCEDURE p1 CREATE PROCEDURE p1
AS AS
BEGIN BEGIN

View File

@ -7560,6 +7560,7 @@ Item *LEX::create_item_ident_sp(THD *thd, Lex_ident_sys_st *name,
const Sp_rcontext_handler *rh; const Sp_rcontext_handler *rh;
sp_variable *spv; sp_variable *spv;
uint unused_off;
DBUG_ASSERT(spcont); DBUG_ASSERT(spcont);
DBUG_ASSERT(sphead); DBUG_ASSERT(sphead);
if ((spv= find_variable(name, &rh))) if ((spv= find_variable(name, &rh)))
@ -7598,7 +7599,9 @@ Item *LEX::create_item_ident_sp(THD *thd, Lex_ident_sys_st *name,
return new (thd->mem_root) Item_func_sqlerrm(thd); return new (thd->mem_root) Item_func_sqlerrm(thd);
} }
if (!current_select) if (!select_stack_head() &&
(current_select->parsing_place != FOR_LOOP_BOUND ||
spcont->find_cursor(name, &unused_off, false) == NULL))
{ {
// we are out of SELECT or FOR so it is syntax error // we are out of SELECT or FOR so it is syntax error
my_error(ER_SP_UNDECLARED_VAR, MYF(0), name->str); my_error(ER_SP_UNDECLARED_VAR, MYF(0), name->str);
@ -9083,7 +9086,8 @@ Item *LEX::create_item_query_expression(THD *thd,
// Add the subtree of subquery to the current SELECT_LEX // Add the subtree of subquery to the current SELECT_LEX
SELECT_LEX *curr_sel= select_stack_head(); SELECT_LEX *curr_sel= select_stack_head();
DBUG_ASSERT(current_select == curr_sel); DBUG_ASSERT(current_select == curr_sel ||
(curr_sel == NULL && current_select == &builtin_select));
if (!curr_sel) if (!curr_sel)
{ {
curr_sel= &builtin_select; curr_sel= &builtin_select;
@ -9315,7 +9319,8 @@ SELECT_LEX *LEX::parsed_subselect(SELECT_LEX_UNIT *unit)
// Add the subtree of subquery to the current SELECT_LEX // Add the subtree of subquery to the current SELECT_LEX
SELECT_LEX *curr_sel= select_stack_head(); SELECT_LEX *curr_sel= select_stack_head();
DBUG_ASSERT(current_select == curr_sel); DBUG_ASSERT(current_select == curr_sel ||
(curr_sel == NULL && current_select == &builtin_select));
if (curr_sel) if (curr_sel)
{ {
curr_sel->register_unit(unit, &curr_sel->context); curr_sel->register_unit(unit, &curr_sel->context);
@ -9391,7 +9396,8 @@ TABLE_LIST *LEX::parsed_derived_table(SELECT_LEX_UNIT *unit,
// Add the subtree of subquery to the current SELECT_LEX // Add the subtree of subquery to the current SELECT_LEX
SELECT_LEX *curr_sel= select_stack_head(); SELECT_LEX *curr_sel= select_stack_head();
DBUG_ASSERT(current_select == curr_sel); DBUG_ASSERT(current_select == curr_sel ||
(curr_sel == NULL && current_select == &builtin_select));
Table_ident *ti= new (thd->mem_root) Table_ident(unit); Table_ident *ti= new (thd->mem_root) Table_ident(unit);
if (ti == NULL) if (ti == NULL)

View File

@ -3632,8 +3632,9 @@ public:
if (unlikely(!select_stack_top)) if (unlikely(!select_stack_top))
{ {
current_select= NULL; current_select= &builtin_select;
DBUG_PRINT("info", ("Top Select is empty")); DBUG_PRINT("info", ("Top Select is empty -> sel builtin: %p",
current_select));
} }
else else
current_select= select_stack[select_stack_top - 1]; current_select= select_stack[select_stack_top - 1];