Commit 587a696a authored by Marc Alff's avatar Marc Alff

Bug#9801 Views: imperfect error message

Backport for 5.5

The root cause of this bug is that the grammar for GROUP BY clauses,
when using WITH CUBE or WITH ROLLUP, cause conflicts with the grammar
for VIEW, when using WITH CHECK OPTION.

The solution is to implement two token look ahead when parsing a WITH token,
to disambiguate the non standard WITH CUBE and WITH ROLLUP syntaxes.

Patch based on code from Marc Alff and Antony Curtis
parent e1be32db
......@@ -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 MySQL server version for the right syntax to use near 'WITH QUERY EXPANSION)' at line 1
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '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
......
......@@ -3958,3 +3958,16 @@ DROP TABLE t1;
# -----------------------------------------------------------------
# -- End of 5.1 tests.
# -----------------------------------------------------------------
drop table if exists t_9801;
drop view if exists v_9801;
create table t_9801 (s1 int);
create view v_9801 as
select sum(s1) from t_9801 with check option;
ERROR HY000: CHECK OPTION on non-updatable view 'test.v_9801'
create view v_9801 as
select sum(s1) from t_9801 group by s1 with check option;
ERROR HY000: CHECK OPTION on non-updatable view 'test.v_9801'
create view v_9801 as
select sum(s1) from t_9801 group by s1 with rollup with check option;
ERROR HY000: CHECK OPTION on non-updatable view 'test.v_9801'
drop table t_9801;
......@@ -3905,3 +3905,29 @@ DROP TABLE t1;
--echo # -----------------------------------------------------------------
--echo # -- End of 5.1 tests.
--echo # -----------------------------------------------------------------
#
# Bug#9801 (Views: imperfect error message)
#
--disable_warnings
drop table if exists t_9801;
drop view if exists v_9801;
--enable_warnings
create table t_9801 (s1 int);
--error ER_VIEW_NONUPD_CHECK
create view v_9801 as
select sum(s1) from t_9801 with check option;
--error ER_VIEW_NONUPD_CHECK
create view v_9801 as
select sum(s1) from t_9801 group by s1 with check option;
--error ER_VIEW_NONUPD_CHECK
create view v_9801 as
select sum(s1) from t_9801 group by s1 with rollup with check option;
drop table t_9801;
......@@ -24,6 +24,8 @@
#include "sp.h"
#include "sp_head.h"
static int lex_one_token(void *arg, void *yythd);
/*
We are using pointer to this variable for distinguishing between assignment
to NEW row field (when parsing trigger definition) and structured variable.
......@@ -117,6 +119,8 @@ Lex_input_stream::Lex_input_stream(THD *thd,
yylineno(1),
yytoklen(0),
yylval(NULL),
lookahead_token(-1),
lookahead_yylval(NULL),
m_ptr(buffer),
m_tok_start(NULL),
m_tok_end(NULL),
......@@ -779,6 +783,60 @@ bool consume_comment(Lex_input_stream *lip, int remaining_recursions_permitted)
*/
int MYSQLlex(void *arg, void *yythd)
{
THD *thd= (THD *)yythd;
Lex_input_stream *lip= & thd->m_parser_state->m_lip;
YYSTYPE *yylval=(YYSTYPE*) arg;
int token;
if (lip->lookahead_token >= 0)
{
/*
The next token was already parsed in advance,
return it.
*/
token= lip->lookahead_token;
lip->lookahead_token= -1;
*yylval= *(lip->lookahead_yylval);
lip->lookahead_yylval= NULL;
return token;
}
token= lex_one_token(arg, yythd);
switch(token) {
case WITH:
/*
Parsing 'WITH' 'ROLLUP' or 'WITH' 'CUBE' requires 2 look ups,
which makes the grammar LALR(2).
Replace by a single 'WITH_ROLLUP' or 'WITH_CUBE' token,
to transform the grammar into a LALR(1) grammar,
which sql_yacc.yy can process.
*/
token= lex_one_token(arg, yythd);
switch(token) {
case CUBE_SYM:
return WITH_CUBE_SYM;
case ROLLUP_SYM:
return WITH_ROLLUP_SYM;
default:
/*
Save the token following 'WITH'
*/
lip->lookahead_yylval= lip->yylval;
lip->yylval= NULL;
lip->lookahead_token= token;
return WITH;
}
break;
default:
break;
}
return token;
}
int lex_one_token(void *arg, void *yythd)
{
reg1 uchar c= 0;
bool comment_closed;
......
......@@ -1411,6 +1411,17 @@ class Lex_input_stream
/** Interface with bison, value of the last token parsed. */
LEX_YYSTYPE yylval;
/**
LALR(2) resolution, look ahead token.
Value of the next token to return, if any,
or -1, if no token was parsed in advance.
Note: 0 is a legal token, and represents YYEOF.
*/
int lookahead_token;
/** LALR(2) resolution, value of the look ahead token.*/
LEX_YYSTYPE lookahead_yylval;
private:
/** Pointer to the current position in the raw input stream. */
const char *m_ptr;
......
......@@ -521,10 +521,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%pure_parser /* We have threads */
/*
Currently there are 169 shift/reduce conflicts.
Currently there are 168 shift/reduce conflicts.
We should not introduce new conflicts any more.
*/
%expect 169
%expect 168
/*
Comments for TOKENS.
......@@ -1118,6 +1118,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token WHERE /* SQL-2003-R */
%token WHILE_SYM
%token WITH /* SQL-2003-R */
%token WITH_CUBE_SYM /* INTERNAL */
%token WITH_ROLLUP_SYM /* INTERNAL */
%token WORK_SYM /* SQL-2003-N */
%token WRAPPER_SYM
%token WRITE_SYM /* SQL-2003-N */
......@@ -9153,8 +9155,15 @@ group_list:
olap_opt:
/* empty */ {}
| WITH CUBE_SYM
| WITH_CUBE_SYM
{
/*
'WITH CUBE' is reserved in the MySQL syntax, but not implemented,
and cause LALR(2) conflicts.
This syntax is not standard.
MySQL syntax: GROUP BY col1, col2, col3 WITH CUBE
SQL-2003: GROUP BY ... CUBE(col1, col2, col3)
*/
LEX *lex=Lex;
if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
{
......@@ -9164,10 +9173,17 @@ olap_opt:
}
lex->current_select->olap= CUBE_TYPE;
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "CUBE");
MYSQL_YYABORT; /* To be deleted in 5.1 */
MYSQL_YYABORT;
}
| WITH ROLLUP_SYM
| WITH_ROLLUP_SYM
{
/*
'WITH ROLLUP' is needed for backward compatibility,
and cause LALR(2) conflicts.
This syntax is not standard.
MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
*/
LEX *lex= Lex;
if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
{
......
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