List:Commits« Previous MessageNext Message »
From:marc.alff Date:March 14 2008 7:07pm
Subject:bk commit into 6.0 tree (malff:1.2608) BUG#9801
View as plain text  
Below is the list of changes that have just been committed into a local
6.0 repository of malff.  When malff does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2008-03-14 13:07:46-06:00, malff@stripped. +6 -0
  Bug#9801 (Views: imperfect error message)
  
  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

  mysql-test/r/fulltext.result@stripped, 2008-03-14 13:07:42-06:00, malff@stripped. +1 -1
    Bug#9801 (Views: imperfect error message)

  mysql-test/r/view.result@stripped, 2008-03-14 13:07:42-06:00, malff@stripped. +13 -0
    Bug#9801 (Views: imperfect error message)

  mysql-test/t/view.test@stripped, 2008-03-14 13:07:43-06:00, malff@stripped. +26 -0
    Bug#9801 (Views: imperfect error message)

  sql/sql_lex.cc@stripped, 2008-03-14 13:07:43-06:00, malff@stripped. +59 -0
    Bug#9801 (Views: imperfect error message)

  sql/sql_lex.h@stripped, 2008-03-14 13:07:43-06:00, malff@stripped. +6 -0
    Bug#9801 (Views: imperfect error message)

  sql/sql_yacc.yy@stripped, 2008-03-14 13:07:43-06:00, malff@stripped. +21 -7
    Bug#9801 (Views: imperfect error message)

diff -Nrup a/mysql-test/r/fulltext.result b/mysql-test/r/fulltext.result
--- a/mysql-test/r/fulltext.result	2007-11-02 03:26:08 -06:00
+++ b/mysql-test/r/fulltext.result	2008-03-14 13:07:42 -06:00
@@ -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 -Nrup a/mysql-test/r/view.result b/mysql-test/r/view.result
--- a/mysql-test/r/view.result	2008-02-22 11:26:36 -07:00
+++ b/mysql-test/r/view.result	2008-03-14 13:07:42 -06:00
@@ -3704,3 +3704,16 @@ DROP TABLE t1;
 # End of test case for Bug#26676.
 
 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 -Nrup a/mysql-test/t/view.test b/mysql-test/t/view.test
--- a/mysql-test/t/view.test	2008-02-22 11:26:36 -07:00
+++ b/mysql-test/t/view.test	2008-03-14 13:07:43 -06:00
@@ -3578,3 +3578,29 @@ DROP TABLE t1;
 --echo
 
 --echo End of 5.1 tests.
+
+#
+# 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 -Nrup a/sql/sql_lex.cc b/sql/sql_lex.cc
--- a/sql/sql_lex.cc	2007-12-21 12:27:46 -07:00
+++ b/sql/sql_lex.cc	2008-03-14 13:07:43 -06:00
@@ -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 *
   yylineno(1),
   yytoklen(0),
   yylval(NULL),
+  lookahead_token(END_OF_INPUT),
+  lookahead_yylval(NULL),
   m_ptr(buffer),
   m_tok_start(NULL),
   m_tok_end(NULL),
@@ -710,6 +714,7 @@ static inline uint int_token(const char 
   return ((uchar) str[-1] <= (uchar) cmp[-1]) ? smaller : bigger;
 }
 
+
 /*
   MYSQLlex remember the following states from the following MYSQLlex()
 
@@ -719,6 +724,60 @@ static inline uint int_token(const char 
 */
 
 int MYSQLlex(void *arg, void *yythd)
+{
+  THD *thd= (THD *)yythd;
+  Lex_input_stream *lip= thd->m_lip;
+  YYSTYPE *yylval=(YYSTYPE*) arg;
+  int token;
+
+  if (lip->lookahead_token != END_OF_INPUT)
+  {
+    /*
+      The next token was already parsed in advance,
+      return it.
+    */
+    token= lip->lookahead_token;
+    lip->lookahead_token= END_OF_INPUT;
+    *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;
   bool comment_closed;
diff -Nrup a/sql/sql_lex.h b/sql/sql_lex.h
--- a/sql/sql_lex.h	2008-02-05 06:55:51 -07:00
+++ b/sql/sql_lex.h	2008-03-14 13:07:43 -06:00
@@ -1370,6 +1370,12 @@ public:
   /** Interface with bison, value of the last token parsed. */
   LEX_YYSTYPE yylval;
 
+  /** LALR(2) resolution, look ahead token.*/
+  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 -Nrup a/sql/sql_yacc.yy b/sql/sql_yacc.yy
--- a/sql/sql_yacc.yy	2008-02-29 02:01:37 -07:00
+++ b/sql/sql_yacc.yy	2008-03-14 13:07:43 -06:00
@@ -512,12 +512,10 @@ bool my_yyoverflow(short **a, YYSTYPE **
 
 %pure_parser                                    /* We have threads */
 /*
-  Currently there are 177 shift/reduce conflicts.
-  Currently there are 168 shift/reduce conflicts.
+  Currently there are 167 shift/reduce conflicts.
   We should not introduce new conflicts any more.
 */
-%expect 177
-%expect 168
+%expect 167
 
 /*
    Comments for TOKENS.
@@ -1101,6 +1099,8 @@ bool my_yyoverflow(short **a, YYSTYPE **
 %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 */
@@ -8284,8 +8284,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)
             {
@@ -8295,10 +8302,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)
             {
Thread
bk commit into 6.0 tree (malff:1.2608) BUG#9801marc.alff14 Mar