Skip to content

Commit 12c80df

Browse files
committed
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+.
1 parent 4ad148b commit 12c80df

File tree

4 files changed

+87
-3
lines changed

4 files changed

+87
-3
lines changed

mysql-test/r/cte_nonrecursive.result

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,4 +1964,59 @@ call p1();
19641964
ERROR 42S22: Unknown column 'a' in 'field list'
19651965
drop procedure p1;
19661966
drop table t1,t2;
1967+
#
1968+
# MDEV-20411: SP containing only one SELECT with WITH clause
1969+
#
1970+
create procedure sp1 ()
1971+
with cte as (select 1 as a) select * from cte;
1972+
call sp1();
1973+
a
1974+
1
1975+
call sp1();
1976+
a
1977+
1
1978+
create table t1 (a int);
1979+
insert into t1 values (3), (7), (1), (7), (1), (1), (3), (1), (5);
1980+
create procedure sp2 ()
1981+
with cte as (select * from t1) select * from cte;
1982+
call sp2();
1983+
a
1984+
3
1985+
7
1986+
1
1987+
7
1988+
1
1989+
1
1990+
3
1991+
1
1992+
5
1993+
call sp2();
1994+
a
1995+
3
1996+
7
1997+
1
1998+
7
1999+
1
2000+
1
2001+
3
2002+
1
2003+
5
2004+
create procedure sp3 ()
2005+
with cte as (select * from t1 group by a) select * from cte;
2006+
call sp3();
2007+
a
2008+
1
2009+
3
2010+
5
2011+
7
2012+
call sp3();
2013+
a
2014+
1
2015+
3
2016+
5
2017+
7
2018+
drop procedure sp1;
2019+
drop procedure sp2;
2020+
drop procedure sp3;
2021+
drop table t1;
19672022
# End of 10.2 tests

mysql-test/r/fulltext.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ a b
4949
Full-text indexes are called collections
5050
Only MyISAM tables support collections
5151
select * from t1 where MATCH(a,b) AGAINST ("indexes" IN BOOLEAN MODE WITH QUERY EXPANSION);
52-
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
52+
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
5353
explain select * from t1 where MATCH(a,b) AGAINST ("collections");
5454
id select_type table type possible_keys key key_len ref rows Extra
5555
1 SIMPLE t1 fulltext a a 0 1 Using where

mysql-test/t/cte_nonrecursive.test

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,4 +1463,33 @@ drop procedure p1;
14631463

14641464
drop table t1,t2;
14651465

1466+
1467+
--echo #
1468+
--echo # MDEV-20411: SP containing only one SELECT with WITH clause
1469+
--echo #
1470+
1471+
create procedure sp1 ()
1472+
with cte as (select 1 as a) select * from cte;
1473+
call sp1();
1474+
call sp1();
1475+
1476+
create table t1 (a int);
1477+
insert into t1 values (3), (7), (1), (7), (1), (1), (3), (1), (5);
1478+
1479+
create procedure sp2 ()
1480+
with cte as (select * from t1) select * from cte;
1481+
call sp2();
1482+
call sp2();
1483+
1484+
create procedure sp3 ()
1485+
with cte as (select * from t1 group by a) select * from cte;
1486+
call sp3();
1487+
call sp3();
1488+
1489+
drop procedure sp1;
1490+
drop procedure sp2;
1491+
drop procedure sp3;
1492+
1493+
drop table t1;
1494+
14661495
--echo # End of 10.2 tests

sql/sql_lex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,7 +2176,7 @@ class Lex_input_stream
21762176
/** Get the token start position, in the raw buffer. */
21772177
const char *get_tok_start()
21782178
{
2179-
return m_tok_start;
2179+
return lookahead_token >= 0 ? m_tok_start_prev : m_tok_start;
21802180
}
21812181

21822182
void set_cpp_tok_start(const char *pos)
@@ -2222,7 +2222,7 @@ class Lex_input_stream
22222222
/** Get the token start position, in the pre-processed buffer. */
22232223
const char *get_cpp_tok_start()
22242224
{
2225-
return m_cpp_tok_start;
2225+
return lookahead_token >= 0 ? m_cpp_tok_start_prev : m_cpp_tok_start;
22262226
}
22272227

22282228
/** Get the token end position, in the pre-processed buffer. */

0 commit comments

Comments
 (0)