List:Commits« Previous MessageNext Message »
From:ahristov Date:August 21 2006 2:52pm
Subject:bk commit into 5.1 tree (andrey:1.2281) BUG#16394
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of andrey. When andrey 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-08-21 16:52:16+02:00, andrey@stripped +3 -0
  Cleanup patch for handling of subselects in commands which cannot
  handle them.
  
  Problem:
  CREATE|ALTER EVENT, HANDLER READ, KILL, Partitioning uses `expr` from the
  parser. This rule comes with all the rings and bells including subqueries.
  However, these commands are not subquery safe. For this reason there are two
  fuse checks in the parser. They were checking by command id. CREATE EVENT
  should forbid subquery is the fix for
  bug#16394 Events: Crash if schedule contains SELECT
  The fix has been incorporated as part of the patch for WL#3337 (Event scheduler
  new architecture).
  
  Solution:
  A new flag was added to LEX command_forbids_subselect. The fuse checks were
  changed. The commands are responsible to set the value to true whenever
  they can't handle subselects.

  sql/sql_lex.cc@stripped, 2006-08-21 16:52:11+02:00, andrey@stripped +1 -0
    initialize the variable

  sql/sql_lex.h@stripped, 2006-08-21 16:52:11+02:00, andrey@stripped +8 -0
    Add a new flag whether the parser should allow a subselect when
    parsing. This is temporarily turned on by commands like CREATE|ALTER EVENT,
    HA_READ, KILL. Could be used by other parts which reuse `expr` rule of the
    grammar and should not allow subqueries as part of it.

  sql/sql_yacc.yy@stripped, 2006-08-21 16:52:12+02:00, andrey@stripped +20 -12
    Forbid subselects in some commands in a better way.
    CREATE|ALTER EVENT, HANDLER READ, KILL, are not subselect
    safe for parameters and therefore they should be forbidden already in
    the parser.
    This patch makes it easier for the developer to add new commands in that
    sense similar to the mentioned above.

# 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:	andrey
# Host:	example.com
# Root:	/work/mysql-5.1-runtime-wl3337

--- 1.193/sql/sql_lex.cc	2006-08-21 16:52:26 +02:00
+++ 1.194/sql/sql_lex.cc	2006-08-21 16:52:26 +02:00
@@ -175,6 +175,7 @@ void lex_start(THD *thd, const uchar *bu
   lex->proc_list.first= 0;
   lex->escape_used= FALSE;
   lex->reset_query_tables_list(FALSE);
+  lex->command_forbids_subselect= FALSE;
 
   lex->name= 0;
   lex->event_parse_data= NULL;

--- 1.239/sql/sql_lex.h	2006-08-21 16:52:26 +02:00
+++ 1.240/sql/sql_lex.h	2006-08-21 16:52:26 +02:00
@@ -958,6 +958,14 @@ typedef struct st_lex : public Query_tab
   */
   nesting_map allow_sum_func;
   enum_sql_command sql_command;
+  /*
+    Usually `expr` rule of yacc is quite reused but some commands better
+    not support subqueries which comes standard with this rule, like
+    KILL, HA_READ, CREATE/ALTER EVENT etc. Set this to `true` to get
+    syntax error back.
+  */
+  bool command_forbids_subselect;
+
   thr_lock_type lock_option;
   enum SSL_type ssl_type;			/* defined in violite.h */
   enum my_lex_states next_state;

--- 1.493/sql/sql_yacc.yy	2006-08-21 16:52:26 +02:00
+++ 1.494/sql/sql_yacc.yy	2006-08-21 16:52:26 +02:00
@@ -1302,8 +1302,9 @@ event_tail:
             $<ulong_num>$= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES;
             YYTHD->client_capabilities &= (~CLIENT_MULTI_QUERIES);
 
-            /* We need that for disallowing subqueries */
             Lex->sql_command= SQLCOM_CREATE_EVENT;
+            /* We need that for disallowing subqueries */
+            Lex->command_forbids_subselect= TRUE;
           }
           ON SCHEDULE_SYM ev_schedule_time
           opt_ev_on_completion
@@ -1325,6 +1326,7 @@ event_tail:
               can overwrite it
             */
             Lex->sql_command= SQLCOM_CREATE_EVENT;
+            Lex->command_forbids_subselect= FALSE;
           }
 
 
@@ -4697,8 +4699,9 @@ alter:
             $<ulong_num>$= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES;
             YYTHD->client_capabilities &= ~CLIENT_MULTI_QUERIES;
 
-            /* we need that for disallowing subqueries */
             Lex->sql_command= SQLCOM_ALTER_EVENT;
+            /* we need that for disallowing subqueries */
+            Lex->command_forbids_subselect= TRUE;
           }
           ev_alter_on_schedule_completion
           opt_ev_rename_to
@@ -4724,6 +4727,7 @@ alter:
               can overwrite it
             */
             Lex->sql_command= SQLCOM_ALTER_EVENT;
+            Lex->command_forbids_subselect= FALSE;
           }
         | ALTER TABLESPACE alter_tablespace_info
           {
@@ -7048,10 +7052,7 @@ select_derived2:
         {
 	  LEX *lex= Lex;
 	  lex->derived_tables|= DERIVED_SUBQUERY;
-          if (lex->sql_command == SQLCOM_HA_READ ||
-              lex->sql_command == SQLCOM_KILL ||
-              lex->sql_command == SQLCOM_CREATE_EVENT ||
-              lex->sql_command == SQLCOM_ALTER_EVENT)
+          if (lex->command_forbids_subselect)
 	  {
 	    yyerror(ER(ER_SYNTAX_ERROR));
 	    YYABORT;
@@ -8554,11 +8555,17 @@ purge_option:
 /* kill threads */
 
 kill:
-	KILL_SYM { Lex->sql_command= SQLCOM_KILL; } kill_option expr
+	KILL_SYM
+        {
+          Lex->sql_command= SQLCOM_KILL;
+          Lex->command_forbids_subselect= TRUE;
+        }
+        kill_option expr
 	{
 	  LEX *lex=Lex;
 	  lex->value_list.empty();
 	  lex->value_list.push_front($4);
+          Lex->command_forbids_subselect= FALSE;
 	};
 
 kill_option:
@@ -10038,6 +10045,7 @@ handler:
 	    my_error(ER_SP_BADSTATEMENT, MYF(0), "HANDLER");
 	    YYABORT;
 	  }
+          lex->command_forbids_subselect= TRUE;
 	  lex->sql_command = SQLCOM_HA_READ;
 	  lex->ha_rkey_mode= HA_READ_KEY_EXACT;	/* Avoid purify warnings */
 	  lex->current_select->select_limit= new Item_int((int32) 1);
@@ -10045,7 +10053,10 @@ handler:
 	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
 	    YYABORT;
         }
-        handler_read_or_scan where_clause opt_limit_clause {}
+        handler_read_or_scan where_clause opt_limit_clause
+        {
+          Lex->command_forbids_subselect= FALSE;
+        }
         ;
 
 handler_read_or_scan:
@@ -10670,10 +10681,7 @@ subselect_start:
 	'(' SELECT_SYM
 	{
 	  LEX *lex=Lex;
-          if (lex->sql_command == SQLCOM_HA_READ ||
-              lex->sql_command == SQLCOM_KILL ||
-              lex->sql_command == SQLCOM_CREATE_EVENT ||
-              lex->sql_command == SQLCOM_ALTER_EVENT)
+          if (lex->command_forbids_subselect)
 	  {
             yyerror(ER(ER_SYNTAX_ERROR));
 	    YYABORT;
Thread
bk commit into 5.1 tree (andrey:1.2281) BUG#16394ahristov21 Aug