List:Commits« Previous MessageNext Message »
From:antony Date:May 15 2007 3:34pm
Subject:bk commit into 6.0-falcon tree (acurtis:1.2516)
View as plain text  
Below is the list of changes that have just been committed into a local
6.0-falcon repository of antony. When antony 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-05-15 08:33:51-07:00, acurtis@stripped +20 -0
  Merge xiphis.org:/home/antony/work2/mysql-5.1
  into  xiphis.org:/home/antony/work2/mysql-5.1-falcon.merge.2
  Manual merge for some files.
  MERGE: 1.2502.3.18

  BitKeeper/etc/ignore@stripped, 2007-05-15 08:21:56-07:00, acurtis@stripped +1 -1
    auto-union
    MERGE: 1.243.1.48

  configure.in@stripped, 2007-05-15 08:33:47-07:00, acurtis@stripped +0 -1
    Manual merge from 5.1 main to falcon repositories
    MERGE: 1.442.1.17

  mysql-test/r/ctype_utf8.result@stripped, 2007-05-15 08:22:05-07:00, acurtis@stripped +0 -0
    Auto merged
    MERGE: 1.114.1.2

  mysql-test/r/information_schema.result@stripped, 2007-05-15 08:22:05-07:00, acurtis@stripped +0 -0
    Auto merged
    MERGE: 1.151.1.1

  mysql-test/r/view.result@stripped, 2007-05-15 08:22:05-07:00, acurtis@stripped +0 -0
    Auto merged
    MERGE: 1.201.1.22

  mysql-test/t/disabled.def@stripped, 2007-05-15 08:22:05-07:00, acurtis@stripped +0 -0
    Auto merged
    MERGE: 1.175.1.75

  sql/ha_partition.cc@stripped, 2007-05-15 08:22:05-07:00, acurtis@stripped +0 -0
    Auto merged
    MERGE: 1.78.1.13

  sql/ha_partition.h@stripped, 2007-05-15 08:22:05-07:00, acurtis@stripped +0 -0
    Auto merged
    MERGE: 1.28.1.8

  sql/handler.cc@stripped, 2007-05-15 08:22:05-07:00, acurtis@stripped +0 -0
    Auto merged
    MERGE: 1.234.1.73

  sql/item_create.cc@stripped, 2007-05-15 08:33:47-07:00, acurtis@stripped +2 -2
    Manual merge from 5.1 main to falcon repositories
    MERGE: 1.76.1.2

  sql/item_create.h@stripped, 2007-05-15 08:22:05-07:00, acurtis@stripped +0 -0
    Auto merged
    MERGE: 1.49.1.1

  sql/log.cc@stripped, 2007-05-15 08:22:05-07:00, acurtis@stripped +0 -0
    Auto merged
    MERGE: 1.267.1.13

  sql/mysql_priv.h@stripped, 2007-05-15 08:33:47-07:00, acurtis@stripped +0 -1
    Manual merge from 5.1 main to falcon repositories
    MERGE: 1.501.1.3

  sql/mysqld.cc@stripped, 2007-05-15 08:33:47-07:00, acurtis@stripped +19 -18
    Manual merge from 5.1 main to falcon repositories
    MERGE: 1.576.1.68

  sql/set_var.cc@stripped, 2007-05-15 08:33:47-07:00, acurtis@stripped +20 -5
    Manual merge from 5.1 main to falcon repositories
    MERGE: 1.188.1.43

  sql/sql_class.cc@stripped, 2007-05-15 08:22:06-07:00, acurtis@stripped +0 -0
    Auto merged
    MERGE: 1.319.1.15

  sql/sql_parse.cc@stripped, 2007-05-15 08:22:06-07:00, acurtis@stripped +0 -0
    Auto merged
    MERGE: 1.620.1.46

  sql/sql_plugin.cc@stripped, 2007-05-15 08:22:06-07:00, acurtis@stripped +0 -0
    Auto merged
    MERGE: 1.47.1.2

  sql/sql_yacc.yy@stripped, 2007-05-15 08:22:07-07:00, acurtis@stripped +0 -0
    Auto merged
    MERGE: 1.564.1.3

  storage/innobase/handler/ha_innodb.cc@stripped, 2007-05-15 08:22:07-07:00, acurtis@stripped +0 -0
    Auto merged
    MERGE: 1.279.1.59

# 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:	acurtis
# Host:	ltamd64.xiphis.org
# Root:	/home/antony/work2/mysql-5.1-falcon.merge.2/RESYNC

--- 1.254/sql/handler.cc	2007-05-15 08:34:09 -07:00
+++ 1.255/sql/handler.cc	2007-05-15 08:34:09 -07:00
@@ -77,6 +77,15 @@
 uint known_extensions_id= 0;
 
 
+
+static plugin_ref ha_default_plugin(THD *thd)
+{
+  if (thd->variables.table_plugin)
+    return thd->variables.table_plugin;
+  return my_plugin_lock(thd, &global_system_variables.table_plugin);
+}
+
+
 /** @brief
   Return the default storage engine handlerton for thread
 
@@ -89,10 +98,11 @@
 */
 handlerton *ha_default_handlerton(THD *thd)
 {
-  return (thd->variables.table_type != NULL) ?
-          thd->variables.table_type :
-          (global_system_variables.table_type != NULL ?
-           global_system_variables.table_type : myisam_hton);
+  plugin_ref plugin= ha_default_plugin(thd);
+  DBUG_ASSERT(plugin);
+  handlerton *hton= plugin_data(plugin, handlerton*);
+  DBUG_ASSERT(hton);
+  return hton;
 }
 
 
@@ -105,26 +115,30 @@
     name        name of storage engine
   
   RETURN
-    pointer to handlerton
+    pointer to storage engine plugin handle
 */
-handlerton *ha_resolve_by_name(THD *thd, const LEX_STRING *name)
+plugin_ref ha_resolve_by_name(THD *thd, const LEX_STRING *name)
 {
   const LEX_STRING *table_alias;
-  st_plugin_int *plugin;
+  plugin_ref plugin;
 
 redo:
   /* my_strnncoll is a macro and gcc doesn't do early expansion of macro */
   if (thd && !my_charset_latin1.coll->strnncoll(&my_charset_latin1,
                            (const uchar *)name->str, name->length,
                            (const uchar *)STRING_WITH_LEN("DEFAULT"), 0))
-    return ha_default_handlerton(thd);
+    return ha_default_plugin(thd);
 
-  if ((plugin= plugin_lock(name, MYSQL_STORAGE_ENGINE_PLUGIN)))
+  if ((plugin= my_plugin_lock_by_name(thd, name, MYSQL_STORAGE_ENGINE_PLUGIN)))
   {
-    handlerton *hton= (handlerton *)plugin->data;
+    handlerton *hton= plugin_data(plugin, handlerton *);
     if (!(hton->flags & HTON_NOT_USER_SELECTABLE))
-      return hton;
-    plugin_unlock(plugin);
+      return plugin;
+      
+    /*
+      unlocking plugin immediately after locking is relatively low cost.
+    */
+    plugin_unlock(thd, plugin);
   }
 
   /*
@@ -145,19 +159,19 @@
 }
 
 
-const char *ha_get_storage_engine(enum legacy_db_type db_type)
+plugin_ref ha_lock_engine(THD *thd, handlerton *hton)
 {
-  switch (db_type) {
-  case DB_TYPE_DEFAULT:
-    return "DEFAULT";
-  default:
-    if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT &&
-        installed_htons[db_type])
-      return hton2plugin[installed_htons[db_type]->slot]->name.str;
-    /* fall through */
-  case DB_TYPE_UNKNOWN:
-    return "UNKNOWN";
+  if (hton)
+  {
+    st_plugin_int **plugin= hton2plugin + hton->slot;
+    
+#ifdef DBUG_OFF
+    return my_plugin_lock(thd, plugin);
+#else
+    return my_plugin_lock(thd, &plugin);
+#endif
   }
+  return NULL;
 }
 
 
@@ -172,14 +186,16 @@
 
 handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type)
 {
+  plugin_ref plugin;
   switch (db_type) {
   case DB_TYPE_DEFAULT:
     return ha_default_handlerton(thd);
-  case DB_TYPE_UNKNOWN:
-    return NULL;
   default:
-    if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT)
-      return installed_htons[db_type];
+    if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT &&
+        (plugin= ha_lock_engine(thd, installed_htons[db_type])))
+      return plugin_data(plugin, handlerton*);
+    /* fall through */
+  case DB_TYPE_UNKNOWN:
     return NULL;
   }
 }
@@ -199,7 +215,7 @@
   {
     if (report_error)
     {
-      const char *engine_name= ha_get_storage_engine(database_type);
+      const char *engine_name= ha_resolve_storage_engine_name(hton);
       my_error(ER_FEATURE_DISABLED,MYF(0),engine_name,engine_name);
     }
     return NULL;
@@ -238,8 +254,7 @@
     Here the call to current_thd() is ok as we call this function a lot of
     times but we enter this branch very seldom.
   */
-  DBUG_RETURN(get_new_handler(share, alloc,
-                              current_thd->variables.table_type));
+  DBUG_RETURN(get_new_handler(share, alloc, ha_default_handlerton(current_thd)));
 }
 
 
@@ -401,6 +416,7 @@
 {
   handlerton *hton;
   DBUG_ENTER("ha_initialize_handlerton");
+  DBUG_PRINT("plugin", ("initialize plugin: '%s'", plugin->name.str));
 
   hton= (handlerton *)my_malloc(sizeof(handlerton),
                                 MYF(MY_WME | MY_ZEROFILL));
@@ -522,10 +538,10 @@
   DBUG_RETURN(error);
 }
 
-static my_bool dropdb_handlerton(THD *unused1, st_plugin_int *plugin,
+static my_bool dropdb_handlerton(THD *unused1, plugin_ref plugin,
                                  void *path)
 {
-  handlerton *hton= (handlerton *)plugin->data;
+  handlerton *hton= plugin_data(plugin, handlerton *);
   if (hton->state == SHOW_OPTION_YES && hton->drop_database)
     hton->drop_database(hton, (char *)path);
   return FALSE;
@@ -538,10 +554,10 @@
 }
 
 
-static my_bool closecon_handlerton(THD *thd, st_plugin_int *plugin,
+static my_bool closecon_handlerton(THD *thd, plugin_ref plugin,
                                    void *unused)
 {
-  handlerton *hton= (handlerton *)plugin->data;
+  handlerton *hton= plugin_data(plugin, handlerton *);
   /*
     there's no need to rollback here as all transactions must
     be rolled back already
@@ -638,7 +654,7 @@
       {
         push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
                             ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
-                            hton2plugin[(*ht)->slot]->name.str);
+                            ha_resolve_storage_engine_name(*ht));
       }
     }
   }
@@ -886,10 +902,10 @@
   int result;
 };
 
-static my_bool xacommit_handlerton(THD *unused1, st_plugin_int *plugin,
+static my_bool xacommit_handlerton(THD *unused1, plugin_ref plugin,
                                    void *arg)
 {
-  handlerton *hton= (handlerton *)plugin->data;
+  handlerton *hton= plugin_data(plugin, handlerton *);
   if (hton->state == SHOW_OPTION_YES && hton->recover)
   {
     hton->commit_by_xid(hton, ((struct xahton_st *)arg)->xid);
@@ -898,10 +914,10 @@
   return FALSE;
 }
 
-static my_bool xarollback_handlerton(THD *unused1, st_plugin_int *plugin,
+static my_bool xarollback_handlerton(THD *unused1, plugin_ref plugin,
                                      void *arg)
 {
-  handlerton *hton= (handlerton *)plugin->data;
+  handlerton *hton= plugin_data(plugin, handlerton *);
   if (hton->state == SHOW_OPTION_YES && hton->recover)
   {
     hton->rollback_by_xid(hton, ((struct xahton_st *)arg)->xid);
@@ -1004,10 +1020,10 @@
   bool dry_run;
 };
 
-static my_bool xarecover_handlerton(THD *unused, st_plugin_int *plugin,
+static my_bool xarecover_handlerton(THD *unused, plugin_ref plugin,
                                     void *arg)
 {
-  handlerton *hton= (handlerton *)plugin->data;
+  handlerton *hton= plugin_data(plugin, handlerton *);
   struct xarecover_st *info= (struct xarecover_st *) arg;
   int got;
 
@@ -1016,7 +1032,7 @@
     while ((got= hton->recover(hton, info->list, info->len)) > 0 )
     {
       sql_print_information("Found %d prepared transaction(s) in %s",
-                            got, hton2plugin[hton->slot]->name.str);
+                            got, ha_resolve_storage_engine_name(hton));
       for (int i=0; i < got; i ++)
       {
         my_xid x=info->list[i].get_my_xid();
@@ -1192,10 +1208,10 @@
   thd:           the thread handle of the current connection
   return value:  always 0
 */
-static my_bool release_temporary_latches(THD *thd, st_plugin_int *plugin,
+static my_bool release_temporary_latches(THD *thd, plugin_ref plugin,
                                  void *unused)
 {
-  handlerton *hton= (handlerton *)plugin->data;
+  handlerton *hton= plugin_data(plugin, handlerton *);
 
   if (hton->state == SHOW_OPTION_YES && hton->release_temporary_latches)
     hton->release_temporary_latches(hton, thd);
@@ -1318,10 +1334,10 @@
 }
 
 
-static my_bool snapshot_handlerton(THD *thd, st_plugin_int *plugin,
+static my_bool snapshot_handlerton(THD *thd, plugin_ref plugin,
                                    void *arg)
 {
-  handlerton *hton= (handlerton *)plugin->data;
+  handlerton *hton= plugin_data(plugin, handlerton *);
   if (hton->state == SHOW_OPTION_YES &&
       hton->start_consistent_snapshot)
   {
@@ -1349,10 +1365,10 @@
 }
 
 
-static my_bool flush_handlerton(THD *thd, st_plugin_int *plugin,
+static my_bool flush_handlerton(THD *thd, plugin_ref plugin,
                                 void *arg)
 {
-  handlerton *hton= (handlerton *)plugin->data;
+  handlerton *hton= plugin_data(plugin, handlerton *);
   if (hton->state == SHOW_OPTION_YES && hton->flush_logs && 
       hton->flush_logs(hton))
     return TRUE;
@@ -1397,7 +1413,7 @@
 
   /* DB_TYPE_UNKNOWN is used in ALTER TABLE when renaming only .frm files */
   if (table_type == NULL ||
-      ! (file=get_new_handler(&dummy_share, thd->mem_root, table_type)))
+      ! (file=get_new_handler((TABLE_SHARE*)0, thd->mem_root, table_type)))
     DBUG_RETURN(ENOENT);
 
   if (lower_case_table_names == 2 && !(file->ha_table_flags() & HA_FILE_BASED))
@@ -1438,6 +1454,8 @@
     dummy_share.table_name.length= strlen(alias);
     dummy_table.alias= alias;
 
+    file->table_share= &dummy_share;
+    file->table= &dummy_table;
     file->print_error(error, 0);
     strmake(new_error, thd->net.last_error, sizeof(buff)-1);
 
@@ -1458,7 +1476,7 @@
 ****************************************************************************/
 handler *handler::clone(MEM_ROOT *mem_root)
 {
-  handler *new_handler= get_new_handler(table->s, mem_root, table->s->db_type);
+  handler *new_handler= get_new_handler(table->s, mem_root, table->s->db_type());
   if (new_handler && !new_handler->ha_open(table,
                                            table->s->normalized_path.str,
                                            table->db_stat,
@@ -1474,6 +1492,17 @@
   statistic_increment(table->in_use->status_var.*offset, &LOCK_status);
 }
 
+void **handler::ha_data(THD *thd) const
+{
+  return (void **) thd->ha_data + ht->slot;
+}
+
+THD *handler::ha_thd(void) const
+{
+  DBUG_ASSERT(!table || !table->in_use || table->in_use == current_thd);
+  return (table && table->in_use) ? table->in_use : current_thd;
+}
+
 
 bool handler::check_if_log_table_locking_is_allowed(uint sql_command,
                                                     ulong type, TABLE *table)
@@ -1567,8 +1596,7 @@
   register int error;
   DBUG_ENTER("handler::read_first_row");
 
-  statistic_increment(table->in_use->status_var.ha_read_first_count,
-                      &LOCK_status);
+  ha_statistic_increment(&SSV::ha_read_first_count);
 
   /*
     If there is very few deleted rows in the table, find the first row by
@@ -2778,11 +2806,11 @@
   uint* frmlen;
 };
 
-static my_bool discover_handlerton(THD *thd, st_plugin_int *plugin,
+static my_bool discover_handlerton(THD *thd, plugin_ref plugin,
                                    void *arg)
 {
   st_discover_args *vargs= (st_discover_args *)arg;
-  handlerton *hton= (handlerton *)plugin->data;
+  handlerton *hton= plugin_data(plugin, handlerton *);
   if (hton->state == SHOW_OPTION_YES && hton->discover &&
       (!(hton->discover(hton, thd, vargs->db, vargs->name, 
                         vargs->frmblob, 
@@ -2827,11 +2855,11 @@
   List<char> *files;
 };
 
-static my_bool find_files_handlerton(THD *thd, st_plugin_int *plugin,
+static my_bool find_files_handlerton(THD *thd, plugin_ref plugin,
                                    void *arg)
 {
   st_find_files_args *vargs= (st_find_files_args *)arg;
-  handlerton *hton= (handlerton *)plugin->data;
+  handlerton *hton= plugin_data(plugin, handlerton *);
 
 
   if (hton->state == SHOW_OPTION_YES && hton->find_files)
@@ -2858,45 +2886,50 @@
   DBUG_RETURN(error);
 }
 
-
-/** @brief
+/*
   Ask handler if the table exists in engine
 
   RETURN
-    0                   Table does not exist
-    1                   Table exists
-    #                   Error code
+    HA_ERR_NO_SUCH_TABLE     Table does not exist
+    HA_ERR_TABLE_EXIST       Table exists
+    #                        Error code
+
+ */
 
-*/
 struct st_table_exists_in_engine_args
 {
   const char *db;
   const char *name;
+  int err;
 };
 
-static my_bool table_exists_in_engine_handlerton(THD *thd, st_plugin_int *plugin,
+static my_bool table_exists_in_engine_handlerton(THD *thd, plugin_ref plugin,
                                    void *arg)
 {
   st_table_exists_in_engine_args *vargs= (st_table_exists_in_engine_args *)arg;
-  handlerton *hton= (handlerton *)plugin->data;
+  handlerton *hton= plugin_data(plugin, handlerton *);
+
+  int err= HA_ERR_NO_SUCH_TABLE;
 
   if (hton->state == SHOW_OPTION_YES && hton->table_exists_in_engine)
-    if ((hton->table_exists_in_engine(hton, thd, vargs->db, vargs->name)) == 1)
-      return TRUE;
+    err = hton->table_exists_in_engine(hton, thd, vargs->db, vargs->name);
+
+  vargs->err = err;
+  if (vargs->err == HA_ERR_TABLE_EXIST)
+    return TRUE;
 
   return FALSE;
 }
 
 int ha_table_exists_in_engine(THD* thd, const char* db, const char* name)
 {
-  int error= 0;
   DBUG_ENTER("ha_table_exists_in_engine");
   DBUG_PRINT("enter", ("db: %s, name: %s", db, name));
-  st_table_exists_in_engine_args args= {db, name};
-  error= plugin_foreach(thd, table_exists_in_engine_handlerton,
+  st_table_exists_in_engine_args args= {db, name, HA_ERR_NO_SUCH_TABLE};
+  plugin_foreach(thd, table_exists_in_engine_handlerton,
                  MYSQL_STORAGE_ENGINE_PLUGIN, &args);
-  DBUG_PRINT("exit", ("error: %d", error));
-  DBUG_RETURN(error);
+  DBUG_PRINT("exit", ("error: %d", args.err));
+  DBUG_RETURN(args.err);
 }
 
 #ifdef HAVE_NDB_BINLOG
@@ -2922,10 +2955,10 @@
 /** @brief
   Listing handlertons first to avoid recursive calls and deadlock
 */
-static my_bool binlog_func_list(THD *thd, st_plugin_int *plugin, void *arg)
+static my_bool binlog_func_list(THD *thd, plugin_ref plugin, void *arg)
 {
   hton_list_st *hton_list= (hton_list_st *)arg;
-  handlerton *hton= (handlerton *)plugin->data;
+  handlerton *hton= plugin_data(plugin, handlerton *);
   if (hton->state == SHOW_OPTION_YES && hton->binlog_func)
   {
     uint sz= hton_list->sz;
@@ -3012,10 +3045,10 @@
 }
 
 static my_bool binlog_log_query_handlerton(THD *thd,
-                                           st_plugin_int *plugin,
+                                           plugin_ref plugin,
                                            void *args)
 {
-  return binlog_log_query_handlerton2(thd, (handlerton *)plugin->data, args);
+  return binlog_log_query_handlerton2(thd, plugin_data(plugin, handlerton *), args);
 }
 
 void ha_binlog_log_query(THD *thd, handlerton *hton,
@@ -3307,11 +3340,11 @@
   RETURN VALUE
     pointer		pointer to TYPELIB structure
 */
-static my_bool exts_handlerton(THD *unused, st_plugin_int *plugin,
+static my_bool exts_handlerton(THD *unused, plugin_ref plugin,
                                void *arg)
 {
   List<char> *found_exts= (List<char> *) arg;
-  handlerton *hton= (handlerton *)plugin->data;
+  handlerton *hton= plugin_data(plugin, handlerton *);
   handler *file;
   if (hton->state == SHOW_OPTION_YES && hton->create &&
       (file= hton->create(hton, (TABLE_SHARE*) 0, current_thd->mem_root)))
@@ -3382,11 +3415,11 @@
 }
 
 
-static my_bool showstat_handlerton(THD *thd, st_plugin_int *plugin,
+static my_bool showstat_handlerton(THD *thd, plugin_ref plugin,
                                    void *arg)
 {
   enum ha_stat_type stat= *(enum ha_stat_type *) arg;
-  handlerton *hton= (handlerton *)plugin->data;
+  handlerton *hton= plugin_data(plugin, handlerton *);
   if (hton->state == SHOW_OPTION_YES && hton->show_status &&
       hton->show_status(hton, thd, stat_print, stat))
     return TRUE;

--- 1.79/sql/item_create.cc	2007-05-15 08:34:09 -07:00
+++ 1.80/sql/item_create.cc	2007-05-15 08:34:09 -07:00
@@ -1732,19 +1732,6 @@
 };
 
 
-class Create_func_reverse : public Create_func_arg1
-{
-public:
-  virtual Item* create(THD *thd, Item *arg1);
-
-  static Create_func_reverse s_singleton;
-
-protected:
-  Create_func_reverse() {}
-  virtual ~Create_func_reverse() {}
-};
-
-
 class Create_func_round : public Create_native_func
 {
 public:
@@ -4168,15 +4155,6 @@
 }
 
 
-Create_func_reverse Create_func_reverse::s_singleton;
-
-Item*
-Create_func_reverse::create(THD *thd, Item *arg1)
-{
-  return new (thd->mem_root) Item_func_reverse(arg1);
-}
-
-
 Create_func_round Create_func_round::s_singleton;
 
 Item*
@@ -4972,6 +4950,14 @@
 }
 
 
+Item*
+create_func_char_cast(THD *thd, Item *a, int len, CHARSET_INFO *cs)
+{
+    CHARSET_INFO *real_cs= (cs ? cs : thd->variables.collation_connection);
+    return new (thd->mem_root) Item_char_typecast(a, len, real_cs);
+}
+
+
 Item *
 create_func_cast(THD *thd, Item *a, Cast_target cast_type,
                  const char *c_len, const char *c_dec,
@@ -5016,9 +5002,7 @@
   }
   case ITEM_CAST_CHAR:
   {
-    CHARSET_INFO *real_cs= (cs ? cs : thd->variables.collation_connection);
-    len= c_len ? atoi(c_len) : -1;
-    res= new (thd->mem_root) Item_char_typecast(a, len, real_cs);
+    res= create_func_char_cast(thd, a, len, cs);
     break;
   }
   default:

--- 1.50/sql/item_create.h	2007-05-15 08:34:09 -07:00
+++ 1.51/sql/item_create.h	2007-05-15 08:34:09 -07:00
@@ -150,6 +150,9 @@
 #endif
 
 
+Item*
+create_func_char_cast(THD *thd, Item *a, int len, CHARSET_INFO *cs);
+
 /**
   Builder for cast expressions.
   @param thd The current thread

--- 1.271/sql/log.cc	2007-05-15 08:34:09 -07:00
+++ 1.272/sql/log.cc	2007-05-15 08:34:09 -07:00
@@ -1916,8 +1916,8 @@
 }
 
 MYSQL_LOG::MYSQL_LOG()
-  : name(0),  log_type(LOG_UNKNOWN), log_state(LOG_CLOSED), write_error(FALSE),
-    inited(FALSE)
+  : name(0), write_error(FALSE), inited(FALSE), log_type(LOG_UNKNOWN),
+    log_state(LOG_CLOSED)
 {
   /*
     We don't want to initialize LOCK_Log here as such initialization depends on

--- 1.600/sql/mysqld.cc	2007-05-15 08:34:09 -07:00
+++ 1.601/sql/mysqld.cc	2007-05-15 08:34:09 -07:00
@@ -30,27 +30,13 @@
 
 #include "rpl_injector.h"
 
-#ifdef WITH_FALCON_STORAGE_ENGINE
-#define OPT_FALCON_DEFAULT 1
-#else
-#define OPT_FALCON_DEFAULT 0
-#endif
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
-#define OPT_INNODB_DEFAULT 1
-#else
-#define OPT_INNODB_DEFAULT 0
-#endif
-#define OPT_BDB_DEFAULT 0
 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
-#define OPT_NDBCLUSTER_DEFAULT 0
 #if defined(NOT_ENOUGH_TESTED) \
   && defined(NDB_SHM_TRANSPORTER) && MYSQL_VERSION_ID >= 50000
 #define OPT_NDB_SHM_DEFAULT 1
 #else
 #define OPT_NDB_SHM_DEFAULT 0
 #endif
-#else
-#define OPT_NDBCLUSTER_DEFAULT 0
 #endif
 
 #ifndef DEFAULT_SKIP_THREAD_PRIORITY
@@ -327,7 +313,6 @@
 static bool volatile select_thread_in_use, signal_thread_in_use;
 static bool volatile ready_to_exit;
 static my_bool opt_debugging= 0, opt_external_locking= 0, opt_console= 0;
-static my_bool opt_ndbcluster;
 static my_bool opt_short_log_format= 0;
 static uint kill_cached_threads, wake_thread;
 static ulong killed_threads, thread_created;
@@ -371,8 +356,6 @@
 my_bool opt_safe_user_create = 0, opt_no_mix_types = 0;
 my_bool opt_show_slave_auth_info, opt_sql_bin_update = 0;
 my_bool opt_log_slave_updates= 0;
-my_bool	opt_innodb;
-my_bool opt_falcon;
 bool slave_warning_issued = false; 
 
 /*
@@ -382,45 +365,6 @@
 handlerton *myisam_hton;
 handlerton *partition_hton;
 
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
-extern ulong innobase_fast_shutdown;
-extern ulong innobase_large_page_size;
-extern char *innobase_home, *innobase_tmpdir, *innobase_logdir;
-extern long innobase_lock_scan_time;
-extern long innobase_mirrored_log_groups, innobase_log_files_in_group;
-extern longlong innobase_log_file_size;
-extern long innobase_log_buffer_size;
-extern longlong innobase_buffer_pool_size;
-extern long innobase_additional_mem_pool_size;
-extern long innobase_file_io_threads, innobase_lock_wait_timeout;
-extern long innobase_force_recovery;
-extern long innobase_open_files;
-extern char *innobase_data_home_dir, *innobase_data_file_path;
-extern char *innobase_log_group_home_dir, *innobase_log_arch_dir;
-extern char *innobase_unix_file_flush_method;
-/* The following variables have to be my_bool for SHOW VARIABLES to work */
-extern my_bool innobase_log_archive,
-               innobase_use_doublewrite,
-               innobase_use_checksums,
-               innobase_use_large_pages,
-               innobase_use_native_aio,
-               innobase_file_per_table, innobase_locks_unsafe_for_binlog,
-               innobase_rollback_on_timeout,
-               innobase_stats_on_metadata,
-               innobase_create_status_file;
-extern "C" {
-extern ulong srv_max_buf_pool_modified_pct;
-extern ulong srv_max_purge_lag;
-extern ulong srv_auto_extend_increment;
-extern ulong srv_n_spin_wait_rounds;
-extern ulong srv_n_free_tickets_to_enter;
-extern ulong srv_thread_sleep_delay;
-extern ulong srv_thread_concurrency;
-extern ulong srv_commit_concurrency;
-extern ulong srv_flush_log_at_trx_commit;
-}
-#endif
-
 #ifdef WITH_FALCON_STORAGE_ENGINE
 extern ulonglong	falcon_min_record_memory;
 extern ulonglong	falcon_max_record_memory;
@@ -434,7 +378,7 @@
 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
 const char *opt_ndbcluster_connectstring= 0;
 const char *opt_ndb_connectstring= 0;
-char opt_ndb_constrbuf[1024];
+char opt_ndb_constrbuf[1024]= {0};
 unsigned opt_ndb_constrbuf_len= 0;
 my_bool	opt_ndb_shm, opt_ndb_optimized_node_selection;
 ulong opt_ndb_cache_check_time;
@@ -471,7 +415,7 @@
 my_bool sp_automatic_privileges= 1;
 
 ulong opt_binlog_rows_event_max_size;
-const char *binlog_format_names[]= {"STATEMENT", "ROW", "MIXED", NullS};
+const char *binlog_format_names[]= {"MIXED", "STATEMENT", "ROW", NullS};
 TYPELIB binlog_format_typelib=
   { array_elements(binlog_format_names) - 1, "",
     binlog_format_names, NULL };
@@ -616,6 +560,7 @@
 pthread_mutex_t LOCK_des_key_file;
 #endif
 rw_lock_t	LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave;
+rw_lock_t	LOCK_system_variables_hash;
 pthread_cond_t COND_refresh, COND_thread_count, COND_global_read_lock;
 pthread_t signal_thread;
 pthread_attr_t connection_attrib;
@@ -647,6 +592,7 @@
 static char *opt_update_logname, *opt_binlog_index_name;
 static char *opt_tc_heuristic_recover;
 static char *mysql_home_ptr, *pidfile_name_ptr;
+static int defaults_argc;
 static char **defaults_argv;
 static char *opt_bin_logname;
 
@@ -739,7 +685,8 @@
 
 pthread_handler_t signal_hand(void *arg);
 static void mysql_init_variables(void);
-static void get_options(int argc,char **argv);
+static void get_options(int *argc,char **argv);
+static my_bool get_one_option(int, const struct my_option *, char *);
 static void set_server_version(void);
 static int init_thread_environment();
 static char *get_relative_path(const char *path);
@@ -762,6 +709,7 @@
 static int test_if_case_insensitive(const char *dir_name);
 
 #ifndef EMBEDDED_LIBRARY
+static void usage(void);
 static void start_signal_handler(void);
 static void close_server_sock();
 static void clean_up_mutexes(void);
@@ -1187,6 +1135,8 @@
   DBUG_ENTER("unireg_abort");
   if (exit_code)
     sql_print_error("Aborting\n");
+  else if (opt_help)
+    usage();
   clean_up(exit_code || !opt_bootstrap); /* purecov: inspected */
   DBUG_PRINT("quit",("done with cleanup in unireg_abort"));
   wait_for_signal_thread_to_end();
@@ -1372,6 +1322,7 @@
   (void) rwlock_destroy(&LOCK_sys_init_connect);
   (void) rwlock_destroy(&LOCK_sys_init_slave);
   (void) pthread_mutex_destroy(&LOCK_global_system_variables);
+  (void) rwlock_destroy(&LOCK_system_variables_hash);
   (void) pthread_mutex_destroy(&LOCK_global_read_lock);
   (void) pthread_mutex_destroy(&LOCK_uuid_generator);
   (void) pthread_mutex_destroy(&LOCK_prepared_stmt_count);
@@ -1390,6 +1341,7 @@
 ** Init IP and UNIX socket
 ****************************************************************************/
 
+#ifndef EMBEDDED_LIBRARY
 static void set_ports()
 {
   char	*env;
@@ -1414,7 +1366,6 @@
   }
 }
 
-#ifndef EMBEDDED_LIBRARY
 /* Change to run as another user if started with --user */
 
 static struct passwd *check_user(const char *user)
@@ -2372,7 +2323,7 @@
   sigaddset(&set,SIGTSTP);
 #endif
   if (thd_lib_detected != THD_LIB_LT)
-    sigaddset(&set,THR_SERVER_ALARM);
+  sigaddset(&set,THR_SERVER_ALARM);
   if (test_flags & TEST_SIGINT)
   {
     // May be SIGINT
@@ -2673,16 +2624,18 @@
 }
 #endif
 
+#if !defined(EMBEDDED_LIBRARY)
 static const char *load_default_groups[]= {
 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
 "mysql_cluster",
 #endif
 "mysqld","server", MYSQL_BASE_VERSION, 0, 0};
 
-#if defined(__WIN__) && !defined(EMBEDDED_LIBRARY)
+#if defined(__WIN__)
 static const int load_default_groups_sz=
 sizeof(load_default_groups)/sizeof(load_default_groups[0]);
 #endif
+#endif /*!EMBEDDED_LIBRARY*/
 
 
 /*
@@ -2730,7 +2683,7 @@
 static int init_common_variables(const char *conf_file_name, int argc,
 				 char **argv, const char **groups)
 {
-  char buff[FN_REFLEN];
+  char buff[FN_REFLEN], *s;
   umask(((~my_umask) & 0666));
   my_decimal_set_zero(&decimal_zero); // set decimal_zero constant;
   tzset();			// Set tzname
@@ -2782,7 +2735,7 @@
     strmake(pidfile_name, STRING_WITH_LEN("mysql"));
   }
   else
-    strmake(pidfile_name, glob_hostname, sizeof(pidfile_name)-5);
+  strmake(pidfile_name, glob_hostname, sizeof(pidfile_name)-5);
   strmov(fn_ext(pidfile_name),".pid");		// Add proper extension
 
   /*
@@ -2796,7 +2749,8 @@
 
   load_defaults(conf_file_name, groups, &argc, &argv);
   defaults_argv=argv;
-  get_options(argc,argv);
+  defaults_argc=argc;
+  get_options(&defaults_argc, defaults_argv);
   set_server_version();
 
   DBUG_PRINT("info",("%s  Ver %s for %s on %s\n",my_progname,
@@ -2808,10 +2762,6 @@
   {
       my_use_large_pages= 1;
       my_large_page_size= opt_large_page_size;
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
-      innobase_use_large_pages= 1;
-      innobase_large_page_size= opt_large_page_size;
-#endif
   }
 #endif /* HAVE_LARGE_PAGES */
 
@@ -2874,7 +2824,12 @@
   if (item_create_init())
     return 1;
   item_init();
-  set_var_init();
+  if (set_var_init())
+    return 1;
+#ifdef HAVE_REPLICATION
+  if (init_replication_sys_vars())
+    return 1;
+#endif
   mysys_uses_curses=0;
 #ifdef USE_REGEX
   my_regex_init(&my_charset_latin1);
@@ -2971,15 +2926,13 @@
                       "--log-slow-queries option, log tables are used. "
                       "To enable logging to files use the --log-output option.");
 
-  if (!opt_logname)
-    opt_logname= make_default_log_name(buff, ".log");
-  sys_var_general_log_path.value= my_strdup(opt_logname, MYF(0));
-  sys_var_general_log_path.value_length= strlen(opt_logname);
-
-  if (!opt_slow_logname)
-    opt_slow_logname= make_default_log_name(buff, "-slow.log");
-  sys_var_slow_log_path.value= my_strdup(opt_slow_logname, MYF(0));
-  sys_var_slow_log_path.value_length= strlen(opt_slow_logname);
+  s= opt_logname ? opt_logname : make_default_log_name(buff, ".log");
+  sys_var_general_log_path.value= my_strdup(s, MYF(0));
+  sys_var_general_log_path.value_length= strlen(s);
+
+  s= opt_slow_logname ? opt_slow_logname : make_default_log_name(buff, "-slow.log");
+  sys_var_slow_log_path.value= my_strdup(s, MYF(0));
+  sys_var_slow_log_path.value_length= strlen(s);
 
   if (use_temp_pool && bitmap_init(&temp_pool,0,1024,1))
     return 1;
@@ -3058,6 +3011,7 @@
   (void) pthread_mutex_init(&LOCK_user_conn, MY_MUTEX_INIT_FAST);
   (void) pthread_mutex_init(&LOCK_active_mi, MY_MUTEX_INIT_FAST);
   (void) pthread_mutex_init(&LOCK_global_system_variables, MY_MUTEX_INIT_FAST);
+  (void) my_rwlock_init(&LOCK_system_variables_hash, NULL);
   (void) pthread_mutex_init(&LOCK_global_read_lock, MY_MUTEX_INIT_FAST);
   (void) pthread_mutex_init(&LOCK_prepared_stmt_count, MY_MUTEX_INIT_FAST);
   (void) pthread_mutex_init(&LOCK_uuid_generator, MY_MUTEX_INIT_FAST);
@@ -3245,8 +3199,12 @@
 
   /* Setup logs */
 
-  /* enable old-fashioned error log */
-  if (opt_error_log)
+  /*
+    Enable old-fashioned error log, except when the user has requested
+    help information. Since the implementation of plugin server
+    variables the help output is now written much later.
+  */
+  if (opt_error_log && !opt_help)
   {
     if (!log_error_file_ptr[0])
       fn_format(log_error_file, pidfile_name, mysql_data_home, ".err",
@@ -3332,13 +3290,13 @@
   }
   if (!opt_bin_log)
     if (opt_binlog_format_id != BINLOG_FORMAT_UNSPEC)
-    {
-      sql_print_error("You need to use --log-bin to make "
-		      "--binlog-format work.");
-      unireg_abort(1);
-    }
+  {
+    sql_print_error("You need to use --log-bin to make "
+                    "--binlog-format work.");
+    unireg_abort(1);
+  }
     else
-    {
+  {
       global_system_variables.binlog_format= BINLOG_FORMAT_UNSPEC;
     }
   else
@@ -3347,7 +3305,7 @@
     else
     { 
       DBUG_ASSERT(global_system_variables.binlog_format != BINLOG_FORMAT_UNSPEC);
-    }
+  }
 
   /* Check that we have not let the format to unspecified at this point */
   DBUG_ASSERT((uint)global_system_variables.binlog_format <=
@@ -3401,12 +3359,51 @@
     using_update_log=1;
   }
 
-  if (plugin_init(opt_bootstrap))
+  if (plugin_init(&defaults_argc, defaults_argv,
+                  (opt_noacl ? PLUGIN_INIT_SKIP_PLUGIN_TABLE : 0) |
+                  (opt_help ? PLUGIN_INIT_SKIP_INITIALIZATION : 0)))
   {
-    sql_print_error("Failed to init plugins.");
-    return 1;
+    sql_print_error("Failed to initialize plugins.");
+    unireg_abort(1);
   }
 
+  if (opt_help)
+    unireg_abort(0);
+
+  /* we do want to exit if there are any other unknown options */
+  if (defaults_argc > 1)
+  {
+    int ho_error;
+    char **tmp_argv= defaults_argv;
+    struct my_option no_opts[]=
+    {
+      {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
+    };
+    /*
+      We need to eat any 'loose' arguments first before we conclude
+      that there are unprocessed options.
+      But we need to preserve defaults_argv pointer intact for
+      free_defaults() to work. Thus we use a copy here.
+    */
+    my_getopt_skip_unknown= 0;
+
+    if ((ho_error= handle_options(&defaults_argc, &tmp_argv, no_opts,
+                                  get_one_option)))
+      unireg_abort(ho_error);
+
+    if (defaults_argc)
+    {
+      fprintf(stderr, "%s: Too many arguments (first extra is '%s').\n"
+              "Use --verbose --help to get a list of available options\n",
+              my_progname, *tmp_argv);
+      unireg_abort(1);
+    }
+  }
+
+  /* if the errmsg.sys is not loaded, terminate to maintain behaviour */
+  if (!errmesg[0][0])
+    unireg_abort(1);
+
   /* We have to initialize the storage engines before CSV logging */
   if (ha_init())
   {
@@ -3435,7 +3432,8 @@
   else
   {
     /* fall back to the log files if tables are not present */
-    if (have_csv_db == SHOW_OPTION_NO)
+    LEX_STRING csv_name={C_STRING_WITH_LEN("csv")};
+    if (!plugin_is_ready(&csv_name, MYSQL_STORAGE_ENGINE_PLUGIN))
     {
       /* purecov: begin inspected */
       sql_print_error("CSV engine is not present, falling back to the "
@@ -3455,11 +3453,16 @@
   /*
     Check that the default storage engine is actually available.
   */
+  if (default_storage_engine_str)
   {
     LEX_STRING name= { default_storage_engine_str,
                        strlen(default_storage_engine_str) };
-    handlerton *hton= ha_resolve_by_name(0, &name);
-    if (hton == NULL)
+    plugin_ref plugin;
+    handlerton *hton;
+    
+    if ((plugin= ha_resolve_by_name(0, &name)))
+      hton= plugin_data(plugin, handlerton*);
+    else
     {
       sql_print_error("Unknown/unsupported table type: %s",
                       default_storage_engine_str);
@@ -3473,9 +3476,17 @@
                         default_storage_engine_str);
         unireg_abort(1);
       }
-      hton= myisam_hton;
+      DBUG_ASSERT(global_system_variables.table_plugin);
+    }
+    else
+    {
+      /*
+        Need to unlock as global_system_variables.table_plugin 
+        was acquired during plugin_init()
+      */
+      plugin_unlock(0, global_system_variables.table_plugin);
+      global_system_variables.table_plugin= plugin;
     }
-    global_system_variables.table_type= hton;
   }
 
   tc_log= (total_ha_2pc > 1 ? (opt_bin_log  ?
@@ -3752,7 +3763,7 @@
     We have enough space for fiddling with the argv, continue
   */
   check_data_home(mysql_real_data_home);
-  if (my_setwd(mysql_real_data_home,MYF(MY_WME)))
+  if (my_setwd(mysql_real_data_home,MYF(MY_WME)) && !opt_help)
     unireg_abort(1);				/* purecov: inspected */
   mysql_data_home= mysql_data_home_buff;
   mysql_data_home[0]=FN_CURLIB;		// all paths are relative from here
@@ -4886,11 +4897,6 @@
   OPT_STORAGE_ENGINE,          OPT_INIT_FILE,
   OPT_DELAY_KEY_WRITE_ALL,     OPT_SLOW_QUERY_LOG,
   OPT_DELAY_KEY_WRITE,	       OPT_CHARSETS_DIR,
-  OPT_BDB_HOME,                OPT_BDB_LOG,
-  OPT_BDB_TMP,                 OPT_BDB_SYNC,
-  OPT_BDB_LOCK,                OPT_BDB,
-  OPT_BDB_NO_RECOVER,          OPT_BDB_SHARED,
-  OPT_BDB_DATA_DIRECT,         OPT_BDB_LOG_DIRECT,
   OPT_MASTER_HOST,             OPT_MASTER_USER,
   OPT_MASTER_PASSWORD,         OPT_MASTER_PORT,
   OPT_MASTER_INFO_FILE,        OPT_MASTER_CONNECT_RETRY,
@@ -4909,28 +4915,14 @@
   OPT_WANT_CORE,               OPT_CONCURRENT_INSERT,
   OPT_MEMLOCK,                 OPT_MYISAM_RECOVER,
   OPT_REPLICATE_REWRITE_DB,    OPT_SERVER_ID,
-  OPT_SKIP_SLAVE_START,        OPT_SKIP_INNOBASE,
+  OPT_SKIP_SLAVE_START,        OPT_SAFE_SHOW_DB, 
   OPT_SAFEMALLOC_MEM_LIMIT,    OPT_REPLICATE_DO_TABLE,
   OPT_REPLICATE_IGNORE_TABLE,  OPT_REPLICATE_WILD_DO_TABLE,
   OPT_REPLICATE_WILD_IGNORE_TABLE, OPT_REPLICATE_SAME_SERVER_ID,
   OPT_DISCONNECT_SLAVE_EVENT_COUNT, OPT_TC_HEURISTIC_RECOVER,
   OPT_ABORT_SLAVE_EVENT_COUNT,
-  OPT_INNODB_DATA_HOME_DIR,
-  OPT_INNODB_DATA_FILE_PATH,
-  OPT_INNODB_LOG_GROUP_HOME_DIR,
-  OPT_INNODB_LOG_ARCH_DIR,
-  OPT_INNODB_LOG_ARCHIVE,
-  OPT_INNODB_FLUSH_LOG_AT_TRX_COMMIT,
-  OPT_INNODB_FLUSH_METHOD,
-  OPT_INNODB_DOUBLEWRITE,
-  OPT_INNODB_CHECKSUMS,
-  OPT_INNODB_FAST_SHUTDOWN,
-  OPT_INNODB_FILE_PER_TABLE, OPT_CRASH_BINLOG_INNODB,
-  OPT_INNODB_LOCKS_UNSAFE_FOR_BINLOG,
   OPT_LOG_BIN_TRUST_FUNCTION_CREATORS,
-  OPT_SAFE_SHOW_DB, OPT_INNODB_SAFE_BINLOG,
-  OPT_INNODB, OPT_ISAM,
-  OPT_ENGINE_CONDITION_PUSHDOWN, OPT_NDBCLUSTER, OPT_NDB_CONNECTSTRING, 
+  OPT_ENGINE_CONDITION_PUSHDOWN, OPT_NDB_CONNECTSTRING, 
   OPT_NDB_USE_EXACT_COUNT, OPT_NDB_USE_TRANSACTIONS,
   OPT_NDB_FORCE_SEND, OPT_NDB_AUTOINCREMENT_PREFETCH_SZ,
   OPT_NDB_SHM, OPT_NDB_OPTIMIZED_NODE_SELECTION, OPT_NDB_CACHE_CHECK_TIME,
@@ -4993,30 +4985,6 @@
   OPT_THREAD_CONCURRENCY, OPT_THREAD_CACHE_SIZE,
   OPT_TMP_TABLE_SIZE, OPT_THREAD_STACK,
   OPT_WAIT_TIMEOUT, OPT_MYISAM_REPAIR_THREADS,
-  OPT_INNODB_MIRRORED_LOG_GROUPS,
-  OPT_INNODB_LOG_FILES_IN_GROUP,
-  OPT_INNODB_LOG_FILE_SIZE,
-  OPT_INNODB_LOG_BUFFER_SIZE,
-  OPT_INNODB_BUFFER_POOL_SIZE,
-  OPT_INNODB_BUFFER_POOL_AWE_MEM_MB,
-  OPT_INNODB_ADDITIONAL_MEM_POOL_SIZE,
-  OPT_INNODB_MAX_PURGE_LAG,
-  OPT_INNODB_FILE_IO_THREADS,
-  OPT_INNODB_LOCK_WAIT_TIMEOUT,
-  OPT_INNODB_THREAD_CONCURRENCY,
-  OPT_INNODB_COMMIT_CONCURRENCY,
-  OPT_INNODB_FORCE_RECOVERY,
-  OPT_INNODB_STATUS_FILE,
-  OPT_INNODB_MAX_DIRTY_PAGES_PCT,
-  OPT_INNODB_TABLE_LOCKS,
-  OPT_INNODB_SUPPORT_XA,
-  OPT_INNODB_OPEN_FILES,
-  OPT_INNODB_AUTOEXTEND_INCREMENT,
-  OPT_INNODB_SYNC_SPIN_LOOPS,
-  OPT_INNODB_CONCURRENCY_TICKETS,
-  OPT_INNODB_THREAD_SLEEP_DELAY,
-  OPT_INNODB_STATS_ON_METADATA,
-
   OPT_FALCON,
   OPT_FALCON_MAX_RECORD_MEMORY,
   OPT_FALCON_MIN_RECORD_MEMORY,
@@ -5025,11 +4993,6 @@
   OPT_FALCON_DEBUG_SERVER,
   OPT_FALCON_LOG_DIR,
   OPT_FALCON_LOG_MASK,
-  OPT_BDB_CACHE_SIZE,
-  OPT_BDB_CACHE_PARTS,
-  OPT_BDB_LOG_BUFFER_SIZE,
-  OPT_BDB_MAX_LOCK,
-  OPT_BDB_REGION_SIZE,
   OPT_ERROR_LOG_FILE,
   OPT_DEFAULT_WEEK_FORMAT,
   OPT_RANGE_ALLOC_BLOCK_SIZE, OPT_ALLOW_SUSPICIOUS_UDFS,
@@ -5039,7 +5002,6 @@
   OPT_SYNC_REPLICATION,
   OPT_SYNC_REPLICATION_SLAVE_ID,
   OPT_SYNC_REPLICATION_TIMEOUT,
-  OPT_BDB_NOSYNC,
   OPT_ENABLE_SHARED_MEMORY,
   OPT_SHARED_MEMORY_BASE_NAME,
   OPT_OLD_PASSWORDS,
@@ -5070,12 +5032,12 @@
   OPT_OLD_STYLE_USER_LIMITS,
   OPT_LOG_SLOW_ADMIN_STATEMENTS,
   OPT_TABLE_LOCK_WAIT_TIMEOUT,
+  OPT_PLUGIN_LOAD,
   OPT_PLUGIN_DIR,
   OPT_LOG_OUTPUT,
   OPT_PORT_OPEN_TIMEOUT,
   OPT_GENERAL_LOG,
   OPT_SLOW_LOG,
-  OPT_MERGE,
   OPT_THREAD_HANDLING,
   OPT_INNODB_ROLLBACK_ON_TIMEOUT,
   OPT_SECURE_FILE_PRIV,
@@ -5142,8 +5104,7 @@
    " to 'row' and back implicitly per each query accessing a NDB table."
 #endif
    ,(gptr*) &opt_binlog_format, (gptr*) &opt_binlog_format,
-   0, GET_STR, REQUIRED_ARG, BINLOG_FORMAT_MIXED, BINLOG_FORMAT_STMT,
-   BINLOG_FORMAT_MIXED, 0, 0, 0},
+   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"binlog-do-db", OPT_BINLOG_DO_DB,
    "Tells the master it should log updates for the specified database, and exclude all others not explicitly mentioned.",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -5332,98 +5293,6 @@
   {"init-slave", OPT_INIT_SLAVE, "Command(s) that are executed when a slave connects to this master",
    (gptr*) &opt_init_slave, (gptr*) &opt_init_slave, 0, GET_STR_ALLOC,
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"innodb", OPT_INNODB, "Enable InnoDB (if this version of MySQL supports it). \
-Disable with --skip-innodb (will save memory).",
-   (gptr*) &opt_innodb, (gptr*) &opt_innodb, 0, GET_BOOL, NO_ARG, OPT_INNODB_DEFAULT, 0, 0,
-   0, 0, 0},
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
-  {"innodb_checksums", OPT_INNODB_CHECKSUMS, "Enable InnoDB checksums validation (enabled by default). \
-Disable with --skip-innodb-checksums.", (gptr*) &innobase_use_checksums,
-   (gptr*) &innobase_use_checksums, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
-#endif
-  {"innodb_data_file_path", OPT_INNODB_DATA_FILE_PATH,
-   "Path to individual files and their sizes.",
-   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
-  {"innodb_data_home_dir", OPT_INNODB_DATA_HOME_DIR,
-   "The common part for InnoDB table spaces.", (gptr*) &innobase_data_home_dir,
-   (gptr*) &innobase_data_home_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0,
-   0},
-  {"innodb_doublewrite", OPT_INNODB_DOUBLEWRITE, "Enable InnoDB doublewrite buffer (enabled by default). \
-Disable with --skip-innodb-doublewrite.", (gptr*) &innobase_use_doublewrite,
-   (gptr*) &innobase_use_doublewrite, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
-  {"innodb_fast_shutdown", OPT_INNODB_FAST_SHUTDOWN,
-   "Speeds up the shutdown process of the InnoDB storage engine. Possible "
-   "values are 0, 1 (faster)"
-   /*
-     NetWare can't close unclosed files, can't automatically kill remaining
-     threads, etc, so on this OS we disable the crash-like InnoDB shutdown.
-   */
-#ifndef __NETWARE__
-   " or 2 (fastest - crash-like)"
-#endif
-   ".",
-   (gptr*) &innobase_fast_shutdown,
-   (gptr*) &innobase_fast_shutdown, 0, GET_ULONG, OPT_ARG, 1, 0,
-   IF_NETWARE(1,2), 0, 0, 0},
-  {"innodb_file_per_table", OPT_INNODB_FILE_PER_TABLE,
-   "Stores each InnoDB table to an .ibd file in the database dir.",
-   (gptr*) &innobase_file_per_table,
-   (gptr*) &innobase_file_per_table, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"innodb_flush_log_at_trx_commit", OPT_INNODB_FLUSH_LOG_AT_TRX_COMMIT,
-   "Set to 0 (write and flush once per second), 1 (write and flush at each commit) or 2 (write at commit, flush once per second).",
-   (gptr*) &srv_flush_log_at_trx_commit,
-   (gptr*) &srv_flush_log_at_trx_commit,
-   0, GET_ULONG, OPT_ARG,  1, 0, 2, 0, 0, 0},
-  {"innodb_flush_method", OPT_INNODB_FLUSH_METHOD,
-   "With which method to flush data.", (gptr*) &innobase_unix_file_flush_method,
-   (gptr*) &innobase_unix_file_flush_method, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
-   0, 0, 0},
-  {"innodb_locks_unsafe_for_binlog", OPT_INNODB_LOCKS_UNSAFE_FOR_BINLOG,
-   "Force InnoDB to not use next-key locking, to use only row-level locking.",
-   (gptr*) &innobase_locks_unsafe_for_binlog,
-   (gptr*) &innobase_locks_unsafe_for_binlog, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"innodb_log_arch_dir", OPT_INNODB_LOG_ARCH_DIR,
-   "Where full logs should be archived.", (gptr*) &innobase_log_arch_dir,
-   (gptr*) &innobase_log_arch_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"innodb_log_archive", OPT_INNODB_LOG_ARCHIVE,
-   "Set to 1 if you want to have logs archived.", 0, 0, 0, GET_LONG, OPT_ARG,
-   0, 0, 0, 0, 0, 0},
-  {"innodb_log_group_home_dir", OPT_INNODB_LOG_GROUP_HOME_DIR,
-   "Path to InnoDB log files.", (gptr*) &innobase_log_group_home_dir,
-   (gptr*) &innobase_log_group_home_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0,
-   0, 0},
-  {"innodb_max_dirty_pages_pct", OPT_INNODB_MAX_DIRTY_PAGES_PCT,
-   "Percentage of dirty pages allowed in bufferpool.", (gptr*) &srv_max_buf_pool_modified_pct,
-   (gptr*) &srv_max_buf_pool_modified_pct, 0, GET_ULONG, REQUIRED_ARG, 90, 0, 100, 0, 0, 0},
-  {"innodb_max_purge_lag", OPT_INNODB_MAX_PURGE_LAG,
-   "Desired maximum length of the purge queue (0 = no limit)",
-   (gptr*) &srv_max_purge_lag,
-   (gptr*) &srv_max_purge_lag, 0, GET_LONG, REQUIRED_ARG, 0, 0, ~0L,
-   0, 1L, 0},
-  {"innodb_rollback_on_timeout", OPT_INNODB_ROLLBACK_ON_TIMEOUT,
-   "Roll back the complete transaction on lock wait timeout, for 4.x compatibility (disabled by default)",
-   (gptr*) &innobase_rollback_on_timeout, (gptr*) &innobase_rollback_on_timeout,
-   0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
-  {"innodb_status_file", OPT_INNODB_STATUS_FILE,
-   "Enable SHOW INNODB STATUS output in the innodb_status.<pid> file",
-   (gptr*) &innobase_create_status_file, (gptr*) &innobase_create_status_file,
-   0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
-  {"innodb_stats_on_metadata", OPT_INNODB_STATS_ON_METADATA,
-   "Enable statistics gathering for metadata commands such as SHOW TABLE STATUS (on by default)",
-   (gptr*) &innobase_stats_on_metadata, (gptr*) &innobase_stats_on_metadata,
-   0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
-  {"innodb_support_xa", OPT_INNODB_SUPPORT_XA,
-   "Enable InnoDB support for the XA two-phase commit",
-   (gptr*) &global_system_variables.innodb_support_xa,
-   (gptr*) &global_system_variables.innodb_support_xa,
-   0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0},
-  {"innodb_table_locks", OPT_INNODB_TABLE_LOCKS,
-   "Enable InnoDB locking in LOCK TABLES",
-   (gptr*) &global_system_variables.innodb_table_locks,
-   (gptr*) &global_system_variables.innodb_table_locks,
-   0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0},
-#endif /* End WITH_INNOBASE_STORAGE_ENGINE */
    {"language", 'L',
    "Client error messages in given language. May be given as a full path.",
    (gptr*) &language_ptr, (gptr*) &language_ptr, 0, GET_STR, REQUIRED_ARG,
@@ -5602,10 +5471,6 @@
    "Syntax: myisam-recover[=option[,option...]], where option can be DEFAULT, BACKUP, FORCE or QUICK.",
    (gptr*) &myisam_recover_options_str, (gptr*) &myisam_recover_options_str, 0,
    GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
-  {"ndbcluster", OPT_NDBCLUSTER, "Enable NDB Cluster (if this version of MySQL supports it). \
-Disable with --skip-ndbcluster (will save memory).",
-   (gptr*) &opt_ndbcluster, (gptr*) &opt_ndbcluster, 0, GET_BOOL, NO_ARG,
-   OPT_NDBCLUSTER_DEFAULT, 0, 0, 0, 0, 0},
 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
   {"ndb-connectstring", OPT_NDB_CONNECTSTRING,
    "Connect string for ndbcluster.",
@@ -6065,84 +5930,6 @@
     (gptr*) &global_system_variables.group_concat_max_len,
     (gptr*) &max_system_variables.group_concat_max_len, 0, GET_ULONG,
     REQUIRED_ARG, 1024, 4, (long) ~0, 0, 1, 0},
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
-  {"innodb_additional_mem_pool_size", OPT_INNODB_ADDITIONAL_MEM_POOL_SIZE,
-   "Size of a memory pool InnoDB uses to store data dictionary information and other internal data structures.",
-   (gptr*) &innobase_additional_mem_pool_size,
-   (gptr*) &innobase_additional_mem_pool_size, 0, GET_LONG, REQUIRED_ARG,
-   1*1024*1024L, 512*1024L, ~0L, 0, 1024, 0},
-  {"innodb_autoextend_increment", OPT_INNODB_AUTOEXTEND_INCREMENT,
-   "Data file autoextend increment in megabytes",
-   (gptr*) &srv_auto_extend_increment,
-   (gptr*) &srv_auto_extend_increment,
-   0, GET_LONG, REQUIRED_ARG, 8L, 1L, 1000L, 0, 1L, 0},
-  {"innodb_buffer_pool_size", OPT_INNODB_BUFFER_POOL_SIZE,
-   "The size of the memory buffer InnoDB uses to cache data and indexes of its tables.",
-   (gptr*) &innobase_buffer_pool_size, (gptr*) &innobase_buffer_pool_size, 0,
-   GET_LL, REQUIRED_ARG, 8*1024*1024L, 1024*1024L, LONGLONG_MAX, 0,
-   1024*1024L, 0},
-  {"innodb_commit_concurrency", OPT_INNODB_COMMIT_CONCURRENCY,
-   "Helps in performance tuning in heavily concurrent environments.",
-   (gptr*) &srv_commit_concurrency, (gptr*) &srv_commit_concurrency,
-   0, GET_LONG, REQUIRED_ARG, 0, 0, 1000, 0, 1, 0},
-  {"innodb_concurrency_tickets", OPT_INNODB_CONCURRENCY_TICKETS,
-   "Number of times a thread is allowed to enter InnoDB within the same \
-    SQL query after it has once got the ticket",
-   (gptr*) &srv_n_free_tickets_to_enter,
-   (gptr*) &srv_n_free_tickets_to_enter,
-   0, GET_LONG, REQUIRED_ARG, 500L, 1L, ~0L, 0, 1L, 0},
-  {"innodb_file_io_threads", OPT_INNODB_FILE_IO_THREADS,
-   "Number of file I/O threads in InnoDB.", (gptr*) &innobase_file_io_threads,
-   (gptr*) &innobase_file_io_threads, 0, GET_LONG, REQUIRED_ARG, 4, 4, 64, 0,
-   1, 0},
-  {"innodb_force_recovery", OPT_INNODB_FORCE_RECOVERY,
-   "Helps to save your data in case the disk image of the database becomes corrupt.",
-   (gptr*) &innobase_force_recovery, (gptr*) &innobase_force_recovery, 0,
-   GET_LONG, REQUIRED_ARG, 0, 0, 6, 0, 1, 0},
-  {"innodb_lock_wait_timeout", OPT_INNODB_LOCK_WAIT_TIMEOUT,
-   "Timeout in seconds an InnoDB transaction may wait for a lock before being rolled back.",
-   (gptr*) &innobase_lock_wait_timeout, (gptr*) &innobase_lock_wait_timeout,
-   0, GET_LONG, REQUIRED_ARG, 50, 1, 1024 * 1024 * 1024, 0, 1, 0},
-  {"innodb_log_buffer_size", OPT_INNODB_LOG_BUFFER_SIZE,
-   "The size of the buffer which InnoDB uses to write log to the log files on disk.",
-   (gptr*) &innobase_log_buffer_size, (gptr*) &innobase_log_buffer_size, 0,
-   GET_LONG, REQUIRED_ARG, 1024*1024L, 256*1024L, ~0L, 0, 1024, 0},
-  {"innodb_log_file_size", OPT_INNODB_LOG_FILE_SIZE,
-   "Size of each log file in a log group.",
-   (gptr*) &innobase_log_file_size, (gptr*) &innobase_log_file_size, 0,
-   GET_LL, REQUIRED_ARG, 5*1024*1024L, 1*1024*1024L, LONGLONG_MAX, 0,
-   1024*1024L, 0},
-  {"innodb_log_files_in_group", OPT_INNODB_LOG_FILES_IN_GROUP,
-   "Number of log files in the log group. InnoDB writes to the files in a circular fashion. Value 3 is recommended here.",
-   (gptr*) &innobase_log_files_in_group, (gptr*) &innobase_log_files_in_group,
-   0, GET_LONG, REQUIRED_ARG, 2, 2, 100, 0, 1, 0},
-  {"innodb_mirrored_log_groups", OPT_INNODB_MIRRORED_LOG_GROUPS,
-   "Number of identical copies of log groups we keep for the database. Currently this should be set to 1.",
-   (gptr*) &innobase_mirrored_log_groups,
-   (gptr*) &innobase_mirrored_log_groups, 0, GET_LONG, REQUIRED_ARG, 1, 1, 10,
-   0, 1, 0},
-  {"innodb_open_files", OPT_INNODB_OPEN_FILES,
-   "How many files at the maximum InnoDB keeps open at the same time.",
-   (gptr*) &innobase_open_files, (gptr*) &innobase_open_files, 0,
-   GET_LONG, REQUIRED_ARG, 300L, 10L, ~0L, 0, 1L, 0},
-  {"innodb_sync_spin_loops", OPT_INNODB_SYNC_SPIN_LOOPS,
-   "Count of spin-loop rounds in InnoDB mutexes",
-   (gptr*) &srv_n_spin_wait_rounds,
-   (gptr*) &srv_n_spin_wait_rounds,
-   0, GET_LONG, REQUIRED_ARG, 20L, 0L, ~0L, 0, 1L, 0},
-  {"innodb_thread_concurrency", OPT_INNODB_THREAD_CONCURRENCY,
-   "Helps in performance tuning in heavily concurrent environments. "
-   "Sets the maximum number of threads allowed inside InnoDB. Value 0"
-   " will disable the thread throttling.",
-   (gptr*) &srv_thread_concurrency, (gptr*) &srv_thread_concurrency,
-   0, GET_LONG, REQUIRED_ARG, 8, 0, 1000, 0, 1, 0},
-  {"innodb_thread_sleep_delay", OPT_INNODB_THREAD_SLEEP_DELAY,
-   "Time of innodb thread sleeping before joining InnoDB queue (usec). Value 0"
-    " disable a sleep",
-   (gptr*) &srv_thread_sleep_delay,
-   (gptr*) &srv_thread_sleep_delay,
-   0, GET_LONG, REQUIRED_ARG, 10000L, 0L, ~0L, 0, 1L, 0},
-#endif /* WITH_INNOBASE_STORAGE_ENGINE */
   {"interactive_timeout", OPT_INTERACTIVE_TIMEOUT,
    "The number of seconds the server waits for activity on an interactive connection before closing it.",
    (gptr*) &global_system_variables.net_interactive_timeout,
@@ -6372,6 +6159,11 @@
    "Directory for plugins.",
    (gptr*) &opt_plugin_dir_ptr, (gptr*) &opt_plugin_dir_ptr, 0,
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+  {"plugin_load", OPT_PLUGIN_LOAD,
+   "Optional colon separated list of plugins to load, where each plugin is "
+   "identified by name and path to library seperated by an equals.",
+   (gptr*) &opt_plugin_load, (gptr*) &opt_plugin_load, 0,
+   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
    {"preload_buffer_size", OPT_PRELOAD_BUFFER_SIZE,
     "The size of the buffer that is allocated when preloading indexes",
     (gptr*) &global_system_variables.preload_buff_size,
@@ -7148,6 +6940,7 @@
 	 server_version,SYSTEM_TYPE,MACHINE_TYPE, MYSQL_COMPILATION_COMMENT);
 }
 
+#ifndef EMBEDDED_LIBRARY
 static void usage(void)
 {
   if (!(default_charset_info= get_charset_by_csname(default_character_set_name,
@@ -7183,17 +6976,17 @@
 #endif
   print_defaults(MYSQL_CONFIG_NAME,load_default_groups);
   puts("");
-  fix_paths();
   set_ports();
 
-  my_print_help(my_long_options);
-  my_print_variables(my_long_options);
+  /* Print out all the options including plugin supplied options */
+  my_print_help_inc_plugins(my_long_options, sizeof(my_long_options)/sizeof(my_option));
 
   puts("\n\
 To see what values a running MySQL server is using, type\n\
 'mysqladmin variables' instead of 'mysqld --verbose --help'.\n");
   }
 }
+#endif /*!EMBEDDED_LIBRARY*/
 
 
 /*
@@ -7230,6 +7023,7 @@
   mqh_used= 0;
   segfaulted= kill_in_progress= 0;
   cleanup_done= 0;
+  defaults_argc= 0;
   defaults_argv= 0;
   server_id_supplied= 0;
   test_flags= select_errors= dropping_tables= ha_open_options=0;
@@ -7317,7 +7111,7 @@
   lc_time_names_name= (char*) "en_US";
   /* Set default values for some option variables */
   default_storage_engine_str= (char*) "MyISAM";
-  global_system_variables.table_type= myisam_hton;
+  global_system_variables.table_plugin= NULL;
   global_system_variables.tx_isolation= ISO_REPEATABLE_READ;
   global_system_variables.select_limit= (ulonglong) HA_POS_ERROR;
   max_system_variables.select_limit=    (ulonglong) HA_POS_ERROR;
@@ -7338,41 +7132,12 @@
 			     "d:t:i:o,/tmp/mysqld.trace");
 #endif
   opt_error_log= IF_WIN(1,0);
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
-  have_innodb= SHOW_OPTION_YES;
-#else
-  have_innodb= SHOW_OPTION_NO;
-#endif
-#ifdef WITH_FALCON_STORAGE_ENGINE
-  have_falcon= SHOW_OPTION_YES;
-#else
-  have_falcon= SHOW_OPTION_NO;
-#endif
-#ifdef WITH_CSV_STORAGE_ENGINE
-  have_csv_db= SHOW_OPTION_YES;
-#else
-  have_csv_db= SHOW_OPTION_NO;
-#endif
-#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
-    have_ndbcluster= SHOW_OPTION_DISABLED;
-#else
-    have_ndbcluster= SHOW_OPTION_NO;
-#endif
-#ifdef WITH_PARTITION_STORAGE_ENGINE
-    have_partition_db= SHOW_OPTION_YES;
-#else
-    have_partition_db= SHOW_OPTION_NO;
-#endif
-#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
-  have_ndbcluster=SHOW_OPTION_DISABLED;
   global_system_variables.ndb_index_stat_enable=FALSE;
   max_system_variables.ndb_index_stat_enable=TRUE;
   global_system_variables.ndb_index_stat_cache_entries=32;
   max_system_variables.ndb_index_stat_cache_entries=~0L;
   global_system_variables.ndb_index_stat_update_freq=20;
   max_system_variables.ndb_index_stat_update_freq=~0L;
-#else
-  have_ndbcluster=SHOW_OPTION_NO;
 #endif
 #ifdef HAVE_OPENSSL
   have_ssl=SHOW_OPTION_YES;
@@ -7665,7 +7430,7 @@
 #endif
   case OPT_EVENT_SCHEDULER:
     if (Events::set_opt_event_scheduler(argument))
-      exit(1);
+	exit(1);
     break;
   case (int) OPT_SKIP_NEW:
     opt_specialflag|= SPECIAL_NO_NEW_FUNC;
@@ -7821,17 +7586,6 @@
     global_system_variables.tx_isolation= (type-1);
     break;
   }
-  case OPT_MERGE:
-  case OPT_BDB:
-    break;
-  case OPT_NDBCLUSTER:
-#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
-    if (opt_ndbcluster)
-      have_ndbcluster= SHOW_OPTION_YES;
-    else
-      have_ndbcluster= SHOW_OPTION_DISABLED;
-#endif
-    break;
 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
   case OPT_NDB_MGMD:
   case OPT_NDB_NODEID:
@@ -7870,32 +7624,6 @@
       ndb_extra_logging= atoi(argument);
     break;
 #endif
-  case OPT_FALCON:
-#ifdef WITH_FALCON_STORAGE_ENGINE
-    if (opt_falcon)
-      have_falcon= SHOW_OPTION_YES;
-    else
-      have_falcon= SHOW_OPTION_DISABLED;
-#endif
-    break;
-  case OPT_INNODB:
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
-    if (opt_innodb)
-      have_innodb= SHOW_OPTION_YES;
-    else
-      have_innodb= SHOW_OPTION_DISABLED;
-#endif
-    break;
-  case OPT_INNODB_DATA_FILE_PATH:
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
-    innobase_data_file_path= argument;
-#endif
-    break;
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
-  case OPT_INNODB_LOG_ARCHIVE:
-    innobase_log_archive= argument ? test(atoi(argument)) : 1;
-    break;
-#endif /* WITH_INNOBASE_STORAGE_ENGINE */
   case OPT_MYISAM_RECOVER:
   {
     if (!argument || !argument[0])
@@ -8026,7 +7754,7 @@
 }
 
 
-static void get_options(int argc,char **argv)
+static void get_options(int *argc,char **argv)
 {
   int ho_error;
 
@@ -8034,38 +7762,20 @@
   strmake(def_ft_boolean_syntax, ft_boolean_syntax,
 	  sizeof(ft_boolean_syntax)-1);
   my_getopt_error_reporter= option_error_reporter;
-  if ((ho_error= handle_options(&argc, &argv, my_long_options,
+
+  /* Skip unknown options so that they may be processed later by plugins */
+  my_getopt_skip_unknown= TRUE;
+
+  if ((ho_error= handle_options(argc, &argv, my_long_options,
                                 get_one_option)))
     exit(ho_error);
+  (*argc)++; /* add back one for the progname handle_options removes */
+             /* no need to do this for argv as we are discarding it. */
 
-#ifndef WITH_NDBCLUSTER_STORAGE_ENGINE
-  if (opt_ndbcluster)
-    sql_print_warning("this binary does not contain NDBCLUSTER storage engine");
-#endif
-#ifndef WITH_FALCON_STORAGE_ENGINE
-  if (opt_falcon)
-    sql_print_warning("this binary does not contain FALCON storage engine");
-#endif
-#ifndef WITH_INNOBASE_STORAGE_ENGINE
-  if (opt_innodb)
-    sql_print_warning("this binary does not contain INNODB storage engine");
-#endif
   if ((opt_log_slow_admin_statements || opt_log_queries_not_using_indexes) &&
       !opt_slow_log)
     sql_print_warning("options --log-slow-admin-statements and --log-queries-not-using-indexes have no effect if --log-slow-queries is not set");
 
-  if (argc > 0)
-  {
-    fprintf(stderr, "%s: Too many arguments (first extra is '%s').\nUse --help to get a list of available options\n", my_progname, *argv);
-    /* FIXME add EXIT_TOO_MANY_ARGUMENTS to "mysys_err.h" and return that code? */
-    exit(1);
-  }
-
-  if (opt_help)
-  {
-    usage();
-    exit(0);
-  }
 #if defined(HAVE_BROKEN_REALPATH)
   my_use_symdir=0;
   my_disable_symlinks=1;
@@ -8418,12 +8128,7 @@
   bzero((char*) &thd->status_var, sizeof(thd->status_var));
 
   /* Reset some global variables */
-  for (SHOW_VAR *ptr= status_vars; ptr->name; ptr++)
-  {
-    /* Note that SHOW_LONG_NOFLUSH variables are not reset */
-    if (ptr->type == SHOW_LONG)
-      *(ulong*) ptr->value= 0;
-  }
+  reset_status_vars();
 
   /* Reset the counters of all key caches (default and named). */
   process_key_caches(reset_key_cache_counters);
@@ -8442,18 +8147,9 @@
 
 
 /*****************************************************************************
-  Instantiate have_xyx for missing storage engines
+  Instantiate variables for missing storage engines
+  This section should go away soon
 *****************************************************************************/
-#undef have_falcon
-#undef have_innodb
-#undef have_ndbcluster
-#undef have_csv_db
-
-SHOW_COMP_OPTION have_falcon= SHOW_OPTION_NO;
-SHOW_COMP_OPTION have_innodb= SHOW_OPTION_NO;
-SHOW_COMP_OPTION have_ndbcluster= SHOW_OPTION_NO;
-SHOW_COMP_OPTION have_csv_db= SHOW_OPTION_NO;
-SHOW_COMP_OPTION have_partition_db= SHOW_OPTION_NO;
 
 #ifndef WITH_FALCON_STORAGE_ENGINE
 //extern "C" {
@@ -8465,41 +8161,6 @@
 my_bool			falcon_debug_server;
 char*			falcon_log_dir;
 //}
-#endif
-
-#ifndef WITH_INNOBASE_STORAGE_ENGINE
-uint innobase_flush_log_at_trx_commit;
-ulong innobase_fast_shutdown;
-long innobase_mirrored_log_groups, innobase_log_files_in_group;
-longlong innobase_log_file_size;
-long innobase_log_buffer_size;
-longlong innobase_buffer_pool_size;
-long innobase_additional_mem_pool_size;
-long innobase_file_io_threads, innobase_lock_wait_timeout;
-long innobase_force_recovery;
-long innobase_open_files;
-char *innobase_data_home_dir, *innobase_data_file_path;
-char *innobase_log_group_home_dir, *innobase_log_arch_dir;
-char *innobase_unix_file_flush_method;
-my_bool innobase_log_archive,
-        innobase_use_doublewrite,
-        innobase_use_checksums,
-        innobase_file_per_table,
-        innobase_locks_unsafe_for_binlog,
-        innobase_rollback_on_timeout,
-        innobase_stats_on_metadata;
-
-extern "C" {
-ulong srv_max_buf_pool_modified_pct;
-ulong srv_max_purge_lag;
-ulong srv_auto_extend_increment;
-ulong srv_n_spin_wait_rounds;
-ulong srv_n_free_tickets_to_enter;
-ulong srv_thread_sleep_delay;
-ulong srv_thread_concurrency;
-ulong srv_commit_concurrency;
-}
-
 #endif
 
 #ifndef WITH_NDBCLUSTER_STORAGE_ENGINE

--- 1.324/sql/sql_class.cc	2007-05-15 08:34:09 -07:00
+++ 1.325/sql/sql_class.cc	2007-05-15 08:34:09 -07:00
@@ -169,18 +169,25 @@
   reset_open_tables_state();
 }
 
-my_bool thd_in_lock_tables(const THD *thd)
+/*
+  The following functions form part of the C plugin API
+*/
+
+extern "C"
+int thd_in_lock_tables(const THD *thd)
 {
-  return thd->in_lock_tables;
+  return test(thd->in_lock_tables);
 }
 
 
-my_bool thd_tablespace_op(const THD *thd)
+extern "C"
+int thd_tablespace_op(const THD *thd)
 {
-  return thd->tablespace_op;
+  return test(thd->tablespace_op);
 }
 
 
+extern "C"
 const char *thd_proc_info(THD *thd, const char *info)
 {
   const char *old_info= thd->proc_info;
@@ -188,11 +195,98 @@
   return old_info;
 }
 
+extern "C"
 void **thd_ha_data(const THD *thd, const struct handlerton *hton)
 {
   return (void **) thd->ha_data + hton->slot;
 }
 
+extern "C"
+long long thd_test_options(const THD *thd, long long test_options)
+{
+  return thd->options & test_options;
+}
+
+extern "C"
+int thd_sql_command(const THD *thd)
+{
+  return (int) thd->lex->sql_command;
+}
+
+extern "C"
+int thd_tx_isolation(const THD *thd)
+{
+  return (int) thd->variables.tx_isolation;
+}
+
+
+/*
+  Dumps a text description of a thread, its security context
+  (user, host) and the current query.
+
+  SYNOPSIS
+    thd_security_context()
+    thd                 current thread context
+    buffer              pointer to preferred result buffer
+    length              length of buffer
+    max_query_len       how many chars of query to copy (0 for all)
+
+  RETURN VALUES
+    pointer to string
+*/
+extern "C"
+char *thd_security_context(THD *thd, char *buffer, unsigned int length,
+                           unsigned int max_query_len)
+{
+  String str(buffer, length, &my_charset_latin1);
+  const Security_context *sctx= &thd->main_security_ctx;
+  char header[64];
+  int len;
+
+  len= my_snprintf(header, sizeof(header),
+                   "MySQL thread id %lu, query id %lu",
+                   thd->thread_id, (ulong) thd->query_id);
+  str.length(0);
+  str.append(header, len);
+
+  if (sctx->host)
+  {
+    str.append(' ');
+    str.append(sctx->host);
+  }
+
+  if (sctx->ip)
+  {
+    str.append(' ');
+    str.append(sctx->ip);
+  }
+
+  if (sctx->user)
+  {
+    str.append(' ');
+    str.append(sctx->user);
+  }
+
+  if (thd->proc_info)
+  {
+    str.append(' ');
+    str.append(thd->proc_info);
+  }
+
+  if (thd->query)
+  {
+    if (max_query_len < 1)
+      len= thd->query_length;
+    else
+      len= min(thd->query_length, max_query_len);
+    str.append('\n');
+    str.append(thd->query, len);
+  }
+  if (str.c_ptr_safe() == buffer)
+    return buffer;
+  return thd->strmake(str.ptr(), str.length());
+}
+
 
 
 THD::THD()
@@ -202,14 +296,18 @@
    lock_id(&main_lock_id),
    user_time(0), in_sub_stmt(0),
    binlog_table_maps(0),
-   global_read_lock(0), is_fatal_error(0),
-   rand_used(0), time_zone_used(0),
    arg_of_last_insert_id_function(FALSE),
    first_successful_insert_id_in_prev_stmt(0),
    first_successful_insert_id_in_prev_stmt_for_binlog(0),
    first_successful_insert_id_in_cur_stmt(0),
-   in_lock_tables(0), bootstrap(0), derived_tables_processing(FALSE),
    stmt_depends_on_first_successful_insert_id_in_prev_stmt(FALSE),
+   global_read_lock(0),
+   is_fatal_error(0),
+   rand_used(0),
+   time_zone_used(0),
+   in_lock_tables(0),
+   bootstrap(0),
+   derived_tables_processing(FALSE),
    spcont(NULL)
 {
   ulong tmp;
@@ -247,6 +345,7 @@
   time_after_lock=(time_t) 0;
   current_linfo =  0;
   slave_thread = 0;
+  bzero(&variables, sizeof(variables));
   thread_id= variables.pseudo_thread_id= 0;
   one_shot_set= 0;
   file_id = 0;
@@ -357,7 +456,7 @@
 void THD::init(void)
 {
   pthread_mutex_lock(&LOCK_global_system_variables);
-  variables= global_system_variables;
+  plugin_thdvar_init(this);
   variables.time_format= date_time_format_copy((THD*) 0,
 					       variables.time_format);
   variables.date_format= date_time_format_copy((THD*) 0,
@@ -506,6 +605,7 @@
     cleanup();
 
   ha_close_connection(this);
+  plugin_thdvar_cleanup(this);
 
   DBUG_PRINT("info", ("freeing security context"));
   main_security_ctx.destroy();
@@ -1736,7 +1836,7 @@
 }
 
 /*
-  Statement functions 
+  Statement functions
 */
 
 Statement::Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg,

--- 1.627/sql/sql_parse.cc	2007-05-15 08:34:09 -07:00
+++ 1.628/sql/sql_parse.cc	2007-05-15 08:34:09 -07:00
@@ -43,37 +43,37 @@
 const char *any_db="*any*";	// Special symbol for check_access
 
 const LEX_STRING command_name[]={
-  C_STRING_WITH_LEN("Sleep"),
-  C_STRING_WITH_LEN("Quit"),
-  C_STRING_WITH_LEN("Init DB"),
-  C_STRING_WITH_LEN("Query"),
-  C_STRING_WITH_LEN("Field List"),
-  C_STRING_WITH_LEN("Create DB"),
-  C_STRING_WITH_LEN("Drop DB"),
-  C_STRING_WITH_LEN("Refresh"),
-  C_STRING_WITH_LEN("Shutdown"),
-  C_STRING_WITH_LEN("Statistics"),
-  C_STRING_WITH_LEN("Processlist"),
-  C_STRING_WITH_LEN("Connect"),
-  C_STRING_WITH_LEN("Kill"),
-  C_STRING_WITH_LEN("Debug"),
-  C_STRING_WITH_LEN("Ping"),
-  C_STRING_WITH_LEN("Time"),
-  C_STRING_WITH_LEN("Delayed insert"),
-  C_STRING_WITH_LEN("Change user"),
-  C_STRING_WITH_LEN("Binlog Dump"),
-  C_STRING_WITH_LEN("Table Dump"),
-  C_STRING_WITH_LEN("Connect Out"),
-  C_STRING_WITH_LEN("Register Slave"),
-  C_STRING_WITH_LEN("Prepare"),
-  C_STRING_WITH_LEN("Execute"),
-  C_STRING_WITH_LEN("Long Data"),
-  C_STRING_WITH_LEN("Close stmt"),
-  C_STRING_WITH_LEN("Reset stmt"),
-  C_STRING_WITH_LEN("Set option"),
-  C_STRING_WITH_LEN("Fetch"),
-  C_STRING_WITH_LEN("Daemon"),
-  C_STRING_WITH_LEN("Error")  // Last command number
+  { C_STRING_WITH_LEN("Sleep") },
+  { C_STRING_WITH_LEN("Quit") },
+  { C_STRING_WITH_LEN("Init DB") },
+  { C_STRING_WITH_LEN("Query") },
+  { C_STRING_WITH_LEN("Field List") },
+  { C_STRING_WITH_LEN("Create DB") },
+  { C_STRING_WITH_LEN("Drop DB") },
+  { C_STRING_WITH_LEN("Refresh") },
+  { C_STRING_WITH_LEN("Shutdown") },
+  { C_STRING_WITH_LEN("Statistics") },
+  { C_STRING_WITH_LEN("Processlist") },
+  { C_STRING_WITH_LEN("Connect") },
+  { C_STRING_WITH_LEN("Kill") },
+  { C_STRING_WITH_LEN("Debug") },
+  { C_STRING_WITH_LEN("Ping") },
+  { C_STRING_WITH_LEN("Time") },
+  { C_STRING_WITH_LEN("Delayed insert") },
+  { C_STRING_WITH_LEN("Change user") },
+  { C_STRING_WITH_LEN("Binlog Dump") },
+  { C_STRING_WITH_LEN("Table Dump") },
+  { C_STRING_WITH_LEN("Connect Out") },
+  { C_STRING_WITH_LEN("Register Slave") },
+  { C_STRING_WITH_LEN("Prepare") },
+  { C_STRING_WITH_LEN("Execute") },
+  { C_STRING_WITH_LEN("Long Data") },
+  { C_STRING_WITH_LEN("Close stmt") },
+  { C_STRING_WITH_LEN("Reset stmt") },
+  { C_STRING_WITH_LEN("Set option") },
+  { C_STRING_WITH_LEN("Fetch") },
+  { C_STRING_WITH_LEN("Daemon") },
+  { C_STRING_WITH_LEN("Error") }  // Last command number
 };
 
 const char *xa_state_names[]={
@@ -4570,7 +4570,8 @@
 
   if (schema_db)
   {
-    if (want_access & ~(SELECT_ACL | EXTRA_ACL))
+    if (!(sctx->master_access & FILE_ACL) && (want_access & FILE_ACL) ||
+        (want_access & ~(SELECT_ACL | EXTRA_ACL | FILE_ACL)))
     {
       if (!no_errors)
       {

--- 1.567/sql/sql_yacc.yy	2007-05-15 08:34:09 -07:00
+++ 1.568/sql/sql_yacc.yy	2007-05-15 08:34:09 -07:00
@@ -917,6 +917,7 @@
 %token  RESUME_SYM
 %token  RETURNS_SYM                   /* SQL-2003-R */
 %token  RETURN_SYM                    /* SQL-2003-R */
+%token  REVERSE_SYM
 %token  REVOKE                        /* SQL-2003-R */
 %token  RIGHT                         /* SQL-2003-R */
 %token  ROLLBACK_SYM                  /* SQL-2003-R */
@@ -1053,6 +1054,7 @@
 %token  WAIT_SYM
 %token  WARNINGS
 %token  WEEK_SYM
+%token  WEIGHT_STRING_SYM
 %token  WHEN_SYM                      /* SQL-2003-R */
 %token  WHERE                         /* SQL-2003-R */
 %token  WHILE_SYM
@@ -1118,7 +1120,11 @@
         ev_alter_on_schedule_completion opt_ev_rename_to opt_ev_sql_stmt
 
 %type <ulong_num>
-	ulong_num real_ulong_num merge_insert_types
+        ulong_num real_ulong_num merge_insert_types
+        ws_nweights
+        ws_level_flag_desc ws_level_flag_reverse ws_level_flags
+        opt_ws_levels ws_level_list ws_level_list_item ws_level_number
+        ws_level_range ws_level_list_or_range  
 
 %type <ulonglong_number>
 	ulonglong_num real_ulonglong_num size_number
@@ -4305,7 +4311,11 @@
 	| TYPE_SYM opt_equal storage_engines
           {
             Lex->create_info.db_type= $3;
-            WARN_DEPRECATED(yythd, "5.2", "TYPE=storage_engine",
+            /*
+               ATTENTION: changed 5.2 to 6.1. Because we are using
+               5.1 code base with 6.0.xyz-falcon-alpha as version name.
+             */
+            WARN_DEPRECATED(yythd, "6.1", "TYPE=storage_engine",
                             "'ENGINE=storage_engine'");
             Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE;
           }
@@ -4914,6 +4924,74 @@
 	}
 	| charset charset_name	{ Lex->charset=$2; } ;
 
+ws_nweights:
+        '(' real_ulong_num
+        {
+          if ($2 == 0)
+          {
+            my_parse_error(ER(ER_SYNTAX_ERROR));
+            MYSQL_YYABORT;
+          }
+        }
+        ')'
+        { $$= $2; }
+        ;
+
+ws_level_flag_desc:
+        ASC { $$= 0; }
+        | DESC { $$= 1 << MY_STRXFRM_DESC_SHIFT; }
+        ;
+
+ws_level_flag_reverse:
+        REVERSE_SYM { $$= 1 << MY_STRXFRM_REVERSE_SHIFT; } ;
+
+ws_level_flags:
+        /* empty */ { $$= 0; }
+        | ws_level_flag_desc { $$= $1; }
+        | ws_level_flag_desc ws_level_flag_reverse { $$= $1 | $2; }
+        | ws_level_flag_reverse { $$= $1 ; }
+        ;
+
+ws_level_number:
+        real_ulong_num
+        {
+          $$= $1 < 1 ? 1 : ($1 > MY_STRXFRM_NLEVELS ? MY_STRXFRM_NLEVELS : $1);
+          $$--;
+        }
+        ;
+
+ws_level_list_item:
+        ws_level_number ws_level_flags
+        {
+          $$= (1 | $2) << $1;
+        }
+        ;
+
+ws_level_list:
+        ws_level_list_item { $$= $1; }
+        | ws_level_list ',' ws_level_list_item { $$|= $3; }
+        ;
+
+ws_level_range:
+        ws_level_number '-' ws_level_number
+        {
+          uint start= $1;
+          uint end= $3;
+          for ($$= 0; start <= end; start++)
+            $$|= (1 << start);
+        }
+        ;
+
+ws_level_list_or_range:
+        ws_level_list { $$= $1; }
+        | ws_level_range { $$= $1; }
+        ;
+
+opt_ws_levels:
+        /* empty*/ { $$= 0; }
+        | LEVEL_SYM ws_level_list_or_range { $$= $2; }
+        ;
+
 opt_primary:
 	/* empty */
 	| PRIMARY_SYM
@@ -5765,8 +5843,12 @@
 	RESTORE_SYM table_or_tables
 	{
 	   Lex->sql_command = SQLCOM_RESTORE_TABLE;
-           WARN_DEPRECATED(yythd, "5.2", "RESTORE TABLE",
-                           "MySQL Administrator (mysqldump, mysql)");
+       /*
+          ATTENTION: changed 5.2 to 6.1. Because we are using
+          5.1 code base with 6.0.xyz-falcon-alpha as version name.
+        */
+       WARN_DEPRECATED(yythd, "6.1", "RESTORE TABLE",
+                       "MySQL Administrator (mysqldump, mysql)");
 	}
 	table_list FROM TEXT_STRING_sys
         {
@@ -5777,8 +5859,12 @@
 	BACKUP_SYM table_or_tables
 	{
 	   Lex->sql_command = SQLCOM_BACKUP_TABLE;
-           WARN_DEPRECATED(yythd, "5.2", "BACKUP TABLE",
-                           "MySQL Administrator (mysqldump, mysql)");
+       /*
+          ATTENTION: changed 5.2 to 6.1. Because we are using
+          5.1 code base with 6.0.xyz-falcon-alpha as version name.
+        */
+       WARN_DEPRECATED(yythd, "6.1", "BACKUP TABLE",
+                       "MySQL Administrator (mysqldump, mysql)");
 	}
 	table_list TO_SYM TEXT_STRING_sys
         {
@@ -6769,6 +6855,8 @@
 	  { $$= new (YYTHD->mem_root) Item_func_repeat($3,$5); }
 	| REPLACE '(' expr ',' expr ',' expr ')'
 	  { $$= new (YYTHD->mem_root) Item_func_replace($3,$5,$7); }
+	| REVERSE_SYM '(' expr ')'
+	  { $$= new (YYTHD->mem_root) Item_func_reverse($3); }
 	| TRUNCATE_SYM '(' expr ',' expr ')'
 	  { $$= new (YYTHD->mem_root) Item_func_round($3,$5,1); }
 	| WEEK_SYM '(' expr ')'
@@ -6782,6 +6870,19 @@
           }
 	| WEEK_SYM '(' expr ',' expr ')'
 	  { $$= new (YYTHD->mem_root) Item_func_week($3,$5); }
+	| WEIGHT_STRING_SYM '(' expr opt_ws_levels ')'
+	  { $$= new (YYTHD->mem_root) Item_func_weight_string($3, 0, $4); }
+	| WEIGHT_STRING_SYM '(' expr AS CHAR_SYM ws_nweights opt_ws_levels ')'
+	  {
+            $$= new (YYTHD->mem_root)
+                Item_func_weight_string($3, $6, $7|MY_STRXFRM_PAD_WITH_SPACE);
+          }
+	| WEIGHT_STRING_SYM '(' expr AS BINARY ws_nweights ')'
+	  {
+            $3= create_func_char_cast(YYTHD, $3, $6, &my_charset_bin);
+            $$= new (YYTHD->mem_root)
+                Item_func_weight_string($3, $6, MY_STRXFRM_PAD_WITH_SPACE);
+          }
         | geometry_function
           {
 #ifdef HAVE_SPATIAL
@@ -8636,7 +8737,11 @@
         | opt_full PLUGIN_SYM
 	  {
 	    LEX *lex= Lex;
-	    WARN_DEPRECATED(yythd, "5.2", "SHOW PLUGIN", "'SHOW PLUGINS'");
+        /*
+           ATTENTION: changed 5.2 to 6.1. Because we are using
+           5.1 code base with 6.0.xyz-falcon-alpha as version name.
+         */
+	    WARN_DEPRECATED(yythd, "6.1", "SHOW PLUGIN", "'SHOW PLUGINS'");
             lex->sql_command= SQLCOM_SHOW_PLUGINS;
             if (prepare_schema_table(YYTHD, lex, 0, SCH_PLUGINS))
               MYSQL_YYABORT;
@@ -8702,7 +8807,7 @@
 	  {
 	    LEX *lex=Lex;
 	    lex->sql_command= SQLCOM_SHOW_STORAGE_ENGINES;
-	    WARN_DEPRECATED(yythd, "5.2", "SHOW TABLE TYPES", "'SHOW [STORAGE] ENGINES'");
+	    WARN_DEPRECATED(yythd, "6.1", "SHOW TABLE TYPES", "'SHOW [STORAGE] ENGINES'");
 	  }
 	| opt_storage ENGINES_SYM
 	  {
@@ -8752,7 +8857,11 @@
 	      my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), "InnoDB");
 	      MYSQL_YYABORT;
             }
-            WARN_DEPRECATED(yythd, "5.2", "SHOW INNODB STATUS", "'SHOW ENGINE INNODB STATUS'");
+          /*
+             ATTENTION: changed 5.2 to 6.1. Because we are using
+             5.1 code base with 6.0.xyz-falcon-alpha as version name.
+           */
+          WARN_DEPRECATED(yythd, "6.1", "SHOW INNODB STATUS", "'SHOW ENGINE INNODB STATUS'");
 	  }
         | MUTEX_SYM STATUS_SYM
           {
@@ -8764,7 +8873,11 @@
 	      my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), "InnoDB");
 	      MYSQL_YYABORT;
             }
-            WARN_DEPRECATED(yythd, "5.2", "SHOW MUTEX STATUS", "'SHOW ENGINE INNODB MUTEX'");
+          /*
+             ATTENTION: changed 5.2 to 6.1. Because we are using
+             5.1 code base with 6.0.xyz-falcon-alpha as version name.
+           */
+          WARN_DEPRECATED(yythd, "6.1", "SHOW MUTEX STATUS", "'SHOW ENGINE INNODB MUTEX'");
 	  }
 	| opt_full PROCESSLIST_SYM
 	  { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
@@ -9114,7 +9227,11 @@
         LOAD TABLE_SYM table_ident FROM MASTER_SYM
         {
 	  LEX *lex=Lex;
-          WARN_DEPRECATED(yythd, "5.2", "LOAD TABLE FROM MASTER",
+          /*
+             ATTENTION: changed 5.2 to 6.1. Because we are using
+             5.1 code base with 6.0.xyz-falcon-alpha as version name.
+           */
+          WARN_DEPRECATED(yythd, "6.1", "LOAD TABLE FROM MASTER",
                           "MySQL Administrator (mysqldump, mysql)");
           if (lex->sphead)
 	  {
@@ -9162,7 +9279,11 @@
 	FROM MASTER_SYM
         {
 	  Lex->sql_command = SQLCOM_LOAD_MASTER_DATA;
-          WARN_DEPRECATED(yythd, "5.2", "LOAD DATA FROM MASTER",
+          /*
+             ATTENTION: changed 5.2 to 6.1. Because we are using
+             5.1 code base with 6.0.xyz-falcon-alpha as version name.
+           */
+          WARN_DEPRECATED(yythd, "6.1", "LOAD DATA FROM MASTER",
                           "mysqldump or future "
                           "BACKUP/RESTORE DATABASE facility");
         };
@@ -10016,6 +10137,7 @@
 	| RESOURCES		{}
         | RESUME_SYM            {}
 	| RETURNS_SYM           {}
+        | REVERSE_SYM           {}
 	| ROLLUP_SYM		{}
 	| ROUTINE_SYM		{}
 	| ROWS_SYM		{}
@@ -10076,6 +10198,7 @@
 	| WARNINGS		{}
 	| WAIT_SYM              {}
 	| WEEK_SYM		{}
+	| WEIGHT_STRING_SYM	{}
 	| WORK_SYM		{}
 	| X509_SYM		{}
 	| YEAR_SYM		{}

--- 1.116/mysql-test/r/ctype_utf8.result	2007-05-15 08:34:09 -07:00
+++ 1.117/mysql-test/r/ctype_utf8.result	2007-05-15 08:34:09 -07:00
@@ -1454,7 +1454,7 @@
 explain
 select substr(Z.a,-1), Z.a from t1 as Y join t1 as Z on Y.a=Z.a order by 1;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	Y	ALL	NULL	NULL	NULL	NULL	2	Using temporary; Using filesort
+1	SIMPLE	Y	ALL	NULL	NULL	NULL	NULL	2	Using temporary; Using filesort; Using join cache
 1	SIMPLE	Z	ALL	NULL	NULL	NULL	NULL	2	Using where
 select substr(Z.a,-1), Z.a from t1 as Y join t1 as Z on Y.a=Z.a order by 1;
 substr(Z.a,-1)	a

--- 1.205/mysql-test/r/view.result	2007-05-15 08:34:09 -07:00
+++ 1.206/mysql-test/r/view.result	2007-05-15 08:34:09 -07:00
@@ -2317,7 +2317,7 @@
 1	SIMPLE	t2	ref	a	a	10	const,test.t1.b	2	Using where; Using index
 EXPLAIN SELECT * FROM v2 WHERE a=1;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	ref	a	a	5	const	1	Using where; Using index
+1	SIMPLE	t1	ref	a	a	5	const	1	Using where; Using index; Using join cache
 1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	3	Using where
 DROP VIEW v1,v2;
 DROP TABLE t1,t2,t3;
@@ -3346,6 +3346,19 @@
 NULL	UNION RESULT	<union1,2>	ALL	NULL	NULL	NULL	NULL	NULL	Using filesort
 DROP VIEW v1;
 DROP TABLE t1;
+CREATE VIEW v1 AS SELECT CAST( 1.23456789 AS DECIMAL( 7,5 ) ) AS col;
+SELECT * FROM v1;
+col
+1.23457
+DESCRIBE v1;
+Field	Type	Null	Key	Default	Extra
+col	decimal(7,5)	NO		0.00000	
+DROP VIEW v1;
+CREATE VIEW v1 AS SELECT CAST(1.23456789 AS DECIMAL(8,0)) AS col;
+SHOW CREATE VIEW v1;
+View	Create View
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(1.23456789 as decimal(8,0)) AS `col`
+DROP VIEW v1;
 End of 5.0 tests.
 DROP DATABASE IF EXISTS `d-1`;
 CREATE DATABASE `d-1`;

--- 1.152/mysql-test/r/information_schema.result	2007-05-15 08:34:09 -07:00
+++ 1.153/mysql-test/r/information_schema.result	2007-05-15 08:34:09 -07:00
@@ -298,7 +298,7 @@
 information_schema.SCHEMATA b where
 a.ROUTINE_SCHEMA = b.SCHEMA_NAME;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	#	ALL	NULL	NULL	NULL	NULL	2	
+1	SIMPLE	#	ALL	NULL	NULL	NULL	NULL	2	Using join cache
 1	SIMPLE	#	ALL	NULL	NULL	NULL	NULL	2	Using where
 select a.ROUTINE_NAME, b.name from information_schema.ROUTINES a,
 mysql.proc b where a.ROUTINE_NAME = convert(b.name using utf8) order by 1;

--- 1.292/storage/innobase/handler/ha_innodb.cc	2007-05-15 08:34:09 -07:00
+++ 1.293/storage/innobase/handler/ha_innodb.cc	2007-05-15 08:34:09 -07:00
@@ -54,7 +54,7 @@
   This needs to exist until the query cache callback is removed
   or learns to pass hton.
 */
-static handlerton *legacy_innodb_hton;
+static handlerton *innodb_hton_ptr;
 
 /* Store MySQL definition of 'byte': in Linux it is char while InnoDB
 uses unsigned char; the header univ.i which we include next defines
@@ -92,7 +92,6 @@
 #include "../storage/innobase/include/ha_prototypes.h"
 }
 
-ulong	innobase_large_page_size = 0;
 
 /* The default values for the following, type long or longlong, start-up
 parameters are declared in mysqld.cc: */
@@ -103,7 +102,7 @@
 	innobase_lock_wait_timeout, innobase_force_recovery,
 	innobase_open_files;
 
-longlong innobase_buffer_pool_size, innobase_log_file_size;
+long long innobase_buffer_pool_size, innobase_log_file_size;
 
 /* The default values for the following char* start-up parameters
 are determined in innobase_init below: */
@@ -119,19 +118,29 @@
 /* Below we have boolean-valued start-up parameters, and their default
 values */
 
+static
 ulong	innobase_fast_shutdown			= 1;
+#ifdef UNIV_LOG_ARCHIVE
+static
 my_bool innobase_log_archive			= FALSE;/* unused */
+#endif /* UNIG_LOG_ARCHIVE */
+static
 my_bool innobase_use_doublewrite		= TRUE;
+static
 my_bool innobase_use_checksums			= TRUE;
-my_bool innobase_use_large_pages		= FALSE;
-my_bool	innobase_use_native_aio			= FALSE;
+static
 my_bool	innobase_file_per_table			= FALSE;
+static
 my_bool innobase_locks_unsafe_for_binlog	= FALSE;
+static
 my_bool innobase_rollback_on_timeout		= FALSE;
+static
 my_bool innobase_create_status_file		= FALSE;
+static
 my_bool innobase_stats_on_metadata		= TRUE;
 
-static char *internal_innobase_data_file_path	= NULL;
+static
+char*	internal_innobase_data_file_path	= NULL;
 
 /* The following counter is used to convey information to InnoDB
 about server activity: in selects it is not sensible to call
@@ -165,6 +174,17 @@
 
 static const char innobase_hton_name[]= "InnoDB";
 
+
+static MYSQL_THDVAR_BOOL(support_xa, PLUGIN_VAR_OPCMDARG,
+  "Enable InnoDB support for the XA two-phase commit",
+  /* check_func */ NULL, /* update_func */ NULL,
+  /* default */ TRUE);
+
+static MYSQL_THDVAR_BOOL(table_locks, PLUGIN_VAR_OPCMDARG,
+  "Enable InnoDB locking in LOCK TABLES",
+  /* check_func */ NULL, /* update_func */ NULL,
+  /* default */ TRUE);
+
 static handler *innobase_create_handler(handlerton *hton,
                                         TABLE_SHARE *table, 
                                         MEM_ROOT *mem_root)
@@ -469,10 +489,9 @@
 thd_to_trx(
 /*=======*/
 				/* out: reference to transaction pointer */
-	THD*		thd,	/* in: MySQL thread */
-	handlerton*	hton)	/* in: InnoDB handlerton */
+	THD*		thd)	/* in: MySQL thread */
 {
-	return(*(trx_t**) thd_ha_data(thd, hton));
+	return(*(trx_t**) thd_ha_data(thd, innodb_hton_ptr));
 }
 
 /************************************************************************
@@ -493,7 +512,7 @@
 		return 0;
 	}
 
-	trx = thd_to_trx(thd, hton);
+	trx = thd_to_trx(thd);
 
 	if (trx) {
 		innobase_release_stat_resources(trx);
@@ -673,78 +692,12 @@
 	uint	max_query_len)	/* in: max query length to print, or 0 to
 				   use the default max length */
 {
-	const THD*	thd;
-	const Security_context *sctx;
-	const char*	s;
-
-	thd = (const THD*) input_thd;
-	/* We probably want to have original user as part of debug output. */
-	sctx = &thd->main_security_ctx;
-
-
-	fprintf(f, "MySQL thread id %lu, query id %lu",
-		thd->thread_id, (ulong) thd->query_id);
-	if (sctx->host) {
-		putc(' ', f);
-		fputs(sctx->host, f);
-	}
-
-	if (sctx->ip) {
-		putc(' ', f);
-		fputs(sctx->ip, f);
-	}
-
-	if (sctx->user) {
-		putc(' ', f);
-		fputs(sctx->user, f);
-	}
-
-	if ((s = thd->proc_info)) {
-		putc(' ', f);
-		fputs(s, f);
-	}
-
-	if ((s = thd->query)) {
-		/* 3100 is chosen because currently 3000 is the maximum
-		   max_query_len we ever give this. */
-		char	buf[3100];
-		uint	len;
-
-		/* If buf is too small, we dynamically allocate storage
-		   in this. */
-		char*	dyn_str = NULL;
-
-		/* Points to buf or dyn_str. */
-		char*	str = buf;
-
-		if (max_query_len == 0) {
-			/* ADDITIONAL SAFETY: the default is to print at
-			   most 300 chars to reduce the probability of a
-			   seg fault if there is a race in
-			   thd->query_length in MySQL; after May 14, 2004
-			   probably no race any more, but better be
-			   safe */
-			max_query_len = 300;
-		}
-
-		len = min(thd->query_length, max_query_len);
-
-		if (len > (sizeof(buf) - 1)) {
-			dyn_str = my_malloc(len + 1, MYF(0));
-			str = dyn_str;
-		}
-
-		/* Use strmake to reduce the timeframe for a race,
-		   compared to fwrite() */
-		len = (uint) (strmake(str, s, len) - str);
-		putc('\n', f);
-		fwrite(str, 1, len, f);
-
-		if (dyn_str) {
-			my_free(dyn_str, MYF(0));
-		}
-	}
+	THD*	thd;
+	char	buffer[1024];
 
+	thd = (THD*) input_thd;
+	fputs(thd_security_context(thd, buffer, sizeof(buffer), 
+				   max_query_len), f);
 	putc('\n', f);
 }
 
@@ -953,7 +906,7 @@
 	handlerton*	hton,	/* in: handlerton for innodb */
 	THD*	thd)	/* in: user thread handle */
 {
-	trx_t*&	trx = thd_to_trx(thd, hton);
+	trx_t*&	trx = thd_to_trx(thd);
 
 	ut_ad(thd == current_thd);
 
@@ -967,7 +920,9 @@
 
 		/* Update the info whether we should skip XA steps that eat
 		CPU time */
-		trx->support_xa = (ibool)(thd->variables.innodb_support_xa);
+		trx->support_xa = THDVAR(thd, support_xa);
+
+		thd_to_trx(thd) = trx;
 	} else {
 		if (trx->magic_n != TRX_MAGIC_N) {
 			mem_analyze_corruption(trx);
@@ -976,13 +931,13 @@
 		}
 	}
 
-	if (thd->options & OPTION_NO_FOREIGN_KEY_CHECKS) {
+	if (thd_test_options(thd, OPTION_NO_FOREIGN_KEY_CHECKS)) {
 		trx->check_foreigns = FALSE;
 	} else {
 		trx->check_foreigns = TRUE;
 	}
 
-	if (thd->options & OPTION_RELAXED_UNIQUE_CHECKS) {
+	if (thd_test_options(thd, OPTION_RELAXED_UNIQUE_CHECKS)) {
 		trx->check_unique_secondary = FALSE;
 	} else {
 		trx->check_unique_secondary = TRUE;
@@ -1069,7 +1024,7 @@
 
 	innobase_register_stmt(hton, thd);
 
-	if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
+	if (thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
 
 		/* No autocommit mode, register for a transaction */
 		trans_register_ha(thd, TRUE, hton);
@@ -1161,14 +1116,15 @@
 
 	ut_a(full_name_len < 999);
 
-	if (thd->variables.tx_isolation == ISO_SERIALIZABLE) {
+	trx = check_trx_exists(innodb_hton_ptr, thd);
+
+	if (trx->isolation_level == TRX_ISO_SERIALIZABLE) {
 		/* In the SERIALIZABLE mode we add LOCK IN SHARE MODE to every
 		plain SELECT if AUTOCOMMIT is not on. */
 
 		return((my_bool)FALSE);
 	}
 
-	trx = check_trx_exists(legacy_innodb_hton, thd);
 	if (trx->has_search_latch) {
 		ut_print_timestamp(stderr);
 		sql_print_error("The calling thread is holding the adaptive "
@@ -1182,7 +1138,7 @@
 
 	innobase_release_stat_resources(trx);
 
-	if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
+	if (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
 
 		is_autocommit = TRUE;
 	} else {
@@ -1227,7 +1183,7 @@
 
 	if (trx->active_trans == 0) {
 
-		innobase_register_trx_and_stmt(legacy_innodb_hton, thd);
+		innobase_register_trx_and_stmt(innodb_hton_ptr, thd);
 		trx->active_trans = 1;
 	}
 
@@ -1367,7 +1323,7 @@
 	one. Update the trx pointers in the prebuilt struct. Normally
 	this operation is done in external_lock. */
 
-	update_thd(current_thd);
+	update_thd(ha_thd());
 
 	/* Initialize the prebuilt struct much like it would be inited in
 	external_lock */
@@ -1386,7 +1342,7 @@
 
 	if (prebuilt->trx->active_trans == 0) {
 
-		innobase_register_trx_and_stmt(ht, current_thd);
+		innobase_register_trx_and_stmt(ht, ha_thd());
 
 		prebuilt->trx->active_trans = 1;
 	}
@@ -1430,9 +1386,9 @@
 
 	DBUG_ENTER("innobase_init");
         handlerton *innobase_hton= (handlerton *)p;
-        legacy_innodb_hton= innobase_hton;
+        innodb_hton_ptr= innobase_hton;
 
-        innobase_hton->state=have_innodb;
+        innobase_hton->state= SHOW_OPTION_YES;
         innobase_hton->db_type= DB_TYPE_INNODB;
         innobase_hton->savepoint_offset=sizeof(trx_named_savept_t);
         innobase_hton->close_connection=innobase_close_connection;
@@ -1457,9 +1413,6 @@
         innobase_hton->flags=HTON_NO_FLAGS;
         innobase_hton->release_temporary_latches=innobase_release_temporary_latches;
 
-	 if (have_innodb != SHOW_OPTION_YES)
-	   DBUG_RETURN(0); // nothing else to do
-
 	ut_a(DATA_MYSQL_TRUE_VARCHAR == (ulint)MYSQL_TYPE_VARCHAR);
 
 #ifdef UNIV_DEBUG
@@ -1641,8 +1594,10 @@
 	srv_use_doublewrite_buf = (ibool) innobase_use_doublewrite;
 	srv_use_checksums = (ibool) innobase_use_checksums;
 
-	os_use_large_pages = (ibool) innobase_use_large_pages;
-	os_large_page_size = (ulint) innobase_large_page_size;
+#ifdef HAVE_LARGE_PAGES
+        if ((os_use_large_pages = (ibool) my_use_large_pages))
+		os_large_page_size = (ulint) opt_large_page_size;
+#endif
 
 	row_rollback_on_timeout = (ibool) innobase_rollback_on_timeout;
 
@@ -1701,7 +1656,6 @@
 
 	DBUG_RETURN(FALSE);
 error:
-	have_innodb= SHOW_OPTION_DISABLED;	// If we couldn't use handler
 	DBUG_RETURN(TRUE);
 }
 
@@ -1844,7 +1798,7 @@
 	trx = check_trx_exists(hton, thd);
 
 	/* Update the info whether we should skip XA steps that eat CPU time */
-	trx->support_xa = (ibool)(thd->variables.innodb_support_xa);
+	trx->support_xa = THDVAR(thd, support_xa);
 
 	/* Since we will reserve the kernel mutex, we have to release
 	the search system latch first to obey the latching order. */
@@ -1875,7 +1829,7 @@
 			" trx->conc_state != TRX_NOT_STARTED");
 	}
 	if (all
-		|| (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))) {
+		|| (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
 
 		/* We were instructed to commit the whole transaction, or
 		this is an SQL statement end and autocommit is on */
@@ -2037,7 +1991,7 @@
 {
 	trx_t*	trx;
 
-	trx = thd_to_trx(thd, hton);
+	trx = thd_to_trx(thd);
 
 	if (trx && trx->active_trans) {
 
@@ -2077,7 +2031,7 @@
 	trx = check_trx_exists(hton, thd);
 
 	/* Update the info whether we should skip XA steps that eat CPU time */
-	trx->support_xa = (ibool)(thd->variables.innodb_support_xa);
+	trx->support_xa = THDVAR(thd, support_xa);
 
 	/* Release a possible FIFO ticket and search latch. Since we will
 	reserve the kernel mutex, we have to release the search system latch
@@ -2094,7 +2048,7 @@
 	}
 
 	if (all
-		|| (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))) {
+		|| !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
 
 		error = trx_rollback_for_mysql(trx);
 		trx->active_trans = 0;
@@ -2226,7 +2180,7 @@
 	  (unless we are in sub-statement), so SQL layer ensures that
 	  this method is never called in such situation.
 	*/
-	DBUG_ASSERT(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN) ||
+	DBUG_ASSERT(thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN) ||
 		thd->in_sub_stmt);
 
 	trx = check_trx_exists(hton, thd);
@@ -2262,7 +2216,7 @@
 {
 	trx_t*	trx;
 
-	trx = thd_to_trx(thd, hton);
+	trx = thd_to_trx(thd);
 
 	ut_a(trx);
 
@@ -2397,7 +2351,7 @@
 	UT_NOT_USED(mode);
 	UT_NOT_USED(test_if_locked);
 
-	thd = current_thd;
+	thd = ha_thd();
 	normalize_table_name(norm_name, name);
 
 	user_thd = NULL;
@@ -3349,8 +3303,8 @@
 	longlong	auto_inc;
 	longlong	dummy;
 	ibool		auto_inc_used= FALSE;
-	THD*		thd = current_thd;
-	trx_t*		trx = thd_to_trx(thd, ht);
+        THD *thd=       ha_thd();
+	trx_t*		trx = thd_to_trx(thd);
 
 	DBUG_ENTER("ha_innobase::write_row");
 
@@ -3374,10 +3328,10 @@
 	if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
 		table->timestamp_field->set_time();
 
-	if ((user_thd->lex->sql_command == SQLCOM_ALTER_TABLE
-			|| user_thd->lex->sql_command == SQLCOM_OPTIMIZE
-			|| user_thd->lex->sql_command == SQLCOM_CREATE_INDEX
-			|| user_thd->lex->sql_command == SQLCOM_DROP_INDEX)
+	if ((thd_sql_command(thd) == SQLCOM_ALTER_TABLE
+			|| thd_sql_command(thd) == SQLCOM_OPTIMIZE
+			|| thd_sql_command(thd) == SQLCOM_CREATE_INDEX
+			|| thd_sql_command(thd) == SQLCOM_DROP_INDEX)
 		&& num_write_row >= 10000) {
 		/* ALTER TABLE is COMMITted at every 10000 copied rows.
 		The IX table lock for the original table has to be re-issued.
@@ -3529,12 +3483,14 @@
         performing those statements. */
 
         if (error == DB_DUPLICATE_KEY && auto_inc_used
-            && (user_thd->lex->sql_command == SQLCOM_REPLACE
-                || user_thd->lex->sql_command == SQLCOM_REPLACE_SELECT
-                || (user_thd->lex->sql_command == SQLCOM_INSERT
-                    && user_thd->lex->duplicates == DUP_UPDATE)
-                || (user_thd->lex->sql_command == SQLCOM_LOAD
-                    && user_thd->lex->duplicates == DUP_REPLACE))) {
+            && (thd_sql_command(user_thd) == SQLCOM_REPLACE
+                || thd_sql_command(user_thd) == SQLCOM_REPLACE_SELECT
+                || (thd_sql_command(user_thd) == SQLCOM_INSERT
+                    && prebuilt->trx->allow_duplicates
+		    && !prebuilt->trx->replace_duplicates)
+                || (thd_sql_command(user_thd) == SQLCOM_LOAD
+                    && prebuilt->trx->allow_duplicates
+		    && prebuilt->trx->replace_duplicates))) {
 
                 auto_inc = table->next_number_field->val_int();
 
@@ -3722,7 +3678,7 @@
 {
 	upd_t*		uvect;
 	int		error = 0;
-	trx_t*		trx = thd_to_trx(current_thd, ht);
+	trx_t*		trx = thd_to_trx(ha_thd());
 
 	DBUG_ENTER("ha_innobase::update_row");
 
@@ -3775,7 +3731,7 @@
 	const mysql_byte* record)	/* in: a row in MySQL format */
 {
 	int		error = 0;
-	trx_t*		trx = thd_to_trx(current_thd, ht);
+	trx_t*		trx = thd_to_trx(ha_thd());
 
 	DBUG_ENTER("ha_innobase::delete_row");
 
@@ -3854,7 +3810,7 @@
 ha_innobase::try_semi_consistent_read(bool yes)
 /*===========================================*/
 {
-	ut_a(prebuilt->trx == thd_to_trx(current_thd, ht));
+	ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
 
 	/* Row read type is set to semi consistent read if this was
 	requested by the MySQL and either innodb_locks_unsafe_for_binlog
@@ -4019,7 +3975,7 @@
 
 	DBUG_ENTER("index_read");
 
-	ut_a(prebuilt->trx == thd_to_trx(current_thd, ht));
+	ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
 
 	ha_statistic_increment(&SSV::ha_read_key_count);
 
@@ -4119,11 +4075,11 @@
 			InnoDB */
 {
 	KEY*		key=0;
-	ha_statistic_increment(&SSV::ha_read_key_count);
 	DBUG_ENTER("change_active_index");
+	ha_statistic_increment(&SSV::ha_read_key_count);
 
-	ut_ad(user_thd == current_thd);
-	ut_a(prebuilt->trx == thd_to_trx(user_thd, ht));
+	ut_ad(user_thd == ha_thd());
+	ut_a(prebuilt->trx == thd_to_trx(user_thd));
 
 	active_index = keynr;
 
@@ -4211,7 +4167,7 @@
 
 	DBUG_ENTER("general_fetch");
 
-	ut_a(prebuilt->trx == thd_to_trx(current_thd, ht));
+	ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
 
 	innodb_srv_conc_enter_innodb(prebuilt->trx);
 
@@ -4436,7 +4392,7 @@
 
 	ha_statistic_increment(&SSV::ha_read_rnd_count);
 
-	ut_a(prebuilt->trx == thd_to_trx(current_thd, ht));
+	ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
 
 	if (prebuilt->clust_index_was_generated) {
 		/* No primary key was defined for the table and we
@@ -4484,7 +4440,7 @@
 {
 	uint		len;
 
-	ut_a(prebuilt->trx == thd_to_trx(current_thd, ht));
+	ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
 
 	if (prebuilt->clust_index_was_generated) {
 		/* No primary key was defined for the table and we
@@ -4807,7 +4763,7 @@
 	uint		i;
 	char		name2[FN_REFLEN];
 	char		norm_name[FN_REFLEN];
-	THD		*thd= current_thd;
+	THD		*thd= ha_thd();
 	ib_longlong	auto_inc_value;
 	ulint		flags;
 
@@ -4837,11 +4793,11 @@
 	trx->mysql_thd = thd;
 	trx->mysql_query_str = &((*thd).query);
 
-	if (thd->options & OPTION_NO_FOREIGN_KEY_CHECKS) {
+	if (thd_test_options(thd, OPTION_NO_FOREIGN_KEY_CHECKS)) {
 		trx->check_foreigns = FALSE;
 	}
 
-	if (thd->options & OPTION_RELAXED_UNIQUE_CHECKS) {
+	if (thd_test_options(thd, OPTION_RELAXED_UNIQUE_CHECKS)) {
 		trx->check_unique_secondary = FALSE;
 	}
 
@@ -4997,7 +4953,7 @@
 
 	ut_a(prebuilt->trx);
 	ut_a(prebuilt->trx->magic_n == TRX_MAGIC_N);
-	ut_a(prebuilt->trx == thd_to_trx(current_thd, ht));
+	ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
 
 	dict_table = prebuilt->table;
 	trx = prebuilt->trx;
@@ -5022,33 +4978,33 @@
 				/* out: error number */
 {
 	int		error;
-	THD*		thd		= current_thd;
+	THD*		thd		= ha_thd();
 
 	DBUG_ENTER("ha_innobase::delete_all_rows");
 
-	if (thd->lex->sql_command != SQLCOM_TRUNCATE) {
-	fallback:
-		/* We only handle TRUNCATE TABLE t as a special case.
-		DELETE FROM t will have to use ha_innobase::delete_row(). */
-		DBUG_RETURN(my_errno=HA_ERR_WRONG_COMMAND);
-	}
-
 	/* Get the transaction associated with the current thd, or create one
 	if not yet created, and update prebuilt->trx */
 
 	update_thd(thd);
 
-	/* Truncate the table in InnoDB */
+	if (thd_sql_command(thd) == SQLCOM_TRUNCATE) {
+		/* Truncate the table in InnoDB */
 
-	error = row_truncate_table_for_mysql(prebuilt->table, prebuilt->trx);
-	if (error == DB_ERROR) {
-		/* Cannot truncate; resort to ha_innobase::delete_row() */
-		goto fallback;
-	}
+		error = row_truncate_table_for_mysql(prebuilt->table, prebuilt->trx);
+		if (error == DB_ERROR) {
+			/* Cannot truncate; resort to ha_innobase::delete_row() */
+			goto fallback;
+		}
 
-	error = convert_error_code_to_mysql(error, NULL);
+		error = convert_error_code_to_mysql(error, NULL);
 
-	DBUG_RETURN(error);
+		DBUG_RETURN(error);
+	}
+
+fallback:
+	/* We only handle TRUNCATE TABLE t as a special case.
+	DELETE FROM t will have to use ha_innobase::delete_row(). */
+	DBUG_RETURN(my_errno=HA_ERR_WRONG_COMMAND);
 }
 
 /*********************************************************************
@@ -5068,7 +5024,7 @@
 	int	error;
 	trx_t*	parent_trx;
 	trx_t*	trx;
-	THD	*thd= current_thd;
+	THD	*thd= ha_thd();
 	char	norm_name[1000];
 
 	DBUG_ENTER("ha_innobase::delete_table");
@@ -5091,75 +5047,75 @@
 
 	trx = trx_allocate_for_mysql();
 
-	trx->mysql_thd = current_thd;
-	trx->mysql_query_str = &((*current_thd).query);
+	trx->mysql_thd = ha_thd();
+        trx->mysql_query_str = &(ha_thd()->query);
 
-	if (thd->options & OPTION_NO_FOREIGN_KEY_CHECKS) {
-		trx->check_foreigns = FALSE;
-	}
+        if (thd_test_options(thd, OPTION_NO_FOREIGN_KEY_CHECKS)) {
+          trx->check_foreigns = FALSE;
+        }
 
-	if (thd->options & OPTION_RELAXED_UNIQUE_CHECKS) {
-		trx->check_unique_secondary = FALSE;
-	}
+        if (thd_test_options(thd, OPTION_RELAXED_UNIQUE_CHECKS)) {
+          trx->check_unique_secondary = FALSE;
+        }
 
-	name_len = strlen(name);
+        name_len = strlen(name);
 
-	assert(name_len < 1000);
+        assert(name_len < 1000);
 
-	/* Strangely, MySQL passes the table name without the '.frm'
-	extension, in contrast to ::create */
+        /* Strangely, MySQL passes the table name without the '.frm'
+           extension, in contrast to ::create */
 
-	normalize_table_name(norm_name, name);
+        normalize_table_name(norm_name, name);
 
-	/* Drop the table in InnoDB */
+        /* Drop the table in InnoDB */
 
-	error = row_drop_table_for_mysql(norm_name, trx,
-		thd->lex->sql_command == SQLCOM_DROP_DB);
+        error = row_drop_table_for_mysql(norm_name, trx,
+                                         thd_sql_command(thd) == SQLCOM_DROP_DB);
 
-	/* Flush the log to reduce probability that the .frm files and
-	the InnoDB data dictionary get out-of-sync if the user runs
-	with innodb_flush_log_at_trx_commit = 0 */
+        /* Flush the log to reduce probability that the .frm files and
+           the InnoDB data dictionary get out-of-sync if the user runs
+           with innodb_flush_log_at_trx_commit = 0 */
 
-	log_buffer_flush_to_disk();
+        log_buffer_flush_to_disk();
 
-	/* Tell the InnoDB server that there might be work for
-	utility threads: */
+        /* Tell the InnoDB server that there might be work for
+           utility threads: */
 
-	srv_active_wake_master_thread();
+        srv_active_wake_master_thread();
 
-	innobase_commit_low(trx);
+        innobase_commit_low(trx);
 
-	trx_free_for_mysql(trx);
+        trx_free_for_mysql(trx);
 
-	error = convert_error_code_to_mysql(error, NULL);
+        error = convert_error_code_to_mysql(error, NULL);
 
-	DBUG_RETURN(error);
+        DBUG_RETURN(error);
 }
 
 /*********************************************************************
-Removes all tables in the named database inside InnoDB. */
+  Removes all tables in the named database inside InnoDB. */
 static
 void
 innobase_drop_database(
-/*===================*/
-			/* out: error number */
-        handlerton *hton, /* in: handlerton of Innodb */
-	char*	path)	/* in: database path; inside InnoDB the name
-			of the last directory in the path is used as
-			the database name: for example, in 'mysql/data/test'
-			the database name is 'test' */
-{
-	ulint	len		= 0;
-	trx_t*	parent_trx;
-	trx_t*	trx;
-	char*	ptr;
-	int	error;
-	char*	namebuf;
+                       /*===================*/
+                       /* out: error number */
+                       handlerton *hton, /* in: handlerton of Innodb */
+                       char*	path)	/* in: database path; inside InnoDB the name
+                                           of the last directory in the path is used as
+                                           the database name: for example, in 'mysql/data/test'
+                                           the database name is 'test' */
+{
+  ulint	len		= 0;
+  trx_t*	parent_trx;
+  trx_t*	trx;
+  char*	ptr;
+  int	error;
+  char*	namebuf;
 
-	/* Get the transaction associated with the current thd, or create one
-	if not yet created */
+  /* Get the transaction associated with the current thd, or create one
+     if not yet created */
 
-	parent_trx = check_trx_exists(hton, current_thd);
+  parent_trx = check_trx_exists(hton, current_thd);
 
 	/* In case MySQL calls this in the middle of a SELECT query, release
 	possible adaptive hash latch to avoid deadlocks of threads */
@@ -5186,7 +5142,7 @@
 	trx->mysql_thd = current_thd;
 	trx->mysql_query_str = &((*current_thd).query);
 
-	if (current_thd->options & OPTION_NO_FOREIGN_KEY_CHECKS) {
+	if (thd_test_options(current_thd, OPTION_NO_FOREIGN_KEY_CHECKS)) {
 		trx->check_foreigns = FALSE;
 	}
 
@@ -5238,7 +5194,7 @@
 	/* Get the transaction associated with the current thd, or create one
 	if not yet created */
 
-	parent_trx = check_trx_exists(ht, current_thd);
+	parent_trx = check_trx_exists(ht, ha_thd());
 
 	/* In case MySQL calls this in the middle of a SELECT query, release
 	possible adaptive hash latch to avoid deadlocks of threads */
@@ -5252,10 +5208,10 @@
 	}
 
 	trx = trx_allocate_for_mysql();
-	trx->mysql_thd = current_thd;
-	trx->mysql_query_str = &((*current_thd).query);
+	trx->mysql_thd = ha_thd();
+	trx->mysql_query_str = &((*ha_thd()).query);
 
-	if (current_thd->options & OPTION_NO_FOREIGN_KEY_CHECKS) {
+	if (thd_test_options(ha_thd(), OPTION_NO_FOREIGN_KEY_CHECKS)) {
 		trx->check_foreigns = FALSE;
 	}
 
@@ -5323,7 +5279,7 @@
 
 	DBUG_ENTER("records_in_range");
 
-	ut_a(prebuilt->trx == thd_to_trx(current_thd, ht));
+	ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
 
 	prebuilt->trx->op_info = (char*)"estimating records in index range";
 
@@ -5407,7 +5363,7 @@
 	external_lock(). To be safe, update the thd of the current table
 	handle. */
 
-	update_thd(current_thd);
+	update_thd(ha_thd());
 
 	prebuilt->trx->op_info = (char*)
 				 "calculating upper bound for table rows";
@@ -5524,7 +5480,7 @@
 	external_lock(). To be safe, update the thd of the current table
 	handle. */
 
-	update_thd(current_thd);
+	update_thd(ha_thd());
 
 	/* In case MySQL calls this in the middle of a SELECT query, release
 	possible adaptive hash latch to avoid deadlocks of threads */
@@ -5755,7 +5711,7 @@
 	ulint		ret;
 
 	ut_a(prebuilt->trx && prebuilt->trx->magic_n == TRX_MAGIC_N);
-	ut_a(prebuilt->trx == thd_to_trx(current_thd, ht));
+	ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
 
 	if (prebuilt->mysql_template == NULL) {
 		/* Build the template; we will use a dummy template
@@ -5797,7 +5753,7 @@
 		return((char*)comment); /* string too long */
 	}
 
-	update_thd(current_thd);
+	update_thd(ha_thd());
 
 	prebuilt->trx->op_info = (char*)"returning table comment";
 
@@ -5868,7 +5824,7 @@
 	external_lock(). To be safe, update the thd of the current table
 	handle. */
 
-	update_thd(current_thd);
+	update_thd(ha_thd());
 
 	prebuilt->trx->op_info = (char*)"getting info on foreign keys";
 
@@ -5917,7 +5873,7 @@
 
   DBUG_ENTER("get_foreign_key_list");
   ut_a(prebuilt != NULL);
-  update_thd(current_thd);
+  update_thd(ha_thd());
   prebuilt->trx->op_info = (char*)"getting list of foreign keys";
   trx_search_latch_release_if_reserved(prebuilt->trx);
   mutex_enter_noninline(&(dict_sys->mutex));
@@ -6052,7 +6008,7 @@
 
 	DBUG_ENTER("ha_innobase::can_switch_engines");
 
-	ut_a(prebuilt->trx == thd_to_trx(current_thd, ht));
+	ut_a(prebuilt->trx == thd_to_trx(ha_thd()));
 
 	prebuilt->trx->op_info =
 			"determining if there are foreign key constraints";
@@ -6133,6 +6089,19 @@
 		case HA_EXTRA_KEYREAD_PRESERVE_FIELDS:
 			prebuilt->keep_other_fields_on_keyread = 1;
 			break;
+		case HA_EXTRA_IGNORE_DUP_KEY:
+			prebuilt->trx->allow_duplicates= TRUE;
+			break;
+		case HA_EXTRA_WRITE_CAN_REPLACE:
+			prebuilt->trx->replace_duplicates= TRUE;
+			break;
+		case HA_EXTRA_WRITE_CANNOT_REPLACE:
+			prebuilt->trx->replace_duplicates= FALSE;
+			break;
+		case HA_EXTRA_NO_IGNORE_DUP_KEY:
+			prebuilt->trx->allow_duplicates= FALSE;
+			prebuilt->trx->replace_duplicates= FALSE;
+			break;
 		default:/* Do nothing */
 			;
 	}
@@ -6199,7 +6168,7 @@
 		prebuilt->select_lock_type = LOCK_X;
 	} else {
 		if (trx->isolation_level != TRX_ISO_SERIALIZABLE
-			&& thd->lex->sql_command == SQLCOM_SELECT
+			&& thd_sql_command(thd) == SQLCOM_SELECT
 			&& lock_type == TL_READ) {
 
 			/* For other than temporary tables, we obtain
@@ -6311,8 +6280,8 @@
 
 		if (trx->isolation_level == TRX_ISO_SERIALIZABLE
 			&& prebuilt->select_lock_type == LOCK_NONE
-			&& (thd->options
-				& (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
+			&& thd_test_options(thd,
+				OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
 
 			/* To get serializable execution, we let InnoDB
 			conceptually add 'LOCK IN SHARE MODE' to all SELECTs
@@ -6339,10 +6308,10 @@
 
 		if (prebuilt->select_lock_type != LOCK_NONE) {
 
-			if (thd->lex->sql_command == SQLCOM_LOCK_TABLES
-			    && thd->variables.innodb_table_locks
-			    && (thd->options & OPTION_NOT_AUTOCOMMIT)
-			    && thd_in_lock_tables(thd)) {
+			if (thd_in_lock_tables(thd) &&
+				thd_sql_command(thd) == SQLCOM_LOCK_TABLES &&
+				THDVAR(thd, table_locks) &&
+				thd_test_options(thd, OPTION_NOT_AUTOCOMMIT)) {
 
 				ulint	error = row_lock_table_for_mysql(
 					prebuilt, NULL, 0);
@@ -6379,7 +6348,7 @@
 
 		innobase_release_stat_resources(trx);
 
-		if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
+		if (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
 			if (trx->active_trans != 0) {
 				innobase_commit(ht, thd, TRUE);
 			}
@@ -6421,7 +6390,7 @@
 	update_thd(thd);
 
 	if (prebuilt->table->ibd_file_missing
-	    && !thd_tablespace_op(current_thd)) {
+	    && !thd_tablespace_op(ha_thd())) {
 		ut_print_timestamp(stderr);
 		fprintf(stderr, "  InnoDB error:\n"
 "MySQL is trying to use a table handle but the .ibd file for\n"
@@ -6466,7 +6435,7 @@
 		trx->active_trans = 1;
 	}
 
-	if (thd->variables.innodb_table_locks && thd_in_lock_tables(thd)) {
+	if (thd_in_lock_tables(thd) && THDVAR(thd, table_locks)) {
 		ulint	error = DB_SUCCESS;
 
 		error = row_lock_table_for_mysql(prebuilt, NULL, 0);
@@ -6476,7 +6445,7 @@
 			DBUG_RETURN((int) error);
 		}
 
-		if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
+		if (thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
 
 			/* Store the current undo_no of the transaction
 			so that we know where to roll back if we have
@@ -6522,10 +6491,6 @@
 
 	DBUG_ENTER("innodb_show_status");
 
-	if (have_innodb != SHOW_OPTION_YES) {
-		DBUG_RETURN(FALSE);
-	}
-
 	trx = check_trx_exists(hton, thd);
 
 	innobase_release_stat_resources(trx);
@@ -6816,8 +6781,7 @@
 	if (lock_type != TL_IGNORE
 	&& trx->n_mysql_tables_in_use == 0) {
 		trx->isolation_level = innobase_map_isolation_level(
-						(enum_tx_isolation)
-						thd->variables.tx_isolation);
+                                    (enum_tx_isolation)thd_tx_isolation(thd));
 
 		if (trx->isolation_level <= TRX_ISO_READ_COMMITTED
 		    && trx->global_read_view) {
@@ -6827,12 +6791,13 @@
 
 			read_view_close_for_mysql(trx);
 		}
-
 	}
 
+	DBUG_ASSERT(thd == current_thd);
 	const bool in_lock_tables = thd_in_lock_tables(thd);
+	const uint sql_command = thd_sql_command(thd);
 
-	if (thd->lex->sql_command == SQLCOM_DROP_TABLE) {
+	if (sql_command == SQLCOM_DROP_TABLE) {
 
 		/* MySQL calls this function in DROP TABLE though this table
 		handle may belong to another thd that is running a query. Let
@@ -6842,7 +6807,7 @@
 		(lock_type == TL_READ_HIGH_PRIORITY && in_lock_tables) ||
 		lock_type == TL_READ_WITH_SHARED_LOCKS ||
 		lock_type == TL_READ_NO_INSERT ||
-		(thd->lex->sql_command != SQLCOM_SELECT
+		(sql_command != SQLCOM_SELECT
 			&& lock_type != TL_IGNORE)) {
 
 		/* The OR cases above are in this order:
@@ -6871,9 +6836,9 @@
 			|| isolation_level == TRX_ISO_READ_COMMITTED)
 		&& isolation_level != TRX_ISO_SERIALIZABLE
 		&& (lock_type == TL_READ || lock_type == TL_READ_NO_INSERT)
-		&& (thd->lex->sql_command == SQLCOM_INSERT_SELECT
-			|| thd->lex->sql_command == SQLCOM_UPDATE
-			|| thd->lex->sql_command == SQLCOM_CREATE_TABLE)) {
+		&& (sql_command == SQLCOM_INSERT_SELECT
+			|| sql_command == SQLCOM_UPDATE
+			|| sql_command == SQLCOM_CREATE_TABLE)) {
 
 			/* If we either have innobase_locks_unsafe_for_binlog
 			option set or this session is using READ COMMITTED
@@ -6886,7 +6851,7 @@
 
 			prebuilt->select_lock_type = LOCK_NONE;
 			prebuilt->stored_select_lock_type = LOCK_NONE;
-		} else if (thd->lex->sql_command == SQLCOM_CHECKSUM) {
+		} else if (sql_command == SQLCOM_CHECKSUM) {
 			/* Use consistent read for checksum table */
 
 			prebuilt->select_lock_type = LOCK_NONE;
@@ -6916,7 +6881,7 @@
 		(if it does not use a consistent read). */
 
 		if (lock_type == TL_READ
-		    && thd->lex->sql_command == SQLCOM_LOCK_TABLES) {
+		    && sql_command == SQLCOM_LOCK_TABLES) {
 			/* We come here if MySQL is processing LOCK TABLES
 			... READ LOCAL. MyISAM under that table lock type
 			reads the table as it was at the time the lock was
@@ -6944,22 +6909,22 @@
 		if ((lock_type >= TL_WRITE_CONCURRENT_INSERT
 		&& lock_type <= TL_WRITE)
 		&& !(in_lock_tables
-			&& thd->lex->sql_command == SQLCOM_LOCK_TABLES)
+			&& sql_command == SQLCOM_LOCK_TABLES)
 		&& !thd_tablespace_op(thd)
-		&& thd->lex->sql_command != SQLCOM_TRUNCATE
-		&& thd->lex->sql_command != SQLCOM_OPTIMIZE
+		&& sql_command != SQLCOM_TRUNCATE
+		&& sql_command != SQLCOM_OPTIMIZE
 
 #ifdef __WIN__
-                /* For alter table on win32 for succesful operation
-                completion it is used TL_WRITE(=10) lock instead of
-                TL_WRITE_ALLOW_READ(=6), however here in innodb handler
-                TL_WRITE is lifted to TL_WRITE_ALLOW_WRITE, which causes
-                race condition when several clients do alter table
-                simultaneously (bug #17264). This fix avoids the problem. */
-                && thd->lex->sql_command != SQLCOM_ALTER_TABLE
+		/* For alter table on win32 for succesful operation
+		completion it is used TL_WRITE(=10) lock instead of
+		TL_WRITE_ALLOW_READ(=6), however here in innodb handler
+		TL_WRITE is lifted to TL_WRITE_ALLOW_WRITE, which causes
+		race condition when several clients do alter table
+		simultaneously (bug #17264). This fix avoids the problem. */
+		&& sql_command != SQLCOM_ALTER_TABLE
 #endif
 
-		&& thd->lex->sql_command != SQLCOM_CREATE_TABLE) {
+		&& sql_command != SQLCOM_CREATE_TABLE) {
 
 			lock_type = TL_WRITE_ALLOW_WRITE;
 		}
@@ -6972,10 +6937,10 @@
 
 		We especially allow concurrent inserts if MySQL is at the
 		start of a stored procedure call (SQLCOM_CALL)
-		(MySQL does have in_lock_tables TRUE there). */
+		(MySQL does have thd_in_lock_tables() TRUE there). */
 
 		if (lock_type == TL_READ_NO_INSERT
-		    && thd->lex->sql_command != SQLCOM_LOCK_TABLES) {
+		    && sql_command != SQLCOM_LOCK_TABLES) {
 
 			lock_type = TL_READ;
 		}
@@ -7010,7 +6975,7 @@
 	ut_a(prebuilt->table);
 
 	/* Prepare prebuilt->trx in the table handle */
-	update_thd(current_thd);
+	update_thd(ha_thd());
 
 	if (prebuilt->trx->conc_state == TRX_NOT_STARTED) {
 		trx_was_not_started = TRUE;
@@ -7153,7 +7118,7 @@
 	int		error;
 
 	/* Prepare prebuilt->trx in the table handle */
-	update_thd(current_thd);
+	update_thd(ha_thd());
 
 	error = innobase_read_and_init_auto_inc(&nr);
 
@@ -7182,7 +7147,7 @@
 
 	int	error;
 
-	update_thd(current_thd);
+	update_thd(ha_thd());
 
 	error = row_lock_table_autoinc_for_mysql(prebuilt);
 
@@ -7201,7 +7166,7 @@
 bool
 ha_innobase::get_error_message(int error, String *buf)
 {
-	trx_t*	trx = check_trx_exists(ht, current_thd);
+	trx_t*	trx = check_trx_exists(ht, ha_thd());
 
 	buf->copy(trx->detailed_error, strlen(trx->detailed_error),
 		system_charset_info);
@@ -7417,6 +7382,7 @@
 /*==========================*/
 {
 	THD*	thd = current_thd;
+	trx_t*	trx;
 
 	if (!thd) {
 		/* InnoDB's internal threads may run InnoDB stored procedures
@@ -7426,17 +7392,9 @@
 		return(FALSE);
 	}
 
-	switch (thd->lex->sql_command) {
-	case SQLCOM_REPLACE:
-	case SQLCOM_REPLACE_SELECT:
-		return(TRUE);
-	case SQLCOM_LOAD:
-		return(thd->lex->duplicates == DUP_REPLACE);
-	case SQLCOM_INSERT:
-		return(thd->lex->duplicates == DUP_UPDATE);
-	default:
-		return(FALSE);
-	}
+	trx = check_trx_exists(innodb_hton_ptr, thd);
+
+	return(trx->allow_duplicates);
 }
 
 /***********************************************************************
@@ -7455,8 +7413,8 @@
 	int error = 0;
 	trx_t* trx = check_trx_exists(hton, thd);
 
-	if (thd->lex->sql_command != SQLCOM_XA_PREPARE &&
-	    (all || !(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))))
+	if (thd_sql_command(thd) != SQLCOM_XA_PREPARE &&
+	    (all || !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
 	{
 
 		/* For ibbackup to work the order of transactions in binlog
@@ -7482,7 +7440,7 @@
 		trx->active_trans = 2;
 	}
 
-	if (!thd->variables.innodb_support_xa) {
+	if (!THDVAR(thd, support_xa)) {
 
 		return(0);
 	}
@@ -7502,7 +7460,7 @@
 	}
 
 	if (all
-		|| (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))) {
+		|| (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
 
 		/* We were instructed to prepare the whole transaction, or
 		this is an SQL statement end and autocommit is on */
@@ -7694,6 +7652,221 @@
 static struct st_mysql_storage_engine innobase_storage_engine=
 { MYSQL_HANDLERTON_INTERFACE_VERSION };
 
+/* plugin options */
+static MYSQL_SYSVAR_BOOL(checksums, innobase_use_checksums,
+  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
+  "Enable InnoDB checksums validation (enabled by default). "
+  "Disable with --skip-innodb-checksums.",
+  NULL, NULL, TRUE);
+
+static MYSQL_SYSVAR_STR(data_home_dir, innobase_data_home_dir,
+  PLUGIN_VAR_READONLY,
+  "The common part for InnoDB table spaces.",
+  NULL, NULL, NULL);
+
+static MYSQL_SYSVAR_BOOL(doublewrite, innobase_use_doublewrite,
+  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
+  "Enable InnoDB doublewrite buffer (enabled by default). "
+  "Disable with --skip-innodb-doublewrite.",
+  NULL, NULL, TRUE);
+
+static MYSQL_SYSVAR_ULONG(fast_shutdown, innobase_fast_shutdown,
+  PLUGIN_VAR_OPCMDARG,
+  "Speeds up the shutdown process of the InnoDB storage engine. Possible "
+  "values are 0, 1 (faster)"
+  /*
+    NetWare can't close unclosed files, can't automatically kill remaining
+    threads, etc, so on this OS we disable the crash-like InnoDB shutdown.
+  */
+  IF_NETWARE("", " or 2 (fastest - crash-like)")
+  ".",
+  NULL, NULL, 1, 0, IF_NETWARE(1,2), 0);
+
+static MYSQL_SYSVAR_BOOL(file_per_table, innobase_file_per_table,
+  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
+  "Stores each InnoDB table to an .ibd file in the database dir.",
+  NULL, NULL, FALSE);
+
+static MYSQL_SYSVAR_ULONG(flush_log_at_trx_commit, srv_flush_log_at_trx_commit,
+  PLUGIN_VAR_OPCMDARG,
+ "Set to 0 (write and flush once per second), 1 (write and flush at each commit)"
+ " or 2 (write at commit, flush once per second).",
+  NULL, NULL, 1, 0, 2, 0);
+
+static MYSQL_SYSVAR_STR(flush_method, innobase_unix_file_flush_method,
+  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
+  "With which method to flush data.", NULL, NULL, NULL);
+
+static MYSQL_SYSVAR_BOOL(locks_unsafe_for_binlog, innobase_locks_unsafe_for_binlog,
+  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
+  "Force InnoDB to not use next-key locking, to use only row-level locking.",
+  NULL, NULL, FALSE);
+
+static MYSQL_SYSVAR_STR(log_arch_dir, innobase_log_arch_dir,
+  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
+  "Where full logs should be archived.", NULL, NULL, NULL);
+
+#ifdef UNIV_LOG_ARCHIVE
+static MYSQL_SYSVAR_BOOL(log_archive, innobase_log_archive,
+  PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
+  "Set to 1 if you want to have logs archived.", NULL, NULL, FALSE);
+#endif /* UNIV_LOG_ARCHIVE */
+
+static MYSQL_SYSVAR_STR(log_group_home_dir, innobase_log_group_home_dir,
+  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
+  "Path to InnoDB log files.", NULL, NULL, NULL);
+
+static MYSQL_SYSVAR_ULONG(max_dirty_pages_pct, srv_max_buf_pool_modified_pct,
+  PLUGIN_VAR_RQCMDARG,
+  "Percentage of dirty pages allowed in bufferpool.",
+  NULL, NULL, 90, 0, 100, 0);
+
+static MYSQL_SYSVAR_ULONG(max_purge_lag, srv_max_purge_lag,
+  PLUGIN_VAR_RQCMDARG,
+  "Desired maximum length of the purge queue (0 = no limit)",
+  NULL, NULL, 0, 0, ~0L, 0);
+
+static MYSQL_SYSVAR_BOOL(rollback_on_timeout, innobase_rollback_on_timeout,
+  PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
+  "Roll back the complete transaction on lock wait timeout, for 4.x compatibility (disabled by default)",
+  NULL, NULL, FALSE);
+
+static MYSQL_SYSVAR_BOOL(status_file, innobase_create_status_file,
+  PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_NOSYSVAR,
+  "Enable SHOW INNODB STATUS output in the innodb_status.<pid> file",
+  NULL, NULL, FALSE);
+
+static MYSQL_SYSVAR_BOOL(stats_on_metadata, innobase_stats_on_metadata,
+  PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_NOSYSVAR,
+  "Enable statistics gathering for metadata commands such as SHOW TABLE STATUS (on by default)",
+  NULL, NULL, TRUE);
+
+static MYSQL_SYSVAR_LONG(additional_mem_pool_size, innobase_additional_mem_pool_size,
+  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
+  "Size of a memory pool InnoDB uses to store data dictionary information and other internal data structures.",
+  NULL, NULL, 1*1024*1024L, 512*1024L, ~0L, 1024);
+
+static MYSQL_SYSVAR_ULONG(autoextend_increment, srv_auto_extend_increment,
+  PLUGIN_VAR_RQCMDARG,
+  "Data file autoextend increment in megabytes",
+  NULL, NULL, 8L, 1L, 1000L, 0);
+
+static MYSQL_SYSVAR_LONGLONG(buffer_pool_size, innobase_buffer_pool_size,
+  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
+  "The size of the memory buffer InnoDB uses to cache data and indexes of its tables.",
+  NULL, NULL, 8*1024*1024L, 1024*1024L, LONGLONG_MAX, 1024*1024L);
+
+static MYSQL_SYSVAR_ULONG(commit_concurrency, srv_commit_concurrency,
+  PLUGIN_VAR_RQCMDARG,
+  "Helps in performance tuning in heavily concurrent environments.",
+  NULL, NULL, 0, 0, 1000, 0);
+
+static MYSQL_SYSVAR_ULONG(concurrency_tickets, srv_n_free_tickets_to_enter,
+  PLUGIN_VAR_RQCMDARG,
+  "Number of times a thread is allowed to enter InnoDB within the same SQL query after it has once got the ticket",
+  NULL, NULL, 500L, 1L, ~0L, 0);
+
+static MYSQL_SYSVAR_LONG(file_io_threads, innobase_file_io_threads,
+  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
+  "Number of file I/O threads in InnoDB.",
+  NULL, NULL, 4, 4, 64, 0);
+
+static MYSQL_SYSVAR_LONG(force_recovery, innobase_force_recovery,
+  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
+  "Helps to save your data in case the disk image of the database becomes corrupt.",
+  NULL, NULL, 0, 0, 6, 0);
+
+static MYSQL_SYSVAR_LONG(lock_wait_timeout, innobase_lock_wait_timeout,
+  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
+  "Timeout in seconds an InnoDB transaction may wait for a lock before being rolled back.",
+  NULL, NULL, 50, 1, 1024 * 1024 * 1024, 0);
+
+static MYSQL_SYSVAR_LONG(log_buffer_size, innobase_log_buffer_size,
+  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
+  "The size of the buffer which InnoDB uses to write log to the log files on disk.",
+  NULL, NULL, 1024*1024L, 256*1024L, ~0L, 1024);
+
+static MYSQL_SYSVAR_LONGLONG(log_file_size, innobase_log_file_size,
+  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
+  "Size of each log file in a log group.",
+  NULL, NULL, 5*1024*1024L, 1*1024*1024L, LONGLONG_MAX, 1024*1024L);
+
+static MYSQL_SYSVAR_LONG(log_files_in_group, innobase_log_files_in_group,
+  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
+  "Number of log files in the log group. InnoDB writes to the files in a circular fashion. Value 3 is recommended here.",
+  NULL, NULL, 2, 2, 100, 0);
+
+static MYSQL_SYSVAR_LONG(mirrored_log_groups, innobase_mirrored_log_groups,
+  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
+  "Number of identical copies of log groups we keep for the database. Currently this should be set to 1.",
+  NULL, NULL, 1, 1, 10, 0);
+
+static MYSQL_SYSVAR_LONG(open_files, innobase_open_files,
+  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
+  "How many files at the maximum InnoDB keeps open at the same time.",
+  NULL, NULL, 300L, 10L, ~0L, 0);
+
+static MYSQL_SYSVAR_ULONG(sync_spin_loops, srv_n_spin_wait_rounds,
+  PLUGIN_VAR_RQCMDARG,
+  "Count of spin-loop rounds in InnoDB mutexes",
+  NULL, NULL, 20L, 0L, ~0L, 0);
+
+static MYSQL_SYSVAR_ULONG(thread_concurrency, srv_thread_concurrency,
+  PLUGIN_VAR_RQCMDARG,
+  "Helps in performance tuning in heavily concurrent environments. Sets the maximum number of threads allowed inside InnoDB. Value 0 will disable the thread throttling.",
+  NULL, NULL, 8, 0, 1000, 0);
+
+static MYSQL_SYSVAR_ULONG(thread_sleep_delay, srv_thread_sleep_delay,
+  PLUGIN_VAR_RQCMDARG,
+  "Time of innodb thread sleeping before joining InnoDB queue (usec). Value 0 disable a sleep",
+  NULL, NULL, 10000L, 0L, ~0L, 0);
+
+static MYSQL_SYSVAR_STR(data_file_path, innobase_data_file_path,
+  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
+  "Path to individual files and their sizes.",
+  NULL, NULL, NULL);
+
+static struct st_mysql_sys_var* innobase_system_variables[]= {
+  MYSQL_SYSVAR(additional_mem_pool_size),
+  MYSQL_SYSVAR(autoextend_increment),
+  MYSQL_SYSVAR(buffer_pool_size),
+  MYSQL_SYSVAR(checksums),
+  MYSQL_SYSVAR(commit_concurrency),
+  MYSQL_SYSVAR(concurrency_tickets),
+  MYSQL_SYSVAR(data_file_path),
+  MYSQL_SYSVAR(data_home_dir),
+  MYSQL_SYSVAR(doublewrite),
+  MYSQL_SYSVAR(fast_shutdown),
+  MYSQL_SYSVAR(file_io_threads),
+  MYSQL_SYSVAR(file_per_table),
+  MYSQL_SYSVAR(flush_log_at_trx_commit),
+  MYSQL_SYSVAR(flush_method),
+  MYSQL_SYSVAR(force_recovery),
+  MYSQL_SYSVAR(locks_unsafe_for_binlog),
+  MYSQL_SYSVAR(lock_wait_timeout),
+  MYSQL_SYSVAR(log_arch_dir),
+#ifdef UNIV_LOG_ARCHIVE
+  MYSQL_SYSVAR(log_archive),
+#endif /* UNIV_LOG_ARCHIVE */
+  MYSQL_SYSVAR(log_buffer_size),
+  MYSQL_SYSVAR(log_file_size),
+  MYSQL_SYSVAR(log_files_in_group),
+  MYSQL_SYSVAR(log_group_home_dir),
+  MYSQL_SYSVAR(max_dirty_pages_pct),
+  MYSQL_SYSVAR(max_purge_lag),
+  MYSQL_SYSVAR(mirrored_log_groups),
+  MYSQL_SYSVAR(open_files),
+  MYSQL_SYSVAR(rollback_on_timeout),
+  MYSQL_SYSVAR(stats_on_metadata),
+  MYSQL_SYSVAR(status_file),
+  MYSQL_SYSVAR(support_xa),
+  MYSQL_SYSVAR(sync_spin_loops),
+  MYSQL_SYSVAR(table_locks),
+  MYSQL_SYSVAR(thread_concurrency),
+  MYSQL_SYSVAR(thread_sleep_delay),
+  NULL
+};
+
 mysql_declare_plugin(innobase)
 {
   MYSQL_STORAGE_ENGINE_PLUGIN,
@@ -7706,8 +7879,8 @@
   NULL, /* Plugin Deinit */
   0x0100 /* 1.0 */,
   innodb_status_variables_export,/* status variables             */
-  NULL,                       /* system variables                */
-  NULL                        /* config options                  */
+  innobase_system_variables, /* system variables */
+  NULL /* reserved */
 }
 mysql_declare_plugin_end;
 

--- 1.205/sql/set_var.cc	2007-05-15 08:34:09 -07:00
+++ 1.206/sql/set_var.cc	2007-05-15 08:34:09 -07:00
@@ -27,8 +27,6 @@
     of it in the my_option structure list in mysqld.cc
   - Don't forget to initialize new fields in global_system_variables and
     max_system_variables!
-  - If the variable should show up in 'show variables' add it to the
-    init_vars[] struct in this file
 
   NOTES:
     - Be careful with var->save_result: sys_var::check() only updates
@@ -59,28 +57,6 @@
 
 #include "events.h"
 
-/* WITH_INNOBASE_STORAGE_ENGINE */
-extern uint innobase_flush_log_at_trx_commit;
-extern ulong innobase_fast_shutdown;
-extern long innobase_mirrored_log_groups, innobase_log_files_in_group;
-extern longlong innobase_log_file_size;
-extern long innobase_log_buffer_size;
-extern longlong innobase_buffer_pool_size;
-extern long innobase_additional_mem_pool_size;
-extern long innobase_file_io_threads, innobase_lock_wait_timeout;
-extern long innobase_force_recovery;
-extern long innobase_open_files;
-extern char *innobase_data_home_dir, *innobase_data_file_path;
-extern char *innobase_log_group_home_dir, *innobase_log_arch_dir;
-extern char *innobase_unix_file_flush_method;
-/* The following variables have to be my_bool for SHOW VARIABLES to work */
-extern my_bool innobase_log_archive,
-               innobase_use_doublewrite,
-               innobase_use_checksums,
-               innobase_file_per_table,
-               innobase_locks_unsafe_for_binlog,
-               innobase_rollback_on_timeout,
-               innobase_stats_on_metadata;
 /* WITH_FALCON_STORAGE_ENGINE */
 //extern "C" {
 extern ulonglong	falcon_min_record_memory;
@@ -92,29 +68,24 @@
 extern char*		falcon_log_dir;
 //}
 
-extern "C" {
-extern ulong srv_max_buf_pool_modified_pct;
-extern ulong srv_max_purge_lag;
-extern ulong srv_auto_extend_increment;
-extern ulong srv_n_spin_wait_rounds;
-extern ulong srv_n_free_tickets_to_enter;
-extern ulong srv_thread_sleep_delay;
-extern ulong srv_thread_concurrency;
-extern ulong srv_commit_concurrency;
-extern ulong srv_flush_log_at_trx_commit;
-}
-
 /* WITH_NDBCLUSTER_STORAGE_ENGINE */
+#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
 extern ulong ndb_cache_check_time;
+extern char opt_ndb_constrbuf[];
 extern ulong ndb_extra_logging;
+#endif
+
 #ifdef HAVE_NDB_BINLOG
 extern ulong ndb_report_thresh_binlog_epoch_slip;
 extern ulong ndb_report_thresh_binlog_mem_usage;
 #endif
 
+extern CHARSET_INFO *character_set_filesystem;
 
 
+static DYNAMIC_ARRAY fixed_show_vars;
 static HASH system_variable_hash;
+
 const char *bool_type_names[]= { "OFF", "ON", NullS };
 TYPELIB bool_typelib=
 {
@@ -181,622 +152,525 @@
   it in the constructor (see sys_var class for details).
 */
 
-sys_var *sys_var::first= NULL;
-uint sys_var::sys_vars= 0;
+static sys_var_chain vars = { NULL, NULL };
 
-sys_var_thd_ulong	sys_auto_increment_increment("auto_increment_increment",
+static sys_var_thd_ulong	sys_auto_increment_increment(&vars, "auto_increment_increment",
                                                      &SV::auto_increment_increment);
-sys_var_thd_ulong	sys_auto_increment_offset("auto_increment_offset",
+static sys_var_thd_ulong	sys_auto_increment_offset(&vars, "auto_increment_offset",
                                                   &SV::auto_increment_offset);
 
-sys_var_bool_ptr	sys_automatic_sp_privileges("automatic_sp_privileges",
+static sys_var_bool_ptr	sys_automatic_sp_privileges(&vars, "automatic_sp_privileges",
 					      &sp_automatic_privileges);
 
-sys_var_const_str       sys_basedir("basedir", mysql_home);
-sys_var_long_ptr	sys_binlog_cache_size("binlog_cache_size",
+static sys_var_const_str       sys_basedir(&vars, "basedir", mysql_home);
+static sys_var_long_ptr	sys_binlog_cache_size(&vars, "binlog_cache_size",
 					      &binlog_cache_size);
-sys_var_thd_binlog_format sys_binlog_format("binlog_format",
+static sys_var_thd_binlog_format sys_binlog_format(&vars, "binlog_format",
                                             &SV::binlog_format);
-sys_var_thd_ulong	sys_bulk_insert_buff_size("bulk_insert_buffer_size",
+static sys_var_thd_ulong	sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
 						  &SV::bulk_insert_buff_size);
-sys_var_character_set_server	sys_character_set_server("character_set_server");
-sys_var_const_str       sys_charset_system("character_set_system",
+static sys_var_character_set_sv	sys_character_set_server(&vars, "character_set_server",
+                                        &SV::collation_server,
+                                        &default_charset_info);
+sys_var_const_str       sys_charset_system(&vars, "character_set_system",
                                            (char *)my_charset_utf8_general_ci.name);
-sys_var_character_set_database	sys_character_set_database("character_set_database");
-sys_var_character_set_client  sys_character_set_client("character_set_client");
-sys_var_character_set_connection  sys_character_set_connection("character_set_connection");
-sys_var_character_set_results sys_character_set_results("character_set_results");
-sys_var_character_set_filesystem  sys_character_set_filesystem("character_set_filesystem");
-sys_var_thd_ulong	sys_completion_type("completion_type",
+static sys_var_character_set_database	sys_character_set_database(&vars, "character_set_database");
+static sys_var_character_set_sv sys_character_set_client(&vars, "character_set_client",
+                                        &SV::character_set_client,
+                                        &default_charset_info);
+static sys_var_character_set_sv sys_character_set_connection(&vars, "character_set_connection",
+                                        &SV::collation_connection,
+                                        &default_charset_info);
+static sys_var_character_set_sv sys_character_set_results(&vars, "character_set_results",
+                                        &SV::character_set_results,
+                                        &default_charset_info, true);
+static sys_var_character_set_sv sys_character_set_filesystem(&vars, "character_set_filesystem",
+                                        &SV::character_set_filesystem,
+                                        &character_set_filesystem);
+static sys_var_thd_ulong	sys_completion_type(&vars, "completion_type",
 					 &SV::completion_type,
 					 check_completion_type,
 					 fix_completion_type);
-sys_var_collation_connection sys_collation_connection("collation_connection");
-sys_var_collation_database sys_collation_database("collation_database");
-sys_var_collation_server sys_collation_server("collation_server");
-sys_var_long_ptr	sys_concurrent_insert("concurrent_insert",
+static sys_var_collation_sv sys_collation_connection(&vars, "collation_connection",
+                                        &SV::collation_connection,
+                                        &default_charset_info);
+static sys_var_collation_sv sys_collation_database(&vars, "collation_database",
+                                        &SV::collation_database,
+                                        &default_charset_info);
+static sys_var_collation_sv sys_collation_server(&vars, "collation_server",
+                                        &SV::collation_server,
+                                        &default_charset_info);
+static sys_var_long_ptr	sys_concurrent_insert(&vars, "concurrent_insert",
                                               &myisam_concurrent_insert);
-sys_var_long_ptr	sys_connect_timeout("connect_timeout",
+static sys_var_long_ptr	sys_connect_timeout(&vars, "connect_timeout",
 					    &connect_timeout);
-sys_var_const_str       sys_datadir("datadir", mysql_real_data_home);
+static sys_var_const_str       sys_datadir(&vars, "datadir", mysql_real_data_home);
 #ifndef DBUG_OFF
-sys_var_thd_dbug        sys_dbug("debug");
+static sys_var_thd_dbug        sys_dbug(&vars, "debug");
 #endif
-sys_var_enum		sys_delay_key_write("delay_key_write",
+static sys_var_enum		sys_delay_key_write(&vars, "delay_key_write",
 					    &delay_key_write_options,
 					    &delay_key_write_typelib,
 					    fix_delay_key_write);
-sys_var_long_ptr	sys_delayed_insert_limit("delayed_insert_limit",
+static sys_var_long_ptr	sys_delayed_insert_limit(&vars, "delayed_insert_limit",
 						 &delayed_insert_limit);
-sys_var_long_ptr	sys_delayed_insert_timeout("delayed_insert_timeout",
+static sys_var_long_ptr	sys_delayed_insert_timeout(&vars, "delayed_insert_timeout",
 						   &delayed_insert_timeout);
-sys_var_long_ptr	sys_delayed_queue_size("delayed_queue_size",
+static sys_var_long_ptr	sys_delayed_queue_size(&vars, "delayed_queue_size",
 					       &delayed_queue_size);
 
-sys_var_event_scheduler sys_event_scheduler("event_scheduler");
-sys_var_long_ptr	sys_expire_logs_days("expire_logs_days",
+static sys_var_event_scheduler sys_event_scheduler(&vars, "event_scheduler");
+static sys_var_long_ptr	sys_expire_logs_days(&vars, "expire_logs_days",
 					     &expire_logs_days);
-sys_var_bool_ptr	sys_flush("flush", &myisam_flush);
-sys_var_long_ptr	sys_flush_time("flush_time", &flush_time);
-sys_var_str             sys_ft_boolean_syntax("ft_boolean_syntax",
+static sys_var_bool_ptr	sys_flush(&vars, "flush", &myisam_flush);
+static sys_var_long_ptr	sys_flush_time(&vars, "flush_time", &flush_time);
+static sys_var_str             sys_ft_boolean_syntax(&vars, "ft_boolean_syntax",
                                          sys_check_ftb_syntax,
                                          sys_update_ftb_syntax,
                                          sys_default_ftb_syntax,
                                          ft_boolean_syntax);
-sys_var_str             sys_init_connect("init_connect", 0,
+sys_var_str             sys_init_connect(&vars, "init_connect", 0,
                                          sys_update_init_connect,
                                          sys_default_init_connect,0);
-sys_var_str             sys_init_slave("init_slave", 0,
+sys_var_str             sys_init_slave(&vars, "init_slave", 0,
                                        sys_update_init_slave,
                                        sys_default_init_slave,0);
-sys_var_thd_ulong	sys_interactive_timeout("interactive_timeout",
+static sys_var_thd_ulong	sys_interactive_timeout(&vars, "interactive_timeout",
 						&SV::net_interactive_timeout);
-sys_var_thd_ulong	sys_join_buffer_size("join_buffer_size",
+static sys_var_thd_ulong	sys_join_buffer_size(&vars, "join_buffer_size",
 					     &SV::join_buff_size);
-sys_var_key_buffer_size	sys_key_buffer_size("key_buffer_size");
-sys_var_key_cache_long  sys_key_cache_block_size("key_cache_block_size",
+static sys_var_key_buffer_size	sys_key_buffer_size(&vars, "key_buffer_size");
+static sys_var_key_cache_long  sys_key_cache_block_size(&vars, "key_cache_block_size",
 						 offsetof(KEY_CACHE,
 							  param_block_size));
-sys_var_key_cache_long	sys_key_cache_division_limit("key_cache_division_limit",
+static sys_var_key_cache_long	sys_key_cache_division_limit(&vars, "key_cache_division_limit",
 						     offsetof(KEY_CACHE,
 							      param_division_limit));
-sys_var_key_cache_long  sys_key_cache_age_threshold("key_cache_age_threshold",
+static sys_var_key_cache_long  sys_key_cache_age_threshold(&vars, "key_cache_age_threshold",
 						     offsetof(KEY_CACHE,
 							      param_age_threshold));
-sys_var_bool_ptr	sys_local_infile("local_infile",
+static sys_var_bool_ptr	sys_local_infile(&vars, "local_infile",
 					 &opt_local_infile);
-sys_var_trust_routine_creators
-sys_trust_routine_creators("log_bin_trust_routine_creators",
+static sys_var_trust_routine_creators
+sys_trust_routine_creators(&vars, "log_bin_trust_routine_creators",
                            &trust_function_creators);
-sys_var_bool_ptr       
-sys_trust_function_creators("log_bin_trust_function_creators",
+static sys_var_bool_ptr       
+sys_trust_function_creators(&vars, "log_bin_trust_function_creators",
                             &trust_function_creators);
-sys_var_bool_ptr
-  sys_log_queries_not_using_indexes("log_queries_not_using_indexes",
+static sys_var_bool_ptr
+  sys_log_queries_not_using_indexes(&vars, "log_queries_not_using_indexes",
                                     &opt_log_queries_not_using_indexes);
-sys_var_thd_ulong	sys_log_warnings("log_warnings", &SV::log_warnings);
-sys_var_thd_ulong	sys_long_query_time("long_query_time",
+static sys_var_thd_ulong	sys_log_warnings(&vars, "log_warnings", &SV::log_warnings);
+static sys_var_thd_ulong	sys_long_query_time(&vars, "long_query_time",
 					     &SV::long_query_time);
-sys_var_thd_bool	sys_low_priority_updates("low_priority_updates",
+static sys_var_thd_bool	sys_low_priority_updates(&vars, "low_priority_updates",
 						 &SV::low_priority_updates,
 						 fix_low_priority_updates);
 #ifndef TO_BE_DELETED	/* Alias for the low_priority_updates */
-sys_var_thd_bool	sys_sql_low_priority_updates("sql_low_priority_updates",
+static sys_var_thd_bool	sys_sql_low_priority_updates(&vars, "sql_low_priority_updates",
 						     &SV::low_priority_updates,
 						     fix_low_priority_updates);
 #endif
-sys_var_thd_ulong	sys_max_allowed_packet("max_allowed_packet",
+static sys_var_thd_ulong	sys_max_allowed_packet(&vars, "max_allowed_packet",
 					       &SV::max_allowed_packet);
-sys_var_long_ptr	sys_max_binlog_cache_size("max_binlog_cache_size",
+static sys_var_long_ptr	sys_max_binlog_cache_size(&vars, "max_binlog_cache_size",
 						  &max_binlog_cache_size);
-sys_var_long_ptr	sys_max_binlog_size("max_binlog_size",
+static sys_var_long_ptr	sys_max_binlog_size(&vars, "max_binlog_size",
 					    &max_binlog_size,
                                             fix_max_binlog_size);
-sys_var_long_ptr	sys_max_connections("max_connections",
+static sys_var_long_ptr	sys_max_connections(&vars, "max_connections",
 					    &max_connections,
                                             fix_max_connections);
-sys_var_long_ptr	sys_max_connect_errors("max_connect_errors",
+static sys_var_long_ptr	sys_max_connect_errors(&vars, "max_connect_errors",
 					       &max_connect_errors);
-sys_var_thd_ulong       sys_max_insert_delayed_threads("max_insert_delayed_threads",
+static sys_var_thd_ulong       sys_max_insert_delayed_threads(&vars, "max_insert_delayed_threads",
 						       &SV::max_insert_delayed_threads,
                                                        check_max_delayed_threads,
                                                        fix_max_connections);
-sys_var_thd_ulong	sys_max_delayed_threads("max_delayed_threads",
+static sys_var_thd_ulong	sys_max_delayed_threads(&vars, "max_delayed_threads",
 						&SV::max_insert_delayed_threads,
                                                 check_max_delayed_threads,
                                                 fix_max_connections);
-sys_var_thd_ulong	sys_max_error_count("max_error_count",
+static sys_var_thd_ulong	sys_max_error_count(&vars, "max_error_count",
 					    &SV::max_error_count);
-sys_var_thd_ulonglong	sys_max_heap_table_size("max_heap_table_size",
+static sys_var_thd_ulonglong	sys_max_heap_table_size(&vars, "max_heap_table_size",
 						&SV::max_heap_table_size);
-sys_var_thd_ulong       sys_pseudo_thread_id("pseudo_thread_id",
+static sys_var_thd_ulong       sys_pseudo_thread_id(&vars, "pseudo_thread_id",
 					     &SV::pseudo_thread_id,
                                              check_pseudo_thread_id, 0);
-sys_var_thd_ha_rows	sys_max_join_size("max_join_size",
+static sys_var_thd_ha_rows	sys_max_join_size(&vars, "max_join_size",
 					  &SV::max_join_size,
 					  fix_max_join_size);
-sys_var_thd_ulong	sys_max_seeks_for_key("max_seeks_for_key",
+static sys_var_thd_ulong	sys_max_seeks_for_key(&vars, "max_seeks_for_key",
 					      &SV::max_seeks_for_key);
-sys_var_thd_ulong   sys_max_length_for_sort_data("max_length_for_sort_data",
+static sys_var_thd_ulong   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
                                                  &SV::max_length_for_sort_data);
 #ifndef TO_BE_DELETED	/* Alias for max_join_size */
-sys_var_thd_ha_rows	sys_sql_max_join_size("sql_max_join_size",
+static sys_var_thd_ha_rows	sys_sql_max_join_size(&vars, "sql_max_join_size",
 					      &SV::max_join_size,
 					      fix_max_join_size);
 #endif
 static sys_var_long_ptr_global
-sys_max_prepared_stmt_count("max_prepared_stmt_count",
+sys_max_prepared_stmt_count(&vars, "max_prepared_stmt_count",
                             &max_prepared_stmt_count,
                             &LOCK_prepared_stmt_count);
-sys_var_long_ptr	sys_max_relay_log_size("max_relay_log_size",
+static sys_var_long_ptr	sys_max_relay_log_size(&vars, "max_relay_log_size",
                                                &max_relay_log_size,
                                                fix_max_relay_log_size);
-sys_var_thd_ulong	sys_max_sort_length("max_sort_length",
+static sys_var_thd_ulong	sys_max_sort_length(&vars, "max_sort_length",
 					    &SV::max_sort_length);
-sys_var_thd_ulong	sys_max_sp_recursion_depth("max_sp_recursion_depth",
+static sys_var_thd_ulong	sys_max_sp_recursion_depth(&vars, "max_sp_recursion_depth",
                                                    &SV::max_sp_recursion_depth);
-sys_var_max_user_conn   sys_max_user_connections("max_user_connections");
-sys_var_thd_ulong	sys_max_tmp_tables("max_tmp_tables",
+static sys_var_max_user_conn   sys_max_user_connections(&vars, "max_user_connections");
+static sys_var_thd_ulong	sys_max_tmp_tables(&vars, "max_tmp_tables",
 					   &SV::max_tmp_tables);
-sys_var_long_ptr	sys_max_write_lock_count("max_write_lock_count",
+static sys_var_long_ptr	sys_max_write_lock_count(&vars, "max_write_lock_count",
 						 &max_write_lock_count);
-sys_var_thd_ulong       sys_multi_range_count("multi_range_count",
+static sys_var_thd_ulong       sys_multi_range_count(&vars, "multi_range_count",
                                               &SV::multi_range_count);
-sys_var_long_ptr	sys_myisam_data_pointer_size("myisam_data_pointer_size",
+static sys_var_long_ptr	sys_myisam_data_pointer_size(&vars, "myisam_data_pointer_size",
                                                     &myisam_data_pointer_size);
-sys_var_thd_ulonglong	sys_myisam_max_sort_file_size("myisam_max_sort_file_size", &SV::myisam_max_sort_file_size, fix_myisam_max_sort_file_size, 1);
-sys_var_thd_ulong       sys_myisam_repair_threads("myisam_repair_threads", &SV::myisam_repair_threads);
-sys_var_thd_ulong	sys_myisam_sort_buffer_size("myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
-sys_var_bool_ptr	sys_myisam_use_mmap("myisam_use_mmap", 
+static sys_var_thd_ulonglong	sys_myisam_max_sort_file_size(&vars, "myisam_max_sort_file_size", &SV::myisam_max_sort_file_size, fix_myisam_max_sort_file_size, 1);
+static sys_var_thd_ulong       sys_myisam_repair_threads(&vars, "myisam_repair_threads", &SV::myisam_repair_threads);
+static sys_var_thd_ulong	sys_myisam_sort_buffer_size(&vars, "myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
+static sys_var_bool_ptr	sys_myisam_use_mmap(&vars, "myisam_use_mmap",
                                             &opt_myisam_use_mmap);
 
-sys_var_thd_enum        sys_myisam_stats_method("myisam_stats_method",
+static sys_var_thd_enum         sys_myisam_stats_method(&vars, "myisam_stats_method",
                                                 &SV::myisam_stats_method,
                                                 &myisam_stats_method_typelib,
                                                 NULL);
 
-sys_var_thd_ulong	sys_net_buffer_length("net_buffer_length",
+static sys_var_thd_ulong	sys_net_buffer_length(&vars, "net_buffer_length",
 					      &SV::net_buffer_length);
-sys_var_thd_ulong	sys_net_read_timeout("net_read_timeout",
+static sys_var_thd_ulong	sys_net_read_timeout(&vars, "net_read_timeout",
 					     &SV::net_read_timeout,
 					     0, fix_net_read_timeout);
-sys_var_thd_ulong	sys_net_write_timeout("net_write_timeout",
+static sys_var_thd_ulong	sys_net_write_timeout(&vars, "net_write_timeout",
 					      &SV::net_write_timeout,
 					      0, fix_net_write_timeout);
-sys_var_thd_ulong	sys_net_retry_count("net_retry_count",
+static sys_var_thd_ulong	sys_net_retry_count(&vars, "net_retry_count",
 					    &SV::net_retry_count,
 					    0, fix_net_retry_count);
-sys_var_thd_bool	sys_new_mode("new", &SV::new_mode);
-sys_var_bool_ptr_readonly sys_old_mode("old", 
+static sys_var_thd_bool	sys_new_mode(&vars, "new", &SV::new_mode);
+static sys_var_bool_ptr_readonly sys_old_mode(&vars, "old",
                                        &global_system_variables.old_mode);
-sys_var_thd_bool	sys_old_alter_table("old_alter_table",
-					    &SV::old_alter_table);
-sys_var_thd_bool	sys_old_passwords("old_passwords", &SV::old_passwords);
-sys_var_thd_ulong       sys_optimizer_prune_level("optimizer_prune_level",
+/* these two cannot be static */
+sys_var_thd_bool                sys_old_alter_table(&vars, "old_alter_table",
+                                            &SV::old_alter_table);
+sys_var_thd_bool                sys_old_passwords(&vars, "old_passwords", &SV::old_passwords);
+static sys_var_thd_ulong        sys_optimizer_prune_level(&vars, "optimizer_prune_level",
                                                   &SV::optimizer_prune_level);
-sys_var_thd_ulong       sys_optimizer_search_depth("optimizer_search_depth",
+static sys_var_thd_ulong        sys_optimizer_search_depth(&vars, "optimizer_search_depth",
                                                    &SV::optimizer_search_depth);
-sys_var_thd_ulong       sys_preload_buff_size("preload_buffer_size",
+static sys_var_thd_ulong        sys_preload_buff_size(&vars, "preload_buffer_size",
                                               &SV::preload_buff_size);
-sys_var_thd_ulong	sys_read_buff_size("read_buffer_size",
+static sys_var_thd_ulong	sys_read_buff_size(&vars, "read_buffer_size",
 					   &SV::read_buff_size);
-sys_var_opt_readonly    sys_readonly("read_only", &opt_readonly);
-sys_var_thd_ulong	sys_read_rnd_buff_size("read_rnd_buffer_size",
+static sys_var_opt_readonly	sys_readonly(&vars, "read_only", &opt_readonly);
+static sys_var_thd_ulong	sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
 					       &SV::read_rnd_buff_size);
-sys_var_thd_ulong	sys_div_precincrement("div_precision_increment",
+static sys_var_thd_ulong	sys_div_precincrement(&vars, "div_precision_increment",
                                               &SV::div_precincrement);
-#ifdef HAVE_REPLICATION
-sys_var_bool_ptr	sys_relay_log_purge("relay_log_purge",
-                                            &relay_log_purge);
-#endif
-sys_var_long_ptr	sys_rpl_recovery_rank("rpl_recovery_rank",
+static sys_var_long_ptr	sys_rpl_recovery_rank(&vars, "rpl_recovery_rank",
 					      &rpl_recovery_rank);
-sys_var_long_ptr	sys_query_cache_size("query_cache_size",
+static sys_var_long_ptr	sys_query_cache_size(&vars, "query_cache_size",
 					     &query_cache_size,
 					     fix_query_cache_size);
 
-sys_var_thd_ulong	sys_range_alloc_block_size("range_alloc_block_size",
+static sys_var_thd_ulong	sys_range_alloc_block_size(&vars, "range_alloc_block_size",
 						   &SV::range_alloc_block_size);
-sys_var_thd_ulong	sys_query_alloc_block_size("query_alloc_block_size",
+static sys_var_thd_ulong	sys_query_alloc_block_size(&vars, "query_alloc_block_size",
 						   &SV::query_alloc_block_size,
 						   0, fix_thd_mem_root);
-sys_var_thd_ulong	sys_query_prealloc_size("query_prealloc_size",
+static sys_var_thd_ulong	sys_query_prealloc_size(&vars, "query_prealloc_size",
 						&SV::query_prealloc_size,
 						0, fix_thd_mem_root);
-sys_var_readonly        sys_tmpdir("tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
-sys_var_thd_ulong	sys_trans_alloc_block_size("transaction_alloc_block_size",
+static sys_var_readonly        sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
+static sys_var_thd_ulong	sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
 						   &SV::trans_alloc_block_size,
 						   0, fix_trans_mem_root);
-sys_var_thd_ulong	sys_trans_prealloc_size("transaction_prealloc_size",
+static sys_var_thd_ulong	sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
 						&SV::trans_prealloc_size,
 						0, fix_trans_mem_root);
-sys_var_thd_enum        sys_thread_handling("thread_handling",
+sys_var_thd_enum        sys_thread_handling(&vars, "thread_handling",
                                             &SV::thread_handling,
                                             &thread_handling_typelib,
                                             NULL);
 
 #ifdef HAVE_QUERY_CACHE
-sys_var_long_ptr	sys_query_cache_limit("query_cache_limit",
+static sys_var_long_ptr	sys_query_cache_limit(&vars, "query_cache_limit",
 					      &query_cache.query_cache_limit);
-sys_var_long_ptr        sys_query_cache_min_res_unit("query_cache_min_res_unit",
+static sys_var_long_ptr        sys_query_cache_min_res_unit(&vars, "query_cache_min_res_unit",
 						     &query_cache_min_res_unit,
 						     fix_query_cache_min_res_unit);
-sys_var_thd_enum	sys_query_cache_type("query_cache_type",
+static sys_var_thd_enum	sys_query_cache_type(&vars, "query_cache_type",
 					     &SV::query_cache_type,
 					     &query_cache_type_typelib);
-sys_var_thd_bool
-sys_query_cache_wlock_invalidate("query_cache_wlock_invalidate",
+static sys_var_thd_bool
+sys_query_cache_wlock_invalidate(&vars, "query_cache_wlock_invalidate",
 				 &SV::query_cache_wlock_invalidate);
 #endif /* HAVE_QUERY_CACHE */
-sys_var_bool_ptr	sys_secure_auth("secure_auth", &opt_secure_auth);
-sys_var_const_str_ptr   sys_secure_file_priv("secure_file_priv",
+static sys_var_bool_ptr	sys_secure_auth(&vars, "secure_auth", &opt_secure_auth);
+static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
                                              &opt_secure_file_priv);
-sys_var_long_ptr	sys_server_id("server_id", &server_id, fix_server_id);
-sys_var_bool_ptr	sys_slave_compressed_protocol("slave_compressed_protocol",
+static sys_var_long_ptr	sys_server_id(&vars, "server_id", &server_id, fix_server_id);
+static sys_var_bool_ptr	sys_slave_compressed_protocol(&vars, "slave_compressed_protocol",
 						      &opt_slave_compressed_protocol);
-#ifdef HAVE_REPLICATION
-sys_var_long_ptr	sys_slave_net_timeout("slave_net_timeout",
-					      &slave_net_timeout);
-sys_var_long_ptr	sys_slave_trans_retries("slave_transaction_retries",
-                                                &slave_trans_retries);
-#endif
-sys_var_long_ptr	sys_slow_launch_time("slow_launch_time",
+static sys_var_long_ptr	sys_slow_launch_time(&vars, "slow_launch_time",
 					     &slow_launch_time);
-sys_var_thd_ulong	sys_sort_buffer("sort_buffer_size",
+static sys_var_thd_ulong	sys_sort_buffer(&vars, "sort_buffer_size",
 					&SV::sortbuff_size);
-sys_var_thd_sql_mode    sys_sql_mode("sql_mode",
+static sys_var_thd_sql_mode    sys_sql_mode(&vars, "sql_mode",
                                      &SV::sql_mode);
 #ifdef HAVE_OPENSSL
 extern char *opt_ssl_ca, *opt_ssl_capath, *opt_ssl_cert, *opt_ssl_cipher,
             *opt_ssl_key;
-sys_var_const_str_ptr	sys_ssl_ca("ssl_ca", &opt_ssl_ca);
-sys_var_const_str_ptr	sys_ssl_capath("ssl_capath", &opt_ssl_capath);
-sys_var_const_str_ptr	sys_ssl_cert("ssl_cert", &opt_ssl_cert);
-sys_var_const_str_ptr	sys_ssl_cipher("ssl_cipher", &opt_ssl_cipher);
-sys_var_const_str_ptr	sys_ssl_key("ssl_key", &opt_ssl_key);
+static sys_var_const_str_ptr	sys_ssl_ca(&vars, "ssl_ca", &opt_ssl_ca);
+static sys_var_const_str_ptr	sys_ssl_capath(&vars, "ssl_capath", &opt_ssl_capath);
+static sys_var_const_str_ptr	sys_ssl_cert(&vars, "ssl_cert", &opt_ssl_cert);
+static sys_var_const_str_ptr	sys_ssl_cipher(&vars, "ssl_cipher", &opt_ssl_cipher);
+static sys_var_const_str_ptr	sys_ssl_key(&vars, "ssl_key", &opt_ssl_key);
 #else
-sys_var_const_str	sys_ssl_ca("ssl_ca", NULL);
-sys_var_const_str	sys_ssl_capath("ssl_capath", NULL);
-sys_var_const_str	sys_ssl_cert("ssl_cert", NULL);
-sys_var_const_str	sys_ssl_cipher("ssl_cipher", NULL);
-sys_var_const_str	sys_ssl_key("ssl_key", NULL);
+static sys_var_const_str	sys_ssl_ca(&vars, "ssl_ca", NULL);
+static sys_var_const_str	sys_ssl_capath(&vars, "ssl_capath", NULL);
+static sys_var_const_str	sys_ssl_cert(&vars, "ssl_cert", NULL);
+static sys_var_const_str	sys_ssl_cipher(&vars, "ssl_cipher", NULL);
+static sys_var_const_str	sys_ssl_key(&vars, "ssl_key", NULL);
 #endif
-sys_var_thd_enum
-sys_updatable_views_with_limit("updatable_views_with_limit",
+static sys_var_thd_enum
+sys_updatable_views_with_limit(&vars, "updatable_views_with_limit",
                                &SV::updatable_views_with_limit,
                                &updatable_views_with_limit_typelib);
 
-sys_var_thd_table_type  sys_table_type("table_type",
-				       &SV::table_type);
-sys_var_thd_storage_engine sys_storage_engine("storage_engine",
-				       &SV::table_type);
-#ifdef HAVE_REPLICATION
-sys_var_sync_binlog_period sys_sync_binlog_period("sync_binlog", &sync_binlog_period);
-#endif
-sys_var_bool_ptr	sys_sync_frm("sync_frm", &opt_sync_frm);
-sys_var_const_str	sys_system_time_zone("system_time_zone",
+static sys_var_thd_table_type  sys_table_type(&vars, "table_type",
+				       &SV::table_plugin);
+static sys_var_thd_storage_engine sys_storage_engine(&vars, "storage_engine",
+				       &SV::table_plugin);
+static sys_var_bool_ptr	sys_sync_frm(&vars, "sync_frm", &opt_sync_frm);
+static sys_var_const_str	sys_system_time_zone(&vars, "system_time_zone",
                                              system_time_zone);
-sys_var_long_ptr	sys_table_def_size("table_definition_cache",
+static sys_var_long_ptr	sys_table_def_size(&vars, "table_definition_cache",
                                            &table_def_size);
-sys_var_long_ptr	sys_table_cache_size("table_open_cache",
+static sys_var_long_ptr	sys_table_cache_size(&vars, "table_open_cache",
 					     &table_cache_size);
-sys_var_long_ptr	sys_table_lock_wait_timeout("table_lock_wait_timeout",
+static sys_var_long_ptr	sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
                                                     &table_lock_wait_timeout);
-sys_var_long_ptr	sys_thread_cache_size("thread_cache_size",
+static sys_var_long_ptr	sys_thread_cache_size(&vars, "thread_cache_size",
 					      &thread_cache_size);
 #if HAVE_POOL_OF_THREADS == 1
-sys_var_long_ptr	sys_thread_pool_size("thread_pool_size",
+sys_var_long_ptr	sys_thread_pool_size(&vars, "thread_pool_size",
 					      &thread_pool_size);
 #endif
-sys_var_thd_enum	sys_tx_isolation("tx_isolation",
+static sys_var_thd_enum	sys_tx_isolation(&vars, "tx_isolation",
 					 &SV::tx_isolation,
 					 &tx_isolation_typelib,
 					 fix_tx_isolation,
 					 check_tx_isolation);
-sys_var_thd_ulonglong	sys_tmp_table_size("tmp_table_size",
+static sys_var_thd_ulonglong	sys_tmp_table_size(&vars, "tmp_table_size",
 					   &SV::tmp_table_size);
-sys_var_bool_ptr  sys_timed_mutexes("timed_mutexes",
+static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes",
                                     &timed_mutexes);
-sys_var_const_str	sys_version("version", server_version);
-sys_var_const_str	sys_version_comment("version_comment",
+static sys_var_const_str	sys_version(&vars, "version", server_version);
+static sys_var_const_str	sys_version_comment(&vars, "version_comment",
                                             MYSQL_COMPILATION_COMMENT);
-sys_var_const_str	sys_version_compile_machine("version_compile_machine",
+static sys_var_const_str	sys_version_compile_machine(&vars, "version_compile_machine",
                                                     MACHINE_TYPE);
-sys_var_const_str	sys_version_compile_os("version_compile_os",
+static sys_var_const_str	sys_version_compile_os(&vars, "version_compile_os",
                                                SYSTEM_TYPE);
-sys_var_thd_ulong	sys_net_wait_timeout("wait_timeout",
+static sys_var_thd_ulong	sys_net_wait_timeout(&vars, "wait_timeout",
 					     &SV::net_wait_timeout);
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
-sys_var_long_ptr	sys_innodb_fast_shutdown("innodb_fast_shutdown",
-						 &innobase_fast_shutdown);
-sys_var_long_ptr        sys_innodb_max_dirty_pages_pct("innodb_max_dirty_pages_pct",
-                                                        &srv_max_buf_pool_modified_pct);
-sys_var_long_ptr	sys_innodb_max_purge_lag("innodb_max_purge_lag",
-							&srv_max_purge_lag);
-sys_var_thd_bool	sys_innodb_table_locks("innodb_table_locks",
-                                               &SV::innodb_table_locks);
-sys_var_thd_bool	sys_innodb_support_xa("innodb_support_xa",
-                                               &SV::innodb_support_xa);
-sys_var_long_ptr	sys_innodb_autoextend_increment("innodb_autoextend_increment",
-							&srv_auto_extend_increment);
-sys_var_long_ptr	sys_innodb_sync_spin_loops("innodb_sync_spin_loops",
-                                             &srv_n_spin_wait_rounds);
-sys_var_long_ptr  sys_innodb_concurrency_tickets("innodb_concurrency_tickets",
-                                             &srv_n_free_tickets_to_enter);
-sys_var_long_ptr  sys_innodb_thread_sleep_delay("innodb_thread_sleep_delay",
-                                                &srv_thread_sleep_delay);
-sys_var_long_ptr  sys_innodb_thread_concurrency("innodb_thread_concurrency",
-                                                &srv_thread_concurrency);
-sys_var_long_ptr  sys_innodb_commit_concurrency("innodb_commit_concurrency",
-                                                &srv_commit_concurrency);
-sys_var_long_ptr  sys_innodb_flush_log_at_trx_commit(
-                                        "innodb_flush_log_at_trx_commit",
-                                        &srv_flush_log_at_trx_commit);
-#endif
+
 /* Condition pushdown to storage engine */
-sys_var_thd_bool
-sys_engine_condition_pushdown("engine_condition_pushdown",
+static sys_var_thd_bool
+sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
 			      &SV::engine_condition_pushdown);
 
+#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
 /* ndb thread specific variable settings */
-sys_var_thd_ulong
-sys_ndb_autoincrement_prefetch_sz("ndb_autoincrement_prefetch_sz",
+static sys_var_thd_ulong
+sys_ndb_autoincrement_prefetch_sz(&vars, "ndb_autoincrement_prefetch_sz",
 				  &SV::ndb_autoincrement_prefetch_sz);
-sys_var_thd_bool
-sys_ndb_force_send("ndb_force_send", &SV::ndb_force_send);
+static sys_var_thd_bool
+sys_ndb_force_send(&vars, "ndb_force_send", &SV::ndb_force_send);
 #ifdef HAVE_NDB_BINLOG
-sys_var_long_ptr
-sys_ndb_report_thresh_binlog_epoch_slip("ndb_report_thresh_binlog_epoch_slip",
+static sys_var_long_ptr
+sys_ndb_report_thresh_binlog_epoch_slip(&vars, "ndb_report_thresh_binlog_epoch_slip",
                                         &ndb_report_thresh_binlog_epoch_slip);
-sys_var_long_ptr
-sys_ndb_report_thresh_binlog_mem_usage("ndb_report_thresh_binlog_mem_usage",
+static sys_var_long_ptr
+sys_ndb_report_thresh_binlog_mem_usage(&vars, "ndb_report_thresh_binlog_mem_usage",
                                        &ndb_report_thresh_binlog_mem_usage);
 #endif
-sys_var_thd_bool
-sys_ndb_use_exact_count("ndb_use_exact_count", &SV::ndb_use_exact_count);
-sys_var_thd_bool
-sys_ndb_use_transactions("ndb_use_transactions", &SV::ndb_use_transactions);
-sys_var_long_ptr
-sys_ndb_cache_check_time("ndb_cache_check_time", &ndb_cache_check_time);
-sys_var_thd_bool
-sys_ndb_index_stat_enable("ndb_index_stat_enable",
+static sys_var_thd_bool
+sys_ndb_use_exact_count(&vars, "ndb_use_exact_count", &SV::ndb_use_exact_count);
+static sys_var_thd_bool
+sys_ndb_use_transactions(&vars, "ndb_use_transactions", &SV::ndb_use_transactions);
+static sys_var_long_ptr
+sys_ndb_cache_check_time(&vars, "ndb_cache_check_time", &ndb_cache_check_time);
+static sys_var_const_str
+sys_ndb_connectstring(&vars, "ndb_connectstring", opt_ndb_constrbuf);
+static sys_var_thd_bool
+sys_ndb_index_stat_enable(&vars, "ndb_index_stat_enable",
                           &SV::ndb_index_stat_enable);
-sys_var_thd_ulong
-sys_ndb_index_stat_cache_entries("ndb_index_stat_cache_entries",
+static sys_var_thd_ulong
+sys_ndb_index_stat_cache_entries(&vars, "ndb_index_stat_cache_entries",
                                  &SV::ndb_index_stat_cache_entries);
-sys_var_thd_ulong
-sys_ndb_index_stat_update_freq("ndb_index_stat_update_freq",
+static sys_var_thd_ulong
+sys_ndb_index_stat_update_freq(&vars, "ndb_index_stat_update_freq",
                                &SV::ndb_index_stat_update_freq);
-sys_var_long_ptr
-sys_ndb_extra_logging("ndb_extra_logging", &ndb_extra_logging);
-sys_var_thd_bool
-sys_ndb_use_copying_alter_table("ndb_use_copying_alter_table", &SV::ndb_use_copying_alter_table);
+static sys_var_long_ptr
+sys_ndb_extra_logging(&vars, "ndb_extra_logging", &ndb_extra_logging);
+static sys_var_thd_bool
+sys_ndb_use_copying_alter_table(&vars, "ndb_use_copying_alter_table", &SV::ndb_use_copying_alter_table);
+#endif //WITH_NDBCLUSTER_STORAGE_ENGINE
 
 /* Time/date/datetime formats */
 
-sys_var_thd_date_time_format sys_time_format("time_format",
+static sys_var_thd_date_time_format sys_time_format(&vars, "time_format",
 					     &SV::time_format,
 					     MYSQL_TIMESTAMP_TIME);
-sys_var_thd_date_time_format sys_date_format("date_format",
+static sys_var_thd_date_time_format sys_date_format(&vars, "date_format",
 					     &SV::date_format,
 					     MYSQL_TIMESTAMP_DATE);
-sys_var_thd_date_time_format sys_datetime_format("datetime_format",
+static sys_var_thd_date_time_format sys_datetime_format(&vars, "datetime_format",
 						 &SV::datetime_format,
 						 MYSQL_TIMESTAMP_DATETIME);
 
 /* Variables that are bits in THD */
 
-sys_var_thd_bit sys_autocommit("autocommit", 0,
+sys_var_thd_bit sys_autocommit(&vars, "autocommit", 0,
                                set_option_autocommit,
                                OPTION_NOT_AUTOCOMMIT,
                                1);
-static sys_var_thd_bit	sys_big_tables("big_tables", 0,
+static sys_var_thd_bit	sys_big_tables(&vars, "big_tables", 0,
 				       set_option_bit,
 				       OPTION_BIG_TABLES);
 #ifndef TO_BE_DELETED	/* Alias for big_tables */
-static sys_var_thd_bit	sys_sql_big_tables("sql_big_tables", 0,
+static sys_var_thd_bit	sys_sql_big_tables(&vars, "sql_big_tables", 0,
 					   set_option_bit,
 					   OPTION_BIG_TABLES);
 #endif
-static sys_var_thd_bit	sys_big_selects("sql_big_selects", 0,
+static sys_var_thd_bit	sys_big_selects(&vars, "sql_big_selects", 0,
 					set_option_bit,
 					OPTION_BIG_SELECTS);
-static sys_var_thd_bit	sys_log_off("sql_log_off",
+static sys_var_thd_bit	sys_log_off(&vars, "sql_log_off",
 				    check_log_update,
 				    set_option_bit,
 				    OPTION_LOG_OFF);
-static sys_var_thd_bit	sys_log_update("sql_log_update",
+static sys_var_thd_bit	sys_log_update(&vars, "sql_log_update",
                                        check_log_update,
 				       set_log_update,
 				       OPTION_BIN_LOG);
-static sys_var_thd_bit	sys_log_binlog("sql_log_bin",
+static sys_var_thd_bit	sys_log_binlog(&vars, "sql_log_bin",
                                        check_log_update,
 				       set_option_bit,
 				       OPTION_BIN_LOG);
-static sys_var_thd_bit	sys_sql_warnings("sql_warnings", 0,
+static sys_var_thd_bit	sys_sql_warnings(&vars, "sql_warnings", 0,
 					 set_option_bit,
 					 OPTION_WARNINGS);
-static sys_var_thd_bit	sys_sql_notes("sql_notes", 0,
+static sys_var_thd_bit	sys_sql_notes(&vars, "sql_notes", 0,
 					 set_option_bit,
 					 OPTION_SQL_NOTES);
-static sys_var_thd_bit	sys_auto_is_null("sql_auto_is_null", 0,
+static sys_var_thd_bit	sys_auto_is_null(&vars, "sql_auto_is_null", 0,
 					 set_option_bit,
 					 OPTION_AUTO_IS_NULL);
-static sys_var_thd_bit	sys_safe_updates("sql_safe_updates", 0,
+static sys_var_thd_bit	sys_safe_updates(&vars, "sql_safe_updates", 0,
 					 set_option_bit,
 					 OPTION_SAFE_UPDATES);
-static sys_var_thd_bit	sys_buffer_results("sql_buffer_result", 0,
+static sys_var_thd_bit	sys_buffer_results(&vars, "sql_buffer_result", 0,
 					   set_option_bit,
 					   OPTION_BUFFER_RESULT);
-static sys_var_thd_bit	sys_quote_show_create("sql_quote_show_create", 0,
+static sys_var_thd_bit	sys_quote_show_create(&vars, "sql_quote_show_create", 0,
 					      set_option_bit,
 					      OPTION_QUOTE_SHOW_CREATE);
-static sys_var_thd_bit	sys_foreign_key_checks("foreign_key_checks", 0,
+static sys_var_thd_bit	sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
 					       set_option_bit,
 					       OPTION_NO_FOREIGN_KEY_CHECKS,
 					       1);
-static sys_var_thd_bit	sys_unique_checks("unique_checks", 0,
+static sys_var_thd_bit	sys_unique_checks(&vars, "unique_checks", 0,
 					  set_option_bit,
 					  OPTION_RELAXED_UNIQUE_CHECKS,
 					  1);
 
 /* Local state variables */
 
-static sys_var_thd_ha_rows	sys_select_limit("sql_select_limit",
+static sys_var_thd_ha_rows	sys_select_limit(&vars, "sql_select_limit",
 						 &SV::select_limit);
-static sys_var_timestamp	sys_timestamp("timestamp");
-static sys_var_last_insert_id	sys_last_insert_id("last_insert_id");
-static sys_var_last_insert_id	sys_identity("identity");
+static sys_var_timestamp	sys_timestamp(&vars, "timestamp");
+static sys_var_last_insert_id	sys_last_insert_id(&vars, "last_insert_id");
+static sys_var_last_insert_id	sys_identity(&vars, "identity");
 
-static sys_var_thd_lc_time_names       sys_lc_time_names("lc_time_names");
+static sys_var_thd_lc_time_names       sys_lc_time_names(&vars, "lc_time_names");
 
-static sys_var_insert_id	sys_insert_id("insert_id");
-static sys_var_readonly		sys_error_count("error_count",
+static sys_var_insert_id	sys_insert_id(&vars, "insert_id");
+static sys_var_readonly		sys_error_count(&vars, "error_count",
 						OPT_SESSION,
 						SHOW_LONG,
 						get_error_count);
-static sys_var_readonly		sys_warning_count("warning_count",
+static sys_var_readonly		sys_warning_count(&vars, "warning_count",
 						  OPT_SESSION,
 						  SHOW_LONG,
 						  get_warning_count);
 
 /* alias for last_insert_id() to be compatible with Sybase */
-#ifdef HAVE_REPLICATION
-static sys_var_slave_skip_counter sys_slave_skip_counter("sql_slave_skip_counter");
-#endif
-static sys_var_rand_seed1	sys_rand_seed1("rand_seed1");
-static sys_var_rand_seed2	sys_rand_seed2("rand_seed2");
+static sys_var_rand_seed1	sys_rand_seed1(&vars, "rand_seed1");
+static sys_var_rand_seed2	sys_rand_seed2(&vars, "rand_seed2");
 
-static sys_var_thd_ulong        sys_default_week_format("default_week_format",
+static sys_var_thd_ulong        sys_default_week_format(&vars, "default_week_format",
 					                &SV::default_week_format);
 
-sys_var_thd_ulong               sys_group_concat_max_len("group_concat_max_len",
+sys_var_thd_ulong               sys_group_concat_max_len(&vars, "group_concat_max_len",
                                                          &SV::group_concat_max_len);
 
-sys_var_thd_time_zone            sys_time_zone("time_zone");
-
-/* Read only variables */
+sys_var_thd_time_zone            sys_time_zone(&vars, "time_zone");
 
 /* Global read-only variable containing hostname */
-sys_var_const_str		sys_hostname("hostname", glob_hostname);
+static sys_var_const_str        sys_hostname(&vars, "hostname", glob_hostname);
 
+/* Read only variables */
 
-sys_var_have_variable sys_have_compress("have_compress", &have_compress);
-sys_var_have_variable sys_have_crypt("have_crypt", &have_crypt);
-sys_var_have_variable sys_have_csv_db("have_csv", &have_csv_db);
-sys_var_have_variable sys_have_dlopen("have_dynamic_loading", &have_dlopen);
-sys_var_have_variable sys_have_falcon("have_falcon", &have_falcon);
-sys_var_have_variable sys_have_geometry("have_geometry", &have_geometry);
-sys_var_have_variable sys_have_innodb("have_innodb", &have_innodb);
-sys_var_have_variable sys_have_ndbcluster("have_ndbcluster", &have_ndbcluster);
-sys_var_have_variable sys_have_openssl("have_openssl", &have_ssl);
-sys_var_have_variable sys_have_ssl("have_ssl", &have_ssl);
-sys_var_have_variable sys_have_partition_db("have_partitioning",
-                                            &have_partition_db);
-sys_var_have_variable sys_have_query_cache("have_query_cache",
+static sys_var_have_variable sys_have_compress(&vars, "have_compress", &have_compress);
+static sys_var_have_variable sys_have_crypt(&vars, "have_crypt", &have_crypt);
+static sys_var_have_plugin sys_have_csv(&vars, "have_csv", C_STRING_WITH_LEN("csv"), MYSQL_STORAGE_ENGINE_PLUGIN);
+static sys_var_have_variable sys_have_dlopen(&vars, "have_dynamic_loading", &have_dlopen);
+static sys_var_have_plugin sys_have_falcon(&vars, "have_falcon", C_STRING_WITH_LEN("falcon"), MYSQL_STORAGE_ENGINE_PLUGIN);
+static sys_var_have_variable sys_have_geometry(&vars, "have_geometry", &have_geometry);
+static sys_var_have_plugin sys_have_innodb(&vars, "have_innodb", C_STRING_WITH_LEN("innodb"), MYSQL_STORAGE_ENGINE_PLUGIN);
+static sys_var_have_plugin sys_have_ndbcluster(&vars, "have_ndbcluster", C_STRING_WITH_LEN("ndbcluster"), MYSQL_STORAGE_ENGINE_PLUGIN);
+static sys_var_have_variable sys_have_openssl(&vars, "have_openssl", &have_ssl);
+static sys_var_have_variable sys_have_ssl(&vars, "have_ssl", &have_ssl);
+static sys_var_have_plugin sys_have_partition_db(&vars, "have_partitioning", C_STRING_WITH_LEN("partition"), MYSQL_STORAGE_ENGINE_PLUGIN);
+static sys_var_have_variable sys_have_query_cache(&vars, "have_query_cache",
                                            &have_query_cache);
-sys_var_have_variable sys_have_rtree_keys("have_rtree_keys", &have_rtree_keys);
-sys_var_have_variable sys_have_symlink("have_symlink", &have_symlink);
+static sys_var_have_variable sys_have_rtree_keys(&vars, "have_rtree_keys", &have_rtree_keys);
+static sys_var_have_variable sys_have_symlink(&vars, "have_symlink", &have_symlink);
 /* Global read-only variable describing server license */
-sys_var_const_str		sys_license("license", STRINGIFY_ARG(LICENSE));
+static sys_var_const_str	sys_license(&vars, "license", STRINGIFY_ARG(LICENSE));
 /* Global variables which enable|disable logging */
-sys_var_log_state sys_var_general_log("general_log", &opt_log,
+static sys_var_log_state sys_var_general_log(&vars, "general_log", &opt_log,
                                       QUERY_LOG_GENERAL);
-sys_var_log_state sys_var_slow_query_log("slow_query_log", &opt_slow_log,
+static sys_var_log_state sys_var_slow_query_log(&vars, "slow_query_log", &opt_slow_log,
                                          QUERY_LOG_SLOW);
-sys_var_str sys_var_general_log_path("general_log_file", sys_check_log_path,
+sys_var_str sys_var_general_log_path(&vars, "general_log_file", sys_check_log_path,
 				     sys_update_general_log_path,
 				     sys_default_general_log_path,
 				     opt_logname);
-sys_var_str sys_var_slow_log_path("slow_query_log_file", sys_check_log_path,
+sys_var_str sys_var_slow_log_path(&vars, "slow_query_log_file", sys_check_log_path,
 				  sys_update_slow_log_path, 
 				  sys_default_slow_log_path,
 				  opt_slow_logname);
-sys_var_log_output sys_var_log_output_state("log_output", &log_output_options,
+static sys_var_log_output sys_var_log_output_state(&vars, "log_output", &log_output_options,
 					    &log_output_typelib, 0);
 
-#ifdef HAVE_REPLICATION
-static int show_slave_skip_errors(THD *thd, SHOW_VAR *var, char *buff)
-{
-  var->type=SHOW_CHAR;
-  var->value= buff;
-  if (!use_slave_mask || bitmap_is_clear_all(&slave_error_mask))
-  {
-    var->value= const_cast<char *>("OFF");
-  }
-  else if (bitmap_is_set_all(&slave_error_mask))
-  {
-    var->value= const_cast<char *>("ALL");
-  }
-  else
-  {
-    /* 10 is enough assuming errors are max 4 digits */
-    int i;
-    var->value= buff;
-    for (i= 1;
-         i < MAX_SLAVE_ERROR &&
-         (buff - var->value) < SHOW_VAR_FUNC_BUFF_SIZE;
-         i++)
-    {
-      if (bitmap_is_set(&slave_error_mask, i))
-      {
-        buff= int10_to_str(i, buff, 10);
-        *buff++= ',';
-      }
-    }
-    if (var->value != buff)
-      buff--;				// Remove last ','
-    if (i < MAX_SLAVE_ERROR)
-      buff= strmov(buff, "...");  // Couldn't show all errors
-    *buff=0;
-  }
-  return 0;
-}
-#endif /* HAVE_REPLICATION */
 
 /*
-  Variables shown by SHOW VARIABLES in alphabetical order
-*/
-
-SHOW_VAR init_vars[]= {
-  {"auto_increment_increment", (char*) &sys_auto_increment_increment, SHOW_SYS},
-  {"auto_increment_offset",   (char*) &sys_auto_increment_offset, SHOW_SYS},
-  {sys_automatic_sp_privileges.name,(char*) &sys_automatic_sp_privileges,       SHOW_SYS},
+  Additional variables (not derived from sys_var class, not accessible as
+  @@varname in SELECT or SET). Sorted in alphabetical order to facilitate
+  maintenance - SHOW VARIABLES will sort its output.
+  TODO: remove this list completelydefine FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(SHOW_VAR))
+static SHOW_VAR fixed_vars[]= {
   {"back_log",                (char*) &back_log,                    SHOW_LONG},
-  {sys_basedir.name,          (char*) &sys_basedir,                 SHOW_SYS},
-  {sys_binlog_cache_size.name,(char*) &sys_binlog_cache_size,	    SHOW_SYS},
-  {sys_binlog_format.name,    (char*) &sys_binlog_format,	    SHOW_SYS},
-  {sys_bulk_insert_buff_size.name,(char*) &sys_bulk_insert_buff_size,SHOW_SYS},
-  {sys_character_set_client.name,(char*) &sys_character_set_client, SHOW_SYS},
-  {sys_character_set_connection.name,(char*) &sys_character_set_connection,SHOW_SYS},
-  {sys_character_set_database.name, (char*) &sys_character_set_database,SHOW_SYS},
-  {sys_character_set_filesystem.name,(char*) &sys_character_set_filesystem, SHOW_SYS},
-  {sys_character_set_results.name,(char*) &sys_character_set_results, SHOW_SYS},
-  {sys_character_set_server.name, (char*) &sys_character_set_server,SHOW_SYS},
-  {sys_charset_system.name,   (char*) &sys_charset_system,          SHOW_SYS},
   {"character_sets_dir",      mysql_charsets_dir,                   SHOW_CHAR},
-  {sys_collation_connection.name,(char*) &sys_collation_connection, SHOW_SYS},
-  {sys_collation_database.name,(char*) &sys_collation_database,     SHOW_SYS},
-  {sys_collation_server.name,(char*) &sys_collation_server,         SHOW_SYS},
-  {sys_completion_type.name,  (char*) &sys_completion_type,	    SHOW_SYS},
-  {sys_concurrent_insert.name,(char*) &sys_concurrent_insert,       SHOW_SYS},
-  {sys_connect_timeout.name,  (char*) &sys_connect_timeout,         SHOW_SYS},
-  {sys_datadir.name,          (char*) &sys_datadir,                 SHOW_SYS},
-  {sys_date_format.name,      (char*) &sys_date_format,		    SHOW_SYS},
-  {sys_datetime_format.name,  (char*) &sys_datetime_format,	    SHOW_SYS},
-#ifndef DBUG_OFF
-  {sys_dbug.name,             (char*) &sys_dbug,                    SHOW_SYS},
-#endif
-  {sys_default_week_format.name, (char*) &sys_default_week_format,  SHOW_SYS},
-  {sys_delay_key_write.name,  (char*) &sys_delay_key_write,         SHOW_SYS},
-  {sys_delayed_insert_limit.name, (char*) &sys_delayed_insert_limit,SHOW_SYS},
-  {sys_delayed_insert_timeout.name, (char*) &sys_delayed_insert_timeout, SHOW_SYS},
-  {sys_delayed_queue_size.name,(char*) &sys_delayed_queue_size,     SHOW_SYS},
-  {sys_div_precincrement.name,(char*) &sys_div_precincrement,SHOW_SYS},
-  {sys_engine_condition_pushdown.name,
-   (char*) &sys_engine_condition_pushdown,                          SHOW_SYS},
-  {sys_event_scheduler.name,  (char*) &sys_event_scheduler,         SHOW_SYS},
-  {sys_expire_logs_days.name, (char*) &sys_expire_logs_days,        SHOW_SYS},
   {"falcon_log_dir",		  (char*) &falcon_log_dir,				SHOW_CHAR_PTR},
   {"falcon_max_record_memory",(char*) &falcon_max_record_memory,	SHOW_LONGLONG},
   {"falcon_min_record_memory",(char*) &falcon_min_record_memory,	SHOW_LONGLONG},
@@ -804,274 +678,49 @@
   {"falcon_log_mask",		  (char*) &falcon_log_mask,				SHOW_INT},
   {"falcon_debug_server",		(char*) &falcon_debug_server,		SHOW_MY_BOOL},
   {"falcon_page_size",		  (char*) &falcon_page_size,			SHOW_INT},
-  {sys_flush.name,             (char*) &sys_flush,                  SHOW_SYS},
-  {sys_flush_time.name,        (char*) &sys_flush_time,             SHOW_SYS},
-  {sys_ft_boolean_syntax.name,(char*) &ft_boolean_syntax,	    SHOW_CHAR},
   {"ft_max_word_len",         (char*) &ft_max_word_len,             SHOW_LONG},
   {"ft_min_word_len",         (char*) &ft_min_word_len,             SHOW_LONG},
   {"ft_query_expansion_limit",(char*) &ft_query_expansion_limit,    SHOW_LONG},
   {"ft_stopword_file",        (char*) &ft_stopword_file,            SHOW_CHAR_PTR},
-  {sys_var_general_log.name, (char*) &opt_log,                      SHOW_MY_BOOL},
-  {sys_var_general_log_path.name, (char*) &sys_var_general_log_path,  SHOW_SYS},
-  {sys_group_concat_max_len.name, (char*) &sys_group_concat_max_len,  SHOW_SYS},
-  {sys_hostname.name,         (char*) &sys_hostname,                SHOW_SYS},
-  {sys_have_compress.name,    (char*) &have_compress,               SHOW_HAVE},
-  {sys_have_crypt.name,       (char*) &have_crypt,                  SHOW_HAVE},
-  {sys_have_csv_db.name,      (char*) &have_csv_db,                 SHOW_HAVE},
-  {sys_have_dlopen.name,      (char*) &have_dlopen,                 SHOW_HAVE},
-  {sys_have_falcon.name,      (char*) &have_falcon,                 SHOW_HAVE},
-  {sys_have_geometry.name,    (char*) &have_geometry,               SHOW_HAVE},
-  {sys_have_innodb.name,      (char*) &have_innodb,                 SHOW_HAVE},
-  {sys_have_ndbcluster.name,  (char*) &have_ndbcluster,             SHOW_HAVE},
-  {sys_have_openssl.name,     (char*) &have_ssl,                    SHOW_HAVE},
-  {sys_have_ssl.name,         (char*) &have_ssl,                    SHOW_HAVE},
-  {sys_have_partition_db.name,(char*) &have_partition_db,           SHOW_HAVE},
-  {sys_have_query_cache.name, (char*) &have_query_cache,            SHOW_HAVE},
-  {sys_have_rtree_keys.name,  (char*) &have_rtree_keys,             SHOW_HAVE},
-  {sys_have_symlink.name,     (char*) &have_symlink,                SHOW_HAVE},
-  {"init_connect",            (char*) &sys_init_connect,            SHOW_SYS},
   {"init_file",               (char*) &opt_init_file,               SHOW_CHAR_PTR},
-  {"init_slave",              (char*) &sys_init_slave,              SHOW_SYS},
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
-  {"innodb_additional_mem_pool_size", (char*) &innobase_additional_mem_pool_size, SHOW_LONG },
-  {sys_innodb_autoextend_increment.name, (char*) &sys_innodb_autoextend_increment, SHOW_SYS},
-  {"innodb_buffer_pool_size", (char*) &innobase_buffer_pool_size, SHOW_LONGLONG },
-  {"innodb_checksums", (char*) &innobase_use_checksums, SHOW_MY_BOOL},
-  {sys_innodb_commit_concurrency.name, (char*) &sys_innodb_commit_concurrency, SHOW_SYS},
-  {sys_innodb_concurrency_tickets.name, (char*) &sys_innodb_concurrency_tickets, SHOW_SYS},
-  {"innodb_data_file_path", (char*) &innobase_data_file_path,	    SHOW_CHAR_PTR},
-  {"innodb_data_home_dir",  (char*) &innobase_data_home_dir,	    SHOW_CHAR_PTR},
-  {"innodb_doublewrite", (char*) &innobase_use_doublewrite, SHOW_MY_BOOL},
-  {sys_innodb_fast_shutdown.name,(char*) &sys_innodb_fast_shutdown, SHOW_SYS},
-  {"innodb_file_io_threads", (char*) &innobase_file_io_threads, SHOW_LONG },
-  {"innodb_file_per_table", (char*) &innobase_file_per_table, SHOW_MY_BOOL},
-  {"innodb_flush_method",    (char*) &innobase_unix_file_flush_method, SHOW_CHAR_PTR},
-  {"innodb_force_recovery", (char*) &innobase_force_recovery, SHOW_LONG },
-  {"innodb_lock_wait_timeout", (char*) &innobase_lock_wait_timeout, SHOW_LONG },
-  {"innodb_locks_unsafe_for_binlog", (char*) &innobase_locks_unsafe_for_binlog, SHOW_MY_BOOL},
-  {"innodb_log_arch_dir",   (char*) &innobase_log_arch_dir, 	    SHOW_CHAR_PTR},
-  {"innodb_log_archive",    (char*) &innobase_log_archive, 	    SHOW_MY_BOOL},
-  {"innodb_log_buffer_size", (char*) &innobase_log_buffer_size, SHOW_LONG },
-  {"innodb_log_file_size", (char*) &innobase_log_file_size, SHOW_LONGLONG},
-  {"innodb_log_files_in_group", (char*) &innobase_log_files_in_group,	SHOW_LONG},
-  {"innodb_log_group_home_dir", (char*) &innobase_log_group_home_dir, SHOW_CHAR_PTR},
-  {sys_innodb_max_dirty_pages_pct.name, (char*) &sys_innodb_max_dirty_pages_pct, SHOW_SYS},
-  {sys_innodb_max_purge_lag.name, (char*) &sys_innodb_max_purge_lag, SHOW_SYS},
-  {"innodb_mirrored_log_groups", (char*) &innobase_mirrored_log_groups, SHOW_LONG},
-  {"innodb_open_files", (char*) &innobase_open_files, SHOW_LONG },
-  {"innodb_rollback_on_timeout", (char*) &innobase_rollback_on_timeout, SHOW_MY_BOOL},
-  {"innodb_stats_on_metadata", (char*) &innobase_stats_on_metadata, SHOW_MY_BOOL},
-  {sys_innodb_support_xa.name, (char*) &sys_innodb_support_xa, SHOW_SYS},
-  {sys_innodb_sync_spin_loops.name, (char*) &sys_innodb_sync_spin_loops, SHOW_SYS},
-  {sys_innodb_table_locks.name, (char*) &sys_innodb_table_locks, SHOW_SYS},
-  {sys_innodb_thread_concurrency.name, (char*) &sys_innodb_thread_concurrency, SHOW_SYS},
-  {sys_innodb_thread_sleep_delay.name, (char*) &sys_innodb_thread_sleep_delay, SHOW_SYS},
-  {sys_innodb_flush_log_at_trx_commit.name, (char*) &sys_innodb_flush_log_at_trx_commit, SHOW_SYS},
-#endif
-  {sys_interactive_timeout.name,(char*) &sys_interactive_timeout,   SHOW_SYS},
-  {sys_join_buffer_size.name,   (char*) &sys_join_buffer_size,	    SHOW_SYS},
-  {sys_key_buffer_size.name,	(char*) &sys_key_buffer_size,	    SHOW_SYS},
-  {sys_key_cache_age_threshold.name,   (char*) &sys_key_cache_age_threshold,
-                                                                    SHOW_SYS},
-  {sys_key_cache_block_size.name,   (char*) &sys_key_cache_block_size,
-                                                                    SHOW_SYS},
-  {sys_key_cache_division_limit.name,   (char*) &sys_key_cache_division_limit,
-                                                                    SHOW_SYS},
   {"language",                language,                             SHOW_CHAR},
   {"large_files_support",     (char*) &opt_large_files,             SHOW_BOOL},
   {"large_page_size",         (char*) &opt_large_page_size,         SHOW_INT},
   {"large_pages",             (char*) &opt_large_pages,             SHOW_MY_BOOL},
-  {sys_lc_time_names.name,    (char*) &sys_lc_time_names,           SHOW_SYS},
-  {sys_license.name,	      (char*) &sys_license,                 SHOW_SYS},
-  {sys_local_infile.name,     (char*) &sys_local_infile,	    SHOW_SYS},
 #ifdef HAVE_MLOCKALL
-  {"locked_in_memory",	      (char*) &locked_in_memory,	    SHOW_BOOL},
+  {"locked_in_memory",	      (char*) &locked_in_memory,	    SHOW_MY_BOOL},
 #endif
-  {"log",                     (char*) &opt_log,                     SHOW_BOOL},
+  {"log",                     (char*) &opt_log,                     SHOW_MY_BOOL},
   {"log_bin",                 (char*) &opt_bin_log,                 SHOW_BOOL},
-  {sys_trust_function_creators.name,(char*) &sys_trust_function_creators, SHOW_SYS},
   {"log_error",               (char*) log_error_file,               SHOW_CHAR},
-  {sys_var_log_output_state.name, (char*) &sys_var_log_output_state, SHOW_SYS},
-  {sys_log_queries_not_using_indexes.name,
-    (char*) &sys_log_queries_not_using_indexes, SHOW_SYS},
-#ifdef HAVE_REPLICATION
-  {"log_slave_updates",       (char*) &opt_log_slave_updates,       SHOW_MY_BOOL},
-#endif
   {"log_slow_queries",        (char*) &opt_slow_log,                SHOW_MY_BOOL},
-  {sys_log_warnings.name,     (char*) &sys_log_warnings,	    SHOW_SYS},
-  {sys_long_query_time.name,  (char*) &sys_long_query_time, 	    SHOW_SYS},
-  {sys_low_priority_updates.name, (char*) &sys_low_priority_updates, SHOW_SYS},
   {"lower_case_file_system",  (char*) &lower_case_file_system,      SHOW_MY_BOOL},
   {"lower_case_table_names",  (char*) &lower_case_table_names,      SHOW_INT},
-  {sys_max_allowed_packet.name,(char*) &sys_max_allowed_packet,	    SHOW_SYS},
-  {sys_max_binlog_cache_size.name,(char*) &sys_max_binlog_cache_size, SHOW_SYS},
-  {sys_max_binlog_size.name,    (char*) &sys_max_binlog_size,	    SHOW_SYS},
-  {sys_max_connect_errors.name, (char*) &sys_max_connect_errors,    SHOW_SYS},
-  {sys_max_connections.name,    (char*) &sys_max_connections,	    SHOW_SYS},
-  {sys_max_delayed_threads.name,(char*) &sys_max_delayed_threads,   SHOW_SYS},
-  {sys_max_error_count.name,	(char*) &sys_max_error_count,	    SHOW_SYS},
-  {sys_max_heap_table_size.name,(char*) &sys_max_heap_table_size,   SHOW_SYS},
-  {sys_max_insert_delayed_threads.name,
-   (char*) &sys_max_insert_delayed_threads,   SHOW_SYS},
-  {sys_max_join_size.name,	(char*) &sys_max_join_size,	    SHOW_SYS},
-  {sys_max_length_for_sort_data.name, (char*) &sys_max_length_for_sort_data,
-   SHOW_SYS},
-  {sys_max_prepared_stmt_count.name, (char*) &sys_max_prepared_stmt_count,
-    SHOW_SYS},
-  {sys_max_relay_log_size.name, (char*) &sys_max_relay_log_size,    SHOW_SYS},
-  {sys_max_seeks_for_key.name,  (char*) &sys_max_seeks_for_key,	    SHOW_SYS},
-  {sys_max_sort_length.name,	(char*) &sys_max_sort_length,	    SHOW_SYS},
-  {sys_max_sp_recursion_depth.name,
-    (char*) &sys_max_sp_recursion_depth, SHOW_SYS},
-  {sys_max_tmp_tables.name,	(char*) &sys_max_tmp_tables,	    SHOW_SYS},
-  {sys_max_user_connections.name,(char*) &sys_max_user_connections, SHOW_SYS},
-  {sys_max_write_lock_count.name, (char*) &sys_max_write_lock_count,SHOW_SYS},
-  {sys_multi_range_count.name,  (char*) &sys_multi_range_count,     SHOW_SYS},
-  {sys_myisam_data_pointer_size.name, (char*) &sys_myisam_data_pointer_size, SHOW_SYS},
-  {sys_myisam_max_sort_file_size.name, (char*) &sys_myisam_max_sort_file_size,
-   SHOW_SYS},
   {"myisam_recover_options",  (char*) &myisam_recover_options_str,  SHOW_CHAR_PTR},
-  {sys_myisam_repair_threads.name, (char*) &sys_myisam_repair_threads,
-   SHOW_SYS},
-  {sys_myisam_sort_buffer_size.name, (char*) &sys_myisam_sort_buffer_size, SHOW_SYS},
-  
-  {sys_myisam_stats_method.name, (char*) &sys_myisam_stats_method, SHOW_SYS},
-  {sys_myisam_use_mmap.name, (char*) &sys_myisam_use_mmap, SHOW_SYS},
-  
 #ifdef __NT__
   {"named_pipe",	      (char*) &opt_enable_named_pipe,       SHOW_MY_BOOL},
 #endif
-  {sys_ndb_autoincrement_prefetch_sz.name,
-   (char*) &sys_ndb_autoincrement_prefetch_sz,                      SHOW_SYS},
-  {sys_ndb_cache_check_time.name,(char*) &sys_ndb_cache_check_time, SHOW_SYS},
-  {sys_ndb_extra_logging.name,(char*) &sys_ndb_extra_logging,       SHOW_SYS},
-  {sys_ndb_force_send.name,   (char*) &sys_ndb_force_send,          SHOW_SYS},
-  {sys_ndb_index_stat_cache_entries.name, (char*) &sys_ndb_index_stat_cache_entries, SHOW_SYS},
-  {sys_ndb_index_stat_enable.name, (char*) &sys_ndb_index_stat_enable, SHOW_SYS},
-  {sys_ndb_index_stat_update_freq.name, (char*) &sys_ndb_index_stat_update_freq, SHOW_SYS},
-#ifdef HAVE_NDB_BINLOG
-  {sys_ndb_report_thresh_binlog_epoch_slip.name,
-   (char*) &sys_ndb_report_thresh_binlog_epoch_slip,                SHOW_SYS},
-  {sys_ndb_report_thresh_binlog_mem_usage.name,
-   (char*) &sys_ndb_report_thresh_binlog_mem_usage,                 SHOW_SYS},
-#endif
-  {sys_ndb_use_copying_alter_table.name,
-   (char*) &sys_ndb_use_copying_alter_table,                        SHOW_SYS},
-  {sys_ndb_use_exact_count.name,(char*) &sys_ndb_use_exact_count,   SHOW_SYS},
-  {sys_ndb_use_transactions.name,(char*) &sys_ndb_use_transactions, SHOW_SYS},
-  {sys_net_buffer_length.name,(char*) &sys_net_buffer_length,       SHOW_SYS},
-  {sys_net_read_timeout.name, (char*) &sys_net_read_timeout,        SHOW_SYS},
-  {sys_net_retry_count.name,  (char*) &sys_net_retry_count,	    SHOW_SYS},
-  {sys_net_write_timeout.name,(char*) &sys_net_write_timeout,       SHOW_SYS},
-  {sys_new_mode.name,         (char*) &sys_new_mode,                SHOW_SYS},
-  {sys_old_mode.name,         (char*) &sys_old_mode,                SHOW_SYS},
-  {sys_old_alter_table.name,  (char*) &sys_old_alter_table,         SHOW_SYS},
-  {sys_old_passwords.name,    (char*) &sys_old_passwords,           SHOW_SYS},
   {"open_files_limit",	      (char*) &open_files_limit,	    SHOW_LONG},
-  {sys_optimizer_prune_level.name, (char*) &sys_optimizer_prune_level,
-   SHOW_SYS},
-  {sys_optimizer_search_depth.name,(char*) &sys_optimizer_search_depth,
-   SHOW_SYS},
   {"pid_file",                (char*) pidfile_name,                 SHOW_CHAR},
   {"plugin_dir",              (char*) opt_plugin_dir,               SHOW_CHAR},
-  {"port",                    (char*) &mysqld_port,                  SHOW_INT},
-  {sys_preload_buff_size.name, (char*) &sys_preload_buff_size,      SHOW_SYS},
+  {"port",                    (char*) &mysqld_port,                 SHOW_INT},
   {"protocol_version",        (char*) &protocol_version,            SHOW_INT},
-  {sys_query_alloc_block_size.name, (char*) &sys_query_alloc_block_size,
-   SHOW_SYS},
-#ifdef HAVE_QUERY_CACHE
-  {sys_query_cache_limit.name,(char*) &sys_query_cache_limit,	    SHOW_SYS},
-  {sys_query_cache_min_res_unit.name, (char*) &sys_query_cache_min_res_unit,
-   SHOW_SYS},
-  {sys_query_cache_size.name, (char*) &sys_query_cache_size,	    SHOW_SYS},
-  {sys_query_cache_type.name, (char*) &sys_query_cache_type,        SHOW_SYS},
-  {sys_query_cache_wlock_invalidate.name,
-   (char *) &sys_query_cache_wlock_invalidate, SHOW_SYS},
-#endif /* HAVE_QUERY_CACHE */
-  {sys_query_prealloc_size.name, (char*) &sys_query_prealloc_size,  SHOW_SYS},
-  {sys_range_alloc_block_size.name, (char*) &sys_range_alloc_block_size,
-   SHOW_SYS},
-  {sys_read_buff_size.name,   (char*) &sys_read_buff_size,	    SHOW_SYS},
-  {sys_readonly.name,         (char*) &sys_readonly,                SHOW_SYS},
-  {sys_read_rnd_buff_size.name,(char*) &sys_read_rnd_buff_size,	    SHOW_SYS},
-#ifdef HAVE_REPLICATION
-  {sys_relay_log_purge.name,  (char*) &sys_relay_log_purge,         SHOW_SYS},
-  {"relay_log_space_limit",  (char*) &relay_log_space_limit,        SHOW_LONGLONG},
-#endif
-  {sys_rpl_recovery_rank.name,(char*) &sys_rpl_recovery_rank,       SHOW_SYS},
-  {"secure_auth",             (char*) &sys_secure_auth,             SHOW_SYS},
-  {"secure_file_priv",        (char*) &sys_secure_file_priv,        SHOW_SYS},
 #ifdef HAVE_SMEM
   {"shared_memory",           (char*) &opt_enable_shared_memory,    SHOW_MY_BOOL},
   {"shared_memory_base_name", (char*) &shared_memory_base_name,     SHOW_CHAR_PTR},
 #endif
-  {sys_server_id.name,	      (char*) &sys_server_id,		    SHOW_SYS},
   {"skip_external_locking",   (char*) &my_disable_locking,          SHOW_MY_BOOL},
   {"skip_networking",         (char*) &opt_disable_networking,      SHOW_BOOL},
   {"skip_show_database",      (char*) &opt_skip_show_db,            SHOW_BOOL},
-#ifdef HAVE_REPLICATION
-  {sys_slave_compressed_protocol.name,
-    (char*) &sys_slave_compressed_protocol,           SHOW_SYS},
-  {"slave_load_tmpdir",       (char*) &slave_load_tmpdir,           SHOW_CHAR_PTR},
-  {sys_slave_net_timeout.name,(char*) &sys_slave_net_timeout,	    SHOW_SYS},
-  {"slave_skip_errors",       (char*) &show_slave_skip_errors,      SHOW_FUNC},
-  {sys_slave_trans_retries.name,(char*) &sys_slave_trans_retries,   SHOW_SYS},
-#endif
-  {sys_slow_launch_time.name, (char*) &sys_slow_launch_time,        SHOW_SYS},
-  {sys_var_slow_query_log.name, (char*) &opt_slow_log,              SHOW_MY_BOOL},
-  {sys_var_slow_log_path.name, (char*) &sys_var_slow_log_path,      SHOW_SYS},
 #ifdef HAVE_SYS_UN_H
-  {"socket",                  (char*) &mysqld_unix_port,             SHOW_CHAR_PTR},
-#endif
-  {sys_sort_buffer.name,      (char*) &sys_sort_buffer,             SHOW_SYS},
-  {sys_big_selects.name,      (char*) &sys_big_selects,             SHOW_SYS},
-  {sys_sql_mode.name,         (char*) &sys_sql_mode,                SHOW_SYS},
-  {"sql_notes",               (char*) &sys_sql_notes,               SHOW_SYS},
-  {"sql_warnings",            (char*) &sys_sql_warnings,            SHOW_SYS},
-  {sys_ssl_ca.name,           (char*) &sys_ssl_ca,                  SHOW_SYS},
-  {sys_ssl_capath.name,       (char*) &sys_ssl_capath,              SHOW_SYS},
-  {sys_ssl_cert.name,         (char*) &sys_ssl_cert,                SHOW_SYS},
-  {sys_ssl_cipher.name,       (char*) &sys_ssl_cipher,              SHOW_SYS},
-  {sys_ssl_key.name,          (char*) &sys_ssl_key,                 SHOW_SYS},
-  {sys_storage_engine.name,   (char*) &sys_storage_engine,          SHOW_SYS},
-#ifdef HAVE_REPLICATION
-  {sys_sync_binlog_period.name,(char*) &sys_sync_binlog_period,     SHOW_SYS},
-#endif
-  {sys_sync_frm.name,         (char*) &sys_sync_frm,               SHOW_SYS},
-#ifdef HAVE_TZNAME
-  {"system_time_zone",        system_time_zone,                     SHOW_CHAR},
+  {"socket",                  (char*) &mysqld_unix_port,            SHOW_CHAR_PTR},
 #endif
   {"table_definition_cache",  (char*) &table_def_size,              SHOW_LONG},
   {"table_lock_wait_timeout", (char*) &table_lock_wait_timeout,     SHOW_LONG },
-  {"table_open_cache",        (char*) &table_cache_size,            SHOW_LONG},
-  {sys_table_type.name,	      (char*) &sys_table_type,	            SHOW_SYS},
-  {sys_thread_cache_size.name,(char*) &sys_thread_cache_size,       SHOW_SYS},
 #ifdef HAVE_THR_SETCONCURRENCY
   {"thread_concurrency",      (char*) &concurrency,                 SHOW_LONG},
 #endif
-  {sys_thread_handling.name,  (char*) &sys_thread_handling,         SHOW_SYS},
-#if HAVE_POOL_OF_THREADS == 1
-  {sys_thread_pool_size.name, (char*) &sys_thread_pool_size,        SHOW_SYS},
-#endif
   {"thread_stack",            (char*) &thread_stack,                SHOW_LONG},
-  {sys_time_format.name,      (char*) &sys_time_format,		    SHOW_SYS},
-  {"time_zone",               (char*) &sys_time_zone,               SHOW_SYS},
-  {sys_timed_mutexes.name,    (char*) &sys_timed_mutexes,       SHOW_SYS},
-  {sys_tmp_table_size.name,   (char*) &sys_tmp_table_size,	    SHOW_SYS},
-  {sys_tmpdir.name,           (char*) &sys_tmpdir,	            SHOW_SYS},
-  {sys_trans_alloc_block_size.name, (char*) &sys_trans_alloc_block_size,
-   SHOW_SYS},
-  {sys_trans_prealloc_size.name, (char*) &sys_trans_prealloc_size,  SHOW_SYS},
-  {sys_tx_isolation.name,     (char*) &sys_tx_isolation,	    SHOW_SYS},
-  {sys_updatable_views_with_limit.name,
-                              (char*) &sys_updatable_views_with_limit,SHOW_SYS},
-  {sys_version.name,          (char*) &sys_version,                 SHOW_SYS},
-  {sys_version_comment.name,  (char*) &sys_version_comment,         SHOW_SYS},
-  {sys_version_compile_machine.name, (char*) &sys_version_compile_machine,
-   SHOW_SYS},
-  {sys_version_compile_os.name,	(char*) &sys_version_compile_os,    SHOW_SYS},
-  {sys_net_wait_timeout.name, (char*) &sys_net_wait_timeout,	    SHOW_SYS},
-  {NullS, NullS, SHOW_LONG}
 };
 
 
@@ -1366,7 +1015,8 @@
   /*
     Cluster does not support changing the binlog format on the fly yet.
   */
-  if (opt_bin_log && (have_ndbcluster == SHOW_OPTION_YES))
+  LEX_STRING ndb_name= {(char*)STRING_WITH_LEN("ndbcluster")};
+  if (opt_bin_log && plugin_is_ready(&ndb_name, MYSQL_STORAGE_ENGINE_PLUGIN))
   {
     my_error(ER_NDB_CANT_SWITCH_BINLOG_FORMAT, MYF(0));
     return 1;
@@ -1457,9 +1107,9 @@
 
 
 sys_var_long_ptr::
-sys_var_long_ptr(const char *name_arg, ulong *value_ptr_arg,
+sys_var_long_ptr(sys_var_chain *chain, const char *name_arg, ulong *value_ptr_arg,
                  sys_after_update_func after_update_arg)
-  :sys_var_long_ptr_global(name_arg, value_ptr_arg,
+  :sys_var_long_ptr_global(chain, name_arg, value_ptr_arg,
                            &LOCK_global_system_variables, after_update_arg)
 {}
 
@@ -1843,7 +1493,13 @@
     return new Item_int((longlong) value);
   }
   case SHOW_MY_BOOL:
-    return new Item_int((int32) *(my_bool*) value_ptr(thd, var_type, base),1);
+  {
+    int32 value;
+    pthread_mutex_lock(&LOCK_global_system_variables);
+    value= *(my_bool*) value_ptr(thd, var_type, base);
+    pthread_mutex_unlock(&LOCK_global_system_variables);
+    return new Item_int(value,1);
+  }
   case SHOW_CHAR:
   {
     Item *tmp;
@@ -2152,122 +1808,25 @@
 }
 
 
-CHARSET_INFO ** sys_var_character_set_connection::ci_ptr(THD *thd,
-							 enum_var_type type)
-{
-  if (type == OPT_GLOBAL)
-    return &global_system_variables.collation_connection;
-  else
-    return &thd->variables.collation_connection;
-}
-
-
-void sys_var_character_set_connection::set_default(THD *thd,
-						   enum_var_type type)
-{
- if (type == OPT_GLOBAL)
-   global_system_variables.collation_connection= default_charset_info;
- else
- {
-   thd->variables.collation_connection= global_system_variables.collation_connection;
-   thd->update_charset();
- }
-}
-
-
-CHARSET_INFO ** sys_var_character_set_client::ci_ptr(THD *thd,
-						     enum_var_type type)
+void sys_var_character_set_sv::set_default(THD *thd, enum_var_type type)
 {
   if (type == OPT_GLOBAL)
-    return &global_system_variables.character_set_client;
+    global_system_variables.*offset= *global_default;
   else
-    return &thd->variables.character_set_client;
-}
-
-
-void sys_var_character_set_client::set_default(THD *thd, enum_var_type type)
-{
- if (type == OPT_GLOBAL)
-   global_system_variables.character_set_client= default_charset_info;
- else
- {
-   thd->variables.character_set_client= (global_system_variables.
-					 character_set_client);
-   thd->update_charset();
- }
-}
-
-
-CHARSET_INFO **
-sys_var_character_set_filesystem::ci_ptr(THD *thd, enum_var_type type)
-{
-  if (type == OPT_GLOBAL)
-    return &global_system_variables.character_set_filesystem;
-  else
-    return &thd->variables.character_set_filesystem;
-}
-
-
-extern CHARSET_INFO *character_set_filesystem;
-
-void
-sys_var_character_set_filesystem::set_default(THD *thd, enum_var_type type)
-{
- if (type == OPT_GLOBAL)
-   global_system_variables.character_set_filesystem= character_set_filesystem;
- else
- {
-   thd->variables.character_set_filesystem= (global_system_variables.
-					     character_set_filesystem);
-   thd->update_charset();
- }
-}
-
-
-CHARSET_INFO **
-sys_var_character_set_results::ci_ptr(THD *thd, enum_var_type type)
-{
-  if (type == OPT_GLOBAL)
-    return &global_system_variables.character_set_results;
-  else
-    return &thd->variables.character_set_results;
-}
-
-
-void sys_var_character_set_results::set_default(THD *thd, enum_var_type type)
-{
- if (type == OPT_GLOBAL)
-   global_system_variables.character_set_results= default_charset_info;
- else
- {
-   thd->variables.character_set_results= (global_system_variables.
-					  character_set_results);
-   thd->update_charset();
- }
+  {
+    thd->variables.*offset= global_system_variables.*offset;
+    thd->update_charset();
+  }
 }
-
-
-CHARSET_INFO **
-sys_var_character_set_server::ci_ptr(THD *thd, enum_var_type type)
+CHARSET_INFO **sys_var_character_set_sv::ci_ptr(THD *thd, enum_var_type type)
 {
   if (type == OPT_GLOBAL)
-    return &global_system_variables.collation_server;
+    return &(global_system_variables.*offset);
   else
-    return &thd->variables.collation_server;
+    return &(thd->variables.*offset);
 }
 
 
-void sys_var_character_set_server::set_default(THD *thd, enum_var_type type)
-{
- if (type == OPT_GLOBAL)
-   global_system_variables.collation_server= default_charset_info;
- else
- {
-   thd->variables.collation_server= global_system_variables.collation_server;
-   thd->update_charset();
- }
-}
-
 CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd,
 						       enum_var_type type)
 {
@@ -2290,113 +1849,39 @@
 }
 
 
-bool sys_var_collation_connection::update(THD *thd, set_var *var)
-{
-  if (var->type == OPT_GLOBAL)
-    global_system_variables.collation_connection= var->save_result.charset;
-  else
-  {
-    thd->variables.collation_connection= var->save_result.charset;
-    thd->update_charset();
-  }
-  return 0;
-}
-
-
-byte *sys_var_collation_connection::value_ptr(THD *thd, enum_var_type type,
-					      LEX_STRING *base)
-{
-  CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
-		  global_system_variables.collation_connection :
-		  thd->variables.collation_connection);
-  return cs ? (byte*) cs->name : (byte*) "NULL";
-}
-
-
-void sys_var_collation_connection::set_default(THD *thd, enum_var_type type)
-{
- if (type == OPT_GLOBAL)
-   global_system_variables.collation_connection= default_charset_info;
- else
- {
-   thd->variables.collation_connection= (global_system_variables.
-					 collation_connection);
-   thd->update_charset();
- }
-}
-
-bool sys_var_collation_database::update(THD *thd, set_var *var)
+bool sys_var_collation_sv::update(THD *thd, set_var *var)
 {
   if (var->type == OPT_GLOBAL)
-    global_system_variables.collation_database= var->save_result.charset;
+    global_system_variables.*offset= var->save_result.charset;
   else
   {
-    thd->variables.collation_database= var->save_result.charset;
+    thd->variables.*offset= var->save_result.charset;
     thd->update_charset();
   }
   return 0;
 }
 
 
-byte *sys_var_collation_database::value_ptr(THD *thd, enum_var_type type,
-					      LEX_STRING *base)
-{
-  CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
-		  global_system_variables.collation_database :
-		  thd->variables.collation_database);
-  return cs ? (byte*) cs->name : (byte*) "NULL";
-}
-
-
-void sys_var_collation_database::set_default(THD *thd, enum_var_type type)
+void sys_var_collation_sv::set_default(THD *thd, enum_var_type type)
 {
- if (type == OPT_GLOBAL)
-   global_system_variables.collation_database= default_charset_info;
- else
- {
-   thd->variables.collation_database= (global_system_variables.
-					 collation_database);
-   thd->update_charset();
- }
-}
-
-
-bool sys_var_collation_server::update(THD *thd, set_var *var)
-{
-  if (var->type == OPT_GLOBAL)
-    global_system_variables.collation_server= var->save_result.charset;
+  if (type == OPT_GLOBAL)
+    global_system_variables.*offset= *global_default;
   else
   {
-    thd->variables.collation_server= var->save_result.charset;
+    thd->variables.*offset= global_system_variables.*offset;
     thd->update_charset();
   }
-  return 0;
 }
 
 
-byte *sys_var_collation_server::value_ptr(THD *thd, enum_var_type type,
-					      LEX_STRING *base)
+byte *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 {
   CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
-		  global_system_variables.collation_server :
-		  thd->variables.collation_server);
+		  global_system_variables.*offset : thd->variables.*offset);
   return cs ? (byte*) cs->name : (byte*) "NULL";
 }
 
 
-void sys_var_collation_server::set_default(THD *thd, enum_var_type type)
-{
- if (type == OPT_GLOBAL)
-   global_system_variables.collation_server= default_charset_info;
- else
- {
-   thd->variables.collation_server= (global_system_variables.
-					 collation_server);
-   thd->update_charset();
- }
-}
-
-
 LEX_STRING default_key_cache_base= {(char *) "default", 7 };
 
 static KEY_CACHE zero_key_cache;
@@ -2838,52 +2323,6 @@
 }
 
 
-#ifdef HAVE_REPLICATION
-bool sys_var_slave_skip_counter::check(THD *thd, set_var *var)
-{
-  int result= 0;
-  pthread_mutex_lock(&LOCK_active_mi);
-  pthread_mutex_lock(&active_mi->rli.run_lock);
-  if (active_mi->rli.slave_running)
-  {
-    my_message(ER_SLAVE_MUST_STOP, ER(ER_SLAVE_MUST_STOP), MYF(0));
-    result=1;
-  }
-  pthread_mutex_unlock(&active_mi->rli.run_lock);
-  pthread_mutex_unlock(&LOCK_active_mi);
-  var->save_result.ulong_value= (ulong) var->value->val_int();
-  return result;
-}
-
-
-bool sys_var_slave_skip_counter::update(THD *thd, set_var *var)
-{
-  pthread_mutex_lock(&LOCK_active_mi);
-  pthread_mutex_lock(&active_mi->rli.run_lock);
-  /*
-    The following test should normally never be true as we test this
-    in the check function;  To be safe against multiple
-    SQL_SLAVE_SKIP_COUNTER request, we do the check anyway
-  */
-  if (!active_mi->rli.slave_running)
-  {
-    pthread_mutex_lock(&active_mi->rli.data_lock);
-    active_mi->rli.slave_skip_counter= var->save_result.ulong_value;
-    pthread_mutex_unlock(&active_mi->rli.data_lock);
-  }
-  pthread_mutex_unlock(&active_mi->rli.run_lock);
-  pthread_mutex_unlock(&LOCK_active_mi);
-  return 0;
-}
-
-
-bool sys_var_sync_binlog_period::update(THD *thd, set_var *var)
-{
-  sync_binlog_period= (ulong) var->save_result.ulonglong_value;
-  return 0;
-}
-#endif /* HAVE_REPLICATION */
-
 bool sys_var_rand_seed1::update(THD *thd, set_var *var)
 {
   thd->rand.seed1= (ulong) var->save_result.ulonglong_value;
@@ -3273,22 +2712,151 @@
 
 
 /*
-  Initialises sys variables and put them in system_variable_hash
+  Add variables to the dynamic hash of system variables
+  
+  SYNOPSIS
+    mysql_add_sys_var_chain()
+    first       Pointer to first system variable to add
+    long_opt    (optional)command line arguments may be tied for limit checks.
+  
+  RETURN VALUES
+    0           SUCCESS
+    otherwise   FAILURE
 */
 
-
-void set_var_init()
+int mysql_add_sys_var_chain(sys_var *first, struct my_option *long_options)
 {
   sys_var *var;
-
-  hash_init(&system_variable_hash, system_charset_info, sys_var::sys_vars, 0,
-	    0, (hash_get_key) get_sys_var_length, 0, 0);
-  for (var= sys_var::first; var; var= var->next)
+  
+  /* A write lock should be held on LOCK_system_variables_hash */
+  
+  for (var= first; var; var= var->next)
   {
     var->name_length= strlen(var->name);
-    var->option_limits= find_option(my_long_options, var->name);
-    my_hash_insert(&system_variable_hash, (byte*) var);
+    /* this fails if there is a conflicting variable name. see HASH_UNIQUE */
+    if (my_hash_insert(&system_variable_hash, (byte*) var))
+      goto error;
+    if (long_options)
+      var->option_limits= find_option(long_options, var->name);
   }
+  return 0;
+
+error:
+  for (; first != var; first= first->next)
+    hash_delete(&system_variable_hash, (byte*) first);
+  return 1;
+}
+
+
+/*
+  Remove variables to the dynamic hash of system variables
+  
+  SYNOPSIS
+    mysql_del_sys_var_chain()
+    first       Pointer to first system variable to remove
+  
+  RETURN VALUES
+    0           SUCCESS
+    otherwise   FAILURE
+*/
+
+int mysql_del_sys_var_chain(sys_var *first)
+{
+  int result= 0;
+
+  /* A write lock should be held on LOCK_system_variables_hash */
+  
+  for (sys_var *var= first; var; var= var->next)
+    result|= hash_delete(&system_variable_hash, (byte*) var);
+
+  return result;
+}
+
+
+static int show_cmp(SHOW_VAR *a, SHOW_VAR *b)
+{
+  return strcmp(a->name, b->name);
+}
+
+
+/*
+  Constructs an array of system variables for display to the user.
+  
+  SYNOPSIS
+    enumerate_sys_vars()
+    thd         current thread
+    sorted      If TRUE, the system variables should be sorted
+  
+  RETURN VALUES
+    pointer     Array of SHOW_VAR elements for display
+    NULL        FAILURE
+*/
+
+SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted)
+{
+  int count= system_variable_hash.records, i;
+  int fixed_count= fixed_show_vars.elements;
+  int size= sizeof(SHOW_VAR) * (count + fixed_count + 1);
+  SHOW_VAR *result= (SHOW_VAR*) thd->alloc(size);
+
+  if (result)
+  {
+    SHOW_VAR *show= result + fixed_count;
+    memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(SHOW_VAR));
+
+    for (i= 0; i < count; i++)
+    {
+      sys_var *var= (sys_var*) hash_element(&system_variable_hash, i);
+      show->name= var->name;
+      show->value= (char*) var;
+      show->type= SHOW_SYS;
+      show++;
+    }
+
+    /* sort into order */
+    if (sorted)
+      qsort(result, count + fixed_count, sizeof(SHOW_VAR), (qsort_cmp)show_cmp);
+    
+    /* make last element empty */
+    bzero(show, sizeof(SHOW_VAR));
+  }
+  return result;
+}
+
+
+/*
+  Initialize the system variables
+  
+  SYNOPSIS
+    set_var_init()
+  
+  RETURN VALUES
+    0           SUCCESS
+    otherwise   FAILURE
+*/
+
+int set_var_init()
+{
+  uint count= 0;
+  DBUG_ENTER("set_var_init");
+  
+  for (sys_var *var=vars.first; var; var= var->next, count++);
+
+  if (my_init_dynamic_array(&fixed_show_vars, sizeof(SHOW_VAR),
+                            FIXED_VARS_SIZE + 64, 64))
+    goto error;
+
+  fixed_show_vars.elements= FIXED_VARS_SIZE;
+  memcpy(fixed_show_vars.buffer, fixed_vars, sizeof(fixed_vars));
+
+  if (hash_init(&system_variable_hash, system_charset_info, count, 0,
+                0, (hash_get_key) get_sys_var_length, 0, HASH_UNIQUE))
+    goto error;
+
+  vars.last->next= NULL;
+  if (mysql_add_sys_var_chain(vars.first, my_long_options))
+    goto error;
+
   /*
     Special cases
     Needed because MySQL can't find the limits for a variable it it has
@@ -3296,12 +2864,40 @@
     As these variables are deprecated, this code will disappear soon...
   */
   sys_sql_max_join_size.option_limits= sys_max_join_size.option_limits;
+
+  DBUG_RETURN(0);
+
+error:
+  fprintf(stderr, "failed to initialize system variables");
+  DBUG_RETURN(1);
 }
 
 
 void set_var_free()
 {
   hash_free(&system_variable_hash);
+  delete_dynamic(&fixed_show_vars);
+}
+
+
+/*
+  Add elements to the dynamic list of read-only system variables.
+  
+  SYNOPSIS
+    mysql_append_static_vars()
+    show_vars	Pointer to start of array
+    count       Number of elements
+  
+  RETURN VALUES
+    0           SUCCESS
+    otherwise   FAILURE
+*/
+int mysql_append_static_vars(const SHOW_VAR *show_vars, uint count)
+{
+  for (; count > 0; count--, show_vars++)
+    if (insert_dynamic(&fixed_show_vars, (char*) show_vars))
+      return 1;
+  return 0;
 }
 
 
@@ -3309,7 +2905,7 @@
   Find a user set-table variable
 
   SYNOPSIS
-    find_sys_var()
+    intern_find_sys_var()
     str		Name of system variable to find
     length	Length of variable.  zero means that we should use strlen()
 		on the variable
@@ -3319,14 +2915,19 @@
     0		Unknown variable (error message is given)
 */
 
-sys_var *find_sys_var(const char *str, uint length)
+sys_var *intern_find_sys_var(const char *str, uint length, bool no_error)
 {
-  sys_var *var= (sys_var*) hash_search(&system_variable_hash,
-				       (byte*) str,
-				       length ? length :
-				       strlen(str));
-  if (!var)
+  sys_var *var;
+
+  /*
+    This function is only called from the sql_plugin.cc.
+    A lock on LOCK_system_variable_hash should be held
+  */
+  var= (sys_var*) hash_search(&system_variable_hash,
+			      (byte*) str, length ? length : strlen(str));
+  if (!(var || no_error))
     my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
+
   return var;
 }
 
@@ -3592,14 +3193,16 @@
   const char *value;
   String str(buff, sizeof(buff), &my_charset_latin1), *res;
 
+  var->save_result.plugin= NULL;
   if (var->value->result_type() == STRING_RESULT)
   {
     LEX_STRING name;
-    handlerton *db_type;
+    handlerton *hton;
     if (!(res=var->value->val_str(&str)) ||
         !(name.str= (char *)res->ptr()) || !(name.length= res->length()) ||
-	!(var->save_result.hton= db_type= ha_resolve_by_name(thd, &name)) ||
-        ha_checktype(thd, ha_legacy_type(db_type), 1, 0) != db_type)
+	!(var->save_result.plugin= ha_resolve_by_name(thd, &name)) ||
+        !(hton= plugin_data(var->save_result.plugin, handlerton *)) ||
+        ha_checktype(thd, ha_legacy_type(hton), 1, 0) != hton)
     {
       value= res ? res->c_ptr() : "NULL";
       goto err;
@@ -3617,28 +3220,52 @@
 byte *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
 					    LEX_STRING *base)
 {
-  handlerton *val;
-  val= (type == OPT_GLOBAL) ? global_system_variables.*offset :
-        thd->variables.*offset;
-  return (byte *) hton2plugin[val->slot]->name.str;
+  byte* result;
+  handlerton *hton;
+  LEX_STRING *name;
+  plugin_ref plugin= thd->variables.*offset;
+  if (type == OPT_GLOBAL)
+    plugin= my_plugin_lock(thd, &(global_system_variables.*offset));
+  hton= plugin_data(plugin, handlerton*);
+  name= &hton2plugin[hton->slot]->name;
+  result= (byte *) thd->strmake(name->str, name->length);
+  if (type == OPT_GLOBAL)
+    plugin_unlock(thd, plugin);
+  return result;
 }
 
 
 void sys_var_thd_storage_engine::set_default(THD *thd, enum_var_type type)
 {
+  plugin_ref old_value, new_value, *value;
   if (type == OPT_GLOBAL)
-    global_system_variables.*offset= myisam_hton;
+  {
+    value= &(global_system_variables.*offset);
+    new_value= ha_lock_engine(NULL, myisam_hton);
+  }
   else
-    thd->variables.*offset= global_system_variables.*offset;
+  {
+    value= &(thd->variables.*offset);
+    new_value= my_plugin_lock(NULL, &(global_system_variables.*offset));
+  }
+  DBUG_ASSERT(new_value);
+  old_value= *value;
+  *value= new_value;
+  plugin_unlock(NULL, old_value);
 }
 
 
 bool sys_var_thd_storage_engine::update(THD *thd, set_var *var)
 {
-  handlerton **value= &(global_system_variables.*offset);
-  if (var->type != OPT_GLOBAL)
-    value= &(thd->variables.*offset);
-  *value= var->save_result.hton;
+  plugin_ref *value= &(global_system_variables.*offset), old_value;
+   if (var->type != OPT_GLOBAL)
+     value= &(thd->variables.*offset);
+  old_value= *value;
+  if (old_value != var->save_result.plugin)
+  {
+    *value= my_plugin_lock(NULL, &var->save_result.plugin);
+    plugin_unlock(NULL, old_value);
+  }
   return 0;
 }
 

--- 1.64/sql/sql_plugin.cc	2007-05-15 08:34:09 -07:00
+++ 1.65/sql/sql_plugin.cc	2007-05-15 08:34:09 -07:00
@@ -1099,7 +1099,7 @@
   if (my_init_dynamic_array(&plugin_dl_array,
                             sizeof(struct st_plugin_dl),16,16) ||
       my_init_dynamic_array(&plugin_array,
-                            sizeof(struct st_plugin_int),16,16))
+                            sizeof(struct st_plugin_int),32,32))
     goto err;
 
   for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++)

--- 1.85/sql/ha_partition.cc	2007-05-15 08:34:09 -07:00
+++ 1.86/sql/ha_partition.cc	2007-05-15 08:34:09 -07:00
@@ -1986,6 +1986,8 @@
 
 void ha_partition::clear_handler_file()
 {
+  if (m_engine_array)
+    plugin_unlock_list(NULL, m_engine_array, m_tot_parts);
   my_free((char*) m_file_buffer, MYF(MY_ALLOW_ZERO_PTR));
   my_free((char*) m_engine_array, MYF(MY_ALLOW_ZERO_PTR));
   m_file_buffer= NULL;
@@ -2008,6 +2010,7 @@
 {
   uint i;
   uint alloc_len= (m_tot_parts + 1) * sizeof(handler*);
+  handlerton *hton0;
   DBUG_ENTER("create_handlers");
 
   if (!(m_file= (handler **) alloc_root(mem_root, alloc_len)))
@@ -2016,19 +2019,21 @@
   bzero((char*) m_file, alloc_len);
   for (i= 0; i < m_tot_parts; i++)
   {
+    handlerton *hton= plugin_data(m_engine_array[i], handlerton*);
     if (!(m_file[i]= get_new_handler(table_share, mem_root,
-                                     m_engine_array[i])))
+                                     hton)))
       DBUG_RETURN(TRUE);
-    DBUG_PRINT("info", ("engine_type: %u", m_engine_array[i]->db_type));
+    DBUG_PRINT("info", ("engine_type: %u", hton->db_type));
   }
   /* For the moment we only support partition over the same table engine */
-  if (m_engine_array[0] == myisam_hton)
+  hton0= plugin_data(m_engine_array[0], handlerton*);
+  if (hton0 == myisam_hton)
   {
     DBUG_PRINT("info", ("MyISAM"));
     m_myisam= TRUE;
   }
   /* INNODB may not be compiled in... */
-  else if (ha_legacy_type(m_engine_array[0]) == DB_TYPE_INNODB)
+  else if (ha_legacy_type(hton0) == DB_TYPE_INNODB)
   {
     DBUG_PRINT("info", ("InnoDB"));
     m_innodb= TRUE;
@@ -2159,8 +2164,7 @@
   m_tot_parts= uint4korr((file_buffer) + 8);
   DBUG_PRINT("info", ("No of parts = %u", m_tot_parts));
   tot_partition_words= (m_tot_parts + 3) / 4;
-  if (!(engine_array= (handlerton **) my_malloc(m_tot_parts * sizeof(handlerton*),MYF(0))))
-    goto err2;
+  engine_array= (handlerton **) my_alloca(m_tot_parts * sizeof(handlerton*));
   for (i= 0; i < m_tot_parts; i++)
     engine_array[i]= ha_resolve_by_legacy_type(current_thd,
                                                (enum legacy_db_type)
@@ -2168,12 +2172,21 @@
   address_tot_name_len= file_buffer + 12 + 4 * tot_partition_words;
   tot_name_words= (uint4korr(address_tot_name_len) + 3) / 4;
   if (len_words != (tot_partition_words + tot_name_words + 4))
-    goto err2;
+    goto err3;
   name_buffer_ptr= file_buffer + 16 + 4 * tot_partition_words;
   VOID(my_close(file, MYF(0)));
   m_file_buffer= file_buffer;          // Will be freed in clear_handler_file()
   m_name_buffer_ptr= name_buffer_ptr;
-  m_engine_array= engine_array;
+  
+  if (!(m_engine_array= (plugin_ref*)
+                my_malloc(m_tot_parts * sizeof(plugin_ref), MYF(MY_WME))))
+    goto err3;
+
+  for (i= 0; i < m_tot_parts; i++)
+    m_engine_array[i]= ha_lock_engine(NULL, engine_array[i]);
+
+  my_afree((gptr) engine_array);
+    
   if (!m_file && create_handlers(mem_root))
   {
     clear_handler_file();
@@ -2181,6 +2194,8 @@
   }
   DBUG_RETURN(FALSE);
 
+err3:
+  my_afree((gptr) engine_array);
 err2:
   my_free(file_buffer, MYF(0));
 err1:
@@ -2324,7 +2339,8 @@
 
 handler *ha_partition::clone(MEM_ROOT *mem_root)
 {
-  handler *new_handler= get_new_handler(table->s, mem_root, table->s->db_type);
+  handler *new_handler= get_new_handler(table->s, mem_root,
+                                        table->s->db_type());
   ((ha_partition*)new_handler)->m_part_info= m_part_info;
   ((ha_partition*)new_handler)->is_clone= TRUE;
   if (new_handler && !new_handler->ha_open(table,

--- 1.34/sql/ha_partition.h	2007-05-15 08:34:09 -07:00
+++ 1.35/sql/ha_partition.h	2007-05-15 08:34:09 -07:00
@@ -27,6 +27,7 @@
   The partition implements the minimum of what you will probably need.
 */
 
+#ifdef NOT_USED
 typedef struct st_partition_share
 {
   char *table_name;
@@ -34,6 +35,7 @@
   pthread_mutex_t mutex;
   THR_LOCK lock;
 } PARTITION_SHARE;
+#endif
 
 
 #define PARTITION_BYTES_IN_POS 2
@@ -54,7 +56,7 @@
   uint m_open_test_lock;                // Open test_if_locked
   char *m_file_buffer;                  // Buffer with names
   char *m_name_buffer_ptr;		// Pointer to first partition name
-  handlerton **m_engine_array;          // Array of types of the handlers
+  plugin_ref *m_engine_array;           // Array of types of the handlers
   handler **m_file;                     // Array of references to handler inst.
   uint m_file_tot_parts;                // Debug
   handler **m_new_file;                 // Array of references to new handlers
@@ -130,7 +132,9 @@
     Variables for lock structures.
   */
   THR_LOCK_DATA lock;                   /* MySQL lock */
+#ifdef NOT_USED
   PARTITION_SHARE *share;               /* Shared lock info */
+#endif
 
   /* 
     TRUE <=> this object was created with ha_partition::clone and doesn't

--- 1.266/BitKeeper/etc/ignore	2007-05-15 08:34:09 -07:00
+++ 1.267/BitKeeper/etc/ignore	2007-05-15 08:34:09 -07:00
@@ -1082,6 +1082,7 @@
 libmysqld/ha_myisammrg.cc
 libmysqld/ha_ndbcluster.cc
 libmysqld/ha_ndbcluster_binlog.cc
+libmysqld/ha_ndbcluster_cond.cc
 libmysqld/ha_partition.cc
 libmysqld/ha_tina.cc
 libmysqld/handler.cc
Thread
bk commit into 6.0-falcon tree (acurtis:1.2516)antony15 May