MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:konstantin Date:March 4 2007 11:44am
Subject:bk commit into 5.0 tree (kostja:1.2438) BUG#26570
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of kostja. When kostja 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, 2007-03-04 14:44:46+03:00, kostja@stripped +10 -0
  A fix for Bug#26570 "valgrind leak in sp_head"
  
  The legend: on a replication slave, in case a trigger creation
  was filtered out because of application of replicate-do-table/
  replicate-ignore-table rule, the parsed definition of a trigger was not 
  cleaned up properly. LEX::sphead member was left around and leaked 
  memory. Until the actual implementation of support of 
  replicate-ignore-table rules for triggers by the patch for Bug 24478 it 
  was never the case that "case SQLCOM_CREATE_TRIGGER"
  was not executed once a trigger was parsed,
  so the deletion of lex->sphead there worked and the memory did not leak.
  
  The fix: 
  
  The real cause of the bug is that there is no 1 or 2 places where
  we can clean up the main LEX after parse. And the reason we 
  can not have just one or two places where we clean up the LEX is
  asymmetric behaviour of MYSQLparse in case of success or error. 
  
  One of the root causes of this behaviour is the code in Item::Item()
  constructor. There, a newly created item adds itself to THD::free_list
  - a single-linked list of Items used in a statement. Yuck. This code
  is unaware that we may have more than one statement active at a time,
  and always assumes that the free_list of the current statement is
  located in THD::free_list. One day we need to be able to explicitly
  allocate an item in a given Query_arena.
  Thus, when parsing a definition of a stored procedure, like
  CREATE PROCEDURE p1() BEGIN SELECT a FROM t1; SELECT b FROM t1; END;
  we actually need to reset THD::mem_root, THD::free_list and THD::lex
  to parse the nested procedure statement (SELECT *).
  The actual reset and restore is implemented in semantic actions
  attached to sp_proc_stmt grammar rule.
  The problem is that in case of a parsing error inside a nested statement
  Bison generated parser would abort immediately, without executing the
  restore part of the semantic action. This would leave THD in an 
  in-the-middle-of-parsing state.
  This is why we couldn't have had a single place where we clean up the LEX
  after MYSQLparse - in case of an error we needed to do a clean up
  immediately, in case of success a clean up could have been delayed.
  This left the door open for a memory leak.
  
  One of the following possibilities were considered when working on a fix:
  - patch the replication logic to do the clean up. Rejected
  as breaks module borders, replication code should not need to know the
  gory details of clean up procedure after CREATE TRIGGER.
  - wrap MYSQLparse with a function that would do a clean up.
  Rejected as ideally we should fix the problem when it happens, not
  adjust for it outside of the problematic code.
  - make sure MYSQLparse cleans up after itself by invoking the clean up
  functionality in the appropriate places before return. Implemented in 
  this patch.
  - use %destructor rule for sp_proc_stmt to restore THD - cleaner
  than the prevoius approach, but rejected
  because needs a careful analysis of the side effects, and this patch is 
  for 5.0, and long term we need to use the next alternative anyway
  - make sure that sp_proc_stmt doesn't juggle with THD - this is a 
  large work that will affect many modules.
  
  Cleanup: move main_lex and main_mem_root from Statement to its
  only two descendants Prepared_statement and THD. This ensures that
  when a Statement instance was created for purposes of statement backup,
  we do not involve LEX constructor/destructor, which is fairly expensive.
  In order to track that the transformation produces equivalent 
  functionality please check the respective constructors and destructors
  of Statement, Prepared_statement and THD - these members were
  used only there.
  Unrelated to the patch and could be moved to 5.1 if reviewer so requests.

  sql/log_event.cc@stripped, 2007-03-04 14:44:38+03:00, kostja@stripped +2 -2
    THD::main_lex is private and should not be used.

  sql/mysqld.cc@stripped, 2007-03-04 14:44:42+03:00, kostja@stripped +0 -12
    Move MYSQLerror to sql_yacc.yy as it depends on LEX headers now.

  sql/sql_class.cc@stripped, 2007-03-04 14:44:42+03:00, kostja@stripped +14 -18
    Cleanup: move main_lex and main_mem_root to THD and Prepared_statement

  sql/sql_class.h@stripped, 2007-03-04 14:44:42+03:00, kostja@stripped +6 -7
    Cleanup: move main_lex and main_mem_root to THD and Prepared_statement

  sql/sql_lex.cc@stripped, 2007-03-04 14:44:42+03:00, kostja@stripped +32 -0
    Implement st_lex::restore_lex()

  sql/sql_lex.h@stripped, 2007-03-04 14:44:42+03:00, kostja@stripped +4 -0
    Declare st_lex::restore_lex().

  sql/sql_parse.cc@stripped, 2007-03-04 14:44:42+03:00, kostja@stripped +7 -27
    Consolidate the calls to unit.cleanup() and deletion of lex->sphead
    in mysql_parse (COM_QUERY handler)

  sql/sql_prepare.cc@stripped, 2007-03-04 14:44:42+03:00, kostja@stripped +19 -15
    No need to delete lex->sphead to restore memory roots now in case of a 
    parse error - this is done automatically inside MYSQLparse

  sql/sql_trigger.cc@stripped, 2007-03-04 14:44:43+03:00, kostja@stripped +2 -5
    This code could lead to double deletion apparently, as in case
    of an error lex.sphead was never reset.

  sql/sql_yacc.yy@stripped, 2007-03-04 14:44:43+03:00, kostja@stripped +394 -327
    Trap all returns from the parser to ensure that MySQL-specific cleanup
    is invoked: we need to restore the global state of THD and LEX in 
    case of a parsing error. In case of a parsing success this happens as 
    part of normal grammar reduction process.

# 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:	kostja
# Host:	bodhi.local
# Root:	/opt/local/work/mysql-5.0-26750

--- 1.227/sql/log_event.cc	2007-02-28 16:09:33 +03:00
+++ 1.228/sql/log_event.cc	2007-03-04 14:44:38 +03:00
@@ -3114,8 +3114,8 @@
 
       ex.skip_lines = skip_lines;
       List<Item> field_list;
-      thd->main_lex.select_lex.context.resolve_in_table_list_only(&tables);
-      set_fields(tables.db, field_list, &thd->main_lex.select_lex.context);
+      thd->lex->select_lex.context.resolve_in_table_list_only(&tables);
+      set_fields(tables.db, field_list, &thd->lex->select_lex.context);
       thd->variables.pseudo_thread_id= thread_id;
       if (net)
       {

--- 1.592/sql/mysqld.cc	2007-03-01 10:41:12 +03:00
+++ 1.593/sql/mysqld.cc	2007-03-04 14:44:42 +03:00
@@ -1598,18 +1598,6 @@
 
 #endif /*!EMBEDDED_LIBRARY*/
 
-void MYSQLerror(const char *s)
-{
-  THD *thd=current_thd;
-  char *yytext= (char*) thd->lex->tok_start;
-  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
-  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
-    s=ER(ER_SYNTAX_ERROR);
-  my_printf_error(ER_PARSE_ERROR,  ER(ER_PARSE_ERROR), MYF(0), s,
-                  (yytext ? (char*) yytext : ""),
-                  thd->lex->yylineno);
-}
-
 
 #ifndef EMBEDDED_LIBRARY
 /*

--- 1.262/sql/sql_class.cc	2007-03-02 00:06:34 +03:00
+++ 1.263/sql/sql_class.cc	2007-03-04 14:44:42 +03:00
@@ -166,14 +166,10 @@
 }
 
 
-/*
-  Pass nominal parameters to Statement constructor only to ensure that
-  the destructor works OK in case of error. The main_mem_root will be
-  re-initialized in init().
-*/
 
 THD::THD()
-  :Statement(CONVENTIONAL_EXECUTION, 0, ALLOC_ROOT_MIN_BLOCK_SIZE, 0),
+   :Statement(&main_lex, &main_mem_root, CONVENTIONAL_EXECUTION,
+              /* statement id */ 0),
    Open_tables_state(refresh_version),
    lock_id(&main_lock_id),
    user_time(0), in_sub_stmt(0), global_read_lock(0), is_fatal_error(0),
@@ -184,6 +180,12 @@
 {
   ulong tmp;
 
+  /*
+    Pass nominal parameters to init_alloc_root only to ensure that
+    the destructor works OK in case of an error. The main_mem_root
+    will be re-initialized in init_for_queries().
+  */
+  init_sql_alloc(&main_mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
   stmt_arena= this;
   thread_stack= 0;
   db= 0;
@@ -443,6 +445,7 @@
 #ifndef DBUG_OFF
   dbug_sentry= THD_SENTRY_GONE;
 #endif  
+  free_root(&main_mem_root, MYF(0));
   DBUG_VOID_RETURN;
 }
 
@@ -1581,18 +1584,17 @@
   Statement functions 
 */
 
-Statement::Statement(enum enum_state state_arg, ulong id_arg,
-                     ulong alloc_block_size, ulong prealloc_size)
-  :Query_arena(&main_mem_root, state_arg),
+Statement::Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg,
+                     enum enum_state state_arg, ulong id_arg)
+  :Query_arena(mem_root_arg, state_arg),
   id(id_arg),
   set_query_id(1),
-  lex(&main_lex),
+  lex(lex_arg),
   query(0),
   query_length(0),
   cursor(0)
 {
   name.str= NULL;
-  init_sql_alloc(&main_mem_root, alloc_block_size, prealloc_size);
 }
 
 
@@ -1634,7 +1636,7 @@
 
 void THD::end_statement()
 {
-  /* Cleanup SQL processing state to resuse this statement in next query. */
+  /* Cleanup SQL processing state to reuse this statement in next query. */
   lex_end(lex);
   delete lex->result;
   lex->result= 0;
@@ -1675,12 +1677,6 @@
 
 Statement::~Statement()
 {
-  /*
-    We must free `main_mem_root', not `mem_root' (pointer), to work
-    correctly if this statement is used as a backup statement,
-    for which `mem_root' may point to some other statement.
-  */
-  free_root(&main_mem_root, MYF(0));
 }
 
 C_MODE_START

--- 1.321/sql/sql_class.h	2007-02-28 16:09:33 +03:00
+++ 1.322/sql/sql_class.h	2007-03-04 14:44:42 +03:00
@@ -772,10 +772,6 @@
   Statement(const Statement &rhs);              /* not implemented: */
   Statement &operator=(const Statement &rhs);   /* non-copyable */
 public:
-  /* FIXME: these must be protected */
-  MEM_ROOT main_mem_root;
-  LEX     main_lex;
-
   /*
     Uniquely identifies each statement object in thread scope; change during
     statement lifetime. FIXME: must be const
@@ -819,10 +815,10 @@
 public:
 
   /* This constructor is called for backup statements */
-  Statement() { clear_alloc_root(&main_mem_root); }
+  Statement() {}
 
-  Statement(enum enum_state state_arg, ulong id_arg,
-            ulong alloc_block_size, ulong prealloc_size);
+  Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg,
+            enum enum_state state_arg, ulong id_arg);
   virtual ~Statement();
 
   /* Assign execution context (note: not all members) of given stmt to self */
@@ -1080,6 +1076,9 @@
 class THD :public Statement,
            public Open_tables_state
 {
+private:
+  LEX main_lex;
+  MEM_ROOT main_mem_root;
 public:
   /*
     Constant for THD::where initialization in the beginning of every query.

--- 1.214/sql/sql_lex.cc	2007-03-02 00:06:34 +03:00
+++ 1.215/sql/sql_lex.cc	2007-03-04 14:44:42 +03:00
@@ -1648,6 +1648,38 @@
   }
 }
 
+/*
+  @brief Restore the LEX and THD in case of a parse error.
+
+  This is a clean up call that is invoked by the Bison generated
+  parser before returning an error from MYSQLparse. If your
+  semantic actions manipulate with the global thread state (which
+  is a very bad practice and should not normally be employed) and
+  need a clean-up in case of error, and you can not use %destructor
+  rule in the grammar file itself, this function should be used
+  to implement the clean up.
+*/
+
+void st_lex::restore_lex(THD *thd)
+{
+  /*
+    Delete sphead for the side effect of restoring of the original
+    LEX state, thd->lex, thd->mem_root and thd->free_list if they
+    were replaced when parsing stored procedure statements.  We
+    will never use sphead object after a parse error, so it's okay
+    to delete it only for the sake of the side effect.
+    TODO: make this functionality explicit in sp_head class.
+    Long term TODO: implement a separate parser for stored
+    procedures.
+    Sic: we must nullify the member of the main lex, not the
+    current one that will be thrown away
+  */
+  if (thd->lex->sphead);
+  {
+    delete thd->lex->sphead;
+    thd->lex->sphead= NULL;
+  }
+}
 
 /*
   Initialize (or reset) Query_tables_list object.

--- 1.239/sql/sql_lex.h	2007-03-02 00:06:34 +03:00
+++ 1.240/sql/sql_lex.h	2007-03-04 14:44:42 +03:00
@@ -1182,6 +1182,10 @@
   {
     return context_stack.head();
   }
+  /*
+    Restore the LEX and THD in case of a parse error.
+  */
+  static void restore_lex(THD *thd);
 
   void reset_n_backup_query_tables_list(Query_tables_list *backup);
   void restore_backup_query_tables_list(Query_tables_list *backup);

--- 1.606/sql/sql_parse.cc	2007-03-02 00:06:34 +03:00
+++ 1.607/sql/sql_parse.cc	2007-03-04 14:44:42 +03:00
@@ -4506,9 +4506,6 @@
       clean up the environment.
     */
 create_sp_error:
-    lex->unit.cleanup();
-    delete lex->sphead;
-    lex->sphead= 0;
     if (sp_result != SP_OK )
       goto error;
     send_ok(thd);
@@ -4879,9 +4876,6 @@
     /* Conditionally writes to binlog. */
     res= mysql_create_or_drop_trigger(thd, all_tables, 1);
 
-    /* We don't care about trigger body after this point */
-    delete lex->sphead;
-    lex->sphead= 0;
     break;
   }
   case SQLCOM_DROP_TRIGGER:
@@ -5904,15 +5898,7 @@
       else
 #endif
       {
-	if (thd->net.report_error)
-	{
-	  if (thd->lex->sphead)
-	  {
-	    delete thd->lex->sphead;
-	    thd->lex->sphead= NULL;
-	  }
-	}
-	else
+	if (! thd->net.report_error)
 	{
           /*
             Binlog logs a string starting from thd->query and having length
@@ -5932,7 +5918,6 @@
 	  query_cache_end_of_result(thd);
 	}
       }
-      lex->unit.cleanup();
     }
     else
     {
@@ -5940,19 +5925,14 @@
       DBUG_PRINT("info",("Command aborted. Fatal_error: %d",
 			 thd->is_fatal_error));
 
-      /*
-        The first thing we do after parse error is freeing sp_head to
-        ensure that we have restored original memroot.
-      */
-      if (thd->lex->sphead)
-      {
-	/* Clean up after failed stored procedure/function */
-	delete thd->lex->sphead;
-	thd->lex->sphead= NULL;
-      }
       query_cache_abort(&thd->net);
-      lex->unit.cleanup();
     }
+    if (thd->lex->sphead)
+    {
+      delete thd->lex->sphead;
+      thd->lex->sphead= 0;
+    }
+    lex->unit.cleanup();
     thd->proc_info="freeing items";
     thd->end_statement();
     thd->cleanup_after_query();

--- 1.508/sql/sql_yacc.yy	2007-03-02 15:05:13 +03:00
+++ 1.509/sql/sql_yacc.yy	2007-03-04 14:44:43 +03:00
@@ -52,11 +52,18 @@
 		      ER_WARN_DEPRECATED_SYNTAX,                    \
 		      ER(ER_WARN_DEPRECATED_SYNTAX), (A), (B));
 
-#define YYABORT_UNLESS(A)                  \
+#define MYSQL_YYABORT                    \
+  do                                     \
+  {                                      \
+    LEX::restore_lex(YYTHD);             \
+    YYABORT;                             \
+  } while (0)
+
+#define MYSQL_YYABORT_UNLESS(A)         \
   if (!(A))                             \
-  {					\
-    yyerror(ER(ER_SYNTAX_ERROR));	\
-    YYABORT;				\
+  {                                     \
+    my_parse_error(ER(ER_SYNTAX_ERROR));\
+    MYSQL_YYABORT;                      \
   }
 
 #ifndef DBUG_OFF
@@ -65,6 +72,66 @@
 #define YYDEBUG 0
 #endif
 
+/*
+  @brief Push an error message into MySQL error stack with line
+  and position information.
+
+  This function provides semantic action implementers with a way
+  to push the famous "You have a syntax error near..." error
+  message into the error stack, which is normally produced only if
+  a parse error is discovered internally by the Bison generated
+  parser.
+*/
+
+void my_parse_error(const char *s)
+{
+  THD *thd= current_thd;
+
+  char *yytext= (char*) thd->lex->tok_start;
+  /* Push an error into the error stack */
+  my_printf_error(ER_PARSE_ERROR,  ER(ER_PARSE_ERROR), MYF(0), s,
+                  (yytext ? (char*) yytext : ""),
+                  thd->lex->yylineno);
+}
+
+/*
+  @brief Bison callback to report a syntax/OOM error
+
+  This function is invoked by the bison-generated parser
+  when a syntax error, a parse error or an out-of-memory
+  condition occurs. This function is not invoked when the
+  parser is requested to abort by semantic action code
+  by means of YYABORT or YYACCEPT macros. This is why these
+  macros should not be used (use MYSQL_YYABORT/MYSQL_YYACCEPT
+  instead).
+
+  The parser will abort immediately after invoking this callback.
+
+  This function is not for use in semantic actions and is internal to
+  the parser, as it performs some pre-return cleanup. 
+  In semantic actions, please use my_parse_error or my_error to
+  push an error into the error stack and MYSQL_YYABORT
+  to abort from the parser.
+*/
+
+void MYSQLerror(const char *s)
+{
+  THD *thd= current_thd;
+
+  /*
+    Restore the original LEX if it was replaced when parsing
+    a stored procedure. We must ensure that a parsing error
+    does not leave any side effects in the THD.
+  */
+  LEX::restore_lex(thd);
+
+  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
+  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
+    s= ER(ER_SYNTAX_ERROR);
+  my_parse_error(s);
+}
+
+
 #ifndef DBUG_OFF
 void turn_parser_debug_on()
 {
@@ -1138,7 +1205,7 @@
 	      (!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT)))
 	   {
 	     my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
-	     YYABORT;
+	     MYSQL_YYABORT;
 	   }
 	   else
 	   {
@@ -1210,8 +1277,8 @@
           LEX *lex= thd->lex;
           if (lex->stmt_prepare_mode)
           {
-            yyerror(ER(ER_SYNTAX_ERROR));
-            YYABORT;
+            my_parse_error(ER(ER_SYNTAX_ERROR));
+            MYSQL_YYABORT;
           }
           lex->sql_command= SQLCOM_DEALLOCATE_PREPARE;
           lex->prepared_stmt_name= $3;
@@ -1230,8 +1297,8 @@
           LEX *lex= thd->lex;
           if (lex->stmt_prepare_mode)
           {
-            yyerror(ER(ER_SYNTAX_ERROR));
-            YYABORT;
+            my_parse_error(ER(ER_SYNTAX_ERROR));
+            MYSQL_YYABORT;
           }
           lex->sql_command= SQLCOM_PREPARE;
           lex->prepared_stmt_name= $2;
@@ -1260,8 +1327,8 @@
           LEX *lex= thd->lex;
           if (lex->stmt_prepare_mode)
           {
-            yyerror(ER(ER_SYNTAX_ERROR));
-            YYABORT;
+            my_parse_error(ER(ER_SYNTAX_ERROR));
+            MYSQL_YYABORT;
           }
           lex->sql_command= SQLCOM_EXECUTE;
           lex->prepared_stmt_name= $2;
@@ -1285,7 +1352,7 @@
           LEX *lex=Lex;
           LEX_STRING *lexstr= (LEX_STRING*)sql_memdup(&$2, sizeof(LEX_STRING));
           if (!lexstr || lex->prepared_stmt_params.push_back(lexstr))
-              YYABORT;
+              MYSQL_YYABORT;
         }
         ;
 
@@ -1297,7 +1364,7 @@
          if (Lex->sphead)
          {
            my_error(ER_SP_BADSTATEMENT, MYF(0), "HELP");
-           YYABORT;
+           MYSQL_YYABORT;
          }
        }
        ident_or_text
@@ -1424,7 +1491,7 @@
 						 (using_update_log ?
 						  TL_READ_NO_INSERT:
 						  TL_READ)))
-	    YYABORT;
+	    MYSQL_YYABORT;
           lex->alter_info.reset();
 	  lex->col_list.empty();
 	  lex->change=NullS;
@@ -1442,7 +1509,7 @@
 	    lex->sql_command= SQLCOM_CREATE_INDEX;
 	    if (!lex->current_select->add_table_to_list(lex->thd, $7, NULL,
 							TL_OPTION_UPDATING))
-	      YYABORT;
+	      MYSQL_YYABORT;
             lex->alter_info.reset();
             lex->alter_info.flags= ALTER_ADD_INDEX;
 	    lex->col_list.empty();
@@ -1503,12 +1570,12 @@
             if (!$1.str || check_db_name($1.str))
             {
 	      my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    if (check_routine_name($3))
             {
 	      my_error(ER_SP_WRONG_NAME, MYF(0), $3.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    $$= new sp_name($1, $3);
 	    $$->init_qname(YYTHD);
@@ -1520,10 +1587,10 @@
 	    if (check_routine_name($1))
             {
 	      my_error(ER_SP_WRONG_NAME, MYF(0), $1.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
             if (thd->copy_db_to(&db.str, &db.length))
-              YYABORT;
+              MYSQL_YYABORT;
 	    $$= new sp_name(db, $1);
             if ($$)
 	      $$->init_qname(YYTHD);
@@ -1543,7 +1610,7 @@
                  and is considered a parsing error.
               */
 	      my_error(ER_WRONG_USAGE, MYF(0), "SONAME", "DEFINER");
-              YYABORT;
+              MYSQL_YYABORT;
             }
 	    lex->sql_command = SQLCOM_CREATE_FUNCTION;
 	    lex->udf.name = lex->spname->m_name;
@@ -1562,13 +1629,13 @@
             if (lex->udf.type == UDFTYPE_AGGREGATE)
             {
               my_error(ER_SP_NO_AGGREGATE, MYF(0));
-              YYABORT;
+              MYSQL_YYABORT;
             }
 
 	    if (lex->sphead)
 	    {
 	      my_error(ER_SP_NO_RECURSIVE_CREATE, MYF(0), "FUNCTION");
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    /* Order is important here: new - reset - init */
 	    sp= new sp_head();
@@ -1609,7 +1676,7 @@
             if (sp->fill_field_definition(YYTHD, lex,
                                           (enum enum_field_types) $8,
                                           &sp->m_return_field_def))
-              YYABORT;
+              MYSQL_YYABORT;
 
 	    bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
 	  }
@@ -1626,14 +1693,14 @@
 	    sp_head *sp= lex->sphead;
 
             if (sp->is_not_allowed_in_function("function"))
-              YYABORT;
+              MYSQL_YYABORT;
 
 	    lex->sql_command= SQLCOM_CREATE_SPFUNCTION;
 	    sp->init_strings(YYTHD, lex);
             if (!(sp->m_flags & sp_head::HAS_RETURN))
             {
               my_error(ER_SP_NORETURN, MYF(0), sp->m_qname.str);
-              YYABORT;
+              MYSQL_YYABORT;
             }
 	    /* Restore flag if it was cleared above */
 	    if (sp->m_old_cmq)
@@ -1763,7 +1830,7 @@
 	    if (spc->find_variable(&$1, TRUE))
 	    {
 	      my_error(ER_SP_DUP_PARAM, MYF(0), $1.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
             sp_variable_t *spvar= spc->push_variable(&$1,
                                                      (enum enum_field_types)$3,
@@ -1773,7 +1840,7 @@
                                                    (enum enum_field_types) $3,
                                                    &spvar->field_def))
             {
-              YYABORT;
+              MYSQL_YYABORT;
             }
             spvar->field_def.field_name= spvar->name.str;
             spvar->field_def.pack_flag |= FIELDFLAG_MAYBE_NULL;
@@ -1800,7 +1867,7 @@
 	    if (spc->find_variable(&$3, TRUE))
 	    {
 	      my_error(ER_SP_DUP_PARAM, MYF(0), $3.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
             sp_variable_t *spvar= spc->push_variable(&$3,
                                                      (enum enum_field_types)$4,
@@ -1810,7 +1877,7 @@
                                                    (enum enum_field_types) $4,
                                                    &spvar->field_def))
             {
-              YYABORT;
+              MYSQL_YYABORT;
             }
             spvar->field_def.field_name= spvar->name.str;
             spvar->field_def.pack_flag |= FIELDFLAG_MAYBE_NULL;
@@ -1849,13 +1916,13 @@
 	    { /* Variable or condition following cursor or handler */
 	      my_message(ER_SP_VARCOND_AFTER_CURSHNDLR,
                          ER(ER_SP_VARCOND_AFTER_CURSHNDLR), MYF(0));
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    if ($2.curs && $1.hndlrs)
 	    { /* Cursor following handler */
 	      my_message(ER_SP_CURSOR_AFTER_HANDLER,
                          ER(ER_SP_CURSOR_AFTER_HANDLER), MYF(0));
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    $$.vars= $1.vars + $2.vars;
 	    $$.conds= $1.conds + $2.conds;
@@ -1893,7 +1960,7 @@
               sp_variable_t *spvar= pctx->find_variable(var_idx);
             
               if (!spvar)
-                YYABORT;
+                MYSQL_YYABORT;
             
               spvar->type= var_type;
               spvar->dflt= dflt_value_item;
@@ -1901,7 +1968,7 @@
               if (lex->sphead->fill_field_definition(YYTHD, lex, var_type,
                                                      &spvar->field_def))
               {
-                YYABORT;
+                MYSQL_YYABORT;
               }
             
               spvar->field_def.field_name= spvar->name.str;
@@ -1929,7 +1996,7 @@
 	    if (spc->find_cond(&$2, TRUE))
 	    {
 	      my_error(ER_SP_DUP_COND, MYF(0), $2.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    YYTHD->lex->spcont->push_cond(&$2, $5);
 	    $$.vars= $$.hndlrs= $$.curs= 0;
@@ -1987,7 +2054,7 @@
 	    {
 	      my_error(ER_SP_DUP_CURS, MYF(0), $2.str);
 	      delete $5;
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
             i= new sp_instr_cpush(sp->instructions(), ctx, $5,
                                   ctx->current_cursor_count());
@@ -2015,13 +2082,13 @@
 	    {
 	      my_message(ER_SP_BAD_CURSOR_QUERY, ER(ER_SP_BAD_CURSOR_QUERY),
                          MYF(0));
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    if (lex->result)
 	    {
 	      my_message(ER_SP_BAD_CURSOR_SELECT, ER(ER_SP_BAD_CURSOR_SELECT),
                          MYF(0));
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    lex->sp_lex_in_use= TRUE;
 	    $$= lex;
@@ -2045,7 +2112,7 @@
 	    if (ctx->find_handler($1))
 	    {
 	      my_message(ER_SP_DUP_HANDLER, ER(ER_SP_DUP_HANDLER), MYF(0));
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    else
 	    {
@@ -2066,7 +2133,7 @@
 	    if (ctx->find_handler($3))
 	    {
 	      my_message(ER_SP_DUP_HANDLER, ER(ER_SP_DUP_HANDLER), MYF(0));
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    else
 	    {
@@ -2092,7 +2159,7 @@
 	    if (!sp_cond_check(&$3))
 	    {
 	      my_error(ER_SP_BAD_SQLSTATE, MYF(0), $3.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
 	    $$->type= sp_cond_type_t::state;
@@ -2117,7 +2184,7 @@
 	    if ($$ == NULL)
 	    {
 	      my_error(ER_SP_COND_MISMATCH, MYF(0), $1.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	  }
 	| SQLWARNING_SYM	/* SQLSTATEs 01??? */
@@ -2148,7 +2215,7 @@
 	    if (spc->find_variable(&$1, TRUE))
 	    {
 	      my_error(ER_SP_DUP_VAR, MYF(0), $1.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    spc->push_variable(&$1, (enum_field_types)0, sp_param_in);
 	    $$= 1;
@@ -2163,7 +2230,7 @@
 	    if (spc->find_variable(&$3, TRUE))
 	    {
 	      my_error(ER_SP_DUP_VAR, MYF(0), $3.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    spc->push_variable(&$3, (enum_field_types)0, sp_param_in);
 	    $$= $1 + 1;
@@ -2191,7 +2258,7 @@
 	    if (lex->sql_command == SQLCOM_CHANGE_DB)
 	    { /* "USE db" doesn't work in a procedure */
 	      my_error(ER_SP_BADSTATEMENT, MYF(0), "USE");
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    /*
               Don't add an instruction for SET statements, since all
@@ -2231,7 +2298,7 @@
 	    if (sp->m_type != TYPE_ENUM_FUNCTION)
 	    {
 	      my_message(ER_SP_BADRETURN, ER(ER_SP_BADRETURN), MYF(0));
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    else
 	    {
@@ -2272,7 +2339,7 @@
 	    if (! lab)
 	    {
 	      my_error(ER_SP_LILABEL_MISMATCH, MYF(0), "LEAVE", $2.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    else
 	    {
@@ -2301,7 +2368,7 @@
 	    if (! lab || lab->type != SP_LAB_ITER)
 	    {
 	      my_error(ER_SP_LILABEL_MISMATCH, MYF(0), "ITERATE", $2.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    else
 	    {
@@ -2329,7 +2396,7 @@
 	    if (! lex->spcont->find_cursor(&$2, &offset))
 	    {
 	      my_error(ER_SP_CURSOR_MISMATCH, MYF(0), $2.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    i= new sp_instr_copen(sp->instructions(), lex->spcont, offset);
 	    sp->add_instr(i);
@@ -2344,7 +2411,7 @@
 	    if (! lex->spcont->find_cursor(&$3, &offset))
 	    {
 	      my_error(ER_SP_CURSOR_MISMATCH, MYF(0), $3.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    i= new sp_instr_cfetch(sp->instructions(), lex->spcont, offset);
 	    sp->add_instr(i);
@@ -2361,7 +2428,7 @@
 	    if (! lex->spcont->find_cursor(&$2, &offset))
 	    {
 	      my_error(ER_SP_CURSOR_MISMATCH, MYF(0), $2.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    i= new sp_instr_cclose(sp->instructions(), lex->spcont,  offset);
 	    sp->add_instr(i);
@@ -2385,7 +2452,7 @@
 	    if (!spc || !(spv = spc->find_variable(&$1)))
 	    {
 	      my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    else
 	    {
@@ -2406,7 +2473,7 @@
 	    if (!spc || !(spv = spc->find_variable(&$3)))
 	    {
 	      my_error(ER_SP_UNDECLARED_VAR, MYF(0), $3.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    else
 	    {
@@ -2475,7 +2542,7 @@
           {
             LEX *lex= Lex;
             if (case_stmt_action_expr(lex, $3))
-              YYABORT;
+              MYSQL_YYABORT;
 
             lex->sphead->restore_lex(YYTHD); /* For expr $3 */
           }
@@ -2578,7 +2645,7 @@
 	    if (lab)
 	    {
 	      my_error(ER_SP_LABEL_REDEFINE, MYF(0), $1.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    else
 	    {
@@ -2599,7 +2666,7 @@
 	          my_strcasecmp(system_charset_info, $5.str, lab->name) != 0)
 	      {
 	        my_error(ER_SP_LABEL_MISMATCH, MYF(0), $5.str);
-	        YYABORT;
+	        MYSQL_YYABORT;
 	      }
 	    }
 	    lex->sphead->backpatch(lex->spcont->pop_label());
@@ -2716,11 +2783,11 @@
             LEX *lex=Lex;
             THD *thd= lex->thd;
             if (!(lex->name= (char *)$2))
-              YYABORT;
+              MYSQL_YYABORT;
             if ($2->db.str == NULL &&
                 thd->copy_db_to(&($2->db.str), &($2->db.length)))
             {
-              YYABORT;
+              MYSQL_YYABORT;
             }
           }
         | '(' LIKE table_ident ')'
@@ -2728,11 +2795,11 @@
             LEX *lex=Lex;
             THD *thd= lex->thd;
             if (!(lex->name= (char *)$3))
-              YYABORT;
+              MYSQL_YYABORT;
             if ($3->db.str == NULL &&
                 thd->copy_db_to(&($3->db.str), &($3->db.length)))
             {
-              YYABORT;
+              MYSQL_YYABORT;
             }
           }
         ;
@@ -2844,8 +2911,8 @@
                 Lex->create_info.table_options|= HA_OPTION_PACK_KEYS;
                 break;
             default:
-                yyerror(ER(ER_SYNTAX_ERROR));
-                YYABORT;
+                my_parse_error(ER(ER_SYNTAX_ERROR));
+                MYSQL_YYABORT;
             }
             Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;
           }
@@ -2861,17 +2928,17 @@
 	| RAID_TYPE opt_equal raid_types
 	  {
 	    my_error(ER_WARN_DEPRECATED_SYNTAX, MYF(0), "RAID_TYPE", "PARTITION");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	| RAID_CHUNKS opt_equal ulong_num
 	  {
 	    my_error(ER_WARN_DEPRECATED_SYNTAX, MYF(0), "RAID_CHUNKS", "PARTITION");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	| RAID_CHUNKSIZE opt_equal ulong_num
 	  {
 	    my_error(ER_WARN_DEPRECATED_SYNTAX, MYF(0), "RAID_CHUNKSIZE", "PARTITION");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	| UNION_SYM opt_equal '(' table_list ')'
 	  {
@@ -2907,7 +2974,7 @@
             my_error(ER_CONFLICTING_DECLARATIONS, MYF(0),
                      "CHARACTER SET ", cinfo->default_table_charset->csname,
                      "CHARACTER SET ", $4->csname);
-            YYABORT;
+            MYSQL_YYABORT;
           }
 	  Lex->create_info.default_table_charset= $4;
           Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
@@ -2923,7 +2990,7 @@
             {
               my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
                        $4->name, cinfo->default_table_charset->csname);
-              YYABORT;
+              MYSQL_YYABORT;
             }
             Lex->create_info.default_table_charset= $4;
             Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
@@ -2935,7 +3002,7 @@
 	  $$ = ha_resolve_by_name($1.str,$1.length);
 	  if ($$ == DB_TYPE_UNKNOWN) {
 	    my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	};
 
@@ -3070,7 +3137,7 @@
                                 &lex->comment,
 				lex->change,&lex->interval_list,lex->charset,
 				lex->uint_geom_type))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	};
 
 type:
@@ -3139,7 +3206,7 @@
 #else
             my_error(ER_FEATURE_DISABLED, MYF(0),
                      sym_group_geom.name, sym_group_geom.needed_define);
-            YYABORT;
+            MYSQL_YYABORT;
 #endif
           }
 	| MEDIUMBLOB			{ Lex->charset=&my_charset_bin;
@@ -3300,7 +3367,7 @@
 	    {
 	      my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
                        $2->name,Lex->charset->csname);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    else
 	    {
@@ -3325,7 +3392,7 @@
 	  if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))))
 	  {
 	    my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str);
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	}
 	| BINARY { $$= &my_charset_bin; }
@@ -3347,7 +3414,7 @@
 	      !($$=get_old_charset_by_name($1.str)))
 	  {
 	    my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str);
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	}
 	| BINARY { $$= &my_charset_bin; }
@@ -3363,7 +3430,7 @@
 	  if (!($$=get_charset_by_name($1.str,MYF(0))))
 	  {
 	    my_error(ER_UNKNOWN_COLLATION, MYF(0), $1.str);
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	};
 
@@ -3390,7 +3457,7 @@
                                                    MY_CS_PRIMARY,MYF(0))))
 	  {
 	    my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), "ucs2");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	}
 	| charset charset_name opt_bin_mod	{ Lex->charset=$2; }
@@ -3409,7 +3476,7 @@
                                                    MY_CS_PRIMARY,MYF(0))))
 	  {
 	    my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), "ucs2");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	}
 	| charset charset_name	{ Lex->charset=$2; } ;
@@ -3472,7 +3539,7 @@
 #else
 	    my_error(ER_FEATURE_DISABLED, MYF(0),
                      sym_group_geom.name, sym_group_geom.needed_define);
-	    YYABORT;
+	    MYSQL_YYABORT;
 #endif
 	  };
 
@@ -3505,7 +3572,7 @@
 #else
             my_error(ER_FEATURE_DISABLED, MYF(0),
                      sym_group_geom.name, sym_group_geom.needed_define);
-	    YYABORT;
+	    MYSQL_YYABORT;
 #endif
 	  }
         ;
@@ -3565,7 +3632,7 @@
 	  lex->duplicates= DUP_ERROR; 
 	  if (!lex->select_lex.add_table_to_list(thd, $4, NULL,
 						 TL_OPTION_UPDATING))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  lex->col_list.empty();
           lex->select_lex.init_order();
 	  lex->select_lex.db=
@@ -3591,7 +3658,7 @@
 	    lex->sql_command=SQLCOM_ALTER_DB;
 	    lex->name= $3;
             if (lex->name == NULL && thd->copy_db_to(&lex->name, NULL))
-              YYABORT;
+              MYSQL_YYABORT;
 	  }
 	| ALTER PROCEDURE sp_name
 	  {
@@ -3600,7 +3667,7 @@
 	    if (lex->sphead)
 	    {
 	      my_error(ER_SP_NO_DROP_SP, MYF(0), "PROCEDURE");
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
           }
@@ -3618,7 +3685,7 @@
 	    if (lex->sphead)
 	    {
 	      my_error(ER_SP_NO_DROP_SP, MYF(0), "FUNCTION");
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
           }
@@ -3697,7 +3764,7 @@
                                   &lex->comment,
 				  $3.str, &lex->interval_list, lex->charset,
 				  lex->uint_geom_type))
-	       YYABORT;
+	       MYSQL_YYABORT;
           }
           opt_place
 	| DROP opt_column field_ident opt_restrict
@@ -3758,13 +3825,13 @@
             if (lex->select_lex.db == NULL &&
                 thd->copy_db_to(&lex->select_lex.db, NULL))
             {
-              YYABORT;
+              MYSQL_YYABORT;
             }
             if (check_table_name($3->table.str,$3->table.length) ||
                 $3->db.str && check_db_name($3->db.str))
             {
               my_error(ER_WRONG_TABLE_NAME, MYF(0), $3->table.str);
-              YYABORT;
+              MYSQL_YYABORT;
             }
 	    lex->name= $3->table.str;
 	    lex->alter_info.flags|= ALTER_RENAME;
@@ -3781,7 +3848,7 @@
 	    {
 	      my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
                        $5->name, $4->csname);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    LEX *lex= Lex;
 	    lex->create_info.table_charset=
@@ -3919,7 +3986,7 @@
             {
                my_message(ER_BAD_SLAVE_UNTIL_COND,
                           ER(ER_BAD_SLAVE_UNTIL_COND), MYF(0));
-               YYABORT;
+               MYSQL_YYABORT;
             }
 
           }
@@ -4011,7 +4078,7 @@
 	  if (lex->sphead)
 	  {
 	    my_error(ER_SP_BADSTATEMENT, MYF(0), "CHECK");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	  lex->sql_command = SQLCOM_CHECK;
 	  lex->check_opt.init();
@@ -4071,12 +4138,12 @@
         user TO_SYM user
         {
           if (Lex->users_list.push_back($1) || Lex->users_list.push_back($3))
-            YYABORT;
+            MYSQL_YYABORT;
         }
         | rename_list ',' user TO_SYM user
           {
             if (Lex->users_list.push_back($3) || Lex->users_list.push_back($5))
-              YYABORT;
+              MYSQL_YYABORT;
           }
         ;
 
@@ -4093,7 +4160,7 @@
 				     TL_IGNORE) ||
 	      !sl->add_table_to_list(lex->thd, $3,NULL,TL_OPTION_UPDATING,
 				     TL_IGNORE))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	};
 
 keycache:
@@ -4118,7 +4185,7 @@
                                       TL_READ,
                                       sel->get_use_index(),
                                       (List<String> *)0))
-            YYABORT;
+            MYSQL_YYABORT;
         }
         ;
 
@@ -4150,7 +4217,7 @@
                                       TL_READ,
                                       sel->get_use_index(),
                                       (List<String> *)0))
-            YYABORT;
+            MYSQL_YYABORT;
 	}
 	;
 
@@ -4205,16 +4272,16 @@
             SELECT_LEX * sel= lex->current_select;
 	    if (sel->set_braces(1))
 	    {
-	      yyerror(ER(ER_SYNTAX_ERROR));
-	      YYABORT;
+              my_parse_error(ER(ER_SYNTAX_ERROR));
+	      MYSQL_YYABORT;
 	    }
             if (sel->linkage == UNION_TYPE &&
                 !sel->master_unit()->first_select()->braces &&
                 sel->master_unit()->first_select()->linkage ==
                 UNION_TYPE)
             {
-              yyerror(ER(ER_SYNTAX_ERROR));
-              YYABORT;
+              my_parse_error(ER(ER_SYNTAX_ERROR));
+              MYSQL_YYABORT;
             }
             /* select in braces, can't contain global parameters */
 	    if (sel->master_unit()->fake_select_lex)
@@ -4230,14 +4297,14 @@
           SELECT_LEX * sel= lex->current_select;
           if (lex->current_select->set_braces(0))
 	  {
-	    yyerror(ER(ER_SYNTAX_ERROR));
-	    YYABORT;
+            my_parse_error(ER(ER_SYNTAX_ERROR));
+	    MYSQL_YYABORT;
 	  }
 	  if (sel->linkage == UNION_TYPE &&
 	      sel->master_unit()->first_select()->braces)
 	  {
-	    yyerror(ER(ER_SYNTAX_ERROR));
-	    YYABORT;
+            my_parse_error(ER(ER_SYNTAX_ERROR));
+	    MYSQL_YYABORT;
 	  }
 	}
 	union_clause
@@ -4286,7 +4353,7 @@
 	    if (test_all_bits(Select->options, SELECT_ALL | SELECT_DISTINCT))
 	    {
 	      my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
-              YYABORT;
+              MYSQL_YYABORT;
 	    }
           }
 	  ;
@@ -4300,7 +4367,7 @@
 	| HIGH_PRIORITY
 	  {
 	    if (check_simple_select())
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    Lex->lock_option= TL_READ_HIGH_PRIORITY;
 	  }
 	| DISTINCT         { Select->options|= SELECT_DISTINCT; }
@@ -4309,13 +4376,13 @@
 	| SQL_BUFFER_RESULT
 	  {
 	    if (check_simple_select())
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    Select->options|= OPTION_BUFFER_RESULT;
 	  }
 	| SQL_CALC_FOUND_ROWS
 	  {
 	    if (check_simple_select())
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    Select->options|= OPTION_FOUND_ROWS;
 	  }
 	| SQL_NO_CACHE_SYM
@@ -4364,7 +4431,7 @@
                                  new Item_field(&thd->lex->current_select->
                                                 context,
                                                 NULL, NULL, "*")))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    (thd->lex->current_select->with_wild)++;
 	  };
 
@@ -4373,7 +4440,7 @@
 	  remember_name select_item2 remember_end select_alias
 	  {
 	    if (add_item_to_list(YYTHD, $2))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    if ($4.str)
             {
               $2->is_autogenerated_name= FALSE;
@@ -4653,7 +4720,7 @@
                                  lex->dec ? atoi(lex->dec) : 0,
                                  lex->charset);
             if (!$$)
-              YYABORT;
+              MYSQL_YYABORT;
 	  }
 	| CASE_SYM opt_expr when_list opt_else END
 	  { $$= new Item_func_case(* $3, $2, $4 ); }
@@ -4664,7 +4731,7 @@
                                  Lex->dec ? atoi(Lex->dec) : 0,
 				 Lex->charset);
             if (!$$)
-              YYABORT;
+              MYSQL_YYABORT;
 	  }
 	| CONVERT_SYM '(' expr USING charset_name ')'
 	  { $$= new Item_func_conv_charset($3,$5); }
@@ -4675,7 +4742,7 @@
 	      Item_splocal *il= static_cast<Item_splocal *>($3);
 
 	      my_error(ER_WRONG_COLUMN_NAME, MYF(0), il->my_name()->str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    $$= new Item_default_value(Lex->current_context(), $3);
 	  }
@@ -4688,7 +4755,7 @@
               my_error(ER_FEATURE_DISABLED, MYF(0),
                        $1.symbol->group->name,
                        $1.symbol->group->needed_define);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    $$= ((Item*(*)(void))($1.symbol->create_func))();
 	  }
@@ -4699,7 +4766,7 @@
               my_error(ER_FEATURE_DISABLED, MYF(0),
                        $1.symbol->group->name,
                        $1.symbol->group->needed_define);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    $$= ((Item*(*)(Item*))($1.symbol->create_func))($3);
 	  }
@@ -4710,7 +4777,7 @@
 	      my_error(ER_FEATURE_DISABLED, MYF(0),
                        $1.symbol->group->name,
                        $1.symbol->group->needed_define);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    $$= ((Item*(*)(Item*,Item*))($1.symbol->create_func))($3,$5);
 	  }
@@ -4721,7 +4788,7 @@
               my_error(ER_FEATURE_DISABLED, MYF(0),
                        $1.symbol->group->name,
                        $1.symbol->group->needed_define);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    $$= ((Item*(*)(Item*,Item*,Item*))($1.symbol->create_func))($3,$5,$7);
 	  }
@@ -4752,7 +4819,7 @@
 	| CONVERT_TZ_SYM '(' expr ',' expr ',' expr ')'
 	  {
             if (Lex->add_time_zone_tables_to_query_tables(YYTHD))
-              YYABORT;
+              MYSQL_YYABORT;
 	    $$= new Item_func_convert_tz($3, $5, $7);
 	  }
 	| CURDATE optional_braces
@@ -4827,7 +4894,7 @@
 #else
 	    my_error(ER_FEATURE_DISABLED, MYF(0),
                      sym_group_geom.name, sym_group_geom.needed_define);
-	    YYABORT;
+	    MYSQL_YYABORT;
 #endif
 	  }
 	| GET_FORMAT '(' date_time_type  ',' expr ')'
@@ -4845,8 +4912,8 @@
 	  {
             if ($1->type() != Item::ROW_ITEM)
             {
-              yyerror(ER(ER_SYNTAX_ERROR));
-              YYABORT;
+              my_parse_error(ER(ER_SYNTAX_ERROR));
+              MYSQL_YYABORT;
             }
             $$= new Item_func_interval((Item_row *)$1);
           }
@@ -5006,8 +5073,8 @@
             {
               if (lex->current_select->inc_in_sum_expr())
               {
-                yyerror(ER(ER_SYNTAX_ERROR));
-                YYABORT;
+                my_parse_error(ER(ER_SYNTAX_ERROR));
+                MYSQL_YYABORT;
               }
             }
             lex->current_select->udf_list.push_front(udf);
@@ -5090,7 +5157,7 @@
                 }
                 break;
               default:
-                YYABORT;
+                MYSQL_YYABORT;
               }
             }
             else
@@ -5099,7 +5166,7 @@
               THD *thd= lex->thd;
               LEX_STRING db;
               if (thd->copy_db_to(&db.str, &db.length))
-                YYABORT;
+                MYSQL_YYABORT;
               sp_name *name= new sp_name(db, $1);
               if (name)
                 name->init_qname(thd);
@@ -5260,8 +5327,8 @@
                 Disallow using AS to specify explicit names for the arguments
                 of stored routine calls
               */
-              yyerror(ER(ER_SYNTAX_ERROR));
-              YYABORT;
+              my_parse_error(ER(ER_SYNTAX_ERROR));
+              MYSQL_YYABORT;
             }
 
             $2->is_autogenerated_name= FALSE;
@@ -5340,7 +5407,7 @@
             if (! Lex->parsing_options.allows_variable)
             {
               my_error(ER_VIEW_SELECT_VARIABLE, MYF(0));
-              YYABORT;
+              MYSQL_YYABORT;
             }
           }
           variable_aux
@@ -5366,11 +5433,11 @@
           {
             if ($3.str && $4.str && check_reserved_words(&$3))
             {
-              yyerror(ER(ER_SYNTAX_ERROR));
-              YYABORT;
+              my_parse_error(ER(ER_SYNTAX_ERROR));
+              MYSQL_YYABORT;
             }
             if (!($$= get_system_var(YYTHD, $2, $3, $4)))
-              YYABORT;
+              MYSQL_YYABORT;
           }
         ;
 
@@ -5404,8 +5471,8 @@
 	  LEX *lex= Lex;
 	  if (lex->current_select->inc_in_sum_expr())
 	  {
-	    yyerror(ER(ER_SYNTAX_ERROR));
-	    YYABORT;
+            my_parse_error(ER(ER_SYNTAX_ERROR));
+	    MYSQL_YYABORT;
 	  }
 	}
 	expr
@@ -5485,12 +5552,12 @@
           {
 	    LEX *lex= Lex;
             if (!($$= lex->current_select->nest_last_join(lex->thd)))
-              YYABORT;
+              MYSQL_YYABORT;
           }
         ;
 
 join_table_list:
-	derived_table_list		{ YYABORT_UNLESS($$=$1); }
+	derived_table_list		{ MYSQL_YYABORT_UNLESS($$=$1); }
 	;
 
 /* Warning - may return NULL in case of incomplete SELECT */
@@ -5498,7 +5565,7 @@
         table_ref { $$=$1; }
         | derived_table_list ',' table_ref
           {
-            YYABORT_UNLESS($1 && ($$=$3));
+            MYSQL_YYABORT_UNLESS($1 && ($$=$3));
           }
         ;
 
@@ -5517,16 +5584,16 @@
           left-associative joins.
         */
         table_ref %prec TABLE_REF_PRIORITY normal_join table_ref
-          { YYABORT_UNLESS($1 && ($$=$3)); }
+          { MYSQL_YYABORT_UNLESS($1 && ($$=$3)); }
 	| table_ref STRAIGHT_JOIN table_factor
-	  { YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1; }
+	  { MYSQL_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1; }
 	| table_ref normal_join table_ref
           ON
           {
-            YYABORT_UNLESS($1 && $3);
+            MYSQL_YYABORT_UNLESS($1 && $3);
             /* Change the current name resolution context to a local context. */
             if (push_new_name_resolution_context(YYTHD, $1, $3))
-              YYABORT;
+              MYSQL_YYABORT;
             Select->parsing_place= IN_ON;
           }
           expr
@@ -5538,10 +5605,10 @@
         | table_ref STRAIGHT_JOIN table_factor
           ON
           {
-            YYABORT_UNLESS($1 && $3);
+            MYSQL_YYABORT_UNLESS($1 && $3);
             /* Change the current name resolution context to a local context. */
             if (push_new_name_resolution_context(YYTHD, $1, $3))
-              YYABORT;
+              MYSQL_YYABORT;
             Select->parsing_place= IN_ON;
           }
           expr
@@ -5554,13 +5621,13 @@
 	| table_ref normal_join table_ref
 	  USING
 	  {
-            YYABORT_UNLESS($1 && $3);
+            MYSQL_YYABORT_UNLESS($1 && $3);
 	  }
 	  '(' using_list ')'
           { add_join_natural($1,$3,$7,Select); $$=$3; }
 	| table_ref NATURAL JOIN_SYM table_factor
 	  {
-            YYABORT_UNLESS($1 && ($$=$4));
+            MYSQL_YYABORT_UNLESS($1 && ($$=$4));
             add_join_natural($1,$4,NULL,Select);
           }
 
@@ -5568,10 +5635,10 @@
 	| table_ref LEFT opt_outer JOIN_SYM table_ref
           ON
           {
-            YYABORT_UNLESS($1 && $5);
+            MYSQL_YYABORT_UNLESS($1 && $5);
             /* Change the current name resolution context to a local context. */
             if (push_new_name_resolution_context(YYTHD, $1, $5))
-              YYABORT;
+              MYSQL_YYABORT;
             Select->parsing_place= IN_ON;
           }
           expr
@@ -5584,7 +5651,7 @@
           }
 	| table_ref LEFT opt_outer JOIN_SYM table_factor
 	  {
-            YYABORT_UNLESS($1 && $5);
+            MYSQL_YYABORT_UNLESS($1 && $5);
 	  }
 	  USING '(' using_list ')'
           { 
@@ -5594,7 +5661,7 @@
           }
 	| table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
 	  {
-            YYABORT_UNLESS($1 && $6);
+            MYSQL_YYABORT_UNLESS($1 && $6);
  	    add_join_natural($1,$6,NULL,Select);
 	    $6->outer_join|=JOIN_TYPE_LEFT;
 	    $$=$6;
@@ -5604,39 +5671,39 @@
 	| table_ref RIGHT opt_outer JOIN_SYM table_ref
           ON
           {
-            YYABORT_UNLESS($1 && $5);
+            MYSQL_YYABORT_UNLESS($1 && $5);
             /* Change the current name resolution context to a local context. */
             if (push_new_name_resolution_context(YYTHD, $1, $5))
-              YYABORT;
+              MYSQL_YYABORT;
             Select->parsing_place= IN_ON;
           }
           expr
           {
 	    LEX *lex= Lex;
             if (!($$= lex->current_select->convert_right_join()))
-              YYABORT;
+              MYSQL_YYABORT;
             add_join_on($$, $8);
             Lex->pop_context();
             Select->parsing_place= NO_MATTER;
           }
 	| table_ref RIGHT opt_outer JOIN_SYM table_factor
 	  {
-            YYABORT_UNLESS($1 && $5);
+            MYSQL_YYABORT_UNLESS($1 && $5);
 	  }
 	  USING '(' using_list ')'
           {
 	    LEX *lex= Lex;
             if (!($$= lex->current_select->convert_right_join()))
-              YYABORT;
+              MYSQL_YYABORT;
             add_join_natural($$,$5,$9,Select);
           }
 	| table_ref NATURAL RIGHT opt_outer JOIN_SYM table_factor
 	  {
-            YYABORT_UNLESS($1 && $6);
+            MYSQL_YYABORT_UNLESS($1 && $6);
 	    add_join_natural($6,$1,NULL,Select);
 	    LEX *lex= Lex;
             if (!($$= lex->current_select->convert_right_join()))
-              YYABORT;
+              MYSQL_YYABORT;
 	  };
 
 normal_join:
@@ -5661,7 +5728,7 @@
 					   lex->lock_option,
 					   sel->get_use_index(),
 					   sel->get_ignore_index())))
-	    YYABORT;
+	    MYSQL_YYABORT;
           sel->add_joined_table($$);
 	}
 	| '{' ident table_ref LEFT OUTER JOIN_SYM table_ref
@@ -5669,19 +5736,19 @@
           {
             /* Change the current name resolution context to a local context. */
             if (push_new_name_resolution_context(YYTHD, $3, $7))
-              YYABORT;
+              MYSQL_YYABORT;
 
           }
           expr '}'
 	  {
 	    LEX *lex= Lex;
-            YYABORT_UNLESS($3 && $7);
+            MYSQL_YYABORT_UNLESS($3 && $7);
             add_join_on($7,$10);
             Lex->pop_context();
             $7->outer_join|=JOIN_TYPE_LEFT;
             $$=$7;
             if (!($$= lex->current_select->nest_last_join(lex->thd)))
-              YYABORT;
+              MYSQL_YYABORT;
           }
 	| select_derived_init get_select_lex select_derived2
           {
@@ -5691,8 +5758,8 @@
             {
 	      if (sel->set_braces(1))
 	      {
-	        yyerror(ER(ER_SYNTAX_ERROR));
-	        YYABORT;
+                my_parse_error(ER(ER_SYNTAX_ERROR));
+	        MYSQL_YYABORT;
 	      }
               /* select in braces, can't contain global parameters */
 	      if (sel->master_unit()->fake_select_lex)
@@ -5700,7 +5767,7 @@
                    sel->master_unit()->fake_select_lex;
             }
             if ($2->init_nested_join(lex->thd))
-              YYABORT;
+              MYSQL_YYABORT;
             $$= 0;
             /* incomplete derived tables return NULL, we must be
                nested in select_derived rule to be here. */
@@ -5734,7 +5801,7 @@
 				    TL_READ,(List<String> *)0,
 	                            (List<String> *)0)))
 
-	      YYABORT;
+	      MYSQL_YYABORT;
             sel->add_joined_table($$);
             lex->pop_context();
           }
@@ -5742,8 +5809,8 @@
           if ($4 || $6)
 	  {
             /* simple nested joins cannot have aliases or unions */
-            yyerror(ER(ER_SYNTAX_ERROR));
-	    YYABORT;
+            my_parse_error(ER(ER_SYNTAX_ERROR));
+	    MYSQL_YYABORT;
 	  }
           else
             $$= $3;
@@ -5756,7 +5823,7 @@
 	  {
             LEX *lex= Lex;
             if ($1->init_nested_join(lex->thd))
-              YYABORT;
+              MYSQL_YYABORT;
           }
           derived_table_list
           {
@@ -5765,11 +5832,11 @@
                for derived tables, both must equal NULL */
 
             if (!($$= $1->end_nested_join(lex->thd)) && $3)
-              YYABORT;
+              MYSQL_YYABORT;
             if (!$3 && $$)
             {
-	      yyerror(ER(ER_SYNTAX_ERROR));
-	      YYABORT;
+              my_parse_error(ER(ER_SYNTAX_ERROR));
+	      MYSQL_YYABORT;
             }
           }
  	;
@@ -5781,12 +5848,12 @@
           if (lex->sql_command == (int)SQLCOM_HA_READ ||
               lex->sql_command == (int)SQLCOM_KILL)
 	  {
-	    yyerror(ER(ER_SYNTAX_ERROR));
-	    YYABORT;
+            my_parse_error(ER(ER_SYNTAX_ERROR));
+	    MYSQL_YYABORT;
 	  }
 	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
               mysql_new_select(lex, 1))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  mysql_init_select(lex);
 	  lex->current_select->linkage= DERIVED_TABLE_TYPE;
 	  lex->current_select->parsing_place= SELECT_LIST;
@@ -5810,7 +5877,7 @@
             if (! lex->parsing_options.allows_derived)
             {
               my_error(ER_VIEW_SELECT_DERIVED, MYF(0));
-              YYABORT;
+              MYSQL_YYABORT;
             }
 
             SELECT_LEX *sel= lex->current_select;
@@ -5818,8 +5885,8 @@
             if (!sel->embedding || sel->end_nested_join(lex->thd))
 	    {
               /* we are not in parentheses */
-              yyerror(ER(ER_SYNTAX_ERROR));
-	      YYABORT;
+              my_parse_error(ER(ER_SYNTAX_ERROR));
+	      MYSQL_YYABORT;
 	    }
             embedding= Select->embedding;
             $$= embedding &&
@@ -5883,7 +5950,7 @@
 	ident
 	  {
             if (!($$= new List<String>))
-	      YYABORT;
+	      MYSQL_YYABORT;
             $$->push_back(new (YYTHD->mem_root)
                               String((const char *) $1.str, $1.length,
                                       system_charset_info));
@@ -6003,9 +6070,9 @@
 
 group_list:
 	group_list ',' order_ident order_dir
-	  { if (add_group_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
+	  { if (add_group_to_list(YYTHD, $3,(bool) $4)) MYSQL_YYABORT; }
 	| order_ident order_dir
-	  { if (add_group_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
+	  { if (add_group_to_list(YYTHD, $1,(bool) $2)) MYSQL_YYABORT; };
 
 olap_opt:
 	/* empty */ {}
@@ -6016,11 +6083,11 @@
 	    {
 	      my_error(ER_WRONG_USAGE, MYF(0), "WITH CUBE",
 		       "global union parameters");
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    lex->current_select->olap= CUBE_TYPE;
 	    my_error(ER_NOT_SUPPORTED_YET, MYF(0), "CUBE");
-	    YYABORT;	/* To be deleted in 5.1 */
+	    MYSQL_YYABORT;	/* To be deleted in 5.1 */
 	  }
 	| WITH ROLLUP_SYM
           {
@@ -6029,7 +6096,7 @@
 	    {
 	      my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
 		       "global union parameters");
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    lex->current_select->olap= ROLLUP_TYPE;
 	  }
@@ -6054,7 +6121,7 @@
             THD *thd= YYTHD;
             bool ascending= ($2 == 1) ? true : false;
             if (add_order_to_list(thd, $1, ascending))
-              YYABORT;
+              MYSQL_YYABORT;
           }
         ;
 
@@ -6077,7 +6144,7 @@
 	  {
 	    my_error(ER_WRONG_USAGE, MYF(0),
                      "CUBE/ROLLUP", "ORDER BY");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
           if (lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
           {
@@ -6094,15 +6161,15 @@
                 (first_sl->order_list.elements || 
                  first_sl->select_limit) &&            
                 unit->add_fake_select_lex(lex->thd))
-              YYABORT;
+              MYSQL_YYABORT;
           }
 	} order_list;
 
 order_list:
 	order_list ',' order_ident order_dir
-	  { if (add_order_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
+	  { if (add_order_to_list(YYTHD, $3,(bool) $4)) MYSQL_YYABORT; }
 	| order_ident order_dir
-	  { if (add_order_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
+	  { if (add_order_to_list(YYTHD, $1,(bool) $2)) MYSQL_YYABORT; };
 
 order_dir:
 	/* empty */ { $$ =  1; }
@@ -6199,13 +6266,13 @@
             if (! lex->parsing_options.allows_select_procedure)
             {
               my_error(ER_VIEW_SELECT_CLAUSE, MYF(0), "PROCEDURE");
-              YYABORT;
+              MYSQL_YYABORT;
             }
 
 	    if (&lex->select_lex != lex->current_select)
 	    {
 	      my_error(ER_WRONG_USAGE, MYF(0), "PROCEDURE", "subquery");
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    lex->proc_list.elements=0;
 	    lex->proc_list.first=0;
@@ -6214,7 +6281,7 @@
                                                           current_select->
                                                           context,
                                                           NULL,NULL,$2.str)))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
 	  }
 	  '(' procedure_list ')';
@@ -6233,7 +6300,7 @@
 	  {
 	    LEX *lex= Lex;
 	    if (add_proc_to_list(lex->thd, $2))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    if (!$2->name)
 	      $2->set_name($1,(uint) ((char*) lex->tok_end - $1),
                            YYTHD->charset());
@@ -6245,7 +6312,7 @@
 	   {
              LEX *lex=Lex;
 	     if (!lex->describe && (!(lex->result= new select_dumpvar())))
-	        YYABORT;
+	        MYSQL_YYABORT;
 	   }
 	   select_var_list
 	   {}
@@ -6277,7 +6344,7 @@
 	     if (!lex->spcont || !(t=lex->spcont->find_variable(&$1)))
 	     {
 	       my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str);
-	       YYABORT;
+	       MYSQL_YYABORT;
 	     }
 	     if (lex->result)
              {
@@ -6306,7 +6373,7 @@
           if (! Lex->parsing_options.allows_select_into)
           {
             my_error(ER_VIEW_SELECT_CLAUSE, MYF(0), "INTO");
-            YYABORT;
+            MYSQL_YYABORT;
           }
 	}
         into_destination
@@ -6319,7 +6386,7 @@
           lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
           if (!(lex->exchange= new sql_exchange($2.str, 0)) ||
               !(lex->result= new select_export(lex->exchange)))
-            YYABORT;
+            MYSQL_YYABORT;
 	}
 	opt_field_term opt_line_term
 	| DUMPFILE TEXT_STRING_filesystem
@@ -6329,9 +6396,9 @@
 	  {
 	    lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
 	    if (!(lex->exchange= new sql_exchange($2.str,1)))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    if (!(lex->result= new select_dump(lex->exchange)))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	  }
 	}
         | select_var_list_init
@@ -6378,7 +6445,7 @@
                                                                 $3.str));
 	     if (!lex->current_select->add_table_to_list(lex->thd, $5, NULL,
 							TL_OPTION_UPDATING))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	  }
 	| DROP DATABASE if_exists ident
 	  {
@@ -6393,7 +6460,7 @@
 	    if (lex->sphead)
 	    {
 	      my_error(ER_SP_NO_DROP_SP, MYF(0), "FUNCTION");
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    lex->sql_command = SQLCOM_DROP_FUNCTION;
 	    lex->drop_if_exists= $3;
@@ -6405,7 +6472,7 @@
 	    if (lex->sphead)
 	    {
 	      my_error(ER_SP_NO_DROP_SP, MYF(0), "PROCEDURE");
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    lex->sql_command = SQLCOM_DROP_PROCEDURE;
 	    lex->drop_if_exists= $3;
@@ -6438,7 +6505,7 @@
 	table_ident
 	{
 	  if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	}
 	;
 
@@ -6536,7 +6603,7 @@
 	    LEX *lex=Lex;
 	    if (!(lex->insert_list = new List_item) ||
 		lex->many_values.push_back(lex->insert_list))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	   }
 	   ident_eq_list;
 
@@ -6566,7 +6633,7 @@
 	  LEX *lex=Lex;
 	  if (lex->field_list.push_back($1) ||
 	      lex->insert_list->push_back($3))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	 };
 
 equal:	EQ		{}
@@ -6582,13 +6649,13 @@
 	 '('
 	 {
 	    if (!(Lex->insert_list = new List_item))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	 }
 	 opt_values ')'
 	 {
 	  LEX *lex=Lex;
 	  if (lex->many_values.push_back(lex->insert_list))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	 };
 
 opt_values:
@@ -6599,12 +6666,12 @@
 	values ','  expr_or_default
 	{
 	  if (Lex->insert_list->push_back($3))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	}
 	| expr_or_default
 	  {
 	    if (Lex->insert_list->push_back($1))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	  }
 	;
 
@@ -6641,7 +6708,7 @@
 	    /* it is single table update and it is update of derived table */
 	    my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
                      lex->select_lex.get_table_list()->alias, "UPDATE");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
           /*
             In case of multi-update setting write lock for all tables may
@@ -6661,7 +6728,7 @@
 	simple_ident_nospvar equal expr_or_default
 	{
 	  if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	};
 
 insert_update_list:
@@ -6674,7 +6741,7 @@
 	  LEX *lex= Lex;
 	  if (lex->update_list.push_back($1) || 
 	      lex->value_list.push_back($3))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	  };
 
 opt_low_priority:
@@ -6701,7 +6768,7 @@
 	{
 	  if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
 					 Lex->lock_option))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	}
 	where_clause opt_order_clause
 	delete_limit_clause {}
@@ -6710,14 +6777,14 @@
           FROM join_table_list where_clause
           { 
             if (multi_delete_set_locks_and_link_aux_tables(Lex))
-              YYABORT;
+              MYSQL_YYABORT;
           }
 	| FROM table_wild_list
 	  { mysql_init_multi_delete(Lex); }
 	  USING join_table_list where_clause
           { 
             if (multi_delete_set_locks_and_link_aux_tables(Lex))
-              YYABORT;
+              MYSQL_YYABORT;
           }
 	;
 
@@ -6731,7 +6798,7 @@
 	  if (!Select->add_table_to_list(YYTHD, new Table_ident($1), $3,
 					 TL_OPTION_UPDATING | 
                                          TL_OPTION_ALIAS, Lex->lock_option))
-	    YYABORT;
+	    MYSQL_YYABORT;
         }
 	| ident '.' ident opt_wild opt_table_alias
 	  {
@@ -6741,7 +6808,7 @@
                                            TL_OPTION_UPDATING | 
                                            TL_OPTION_ALIAS,
 					   Lex->lock_option))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	  }
 	;
 
@@ -6796,7 +6863,7 @@
            lex->sql_command= SQLCOM_SELECT;
            lex->orig_sql_command= SQLCOM_SHOW_DATABASES;
            if (prepare_schema_table(YYTHD, lex, 0, SCH_SCHEMATA))
-             YYABORT;
+             MYSQL_YYABORT;
          }
          | opt_full TABLES opt_db wild_and_where
            {
@@ -6805,7 +6872,7 @@
              lex->orig_sql_command= SQLCOM_SHOW_TABLES;
              lex->select_lex.db= $3;
              if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLE_NAMES))
-               YYABORT;
+               MYSQL_YYABORT;
            }
          | opt_full TRIGGERS_SYM opt_db wild_and_where
            {
@@ -6814,7 +6881,7 @@
              lex->orig_sql_command= SQLCOM_SHOW_TRIGGERS;
              lex->select_lex.db= $3;
              if (prepare_schema_table(YYTHD, lex, 0, SCH_TRIGGERS))
-               YYABORT;
+               MYSQL_YYABORT;
            }
          | TABLE_SYM STATUS_SYM opt_db wild_and_where
            {
@@ -6823,7 +6890,7 @@
              lex->orig_sql_command= SQLCOM_SHOW_TABLE_STATUS;
              lex->select_lex.db= $3;
              if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLES))
-               YYABORT;
+               MYSQL_YYABORT;
            }
         | OPEN_SYM TABLES opt_db wild_and_where
 	  {
@@ -6832,7 +6899,7 @@
             lex->orig_sql_command= SQLCOM_SHOW_OPEN_TABLES;
 	    lex->select_lex.db= $3;
             if (prepare_schema_table(YYTHD, lex, 0, SCH_OPEN_TABLES))
-              YYABORT;
+              MYSQL_YYABORT;
 	  }
 	| ENGINE_SYM storage_engines 
 	  { Lex->create_info.db_type= $2; }
@@ -6845,7 +6912,7 @@
 	    if ($5)
 	      $4->change_db($5);
 	    if (prepare_schema_table(YYTHD, lex, $4, SCH_COLUMNS))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	  }
         | NEW_SYM MASTER_SYM FOR_SYM SLAVE WITH MASTER_LOG_FILE_SYM EQ
 	  TEXT_STRING_sys AND_SYM MASTER_LOG_POS_SYM EQ ulonglong_num
@@ -6878,7 +6945,7 @@
 	    if ($4)
 	      $3->change_db($4);
             if (prepare_schema_table(YYTHD, lex, $3, SCH_STATISTICS))
-              YYABORT;
+              MYSQL_YYABORT;
 	  }
 	| COLUMN_SYM TYPES_SYM
 	  {
@@ -6916,7 +6983,7 @@
             lex->orig_sql_command= SQLCOM_SHOW_STATUS;
             lex->option_type= $1;
             if (prepare_schema_table(YYTHD, lex, 0, SCH_STATUS))
-              YYABORT;
+              MYSQL_YYABORT;
 	  }	
         | INNOBASE_SYM STATUS_SYM
           { Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS; WARN_DEPRECATED("SHOW INNODB STATUS", "SHOW ENGINE INNODB STATUS"); }
@@ -6931,7 +6998,7 @@
             lex->orig_sql_command= SQLCOM_SHOW_VARIABLES;
             lex->option_type= $1;
             if (prepare_schema_table(YYTHD, lex, 0, SCH_VARIABLES))
-              YYABORT;
+              MYSQL_YYABORT;
 	  }
         | charset wild_and_where
           {
@@ -6939,7 +7006,7 @@
             lex->sql_command= SQLCOM_SELECT;
             lex->orig_sql_command= SQLCOM_SHOW_CHARSETS;
             if (prepare_schema_table(YYTHD, lex, 0, SCH_CHARSETS))
-              YYABORT;
+              MYSQL_YYABORT;
           }
         | COLLATION_SYM wild_and_where
           {
@@ -6947,7 +7014,7 @@
             lex->sql_command= SQLCOM_SELECT;
             lex->orig_sql_command= SQLCOM_SHOW_COLLATIONS;
             if (prepare_schema_table(YYTHD, lex, 0, SCH_COLLATIONS))
-              YYABORT;
+              MYSQL_YYABORT;
           }
 	| BERKELEY_DB_SYM LOGS_SYM
 	  { Lex->sql_command= SQLCOM_SHOW_LOGS; WARN_DEPRECATED("SHOW BDB LOGS", "SHOW ENGINE BDB LOGS"); }
@@ -6959,7 +7026,7 @@
 	    lex->sql_command= SQLCOM_SHOW_GRANTS;
 	    LEX_USER *curr_user;
             if (!(curr_user= (LEX_USER*) lex->thd->alloc(sizeof(st_lex_user))))
-              YYABORT;
+              MYSQL_YYABORT;
             bzero(curr_user, sizeof(st_lex_user));
 	    lex->grant_user= curr_user;
 	  }
@@ -6981,7 +7048,7 @@
             LEX *lex= Lex;
 	    lex->sql_command = SQLCOM_SHOW_CREATE;
 	    if (!lex->select_lex.add_table_to_list(YYTHD, $3, NULL,0))
-	      YYABORT;
+	      MYSQL_YYABORT;
             lex->only_view= 0;
 	  }
         | CREATE VIEW_SYM table_ident
@@ -6989,7 +7056,7 @@
             LEX *lex= Lex;
 	    lex->sql_command = SQLCOM_SHOW_CREATE;
 	    if (!lex->select_lex.add_table_to_list(YYTHD, $3, NULL, 0))
-	      YYABORT;
+	      MYSQL_YYABORT;
             lex->only_view= 1;
 	  }
         | MASTER_SYM STATUS_SYM
@@ -7020,9 +7087,9 @@
             lex->sql_command= SQLCOM_SELECT;
             lex->orig_sql_command= SQLCOM_SHOW_STATUS_PROC;
 	    if (!sp_add_to_query_tables(YYTHD, lex, "mysql", "proc", TL_READ))
-	      YYABORT;
+	      MYSQL_YYABORT;
             if (prepare_schema_table(YYTHD, lex, 0, SCH_PROCEDURES))
-              YYABORT;
+              MYSQL_YYABORT;
 	  }
 	| FUNCTION_SYM STATUS_SYM wild_and_where
 	  {
@@ -7030,15 +7097,15 @@
             lex->sql_command= SQLCOM_SELECT;
             lex->orig_sql_command= SQLCOM_SHOW_STATUS_FUNC;
 	    if (!sp_add_to_query_tables(YYTHD, lex, "mysql", "proc", TL_READ))
-	      YYABORT;
+	      MYSQL_YYABORT;
             if (prepare_schema_table(YYTHD, lex, 0, SCH_PROCEDURES))
-              YYABORT;
+              MYSQL_YYABORT;
 	  }
         | PROCEDURE CODE_SYM sp_name
           {
 #ifdef DBUG_OFF
-            yyerror(ER(ER_SYNTAX_ERROR));
-            YYABORT;
+            my_parse_error(ER(ER_SYNTAX_ERROR));
+            MYSQL_YYABORT;
 #else
             Lex->sql_command= SQLCOM_SHOW_PROC_CODE;
 	    Lex->spname= $3;
@@ -7047,8 +7114,8 @@
         | FUNCTION_SYM CODE_SYM sp_name
           {
 #ifdef DBUG_OFF
-            yyerror(ER(ER_SYNTAX_ERROR));
-            YYABORT;
+            my_parse_error(ER(ER_SYNTAX_ERROR));
+            MYSQL_YYABORT;
 #else
             Lex->sql_command= SQLCOM_SHOW_FUNC_CODE;
 	    Lex->spname= $3;
@@ -7068,7 +7135,7 @@
 	      break;
 	    default:
 	      my_error(ER_NOT_SUPPORTED_YET, MYF(0), "STATUS");
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	  }
 	| LOGS_SYM
@@ -7079,7 +7146,7 @@
 	      break;
 	    default:
 	      my_error(ER_NOT_SUPPORTED_YET, MYF(0), "LOGS");
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	  };
 
@@ -7138,7 +7205,7 @@
           lex->select_lex.db= 0;
           lex->verbose= 0;
           if (prepare_schema_table(YYTHD, lex, $2, SCH_COLUMNS))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	}
 	opt_describe_column {}
 	| describe_command opt_extended_describe
@@ -7280,7 +7347,7 @@
 	  if (lex->sphead)
 	  {
 	    my_error(ER_SP_BADSTATEMENT, MYF(0), "LOAD DATA");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
           lex->fname_start= lex->ptr;
         }
@@ -7293,14 +7360,14 @@
 	  if (lex->sphead)
 	  {
 	    my_error(ER_SP_BADSTATEMENT, MYF(0), "LOAD TABLE");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
           lex->sql_command = SQLCOM_LOAD_MASTER_TABLE;
           WARN_DEPRECATED("LOAD TABLE FROM MASTER",
                           "mysqldump or future "
                           "BACKUP/RESTORE DATABASE facility");
           if (!Select->add_table_to_list(YYTHD, $3, NULL, TL_OPTION_UPDATING))
-            YYABORT;
+            MYSQL_YYABORT;
         };
 
 load_data:
@@ -7313,7 +7380,7 @@
 	  lex->duplicates= DUP_ERROR;
 	  lex->ignore= 0;
 	  if (!(lex->exchange= new sql_exchange($4.str, 0)))
-	    YYABORT;
+	    MYSQL_YYABORT;
         }
         opt_duplicate INTO
         {
@@ -7325,7 +7392,7 @@
           LEX *lex=Lex;
           if (!Select->add_table_to_list(YYTHD, $10, NULL, TL_OPTION_UPDATING,
                                          lex->lock_option))
-            YYABORT;
+            MYSQL_YYABORT;
           lex->field_list.empty();
           lex->update_list.empty();
           lex->value_list.empty();
@@ -7504,13 +7571,13 @@
           if (! lex->parsing_options.allows_variable)
           {
             my_error(ER_VIEW_SELECT_VARIABLE, MYF(0));
-            YYABORT;
+            MYSQL_YYABORT;
           }
           item= new Item_param((uint) (lex->tok_start - (uchar *) thd->query));
           if (!($$= item) || lex->param_list.push_back(item))
           {
             my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
-            YYABORT;
+            MYSQL_YYABORT;
           }
         }
 	;
@@ -7576,7 +7643,7 @@
            $$= new Item_decimal($1.str, $1.length, YYTHD->charset());
 	   if (YYTHD->net.report_error)
 	   {
-	     YYABORT;
+	     MYSQL_YYABORT;
 	   }
 	}
 	| FLOAT_NUM
@@ -7584,7 +7651,7 @@
 	   $$ =	new Item_float($1.str, $1.length);
 	   if (YYTHD->net.report_error)
 	   {
-	     YYABORT;
+	     MYSQL_YYABORT;
 	   }
 	}
 	;
@@ -7629,7 +7696,7 @@
             if (! lex->parsing_options.allows_variable)
             {
               my_error(ER_VIEW_SELECT_VARIABLE, MYF(0));
-              YYABORT;
+              MYSQL_YYABORT;
             }
 
             Item_splocal *splocal;
@@ -7689,14 +7756,14 @@
                 !new_row)
             {
               my_error(ER_TRG_NO_SUCH_ROW_IN_TRG, MYF(0), "OLD", "on INSERT");
-              YYABORT;
+              MYSQL_YYABORT;
             }
 
             if (lex->trg_chistics.event == TRG_EVENT_DELETE &&
                 new_row)
             {
               my_error(ER_TRG_NO_SUCH_ROW_IN_TRG, MYF(0), "NEW", "on DELETE");
-              YYABORT;
+              MYSQL_YYABORT;
             }
 
             DBUG_ASSERT(!new_row ||
@@ -7711,7 +7778,7 @@
                                                   $3.str,
                                                   SELECT_ACL,
                                                   read_only)))
-              YYABORT;
+              MYSQL_YYABORT;
 
             /*
               Let us add this item to list of all Item_trigger_field objects
@@ -7782,13 +7849,13 @@
             if (my_strcasecmp(table_alias_charset, $1.str, table->db))
             {
               my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
-              YYABORT;
+              MYSQL_YYABORT;
             }
             if (my_strcasecmp(table_alias_charset, $3.str,
                               table->table_name))
             {
               my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
-              YYABORT;
+              MYSQL_YYABORT;
             }
             $$=$5;
           }
@@ -7798,7 +7865,7 @@
             if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
             {
               my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
-              YYABORT;
+              MYSQL_YYABORT;
             }
             $$=$3;
           }
@@ -7830,7 +7897,7 @@
               {
                 my_error(ER_INVALID_CHARACTER_STRING, MYF(0),
                          cs->csname, $1.str + wlen);
-                YYABORT;
+                MYSQL_YYABORT;
               }
 	      $$= $1;
             }
@@ -7907,32 +7974,32 @@
 	{
 	  THD *thd= YYTHD;
 	  if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  $$->user = $1;
 	  $$->host.str= (char *) "%";
 	  $$->host.length= 1;
 
 	  if (check_string_length(&$$->user,
                                   ER(ER_USERNAME), USERNAME_LENGTH))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	}
 	| ident_or_text '@' ident_or_text
 	  {
 	    THD *thd= YYTHD;
 	    if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    $$->user = $1; $$->host=$3;
 
 	    if (check_string_length(&$$->user,
                                     ER(ER_USERNAME), USERNAME_LENGTH) ||
 	        check_string_length(&$$->host,
                                     ER(ER_HOSTNAME), HOSTNAME_LENGTH))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	  }
 	| CURRENT_USER optional_braces
 	{
           if (!($$=(LEX_USER*) YYTHD->alloc(sizeof(st_lex_user))))
-            YYABORT;
+            MYSQL_YYABORT;
           /* 
             empty LEX_USER means current_user and 
             will be handled in the  get_current_user() function
@@ -8275,7 +8342,7 @@
 
               if (!(i= new sp_instr_stmt(sp->instructions(), lex->spcont,
                                          lex)))
-                YYABORT;
+                MYSQL_YYABORT;
 
               /*
                 Extract the query statement from the tokenizer.  The
@@ -8288,7 +8355,7 @@
                 qbuff.length= lex->tok_end - sp->m_tmp_query;
 
               if (!(qbuff.str= alloc_root(YYTHD->mem_root, qbuff.length + 5)))
-                YYABORT;
+                MYSQL_YYABORT;
 
               strmake(strmake(qbuff.str, "SET ", 4), (char *)sp->m_tmp_query,
                       qbuff.length);
@@ -8344,8 +8411,8 @@
 	    LINT_INIT(sp_fld);
             if ($1)
             {
-              yyerror(ER(ER_SYNTAX_ERROR));
-              YYABORT;
+              my_parse_error(ER(ER_SYNTAX_ERROR));
+              MYSQL_YYABORT;
             }
             if ($4)
               it= $4;
@@ -8367,7 +8434,7 @@
                                 	                 lex->spcont,
 							 trg_fld,
                                         	         it, lex)))
-              YYABORT;
+              MYSQL_YYABORT;
 
             /*
               Let us add this item to list of all Item_trigger_field
@@ -8394,8 +8461,8 @@
             Item *it;
             if ($1)
             {
-              yyerror(ER(ER_SYNTAX_ERROR));
-              YYABORT;
+              my_parse_error(ER(ER_SYNTAX_ERROR));
+              MYSQL_YYABORT;
             }
 
             spv= ctx->find_variable(&$2.base_name);
@@ -8451,9 +8518,9 @@
 	    if (spc && spc->find_variable(&names))
               my_error(ER_SP_BAD_VAR_SHADOW, MYF(0), names.str);
             else
-              yyerror(ER(ER_SYNTAX_ERROR));
+              my_parse_error(ER(ER_SYNTAX_ERROR));
 
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	| NAMES_SYM charset_name_or_default opt_collate
 	{
@@ -8464,7 +8531,7 @@
 	  {
 	    my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
                      $3->name, $2->csname);
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	  lex->var_list.push_back(new set_var_collation_client($3,$3,$3));
 	}
@@ -8481,10 +8548,10 @@
 	    if (spc && spc->find_variable(&pw))
 	    {
               my_error(ER_SP_BAD_VAR_SHADOW, MYF(0), pw.str);
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	    if (!(user=(LEX_USER*) thd->alloc(sizeof(LEX_USER))))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    user->host=null_lex_str;
 	    user->user.str=thd->security_ctx->priv_user;
 	    thd->lex->var_list.push_back(new set_var_password(user, $3));
@@ -8508,7 +8575,7 @@
             /* Not an SP local variable */
 	    sys_var *tmp=find_sys_var($1.str, $1.length);
 	    if (!tmp)
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    $$.var= tmp;
 	    $$.base_name= null_lex_str;
             /*
@@ -8517,7 +8584,7 @@
             */
             if (tmp == &sys_time_zone &&
                 lex->add_time_zone_tables_to_query_tables(YYTHD))
-              YYABORT;
+              MYSQL_YYABORT;
             else if (spc && tmp == &sys_autocommit)
             {
               /*
@@ -8539,8 +8606,8 @@
             LEX *lex= Lex;
             if (check_reserved_words(&$1))
             {
-	      yyerror(ER(ER_SYNTAX_ERROR));
-              YYABORT;
+              my_parse_error(ER(ER_SYNTAX_ERROR));
+              MYSQL_YYABORT;
             }
             if (lex->sphead && lex->sphead->m_type == TYPE_ENUM_TRIGGER &&
                 (!my_strcasecmp(system_charset_info, $1.str, "NEW") || 
@@ -8549,18 +8616,18 @@
               if ($1.str[0]=='O' || $1.str[0]=='o')
               {
                 my_error(ER_TRG_CANT_CHANGE_ROW, MYF(0), "OLD", "");
-                YYABORT;
+                MYSQL_YYABORT;
               }
               if (lex->trg_chistics.event == TRG_EVENT_DELETE)
               {
                 my_error(ER_TRG_NO_SUCH_ROW_IN_TRG, MYF(0),
                          "NEW", "on DELETE");
-                YYABORT;
+                MYSQL_YYABORT;
               }
               if (lex->trg_chistics.action_time == TRG_ACTION_AFTER)
               {
                 my_error(ER_TRG_CANT_CHANGE_ROW, MYF(0), "NEW", "after ");
-                YYABORT;
+                MYSQL_YYABORT;
               }
               /* This special combination will denote field of NEW row */
               $$.var= &trg_new_row_fake_var;
@@ -8570,7 +8637,7 @@
             {
               sys_var *tmp=find_sys_var($3.str, $3.length);
               if (!tmp)
-                YYABORT;
+                MYSQL_YYABORT;
               if (!tmp->is_struct())
                 my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str);
               $$.var= tmp;
@@ -8581,7 +8648,7 @@
 	  {
 	    sys_var *tmp=find_sys_var($3.str, $3.length);
 	    if (!tmp)
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    if (!tmp->is_struct())
 	      my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str);
 	    $$.var= tmp;
@@ -8633,7 +8700,7 @@
 	  if (lex->sphead)
 	  {
 	    my_error(ER_SP_BADSTATEMENT, MYF(0), "LOCK");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	  lex->sql_command= SQLCOM_LOCK_TABLES;
 	}
@@ -8653,7 +8720,7 @@
 	table_ident opt_table_alias lock_option
 	{
 	  if (!Select->add_table_to_list(YYTHD, $1, $2, 0, (thr_lock_type) $3))
-	   YYABORT;
+	   MYSQL_YYABORT;
 	}
         ;
 
@@ -8672,7 +8739,7 @@
 	  if (lex->sphead)
 	  {
 	    my_error(ER_SP_BADSTATEMENT, MYF(0), "UNLOCK");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	  lex->sql_command= SQLCOM_UNLOCK_TABLES;
 	}
@@ -8692,11 +8759,11 @@
 	  if (lex->sphead)
 	  {
 	    my_error(ER_SP_BADSTATEMENT, MYF(0), "HANDLER");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	  lex->sql_command = SQLCOM_HA_OPEN;
 	  if (!lex->current_select->add_table_to_list(lex->thd, $2, $4, 0))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	}
 	| HANDLER_SYM table_ident_nodb CLOSE_SYM
 	{
@@ -8704,11 +8771,11 @@
 	  if (lex->sphead)
 	  {
 	    my_error(ER_SP_BADSTATEMENT, MYF(0), "HANDLER");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	  lex->sql_command = SQLCOM_HA_CLOSE;
 	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	}
 	| HANDLER_SYM table_ident_nodb READ_SYM
 	{
@@ -8716,14 +8783,14 @@
 	  if (lex->sphead)
 	  {
 	    my_error(ER_SP_BADSTATEMENT, MYF(0), "HANDLER");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	  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);
 	  lex->current_select->offset_limit= 0;
 	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
-	    YYABORT;
+	    MYSQL_YYABORT;
         }
         handler_read_or_scan where_clause opt_limit_clause {}
         ;
@@ -8749,7 +8816,7 @@
 	  lex->ha_read_mode = RKEY;
 	  lex->ha_rkey_mode=$1;
 	  if (!(lex->insert_list = new List_item))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	} '(' values ')' { }
         ;
 
@@ -8781,8 +8848,8 @@
           LEX *lex= Lex;
           if (lex->columns.elements)
           {
-            yyerror(ER(ER_SYNTAX_ERROR));
-	    YYABORT;
+            my_parse_error(ER(ER_SYNTAX_ERROR));
+	    MYSQL_YYABORT;
           }
 	  lex->sql_command= SQLCOM_REVOKE;
           lex->type= TYPE_ENUM_FUNCTION;
@@ -8794,8 +8861,8 @@
           LEX *lex= Lex;
           if (lex->columns.elements)
           {
-            yyerror(ER(ER_SYNTAX_ERROR));
-	    YYABORT;
+            my_parse_error(ER(ER_SYNTAX_ERROR));
+	    MYSQL_YYABORT;
           }
 	  lex->sql_command= SQLCOM_REVOKE;
           lex->type= TYPE_ENUM_PROCEDURE;
@@ -8827,8 +8894,8 @@
           LEX *lex= Lex;
           if (lex->columns.elements)
           {
-            yyerror(ER(ER_SYNTAX_ERROR));
-	    YYABORT;
+            my_parse_error(ER(ER_SYNTAX_ERROR));
+	    MYSQL_YYABORT;
           }
           lex->sql_command= SQLCOM_GRANT;
           lex->type= TYPE_ENUM_FUNCTION;
@@ -8840,8 +8907,8 @@
           LEX *lex= Lex;
           if (lex->columns.elements)
           {
-            yyerror(ER(ER_SYNTAX_ERROR));
-	    YYABORT;
+            my_parse_error(ER(ER_SYNTAX_ERROR));
+	    MYSQL_YYABORT;
           }
           lex->sql_command= SQLCOM_GRANT;
           lex->type= TYPE_ENUM_PROCEDURE;
@@ -8918,7 +8985,7 @@
 	  if (lex->x509_subject)
 	  {
 	    my_error(ER_DUP_ARGUMENT, MYF(0), "SUBJECT");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	  lex->x509_subject=$2.str;
 	}
@@ -8928,7 +8995,7 @@
 	  if (lex->x509_issuer)
 	  {
 	    my_error(ER_DUP_ARGUMENT, MYF(0), "ISSUER");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	  lex->x509_issuer=$2.str;
 	}
@@ -8938,7 +9005,7 @@
 	  if (lex->ssl_cipher)
 	  {
 	    my_error(ER_DUP_ARGUMENT, MYF(0), "CIPHER");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	  lex->ssl_cipher=$2.str;
 	}
@@ -8950,14 +9017,14 @@
 	    LEX *lex= Lex;
             THD *thd= lex->thd;
             if (thd->copy_db_to(&lex->current_select->db, NULL))
-              YYABORT;
+              MYSQL_YYABORT;
 	    if (lex->grant == GLOBAL_ACLS)
 	      lex->grant = DB_ACLS & ~GRANT_ACL;
 	    else if (lex->columns.elements)
 	    {
 	      my_message(ER_ILLEGAL_GRANT_FOR_TABLE,
                          ER(ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0));
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	  }
 	| ident '.' '*'
@@ -8970,7 +9037,7 @@
 	    {
 	      my_message(ER_ILLEGAL_GRANT_FOR_TABLE,
                          ER(ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0));
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	  }
 	| '*' '.' '*'
@@ -8983,14 +9050,14 @@
 	    {
 	      my_message(ER_ILLEGAL_GRANT_FOR_TABLE,
                          ER(ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0));
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    }
 	  }
 	| table_ident
 	  {
 	    LEX *lex=Lex;
 	    if (!lex->current_select->add_table_to_list(lex->thd, $1,NULL,0))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	    if (lex->grant == GLOBAL_ACLS)
 	      lex->grant =  TABLE_ACLS & ~GRANT_ACL;
 	  }
@@ -8998,21 +9065,21 @@
 
 
 user_list:
-	user  { if (Lex->users_list.push_back($1)) YYABORT;}
+	user  { if (Lex->users_list.push_back($1)) MYSQL_YYABORT;}
 	| user_list ',' user
 	  {
 	    if (Lex->users_list.push_back($3))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	  }
 	;
 
 
 grant_list:
-	grant_user  { if (Lex->users_list.push_back($1)) YYABORT;}
+	grant_user  { if (Lex->users_list.push_back($1)) MYSQL_YYABORT;}
 	| grant_list ',' grant_user
 	  {
 	    if (Lex->users_list.push_back($3))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	  }
 	;
 
@@ -9235,17 +9302,17 @@
 	  {
 	    /* Only the last SELECT can have  INTO...... */
 	    my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 	  {
-            yyerror(ER(ER_SYNTAX_ERROR));
-	    YYABORT;
+            my_parse_error(ER(ER_SYNTAX_ERROR));
+	    MYSQL_YYABORT;
 	  }
           /* This counter shouldn't be incremented for UNION parts */
           Lex->nest_level--;
 	  if (mysql_new_select(lex, 0))
-	    YYABORT;
+	    MYSQL_YYABORT;
           mysql_init_select(lex);
 	  lex->current_select->linkage=UNION_TYPE;
           if ($2) /* UNION DISTINCT - remember position */
@@ -9339,8 +9406,8 @@
           if (lex->sql_command == (int)SQLCOM_HA_READ ||
               lex->sql_command == (int)SQLCOM_KILL)
 	  {
-            yyerror(ER(ER_SYNTAX_ERROR));
-	    YYABORT;
+            my_parse_error(ER(ER_SYNTAX_ERROR));
+	    MYSQL_YYABORT;
 	  }
           /* 
             we are making a "derived table" for the parenthesis
@@ -9350,7 +9417,7 @@
             SELECT * FROM ((SELECT ...) UNION ...)
           */
 	  if (mysql_new_select(Lex, 1))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	};
 
 subselect_end:
@@ -9468,7 +9535,7 @@
 	  lex->sql_command= SQLCOM_CREATE_VIEW;
 	  /* first table in list is target VIEW name */
 	  if (!lex->select_lex.add_table_to_list(thd, $3, NULL, TL_OPTION_UPDATING))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	}
 	view_list_opt AS view_select view_check_option
 	{}
@@ -9559,11 +9626,11 @@
 	  if (lex->sphead)
 	  {
 	    my_error(ER_SP_NO_RECURSIVE_CREATE, MYF(0), "TRIGGER");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 	
 	  if (!(sp= new sp_head()))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  sp->reset_thd_mem_root(YYTHD);
 	  sp->init(lex);
           sp->init_sp_name(YYTHD, $3);
@@ -9602,7 +9669,7 @@
 	  sp->restore_thd_mem_root(YYTHD);
 	
 	  if (sp->is_not_allowed_in_function("trigger"))
-	      YYABORT;
+	      MYSQL_YYABORT;
 	
 	  /*
 	    We have to do it after parsing trigger body, because some of
@@ -9613,7 +9680,7 @@
 	                                         (LEX_STRING*) 0,
 	                                         TL_OPTION_UPDATING,
                                                  TL_IGNORE))
-	    YYABORT;
+	    MYSQL_YYABORT;
 	}
 	;
 
@@ -9641,7 +9708,7 @@
 	  if (lex->sphead)
 	  {
 	    my_error(ER_SP_NO_RECURSIVE_CREATE, MYF(0), "PROCEDURE");
-	    YYABORT;
+	    MYSQL_YYABORT;
 	  }
 
 	  lex->stmt_definition_begin= $2;
@@ -9727,23 +9794,23 @@
 
 xid: text_string
      {
-       YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE);
+       MYSQL_YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE);
        if (!(Lex->xid=(XID *)YYTHD->alloc(sizeof(XID))))
-         YYABORT;
+         MYSQL_YYABORT;
        Lex->xid->set(1L, $1->ptr(), $1->length(), 0, 0);
      }
      | text_string ',' text_string
      {
-       YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE && $3->length() <= MAXBQUALSIZE);
+       MYSQL_YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE && $3->length() <= MAXBQUALSIZE);
        if (!(Lex->xid=(XID *)YYTHD->alloc(sizeof(XID))))
-         YYABORT;
+         MYSQL_YYABORT;
        Lex->xid->set(1L, $1->ptr(), $1->length(), $3->ptr(), $3->length());
      }
      | text_string ',' text_string ',' ulong_num
      {
-       YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE && $3->length() <= MAXBQUALSIZE);
+       MYSQL_YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE && $3->length() <= MAXBQUALSIZE);
        if (!(Lex->xid=(XID *)YYTHD->alloc(sizeof(XID))))
-         YYABORT;
+         MYSQL_YYABORT;
        Lex->xid->set($5, $1->ptr(), $1->length(), $3->ptr(), $3->length());
      }
      ;

--- 1.64/sql/sql_trigger.cc	2007-02-27 11:46:45 +03:00
+++ 1.65/sql/sql_trigger.cc	2007-03-04 14:44:43 +03:00
@@ -983,11 +983,8 @@
 	thd->spcont= 0;
         if (MYSQLparse((void *)thd) || thd->is_fatal_error)
         {
-          /*
-            Free lex associated resources.
-            QQ: Do we really need all this stuff here ?
-          */
-          delete lex.sphead;
+          /* Currently sphead is always deleted in case of a parse error */
+          DBUG_ASSERT(lex.sphead == 0);
           goto err_with_lex_cleanup;
         }
 

--- 1.195/sql/sql_prepare.cc	2007-02-26 15:57:41 +03:00
+++ 1.196/sql/sql_prepare.cc	2007-03-04 14:44:42 +03:00
@@ -141,6 +141,9 @@
   bool execute(String *expanded_query, bool open_cursor);
   /* Destroy this statement */
   bool deallocate();
+private:
+  MEM_ROOT main_mem_root;
+  LEX main_lex;
 };
 
 
@@ -2034,6 +2037,7 @@
     delete stmt;
     DBUG_VOID_RETURN;
   }
+
   if (thd->stmt_map.insert(thd, stmt))
   {
     /* The statement is deleted and an error is set if insert fails */
@@ -2629,17 +2633,18 @@
 ****************************************************************************/
 
 Prepared_statement::Prepared_statement(THD *thd_arg, Protocol *protocol_arg)
-  :Statement(INITIALIZED, ++thd_arg->statement_id_counter,
-             thd_arg->variables.query_alloc_block_size,
-             thd_arg->variables.query_prealloc_size),
+  :Statement(&main_lex, &main_mem_root,
+             INITIALIZED, ++thd_arg->statement_id_counter),
   thd(thd_arg),
   result(thd_arg),
   protocol(protocol_arg),
   param_array(0),
   param_count(0),
   last_errno(0),
-   flags((uint) IS_IN_USE)
+  flags((uint) IS_IN_USE)
 {
+  init_alloc_root(&main_mem_root, thd_arg->variables.query_alloc_block_size,
+                  thd_arg->variables.query_prealloc_size);
   *last_error= '\0';
 }
 
@@ -2688,6 +2693,7 @@
   */
   free_items();
   delete lex->result;
+  free_root(&main_mem_root, MYF(0));
   DBUG_VOID_RETURN;
 }
 
@@ -2703,6 +2709,7 @@
   DBUG_ENTER("Prepared_statement::cleanup_stmt");
   DBUG_PRINT("enter",("stmt: %p", this));
 
+  DBUG_ASSERT(lex->sphead == 0);
   /* The order is important */
   lex->unit.cleanup();
   cleanup_items(free_list);
@@ -2790,15 +2797,6 @@
       thd->net.report_error || init_param_array(this);
 
   /*
-    The first thing we do after parse error is freeing sp_head to
-    ensure that we have restored original memroot.
-  */
-  if (error && lex->sphead)
-  {
-    delete lex->sphead;
-    lex->sphead= NULL;
-  }
-  /*
     While doing context analysis of the query (in check_prepared_statement)
     we allocate a lot of additional memory: for open tables, JOINs, derived
     tables, etc.  Let's save a snapshot of current parse tree to the
@@ -2823,12 +2821,18 @@
   if (error == 0)
     error= check_prepared_statement(this, name.str != 0);
 
-  /* Free sp_head if check_prepared_statement() failed. */
-  if (error && lex->sphead)
+  /*
+    Currently CREATE PROCEDURE/TRIGGER/EVENT are prohibited in prepared
+    statements: ensure we have no memory leak here if by someone tries
+    to PREPARE stmt FROM "CREATE PROCEDURE ..."
+  */
+  DBUG_ASSERT(lex->sphead == NULL || error != 0);
+  if (lex->sphead)
   {
     delete lex->sphead;
     lex->sphead= NULL;
   }
+
   lex_end(lex);
   cleanup_stmt();
   thd->restore_backup_statement(this, &stmt_backup);
Thread
bk commit into 5.0 tree (kostja:1.2438) BUG#26570konstantin4 Mar