summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/cte_nonrecursive.result55
-rw-r--r--mysql-test/r/fulltext.result2
-rw-r--r--mysql-test/t/cte_nonrecursive.test29
-rw-r--r--sql/sql_lex.h4
4 files changed, 87 insertions, 3 deletions
diff --git a/mysql-test/r/cte_nonrecursive.result b/mysql-test/r/cte_nonrecursive.result
index 7c6c6e8dedd..c1d7fd0a615 100644
--- a/mysql-test/r/cte_nonrecursive.result
+++ b/mysql-test/r/cte_nonrecursive.result
@@ -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
diff --git a/mysql-test/r/fulltext.result b/mysql-test/r/fulltext.result
index 5118cc38fdf..709e91cca4d 100644
--- a/mysql-test/r/fulltext.result
+++ b/mysql-test/r/fulltext.result
@@ -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
diff --git a/mysql-test/t/cte_nonrecursive.test b/mysql-test/t/cte_nonrecursive.test
index f994781548f..cbe4f8b855d 100644
--- a/mysql-test/t/cte_nonrecursive.test
+++ b/mysql-test/t/cte_nonrecursive.test
@@ -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
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 03c06b9ae0f..bdf52e8ef7b 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -2176,7 +2176,7 @@ public:
/** 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 @@ public:
/** 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. */