List:Commits« Previous MessageNext Message »
From:kgeorge Date:October 19 2006 1:09pm
Subject:bk commit into 5.0 tree (gkodinov:1.2302) BUG#21809
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of kgeorge. When kgeorge 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, 2006-10-19 14:09:24+03:00, gkodinov@stripped +8 -0
  Bug #21809: Error 1356 while selecting from view with grouping though underlying
              select OK.
  The SQL parser was using Item::name to transfer user defined function attributes
  to the user defined function. It was not distinguishing between user defined 
  function call arguments and stored procedure call arguments. Setting Item::name 
  was causing Item::print() method to print the argument as quoted identifier and 
  caused views that reference such functions (and rely on Item::print() for the 
  text of the view to store) to throw an undefined identifier error.
  Fixed by making a designated member of Item for user defined functions 
  attributes and properly detecting using AS clause in stored procedure arguments
  as an error.

  mysql-test/r/sp.result@stripped, 2006-10-19 14:09:12+03:00, gkodinov@stripped +17 -0
    Bug #21809: Error 1356 while selecting from view with grouping though underlying
                select OK.
     - test case

  mysql-test/t/sp.test@stripped, 2006-10-19 14:09:13+03:00, gkodinov@stripped +25 -0
    Bug #21809: Error 1356 while selecting from view with grouping though underlying
                select OK.
     - test case

  sql/item.cc@stripped, 2006-10-19 14:09:14+03:00, gkodinov@stripped +15 -1
    Bug #21809: Error 1356 while selecting from view with grouping though underlying
                select OK.
     - don't use Item::name for storing user defined function argument attributes.

  sql/item.h@stripped, 2006-10-19 14:09:14+03:00, gkodinov@stripped +5 -0
    Bug #21809: Error 1356 while selecting from view with grouping though underlying
                select OK.
     - don't use Item::name for storing user defined function argument attributes.

  sql/item_func.cc@stripped, 2006-10-19 14:09:15+03:00, gkodinov@stripped +2 -2
    Bug #21809: Error 1356 while selecting from view with grouping though underlying
                select OK.
     - don't use Item::name for storing user defined function argument attributes.

  sql/sql_lex.cc@stripped, 2006-10-19 14:09:16+03:00, gkodinov@stripped +2 -0
    Bug #21809: Error 1356 while selecting from view with grouping though underlying
                select OK.
     - don't use Item::name for storing user defined function argument attributes.

  sql/sql_lex.h@stripped, 2006-10-19 14:09:17+03:00, gkodinov@stripped +2 -0
    Bug #21809: Error 1356 while selecting from view with grouping though underlying
                select OK.
     - don't use Item::name for storing user defined function argument attributes.

  sql/sql_yacc.yy@stripped, 2006-10-19 14:09:17+03:00, gkodinov@stripped +23 -13
    Bug #21809: Error 1356 while selecting from view with grouping though underlying
                select OK.
     - don't use Item::name for storing udf_attribute.
     - don't allow AS clause for stored procedure args
     - fix bison duplicate symbol warnings

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	gkodinov
# Host:	macbook.gmz
# Root:	/Users/kgeorge/mysql/work/B21809-5.0-opt

--- 1.235/sql/item.cc	2006-10-19 14:09:43 +03:00
+++ 1.236/sql/item.cc	2006-10-19 14:09:43 +03:00
@@ -607,7 +607,9 @@ bool Item::check_cols(uint c)
 }
 
 
-void Item::set_name(const char *str, uint length, CHARSET_INFO *cs)
+static void set_name_buffer(const char *str, uint length, CHARSET_INFO *cs,
+                            bool is_autogenerated_name, 
+                            my_string &name, uint &name_length)
 {
   if (!length)
   {
@@ -643,6 +645,18 @@ void Item::set_name(const char *str, uin
   }
   else
     name= sql_strmake(str, (name_length= min(length,MAX_ALIAS_NAME)));
+}
+
+void Item::set_name(const char *str, uint length, CHARSET_INFO *cs)
+{
+  set_name_buffer (str, length, cs, is_autogenerated_name, 
+                   name, name_length);
+}
+
+void Item::set_udf_attribute(const char *str, uint length, CHARSET_INFO *cs)
+{
+  set_name_buffer (str, length, cs, is_autogenerated_name, 
+                   udf_attribute, udf_attribute_length);
 }
 
 

--- 1.209/sql/item.h	2006-10-19 14:09:43 +03:00
+++ 1.210/sql/item.h	2006-10-19 14:09:43 +03:00
@@ -462,6 +462,10 @@ public:
   my_string name;			/* Name from select */
   /* Original item name (if it was renamed)*/
   my_string orig_name;
+  /* attribute name for an user defined function (UDF) */
+  my_string udf_attribute;
+  /* length of udf_attribute */
+  uint udf_attribute_length;
   Item *next;
   uint32 max_length;
   uint name_length;                     /* Length of name */
@@ -496,6 +500,7 @@ public:
 #endif
   }		/*lint -e1509 */
   void set_name(const char *str, uint length, CHARSET_INFO *cs);
+  void set_udf_attribute(const char *str, uint length, CHARSET_INFO *cs);
   void rename(char *new_name);
   void init_make_field(Send_field *tmp_field,enum enum_field_types type);
   virtual void cleanup();

--- 1.304/sql/item_func.cc	2006-10-19 14:09:43 +03:00
+++ 1.305/sql/item_func.cc	2006-10-19 14:09:43 +03:00
@@ -2686,8 +2686,8 @@ udf_handler::fix_fields(THD *thd, Item_r
       f_args.args[i]=0;
       f_args.lengths[i]= arguments[i]->max_length;
       f_args.maybe_null[i]= (char) arguments[i]->maybe_null;
-      f_args.attributes[i]= arguments[i]->name;
-      f_args.attribute_lengths[i]= arguments[i]->name_length;
+      f_args.attributes[i]= arguments[i]->udf_attribute;
+      f_args.attribute_lengths[i]= arguments[i]->udf_attribute_length;
 
       switch(arguments[i]->type()) {
       case Item::STRING_ITEM:			// Constant string !

--- 1.201/sql/sql_lex.cc	2006-10-19 14:09:44 +03:00
+++ 1.202/sql/sql_lex.cc	2006-10-19 14:09:44 +03:00
@@ -163,6 +163,7 @@ void lex_start(THD *thd, uchar *buf,uint
   lex->select_lex.ftfunc_list= &lex->select_lex.ftfunc_list_alloc;
   lex->select_lex.group_list.empty();
   lex->select_lex.order_list.empty();
+  lex->select_lex.udf_list.empty();
   lex->current_select= &lex->select_lex;
   lex->yacc_yyss=lex->yacc_yyvs=0;
   lex->ignore_space=test(thd->variables.sql_mode & MODE_IGNORE_SPACE);
@@ -1166,6 +1167,7 @@ void st_select_lex::init_select()
   braces= 0;
   when_list.empty();
   expr_list.empty();
+  udf_list.empty();
   interval_list.empty();
   use_index.empty();
   ftfunc_list_alloc.empty();

--- 1.228/sql/sql_lex.h	2006-10-19 14:09:44 +03:00
+++ 1.229/sql/sql_lex.h	2006-10-19 14:09:44 +03:00
@@ -580,6 +580,8 @@ public:
   /* exclude this select from check of unique_table() */
   bool exclude_from_table_unique_test;
 
+  List<udf_func>     udf_list;                  /* udf function calls stack */
+
   void init_query();
   void init_select();
   st_select_lex_unit* master_unit();

--- 1.491/sql/sql_yacc.yy	2006-10-19 14:09:44 +03:00
+++ 1.492/sql/sql_yacc.yy	2006-10-19 14:09:44 +03:00
@@ -650,11 +650,8 @@ bool my_yyoverflow(short **a, YYSTYPE **
 %token  UNIX_TIMESTAMP
 %token  UNKNOWN_SYM
 %token  UNLOCK_SYM
-%token  UNLOCK_SYM
 %token  UNSIGNED
 %token  UNTIL_SYM
-%token  UNTIL_SYM
-%token  UPDATE_SYM
 %token  UPDATE_SYM
 %token  UPGRADE_SYM
 %token  USAGE
@@ -764,7 +761,7 @@ bool my_yyoverflow(short **a, YYSTYPE **
 
 %type <item_list>
 	expr_list udf_expr_list udf_expr_list2 when_list
-	ident_list ident_list_arg
+	ident_list ident_list_arg opt_expr_list
 
 %type <var_type>
         option_type opt_var_type opt_var_ident_type
@@ -4724,7 +4721,7 @@ simple_expr:
 	  { $$= new Item_func_trim($5,$3); }
 	| TRUNCATE_SYM '(' expr ',' expr ')'
 	  { $$= new Item_func_round($3,$5,1); }
-	| ident '.' ident '(' udf_expr_list ')'
+	| ident '.' ident '(' opt_expr_list ')'
 	  {
 	    LEX *lex= Lex;
 	    sp_name *name= new sp_name($1, $3);
@@ -4741,27 +4738,27 @@ simple_expr:
           {
 #ifdef HAVE_DLOPEN
             udf_func *udf= 0;
+            LEX *lex= Lex;
             if (using_udf_functions &&
                 (udf= find_udf($1.str, $1.length)) &&
                 udf->type == UDFTYPE_AGGREGATE)
             {
-              LEX *lex= Lex;
               if (lex->current_select->inc_in_sum_expr())
               {
                 yyerror(ER(ER_SYNTAX_ERROR));
                 YYABORT;
               }
             }
-            $<udf>$= udf;
+            lex->current_select->udf_list.push_front(udf);
 #endif
           }
           udf_expr_list ')'
           {
 #ifdef HAVE_DLOPEN
-            udf_func *udf= $<udf>3;
-            SELECT_LEX *sel= Select;
+            udf_func *udf;
+            LEX *lex= Lex;
 
-            if (udf)
+            if (NULL != (udf= lex->current_select->udf_list.pop()))
             {
               if (udf->type == UDFTYPE_AGGREGATE)
                 Select->in_sum_expr--;
@@ -4988,13 +4985,21 @@ udf_expr_list3:
 udf_expr:
 	remember_name expr remember_end select_alias
 	{
+          LEX *lex= Lex;
+          udf_func *udf= lex->current_select->udf_list.head();
 	  if ($4.str)
           {
+            if (!udf)
+            {
+              yyerror(ER(ER_SYNTAX_ERROR));
+              YYABORT;
+            }
+              
             $2->is_autogenerated_name= FALSE;
-	    $2->set_name($4.str, $4.length, system_charset_info);
+	    $2->set_udf_attribute($4.str, $4.length, system_charset_info);
           }
-	  else
-	    $2->set_name($1, (uint) ($3 - $1), YYTHD->charset());
+	  else if (udf)
+	    $2->set_udf_attribute($1, (uint) ($3 - $1), YYTHD->charset());
 	  $$= $2;
 	}
 	;
@@ -5112,6 +5117,11 @@ cast_type:
         | TIME_SYM		{ $$=ITEM_CAST_TIME; Lex->charset= NULL;
Lex->dec=Lex->length= (char*)0; }
         | DATETIME		{ $$=ITEM_CAST_DATETIME; Lex->charset= NULL;
Lex->dec=Lex->length= (char*)0; }
         | DECIMAL_SYM float_options { $$=ITEM_CAST_DECIMAL; Lex->charset= NULL; }
+	;
+
+opt_expr_list:
+	/* empty */ { $$= NULL; }
+	| expr_list { $$= $1;}
 	;
 
 expr_list:

--- 1.212/mysql-test/r/sp.result	2006-10-19 14:09:44 +03:00
+++ 1.213/mysql-test/r/sp.result	2006-10-19 14:09:44 +03:00
@@ -5458,3 +5458,20 @@ CHF
 DROP FUNCTION bug21493|
 DROP TABLE t3,t4|
 drop table t1,t2;
+CREATE TABLE t1(a INT, b INT);
+INSERT INTO t1 values (1,1),(2,2);
+CREATE FUNCTION fn(a int) RETURNS int DETERMINISTIC
+BEGIN
+RETURN a;
+END
+||
+CREATE VIEW v1 AS SELECT a, fn(MIN(b)) as c FROM t1 GROUP BY a;
+SELECT a,c FROM v1;
+a	c
+1	1
+2	2
+SELECT a, fn(MIN(b) xx) as c FROM t1 GROUP BY a;
+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 'xx) as c FROM t1 GROUP BY a'
at line 1
+DROP VIEW v1;
+DROP TABLE t1;
+DROP FUNCTION fn;

--- 1.200/mysql-test/t/sp.test	2006-10-19 14:09:44 +03:00
+++ 1.201/mysql-test/t/sp.test	2006-10-19 14:09:44 +03:00
@@ -6401,3 +6401,28 @@ DROP TABLE t3,t4|
 # practical, or create table t3, t4 etc temporarily (and drop them).
 delimiter ;|
 drop table t1,t2;
+
+#
+# Bug #21809: Error 1356 while selecting from view with grouping though 
+#              underlying select OK.
+#
+CREATE TABLE t1(a INT, b INT); INSERT INTO t1 values (1,1),(2,2);
+
+DELIMITER ||;
+CREATE FUNCTION fn(a int) RETURNS int DETERMINISTIC
+BEGIN
+    RETURN a;
+END
+||
+DELIMITER ;||
+
+CREATE VIEW v1 AS SELECT a, fn(MIN(b)) as c FROM t1 GROUP BY a;
+
+SELECT a,c FROM v1;
+
+--error 1064
+SELECT a, fn(MIN(b) xx) as c FROM t1 GROUP BY a;
+
+DROP VIEW v1;
+DROP TABLE t1;
+DROP FUNCTION fn;
Thread
bk commit into 5.0 tree (gkodinov:1.2302) BUG#21809kgeorge19 Oct