diff --git a/mysql-test/r/fulltext.result b/mysql-test/r/fulltext.result index abab18e0e99..40f408b0fc8 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 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 diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 69bcf349f51..f9156d4ae70 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -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; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index b2490847dbc..e180d4ebab8 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -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; + diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 2adbc44eb12..88bed97cd35 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -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; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 4a4acde6e76..be7375fa3fa 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1411,6 +1411,17 @@ public: /** 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; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 6eb0d152617..e21ef0040fa 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -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) {