Commit 12c80df4 authored by Igor Babaev's avatar Igor Babaev

MDEV-20411 Procedure containing CTE incorrectly stored in mysql.proc

If the first token of the body of a stored procedure was 'WITH' then
the beginning of the body was determined incorrectly and that token was
missing in the string representing the body of the SP in mysql.proc. As a
resultnany call of such procedure failed as the string representing the
body could not be parsed.

The patch corrects the code of the functions get_tok_start() and
get_cpp_tok_start() of the class Lex_input_stream to make them take into
account look ahead tokens. The patch is needed only for 10.2 as this
problem has neen resolved in 10.3+.
parent 4ad148b1
......@@ -1964,4 +1964,59 @@ call p1();
ERROR 42S22: Unknown column 'a' in 'field list'
drop procedure p1;
drop table t1,t2;
#
# MDEV-20411: SP containing only one SELECT with WITH clause
#
create procedure sp1 ()
with cte as (select 1 as a) select * from cte;
call sp1();
a
1
call sp1();
a
1
create table t1 (a int);
insert into t1 values (3), (7), (1), (7), (1), (1), (3), (1), (5);
create procedure sp2 ()
with cte as (select * from t1) select * from cte;
call sp2();
a
3
7
1
7
1
1
3
1
5
call sp2();
a
3
7
1
7
1
1
3
1
5
create procedure sp3 ()
with cte as (select * from t1 group by a) select * from cte;
call sp3();
a
1
3
5
7
call sp3();
a
1
3
5
7
drop procedure sp1;
drop procedure sp2;
drop procedure sp3;
drop table t1;
# End of 10.2 tests
......@@ -49,7 +49,7 @@ a b
Full-text indexes are called collections
Only MyISAM tables support collections
select * from t1 where MATCH(a,b) AGAINST ("indexes" IN BOOLEAN MODE WITH QUERY EXPANSION);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'QUERY EXPANSION)' at line 1
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WITH QUERY EXPANSION)' at line 1
explain select * from t1 where MATCH(a,b) AGAINST ("collections");
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 fulltext a a 0 1 Using where
......
......@@ -1463,4 +1463,33 @@ drop procedure p1;
drop table t1,t2;
--echo #
--echo # MDEV-20411: SP containing only one SELECT with WITH clause
--echo #
create procedure sp1 ()
with cte as (select 1 as a) select * from cte;
call sp1();
call sp1();
create table t1 (a int);
insert into t1 values (3), (7), (1), (7), (1), (1), (3), (1), (5);
create procedure sp2 ()
with cte as (select * from t1) select * from cte;
call sp2();
call sp2();
create procedure sp3 ()
with cte as (select * from t1 group by a) select * from cte;
call sp3();
call sp3();
drop procedure sp1;
drop procedure sp2;
drop procedure sp3;
drop table t1;
--echo # End of 10.2 tests
......@@ -2176,7 +2176,7 @@ class Lex_input_stream
/** Get the token start position, in the raw buffer. */
const char *get_tok_start()
{
return m_tok_start;
return lookahead_token >= 0 ? m_tok_start_prev : m_tok_start;
}
void set_cpp_tok_start(const char *pos)
......@@ -2222,7 +2222,7 @@ class Lex_input_stream
/** Get the token start position, in the pre-processed buffer. */
const char *get_cpp_tok_start()
{
return m_cpp_tok_start;
return lookahead_token >= 0 ? m_cpp_tok_start_prev : m_cpp_tok_start;
}
/** Get the token end position, in the pre-processed buffer. */
......
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