List:Commits« Previous MessageNext Message »
From:Mats Kindahl Date:December 9 2009 11:30am
Subject:bzr push into mysql-5.5-trunk branch (mats:2921 to 2922) WL#5030
View as plain text  
 2922 Mats Kindahl	2009-11-18
      WL#5030: Split and remove mysql_priv.h
      
      This patch empties the mysql_priv.h file and remove the
      cyclic dependencies caused by the continous adding of all
      kinds of things to the file by:
      
      - Moving function prototypes into the header file for the
        component where it is defined. There are some exceptions
        to this to make this work possible at all.
      
      - Eliminating all includes from the file: it now only holds
        truly server-internal and general definitions that could
        not be moved elsewhere.
      
        Note that some storage engines still include this one,
        even though it should not be done. This will be handled
        with another patch.
      
      - Renaming the file to sql_priv.h to avoid misuse.
      
        A mysql_priv.h file will be added with just an #error
        directive, but Bazaar is making noises about adding a
        file that was just renamed, so this will come in a
        separate patch.
      
      To avoid merge problems, this patch does not make changes
      inside source files (except by adding includes) or move
      misplaced functions to different components.

    added:
      include/password.h
      sql/derror.h
      sql/des_key_file.h
      sql/discover.h
      sql/filesort.h
      sql/frm_crypt.h
      sql/hostname.h
      sql/init.h
      sql/key.h
      sql/lock.h
      sql/mysqld.h
      sql/sql_base.h
      sql/sql_binlog.h
      sql/sql_connect.h
      sql/sql_const.h
      sql/sql_db.h
      sql/sql_delete.h
      sql/sql_derived.h
      sql/sql_do.h
      sql/sql_handler.h
      sql/sql_help.h
      sql/sql_insert.h
      sql/sql_load.h
      sql/sql_locale.h
      sql/sql_manager.h
      sql/sql_parse.h
      sql/sql_rename.h
      sql/sql_table.h
      sql/sql_tablespace.h
      sql/sql_test.h
      sql/sql_time.h
      sql/sql_union.h
      sql/sql_update.h
      sql/strfunc.h
      sql/thr_malloc.h
    renamed:
      sql/mysql_priv.h => sql/sql_priv.h
      sql/mysql_priv.h.pp => sql/sql_priv.h.pp
      sql/time.cc => sql/sql_time.cc
    modified:
      .bzrignore
      client/Makefile.am
      client/client_priv.h
      client/mysqlbinlog.cc
      configure.in
      include/Makefile.am
      include/ft_global.h
      include/hash.h
      include/keycache.h
      include/m_ctype.h
      include/m_string.h
      include/my_dbug.h
      include/my_dir.h
      include/my_global.h
      include/my_handler.h
      include/my_net.h
      include/my_pthread.h
      include/my_sys.h
      include/my_tree.h
      include/mysys_err.h
      include/queues.h
      include/violite.h
      libmysql/Makefile.am
      libmysqld/Makefile.am
      libmysqld/emb_qcache.cc
      libmysqld/emb_qcache.h
      libmysqld/libmysqld.c
      plugin/daemon_example/daemon_example.cc
      plugin/semisync/semisync.h
      plugin/semisync/semisync_master_plugin.cc
      plugin/semisync/semisync_slave_plugin.cc
      sql/Makefile.am
      sql/debug_sync.cc
      sql/derror.cc
      sql/des_key_file.cc
      sql/discover.cc
      sql/event_data_objects.cc
      sql/event_data_objects.h
      sql/event_db_repository.cc
      sql/event_parse_data.cc
      sql/event_parse_data.h
      sql/event_queue.cc
      sql/event_queue.h
      sql/event_scheduler.cc
      sql/event_scheduler.h
      sql/events.cc
      sql/events.h
      sql/field.cc
      sql/field.h
      sql/field_conv.cc
      sql/filesort.cc
      sql/frm_crypt.cc
      sql/gstream.cc
      sql/gstream.h
      sql/ha_ndbcluster.cc
      sql/ha_ndbcluster.h
      sql/ha_ndbcluster_binlog.cc
      sql/ha_ndbcluster_binlog.h
      sql/ha_ndbcluster_cond.cc
      sql/ha_ndbcluster_cond.h
      sql/ha_partition.cc
      sql/ha_partition.h
      sql/handler.cc
      sql/handler.h
      sql/hash_filo.cc
      sql/hash_filo.h
      sql/hostname.cc
      sql/init.cc
      sql/item.cc
      sql/item.h
      sql/item_buff.cc
      sql/item_cmpfunc.cc
      sql/item_cmpfunc.h
      sql/item_create.cc
      sql/item_create.h
      sql/item_func.cc
      sql/item_func.h
      sql/item_geofunc.cc
      sql/item_row.cc
      sql/item_strfunc.cc
      sql/item_strfunc.h
      sql/item_subselect.cc
      sql/item_subselect.h
      sql/item_sum.cc
      sql/item_sum.h
      sql/item_timefunc.cc
      sql/item_timefunc.h
      sql/item_xmlfunc.cc
      sql/key.cc
      sql/lock.cc
      sql/log.cc
      sql/log.h
      sql/log_event.cc
      sql/log_event.h
      sql/log_event_old.cc
      sql/mf_iocache.cc
      sql/my_decimal.cc
      sql/my_decimal.h
      sql/mysqld.cc
      sql/net_serv.cc
      sql/opt_range.cc
      sql/opt_range.h
      sql/opt_sum.cc
      sql/parse_file.cc
      sql/parse_file.h
      sql/partition_element.h
      sql/partition_info.cc
      sql/partition_info.h
      sql/password.c
      sql/procedure.cc
      sql/procedure.h
      sql/protocol.cc
      sql/protocol.h
      sql/records.cc
      sql/repl_failsafe.cc
      sql/replication.h
      sql/rpl_filter.cc
      sql/rpl_filter.h
      sql/rpl_handler.cc
      sql/rpl_handler.h
      sql/rpl_injector.cc
      sql/rpl_injector.h
      sql/rpl_mi.cc
      sql/rpl_mi.h
      sql/rpl_record.cc
      sql/rpl_record.h
      sql/rpl_record_old.cc
      sql/rpl_record_old.h
      sql/rpl_reporting.cc
      sql/rpl_reporting.h
      sql/rpl_rli.cc
      sql/rpl_rli.h
      sql/rpl_tblmap.cc
      sql/rpl_tblmap.h
      sql/rpl_utility.cc
      sql/rpl_utility.h
      sql/scheduler.cc
      sql/set_var.cc
      sql/set_var.h
      sql/slave.cc
      sql/slave.h
      sql/sp.cc
      sql/sp.h
      sql/sp_cache.cc
      sql/sp_cache.h
      sql/sp_head.cc
      sql/sp_head.h
      sql/sp_pcontext.cc
      sql/sp_pcontext.h
      sql/sp_rcontext.cc
      sql/sp_rcontext.h
      sql/spatial.cc
      sql/spatial.h
      sql/sql_acl.cc
      sql/sql_acl.h
      sql/sql_analyse.cc
      sql/sql_analyse.h
      sql/sql_base.cc
      sql/sql_binlog.cc
      sql/sql_bitmap.h
      sql/sql_cache.cc
      sql/sql_cache.h
      sql/sql_class.cc
      sql/sql_class.h
      sql/sql_client.cc
      sql/sql_connect.cc
      sql/sql_crypt.cc
      sql/sql_crypt.h
      sql/sql_cursor.cc
      sql/sql_cursor.h
      sql/sql_db.cc
      sql/sql_delete.cc
      sql/sql_derived.cc
      sql/sql_do.cc
      sql/sql_error.cc
      sql/sql_error.h
      sql/sql_handler.cc
      sql/sql_help.cc
      sql/sql_insert.cc
      sql/sql_lex.cc
      sql/sql_lex.h
      sql/sql_list.cc
      sql/sql_list.h
      sql/sql_load.cc
      sql/sql_locale.cc
      sql/sql_manager.cc
      sql/sql_map.cc
      sql/sql_map.h
      sql/sql_olap.cc
      sql/sql_parse.cc
      sql/sql_partition.cc
      sql/sql_partition.h
      sql/sql_plugin.cc
      sql/sql_plugin.h
      sql/sql_prepare.cc
      sql/sql_profile.cc
      sql/sql_profile.h
      sql/sql_rename.cc
      sql/sql_repl.cc
      sql/sql_repl.h
      sql/sql_select.cc
      sql/sql_select.h
      sql/sql_servers.cc
      sql/sql_servers.h
      sql/sql_show.cc
      sql/sql_show.h
      sql/sql_signal.cc
      sql/sql_sort.h
      sql/sql_string.h
      sql/sql_table.cc
      sql/sql_tablespace.cc
      sql/sql_test.cc
      sql/sql_trigger.cc
      sql/sql_trigger.h
      sql/sql_udf.cc
      sql/sql_union.cc
      sql/sql_update.cc
      sql/sql_view.cc
      sql/sql_view.h
      sql/sql_yacc.yy
      sql/strfunc.cc
      sql/structs.h
      sql/table.cc
      sql/table.h
      sql/thr_malloc.cc
      sql/tztime.cc
      sql/tztime.h
      sql/uniques.cc
      sql/unireg.cc
      sql/unireg.h
      storage/archive/ha_archive.cc
      storage/blackhole/ha_blackhole.cc
      storage/blackhole/ha_blackhole.h
      storage/csv/ha_tina.cc
      storage/csv/transparent_file.cc
      storage/example/ha_example.cc
      storage/example/ha_example.h
      storage/federated/ha_federated.cc
      storage/heap/ha_heap.cc
      storage/heap/ha_heap.h
      storage/innobase/handler/ha_innodb.cc
      storage/innobase/handler/ha_innodb.h
      storage/innobase/handler/handler0alter.cc
      storage/innobase/handler/i_s.cc
      storage/innobase/handler/mysql_addons.cc
      storage/myisam/ha_myisam.cc
      storage/myisam/ha_myisam.h
      storage/myisammrg/ha_myisammrg.cc
      sql/sql_priv.h
      sql/sql_time.cc
 2921 Alexander Nozdrin	2009-11-12 [merge]
      Auto-merge from mysql-trunk-bugfixing.

    modified:
      .bzr-mysql/default.conf
      mysql-test/lib/My/ConfigFactory.pm
=== modified file '.bzrignore'
--- a/.bzrignore	2009-11-10 07:31:33 +0000
+++ b/.bzrignore	2009-11-18 08:54:54 +0000
@@ -393,6 +393,7 @@ client/rpl_tblmap.h
 client/rpl_tblmap.cc
 client/rpl_utility.h
 client/select_test
+client/sql_const.h
 client/sql_string.cpp
 client/ssl_test
 client/thimble
@@ -1207,7 +1208,7 @@ libmysqld/stacktrace.c
 libmysqld/strfunc.cc
 libmysqld/table.cc
 libmysqld/thr_malloc.cc
-libmysqld/time.cc
+libmysqld/sql_time.cc
 libmysqld/tztime.cc
 libmysqld/uniques.cc
 libmysqld/unireg.cc
@@ -1412,7 +1413,7 @@ mysql-test/var/*
 mysql-test/windows_sys_vars.inc
 mysql.kdevprj
 mysql.proj
-mysql_priv.h
+sql_priv.h
 mysqlbinlog/*.ds?
 mysqlbinlog/*.vcproj
 mysqlcheck/*.ds?

=== modified file 'client/Makefile.am'
--- a/client/Makefile.am	2009-09-03 12:29:25 +0000
+++ b/client/Makefile.am	2009-11-18 08:54:54 +0000
@@ -103,11 +103,12 @@ DEFS =			-DMYSQL_CLIENT_NO_THREADS \
 			-DDEFAULT_MYSQL_HOME="\"$(prefix)\"" \
 			-DMYSQL_DATADIR="\"$(localstatedir)\""
 
-sql_src=log_event.h mysql_priv.h rpl_constants.h \
+sql_src=log_event.h sql_priv.h rpl_constants.h \
 	rpl_utility.h rpl_tblmap.h rpl_tblmap.cc \
 	log_event.cc my_decimal.h my_decimal.cc \
 	log_event_old.h log_event_old.cc \
-	rpl_record_old.h rpl_record_old.cc
+	rpl_record_old.h rpl_record_old.cc \
+	sql_const.h
 strings_src=decimal.c
 
 link_sources:

=== modified file 'client/client_priv.h'
--- a/client/client_priv.h	2009-10-15 12:23:43 +0000
+++ b/client/client_priv.h	2009-11-18 08:54:54 +0000
@@ -19,7 +19,6 @@
 #include <my_sys.h>
 #include <m_string.h>
 #include <mysql.h>
-#include <mysql_embed.h>
 #include <errmsg.h>
 #include <my_getopt.h>
 

=== modified file 'client/mysqlbinlog.cc'
--- a/client/mysqlbinlog.cc	2009-11-06 14:20:27 +0000
+++ b/client/mysqlbinlog.cc	2009-11-18 08:54:54 +0000
@@ -31,7 +31,7 @@
 #include "client_priv.h"
 #include <my_time.h>
 /* That one is necessary for defines of OPTION_NO_FOREIGN_KEY_CHECKS etc */
-#include "mysql_priv.h" 
+#include "sql_priv.h"
 #include "log_event.h"
 #include "sql_common.h"
 

=== modified file 'configure.in'
--- a/configure.in	2009-11-10 07:31:33 +0000
+++ b/configure.in	2009-11-18 08:54:54 +0000
@@ -976,8 +976,8 @@ AC_CHECK_TYPES([fp_except], [], [], [
 # Some system specific hacks
 #
 
-MAX_C_OPTIMIZE="-O3"
-MAX_CXX_OPTIMIZE="-O3"
+MAX_C_OPTIMIZE="-O3 -ggdb"
+MAX_CXX_OPTIMIZE="-O3 -ggdb"
 
 case $SYSTEM_TYPE in
   *solaris2.7*)

=== modified file 'include/Makefile.am'
--- a/include/Makefile.am	2009-11-02 20:05:42 +0000
+++ b/include/Makefile.am	2009-11-18 08:54:54 +0000
@@ -31,7 +31,7 @@ pkginclude_HEADERS =	$(HEADERS_ABI) my_d
 			$(HEADERS_GEN_MAKE) probes_mysql.h probes_mysql_nodtrace.h
 
 noinst_HEADERS =	config-win.h config-netware.h my_bit.h \
-			heap.h my_bitmap.h my_uctype.h \
+			heap.h my_bitmap.h my_uctype.h password.h \
 			myisam.h myisampack.h myisammrg.h ft_global.h\
 			mysys_err.h my_base.h help_start.h help_end.h \
 			my_nosys.h my_alarm.h queues.h rijndael.h sha1.h \

=== modified file 'include/ft_global.h'
--- a/include/ft_global.h	2007-05-10 09:59:39 +0000
+++ b/include/ft_global.h	2009-11-18 08:54:54 +0000
@@ -65,6 +65,14 @@ void ft_free_stopwords(void);
 FT_INFO *ft_init_search(uint,void *, uint, uchar *, uint,CHARSET_INFO *, uchar *);
 my_bool ft_boolean_check_syntax_string(const uchar *);
 
+/*
+  This variable is defined in mysqld.cc but requires definitions
+  provided in this file, so the declaration is placed here.
+
+  TODO: Move definition and declaration into same component.
+*/
+extern char def_ft_boolean_syntax[sizeof(ft_boolean_syntax)];
+
 #ifdef  __cplusplus
 }
 #endif

=== modified file 'include/hash.h'
--- a/include/hash.h	2009-10-14 16:37:38 +0000
+++ b/include/hash.h	2009-11-18 08:54:54 +0000
@@ -17,6 +17,22 @@
 
 #ifndef _hash_h
 #define _hash_h
+
+#include "mysql.h"                              /* my_bool */
+#include "my_global.h"                          /* uchar */
+#include "my_sys.h"                             /* DYNAMIC_ARRAY */
+
+/*
+  This forward declaration is used from C files where the real
+  definition is included before.  Since C does not allow repeated
+  typedef declarations, even when identical, the definition may not be
+  repeated.
+*/
+#ifndef CHARSET_INFO_DEFINED
+#define CHARSET_INFO_DEFINED
+typedef struct charset_info_st CHARSET_INFO;
+#endif  /* CHARSET_INFO_DEFINED */
+
 #ifdef	__cplusplus
 extern "C" {
 #endif

=== modified file 'include/keycache.h'
--- a/include/keycache.h	2009-09-09 15:13:13 +0000
+++ b/include/keycache.h	2009-11-18 08:54:54 +0000
@@ -17,6 +17,9 @@
 
 #ifndef _keycache_h
 #define _keycache_h
+
+#include "my_sys.h"                             /* flush_type */
+
 C_MODE_START
 
 /* declare structures that is used by st_key_cache */

=== modified file 'include/m_ctype.h'
--- a/include/m_ctype.h	2009-10-15 12:23:43 +0000
+++ b/include/m_ctype.h	2009-11-18 08:54:54 +0000
@@ -15,13 +15,13 @@
 
 /*
   A better inplementation of the UNIX ctype(3) library.
-  Notes:   my_global.h should be included before ctype.h
 */
 
 #ifndef _m_ctype_h
 #define _m_ctype_h
 
 #include <my_attribute.h>
+#include "my_global.h"                          /* uint16, uchar */
 
 #ifdef	__cplusplus
 extern "C" {
@@ -248,6 +248,14 @@ extern MY_CHARSET_HANDLER my_charset_ucs
 
 
 /* See strings/CHARSET_INFO.txt about information on this structure  */
+/*
+  This forward declaration is used from C files where the real
+  definition is included before.  Since C does not allow repeated
+  typedef declarations, even when identical, the definition may not be
+  repeated.
+*/
+#ifndef CHARSET_INFO_DEFINED
+#define CHARSET_INFO_DEFINED
 typedef struct charset_info_st
 {
   uint      number;
@@ -283,6 +291,8 @@ typedef struct charset_info_st
   MY_COLLATION_HANDLER *coll;
   
 } CHARSET_INFO;
+#endif  /* CHARSET_INFO_DEFINED */
+
 #define ILLEGAL_CHARSET_INFO_NUMBER (~0U)
 
 

=== modified file 'include/m_string.h'
--- a/include/m_string.h	2009-11-02 20:05:42 +0000
+++ b/include/m_string.h	2009-11-18 08:54:54 +0000
@@ -20,6 +20,9 @@
 
 #ifndef _m_string_h
 #define _m_string_h
+
+#include "my_global.h"                          /* HAVE_* */
+
 #ifndef __USE_GNU
 #define __USE_GNU				/* We want to use stpcpy */
 #endif
@@ -237,13 +240,6 @@ extern ulonglong strtoull(const char *st
 #endif
 #endif
 
-/* my_vsnprintf.c */
-
-extern size_t my_vsnprintf(char *str, size_t n,
-                           const char *format, va_list ap);
-extern size_t my_snprintf(char *to, size_t n, const char *fmt, ...)
-  ATTRIBUTE_FORMAT(printf, 3, 4);
-
 #if defined(__cplusplus)
 }
 #endif
@@ -260,4 +256,10 @@ typedef struct st_mysql_lex_string LEX_S
 #define USTRING_WITH_LEN(X) ((uchar*) X), ((size_t) (sizeof(X) - 1))
 #define C_STRING_WITH_LEN(X) ((char *) (X)), ((size_t) (sizeof(X) - 1))
 
+static inline void lex_string_set(LEX_STRING *lex_str, const char *c_str)
+{
+  lex_str->str= (char *) c_str;
+  lex_str->length= strlen(c_str);
+}
+
 #endif

=== modified file 'include/my_dbug.h'
--- a/include/my_dbug.h	2009-10-30 18:13:58 +0000
+++ b/include/my_dbug.h	2009-11-18 08:54:54 +0000
@@ -145,7 +145,23 @@ extern  const char* _db_get_func_(void);
 #define DBUG_CRASH_VOID_RETURN          do { return; } while(0)
 
 #endif
-#ifdef  __cplusplus
+
+#ifdef EXTRA_DEBUG
+/**
+  Sync points allow us to force the server to reach a certain line of code
+  and block there until the client tells the server it is ok to go on.
+  The client tells the server to block with SELECT GET_LOCK()
+  and unblocks it with SELECT RELEASE_LOCK(). Used for debugging difficult
+  concurrency problems
+*/
+#define DBUG_SYNC_POINT(lock_name,lock_timeout) \
+ debug_sync_point(lock_name,lock_timeout)
+void debug_sync_point(const char* lock_name, uint lock_timeout);
+#else
+#define DBUG_SYNC_POINT(lock_name,lock_timeout)
+#endif /* EXTRA_DEBUG */
+
+#ifdef	__cplusplus
 }
 #endif
 #endif

=== modified file 'include/my_dir.h'
--- a/include/my_dir.h	2009-09-11 20:26:35 +0000
+++ b/include/my_dir.h	2009-11-18 08:54:54 +0000
@@ -22,6 +22,8 @@ extern "C" {
 #ifndef MY_DIR_H
 #define MY_DIR_H
 
+#include "my_global.h"
+
 #include <sys/stat.h>
 
 	/* Defines for my_dir and my_stat */

=== modified file 'include/my_global.h'
--- a/include/my_global.h	2009-10-30 18:13:58 +0000
+++ b/include/my_global.h	2009-11-18 08:54:54 +0000
@@ -1102,6 +1102,12 @@ typedef unsigned long my_off_t;
 typedef off_t os_off_t;
 #endif
 
+/*
+  TODO Convert these to use Bitmap class.
+ */
+typedef ulonglong table_map;          /* Used for table bits in join */
+typedef ulong nesting_map;  /* Used for flags of nesting constructs */
+
 #if defined(__WIN__)
 #define socket_errno	WSAGetLastError()
 #define SOCKET_EINTR	WSAEINTR
@@ -1573,6 +1579,12 @@ inline void  operator delete[](void*, vo
 #define max(a, b)	((a) > (b) ? (a) : (b))
 #define min(a, b)	((a) < (b) ? (a) : (b))
 #endif  
+
+#define x_free(A) \
+  do { my_free((uchar*)(A), MYF(MY_WME|MY_FAE|MY_ALLOW_ZERO_PTR)); } while (0)
+#define safeFree(X) \
+    do { if (X) { my_free((uchar*)(X), MYF(0)); (X) = NULL; } } while (0)
+
 /*
   Only Linux is known to need an explicit sync of the directory to make sure a
   file creation/deletion/renaming in(from,to) this directory durable.
@@ -1633,4 +1645,20 @@ static inline double rint(double x)
 #endif
 #endif
 
+/* Defines that are unique to the embedded version of MySQL */
+
+#ifdef EMBEDDED_LIBRARY
+
+/* Things we don't need in the embedded version of MySQL */
+/* TODO HF add #undef HAVE_VIO if we don't want client in embedded library */
+
+#undef HAVE_PSTACK				/* No stacktrace */
+#undef HAVE_OPENSSL
+#undef HAVE_SMEM				/* No shared memory */
+#undef HAVE_NDBCLUSTER_DB /* No NDB cluster */
+
+#define DONT_USE_RAID
+
+#endif /* EMBEDDED_LIBRARY */
+
 #endif /* my_global_h */

=== modified file 'include/my_handler.h'
--- a/include/my_handler.h	2009-10-15 10:17:32 +0000
+++ b/include/my_handler.h	2009-11-18 08:54:54 +0000
@@ -23,6 +23,8 @@
 extern "C" {
 #endif
 
+#include "m_ctype.h"                            /* CHARSET_INFO */
+
 /*
   There is a hard limit for the maximum number of keys as there are only
   8 bits in the index file header for the number of keys in a table.

=== modified file 'include/my_net.h'
--- a/include/my_net.h	2006-12-23 19:20:40 +0000
+++ b/include/my_net.h	2009-11-18 08:54:54 +0000
@@ -24,6 +24,9 @@
 
 #ifndef _my_net_h
 #define _my_net_h
+
+#include "my_global.h"                  /* C_MODE_START, C_MODE_END */
+
 C_MODE_START
 
 #include <errno.h>

=== modified file 'include/my_pthread.h'
--- a/include/my_pthread.h	2009-10-30 18:13:58 +0000
+++ b/include/my_pthread.h	2009-11-18 08:54:54 +0000
@@ -18,6 +18,8 @@
 #ifndef _my_pthread_h
 #define _my_pthread_h
 
+#include "my_global.h"                          /* myf */
+
 #ifndef ETIME
 #define ETIME ETIMEDOUT				/* For FreeBSD */
 #endif

=== modified file 'include/my_sys.h'
--- a/include/my_sys.h	2009-11-10 07:31:33 +0000
+++ b/include/my_sys.h	2009-11-18 08:54:54 +0000
@@ -15,6 +15,9 @@
 
 #ifndef _my_sys_h
 #define _my_sys_h
+
+#include "my_global.h"                  /* C_MODE_START, C_MODE_END */
+
 C_MODE_START
 
 #ifdef HAVE_AIOWAIT

=== modified file 'include/my_tree.h'
--- a/include/my_tree.h	2007-05-10 09:59:39 +0000
+++ b/include/my_tree.h	2009-11-18 08:54:54 +0000
@@ -20,6 +20,7 @@ extern "C" {
 #endif
 
 #include "my_base.h"		/* get 'enum ha_rkey_function' */
+#include "my_alloc.h"           /* MEM_ROOT */
 
 /* Worst case tree is half full. This gives use 2^(MAX_TREE_HEIGHT/2) leafs */
 #define MAX_TREE_HEIGHT	64

=== modified file 'include/mysys_err.h'
--- a/include/mysys_err.h	2007-03-02 16:43:45 +0000
+++ b/include/mysys_err.h	2009-11-18 08:54:54 +0000
@@ -16,6 +16,9 @@
 #ifndef _mysys_err_h
 #define _mysys_err_h
 #ifdef	__cplusplus
+
+#include "my_global.h"                          /* NEAR */
+
 extern "C" {
 #endif
 

=== added file 'include/password.h'
--- a/include/password.h	1970-01-01 00:00:00 +0000
+++ b/include/password.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,32 @@
+#ifndef PASSWORD_INCLUDED
+#define PASSWORD_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "my_global.h"
+
+C_MODE_START
+
+void my_make_scrambled_password_323(char *to, const char *password,
+                                    size_t pass_len);
+void my_make_scrambled_password(char *to, const char *password,
+                                size_t pass_len);
+
+void hash_password(ulong *result, const char *password, uint password_len);
+
+C_MODE_END
+
+#endif /* PASSWORD_INCLUDED */

=== modified file 'include/queues.h'
--- a/include/queues.h	2007-11-14 18:20:31 +0000
+++ b/include/queues.h	2009-11-18 08:54:54 +0000
@@ -22,6 +22,9 @@
 
 #ifndef _queues_h
 #define _queues_h
+
+#include "my_global.h"                          /* uchar */
+
 #ifdef	__cplusplus
 extern "C" {
 #endif

=== modified file 'include/violite.h'
--- a/include/violite.h	2009-11-02 22:19:58 +0000
+++ b/include/violite.h	2009-11-18 08:54:54 +0000
@@ -30,6 +30,10 @@
 extern "C" {
 #endif /* __cplusplus */
 
+#ifdef __cplusplus
+typedef struct st_vio Vio;
+#endif /* __cplusplus */
+
 enum enum_vio_type
 {
   VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE,

=== modified file 'libmysql/Makefile.am'
--- a/libmysql/Makefile.am	2009-07-08 14:49:45 +0000
+++ b/libmysql/Makefile.am	2009-11-18 08:54:54 +0000
@@ -81,7 +81,7 @@ link_sources:
 #
 # A list of needed headers collected from the deps information 000213
 nh =		my_global.h config-win32.h dbug.h errmsg.h \
-		m_ctype.h m_string.h \
+		m_ctype.h m_string.h password.h \
 		my_alarm.h my_config.h my_dir.h my_list.h my_net.h my_sys.h \
 		mysql.h mysql_com.h mysql_version.h mysqld_error.h \
 		mysys_err.h my_pthread.h thr_alarm.h violite.h hash.h \

=== modified file 'libmysqld/Makefile.am'
--- a/libmysqld/Makefile.am	2009-10-22 22:30:28 +0000
+++ b/libmysqld/Makefile.am	2009-11-18 08:54:54 +0000
@@ -69,7 +69,7 @@ sqlsources = derror.cc field.cc field_co
 	sql_prepare.cc sql_derived.cc sql_rename.cc \
 	sql_select.cc sql_do.cc sql_show.cc set_var.cc \
 	sql_string.cc sql_table.cc sql_test.cc sql_udf.cc \
-	sql_update.cc sql_yacc.cc table.cc thr_malloc.cc time.cc \
+	sql_update.cc sql_yacc.cc table.cc thr_malloc.cc sql_time.cc \
 	unireg.cc uniques.cc sql_union.cc hash_filo.cc \
 	spatial.cc gstream.cc sql_help.cc tztime.cc sql_cursor.cc \
 	sp_head.cc sp_pcontext.cc sp.cc sp_cache.cc sp_rcontext.cc \

=== modified file 'libmysqld/emb_qcache.cc'
--- a/libmysqld/emb_qcache.cc	2009-09-10 09:18:29 +0000
+++ b/libmysqld/emb_qcache.cc	2009-11-18 08:54:54 +0000
@@ -13,11 +13,14 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "my_global.h"                          // HAVE_*
+
 #ifdef HAVE_QUERY_CACHE
 #include <mysql.h>
 #include "emb_qcache.h"
 #include "embedded_priv.h"
+#include "sql_class.h"                          // THD
 
 void Querycache_stream::store_uchar(uchar c)
 {

=== modified file 'libmysqld/emb_qcache.h'
--- a/libmysqld/emb_qcache.h	2009-10-13 18:21:42 +0000
+++ b/libmysqld/emb_qcache.h	2009-11-18 08:54:54 +0000
@@ -13,6 +13,8 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
+#include "sql_cache.h"                         /* Query_cache_block */
+
 class Querycache_stream
 {
   uchar *cur_data;

=== modified file 'libmysqld/libmysqld.c'
--- a/libmysqld/libmysqld.c	2009-10-23 11:22:21 +0000
+++ b/libmysqld/libmysqld.c	2009-11-18 08:54:54 +0000
@@ -15,7 +15,6 @@
 
 #include <my_global.h>
 #include <mysql.h>
-#include <mysql_embed.h>
 #include <mysqld_error.h>
 #include <my_pthread.h>
 #include "embedded_priv.h"

=== modified file 'plugin/daemon_example/daemon_example.cc'
--- a/plugin/daemon_example/daemon_example.cc	2007-05-10 09:59:39 +0000
+++ b/plugin/daemon_example/daemon_example.cc	2009-11-18 08:54:54 +0000
@@ -13,13 +13,17 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
-#include <mysql_priv.h>
+#include <sql_priv.h>
 #include <stdlib.h>
 #include <ctype.h>
 #include <mysql_version.h>
 #include <mysql/plugin.h>
 #include <my_global.h>
 #include <my_dir.h>
+#include "my_pthread.h"                         // pthread_handler_t
+#include "my_sys.h"                             // my_write, my_malloc
+#include "m_string.h"                           // strlen
+#include "sql_plugin.h"                         // st_plugin_int
 
 /*
   Disable __attribute__() on non-gcc compilers.

=== modified file 'plugin/semisync/semisync.h'
--- a/plugin/semisync/semisync.h	2009-10-12 12:55:01 +0000
+++ b/plugin/semisync/semisync.h	2009-11-18 08:54:54 +0000
@@ -20,11 +20,13 @@
 
 #define MYSQL_SERVER
 #define HAVE_REPLICATION
-#include <mysql_priv.h>
+#include <sql_priv.h>
+#include "unireg.h"
 #include <my_global.h>
 #include <my_pthread.h>
 #include <mysql/plugin.h>
 #include <replication.h>
+#include "log.h"                                /* sql_print_information */
 
 typedef struct st_mysql_show_var SHOW_VAR;
 typedef struct st_mysql_sys_var SYS_VAR;

=== modified file 'plugin/semisync/semisync_master_plugin.cc'
--- a/plugin/semisync/semisync_master_plugin.cc	2009-10-18 12:29:03 +0000
+++ b/plugin/semisync/semisync_master_plugin.cc	2009-11-18 08:54:54 +0000
@@ -16,6 +16,7 @@
 
 
 #include "semisync_master.h"
+#include "sql_class.h"                          // THD
 
 ReplSemiSyncMaster repl_semisync;
 

=== modified file 'plugin/semisync/semisync_slave_plugin.cc'
--- a/plugin/semisync/semisync_slave_plugin.cc	2009-10-12 13:15:32 +0000
+++ b/plugin/semisync/semisync_slave_plugin.cc	2009-11-18 08:54:54 +0000
@@ -16,6 +16,7 @@
 
 
 #include "semisync_slave.h"
+#include <mysql.h>
 
 ReplSemiSyncSlave repl_semisync;
 

=== modified file 'sql/Makefile.am'
--- a/sql/Makefile.am	2009-11-05 12:08:37 +0000
+++ b/sql/Makefile.am	2009-11-18 08:54:54 +0000
@@ -84,22 +84,30 @@ noinst_HEADERS =	item.h item_func.h item
 			item_strfunc.h item_timefunc.h \
 			item_xmlfunc.h sql_plugin_services.h \
 			item_create.h item_subselect.h item_row.h \
-			mysql_priv.h item_geofunc.h sql_bitmap.h \
+			sql_priv.h item_geofunc.h sql_bitmap.h \
 			procedure.h sql_class.h sql_lex.h sql_list.h \
 			sql_map.h sql_string.h unireg.h \
 			sql_error.h field.h handler.h mysqld_suffix.h \
-			sql_profile.h \
+			sql_profile.h sql_help.h frm_crypt.h \
+			mysqld.h \
 			ha_ndbcluster.h ha_ndbcluster_cond.h \
 			ha_ndbcluster_binlog.h ha_ndbcluster_tables.h \
 			ha_partition.h rpl_constants.h \
 			debug_sync.h \
 			opt_range.h protocol.h rpl_tblmap.h rpl_utility.h \
-			rpl_reporting.h \
+			rpl_reporting.h sql_locale.h sql_parse.h \
 			log.h sql_show.h rpl_rli.h rpl_mi.h \
 			sql_select.h structs.h table.h sql_udf.h hash_filo.h \
-			lex.h lex_symbol.h sql_acl.h sql_crypt.h  \
+			lex.h lex_symbol.h sql_acl.h sql_crypt.h sql_base.h \
+			sql_table.h key.h lock.h thr_malloc.h strfunc.h \
+			sql_delete.h sql_insert.h sql_update.h sql_db.h \
+			sql_connect.h sql_rename.h sql_time.h sql_tablespace.h \
+			hostname.h sql_test.h records.h filesort.h \
+			sql_derived.h sql_load.h sql_handler.h init.h \
+			derror.h sql_union.h des_key_file.h sql_binlog.h \
+			discover.h sql_manager.h sql_do.h \
 			sql_repl.h slave.h rpl_filter.h rpl_injector.h \
-			log_event.h rpl_record.h \
+			log_event.h rpl_record.h sql_const.h \
 			log_event_old.h rpl_record_old.h \
 			sql_sort.h sql_cache.h set_var.h \
 			spatial.h gstream.h client_settings.h tzfile.h \
@@ -135,7 +143,7 @@ mysqld_SOURCES =	sql_lex.cc sql_handler.
 			unireg.cc des_key_file.cc \
 			log_event.cc rpl_record.cc \
 			log_event_old.cc rpl_record_old.cc \
-			discover.cc time.cc opt_range.cc opt_sum.cc \
+			discover.cc sql_time.cc opt_range.cc opt_sum.cc \
 		   	records.cc filesort.cc handler.cc \
 		        ha_partition.cc \
 			debug_sync.cc \

=== modified file 'sql/debug_sync.cc'
--- a/sql/debug_sync.cc	2009-10-30 18:13:58 +0000
+++ b/sql/debug_sync.cc	2009-11-18 08:54:54 +0000
@@ -321,12 +321,13 @@
 
 /*
   Due to weaknesses in our include files, we need to include
-  mysql_priv.h here. To have THD declared, we need to include
+  sql_priv.h here. To have THD declared, we need to include
   sql_class.h. This includes log_event.h, which in turn requires
-  declarations from mysql_priv.h (e.g. OPTION_AUTO_IS_NULL).
-  mysql_priv.h includes almost everything, so is sufficient here.
+  declarations from sql_priv.h (e.g. OPTION_AUTO_IS_NULL).
+  sql_priv.h includes almost everything, so is sufficient here.
 */
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "sql_parse.h"
 
 /*
   Action to perform at a synchronization point.
@@ -394,7 +395,7 @@ extern "C" void (*debug_sync_C_callback_
 
     We cannot place a sync point directly in C files (like those in mysys or
     certain storage engines written mostly in C like MyISAM or Maria). Because
-    they are C code and do not include mysql_priv.h. So they do not know the
+    they are C code and do not include sql_priv.h. So they do not know the
     macro DEBUG_SYNC(thd, sync_point_name). The macro needs a 'thd' argument.
     Hence it cannot be used in files outside of the sql/ directory.
 

=== modified file 'sql/derror.cc'
--- a/sql/derror.cc	2009-10-15 12:23:43 +0000
+++ b/sql/derror.cc	2009-11-18 08:54:54 +0000
@@ -21,8 +21,13 @@
   Read language depeneded messagefile
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "derror.h"
 #include "mysys_err.h"
+#include "mysqld.h"                             // lc_messages_dir
+#include "derror.h"                             // read_texts
+#include "sql_class.h"                          // THD
 
 static void init_myfunc_errs(void);
 

=== added file 'sql/derror.h'
--- a/sql/derror.h	1970-01-01 00:00:00 +0000
+++ b/sql/derror.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,25 @@
+#ifndef DERROR_INCLUDED
+#define DERROR_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "my_global.h"                          /* uint */
+
+bool init_errmessage(void);
+bool read_texts(const char *file_name, const char *language,
+                const char ***point, uint error_messages);
+
+#endif /* DERROR_INCLUDED */

=== modified file 'sql/des_key_file.cc'
--- a/sql/des_key_file.cc	2007-10-09 21:56:32 +0000
+++ b/sql/des_key_file.cc	2009-11-18 08:54:54 +0000
@@ -13,7 +13,10 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "my_global.h"          // HAVE_*
+#include "sql_priv.h"
+#include "des_key_file.h"       // st_des_keyschedule, st_des_keyblock
+#include "log.h"                // sql_print_error
 #include <m_ctype.h>
 
 #ifdef HAVE_OPENSSL

=== added file 'sql/des_key_file.h'
--- a/sql/des_key_file.h	1970-01-01 00:00:00 +0000
+++ b/sql/des_key_file.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,40 @@
+#ifndef DES_KEY_FILE_INCLUDED
+#define DES_KEY_FILE_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#ifdef HAVE_OPENSSL
+#include <openssl/des.h>
+
+#include "violite.h"                /* DES_cblock, DES_key_schedule */
+
+struct st_des_keyblock
+{
+  DES_cblock key1, key2, key3;
+};
+
+struct st_des_keyschedule
+{
+  DES_key_schedule ks1, ks2, ks3;
+};
+
+extern struct st_des_keyschedule des_keyschedule[10];
+extern uint des_default_key;
+
+bool load_des_key_file(const char *file_name);
+#endif /* HAVE_OPENSSL */
+
+#endif /* DES_KEY_FILE_INCLUDED */

=== modified file 'sql/discover.cc'
--- a/sql/discover.cc	2007-10-09 21:56:32 +0000
+++ b/sql/discover.cc	2009-11-18 08:54:54 +0000
@@ -21,7 +21,9 @@
   Functions for discover of frm file from handler
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "discover.h"
 #include <my_dir.h>
 
 /**

=== added file 'sql/discover.h'
--- a/sql/discover.h	1970-01-01 00:00:00 +0000
+++ b/sql/discover.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,24 @@
+#ifndef DISCOVER_INCLUDED
+#define DISCOVER_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "my_global.h"                          /* uchar */
+
+int readfrm(const char *name, uchar **data, size_t *length);
+int writefrm(const char* name, const uchar* data, size_t len);
+
+#endif /* DISCOVER_INCLUDED */

=== modified file 'sql/event_data_objects.cc'
--- a/sql/event_data_objects.cc	2009-11-05 20:28:35 +0000
+++ b/sql/event_data_objects.cc	2009-11-18 08:54:54 +0000
@@ -14,11 +14,22 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 #define MYSQL_LEX 1
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_parse.h"                          // parse_sql
+#include "strfunc.h"                           // find_string_in_array
+#include "sql_db.h"                        // get_default_db_collation
+#include "sql_time.h"                      // interval_type_to_name,
+                                           // date_add_interval,
+                                           // calc_time_diff
+#include "tztime.h"     // my_tz_find, my_tz_OFFSET0, struct Time_zone
+#include "sql_acl.h"    // EVENT_ACL, SUPER_ACL
+#include "sp.h"         // load_charset, load_collation
 #include "events.h"
 #include "event_data_objects.h"
 #include "event_db_repository.h"
 #include "sp_head.h"
+#include "sql_show.h"                // append_definer, append_identifier
 
 /**
   @addtogroup Event_Scheduler

=== modified file 'sql/event_data_objects.h'
--- a/sql/event_data_objects.h	2008-05-09 07:43:02 +0000
+++ b/sql/event_data_objects.h	2009-11-18 08:54:54 +0000
@@ -23,6 +23,12 @@
 */
 
 #include "event_parse_data.h"
+#include "thr_lock.h"                           /* thr_lock_type */
+
+class Field;
+class THD;
+class Time_zone;
+struct TABLE;
 
 class Event_queue_element_for_exec
 {

=== modified file 'sql/event_db_repository.cc'
--- a/sql/event_db_repository.cc	2009-09-23 13:21:29 +0000
+++ b/sql/event_db_repository.cc	2009-11-18 08:54:54 +0000
@@ -13,8 +13,16 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_base.h"                           // close_thread_tables
 #include "event_db_repository.h"
+#include "key.h"                                // key_copy
+#include "sql_db.h"                        // get_default_db_collation
+#include "sql_time.h"                      // interval_type_to_name
+#include "tztime.h"                             // struct Time_zone
+#include "sql_acl.h" // SUPER_ACL, MYSQL_DB_FIELD_COUNT, mysql_db_table_fields
+#include "records.h"          // init_read_record, end_read_record
 #include "sp_head.h"
 #include "event_data_objects.h"
 #include "events.h"

=== modified file 'sql/event_parse_data.cc'
--- a/sql/event_parse_data.cc	2009-02-13 16:41:47 +0000
+++ b/sql/event_parse_data.cc	2009-11-18 08:54:54 +0000
@@ -13,9 +13,11 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #include "sp_head.h"
 #include "event_parse_data.h"
+#include "sql_time.h"                           // TIME_to_timestamp
 
 /*
   Returns a new instance

=== modified file 'sql/event_parse_data.h'
--- a/sql/event_parse_data.h	2008-11-10 20:21:49 +0000
+++ b/sql/event_parse_data.h	2009-11-18 08:54:54 +0000
@@ -16,6 +16,12 @@
 #ifndef _EVENT_PARSE_DATA_H_
 #define _EVENT_PARSE_DATA_H_
 
+#include "sql_list.h"                           /* Sql_alloc */
+
+class Item;
+class THD;
+class sp_name;
+
 #define EVEX_GET_FIELD_FAILED   -2
 #define EVEX_BAD_PARAMS         -5
 #define EVEX_MICROSECOND_UNSUP  -6

=== modified file 'sql/event_queue.cc'
--- a/sql/event_queue.cc	2008-05-09 07:43:02 +0000
+++ b/sql/event_queue.cc	2009-11-18 08:54:54 +0000
@@ -13,9 +13,13 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #include "event_queue.h"
 #include "event_data_objects.h"
+#include "tztime.h"     // my_tz_find, my_tz_OFFSET0, struct Time_zone
+#include "log.h"        // sql_print_error
+#include "sql_class.h"  // struct THD
 
 /**
   @addtogroup Event_Scheduler

=== modified file 'sql/event_queue.h'
--- a/sql/event_queue.h	2007-08-15 15:08:44 +0000
+++ b/sql/event_queue.h	2009-11-18 08:54:54 +0000
@@ -25,6 +25,10 @@
   Queue of events awaiting execution.
 */
 
+#include "queues.h"                             // QUEUE
+#include "sql_string.h"                         /* LEX_STRING */
+#include "my_time.h"                    /* my_time_t, interval_type */
+
 class Event_basic;
 class Event_queue_element;
 class Event_queue_element_for_exec;

=== modified file 'sql/event_scheduler.cc'
--- a/sql/event_scheduler.cc	2009-10-13 18:29:28 +0000
+++ b/sql/event_scheduler.cc	2009-11-18 08:54:54 +0000
@@ -13,12 +13,15 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "event_scheduler.h"
 #include "events.h"
 #include "event_data_objects.h"
-#include "event_scheduler.h"
 #include "event_queue.h"
 #include "event_db_repository.h"
+#include "sql_connect.h"         // init_new_connection_handler_thread
+#include "sql_acl.h"             // SUPER_ACL
 
 /**
   @addtogroup Event_Scheduler

=== modified file 'sql/event_scheduler.h'
--- a/sql/event_scheduler.h	2007-08-15 15:08:44 +0000
+++ b/sql/event_scheduler.h	2009-11-18 08:54:54 +0000
@@ -34,7 +34,9 @@
 class Event_queue;
 class Event_job_data;
 class Event_db_repository;
+class Event_queue_element_for_exec;
 class Events;
+class THD;
 
 void
 pre_init_event_thread(THD* thd);

=== modified file 'sql/events.cc'
--- a/sql/events.cc	2009-11-05 20:28:35 +0000
+++ b/sql/events.cc	2009-11-18 08:54:54 +0000
@@ -13,8 +13,17 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_parse.h"                          // check_access
+#include "sql_base.h"                           // close_thread_tables
+#include "sql_show.h"                           // append_definer
 #include "events.h"
+#include "sql_db.h"                          // check_db_dir_existence
+#include "sql_table.h"                       // write_bin_log
+#include "tztime.h"                             // struct Time_zone
+#include "sql_acl.h"                            // EVENT_ACL
+#include "records.h"          // init_read_record, end_read_record
 #include "event_data_objects.h"
 #include "event_db_repository.h"
 #include "event_queue.h"

=== modified file 'sql/events.h'
--- a/sql/events.h	2007-08-15 15:08:44 +0000
+++ b/sql/events.h	2009-11-18 08:54:54 +0000
@@ -25,10 +25,17 @@
   A public interface of Events_Scheduler module.
 */
 
-class Event_parse_data;
+#include "sql_string.h"                         /* LEX_STRING */
+#include "my_time.h"                            /* interval_type */
+
 class Event_db_repository;
+class Event_parse_data;
 class Event_queue;
 class Event_scheduler;
+class TABLE_LIST;
+class THD;
+typedef class Item COND;
+typedef struct charset_info_st CHARSET_INFO;
 
 /* Return codes */
 enum enum_events_error_code

=== modified file 'sql/field.cc'
--- a/sql/field.cc	2009-11-10 07:31:33 +0000
+++ b/sql/field.cc	2009-11-18 08:54:54 +0000
@@ -25,10 +25,18 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
 #include "sql_select.h"
 #include "rpl_rli.h"                            // Pull in Relay_log_info
 #include "slave.h"                              // Pull in rpl_master_has_bug()
+#include "strfunc.h"                            // find_type2, find_set
+#include "sql_time.h"                    // str_to_datetime_with_warn,
+                                         // str_to_time_with_warn,
+                                         // TIME_to_timestamp,
+                                         // make_time, make_date,
+                                         // make_truncated_value_warning
+#include "tztime.h"                      // struct Time_zone
+#include "filesort.h"                    // change_double_for_sort
 #include <m_ctype.h>
 #include <errno.h>
 #ifdef HAVE_FCONVERT

=== modified file 'sql/field.h'
--- a/sql/field.h	2009-11-06 14:20:27 +0000
+++ b/sql/field.h	2009-11-18 08:54:54 +0000
@@ -25,6 +25,12 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
+#include "mysqld.h"                             /* system_charset_info */
+#include "table.h"                              /* TABLE */
+#include "sql_string.h"                         /* String */
+#include "my_decimal.h"                         /* my_decimal */
+#include "sql_error.h"                          /* MYSQL_ERROR */
+
 #define NOT_FIXED_DEC			31
 #define DATETIME_DEC                     6
 const uint32 max_field_size= (uint32) 4294967295U;
@@ -33,6 +39,29 @@ class Send_field;
 class Protocol;
 class Create_field;
 class Relay_log_info;
+class Field;
+
+enum enum_check_fields
+{
+  CHECK_FIELD_IGNORE,
+  CHECK_FIELD_WARN,
+  CHECK_FIELD_ERROR_FOR_NULL
+};
+
+
+enum Derivation
+{
+  DERIVATION_IGNORABLE= 5,
+  DERIVATION_COERCIBLE= 4,
+  DERIVATION_SYSCONST= 3,
+  DERIVATION_IMPLICIT= 2,
+  DERIVATION_NONE= 1,
+  DERIVATION_EXPLICIT= 0
+};
+
+#define STORAGE_TYPE_MASK 7
+#define COLUMN_FORMAT_MASK 7
+#define COLUMN_FORMAT_SHIFT 3
 
 struct st_cache_field;
 int field_conv(Field *to,Field *from);

=== modified file 'sql/field_conv.cc'
--- a/sql/field_conv.cc	2009-06-17 14:56:44 +0000
+++ b/sql/field_conv.cc	2009-11-18 08:54:54 +0000
@@ -24,7 +24,8 @@
     gives much more speed.
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "sql_class.h"                          // THD
 #include <m_ctype.h>
 
 static void do_field_eq(Copy_field *copy)

=== modified file 'sql/filesort.cc'
--- a/sql/filesort.cc	2009-02-17 12:24:09 +0000
+++ b/sql/filesort.cc	2009-11-18 08:54:54 +0000
@@ -21,13 +21,18 @@
   Sorts a database
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "filesort.h"
+#include "unireg.h"                      // REQUIRED by other includes
 #ifdef HAVE_STDDEF_H
 #include <stddef.h>			/* for macro offsetof */
 #endif
 #include <m_ctype.h>
 #include "sql_sort.h"
 #include "probes_mysql.h"
+#include "sql_test.h"                           // TEST_filesort
+#include "opt_range.h"                          // SQL_SELECT
+#include "sql_class.h"                          // THD
 
 #ifndef THREAD
 #define SKIP_DBUG_IN_FILESORT

=== added file 'sql/filesort.h'
--- a/sql/filesort.h	1970-01-01 00:00:00 +0000
+++ b/sql/filesort.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,36 @@
+#ifndef FILESORT_INCLUDED
+#define FILESORT_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+class SQL_SELECT;
+
+#include "my_global.h"                          /* uint, uchar */
+#include "my_base.h"                            /* ha_rows */
+
+class SQL_SELECT;
+class THD;
+struct TABLE;
+typedef struct st_sort_field SORT_FIELD;
+
+ha_rows filesort(THD *thd, TABLE *table, st_sort_field *sortorder,
+                 uint s_length, SQL_SELECT *select,
+                 ha_rows max_rows, bool sort_positions,
+                 ha_rows *examined_rows);
+void filesort_free_buffers(TABLE *table, bool full);
+void change_double_for_sort(double nr,uchar *to);
+
+#endif /* FILESORT_INCLUDED */

=== modified file 'sql/frm_crypt.cc'
--- a/sql/frm_crypt.cc	2006-12-31 00:02:27 +0000
+++ b/sql/frm_crypt.cc	2009-11-18 08:54:54 +0000
@@ -21,7 +21,8 @@
 ** mysql binary.
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "frm_crypt.h"
 
 #ifdef HAVE_CRYPTED_FRM
 

=== added file 'sql/frm_crypt.h'
--- a/sql/frm_crypt.h	1970-01-01 00:00:00 +0000
+++ b/sql/frm_crypt.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,23 @@
+#ifndef FRM_CRYPT_INCLUDED
+#define FRM_CRYPT_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+class SQL_CRYPT;
+
+SQL_CRYPT *get_crypt_for_frm(void);
+
+#endif /* FRM_CRYPT_INCLUDED */

=== modified file 'sql/gstream.cc'
--- a/sql/gstream.cc	2009-06-09 16:44:26 +0000
+++ b/sql/gstream.cc	2009-11-18 08:54:54 +0000
@@ -18,7 +18,9 @@
   NOTE: These functions assumes that the string is end \0 terminated!
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "gstream.h"
+#include "m_string.h"                           // LEX_STRING
 
 enum Gis_read_stream::enum_tok_types Gis_read_stream::get_next_toc_type()
 {

=== modified file 'sql/gstream.h'
--- a/sql/gstream.h	2009-09-23 21:32:31 +0000
+++ b/sql/gstream.h	2009-11-18 08:54:54 +0000
@@ -17,6 +17,13 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 
+#include "my_global.h"                          /* NULL, NullS */
+#include "my_sys.h"                             /* MY_ALLOW_ZERO_PTR */
+#include "m_ctype.h"           /* my_charset_latin1, my_charset_bin */
+
+typedef struct charset_info_st CHARSET_INFO;
+typedef struct st_mysql_lex_string LEX_STRING;
+
 class Gis_read_stream
 {
 public:

=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2009-11-10 07:31:33 +0000
+++ b/sql/ha_ndbcluster.cc	2009-11-18 08:54:54 +0000
@@ -26,7 +26,15 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"         // REQUIRED: for other includes
+#include "sql_table.h"                         // build_table_filename,
+                                               // tablename_to_filename,
+                                               // filename_to_tablename
+#include "sql_partition.h"  // HA_CAN_*, partition_info, part_id_range
+#include "sql_base.h"       // close_cached_tables
+#include "discover.h"       // readfrm
+#include "sql_acl.h"        // wild_case_compare
 #include "rpl_mi.h"
 
 /*
@@ -48,8 +56,11 @@ int ha_ndb_dummy;
 #include "ha_ndbcluster_binlog.h"
 #include "ha_ndbcluster_tables.h"
 
-#include <mysql/plugin.h>
+#include "sql_plugin.h"
 #include "probes_mysql.h"
+#include "sql_show.h"                   // init_fill_schema_files_row,
+                                        // schema_table_store_record
+#include "sql_test.h"                   // print_where
 
 #ifdef ndb_dynamite
 #undef assert

=== modified file 'sql/ha_ndbcluster.h'
--- a/sql/ha_ndbcluster.h	2009-10-22 22:30:28 +0000
+++ b/sql/ha_ndbcluster.h	2009-11-18 08:54:54 +0000
@@ -48,6 +48,8 @@ class NdbIndexStat;
 class NdbEventOperation;
 class ha_ndbcluster_cond;
 
+#include "sql_partition.h"                      /* part_id_range */
+
 // connectstring to cluster if given by mysqld
 extern const char *ndbcluster_connectstring;
 extern ulong ndb_cache_check_time;

=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc	2009-11-10 07:31:33 +0000
+++ b/sql/ha_ndbcluster_binlog.cc	2009-11-18 08:54:54 +0000
@@ -14,7 +14,8 @@
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"         // REQUIRED: for other includes
 #include "sql_show.h"
 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
 #include "ha_ndbcluster.h"
@@ -28,6 +29,14 @@
 #include "ndb_cluster_connection.hpp"
 #include <util/NdbAutoPtr.hpp>
 
+#include "sql_base.h"                           // close_thread_tables
+#include "sql_table.h"                         // build_table_filename
+#include "table.h"                             // open_table_from_share
+#include "discover.h"                          // readfrm, writefrm
+#include "lock.h"                              // MYSQL_LOCK_IGNORE_FLUSH,
+                                               // mysql_unlock_tables
+#include "sql_parse.h"                         // mysql_parse
+
 #ifdef ndb_dynamite
 #undef assert
 #define assert(x) do { if(x) break; ::printf("%s %d: assert failed: %s\n", __FILE__, __LINE__, #x); ::fflush(stdout); ::signal(SIGABRT,SIG_DFL); ::abort(); ::kill(::getpid(),6); ::kill(::getpid(),9); } while (0)

=== modified file 'sql/ha_ndbcluster_binlog.h'
--- a/sql/ha_ndbcluster_binlog.h	2009-09-23 21:32:31 +0000
+++ b/sql/ha_ndbcluster_binlog.h	2009-11-18 08:54:54 +0000
@@ -17,6 +17,8 @@
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
+#include "sql_class.h"                      /* THD */
+
 // Typedefs for long names
 typedef NdbDictionary::Object NDBOBJ;
 typedef NdbDictionary::Column NDBCOL;

=== modified file 'sql/ha_ndbcluster_cond.cc'
--- a/sql/ha_ndbcluster_cond.cc	2008-03-29 08:02:54 +0000
+++ b/sql/ha_ndbcluster_cond.cc	2009-11-18 08:54:54 +0000
@@ -22,7 +22,8 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "my_global.h"                          // WITH_*
 
 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
 #include <ndbapi/NdbApi.hpp>

=== modified file 'sql/ha_ndbcluster_cond.h'
--- a/sql/ha_ndbcluster_cond.h	2009-09-23 21:32:31 +0000
+++ b/sql/ha_ndbcluster_cond.h	2009-11-18 08:54:54 +0000
@@ -25,6 +25,13 @@
 #pragma interface                       /* gcc class implementation */
 #endif
 
+/*
+  It is necessary to include set_var.h instead of item.h because there
+  are dependencies on include order for set_var.h and item.h. This
+  will be resolved later.
+*/
+#include "set_var.h"                            /* Item, Item_field */
+
 typedef enum ndb_item_type {
   NDB_VALUE = 0,   // Qualified more with Item::Type
   NDB_FIELD = 1,   // Qualified from table definition

=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc	2009-11-03 11:37:02 +0000
+++ b/sql/ha_partition.cc	2009-11-18 08:54:54 +0000
@@ -51,12 +51,14 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "sql_parse.h"                          // append_file_to_dir
 
 #ifdef WITH_PARTITION_STORAGE_ENGINE
 #include "ha_partition.h"
-
-#include <mysql/plugin.h>
+#include "sql_table.h"                        // tablename_to_filename
+#include "key.h"
+#include "sql_plugin.h"
 
 static const char *ha_par_ext= ".par";
 #ifdef NOT_USED

=== modified file 'sql/ha_partition.h'
--- a/sql/ha_partition.h	2009-11-03 11:37:02 +0000
+++ b/sql/ha_partition.h	2009-11-18 08:54:54 +0000
@@ -20,6 +20,9 @@
 #pragma interface				/* gcc class implementation */
 #endif
 
+#include "sql_partition.h"      /* part_id_range, partition_element */
+#include "queues.h"             /* QUEUE */
+
 enum partition_keywords
 { 
   PKW_HASH= 0, PKW_RANGE, PKW_LIST, PKW_KEY, PKW_MAXVALUE, PKW_LINEAR,

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2009-11-06 14:20:27 +0000
+++ b/sql/handler.cc	2009-11-18 08:54:54 +0000
@@ -23,8 +23,19 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #include "rpl_handler.h"
+#include "sql_cache.h"                   // query_cache, query_cache_*
+#include "key.h"     // key_copy, key_unpack, key_cmp_if_same, key_cmp
+#include "sql_table.h"                   // build_table_filename
+#include "lock.h"               // wait_if_global_read_lock,
+                                // start_waiting_global_read_lock
+#include "sql_parse.h"                          // check_stack_overrun
+#include "sql_acl.h"            // SUPER_ACL
+#include "sql_base.h"           // free_io_cache
+#include "discover.h"           // writefrm
+#include "log_event.h"          // *_rows_log_event
 #include "rpl_filter.h"
 #include <myisampack.h>
 #include <errno.h>

=== modified file 'sql/handler.h'
--- a/sql/handler.h	2009-11-06 09:37:00 +0000
+++ b/sql/handler.h	2009-11-18 08:54:54 +0000
@@ -23,6 +23,13 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
+#include "sql_const.h"
+#include "mysqld.h"                             /* server_id */
+#include "sql_plugin.h"        /* plugin_ref, st_plugin_int, plugin */
+#include "thr_lock.h"          /* thr_lock_type, THR_LOCK_DATA */
+#include "sql_cache.h"
+#include "structs.h"                            /* SHOW_COMP_OPTION */
+
 #include <my_handler.h>
 #include <ft_global.h>
 #include <keycache.h>
@@ -2082,4 +2089,15 @@ int ha_binlog_end(THD *thd);
 #define ha_binlog_wait(a) do {} while (0)
 #define ha_binlog_end(a)  do {} while (0)
 #endif
+
+const char *get_canonical_filename(handler *file, const char *path,
+                                   char *tmp_path);
+bool mysql_xa_recover(THD *thd);
+
+
+inline const char *table_case_name(HA_CREATE_INFO *info, const char *name)
+{
+  return ((lower_case_table_names == 2 && info->alias) ? info->alias : name);
+}
+
 #endif /* HANDLER_INCLUDED */

=== modified file 'sql/hash_filo.cc'
--- a/sql/hash_filo.cc	2006-12-31 00:02:27 +0000
+++ b/sql/hash_filo.cc	2009-11-18 08:54:54 +0000
@@ -23,5 +23,5 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
 #include "hash_filo.h"

=== modified file 'sql/hash_filo.h'
--- a/sql/hash_filo.h	2009-10-14 16:37:38 +0000
+++ b/sql/hash_filo.h	2009-11-18 08:54:54 +0000
@@ -26,6 +26,9 @@
 #pragma interface			/* gcc class interface */
 #endif
 
+#include "hash.h"        /* my_hash_get_key, my_hash_free_key, HASH */
+#include "m_string.h"    /* bzero */
+
 class hash_filo_element
 {
   hash_filo_element *next_used,*prev_used;

=== modified file 'sql/hostname.cc'
--- a/sql/hostname.cc	2009-10-14 16:37:38 +0000
+++ b/sql/hostname.cc	2009-11-18 08:54:54 +0000
@@ -24,9 +24,14 @@
     checked that they doesn't resemble an ip.
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "hostname.h"
 #include "hash_filo.h"
 #include <m_ctype.h>
+#include "log.h"                                // sql_print_warning,
+                                                // sql_print_information
+#include "violite.h"                            // vio_getnameinfo,
+                                                // vio_get_normalized_ip_string
 #ifdef	__cplusplus
 extern "C" {					// Because of SCO 3.2V4.2
 #endif

=== added file 'sql/hostname.h'
--- a/sql/hostname.h	1970-01-01 00:00:00 +0000
+++ b/sql/hostname.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,28 @@
+#ifndef HOSTNAME_INCLUDED
+#define HOSTNAME_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "my_global.h"                          /* uint */
+
+char * ip_to_hostname(struct in_addr *in, uint *errors);
+void inc_host_errors(struct in_addr *in);
+void reset_host_errors(struct in_addr *in);
+bool hostname_cache_init();
+void hostname_cache_free();
+void hostname_cache_refresh(void);
+
+#endif /* HOSTNAME_INCLUDED */

=== modified file 'sql/init.cc'
--- a/sql/init.cc	2008-04-03 17:14:57 +0000
+++ b/sql/init.cc	2009-11-18 08:54:54 +0000
@@ -21,7 +21,12 @@
   Init and dummy functions for interface with unireg
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "init.h"
+#include "my_sys.h"
+#include "mysqld.h"                             // abort_loop, ...
+#include "my_time.h"                            // my_init_time
+#include "unireg.h"                             // SPECIAL_SAME_DB_NAME
 #include <m_ctype.h>
 
 void unireg_init(ulong options)

=== added file 'sql/init.h'
--- a/sql/init.h	1970-01-01 00:00:00 +0000
+++ b/sql/init.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,23 @@
+#ifndef INIT_INCLUDED
+#define INIT_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "my_global.h"                          /* ulong */
+
+void unireg_init(ulong options);
+
+#endif /* INIT_INCLUDED */

=== modified file 'sql/item.cc'
--- a/sql/item.cc	2009-11-06 14:20:27 +0000
+++ b/sql/item.cc	2009-11-18 08:54:54 +0000
@@ -17,7 +17,8 @@
 #ifdef USE_PRAGMA_IMPLEMENTATION
 #pragma implementation				// gcc: Class implementation
 #endif
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"                    // REQUIRED: for other includes
 #include <mysql.h>
 #include <m_ctype.h>
 #include "my_dir.h"
@@ -25,6 +26,19 @@
 #include "sp_head.h"
 #include "sql_trigger.h"
 #include "sql_select.h"
+#include "sql_show.h"                           // append_identifier
+#include "sql_view.h"                           // VIEW_ANY_SQL
+#include "sql_time.h"                  // str_to_datetime_with_warn,
+                                       // make_truncated_value_warning
+#include "sql_acl.h"                   // get_column_grant,
+                                       // SELECT_ACL, UPDATE_ACL,
+                                       // INSERT_ACL,
+                                       // check_grant_column
+#include "sql_base.h"                  // enum_resolution_type,
+                                       // REPORT_EXCEPT_NOT_FOUND,
+                                       // find_item_in_list,
+                                       // RESOLVED_AGAINST_ALIAS, ...
+#include "log_event.h"                 // append_query_string
 
 const String my_null_string("NULL", 4, default_charset_info);
 

=== modified file 'sql/item.h'
--- a/sql/item.h	2009-11-06 14:20:27 +0000
+++ b/sql/item.h	2009-11-18 08:54:54 +0000
@@ -21,10 +21,18 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
+#include "sql_priv.h"                /* STRING_BUFFER_USUAL_SIZE */
+#include "unireg.h"
+#include "sql_const.h"                 /* RAND_TABLE_BIT, MAX_FIELD_NAME */
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "thr_malloc.h"                         /* sql_calloc */
+#include "field.h"                              /* Derivation */
+
 class Protocol;
 struct TABLE_LIST;
 void item_init(void);			/* Init item functions */
 class Item_field;
+class user_var_entry;
 
 /*
    "Declared Type Collation"
@@ -2477,6 +2485,7 @@ public:
 #include "item_timefunc.h"
 #include "item_subselect.h"
 #include "item_xmlfunc.h"
+#include "item_create.h"
 #endif
 
 /**
@@ -2809,18 +2818,6 @@ public:
 };
 
 
-/*
-  We need this two enums here instead of sql_lex.h because
-  at least one of them is used by Item_trigger_field interface.
-
-  Time when trigger is invoked (i.e. before or after row actually
-  inserted/updated/deleted).
-*/
-enum trg_action_time_type
-{
-  TRG_ACTION_BEFORE= 0, TRG_ACTION_AFTER= 1, TRG_ACTION_MAX
-};
-
 class Table_triggers_list;
 
 /*
@@ -3155,4 +3152,6 @@ extern Item_result item_cmp_type(Item_re
 extern void resolve_const_item(THD *thd, Item **ref, Item *cmp_item);
 extern int stored_field_cmp_to_item(THD *thd, Field *field, Item *item);
 
+extern const String my_null_string;
+
 #endif /* ITEM_INCLUDED */

=== modified file 'sql/item_buff.cc'
--- a/sql/item_buff.cc	2007-10-11 17:29:09 +0000
+++ b/sql/item_buff.cc	2009-11-18 08:54:54 +0000
@@ -21,7 +21,14 @@
   Buffers to save and compare item values
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+/*
+  It is necessary to include set_var.h instead of item.h because there
+  are dependencies on include order for set_var.h and item.h. This
+  will be resolved later.
+*/
+#include "set_var.h"            // Cached_item, Cached_item_field, ...
+#include "sql_class.h"          // THD
 
 /**
   Create right type of Cached_item for an item.

=== modified file 'sql/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc	2009-11-03 12:48:59 +0000
+++ b/sql/item_cmpfunc.cc	2009-11-18 08:54:54 +0000
@@ -25,9 +25,11 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
 #include <m_ctype.h>
 #include "sql_select.h"
+#include "sql_parse.h"                          // check_stack_overrun
+#include "sql_time.h"                  // make_truncated_value_warning
 
 static bool convert_constant_item(THD *, Item_field *, Item **);
 

=== modified file 'sql/item_cmpfunc.h'
--- a/sql/item_cmpfunc.h	2009-11-06 14:20:27 +0000
+++ b/sql/item_cmpfunc.h	2009-11-18 08:54:54 +0000
@@ -23,6 +23,9 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
+#include "thr_malloc.h"                         /* sql_calloc */
+#include "item_func.h"             /* Item_int_func, Item_bool_func */
+
 extern Item_result item_cmp_type(Item_result a,Item_result b);
 class Item_bool_func2;
 class Arg_comparator;
@@ -1723,9 +1726,26 @@ inline Item *and_conds(Item *a, Item *b)
   return new Item_cond_and(a, b);
 }
 
+
 Item *and_expressions(Item *a, Item *b, Item **org_item);
 
+longlong get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
+                            Item *warn_item, bool *is_null);
+
+
 bool get_mysql_time_from_str(THD *thd, String *str, timestamp_type warn_type,
                              const char *warn_name, MYSQL_TIME *l_time);
 
+/*
+  These need definitions from this file but the variables are defined
+  in mysqld.h. The variables really belong in this component, but for
+  the time being we leave them in mysqld.cc to avoid merge problems.
+*/
+extern Eq_creator eq_creator;
+extern Ne_creator ne_creator;
+extern Gt_creator gt_creator;
+extern Lt_creator lt_creator;
+extern Ge_creator ge_creator;
+extern Le_creator le_creator;
+
 #endif /* ITEM_CMPFUNC_INCLUDED */

=== modified file 'sql/item_create.cc'
--- a/sql/item_create.cc	2009-11-03 11:37:02 +0000
+++ b/sql/item_create.cc	2009-11-18 08:54:54 +0000
@@ -20,8 +20,14 @@
   Functions to create an item. Used by sql_yac.yy
 */
 
-#include "mysql_priv.h"
-#include "item_create.h"
+#include "sql_priv.h"
+/*
+  It is necessary to include set_var.h instead of item.h because there
+  are dependencies on include order for set_var.h and item.h. This
+  will be resolved later.
+*/
+#include "set_var.h"
+#include "sql_class.h"
 #include "sp_head.h"
 #include "sp.h"
 

=== modified file 'sql/item_create.h'
--- a/sql/item_create.h	2007-08-15 13:43:08 +0000
+++ b/sql/item_create.h	2009-11-18 08:54:54 +0000
@@ -18,6 +18,8 @@
 #ifndef ITEM_CREATE_H
 #define ITEM_CREATE_H
 
+typedef struct st_udf_func udf_func;
+
 /**
   Public function builder interface.
   The parser (sql/sql_yacc.yy) uses a factory / builder pattern to
@@ -163,5 +165,9 @@ Item *
 create_func_cast(THD *thd, Item *a, Cast_target cast_type,
                  const char *len, const char *dec,
                  CHARSET_INFO *cs);
+
+int item_create_init();
+void item_create_cleanup();
+
 #endif
 

=== modified file 'sql/item_func.cc'
--- a/sql/item_func.cc	2009-11-06 14:20:27 +0000
+++ b/sql/item_func.cc	2009-11-18 08:54:54 +0000
@@ -25,8 +25,19 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+/*
+  It is necessary to include set_var.h instead of item.h because there
+  are dependencies on include order for set_var.h and item.h. This
+  will be resolved later.
+*/
+#include "set_var.h"
 #include "slave.h"				// for wait_for_master_pos
+#include "sql_show.h"                           // append_identifier
+#include "strfunc.h"                            // find_type
+#include "sql_parse.h"                          // is_update_query
+#include "sql_acl.h"                            // EXECUTE_ACL
+#include "mysqld.h"                             // LOCK_uuid_generator
 #include "rpl_mi.h"
 #include <m_ctype.h>
 #include <hash.h>

=== modified file 'sql/item_func.h'
--- a/sql/item_func.h	2009-11-06 14:20:27 +0000
+++ b/sql/item_func.h	2009-11-18 08:54:54 +0000
@@ -1720,4 +1720,14 @@ public:
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
 };
 
+Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name,
+                     LEX_STRING component);
+extern bool check_reserved_words(LEX_STRING *name);
+extern enum_field_types agg_field_type(Item **items, uint nitems);
+double my_double_round(double value, longlong dec, bool dec_unsigned,
+                       bool truncate);
+bool eval_const_cond(COND *cond);
+
+extern bool volatile  mqh_used;
+
 #endif /* ITEM_FUNC_INCLUDED */

=== modified file 'sql/item_geofunc.cc'
--- a/sql/item_geofunc.cc	2009-10-24 06:57:31 +0000
+++ b/sql/item_geofunc.cc	2009-11-18 08:54:54 +0000
@@ -25,7 +25,14 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+/*
+  It is necessary to include set_var.h instead of item.h because there
+  are dependencies on include order for set_var.h and item.h. This
+  will be resolved later.
+*/
+#include "set_var.h"
+#include "sql_class.h"                          // THD
 #ifdef HAVE_SPATIAL
 #include <m_ctype.h>
 

=== modified file 'sql/item_row.cc'
--- a/sql/item_row.cc	2008-02-22 10:30:33 +0000
+++ b/sql/item_row.cc	2009-11-18 08:54:54 +0000
@@ -13,7 +13,14 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+/*
+  It is necessary to include set_var.h instead of item.h because there
+  are dependencies on include order for set_var.h and item.h. This
+  will be resolved later.
+*/
+#include "set_var.h"
+#include "sql_class.h"                          // THD
 
 /**
   Row items used for comparing rows and IN operations on rows:

=== modified file 'sql/item_strfunc.cc'
--- a/sql/item_strfunc.cc	2009-10-05 15:06:04 +0000
+++ b/sql/item_strfunc.cc	2009-11-18 08:54:54 +0000
@@ -29,7 +29,21 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "my_global.h"                          // HAVE_*
+
+
+#include "sql_priv.h"
+/*
+  It is necessary to include set_var.h instead of item.h because there
+  are dependencies on include order for set_var.h and item.h. This
+  will be resolved later.
+*/
+#include "set_var.h"
+#include "mysqld.h"                             // LOCK_uuid_generator
+#include "sql_acl.h"                            // SUPER_ACL
+#include "des_key_file.h"       // st_des_keyschedule, st_des_keyblock
+#include "password.h"           // my_make_scrambled_password,
+                                // my_make_scrambled_password_323
 #include <m_ctype.h>
 #include "my_md5.h"
 #include "sha1.h"

=== modified file 'sql/item_strfunc.h'
--- a/sql/item_strfunc.h	2009-10-22 22:30:28 +0000
+++ b/sql/item_strfunc.h	2009-11-18 08:54:54 +0000
@@ -23,6 +23,8 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
+typedef struct my_locale_st MY_LOCALE;
+
 class Item_str_func :public Item_func
 {
 public:
@@ -850,4 +852,6 @@ public:
   String *val_str(String *);
 };
 
+extern String my_empty_string;
+
 #endif /* ITEM_STRFUNC_INCLUDED */

=== modified file 'sql/item_subselect.cc'
--- a/sql/item_subselect.cc	2009-11-06 16:13:33 +0000
+++ b/sql/item_subselect.cc	2009-11-18 08:54:54 +0000
@@ -28,8 +28,15 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+/*
+  It is necessary to include set_var.h instead of item.h because there
+  are dependencies on include order for set_var.h and item.h. This
+  will be resolved later.
+*/
+#include "set_var.h"
 #include "sql_select.h"
+#include "sql_parse.h"                          // check_stack_overrun
 
 inline Item * and_items(Item* cond, Item *item)
 {

=== modified file 'sql/item_subselect.h'
--- a/sql/item_subselect.h	2009-09-23 21:32:31 +0000
+++ b/sql/item_subselect.h	2009-11-18 08:54:54 +0000
@@ -28,6 +28,15 @@ class JOIN;
 class select_subselect;
 class subselect_engine;
 class Item_bool_func2;
+class Comp_creator;
+
+typedef class st_select_lex SELECT_LEX;
+
+/**
+  Convenience typedef used in this file, and further used by any files
+  including this file.
+*/
+typedef Comp_creator* (*chooser_compare_func_creator)(bool invert);
 
 /* base class for subselects */
 
@@ -571,6 +580,15 @@ public:
   virtual void print (String *str, enum_query_type query_type);
 };
 
+/*
+  This function is actually defined in sql_parse.cc, but it depends on
+  chooser_compare_func_creator defined in this file.
+ */
+Item * all_any_subquery_creator(Item *left_expr,
+                                chooser_compare_func_creator cmp,
+                                bool all,
+                                SELECT_LEX *select_lex);
+
 
 inline bool Item_subselect::is_evaluated() const
 {

=== modified file 'sql/item_sum.cc'
--- a/sql/item_sum.cc	2009-11-06 14:20:27 +0000
+++ b/sql/item_sum.cc	2009-11-18 08:54:54 +0000
@@ -25,7 +25,7 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
 #include "sql_select.h"
 
 /**

=== modified file 'sql/item_sum.h'
--- a/sql/item_sum.h	2009-10-28 10:07:30 +0000
+++ b/sql/item_sum.h	2009-11-18 08:54:54 +0000
@@ -24,6 +24,7 @@
 #endif
 
 #include <my_tree.h>
+#include "sql_udf.h"                            /* udf_handler */
 
 class Item_sum;
 class Aggregator_distinct;

=== modified file 'sql/item_timefunc.cc'
--- a/sql/item_timefunc.cc	2009-10-28 17:22:36 +0000
+++ b/sql/item_timefunc.cc	2009-11-18 08:54:54 +0000
@@ -28,7 +28,27 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+/*
+  It is necessary to include set_var.h instead of item.h because there
+  are dependencies on include order for set_var.h and item.h. This
+  will be resolved later.
+*/
+#include "set_var.h"
+#include "sql_locale.h"          // MY_LOCALE my_locale_en_US
+#include "strfunc.h"             // check_word
+#include "sql_time.h"            // make_truncated_value_warning,
+                                 // make_time, get_date_from_daynr,
+                                 // calc_weekday, calc_week,
+                                 // convert_month_to_period,
+                                 // convert_period_to_month,
+                                 // TIME_to_timestamp, make_date,
+                                 // calc_time_diff,
+                                 // calc_time_from_sec,
+                                 // known_date_time_format,
+                                 // get_date_time_format_str
+#include "tztime.h"              // struct Time_zone
+#include "sql_class.h"           // THD
 #include <m_ctype.h>
 #include <time.h>
 

=== modified file 'sql/item_timefunc.h'
--- a/sql/item_timefunc.h	2009-11-02 10:09:15 +0000
+++ b/sql/item_timefunc.h	2009-11-18 08:54:54 +0000
@@ -23,6 +23,8 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
+typedef struct my_locale_st MY_LOCALE;
+
 enum date_time_format_types 
 { 
   TIME_ONLY= 0, TIME_MICROSECOND, DATE_ONLY, DATE_TIME, DATE_TIME_MICROSECOND
@@ -1054,4 +1056,10 @@ public:
   }
 };
 
+
+/* Function prototypes */
+
+bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
+                    timestamp_type type, String *str);
+
 #endif /* ITEM_TIMEFUNC_INCLUDED */

=== modified file 'sql/item_xmlfunc.cc'
--- a/sql/item_xmlfunc.cc	2009-09-23 13:21:29 +0000
+++ b/sql/item_xmlfunc.cc	2009-11-18 08:54:54 +0000
@@ -17,9 +17,16 @@
 #pragma implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+/*
+  It is necessary to include set_var.h instead of item.h because there
+  are dependencies on include order for set_var.h and item.h. This
+  will be resolved later.
+*/
+#include "set_var.h"
 #include "my_xml.h"
 #include "sp_pcontext.h"
+#include "sql_class.h"                          // THD
 
 /*
   TODO: future development directions:

=== modified file 'sql/key.cc'
--- a/sql/key.cc	2009-10-15 12:23:43 +0000
+++ b/sql/key.cc	2009-11-18 08:54:54 +0000
@@ -16,7 +16,10 @@
 
 /* Functions to handle keys and fields in forms */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"                     // REQUIRED: by includes later
+#include "key.h"                                // key_rec_cmp
+#include "field.h"                              // Field
 
 /*
   Search after a key that starts with 'field'

=== added file 'sql/key.h'
--- a/sql/key.h	1970-01-01 00:00:00 +0000
+++ b/sql/key.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,39 @@
+#ifndef KEY_INCLUDED
+#define KEY_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "my_global.h"                          /* uchar */
+
+class Field;
+class String;
+struct TABLE;
+typedef struct st_bitmap MY_BITMAP;
+typedef struct st_key KEY;
+typedef struct st_key_part_info KEY_PART_INFO;
+
+int find_ref_key(KEY *key, uint key_count, uchar *record, Field *field,
+                 uint *key_length, uint *keypart);
+void key_copy(uchar *to_key, uchar *from_record, KEY *key_info, uint key_length);
+void key_restore(uchar *to_record, uchar *from_key, KEY *key_info,
+                 uint key_length);
+bool key_cmp_if_same(TABLE *form,const uchar *key,uint index,uint key_length);
+void key_unpack(String *to,TABLE *form,uint index);
+bool is_key_used(TABLE *table, uint idx, const MY_BITMAP *fields);
+int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length);
+extern "C" int key_rec_cmp(void *key_info, uchar *a, uchar *b);
+
+#endif /* KEY_INCLUDED */

=== modified file 'sql/lock.cc'
--- a/sql/lock.cc	2009-10-14 16:37:38 +0000
+++ b/sql/lock.cc	2009-11-18 08:54:54 +0000
@@ -73,7 +73,12 @@
   we are forced to use mysql_lock_merge.
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "lock.h"
+#include "sql_base.h"                       // close_tables_for_reopen
+#include "sql_parse.h"                     // is_log_table_write_query
+#include "sql_acl.h"                       // SUPER_ACL
 #include <hash.h>
 #include <assert.h>
 

=== added file 'sql/lock.h'
--- a/sql/lock.h	1970-01-01 00:00:00 +0000
+++ b/sql/lock.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,58 @@
+#ifndef LOCK_INCLUDED
+#define LOCK_INCLUDED
+
+#include "thr_lock.h"                           /* thr_lock_type */
+
+class TABLE_LIST;
+class THD;
+struct TABLE;
+typedef struct st_mysql_lock MYSQL_LOCK;
+
+MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **table, uint count,
+                              uint flags, bool *need_reopen);
+/* mysql_lock_tables() and open_table() flags bits */
+#define MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK      0x0001
+#define MYSQL_LOCK_IGNORE_FLUSH                 0x0002
+#define MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN        0x0004
+#define MYSQL_OPEN_TEMPORARY_ONLY               0x0008
+#define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY      0x0010
+#define MYSQL_LOCK_PERF_SCHEMA                  0x0020
+
+void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock);
+void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock);
+void mysql_unlock_some_tables(THD *thd, TABLE **table,uint count);
+void mysql_lock_remove(THD *thd, MYSQL_LOCK *locked,TABLE *table,
+                       bool always_unlock);
+void mysql_lock_abort(THD *thd, TABLE *table, bool upgrade_lock);
+void mysql_lock_downgrade_write(THD *thd, TABLE *table,
+                                thr_lock_type new_lock_type);
+bool mysql_lock_abort_for_thread(THD *thd, TABLE *table);
+MYSQL_LOCK *mysql_lock_merge(MYSQL_LOCK *a,MYSQL_LOCK *b);
+TABLE_LIST *mysql_lock_have_duplicate(THD *thd, TABLE_LIST *needle,
+                                      TABLE_LIST *haystack);
+bool lock_global_read_lock(THD *thd);
+void unlock_global_read_lock(THD *thd);
+bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh,
+                              bool is_not_commit);
+void start_waiting_global_read_lock(THD *thd);
+bool make_global_read_lock_block_commit(THD *thd);
+bool set_protect_against_global_read_lock(void);
+void unset_protect_against_global_read_lock(void);
+void broadcast_refresh(void);
+
+/* Lock based on name */
+int lock_and_wait_for_table_name(THD *thd, TABLE_LIST *table_list);
+int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use);
+void unlock_table_name(THD *thd, TABLE_LIST *table_list);
+bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list);
+bool lock_table_names(THD *thd, TABLE_LIST *table_list);
+void unlock_table_names(THD *thd, TABLE_LIST *table_list,
+			TABLE_LIST *last_table);
+bool lock_table_names_exclusively(THD *thd, TABLE_LIST *table_list);
+bool is_table_name_exclusively_locked_by_this_thread(THD *thd, 
+                                                     TABLE_LIST *table_list);
+bool is_table_name_exclusively_locked_by_this_thread(THD *thd, uchar *key,
+                                                     int key_length);
+
+
+#endif /* LOCK_INCLUDED */

=== modified file 'sql/log.cc'
--- a/sql/log.cc	2009-11-06 14:20:27 +0000
+++ b/sql/log.cc	2009-11-18 08:54:54 +0000
@@ -24,8 +24,16 @@
     Abort logging when we get an error in reading or writing log files
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "log.h"
+#include "sql_base.h"                           // close_thread_tables
 #include "sql_repl.h"
+#include "sql_delete.h"                         // mysql_truncate
+#include "sql_parse.h"                          // command_name
+#include "sql_time.h"           // calc_time_from_sec, my_time_compare
+#include "tztime.h"             // my_tz_OFFSET0, struct Time_zone
+#include "sql_acl.h"            // SUPER_ACL
+#include "log_event.h"          // Query_log_event
 #include "rpl_filter.h"
 #include "rpl_rli.h"
 
@@ -37,7 +45,7 @@
 #include "message.h"
 #endif
 
-#include <mysql/plugin.h>
+#include "sql_plugin.h"
 #include "rpl_handler.h"
 
 /* max size of the log message */

=== modified file 'sql/log.h'
--- a/sql/log.h	2009-10-07 21:13:07 +0000
+++ b/sql/log.h	2009-11-18 08:54:54 +0000
@@ -16,6 +16,9 @@
 #ifndef LOG_H
 #define LOG_H
 
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "handler.h"                            /* my_xid */
+
 class Relay_log_info;
 
 class Format_description_log_event;
@@ -610,6 +613,35 @@ enum enum_binlog_format {
 };
 extern TYPELIB binlog_format_typelib;
 
+int vprint_msg_to_log(enum loglevel level, const char *format, va_list args);
+void sql_print_error(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
+void sql_print_warning(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
+void sql_print_information(const char *format, ...)
+  ATTRIBUTE_FORMAT(printf, 1, 2);
+typedef void (*sql_print_message_func)(const char *format, ...)
+  ATTRIBUTE_FORMAT(printf, 1, 2);
+extern sql_print_message_func sql_print_message_handlers[];
+
+int error_log_print(enum loglevel level, const char *format,
+                    va_list args);
+
+bool slow_log_print(THD *thd, const char *query, uint query_length,
+                    ulonglong current_utime);
+
+bool general_log_print(THD *thd, enum enum_server_command command,
+                       const char *format,...);
+
+bool general_log_write(THD *thd, enum enum_server_command command,
+                       const char *query, uint query_length);
+
+void sql_perror(const char *message);
+bool flush_error_log();
+
 int query_error_code(THD *thd, bool not_killed);
+File open_binlog(IO_CACHE *log, const char *log_file_name,
+                 const char **errmsg);
+
+extern MYSQL_PLUGIN_IMPORT MYSQL_BIN_LOG mysql_bin_log;
+extern LOGGER logger;
 
 #endif /* LOG_H */

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2009-11-10 07:31:33 +0000
+++ b/sql/log_event.cc	2009-11-18 08:54:54 +0000
@@ -16,7 +16,7 @@
 
 #ifdef MYSQL_CLIENT
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
 
 #else
 
@@ -24,7 +24,19 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "my_global.h" // REQUIRED by log_event.h > m_string.h > my_bitmap.h
+#include "log_event.h"
+#include "sql_base.h"                           // close_thread_tables
+#include "sql_cache.h"                       // QUERY_CACHE_FLAGS_SIZE
+#include "sql_locale.h" // MY_LOCALE, my_locale_by_number, my_locale_en_US
+#include "key.h"        // key_copy
+#include "lock.h"       // mysql_unlock_tables
+#include "sql_parse.h"  // mysql_test_parse_for_slave
+#include "tztime.h"     // struct Time_zone
+#include "sql_load.h"   // mysql_load
+#include "sql_db.h"     // load_db_opt_by_name
 #include "slave.h"
 #include "rpl_rli.h"
 #include "rpl_mi.h"

=== modified file 'sql/log_event.h'
--- a/sql/log_event.h	2009-10-22 22:30:28 +0000
+++ b/sql/log_event.h	2009-11-18 08:54:54 +0000
@@ -28,7 +28,7 @@
 #ifndef _log_event_h
 #define _log_event_h
 
-#if defined(USE_PRAGMA_INTERFACE) && !defined(MYSQL_CLIENT)
+#if defined(USE_PRAGMA_INTERFACE) && defined(MYSQL_SERVER)
 #pragma interface			/* gcc class implementation */
 #endif
 
@@ -36,17 +36,22 @@
 #include "rpl_constants.h"
 
 #ifdef MYSQL_CLIENT
+#include "sql_const.h"
 #include "rpl_utility.h"
 #include "hash.h"
 #include "rpl_tblmap.h"
 #include "rpl_tblmap.cc"
 #endif
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
 #include "rpl_record.h"
 #include "rpl_reporting.h"
+#include "sql_class.h"                          /* THD */
 #endif
 
+/* Forward declarations */
+class String;
+
 #define PREFIX_SQL_LOAD "SQL_LOAD-"
 
 /**
@@ -602,7 +607,7 @@ enum Int_event_type
 };
 
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
 class String;
 class MYSQL_BIN_LOG;
 class THD;
@@ -680,11 +685,9 @@ typedef struct st_print_event_info
   uint8 common_header_len;
   char delimiter[16];
 
-#ifdef MYSQL_CLIENT
   uint verbose;
   table_mapping m_table_map;
   table_mapping m_table_map_ignored;
-#endif
 
   /*
      These two caches are used by the row-based replication events to
@@ -929,7 +932,7 @@ public:
   */
   ulong slave_exec_mode;
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   THD* thd;
 
   Log_event();
@@ -1001,7 +1004,7 @@ public:
   static void *operator new(size_t, void* ptr) { return ptr; }
   static void operator delete(void*, void*) { }
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   bool write_header(IO_CACHE* file, ulong data_length);
   virtual bool write(IO_CACHE* file)
   {
@@ -1064,7 +1067,7 @@ public:
 
   /* Return start of query time or current time */
 
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
 public:
 
   /**
@@ -1368,7 +1371,7 @@ protected:
     <td>Q_SQL_MODE_CODE == 1</td>
     <td>8 byte bitfield</td>
     <td>The @c sql_mode variable.  See the section "SQL Modes" in the
-    MySQL manual, and see mysql_priv.h for a list of the possible
+    MySQL manual, and see sql_priv.h for a list of the possible
     flags. Currently (2007-10-04), the following flags are available:
     <pre>
     MODE_REAL_AS_FLOAT==0x1
@@ -1642,7 +1645,7 @@ public:
   */
   ulonglong table_map_for_update;
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
 
   Query_log_event(THD* thd_arg, const char* query_arg, ulong query_length,
                   bool using_trans, bool suppress_use, int error);
@@ -1665,7 +1668,7 @@ public:
       my_free((uchar*) data_buf, MYF(0));
   }
   Log_event_type get_type_code() { return QUERY_EVENT; }
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   bool write(IO_CACHE* file);
   virtual bool write_post_header_for_derived(IO_CACHE* file) { return FALSE; }
 #endif
@@ -1679,7 +1682,7 @@ public:
   /* Writes derived event-specific part of post header. */
 
 public:        /* !!! Public in this patch to allow old usage */
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
   virtual int do_apply_event(Relay_log_info const *rli);
   virtual int do_update_pos(Relay_log_info *rli);
@@ -1754,7 +1757,7 @@ public:
   int master_log_len;
   uint16 master_port;
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Slave_log_event(THD* thd_arg, Relay_log_info* rli);
   void pack_info(Protocol* protocol);
 #else
@@ -1766,12 +1769,12 @@ public:
   int get_data_size();
   bool is_valid() const { return master_host != 0; }
   Log_event_type get_type_code() { return SLAVE_EVENT; }
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   bool write(IO_CACHE* file);
 #endif
 
 private:
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_apply_event(Relay_log_info const* rli);
 #endif
 };
@@ -2025,7 +2028,7 @@ public:
     return local_fname;
   }
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   String field_lens_buf;
   String fields_buf;
 
@@ -2058,7 +2061,7 @@ public:
   {
     return sql_ex.new_format() ? NEW_LOAD_EVENT: LOAD_EVENT;
   }
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   bool write_data_header(IO_CACHE* file);
   bool write_data_body(IO_CACHE* file);
 #endif
@@ -2071,7 +2074,7 @@ public:
   }
 
 public:        /* !!! Public in this patch to allow old usage */
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_apply_event(Relay_log_info const* rli)
   {
     return do_apply_event(thd->slave_net,rli,0);
@@ -2133,7 +2136,7 @@ public:
   */
   bool dont_set_created;
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Start_log_event_v3();
 #ifdef HAVE_REPLICATION
   void pack_info(Protocol* protocol);
@@ -2147,7 +2150,7 @@ public:
                      const Format_description_log_event* description_event);
   ~Start_log_event_v3() {}
   Log_event_type get_type_code() { return START_EVENT_V3;}
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   bool write(IO_CACHE* file);
 #endif
   bool is_valid() const { return 1; }
@@ -2157,7 +2160,7 @@ public:
   }
 
 protected:
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_apply_event(Relay_log_info const *rli);
   virtual enum_skip_reason do_shall_skip(Relay_log_info*)
   {
@@ -2209,7 +2212,7 @@ public:
     my_free((uchar*)post_header_len, MYF(MY_ALLOW_ZERO_PTR));
   }
   Log_event_type get_type_code() { return FORMAT_DESCRIPTION_EVENT;}
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   bool write(IO_CACHE* file);
 #endif
   bool is_valid() const
@@ -2231,7 +2234,7 @@ public:
   void calc_server_version_split();
 
 protected:
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_apply_event(Relay_log_info const *rli);
   virtual int do_update_pos(Relay_log_info *rli);
   virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
@@ -2283,7 +2286,7 @@ public:
   ulonglong val;
   uchar type;
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Intvar_log_event(THD* thd_arg,uchar type_arg, ulonglong val_arg)
     :Log_event(thd_arg,0,0),val(val_arg),type(type_arg)
   {}
@@ -2300,13 +2303,13 @@ public:
   Log_event_type get_type_code() { return INTVAR_EVENT;}
   const char* get_var_type_name();
   int get_data_size() { return  9; /* sizeof(type) + sizeof(val) */;}
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   bool write(IO_CACHE* file);
 #endif
   bool is_valid() const { return 1; }
 
 private:
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_apply_event(Relay_log_info const *rli);
   virtual int do_update_pos(Relay_log_info *rli);
   virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
@@ -2359,7 +2362,7 @@ class Rand_log_event: public Log_event
   ulonglong seed1;
   ulonglong seed2;
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Rand_log_event(THD* thd_arg, ulonglong seed1_arg, ulonglong seed2_arg)
     :Log_event(thd_arg,0,0),seed1(seed1_arg),seed2(seed2_arg)
   {}
@@ -2375,13 +2378,13 @@ class Rand_log_event: public Log_event
   ~Rand_log_event() {}
   Log_event_type get_type_code() { return RAND_EVENT;}
   int get_data_size() { return 16; /* sizeof(ulonglong) * 2*/ }
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   bool write(IO_CACHE* file);
 #endif
   bool is_valid() const { return 1; }
 
 private:
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_apply_event(Relay_log_info const *rli);
   virtual int do_update_pos(Relay_log_info *rli);
   virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
@@ -2405,7 +2408,7 @@ class Xid_log_event: public Log_event
  public:
    my_xid xid;
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Xid_log_event(THD* thd_arg, my_xid x): Log_event(thd_arg,0,0), xid(x) {}
 #ifdef HAVE_REPLICATION
   void pack_info(Protocol* protocol);
@@ -2419,13 +2422,13 @@ class Xid_log_event: public Log_event
   ~Xid_log_event() {}
   Log_event_type get_type_code() { return XID_EVENT;}
   int get_data_size() { return sizeof(xid); }
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   bool write(IO_CACHE* file);
 #endif
   bool is_valid() const { return 1; }
 
 private:
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_apply_event(Relay_log_info const *rli);
   enum_skip_reason do_shall_skip(Relay_log_info *rli);
 #endif
@@ -2450,7 +2453,7 @@ public:
   Item_result type;
   uint charset_number;
   bool is_null;
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   User_var_log_event(THD* thd_arg, char *name_arg, uint name_len_arg,
                      char *val_arg, ulong val_len_arg, Item_result type_arg,
 		     uint charset_number_arg)
@@ -2466,13 +2469,13 @@ public:
                      const Format_description_log_event *description_event);
   ~User_var_log_event() {}
   Log_event_type get_type_code() { return USER_VAR_EVENT;}
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   bool write(IO_CACHE* file);
 #endif
   bool is_valid() const { return 1; }
 
 private:
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_apply_event(Relay_log_info const *rli);
   virtual int do_update_pos(Relay_log_info *rli);
   virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
@@ -2491,7 +2494,7 @@ private:
 class Stop_log_event: public Log_event
 {
 public:
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Stop_log_event() :Log_event()
   {}
 #else
@@ -2507,7 +2510,7 @@ public:
   bool is_valid() const { return 1; }
 
 private:
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_update_pos(Relay_log_info *rli);
   virtual enum_skip_reason do_shall_skip(Relay_log_info *rli)
   {
@@ -2583,7 +2586,7 @@ public:
   ulonglong pos;
   uint ident_len;
   uint flags;
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Rotate_log_event(const char* new_log_ident_arg,
 		   uint ident_len_arg,
 		   ulonglong pos_arg, uint flags);
@@ -2604,12 +2607,12 @@ public:
   Log_event_type get_type_code() { return ROTATE_EVENT;}
   int get_data_size() { return  ident_len + ROTATE_HEADER_LEN;}
   bool is_valid() const { return new_log_ident != 0; }
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   bool write(IO_CACHE* file);
 #endif
 
 private:
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_update_pos(Relay_log_info *rli);
   virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 #endif
@@ -2640,7 +2643,7 @@ public:
   uint file_id;
   bool inited_from_old;
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Create_file_log_event(THD* thd, sql_exchange* ex, const char* db_arg,
 			const char* table_name_arg,
 			List<Item>& fields_arg,
@@ -2674,7 +2677,7 @@ public:
 	    4 + 1 + block_len);
   }
   bool is_valid() const { return inited_from_old || block != 0; }
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   bool write_data_header(IO_CACHE* file);
   bool write_data_body(IO_CACHE* file);
   /*
@@ -2685,7 +2688,7 @@ public:
 #endif
 
 private:
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_apply_event(Relay_log_info const *rli);
 #endif
 };
@@ -2716,7 +2719,7 @@ public:
   */
   const char* db;
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Append_block_log_event(THD* thd, const char* db_arg, uchar* block_arg,
 			 uint block_len_arg, bool using_trans);
 #ifdef HAVE_REPLICATION
@@ -2734,13 +2737,13 @@ public:
   Log_event_type get_type_code() { return APPEND_BLOCK_EVENT;}
   int get_data_size() { return  block_len + APPEND_BLOCK_HEADER_LEN ;}
   bool is_valid() const { return block != 0; }
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   bool write(IO_CACHE* file);
   const char* get_db() { return db; }
 #endif
 
 private:
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_apply_event(Relay_log_info const *rli);
 #endif
 };
@@ -2758,7 +2761,7 @@ public:
   uint file_id;
   const char* db; /* see comment in Append_block_log_event */
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Delete_file_log_event(THD* thd, const char* db_arg, bool using_trans);
 #ifdef HAVE_REPLICATION
   void pack_info(Protocol* protocol);
@@ -2775,13 +2778,13 @@ public:
   Log_event_type get_type_code() { return DELETE_FILE_EVENT;}
   int get_data_size() { return DELETE_FILE_HEADER_LEN ;}
   bool is_valid() const { return file_id != 0; }
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   bool write(IO_CACHE* file);
   const char* get_db() { return db; }
 #endif
 
 private:
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_apply_event(Relay_log_info const *rli);
 #endif
 };
@@ -2799,7 +2802,7 @@ public:
   uint file_id;
   const char* db; /* see comment in Append_block_log_event */
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Execute_load_log_event(THD* thd, const char* db_arg, bool using_trans);
 #ifdef HAVE_REPLICATION
   void pack_info(Protocol* protocol);
@@ -2815,13 +2818,13 @@ public:
   Log_event_type get_type_code() { return EXEC_LOAD_EVENT;}
   int get_data_size() { return  EXEC_LOAD_HEADER_LEN ;}
   bool is_valid() const { return file_id != 0; }
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   bool write(IO_CACHE* file);
   const char* get_db() { return db; }
 #endif
 
 private:
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_apply_event(Relay_log_info const *rli);
 #endif
 };
@@ -2839,7 +2842,7 @@ private:
 class Begin_load_query_log_event: public Append_block_log_event
 {
 public:
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Begin_load_query_log_event(THD* thd_arg, const char *db_arg,
                              uchar* block_arg, uint block_len_arg,
                              bool using_trans);
@@ -2854,7 +2857,7 @@ public:
   ~Begin_load_query_log_event() {}
   Log_event_type get_type_code() { return BEGIN_LOAD_QUERY_EVENT; }
 private:
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 #endif
 };
@@ -2890,7 +2893,7 @@ public:
   */
   enum_load_dup_handling dup_handling;
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Execute_load_query_log_event(THD* thd, const char* query_arg,
                                ulong query_length, uint fn_pos_start_arg,
                                uint fn_pos_end_arg,
@@ -2915,12 +2918,12 @@ public:
   bool is_valid() const { return Query_log_event::is_valid() && file_id != 0; }
 
   ulong get_post_header_size_for_derived();
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   bool write_post_header_for_derived(IO_CACHE* file);
 #endif
 
 private:
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_apply_event(Relay_log_info const *rli);
 #endif
 };
@@ -3311,7 +3314,7 @@ public:
   void clear_flags(flag_set flag) { m_flags &= ~flag; }
   flag_set get_flags(flag_set flag) const { return m_flags & flag; }
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Table_map_log_event(THD *thd, TABLE *tbl, ulong tid, 
 		      bool is_transactional, uint16 flags);
 #endif
@@ -3337,14 +3340,14 @@ public:
   virtual bool is_valid() const { return m_memory != NULL; /* we check malloc */ }
 
   virtual int get_data_size() { return (uint) m_data_size; } 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   virtual int save_field_metadata();
   virtual bool write_data_header(IO_CACHE *file);
   virtual bool write_data_body(IO_CACHE *file);
   virtual const char *get_db() { return m_dbnam; }
 #endif
 
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual void pack_info(Protocol *protocol);
 #endif
 
@@ -3354,13 +3357,13 @@ public:
 
 
 private:
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_apply_event(Relay_log_info const *rli);
   virtual int do_update_pos(Relay_log_info *rli);
   virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 #endif
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   TABLE         *m_table;
 #endif
   char const    *m_dbnam;
@@ -3456,7 +3459,7 @@ public:
   void clear_flags(flag_set flags_arg) { m_flags &= ~flags_arg; }
   flag_set get_flags(flag_set flags_arg) const { return m_flags & flags_arg; }
 
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual void pack_info(Protocol *protocol);
 #endif
 
@@ -3471,7 +3474,7 @@ public:
                                const uchar *ptr, const uchar *prefix);
 #endif
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   int add_row_data(uchar *data, size_t length)
   {
     return do_add_row_data(data,length); 
@@ -3485,7 +3488,7 @@ public:
   size_t get_width() const          { return m_width; }
   ulong get_table_id() const        { return m_table_id; }
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   virtual bool write_data_header(IO_CACHE *file);
   virtual bool write_data_body(IO_CACHE *file);
   virtual const char *get_db() { return m_table->s->db.str; }
@@ -3508,7 +3511,7 @@ protected:
      The constructors are protected since you're supposed to inherit
      this class, not create instances of this class.
   */
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Rows_log_event(THD*, TABLE*, ulong table_id, 
 		 MY_BITMAP const *cols, bool is_transactional);
 #endif
@@ -3520,11 +3523,11 @@ protected:
   void print_helper(FILE *, PRINT_EVENT_INFO *, char const *const name);
 #endif
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   virtual int do_add_row_data(uchar *data, size_t length);
 #endif
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   TABLE *m_table;		/* The table the rows belong to */
 #endif
   ulong       m_table_id;	/* Table ID */
@@ -3553,7 +3556,7 @@ protected:
 
   /* helper functions */
 
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   const uchar *m_curr_row;     /* Start of the row being processed */
   const uchar *m_curr_row_end; /* One-after the end of the current row */
   uchar    *m_key;      /* Buffer to keep key value during searches */
@@ -3581,7 +3584,7 @@ protected:
 
 private:
 
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_apply_event(Relay_log_info const *rli);
   virtual int do_update_pos(Relay_log_info *rli);
   virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
@@ -3636,7 +3639,7 @@ private:
       
   */
   virtual int do_exec_row(const Relay_log_info *const rli) = 0;
-#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
+#endif /* defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) */
 
   friend class Old_rows_log_event;
 };
@@ -3659,7 +3662,7 @@ public:
     TYPE_CODE = WRITE_ROWS_EVENT
   };
 
-#if !defined(MYSQL_CLIENT)
+#if defined(MYSQL_SERVER)
   Write_rows_log_event(THD*, TABLE*, ulong table_id, 
 		       MY_BITMAP const *cols, bool is_transactional);
 #endif
@@ -3667,7 +3670,7 @@ public:
   Write_rows_log_event(const char *buf, uint event_len, 
                        const Format_description_log_event *description_event);
 #endif
-#if !defined(MYSQL_CLIENT) 
+#if defined(MYSQL_SERVER) 
   static bool binlog_row_logging_function(THD *thd, TABLE *table,
                                           bool is_transactional,
                                           MY_BITMAP *cols,
@@ -3688,7 +3691,7 @@ private:
   void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
 #endif
 
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_before_row_operations(const Slave_reporting_capability *const);
   virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
   virtual int do_exec_row(const Relay_log_info *const);
@@ -3717,7 +3720,7 @@ public:
     TYPE_CODE = UPDATE_ROWS_EVENT
   };
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Update_rows_log_event(THD*, TABLE*, ulong table_id,
 			MY_BITMAP const *cols_bi,
 			MY_BITMAP const *cols_ai,
@@ -3737,7 +3740,7 @@ public:
 			const Format_description_log_event *description_event);
 #endif
 
-#if !defined(MYSQL_CLIENT) 
+#ifdef MYSQL_SERVER
   static bool binlog_row_logging_function(THD *thd, TABLE *table,
                                           bool is_transactional,
                                           MY_BITMAP *cols,
@@ -3762,11 +3765,11 @@ protected:
   void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
 #endif
 
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_before_row_operations(const Slave_reporting_capability *const);
   virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
   virtual int do_exec_row(const Relay_log_info *const);
-#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
+#endif /* defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) */
 };
 
 /**
@@ -3798,7 +3801,7 @@ public:
     TYPE_CODE = DELETE_ROWS_EVENT
   };
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Delete_rows_log_event(THD*, TABLE*, ulong, 
 			MY_BITMAP const *cols, bool is_transactional);
 #endif
@@ -3806,7 +3809,7 @@ public:
   Delete_rows_log_event(const char *buf, uint event_len, 
 			const Format_description_log_event *description_event);
 #endif
-#if !defined(MYSQL_CLIENT) 
+#ifdef MYSQL_SERVER
   static bool binlog_row_logging_function(THD *thd, TABLE *table,
                                           bool is_transactional,
                                           MY_BITMAP *cols,
@@ -3827,7 +3830,7 @@ protected:
   void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
 #endif
 
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_before_row_operations(const Slave_reporting_capability *const);
   virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
   virtual int do_exec_row(const Relay_log_info *const);
@@ -3875,7 +3878,7 @@ protected:
 */
 class Incident_log_event : public Log_event {
 public:
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   Incident_log_event(THD *thd_arg, Incident incident)
     : Log_event(thd_arg, 0, FALSE), m_incident(incident)
   {
@@ -3896,7 +3899,7 @@ public:
   }
 #endif
 
-#ifndef MYSQL_CLIENT
+#ifdef MYSQL_SERVER
   void pack_info(Protocol*);
 #endif
 
@@ -3909,7 +3912,7 @@ public:
   virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
 #endif
 
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_apply_event(Relay_log_info const *rli);
 #endif
 
@@ -3977,6 +3980,9 @@ private:
 };
 #endif
 
+int append_query_string(CHARSET_INFO *csinfo,
+                        String const *from, String *to);
+
 /**
   @} (end of group Replication)
 */

=== modified file 'sql/log_event_old.cc'
--- a/sql/log_event_old.cc	2009-11-06 14:20:27 +0000
+++ b/sql/log_event_old.cc	2009-11-18 08:54:54 +0000
@@ -1,6 +1,16 @@
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
 #ifndef MYSQL_CLIENT
+#include "unireg.h"
+#endif
+#include "my_global.h" // REQUIRED by log_event.h > m_string.h > my_bitmap.h
+#include "log_event.h"
+#ifndef MYSQL_CLIENT
+#include "sql_cache.h"                       // QUERY_CACHE_FLAGS_SIZE
+#include "sql_base.h"                       // close_tables_for_reopen
+#include "key.h"                            // key_copy
+#include "lock.h"                           // mysql_unlock_tables
+#include "sql_parse.h"             // mysql_reset_thd_for_next_command
 #include "rpl_rli.h"
 #include "rpl_utility.h"
 #endif

=== modified file 'sql/mf_iocache.cc'
--- a/sql/mf_iocache.cc	2007-10-11 17:29:09 +0000
+++ b/sql/mf_iocache.cc	2009-11-18 08:54:54 +0000
@@ -32,7 +32,8 @@
   flush_io_cache().  
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "sql_class.h"                          // THD
 #ifdef HAVE_REPLICATION
 
 extern "C" {

=== modified file 'sql/my_decimal.cc'
--- a/sql/my_decimal.cc	2009-09-10 09:18:29 +0000
+++ b/sql/my_decimal.cc	2009-11-18 08:54:54 +0000
@@ -13,9 +13,12 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
 #include <time.h>
 
+#ifndef MYSQL_CLIENT
+#include "sql_class.h"                          // THD
+#endif
 
 #ifndef MYSQL_CLIENT
 /**

=== modified file 'sql/my_decimal.h'
--- a/sql/my_decimal.h	2009-11-02 11:21:39 +0000
+++ b/sql/my_decimal.h	2009-11-18 08:54:54 +0000
@@ -28,10 +28,17 @@
 #ifndef my_decimal_h
 #define my_decimal_h
 
+#if defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY)
+#include "sql_string.h"                         /* String */
+#endif
+
 C_MODE_START
 #include <decimal.h>
 C_MODE_END
 
+class String;
+typedef struct st_mysql_time MYSQL_TIME;
+
 #define DECIMAL_LONGLONG_DIGITS 22
 #define DECIMAL_LONG_DIGITS 10
 #define DECIMAL_LONG3_DIGITS 8
@@ -290,6 +297,7 @@ int my_decimal_ceiling(uint mask, const 
 
 
 #ifndef MYSQL_CLIENT
+class String;
 int my_decimal2string(uint mask, const my_decimal *d, uint fixed_prec,
 		      uint fixed_dec, char filler, String *str);
 #endif

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2009-11-06 14:20:27 +0000
+++ b/sql/mysqld.cc	2009-11-18 08:54:54 +0000
@@ -13,7 +13,40 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "my_global.h"
+#include <signal.h>
+#include "sql_parse.h"    // test_if_data_home_dir
+#include "sql_cache.h"    // query_cache, query_cache_*
+#include "sql_locale.h"   // MY_LOCALES, my_locales, my_locale_by_name
+#include "sql_show.h"     // free_status_vars, add_status_vars,
+                          // reset_status_vars
+#include "strfunc.h"      // find_set_from_flags
+#include "parse_file.h"   // File_parser_dummy_hook
+#include "sql_db.h"       // my_database_names_free,
+                          // my_database_names_init
+#include "sql_table.h"    // release_ddl_log, execute_ddl_log_recovery
+#include "sql_connect.h"  // free_max_user_conn, init_max_user_conn,
+                          // handle_one_connection
+#include "sql_time.h"     // known_date_time_formats,
+                          // get_date_time_format_str,
+                          // date_time_format_make
+#include "tztime.h"       // my_tz_free, my_tz_init, my_tz_SYSTEM
+#include "hostname.h"     // hostname_cache_free, hostname_cache_init
+#include "sql_acl.h"      // acl_free, grant_free, acl_init,
+                          // grant_init
+#include "sql_base.h"     // table_def_free, table_def_init,
+                          // cached_open_tables,
+                          // cached_table_definitions
+#include "sql_test.h"     // mysql_print_status
+#include "item_create.h"  // item_create_cleanup, item_create_init
+#include "sql_servers.h"  // servers_free, servers_init
+#include "init.h"         // unireg_init
+#include "derror.h"       // init_errmessage
+#include "derror.h"       // init_errmessage
+#include "des_key_file.h" // load_des_key_file
+#include "sql_manager.h"  // stop_handle_manager, start_handle_manager
 #include <m_ctype.h>
 #include <my_dir.h>
 #include <my_bit.h>

=== added file 'sql/mysqld.h'
--- a/sql/mysqld.h	1970-01-01 00:00:00 +0000
+++ b/sql/mysqld.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,327 @@
+#ifndef MYSQLD_INCLUDED
+#define MYSQLD_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "my_global.h" /* MYSQL_PLUGIN_IMPORT, FN_REFLEN, FN_EXTLEN */
+#include "sql_bitmap.h"                         /* Bitmap */
+#include "my_decimal.h"                         /* my_decimal */
+#include "mysql_com.h"                     /* SERVER_VERSION_LENGTH */
+#include "sql_list.h"                      /* I_List */
+
+class THD;
+class handlerton;
+class scheduler_functions;
+
+typedef struct st_mysql_const_lex_string LEX_CSTRING;
+typedef struct st_mysql_show_var SHOW_VAR;
+
+/*
+  This forward declaration is used from C files where the real
+  definition is included before.  Since C does not allow repeated
+  typedef declarations, even when identical, the definition may not be
+  repeated.
+*/
+#ifndef CHARSET_INFO_DEFINED
+#define CHARSET_INFO_DEFINED
+typedef struct charset_info_st CHARSET_INFO;
+#endif  /* CHARSET_INFO_DEFINED */
+
+#if MAX_INDEXES <= 64
+typedef Bitmap<64>  key_map;          /* Used for finding keys */
+#else
+typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */
+#endif
+
+	/* Bits from testflag */
+#define TEST_PRINT_CACHED_TABLES 1
+#define TEST_NO_KEY_GROUP	 2
+#define TEST_MIT_THREAD		4
+#define TEST_BLOCKING		8
+#define TEST_KEEP_TMP_TABLES	16
+#define TEST_READCHECK		64	/**< Force use of readcheck */
+#define TEST_NO_EXTRA		128
+#define TEST_CORE_ON_SIGNAL	256	/**< Give core if signal */
+#define TEST_NO_STACKTRACE	512
+#define TEST_SIGINT		1024	/**< Allow sigint on threads */
+#define TEST_SYNCHRONIZATION    2048    /**< get server to do sleep in
+                                           some places */
+/* Function prototypes */
+void kill_mysql(void);
+void close_connection(THD *thd, uint errcode, bool lock);
+void handle_connection_in_main_thread(THD *thd);
+void create_thread_to_handle_connection(THD *thd);
+void unlink_thd(THD *thd);
+bool one_thread_per_connection_end(THD *thd, bool put_in_cache);
+void flush_thread_cache();
+void refresh_status(THD *thd);
+
+extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *system_charset_info;
+extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *files_charset_info ;
+extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *national_charset_info;
+extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *table_alias_charset;
+
+/**
+  Character set of the buildin error messages loaded from errmsg.sys.
+*/
+extern CHARSET_INFO *error_message_charset_info;
+
+extern CHARSET_INFO *character_set_filesystem;
+
+extern MY_BITMAP temp_pool;
+extern bool opt_large_files, server_id_supplied;
+extern bool opt_update_log, opt_bin_log, opt_error_log;
+extern my_bool opt_log, opt_slow_log;
+extern my_bool opt_backup_history_log;
+extern my_bool opt_backup_progress_log;
+extern ulong log_output_options;
+extern ulong log_backup_output_options;
+extern my_bool opt_log_queries_not_using_indexes;
+extern bool opt_disable_networking, opt_skip_show_db;
+extern bool opt_ignore_builtin_innodb;
+extern my_bool opt_character_set_client_handshake;
+extern bool volatile abort_loop;
+extern bool in_bootstrap;
+extern uint volatile thread_count, thread_running, global_read_lock;
+extern uint connection_count;
+extern my_bool opt_sql_bin_update, opt_safe_user_create, opt_no_mix_types;
+extern my_bool opt_safe_show_db, opt_local_infile, opt_myisam_use_mmap;
+extern my_bool opt_slave_compressed_protocol, use_temp_pool;
+extern ulong slave_exec_mode_options;
+extern my_bool opt_readonly, lower_case_file_system;
+extern my_bool opt_enable_named_pipe, opt_sync_frm, opt_allow_suspicious_udfs;
+extern my_bool opt_secure_auth;
+extern char* opt_secure_file_priv;
+extern char* opt_secure_backup_file_priv;
+extern size_t opt_secure_backup_file_priv_len;
+extern my_bool opt_log_slow_admin_statements, opt_log_slow_slave_statements;
+extern my_bool sp_automatic_privileges, opt_noacl;
+extern my_bool opt_old_style_user_limits, trust_function_creators;
+extern uint opt_crash_binlog_innodb;
+extern char *shared_memory_base_name, *mysqld_unix_port;
+extern my_bool opt_enable_shared_memory;
+extern char *default_tz_name;
+extern bool opt_endinfo, using_udf_functions;
+extern my_bool locked_in_memory;
+extern bool opt_using_transactions;
+extern ulong current_pid;
+extern ulong expire_logs_days;
+extern my_bool relay_log_recovery;
+extern uint sync_binlog_period, sync_relaylog_period, 
+            sync_relayloginfo_period, sync_masterinfo_period;
+extern ulong opt_tc_log_size, tc_log_max_pages_used, tc_log_page_size;
+extern ulong tc_log_page_waits;
+extern my_bool relay_log_purge, opt_innodb_safe_binlog, opt_innodb;
+extern my_bool relay_log_recovery;
+extern uint test_flags,select_errors,ha_open_options;
+extern uint protocol_version, mysqld_port, dropping_tables;
+extern uint delay_key_write_options;
+extern char *opt_logname, *opt_slow_logname;
+extern char *opt_backup_history_logname, *opt_backup_progress_logname,
+            *opt_backup_settings_name;
+extern const char *log_output_str;
+extern const char *log_backup_output_str;
+extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN];
+extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
+extern char default_logfile_name[FN_REFLEN];
+extern char log_error_file[FN_REFLEN], *opt_tc_log_file;
+extern const double log_10[309];
+extern ulonglong keybuff_size;
+extern ulonglong thd_startup_options;
+extern ulong thread_id;
+extern ulong binlog_cache_use, binlog_cache_disk_use;
+extern ulong aborted_threads,aborted_connects;
+extern ulong delayed_insert_timeout;
+extern ulong delayed_insert_limit, delayed_queue_size;
+extern ulong delayed_insert_threads, delayed_insert_writes;
+extern ulong delayed_rows_in_use,delayed_insert_errors;
+extern ulong slave_open_temp_tables;
+extern ulong query_cache_size, query_cache_min_res_unit;
+extern ulong slow_launch_threads, slow_launch_time;
+extern ulong table_cache_size, table_def_size;
+extern MYSQL_PLUGIN_IMPORT ulong max_connections;
+extern ulong max_connect_errors, connect_timeout;
+extern my_bool slave_allow_batching;
+extern my_bool allow_slave_start;
+extern LEX_CSTRING reason_slave_blocked;
+extern ulong slave_net_timeout, slave_trans_retries;
+extern uint max_user_connections;
+extern ulong what_to_log,flush_time;
+extern ulong query_buff_size;
+extern ulong max_prepared_stmt_count, prepared_stmt_count;
+extern ulong binlog_cache_size, open_files_limit;
+extern ulonglong max_binlog_cache_size;
+extern ulong max_binlog_size, max_relay_log_size;
+extern ulong opt_binlog_rows_event_max_size;
+extern ulong rpl_recovery_rank, thread_cache_size, thread_pool_size;
+extern ulong back_log;
+extern char language[FN_REFLEN];
+extern ulong server_id, concurrency;
+extern time_t server_start_time, flush_status_time;
+extern char *opt_mysql_tmpdir, mysql_charsets_dir[];
+extern int mysql_unpacked_real_data_home_len;
+extern MY_TMPDIR mysql_tmpdir_list;
+extern const char *first_keyword, *delayed_user, *binary_keyword;
+extern MYSQL_PLUGIN_IMPORT const char  *my_localhost;
+extern MYSQL_PLUGIN_IMPORT const char **errmesg;			/* Error messages */
+extern const char *myisam_recover_options_str;
+extern const char *in_left_expr_name, *in_additional_cond, *in_having_cond;
+extern SHOW_VAR status_vars[];
+extern struct system_variables max_system_variables;
+extern struct system_status_var global_status_var;
+extern struct rand_struct sql_rand;
+extern const char *opt_date_time_formats[];
+extern handlerton *partition_hton;
+extern handlerton *myisam_hton;
+extern handlerton *heap_hton;
+extern const char *load_default_groups[];
+extern struct my_option my_long_options[];
+extern int mysqld_server_started;
+extern int orig_argc;
+extern char **orig_argv;
+extern pthread_attr_t connection_attrib;
+extern FILE *bootstrap_file;
+extern int bootstrap_error;
+extern FILE *stderror_file;
+extern I_List<THD> threads;
+extern char err_shared_dir[];
+extern scheduler_functions thread_scheduler;
+extern TYPELIB thread_handling_typelib;
+extern my_decimal decimal_zero;
+
+extern pthread_key(MEM_ROOT**,THR_MALLOC);
+
+bool fn_format_relative_to_data_home(char * to, const char *name,
+				     const char *dir, const char *extension);
+
+
+#ifndef __WIN__
+extern pthread_t signal_thread;
+#endif
+
+#ifdef HAVE_OPENSSL
+extern struct st_VioSSLFd * ssl_acceptor_fd;
+#endif /* HAVE_OPENSSL */
+
+/*
+  The following variables were under INNODB_COMPABILITY_HOOKS
+ */
+extern my_bool opt_large_pages;
+extern uint opt_large_page_size;
+extern char lc_messages_dir[FN_REFLEN];
+extern MYSQL_PLUGIN_IMPORT char reg_ext[FN_EXTLEN];
+extern MYSQL_PLUGIN_IMPORT uint reg_ext_length;
+extern MYSQL_PLUGIN_IMPORT uint lower_case_table_names;
+extern MYSQL_PLUGIN_IMPORT bool mysqld_embedded;
+extern ulong specialflag;
+extern uint mysql_data_home_len;
+extern uint mysql_real_data_home_len;
+extern MYSQL_PLUGIN_IMPORT char  *mysql_data_home;
+extern char server_version[SERVER_VERSION_LENGTH];
+extern MYSQL_PLUGIN_IMPORT char mysql_real_data_home[];
+extern char mysql_unpacked_real_data_home[];
+extern MYSQL_PLUGIN_IMPORT struct system_variables global_system_variables;
+extern char default_logfile_name[FN_REFLEN];
+extern char err_shared_dir[];
+
+#define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list))
+
+extern MYSQL_PLUGIN_IMPORT const key_map key_map_empty;
+extern MYSQL_PLUGIN_IMPORT key_map key_map_full;          /* Should be threaded as const */
+
+/*
+  Server mutex locks and condition variables.
+ */
+extern pthread_mutex_t LOCK_mysql_create_db, LOCK_open, LOCK_lock_db,
+       LOCK_mapped_file,LOCK_user_locks, LOCK_status,
+       LOCK_error_log, LOCK_delayed_insert, LOCK_uuid_generator,
+       LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone,
+       LOCK_slave_list, LOCK_active_mi, LOCK_manager, LOCK_global_read_lock,
+       LOCK_global_system_variables, LOCK_user_conn,
+       LOCK_prepared_stmt_count, LOCK_error_messages, LOCK_connection_count;
+extern MYSQL_PLUGIN_IMPORT pthread_mutex_t LOCK_thread_count;
+#ifdef HAVE_OPENSSL
+extern pthread_mutex_t LOCK_des_key_file;
+#endif
+extern pthread_mutex_t LOCK_server_started;
+extern pthread_cond_t COND_server_started;
+extern rw_lock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave;
+extern rw_lock_t LOCK_system_variables_hash;
+extern pthread_cond_t COND_refresh, COND_thread_count, COND_manager;
+extern pthread_cond_t COND_global_read_lock;
+
+extern MYSQL_PLUGIN_IMPORT pthread_key(THD*, THR_THD);
+
+/**
+  Query type constants.
+
+  QT_ORDINARY -- ordinary SQL query.
+  QT_IS -- SQL query to be shown in INFORMATION_SCHEMA (in utf8 and without
+  character set introducers).
+*/
+enum enum_query_type
+{
+  QT_ORDINARY,
+  QT_IS
+};
+
+/* query_id */
+typedef ulonglong query_id_t;
+extern query_id_t global_query_id;
+
+void unireg_end(void) __attribute__((noreturn));
+
+/* increment query_id and return it.  */
+inline query_id_t next_query_id() { return global_query_id++; }
+
+/*
+  TODO: Replace this with an inline function.
+ */
+#ifndef EMBEDDED_LIBRARY
+extern "C" void unireg_abort(int exit_code) __attribute__((noreturn));
+#else
+extern "C" void unireg_clear(int exit_code);
+#define unireg_abort(exit_code) do { unireg_clear(exit_code); DBUG_RETURN(exit_code); } while(0)
+#endif
+
+inline void table_case_convert(char * name, uint length)
+{
+  if (lower_case_table_names)
+    files_charset_info->cset->casedn(files_charset_info,
+                                     name, length, name, length);
+}
+
+inline ulong sql_rnd_with_mutex()
+{
+  pthread_mutex_lock(&LOCK_thread_count);
+  ulong tmp=(ulong) (my_rnd(&sql_rand) * 0xffffffff); /* make all bits random */
+  pthread_mutex_unlock(&LOCK_thread_count);
+  return tmp;
+}
+
+#if defined(MYSQL_DYNAMIC_PLUGIN) && defined(_WIN32)
+extern "C" THD *_current_thd_noinline();
+#define _current_thd() _current_thd_noinline()
+#else
+extern pthread_key(THD*, THR_THD);
+inline THD *_current_thd(void)
+{
+  return my_pthread_getspecific_ptr(THD*,THR_THD);
+}
+#endif
+#define current_thd _current_thd()
+
+#endif /* MYSQLD_INCLUDED */

=== modified file 'sql/net_serv.cc'
--- a/sql/net_serv.cc	2009-11-02 11:10:04 +0000
+++ b/sql/net_serv.cc	2009-11-18 08:54:54 +0000
@@ -39,7 +39,6 @@
  */
 #include <my_global.h>
 #include <mysql.h>
-#include <mysql_embed.h>
 #include <mysql_com.h>
 #include <mysqld_error.h>
 #include <my_sys.h>
@@ -86,7 +85,7 @@ void sql_print_error(const char *format,
 #ifdef MYSQL_SERVER
 /*
   The following variables/functions should really not be declared
-  extern, but as it's hard to include mysql_priv.h here, we have to
+  extern, but as it's hard to include sql_priv.h here, we have to
   live with this for a while.
 */
 extern uint test_flags;

=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc	2009-11-10 08:34:26 +0000
+++ b/sql/opt_range.cc	2009-11-18 08:54:54 +0000
@@ -65,7 +65,13 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "key.h"        // is_key_used, key_copy, key_cmp, key_restore
+#include "sql_parse.h"                          // check_stack_overrun
+#include "sql_partition.h"    // get_part_id_func, PARTITION_ITERATOR,
+                              // struct partition_info
+#include "sql_base.h"         // free_io_cache
+#include "records.h"          // init_read_record, end_read_record
 #include <m_ctype.h>
 #include "sql_select.h"
 

=== modified file 'sql/opt_range.h'
--- a/sql/opt_range.h	2009-09-28 07:21:25 +0000
+++ b/sql/opt_range.h	2009-11-18 08:54:54 +0000
@@ -23,6 +23,19 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
+#include "thr_malloc.h"                         /* sql_memdup */
+#include "records.h"                            /* READ_RECORD */
+#include "queues.h"                             /* QUEUE */
+/*
+  It is necessary to include set_var.h instead of item.h because there
+  are dependencies on include order for set_var.h and item.h. This
+  will be resolved later.
+*/
+#include "set_var.h"                            /* Item */
+
+class JOIN;
+class Item_sum;
+
 typedef struct st_key_part {
   uint16           key,part;
   /* See KEY_PART_INFO for meaning of the next two: */
@@ -742,10 +755,15 @@ QUICK_RANGE_SELECT *get_quick_select_for
                                              struct st_table_ref *ref,
                                              ha_rows records);
 uint get_index_for_order(TABLE *table, ORDER *order, ha_rows limit);
+SQL_SELECT *make_select(TABLE *head, table_map const_tables,
+			table_map read_tables, COND *conds,
+                        bool allow_null_cond,  int *error);
 
 #ifdef WITH_PARTITION_STORAGE_ENGINE
 bool prune_partitions(THD *thd, TABLE *table, Item *pprune_cond);
 void store_key_image_to_rec(Field *field, uchar *ptr, uint len);
 #endif
 
+extern String null_string;
+
 #endif

=== modified file 'sql/opt_sum.cc'
--- a/sql/opt_sum.cc	2009-10-28 10:07:30 +0000
+++ b/sql/opt_sum.cc	2009-11-18 08:54:54 +0000
@@ -47,7 +47,8 @@
   (assuming a index for column d of table t2 is defined)
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "key.h"                                // key_cmp_if_same
 #include "sql_select.h"
 
 static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref, Field* field,

=== modified file 'sql/parse_file.cc'
--- a/sql/parse_file.cc	2009-06-19 08:24:43 +0000
+++ b/sql/parse_file.cc	2009-11-18 08:54:54 +0000
@@ -20,7 +20,10 @@
   Text .frm files management routines
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "parse_file.h"
+#include "unireg.h"                            // CREATE_MODE
+#include "sql_table.h"                        // build_table_filename
 #include <errno.h>
 #include <m_ctype.h>
 #include <my_sys.h>

=== modified file 'sql/parse_file.h'
--- a/sql/parse_file.h	2009-05-15 12:57:51 +0000
+++ b/sql/parse_file.h	2009-11-18 08:54:54 +0000
@@ -17,6 +17,15 @@
 #ifndef _PARSE_FILE_H_
 #define _PARSE_FILE_H_
 
+#include "my_global.h"                          // uchar
+#include "sql_string.h"                         // LEX_STRING
+#include "sql_list.h"                           // Sql_alloc
+
+class THD;
+
+class THD;
+typedef struct st_mem_root MEM_ROOT;
+
 #define PARSE_FILE_TIMESTAMPLENGTH 19
 
 enum file_opt_type {

=== modified file 'sql/partition_element.h'
--- a/sql/partition_element.h	2009-10-28 17:32:48 +0000
+++ b/sql/partition_element.h	2009-11-18 08:54:54 +0000
@@ -16,6 +16,9 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
+#include "my_base.h"                            /* ha_rows */
+#include "handler.h"                            /* UNDEF_NODEGROUP */
+
 /**
  * An enum and a struct to handle partitioning and subpartitioning.
  */

=== modified file 'sql/partition_info.cc'
--- a/sql/partition_info.cc	2009-11-10 09:32:29 +0000
+++ b/sql/partition_info.cc	2009-11-18 08:54:54 +0000
@@ -19,7 +19,11 @@
 #pragma implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "partition_info.h"
+#include "sql_parse.h"                        // test_if_data_home_dir
+#include "sql_acl.h"                          // *_ACL
 
 #ifdef WITH_PARTITION_STORAGE_ENGINE
 #include "ha_partition.h"

=== modified file 'sql/partition_info.h'
--- a/sql/partition_info.h	2009-10-28 17:22:36 +0000
+++ b/sql/partition_info.h	2009-11-18 08:54:54 +0000
@@ -21,6 +21,7 @@
 #endif
 
 #include "partition_element.h"
+#include "sql_partition.h"                      /* LIST_PART_ENTRY */
 
 class partition_info;
 

=== modified file 'sql/password.c'
--- a/sql/password.c	2009-06-01 12:00:38 +0000
+++ b/sql/password.c	2009-11-18 08:54:54 +0000
@@ -58,6 +58,7 @@
 
 *****************************************************************************/
 
+#include <password.h>
 #include <my_global.h>
 #include <my_sys.h>
 #include <m_string.h>

=== modified file 'sql/procedure.cc'
--- a/sql/procedure.cc	2007-10-11 18:37:45 +0000
+++ b/sql/procedure.cc	2009-11-18 08:54:54 +0000
@@ -20,7 +20,7 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
 #include "procedure.h"
 #include "sql_analyse.h"			// Includes procedure
 #ifdef USE_PROC_RANGE

=== modified file 'sql/procedure.h'
--- a/sql/procedure.h	2009-10-28 07:55:44 +0000
+++ b/sql/procedure.h	2009-11-18 08:54:54 +0000
@@ -23,6 +23,14 @@
 #pragma interface				/* gcc class implementation */
 #endif
 
+/*
+  It is necessary to include set_var.h instead of item.h because there
+  are dependencies on include order for set_var.h and item.h. This
+  will be resolved later.
+*/
+#include "set_var.h"                            /* Item */
+#include "sql_class.h"                          /* select_result */
+
 #define PROC_NO_SORT 1				/**< Bits in flags */
 #define PROC_GROUP   2				/**< proc must have group */
 

=== modified file 'sql/protocol.cc'
--- a/sql/protocol.cc	2009-10-23 11:22:21 +0000
+++ b/sql/protocol.cc	2009-11-18 08:54:54 +0000
@@ -24,7 +24,10 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "protocol.h"
+#include "sql_class.h"                          // THD
 #include <stdarg.h>
 
 static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024;

=== modified file 'sql/protocol.h'
--- a/sql/protocol.h	2009-10-28 07:55:44 +0000
+++ b/sql/protocol.h	2009-11-18 08:54:54 +0000
@@ -21,8 +21,10 @@
 #endif
 
 #include "sql_error.h"
+#include "my_decimal.h"                         /* my_decimal */
 
 class i_string;
+class Field;
 class THD;
 class Item_param;
 typedef struct st_mysql_field MYSQL_FIELD;

=== modified file 'sql/records.cc'
--- a/sql/records.cc	2009-11-06 16:13:33 +0000
+++ b/sql/records.cc	2009-11-18 08:54:54 +0000
@@ -25,7 +25,11 @@
 */
 
 #include "records.h"
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "records.h"
+#include "filesort.h"            // filesort_free_buffers
+#include "opt_range.h"                          // SQL_SELECT
+#include "sql_class.h"                          // THD
 
 
 static int rr_quick(READ_RECORD *info);

=== modified file 'sql/repl_failsafe.cc'
--- a/sql/repl_failsafe.cc	2009-10-23 11:22:21 +0000
+++ b/sql/repl_failsafe.cc	2009-11-18 08:54:54 +0000
@@ -23,15 +23,18 @@
   functions like register_slave()) are working.
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "sql_parse.h"                          // check_access
 #ifdef HAVE_REPLICATION
 
 #include "repl_failsafe.h"
+#include "sql_acl.h"                            // REPL_SLAVE_ACL
 #include "sql_repl.h"
 #include "slave.h"
 #include "rpl_mi.h"
 #include "rpl_filter.h"
 #include "log_event.h"
+#include "sql_db.h"                             // mysql_create_db
 #include <mysql.h>
 
 #define SLAVE_LIST_CHUNK 128

=== modified file 'sql/replication.h'
--- a/sql/replication.h	2009-11-02 20:05:42 +0000
+++ b/sql/replication.h	2009-11-18 08:54:54 +0000
@@ -16,6 +16,8 @@
 #ifndef REPLICATION_H
 #define REPLICATION_H
 
+#include <mysql.h>
+
 typedef struct st_mysql MYSQL;
 
 #ifdef __cplusplus

=== modified file 'sql/rpl_filter.cc'
--- a/sql/rpl_filter.cc	2009-10-14 16:37:38 +0000
+++ b/sql/rpl_filter.cc	2009-11-18 08:54:54 +0000
@@ -13,8 +13,11 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"                      // REQUIRED by other includes
 #include "rpl_filter.h"
+#include "hash.h"                               // my_hash_free
+#include "table.h"                              // TABLE_LIST
 
 #define TABLE_RULE_HASH_SIZE   16
 #define TABLE_RULE_ARR_SIZE   16

=== modified file 'sql/rpl_filter.h'
--- a/sql/rpl_filter.h	2007-05-10 09:59:39 +0000
+++ b/sql/rpl_filter.h	2009-11-18 08:54:54 +0000
@@ -17,6 +17,12 @@
 #define RPL_FILTER_H
 
 #include "mysql.h"
+#include "sql_list.h"                           /* I_List */
+#include "hash.h"                               /* HASH */
+
+class String;
+class TABLE_LIST;
+typedef struct st_dynamic_array DYNAMIC_ARRAY;
 
 typedef struct st_table_rule_ent
 {

=== modified file 'sql/rpl_handler.cc'
--- a/sql/rpl_handler.cc	2009-10-28 08:42:18 +0000
+++ b/sql/rpl_handler.cc	2009-11-18 08:54:54 +0000
@@ -13,7 +13,8 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 
 #include "rpl_mi.h"
 #include "sql_repl.h"

=== modified file 'sql/rpl_handler.h'
--- a/sql/rpl_handler.h	2009-09-26 04:49:49 +0000
+++ b/sql/rpl_handler.h	2009-11-18 08:54:54 +0000
@@ -16,7 +16,7 @@
 #ifndef RPL_HANDLER_H
 #define RPL_HANDLER_H
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
 #include "rpl_mi.h"
 #include "rpl_rli.h"
 #include "sql_plugin.h"

=== modified file 'sql/rpl_injector.cc'
--- a/sql/rpl_injector.cc	2008-02-19 11:43:01 +0000
+++ b/sql/rpl_injector.cc	2009-11-18 08:54:54 +0000
@@ -13,8 +13,12 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
-#include "mysql_priv.h" 
+#include "sql_priv.h" 
+#include "unireg.h"                             // REQUIRED by later includes
 #include "rpl_injector.h"
+#include "sql_parse.h"                          // begin_trans, end_trans, COMMIT
+#include "sql_base.h"                           // close_thread_tables
+#include "log_event.h"                          // Incident_log_event
 
 /*
   injector::transaction - member definitions

=== modified file 'sql/rpl_injector.h'
--- a/sql/rpl_injector.h	2009-10-14 11:14:58 +0000
+++ b/sql/rpl_injector.h	2009-11-18 08:54:54 +0000
@@ -21,6 +21,7 @@
 #include <my_bitmap.h>
 
 #include "rpl_constants.h"
+#include "table.h"                              /* TABLE */
 
 /* Forward declarations */
 class handler;

=== modified file 'sql/rpl_mi.cc'
--- a/sql/rpl_mi.cc	2009-10-01 17:22:44 +0000
+++ b/sql/rpl_mi.cc	2009-11-18 08:54:54 +0000
@@ -14,10 +14,11 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 #include <my_global.h> // For HAVE_REPLICATION
-#include "mysql_priv.h"
+#include "sql_priv.h"
 #include <my_dir.h>
-
+#include "unireg.h"                             // REQUIRED by other includes
 #include "rpl_mi.h"
+#include "slave.h"                              // SLAVE_MAX_HEARTBEAT_PERIOD
 
 #ifdef HAVE_REPLICATION
 

=== modified file 'sql/rpl_mi.h'
--- a/sql/rpl_mi.h	2009-10-01 17:22:44 +0000
+++ b/sql/rpl_mi.h	2009-11-18 08:54:54 +0000
@@ -22,9 +22,9 @@
 #include "rpl_reporting.h"
 #include "my_sys.h"
 
+typedef struct st_mysql MYSQL;
 
 /*****************************************************************************
-
   Replication IO Thread
 
   Master_info contains:

=== modified file 'sql/rpl_record.cc'
--- a/sql/rpl_record.cc	2009-09-29 14:18:44 +0000
+++ b/sql/rpl_record.cc	2009-11-18 08:54:54 +0000
@@ -13,7 +13,8 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #include "rpl_rli.h"
 #include "rpl_record.h"
 #include "slave.h"                  // Need to pull in slave_print_msg

=== modified file 'sql/rpl_record.h'
--- a/sql/rpl_record.h	2009-09-29 14:18:44 +0000
+++ b/sql/rpl_record.h	2009-11-18 08:54:54 +0000
@@ -17,6 +17,11 @@
 #define RPL_RECORD_H
 
 #include <rpl_reporting.h>
+#include "my_global.h"                          /* uchar */
+
+class Relay_log_info;
+struct TABLE;
+typedef struct st_bitmap MY_BITMAP;
 
 #if !defined(MYSQL_CLIENT)
 size_t pack_row(TABLE* table, MY_BITMAP const* cols,

=== modified file 'sql/rpl_record_old.cc'
--- a/sql/rpl_record_old.cc	2007-08-16 05:37:50 +0000
+++ b/sql/rpl_record_old.cc	2009-11-18 08:54:54 +0000
@@ -1,7 +1,9 @@
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"                      // REQUIRED by other includes
 #include "rpl_rli.h"
 #include "rpl_record_old.h"
+#include "log_event.h"                          // Log_event_type
 
 size_t
 pack_row_old(TABLE *table, MY_BITMAP const* cols,

=== modified file 'sql/rpl_record_old.h'
--- a/sql/rpl_record_old.h	2007-08-16 05:37:50 +0000
+++ b/sql/rpl_record_old.h	2009-11-18 08:54:54 +0000
@@ -16,6 +16,8 @@
 #ifndef RPL_RECORD_OLD_H
 #define RPL_RECORD_OLD_H
 
+#include "log_event.h"                          /* Log_event_type */
+
 #ifndef MYSQL_CLIENT
 size_t pack_row_old(TABLE *table, MY_BITMAP const* cols,
                     uchar *row_data, const uchar *record);

=== modified file 'sql/rpl_reporting.cc'
--- a/sql/rpl_reporting.cc	2009-06-16 15:04:30 +0000
+++ b/sql/rpl_reporting.cc	2009-11-18 08:54:54 +0000
@@ -1,6 +1,8 @@
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
 #include "rpl_reporting.h"
+#include "log.h" // sql_print_error, sql_print_warning,
+                 // sql_print_information
 
 void
 Slave_reporting_capability::report(loglevel level, int err_code,

=== modified file 'sql/rpl_reporting.h'
--- a/sql/rpl_reporting.h	2009-06-16 15:04:30 +0000
+++ b/sql/rpl_reporting.h	2009-11-18 08:54:54 +0000
@@ -1,6 +1,23 @@
 #ifndef RPL_REPORTING_H
 #define RPL_REPORTING_H
 
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "my_sys.h"                             /* loglevel */
+
 /**
    Maximum size of an error message from a slave thread.
  */

=== modified file 'sql/rpl_rli.cc'
--- a/sql/rpl_rli.cc	2009-10-22 22:30:28 +0000
+++ b/sql/rpl_rli.cc	2009-11-18 08:54:54 +0000
@@ -13,13 +13,18 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
-
+#include "sql_priv.h"
+#include "unireg.h"                             // HAVE_*
 #include "rpl_mi.h"
 #include "rpl_rli.h"
+#include "sql_base.h"                        // close_thread_tables
 #include <my_dir.h>    // For MY_STAT
 #include "sql_repl.h"  // For check_binlog_magic
+#include "log_event.h" // Format_description_log_event, Log_event,
+                       // FORMAT_DESCRIPTION_LOG_EVENT, ROTATE_EVENT,
+                       // PREFIX_SQL_LOAD
 #include "rpl_utility.h"
+#include "sql_parse.h"                          // end_trans, ROLLBACK
 
 static int count_relay_log_space(Relay_log_info* rli);
 

=== modified file 'sql/rpl_rli.h'
--- a/sql/rpl_rli.h	2009-10-09 13:26:37 +0000
+++ b/sql/rpl_rli.h	2009-11-18 08:54:54 +0000
@@ -19,6 +19,8 @@
 #include "rpl_tblmap.h"
 #include "rpl_reporting.h"
 #include "rpl_utility.h"
+#include "log.h"                         /* LOG_INFO, MYSQL_BIN_LOG */
+#include "sql_class.h"                   /* THD */
 
 struct RPL_TABLE_LIST;
 class Master_info;

=== modified file 'sql/rpl_tblmap.cc'
--- a/sql/rpl_tblmap.cc	2009-10-14 16:37:38 +0000
+++ b/sql/rpl_tblmap.cc	2009-11-18 08:54:54 +0000
@@ -13,11 +13,15 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "my_global.h"                          // HAVE_REPLICATION
 
 #ifdef HAVE_REPLICATION
 
 #include "rpl_tblmap.h"
+#ifndef MYSQL_CLIENT
+#include "table.h"
+#endif
 
 #ifdef MYSQL_CLIENT
 #define MAYBE_TABLE_NAME(T) ("")

=== modified file 'sql/rpl_tblmap.h'
--- a/sql/rpl_tblmap.h	2009-10-14 16:37:38 +0000
+++ b/sql/rpl_tblmap.h	2009-11-18 08:54:54 +0000
@@ -52,6 +52,8 @@ void free_table_map_log_event(TABLE *tab
   A dedicated MEM_ROOT needs to be used, see below.
 */
 
+#include "hash.h"                               /* HASH */
+
 class table_mapping {
 
 private:

=== modified file 'sql/rpl_utility.cc'
--- a/sql/rpl_utility.cc	2008-06-30 20:11:18 +0000
+++ b/sql/rpl_utility.cc	2009-11-18 08:54:54 +0000
@@ -13,6 +13,7 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
+#include "unireg.h"                      // REQUIRED by later includes
 #include "rpl_utility.h"
 #include "rpl_rli.h"
 

=== modified file 'sql/rpl_utility.h'
--- a/sql/rpl_utility.h	2009-03-25 10:53:56 +0000
+++ b/sql/rpl_utility.h	2009-11-18 08:54:54 +0000
@@ -20,7 +20,11 @@
 #error "Don't include this C++ header file from a non-C++ file!"
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "m_string.h"                           /* bzero, memcpy */
+#ifdef MYSQL_SERVER
+#include "table.h"                              /* TABLE_LIST */
+#endif
 
 class Relay_log_info;
 

=== modified file 'sql/scheduler.cc'
--- a/sql/scheduler.cc	2007-02-23 11:13:55 +0000
+++ b/sql/scheduler.cc	2009-11-18 08:54:54 +0000
@@ -21,7 +21,10 @@
 #pragma implementation
 #endif
 
-#include <mysql_priv.h>
+#include <sql_priv.h>
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "scheduler.h"
+#include "sql_connect.h"         // init_new_connection_handler_thread
 
 /*
   'Dummy' functions to be used when we don't need any handling for a scheduler

=== modified file 'sql/set_var.cc'
--- a/sql/set_var.cc	2009-11-02 11:10:04 +0000
+++ b/sql/set_var.cc	2009-11-18 08:54:54 +0000
@@ -26,7 +26,7 @@
     one for the variable type.
   - Define it in the 'variable definition list' in this file.
   - If the variable is thread specific, add it to 'system_variables' struct.
-    If not, add it to mysqld.cc and an declaration in 'mysql_priv.h'
+    If not, add it to mysqld.cc and an declaration in 'sql_priv.h'
   - If the variable should be changed from the command line, add a definition
     of it in the my_option structure list in mysqld.cc
   - Don't forget to initialize new fields in global_system_variables and
@@ -51,7 +51,27 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "set_var.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "mysqld.h"                             // lc_messages_dir
+#include "lock.h"                               // lock_global_read_lock,
+                                                // make_global_read_lock_block_commit,
+                                                // unlock_global_read_lock
+#include "sql_base.h"                           // close_thread_tables
+#include "sql_locale.h"                         // my_locale_by_number,
+                                                // my_locale_by_name
+#include "strfunc.h"      // find_set_from_flags, find_set
+#include "sql_view.h"   // updatable_views_with_limit_typelib
+#include "sql_parse.h"  // check_global_access
+#include "sql_table.h"  // reassign_keycache_tables
+#include "sql_time.h"   // date_time_format_copy,
+                        // date_time_format_make
+#include "derror.h"
+#include "tztime.h"     // my_tz_find, my_tz_SYSTEM, struct Time_zone
+#include "sql_acl.h"    // SUPER_ACL
+#include "sql_select.h" // free_underlaid_joins
+#include "sql_show.h"   // make_default_log_name
 #include <mysql.h>
 #include "slave.h"
 #include "rpl_mi.h"
@@ -61,6 +81,8 @@
 #include <my_dir.h>
 
 #include "events.h"
+#include "sql_locale.h"           // my_locale_by_number,
+                                  // my_locale_by_name, my_locale_st
 
 /* WITH_NDBCLUSTER_STORAGE_ENGINE */
 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE

=== modified file 'sql/set_var.h'
--- a/sql/set_var.h	2009-10-29 11:19:36 +0000
+++ b/sql/set_var.h	2009-11-18 08:54:54 +0000
@@ -22,6 +22,9 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
+#include "log.h"                           /* binlog_format_typelib */
+#include "sql_plugin.h"                    /* SHOW_HA_ROWS, SHOW_MY_BOOL */
+
 /****************************************************************************
   Variables that are changable runtime are declared using the
   following classes
@@ -32,6 +35,15 @@ class set_var;
 class sys_var_pluginvar; /* opaque */
 typedef struct system_variables SV;
 typedef struct my_locale_st MY_LOCALE;
+class Item_func_set_user_var;
+
+enum enum_var_type
+{
+  OPT_DEFAULT= 0, OPT_SESSION, OPT_GLOBAL
+};
+
+// This include needs to be here since item.h requires enum_var_type :-P
+#include "item.h"                          /* Item */
 
 extern TYPELIB bool_typelib, delay_key_write_typelib, sql_mode_typelib,
   optimizer_switch_typelib, slave_exec_mode_typelib;
@@ -1521,4 +1533,19 @@ bool process_key_caches(process_key_cach
 void delete_elements(I_List<NAMED_LIST> *list,
 		     void (*free_element)(const char*, uchar*));
 
+extern TYPELIB log_output_typelib;
+
+/*
+  This variable is defined in mysqld.cc, but the NAMED_LIST type is
+  defined here, so we place the variable here.
+ */
+extern I_List<NAMED_LIST> key_caches;
+
+extern SHOW_COMP_OPTION have_profiling;
+extern SHOW_COMP_OPTION have_ssl, have_symlink, have_dlopen;
+extern SHOW_COMP_OPTION have_query_cache;
+extern SHOW_COMP_OPTION have_geometry, have_rtree_keys;
+extern SHOW_COMP_OPTION have_crypt;
+extern SHOW_COMP_OPTION have_compress;
+
 #endif /* SET_VAR_INCLUDED */

=== modified file 'sql/slave.cc'
--- a/sql/slave.cc	2009-11-10 07:31:33 +0000
+++ b/sql/slave.cc	2009-11-18 08:54:54 +0000
@@ -24,11 +24,11 @@
   replication slave.
 */
 
-#include "mysql_priv.h"
-
-#include <mysql.h>
-#include <myisam.h>
+#include "sql_priv.h"
+#include "my_global.h"
 #include "slave.h"
+#include "sql_parse.h"                         // execute_init_command
+#include "sql_table.h"                         // mysql_rm_table
 #include "rpl_mi.h"
 #include "rpl_rli.h"
 #include "sql_repl.h"
@@ -41,6 +41,15 @@
 #include <mysqld_error.h>
 #include <mysys_err.h>
 #include "rpl_handler.h"
+#include <signal.h>
+#include <mysql.h>
+#include <myisam.h>
+
+#include "sql_base.h"                           // close_thread_tables
+#include "tztime.h"                             // struct Time_zone
+#include "log_event.h"                          // Rotate_log_event,
+                                                // Create_file_log_event,
+                                                // Format_description_log_event
 
 #ifdef HAVE_REPLICATION
 

=== modified file 'sql/slave.h'
--- a/sql/slave.h	2009-10-22 22:30:28 +0000
+++ b/sql/slave.h	2009-11-18 08:54:54 +0000
@@ -205,6 +205,8 @@ int apply_event_and_update_pos(Log_event
 
 pthread_handler_t handle_slave_io(void *arg);
 pthread_handler_t handle_slave_sql(void *arg);
+bool net_request_file(NET* net, const char* fname);
+
 extern bool volatile abort_loop;
 extern Master_info main_mi, *active_mi; /* active_mi for multi-master */
 extern LIST master_list;

=== modified file 'sql/sp.cc'
--- a/sql/sp.cc	2009-11-05 20:28:35 +0000
+++ b/sql/sp.cc	2009-11-18 08:54:54 +0000
@@ -13,8 +13,18 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #include "sp.h"
+#include "sql_base.h"                           // close_thread_tables
+#include "sql_parse.h"                          // parse_sql
+#include "key.h"                                // key_copy
+#include "sql_show.h"             // append_definer, append_identifier
+#include "sql_db.h" // get_default_db_collation, mysql_opt_change_db,
+                    // mysql_change_db, check_db_dir_existence,
+                    // load_db_opt_by_name
+#include "sql_table.h"                          // write_bin_log
+#include "sql_acl.h"                       // SUPER_ACL
 #include "sp_head.h"
 #include "sp_cache.h"
 #include "sql_trigger.h"

=== modified file 'sql/sp.h'
--- a/sql/sp.h	2009-07-28 17:44:38 +0000
+++ b/sql/sp.h	2009-11-18 08:54:54 +0000
@@ -17,6 +17,23 @@
 #ifndef _SP_H_
 #define _SP_H_
 
+#include "sql_string.h"                         // LEX_STRING
+
+class Field;
+class Open_tables_state;
+class Query_arena;
+class Query_tables_list;
+class THD;
+class sp_cache;
+class sp_head;
+class sp_name;
+class st_sp_chistics;
+struct LEX;
+struct TABLE;
+struct TABLE_LIST;
+typedef struct st_hash HASH;
+typedef struct st_sql_list SQL_LIST;
+
 /* Tells what SP_DEFAULT_ACCESS should be mapped to */
 #define SP_DEFAULT_ACCESS_MAPPING SP_CONTAINS_SQL
 
@@ -86,4 +103,14 @@ extern "C" uchar* sp_sroutine_key(const 
 */
 TABLE *open_proc_table_for_read(THD *thd, Open_tables_state *backup);
 
+bool load_charset(MEM_ROOT *mem_root,
+                  Field *field,
+                  CHARSET_INFO *dflt_cs,
+                  CHARSET_INFO **cs);
+
+bool load_collation(MEM_ROOT *mem_root,
+                    Field *field,
+                    CHARSET_INFO *dflt_cl,
+                    CHARSET_INFO **cl);
+
 #endif /* _SP_H_ */

=== modified file 'sql/sp_cache.cc'
--- a/sql/sp_cache.cc	2009-10-14 16:37:38 +0000
+++ b/sql/sp_cache.cc	2009-11-18 08:54:54 +0000
@@ -13,7 +13,8 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #ifdef USE_PRAGMA_IMPLEMENTATION
 #pragma implementation
 #endif

=== modified file 'sql/sp_cache.h'
--- a/sql/sp_cache.h	2008-07-03 19:41:22 +0000
+++ b/sql/sp_cache.h	2009-11-18 08:54:54 +0000
@@ -21,6 +21,8 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
+#include "my_global.h"                          /* ulong */
+
 /*
   Stored procedures/functions cache. This is used as follows:
    * Each thread has its own cache.
@@ -30,6 +32,7 @@
 
 class sp_head;
 class sp_cache;
+class sp_name;
 
 /*
   Cache usage scenarios:

=== modified file 'sql/sp_head.cc'
--- a/sql/sp_head.cc	2009-11-06 15:28:25 +0000
+++ b/sql/sp_head.cc	2009-11-18 08:54:54 +0000
@@ -13,9 +13,19 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #include "sql_prepare.h"
+#include "sql_cache.h"                          // query_cache_*
 #include "probes_mysql.h"
+#include "sql_show.h"                           // append_identifier
+#include "sql_db.h"            // mysql_opt_change_db, mysql_change_db
+#include "sql_table.h"         // sp_prepare_create_field,
+                               // prepare_create_field
+#include "sql_acl.h"           // *_ACL
+#include "sql_array.h"         // Dynamic_array
+#include "log_event.h"         // append_query_string, Query_log_event
+
 #ifdef USE_PRAGMA_IMPLEMENTATION
 #pragma implementation
 #endif
@@ -24,6 +34,8 @@
 #include "sp_pcontext.h"
 #include "sp_rcontext.h"
 #include "sp_cache.h"
+#include "sql_parse.h"                          // cleanup_items
+#include "sql_base.h"                           // close_thread_tables
 
 /*
   Sufficient max length of printed destinations and frame offsets (all uints).

=== modified file 'sql/sp_head.h'
--- a/sql/sp_head.h	2009-04-29 02:59:10 +0000
+++ b/sql/sp_head.h	2009-11-18 08:54:54 +0000
@@ -21,6 +21,14 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
+/*
+  It is necessary to include set_var.h instead of item.h because there
+  are dependencies on include order for set_var.h and item.h. This
+  will be resolved later.
+*/
+#include "set_var.h"                            // Item
+#include "sql_class.h"                          // THD
+
 #include <stddef.h>
 
 /**

=== modified file 'sql/sp_pcontext.cc'
--- a/sql/sp_pcontext.cc	2009-09-10 09:18:29 +0000
+++ b/sql/sp_pcontext.cc	2009-11-18 08:54:54 +0000
@@ -13,7 +13,8 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #ifdef USE_PRAGMA_IMPLEMENTATION
 #pragma implementation
 #endif

=== modified file 'sql/sp_pcontext.h'
--- a/sql/sp_pcontext.h	2009-09-10 09:18:29 +0000
+++ b/sql/sp_pcontext.h	2009-11-18 08:54:54 +0000
@@ -21,6 +21,12 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
+#include "sql_string.h"                         // LEX_STRING
+#include "mysql_com.h"                          // enum_field_types
+#include "field.h"                              // Create_field
+
+class sp_pcontext;
+
 typedef enum
 {
   sp_param_in,

=== modified file 'sql/sp_rcontext.cc'
--- a/sql/sp_rcontext.cc	2009-09-10 09:18:29 +0000
+++ b/sql/sp_rcontext.cc	2009-11-18 08:54:54 +0000
@@ -13,7 +13,8 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #ifdef USE_PRAGMA_IMPLEMENTATION
 #pragma implementation
 #endif
@@ -27,7 +28,7 @@
 #include "sql_cursor.h"
 #include "sp_rcontext.h"
 #include "sp_pcontext.h"
-
+#include "sql_select.h"                     // create_virtual_tmp_table
 
 sp_rcontext::sp_rcontext(sp_pcontext *root_parsing_ctx,
                          Field *return_value_fld,

=== modified file 'sql/sp_rcontext.h'
--- a/sql/sp_rcontext.h	2009-09-10 09:18:29 +0000
+++ b/sql/sp_rcontext.h	2009-11-18 08:54:54 +0000
@@ -21,11 +21,19 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
+#include "sql_class.h"                    // select_result_interceptor
+
 struct sp_cond_type;
 class sp_cursor;
 struct sp_variable;
 class sp_lex_keeper;
 class sp_instr_cpush;
+class Query_arena;
+class sp_head;
+class sp_pcontext;
+class Item_cache;
+typedef class st_select_lex_unit SELECT_LEX_UNIT;
+class Server_side_cursor;
 
 #define SP_HANDLER_NONE      0
 #define SP_HANDLER_EXIT      1

=== modified file 'sql/spatial.cc'
--- a/sql/spatial.cc	2009-08-28 16:21:54 +0000
+++ b/sql/spatial.cc	2009-11-18 08:54:54 +0000
@@ -13,7 +13,11 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "my_global.h"                          // REQUIRED for HAVE_* below
+#include "spatial.h"
+#include "gstream.h"                            // Gis_read_stream
+#include "sql_string.h"                         // String
 
 #ifdef HAVE_SPATIAL
 

=== modified file 'sql/spatial.h'
--- a/sql/spatial.h	2009-06-17 14:56:44 +0000
+++ b/sql/spatial.h	2009-11-18 08:54:54 +0000
@@ -16,8 +16,12 @@
 #ifndef _spatial_h
 #define _spatial_h
 
+#include "sql_string.h"                         /* String, LEX_STRING */
+
 #ifdef HAVE_SPATIAL
 
+class Gis_read_stream;
+
 const uint SRID_SIZE= 4;
 const uint SIZEOF_STORED_DOUBLE= 8;
 const uint POINT_DATA_SIZE= SIZEOF_STORED_DOUBLE*2; 

=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc	2009-11-06 14:20:27 +0000
+++ b/sql/sql_acl.cc	2009-11-18 08:54:54 +0000
@@ -24,12 +24,23 @@
   in the relevant fields. Empty strings comes last.
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "sql_acl.h"         // MYSQL_DB_FIELD_COUNT, ACL_ACCESS
+#include "sql_base.h"                           // close_thread_tables
+#include "key.h"             // key_copy, key_cmp_if_same, key_restore
+#include "sql_show.h"        // append_identifier
+#include "sql_table.h"                         // build_table_filename
 #include "hash_filo.h"
+#include "sql_parse.h"                          // check_access
+#include "sql_view.h"                           // VIEW_ANY_ACL
+#include "records.h"              // READ_RECORD, read_record_info,
+                                  // init_read_record, end_read_record
+#include "rpl_filter.h"           // rpl_filter
 #include <m_ctype.h>
 #include <stdarg.h>
 #include "sp_head.h"
 #include "sp.h"
+#include "records.h"             // init_read_record, end_read_record
 
 time_t mysql_db_table_last_check= 0L;
 

=== modified file 'sql/sql_acl.h'
--- a/sql/sql_acl.h	2009-10-28 07:55:44 +0000
+++ b/sql/sql_acl.h	2009-11-18 08:54:54 +0000
@@ -16,7 +16,8 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "slave.h" // for tables_ok(), rpl_filter
+#include "violite.h"                            /* SSL_type */
+#include "sql_class.h"                          /* LEX_COLUMN */
 
 #define SELECT_ACL	(1L << 0)
 #define INSERT_ACL	(1L << 1)
@@ -278,6 +279,12 @@ bool sp_grant_privileges(THD *thd, const
 bool check_routine_level_acl(THD *thd, const char *db, const char *name,
                              bool is_proc);
 bool is_acl_user(const char *host, const char *user);
+int fill_schema_user_privileges(THD *thd, TABLE_LIST *tables, COND *cond);
+int fill_schema_schema_privileges(THD *thd, TABLE_LIST *tables, COND *cond);
+int fill_schema_table_privileges(THD *thd, TABLE_LIST *tables, COND *cond);
+int fill_schema_column_privileges(THD *thd, TABLE_LIST *tables, COND *cond);
+int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr);
+
 bool has_any_table_level_privileges(THD *thd, ulong required_access,
                                     TABLE_LIST *tables);
 

=== modified file 'sql/sql_analyse.cc'
--- a/sql/sql_analyse.cc	2009-06-17 14:56:44 +0000
+++ b/sql/sql_analyse.cc	2009-11-18 08:54:54 +0000
@@ -28,7 +28,7 @@
 
 #define MYSQL_LEX 1
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
 #include "procedure.h"
 #include "sql_analyse.h"
 #include <m_ctype.h>

=== modified file 'sql/sql_analyse.h'
--- a/sql/sql_analyse.h	2009-09-23 21:32:31 +0000
+++ b/sql/sql_analyse.h	2009-11-18 08:54:54 +0000
@@ -23,6 +23,8 @@
 #pragma interface				/* gcc class implementation */
 #endif
 
+#include "procedure.h"                          /* Procedure */
+
 #define my_thd_charset	default_charset_info
 
 #define DEC_IN_AVG 4
@@ -359,4 +361,6 @@ public:
 				      List<Item> &field_list);
 };
 
+bool append_escaped(String *to_str, String *from_str);
+
 #endif /* SQL_ANALYSE_INCLUDED */

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2009-11-06 14:20:27 +0000
+++ b/sql/sql_base.cc	2009-11-18 08:54:54 +0000
@@ -16,8 +16,29 @@
 
 /* Basic functions needed by many modules */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #include "debug_sync.h"
+#include "sql_base.h"                           // setup_table_map
+#include "lock.h"        // broadcast_refresh, mysql_lock_remove,
+                         // mysql_unlock_tables,
+                         // mysql_lock_have_duplicate
+#include "sql_show.h"    // append_identifier
+#include "strfunc.h"     // find_type
+#include "parse_file.h"  // sql_parse_prepare, File_parser
+#include "sql_view.h"    // mysql_frm_type, mysql_make_view, VIEW_ANY_ACL
+#include "sql_parse.h"   // check_table_access
+#include "sql_insert.h"  // kill_delayed_threads
+#include "sql_acl.h"     // *_ACL, check_grant_all_columns,
+                         // check_column_grant_in_table_ref,
+                         // get_column_grant
+#include "sql_partition.h"               // ALTER_PARTITION_PARAM_TYPE
+#include "sql_derived.h" // mysql_derived_prepare,
+                         // mysql_handle_derived,
+                         // mysql_derived_filling
+#include "sql_handler.h" // mysql_ha_flush
+#include "sql_partition.h"                      // ALTER_PARTITION_PARAM_TYPE
+#include "log_event.h"                          // Query_log_event
 #include "sql_select.h"
 #include "sp_head.h"
 #include "sp.h"
@@ -27,6 +48,7 @@
 #include <my_dir.h>
 #include <hash.h>
 #include "rpl_filter.h"
+#include "sql_table.h"                          // build_table_filename
 #ifdef  __WIN__
 #include <io.h>
 #endif

=== added file 'sql/sql_base.h'
--- a/sql/sql_base.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_base.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,333 @@
+#ifndef SQL_BASE_INCLUDED
+#define SQL_BASE_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "table.h"                              /* open_table_mode */
+#include "sql_trigger.h"                        /* trg_event_type */
+#include "sql_class.h"                          /* enum_mark_columns */
+#include "mysqld.h"                             /* key_map */
+
+class Item_ident;
+class Name_resolution_context;
+class Open_table_context;
+class Open_tables_state;
+class Prelocking_strategy;
+class TABLE_LIST;
+class THD;
+class handlerton;
+struct TABLE;
+
+typedef class st_select_lex SELECT_LEX;
+
+typedef struct st_lock_param_type ALTER_PARTITION_PARAM_TYPE;
+
+typedef struct st_lock_param_type ALTER_PARTITION_PARAM_TYPE;
+
+/*
+  This enumeration type is used only by the function find_item_in_list
+  to return the info on how an item has been resolved against a list
+  of possibly aliased items.
+  The item can be resolved:
+   - against an alias name of the list's element (RESOLVED_AGAINST_ALIAS)
+   - against non-aliased field name of the list  (RESOLVED_WITH_NO_ALIAS)
+   - against an aliased field name of the list   (RESOLVED_BEHIND_ALIAS)
+   - ignoring the alias name in cases when SQL requires to ignore aliases
+     (e.g. when the resolved field reference contains a table name or
+     when the resolved item is an expression)   (RESOLVED_IGNORING_ALIAS)
+*/
+enum enum_resolution_type {
+  NOT_RESOLVED=0,
+  RESOLVED_IGNORING_ALIAS,
+  RESOLVED_BEHIND_ALIAS,
+  RESOLVED_WITH_NO_ALIAS,
+  RESOLVED_AGAINST_ALIAS
+};
+
+enum enum_open_table_action {OT_NO_ACTION= 0, OT_BACK_OFF_AND_RETRY,
+                             OT_DISCOVER, OT_REPAIR};
+
+enum find_item_error_report_type {REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND,
+				  IGNORE_ERRORS, REPORT_EXCEPT_NON_UNIQUE,
+                                  IGNORE_EXCEPT_NON_UNIQUE};
+
+enum enum_tdc_remove_table_type {TDC_RT_REMOVE_ALL, TDC_RT_REMOVE_NOT_OWN,
+                                 TDC_RT_REMOVE_UNUSED};
+
+#define TMP_TABLE_KEY_EXTRA 8
+
+/* bits for last argument to remove_table_from_cache() */
+#define RTFC_NO_FLAG                0x0000
+#define RTFC_OWNED_BY_THD_FLAG      0x0001
+#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
+#define RTFC_CHECK_KILLED_FLAG      0x0004
+
+bool check_dup(const char *db, const char *name, TABLE_LIST *tables);
+bool table_cache_init(void);
+void table_cache_free(void);
+bool table_def_init(void);
+void table_def_free(void);
+void table_def_start_shutdown(void);
+void assign_new_table_id(TABLE_SHARE *share);
+uint cached_open_tables(void);
+uint cached_table_definitions(void);
+uint create_table_def_key(THD *thd, char *key, TABLE_LIST *table_list,
+                          bool tmp_table);
+TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
+                             uint key_length, uint db_flags, int *error);
+void release_table_share(TABLE_SHARE *share, enum release_type type);
+TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
+
+TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update,
+                   uint lock_flags);
+TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT* mem,
+                  bool *refresh, uint flags);
+bool name_lock_locked_table(THD *thd, TABLE_LIST *tables);
+bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list, bool link_in);
+TABLE *table_cache_insert_placeholder(THD *thd, const char *key,
+                                      uint key_length);
+bool lock_table_name_if_not_cached(THD *thd, const char *db,
+                                   const char *table_name, TABLE **table);
+void detach_merge_children(TABLE *table, bool clear_refs);
+bool fix_merge_after_open(TABLE_LIST *old_child_list, TABLE_LIST **old_last,
+                          TABLE_LIST *new_child_list, TABLE_LIST **new_last);
+bool reopen_table(TABLE *table);
+bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
+void close_data_files_and_morph_locks(THD *thd, const char *db,
+                                      const char *table_name);
+void close_handle_and_leave_table_as_lock(TABLE *table);
+bool wait_for_tables(THD *thd);
+bool table_is_used(TABLE *table, bool wait_for_name_lock);
+TABLE *drop_locked_tables(THD *thd,const char *db, const char *table_name);
+void abort_locked_tables(THD *thd,const char *db, const char *table_name);
+
+bool get_key_map_from_key_list(key_map *map, TABLE *table,
+                               List<String> *index_list);
+TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
+			    const char *table_name, bool link_in_list);
+TABLE *find_locked_table(THD *thd, const char *db,const char *table_name);
+TABLE *find_write_locked_table(TABLE *list, const char *db,
+                               const char *table_name);
+thr_lock_type read_lock_type_for_table(THD *thd, TABLE *table);
+
+my_bool mysql_rm_tmp_tables(void);
+bool rm_temporary_table(handlerton *base, char *path);
+void close_tables_for_reopen(THD *thd, TABLE_LIST **tables);
+TABLE_LIST *find_table_in_list(TABLE_LIST *table,
+                               TABLE_LIST *TABLE_LIST::*link,
+                               const char *db_name,
+                               const char *table_name);
+TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name);
+TABLE *find_temporary_table(THD *thd, TABLE_LIST *table_list);
+void close_thread_tables(THD *thd);
+bool fill_record_n_invoke_before_triggers(THD *thd, List<Item> &fields,
+                                          List<Item> &values,
+                                          bool ignore_errors,
+                                          Table_triggers_list *triggers,
+                                          enum trg_event_type event);
+bool fill_record_n_invoke_before_triggers(THD *thd, Field **field,
+                                          List<Item> &values,
+                                          bool ignore_errors,
+                                          Table_triggers_list *triggers,
+                                          enum trg_event_type event);
+bool insert_fields(THD *thd, Name_resolution_context *context,
+		   const char *db_name, const char *table_name,
+                   List_iterator<Item> *it, bool any_privileges);
+int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
+	       List<Item> *sum_func_list, uint wild_num);
+bool setup_fields(THD *thd, Item** ref_pointer_array,
+                  List<Item> &item, enum_mark_columns mark_used_columns,
+                  List<Item> *sum_func_list, bool allow_sum_func);
+bool fill_record(THD *thd, Field **field, List<Item> &values,
+                 bool ignore_errors);
+
+Field *
+find_field_in_tables(THD *thd, Item_ident *item,
+                     TABLE_LIST *first_table, TABLE_LIST *last_table,
+                     Item **ref, find_item_error_report_type report_error,
+                     bool check_privileges, bool register_tree_change);
+Field *
+find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
+                        const char *name, uint length,
+                        const char *item_name, const char *db_name,
+                        const char *table_name, Item **ref,
+                        bool check_privileges, bool allow_rowid,
+                        uint *cached_field_index_ptr,
+                        bool register_tree_change, TABLE_LIST **actual_table);
+Field *
+find_field_in_table(THD *thd, TABLE *table, const char *name, uint length,
+                    bool allow_rowid, uint *cached_field_index_ptr);
+Field *
+find_field_in_table_sef(TABLE *table, const char *name);
+Item ** find_item_in_list(Item *item, List<Item> &items, uint *counter,
+                          find_item_error_report_type report_error,
+                          enum_resolution_type *resolution);
+bool setup_tables(THD *thd, Name_resolution_context *context,
+                  List<TABLE_LIST> *from_clause, TABLE_LIST *tables,
+                  TABLE_LIST **leaves, bool select_insert);
+bool setup_tables_and_check_access(THD *thd,
+                                   Name_resolution_context *context,
+                                   List<TABLE_LIST> *from_clause,
+                                   TABLE_LIST *tables,
+                                   TABLE_LIST **leaves,
+                                   bool select_insert,
+                                   ulong want_access_first,
+                                   ulong want_access);
+void wait_while_table_is_used(THD *thd, TABLE *table,
+                              enum ha_extra_function function);
+void unlink_open_table(THD *thd, TABLE *find, bool unlock);
+
+void drop_open_table(THD *thd, TABLE *table, const char *db_name,
+                     const char *table_name);
+void close_all_tables_for_name(THD *thd, TABLE_SHARE *share,
+                               bool remove_from_locked_tables);
+void update_non_unique_table_error(TABLE_LIST *update,
+                                   const char *operation,
+                                   TABLE_LIST *duplicate);
+int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
+		COND **conds);
+int setup_ftfuncs(SELECT_LEX* select);
+int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order);
+void wait_for_condition(THD *thd, pthread_mutex_t *mutex,
+                        pthread_cond_t *cond);
+int open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags);
+/* open_and_lock_tables with optional derived handling */
+int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, bool derived);
+/* simple open_and_lock_tables without derived handling for single table */
+TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
+                                thr_lock_type lock_type);
+bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags);
+int lock_tables(THD *thd, TABLE_LIST *tables, uint count, bool *need_reopen);
+int abort_and_upgrade_lock(ALTER_PARTITION_PARAM_TYPE *lpt);
+int decide_logging_format(THD *thd, TABLE_LIST *tables);
+void free_io_cache(TABLE *entry);
+void intern_close_table(TABLE *entry);
+bool close_thread_table(THD *thd, TABLE **table_ptr);
+void close_temporary_tables(THD *thd);
+TABLE_LIST *unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
+                         bool check_alias);
+int drop_temporary_table(THD *thd, TABLE_LIST *table_list);
+void close_temporary_table(THD *thd, TABLE *table, bool free_share,
+                           bool delete_table);
+void close_temporary(TABLE *table, bool free_share, bool delete_table);
+bool rename_temporary_table(THD* thd, TABLE *table, const char *new_db,
+			    const char *table_name);
+void mysql_wait_completed_table(ALTER_PARTITION_PARAM_TYPE *lpt, TABLE *my_table);
+void remove_db_from_cache(const char *db);
+void flush_tables();
+bool is_equal(const LEX_STRING *a, const LEX_STRING *b);
+
+/* Functions to work with system tables. */
+bool open_system_tables_for_read(THD *thd, TABLE_LIST *table_list,
+                                 Open_tables_state *backup);
+void close_system_tables(THD *thd, Open_tables_state *backup);
+TABLE *open_system_table_for_update(THD *thd, TABLE_LIST *one_table);
+
+TABLE *open_performance_schema_table(THD *thd, TABLE_LIST *one_table,
+                                     Open_tables_state *backup);
+void close_performance_schema_table(THD *thd, Open_tables_state *backup);
+
+bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
+                         bool wait_for_refresh, bool wait_for_placeholders);
+bool close_cached_connection_tables(THD *thd, bool wait_for_refresh,
+                                    LEX_STRING *connect_string,
+                                    bool have_lock = FALSE);
+OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild);
+bool remove_table_from_cache(THD *thd, const char *db, const char *table,
+                             uint flags);
+
+
+extern uint  table_cache_count;
+extern TABLE *unused_tables;
+extern Item **not_found_item;
+extern Field *not_found_field;
+extern Field *view_ref_found;
+extern HASH open_cache;
+
+/**
+  clean/setup table fields and map.
+
+  @param table        TABLE structure pointer (which should be setup)
+  @param table_list   TABLE_LIST structure pointer (owner of TABLE)
+  @param tablenr     table number
+*/
+
+
+inline void setup_table_map(TABLE *table, TABLE_LIST *table_list, uint tablenr)
+{
+  table->used_fields= 0;
+  table->const_table= 0;
+  table->null_row= 0;
+  table->status= STATUS_NO_RECORD;
+  table->maybe_null= table_list->outer_join;
+  TABLE_LIST *embedding= table_list->embedding;
+  while (!table->maybe_null && embedding)
+  {
+    table->maybe_null= embedding->outer_join;
+    embedding= embedding->embedding;
+  }
+  table->tablenr= tablenr;
+  table->map= (table_map) 1 << tablenr;
+  table->force_index= table_list->force_index;
+  table->force_index_order= table->force_index_group= 0;
+  table->covering_keys= table->s->keys_for_keyread;
+  table->merge_keys.clear_all();
+}
+
+inline TABLE_LIST *find_table_in_global_list(TABLE_LIST *table,
+                                             const char *db_name,
+                                             const char *table_name)
+{
+  return find_table_in_list(table, &TABLE_LIST::next_global,
+                            db_name, table_name);
+}
+
+inline TABLE_LIST *find_table_in_local_list(TABLE_LIST *table,
+                                            const char *db_name,
+                                            const char *table_name)
+{
+  return find_table_in_list(table, &TABLE_LIST::next_local,
+                            db_name, table_name);
+}
+
+inline bool setup_fields_with_no_wrap(THD *thd, Item **ref_pointer_array,
+                                      List<Item> &item,
+                                      enum_mark_columns mark_used_columns,
+                                      List<Item> *sum_func_list,
+                                      bool allow_sum_func)
+{
+  bool res;
+  thd->lex->select_lex.no_wrap_view_item= TRUE;
+  res= setup_fields(thd, ref_pointer_array, item, mark_used_columns,
+                    sum_func_list, allow_sum_func);
+  thd->lex->select_lex.no_wrap_view_item= FALSE;
+  return res;
+}
+
+/* simple open_and_lock_tables without derived handling */
+inline bool simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables)
+{
+  return open_and_lock_tables_derived(thd, tables, FALSE);
+}
+
+/* open_and_lock_tables with derived handling */
+inline bool open_and_lock_tables(THD *thd, TABLE_LIST *tables)
+{
+  return open_and_lock_tables_derived(thd, tables, TRUE);
+}
+
+#endif /* SQL_BASE_INCLUDED */

=== modified file 'sql/sql_binlog.cc'
--- a/sql/sql_binlog.cc	2009-10-22 22:30:28 +0000
+++ b/sql/sql_binlog.cc	2009-11-18 08:54:54 +0000
@@ -13,10 +13,20 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "sql_binlog.h"
+#include "sql_parse.h"                          // check_global_access
+#include "sql_acl.h"                            // *_ACL
 #include "rpl_rli.h"
 #include "base64.h"
-
+#include "slave.h"                              // apply_event_and_update_pos
+#include "log_event.h"                          // Format_description_log_event,
+                                                // EVENT_LEN_OFFSET,
+                                                // EVENT_TYPE_OFFSET,
+                                                // FORMAT_DESCRIPTION_LOG_EVENT,
+                                                // START_EVENT_V3,
+                                                // Log_event_type,
+                                                // Log_event
 /**
   Execute a BINLOG statement.
 

=== added file 'sql/sql_binlog.h'
--- a/sql/sql_binlog.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_binlog.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,23 @@
+#ifndef SQL_BINLOG_INCLUDED
+#define SQL_BINLOG_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+class THD;
+
+void mysql_client_binlog_statement(THD *thd);
+
+#endif /* SQL_BINLOG_INCLUDED */

=== modified file 'sql/sql_bitmap.h'
--- a/sql/sql_bitmap.h	2008-01-29 11:14:34 +0000
+++ b/sql/sql_bitmap.h	2009-11-18 08:54:54 +0000
@@ -19,6 +19,9 @@
   also be able to use 32 or 64 bits bitmaps very efficiently
 */
 
+#ifndef SQL_BITMAP_INCLUDED
+#define SQL_BITMAP_INCLUDED
+
 #include <my_bitmap.h>
 
 template <uint default_width> class Bitmap
@@ -138,3 +141,5 @@ public:
   ulonglong to_ulonglong() const { return map; }
 };
 
+
+#endif /* SQL_BITMAP_INCLUDED */

=== modified file 'sql/sql_cache.cc'
--- a/sql/sql_cache.cc	2009-11-06 15:28:25 +0000
+++ b/sql/sql_cache.cc	2009-11-18 08:54:54 +0000
@@ -327,7 +327,12 @@ TODO list:
       (This could be done with almost no speed penalty)
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "sql_cache.h"
+#include "sql_parse.h"                          // check_table_access
+#include "tztime.h"                             // struct Time_zone
+#include "sql_acl.h"                            // SELECT_ACL
+#include "sql_base.h"                           // TMP_TABLE_KEY_EXTRA
 #ifdef HAVE_QUERY_CACHE
 #include <m_ctype.h>
 #include <my_dir.h>

=== modified file 'sql/sql_cache.h'
--- a/sql/sql_cache.h	2009-10-29 11:19:36 +0000
+++ b/sql/sql_cache.h	2009-11-18 08:54:54 +0000
@@ -16,6 +16,16 @@
 #ifndef _SQL_CACHE_H
 #define _SQL_CACHE_H
 
+#include "hash.h"
+#include "my_base.h"                            /* ha_rows */
+
+class TABLE_LIST;
+class Time_zone;
+struct LEX;
+struct TABLE;
+typedef struct my_locale_st MY_LOCALE;
+typedef struct st_changed_table_list CHANGED_TABLE_LIST;
+
 /* Query cache */
 
 /*
@@ -66,6 +76,11 @@ struct Query_cache_result;
 class Query_cache;
 struct Query_cache_tls;
 struct LEX;
+class THD;
+
+typedef my_bool (*qc_engine_callback)(THD *thd, char *table_key,
+                                      uint key_length,
+                                      ulonglong *engine_data);
 
 /**
   This class represents a node in the linked chain of queries
@@ -502,6 +517,69 @@ protected:
   void unlock(void);
 };
 
+#ifdef HAVE_QUERY_CACHE
+struct Query_cache_query_flags
+{
+  unsigned int client_long_flag:1;
+  unsigned int client_protocol_41:1;
+  unsigned int protocol_type:2;
+  unsigned int more_results_exists:1;
+  unsigned int in_trans:1;
+  unsigned int autocommit:1;
+  unsigned int pkt_nr;
+  uint character_set_client_num;
+  uint character_set_results_num;
+  uint collation_connection_num;
+  ha_rows limit;
+  Time_zone *time_zone;
+  ulong sql_mode;
+  ulong max_sort_length;
+  ulong group_concat_max_len;
+  ulong default_week_format;
+  ulong div_precision_increment;
+  MY_LOCALE *lc_time_names;
+};
+#define QUERY_CACHE_FLAGS_SIZE sizeof(Query_cache_query_flags)
+#include "sql_cache.h"
+#define query_cache_abort(A) query_cache.abort(A)
+#define query_cache_end_of_result(A) query_cache.end_of_result(A)
+#define query_cache_store_query(A, B) query_cache.store_query(A, B)
+#define query_cache_destroy() query_cache.destroy()
+#define query_cache_result_size_limit(A) query_cache.result_size_limit(A)
+#define query_cache_init() query_cache.init()
+#define query_cache_resize(A) query_cache.resize(A)
+#define query_cache_set_min_res_unit(A) query_cache.set_min_res_unit(A)
+#define query_cache_invalidate3(A, B, C) query_cache.invalidate(A, B, C)
+#define query_cache_invalidate1(A) query_cache.invalidate(A)
+#define query_cache_send_result_to_client(A, B, C) \
+  query_cache.send_result_to_client(A, B, C)
+#define query_cache_invalidate_by_MyISAM_filename_ref \
+  &query_cache_invalidate_by_MyISAM_filename
+/* note the "maybe": it's a read without mutex */
+#define query_cache_maybe_disabled(T)                                 \
+  (T->variables.query_cache_type == 0 || query_cache.query_cache_size == 0)
+#define query_cache_is_cacheable_query(L) \
+  (((L)->sql_command == SQLCOM_SELECT) && (L)->safe_to_cache_query)
+#else
+#define QUERY_CACHE_FLAGS_SIZE 0
+#define query_cache_store_query(A, B)
+#define query_cache_destroy()
+#define query_cache_result_size_limit(A)
+#define query_cache_init()
+#define query_cache_resize(A)
+#define query_cache_set_min_res_unit(A)
+#define query_cache_invalidate3(A, B, C)
+#define query_cache_invalidate1(A)
+#define query_cache_send_result_to_client(A, B, C) 0
+#define query_cache_invalidate_by_MyISAM_filename_ref NULL
+
+#define query_cache_abort(A)
+#define query_cache_end_of_result(A)
+#define query_cache_invalidate_by_MyISAM_filename_ref NULL
+#define query_cache_maybe_disabled(T) 1
+#define query_cache_is_cacheable_query(L) 0
+#endif /*HAVE_QUERY_CACHE*/
+
 extern Query_cache query_cache;
 extern TYPELIB query_cache_type_typelib;
 #endif

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2009-11-10 07:31:33 +0000
+++ b/sql/sql_class.cc	2009-11-18 08:54:54 +0000
@@ -25,7 +25,17 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "sql_class.h"
+#include "lock.h"      // unlock_global_read_lock, mysql_unlock_tables
+#include "sql_cache.h"                          // query_cache_abort
+#include "sql_base.h"                           // close_thread_tables
+#include "sql_time.h"                         // date_time_format_copy
+#include "sql_acl.h"                          // NO_ACCESS,
+                                              // acl_getroot_no_password
+#include "sql_base.h"                         // close_temporary_tables
+#include "sql_handler.h"                      // mysql_ha_cleanup
 #include "rpl_rli.h"
 #include "rpl_filter.h"
 #include "rpl_record.h"
@@ -43,6 +53,7 @@
 #include "sp_rcontext.h"
 #include "sp_cache.h"
 #include "debug_sync.h"
+#include "sql_parse.h"                          // is_update_query
 
 /*
   The following is used to initialise Table_ident with a internal

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2009-11-10 07:31:33 +0000
+++ b/sql/sql_class.h	2009-11-18 08:54:54 +0000
@@ -23,9 +23,19 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
+#ifdef MYSQL_SERVER
+#include "unireg.h"                    // REQUIRED: for other includes
+#endif
+#include "sql_const.h"
 #include "log.h"
 #include "rpl_tblmap.h"
-
+#include "sql_locale.h"                         /* my_locale_st */
+#include "sql_profile.h"                   /* PROFILING */
+#include "scheduler.h"                     /* thd_scheduler */
+#include "protocol.h"             /* Protocol_text, Protocol_binary */
+#include "violite.h"              /* vio_is_connected */
+#include "thr_lock.h"             /* thr_lock_type, THR_LOCK_DATA,
+                                     THR_LOCK_INFO, THR_LOCK_OWNER */
 
 class Reprepare_observer;
 class Relay_log_info;
@@ -37,6 +47,8 @@ class sp_rcontext;
 class sp_cache;
 class Parser_state;
 class Rows_log_event;
+class User_level_lock;
+class user_var_entry;
 
 enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE };
 enum enum_ha_read_modes { RFIRST, RNEXT, RPREV, RLAST, RKEY, RNEXT_SAME };
@@ -50,6 +62,40 @@ enum enum_mark_columns
 { MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE};
 enum enum_filetype { FILETYPE_CSV, FILETYPE_XML };
 
+/* Bits for different SQL modes modes (including ANSI mode) */
+#define MODE_REAL_AS_FLOAT              1
+#define MODE_PIPES_AS_CONCAT            2
+#define MODE_ANSI_QUOTES                4
+#define MODE_IGNORE_SPACE               8
+#define MODE_NOT_USED                   16
+#define MODE_ONLY_FULL_GROUP_BY         32
+#define MODE_NO_UNSIGNED_SUBTRACTION    64
+#define MODE_NO_DIR_IN_CREATE           128
+#define MODE_POSTGRESQL                 256
+#define MODE_ORACLE                     512
+#define MODE_MSSQL                      1024
+#define MODE_DB2                        2048
+#define MODE_MAXDB                      4096
+#define MODE_NO_KEY_OPTIONS             8192
+#define MODE_NO_TABLE_OPTIONS           16384
+#define MODE_NO_FIELD_OPTIONS           32768
+#define MODE_MYSQL323                   65536L
+#define MODE_MYSQL40                    (MODE_MYSQL323*2)
+#define MODE_ANSI                       (MODE_MYSQL40*2)
+#define MODE_NO_AUTO_VALUE_ON_ZERO      (MODE_ANSI*2)
+#define MODE_NO_BACKSLASH_ESCAPES       (MODE_NO_AUTO_VALUE_ON_ZERO*2)
+#define MODE_STRICT_TRANS_TABLES        (MODE_NO_BACKSLASH_ESCAPES*2)
+#define MODE_STRICT_ALL_TABLES          (MODE_STRICT_TRANS_TABLES*2)
+#define MODE_NO_ZERO_IN_DATE            (MODE_STRICT_ALL_TABLES*2)
+#define MODE_NO_ZERO_DATE               (MODE_NO_ZERO_IN_DATE*2)
+#define MODE_INVALID_DATES              (MODE_NO_ZERO_DATE*2)
+#define MODE_ERROR_FOR_DIVISION_BY_ZERO (MODE_INVALID_DATES*2)
+#define MODE_TRADITIONAL                (MODE_ERROR_FOR_DIVISION_BY_ZERO*2)
+#define MODE_NO_AUTO_CREATE_USER        (MODE_TRADITIONAL*2)
+#define MODE_HIGH_NOT_PRECEDENCE        (MODE_NO_AUTO_CREATE_USER*2)
+#define MODE_NO_ENGINE_SUBSTITUTION     (MODE_HIGH_NOT_PRECEDENCE*2)
+#define MODE_PAD_CHAR_TO_FULL_LENGTH    (ULL(1) << 31)
+
 extern char internal_table_name[2];
 extern char empty_c_string[1];
 extern MYSQL_PLUGIN_IMPORT const char **errmesg;
@@ -242,6 +288,8 @@ public:
   LEX_COLUMN (const String& x,const  uint& y ): column (x),rights (y) {}
 };
 
+typedef struct my_locale_st MY_LOCALE;
+
 /**
   Query_cache_tls -- query cache thread local data.
 */
@@ -2388,8 +2436,6 @@ public:
   bool escaped_given(void);
 };
 
-#include "log_event.h"
-
 /*
   This is used to get result from a select
 */
@@ -3083,13 +3129,54 @@ public:
 */
 #define CF_DIAGNOSTIC_STMT        (1U << 8)
 
-/* Functions in sql_class.cc */
-
 void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var);
 
 void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
                         STATUS_VAR *dec_var);
 void mark_transaction_to_rollback(THD *thd, bool all);
 
+/**
+  The meat of thd_proc_info(THD*, char*), a macro that packs the last
+  three calling-info parameters.
+*/
+extern "C"
+const char *set_thd_proc_info(THD *thd, const char *info,
+                              const char *calling_func,
+                              const char *calling_file,
+                              const unsigned int calling_line);
+
+/*
+  This prototype is placed here instead of in item_func.h because it
+  depends on the definition of enum_sql_command, which is in this
+  file.
+ */
+int get_var_with_binlog(THD *thd, enum_sql_command sql_command,
+                        LEX_STRING &name, user_var_entry **out_entry);
+
+/* Inline functions */
+
+inline bool add_item_to_list(THD *thd, Item *item)
+{
+  return thd->lex->current_select->add_item_to_list(thd, item);
+}
+
+inline bool add_value_to_list(THD *thd, Item *value)
+{
+  return thd->lex->value_list.push_back(value);
+}
+
+inline bool add_order_to_list(THD *thd, Item *item, bool asc)
+{
+  return thd->lex->current_select->add_order_to_list(thd, item, asc);
+}
+
+inline bool add_group_to_list(THD *thd, Item *item, bool asc)
+{
+  return thd->lex->current_select->add_group_to_list(thd, item, asc);
+}
+
+#define thd_proc_info(thd, msg) \
+  set_thd_proc_info(thd, msg, __func__, __FILE__, __LINE__)
+
 #endif /* MYSQL_SERVER */
 #endif /* SQL_CLASS_INCLUDED */

=== modified file 'sql/sql_client.cc'
--- a/sql/sql_client.cc	2007-05-24 09:21:27 +0000
+++ b/sql/sql_client.cc	2009-11-18 08:54:54 +0000
@@ -17,7 +17,8 @@
   This files defines some MySQL C API functions that are server specific
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "sql_class.h"                          // system_variables
 
 /*
   Function called by my_net_init() to set some check variables

=== modified file 'sql/sql_connect.cc'
--- a/sql/sql_connect.cc	2009-11-02 11:10:04 +0000
+++ b/sql/sql_connect.cc	2009-11-18 08:54:54 +0000
@@ -18,8 +18,18 @@
   Functions to autenticate and handle reqests for a connection
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "sql_connect.h"
+#include "my_global.h"
 #include "probes_mysql.h"
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "sql_parse.h"                          // sql_command_flags,
+                                                // execute_init_command,
+                                                // do_command
+#include "sql_db.h"                             // mysql_change_db
+#include "hostname.h" // inc_host_errors, ip_to_hostname,
+                      // reset_host_errors
+#include "sql_acl.h"  // acl_getroot, NO_ACCESS, SUPER_ACL
 
 #ifdef HAVE_OPENSSL
 /*

=== added file 'sql/sql_connect.h'
--- a/sql/sql_connect.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_connect.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,42 @@
+#ifndef SQL_CONNECT_INCLUDED
+#define SQL_CONNECT_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "my_sys.h"                          /* pthread_handler_t */
+#include "mysql_com.h"                         /* enum_server_command */
+
+class THD;
+typedef struct st_lex_user LEX_USER;
+typedef struct user_conn USER_CONN;
+
+void init_max_user_conn(void);
+void free_max_user_conn(void);
+
+pthread_handler_t handle_one_connection(void *arg);
+bool init_new_connection_handler_thread();
+void reset_mqh(LEX_USER *lu, bool get_them);
+bool check_mqh(THD *thd, uint check_command);
+void time_out_user_resource_limits(THD *thd, USER_CONN *uc);
+void decrease_user_connections(USER_CONN *uc);
+void thd_init_client_charset(THD *thd, uint cs_number);
+bool setup_connection_thread_globals(THD *thd);
+
+int check_user(THD *thd, enum enum_server_command command,
+	       const char *passwd, uint passwd_len, const char *db,
+	       bool check_count);
+
+#endif /* SQL_CONNECT_INCLUDED */

=== added file 'sql/sql_const.h'
--- a/sql/sql_const.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_const.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,319 @@
+#ifndef SQL_CONST_INCLUDED
+#define SQL_CONST_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+/**
+  @file
+
+  File containing constants that can be used throughout the server and
+  also in the clients.
+
+  @note This file shall not contain any includes of any kinds.
+*/
+
+#define LIBLEN FN_REFLEN-FN_LEN			/* Max l{ngd p} dev */
+/* extra 4+4 bytes for slave tmp tables */
+#define MAX_DBKEY_LENGTH (NAME_LEN*2+1+1+4+4)
+#define MAX_ALIAS_NAME 256
+#define MAX_FIELD_NAME 34			/* Max colum name length +2 */
+#define MAX_SYS_VAR_LENGTH 32
+#define MAX_KEY MAX_INDEXES                     /* Max used keys */
+#define MAX_REF_PARTS 16			/* Max parts used as ref */
+#define MAX_KEY_LENGTH 3072			/* max possible key */
+#if SIZEOF_OFF_T > 4
+#define MAX_REFLENGTH 8				/* Max length for record ref */
+#else
+#define MAX_REFLENGTH 4				/* Max length for record ref */
+#endif
+#define MAX_HOSTNAME  61			/* len+1 in mysql.user */
+
+#define MAX_MBWIDTH		3		/* Max multibyte sequence */
+#define MAX_FIELD_CHARLENGTH	255
+#define MAX_FIELD_VARCHARLENGTH	65535
+#define MAX_FIELD_BLOBLENGTH UINT_MAX32     /* cf field_blob::get_length() */
+#define CONVERT_IF_BIGGER_TO_BLOB 512		/* Used for CREATE ... SELECT */
+
+/* Max column width +1 */
+#define MAX_FIELD_WIDTH		(MAX_FIELD_CHARLENGTH*MAX_MBWIDTH+1)
+
+#define MAX_BIT_FIELD_LENGTH    64      /* Max length in bits for bit fields */
+
+#define MAX_DATE_WIDTH		10	/* YYYY-MM-DD */
+#define MAX_TIME_WIDTH		23	/* -DDDDDD HH:MM:SS.###### */
+#define MAX_DATETIME_FULL_WIDTH 29	/* YYYY-MM-DD HH:MM:SS.###### AM */
+#define MAX_DATETIME_WIDTH	19	/* YYYY-MM-DD HH:MM:SS */
+#define MAX_DATETIME_COMPRESSED_WIDTH 14  /* YYYYMMDDHHMMSS */
+
+#define MAX_TABLES	(sizeof(table_map)*8-3)	/* Max tables in join */
+#define PARAM_TABLE_BIT	(((table_map) 1) << (sizeof(table_map)*8-3))
+#define OUTER_REF_TABLE_BIT	(((table_map) 1) << (sizeof(table_map)*8-2))
+#define RAND_TABLE_BIT	(((table_map) 1) << (sizeof(table_map)*8-1))
+#define PSEUDO_TABLE_BITS (PARAM_TABLE_BIT | OUTER_REF_TABLE_BIT | \
+                           RAND_TABLE_BIT)
+#define MAX_FIELDS	4096			/* Limit in the .frm file */
+#define MAX_PARTITIONS  1024
+
+#define MAX_SELECT_NESTING (sizeof(nesting_map)*8-1)
+
+#define MAX_SORT_MEMORY (2048*1024-MALLOC_OVERHEAD)
+#define MIN_SORT_MEMORY (32*1024-MALLOC_OVERHEAD)
+
+/* Some portable defines */
+
+#define portable_sizeof_char_ptr 8
+#define STRING_BUFFER_USUAL_SIZE 80
+
+/* Memory allocated when parsing a statement / saving a statement */
+#define MEM_ROOT_BLOCK_SIZE       8192
+#define MEM_ROOT_PREALLOC         8192
+#define TRANS_MEM_ROOT_BLOCK_SIZE 4096
+#define TRANS_MEM_ROOT_PREALLOC   4096
+
+#define DEFAULT_ERROR_COUNT	64
+#define EXTRA_RECORDS	10			/* Extra records in sort */
+#define SCROLL_EXTRA	5			/* Extra scroll-rows. */
+#define FIELD_NAME_USED ((uint) 32768)		/* Bit set if fieldname used */
+#define FORM_NAME_USED	((uint) 16384)		/* Bit set if formname used */
+#define FIELD_NR_MASK	16383			/* To get fieldnumber */
+#define FERR		-1			/* Error from my_functions */
+#define CREATE_MODE	0			/* Default mode on new files */
+#define NAMES_SEP_CHAR	'\377'			/* Char to sep. names */
+
+#define READ_RECORD_BUFFER	(uint) (IO_SIZE*8) /* Pointer_buffer_size */
+#define DISK_BUFFER_SIZE	(uint) (IO_SIZE*16) /* Size of diskbuffer */
+
+#define FRM_VER_TRUE_VARCHAR (FRM_VER+4) /* 10 */
+
+/***************************************************************************
+  Configuration parameters
+****************************************************************************/
+
+#define ACL_CACHE_SIZE		256
+#define MAX_PASSWORD_LENGTH	32
+#define HOST_CACHE_SIZE		128
+#define MAX_ACCEPT_RETRY	10	// Test accept this many times
+#define MAX_FIELDS_BEFORE_HASH	32
+#define USER_VARS_HASH_SIZE     16
+#define TABLE_OPEN_CACHE_MIN    400
+#define TABLE_OPEN_CACHE_DEFAULT 400
+#define TABLE_DEF_CACHE_DEFAULT 400
+/**
+  We must have room for at least 400 table definitions in the table
+  cache, since otherwise there is no chance prepared
+  statements that use these many tables can work.
+  Prepared statements use table definition cache ids (table_map_id)
+  as table version identifiers. If the table definition
+  cache size is less than the number of tables used in a statement,
+  the contents of the table definition cache is guaranteed to rotate
+  between a prepare and execute. This leads to stable validation
+  errors. In future we shall use more stable version identifiers,
+  for now the only solution is to ensure that the table definition
+  cache can contain at least all tables of a given statement.
+*/
+#define TABLE_DEF_CACHE_MIN     400
+
+/*
+  Stack reservation.
+  Feel free to raise this by the smallest amount you can to get the
+  "execution_constants" test to pass.
+*/
+#define STACK_MIN_SIZE          16000   // Abort if less stack during eval.
+
+#define STACK_MIN_SIZE_FOR_OPEN 1024*80
+#define STACK_BUFF_ALLOC        352     ///< For stack overrun checks
+#ifndef MYSQLD_NET_RETRY_COUNT
+#define MYSQLD_NET_RETRY_COUNT  10	///< Abort read after this many int.
+#endif
+#define TEMP_POOL_SIZE          128
+
+#define QUERY_ALLOC_BLOCK_SIZE		8192
+#define QUERY_ALLOC_PREALLOC_SIZE   	8192
+#define TRANS_ALLOC_BLOCK_SIZE		4096
+#define TRANS_ALLOC_PREALLOC_SIZE	4096
+#define RANGE_ALLOC_BLOCK_SIZE		4096
+#define ACL_ALLOC_BLOCK_SIZE		1024
+#define UDF_ALLOC_BLOCK_SIZE		1024
+#define TABLE_ALLOC_BLOCK_SIZE		1024
+#define BDB_LOG_ALLOC_BLOCK_SIZE	1024
+#define WARN_ALLOC_BLOCK_SIZE		2048
+#define WARN_ALLOC_PREALLOC_SIZE	1024
+#define PROFILE_ALLOC_BLOCK_SIZE  2048
+#define PROFILE_ALLOC_PREALLOC_SIZE 1024
+
+/*
+  The following parameters is to decide when to use an extra cache to
+  optimise seeks when reading a big table in sorted order
+*/
+#define MIN_FILE_LENGTH_TO_USE_ROW_CACHE (10L*1024*1024)
+#define MIN_ROWS_TO_USE_TABLE_CACHE	 100
+#define MIN_ROWS_TO_USE_BULK_INSERT	 100
+
+/**
+  The following is used to decide if MySQL should use table scanning
+  instead of reading with keys.  The number says how many evaluation of the
+  WHERE clause is comparable to reading one extra row from a table.
+*/
+#define TIME_FOR_COMPARE   5	// 5 compares == one read
+
+/**
+  Number of comparisons of table rowids equivalent to reading one row from a 
+  table.
+*/
+#define TIME_FOR_COMPARE_ROWID  (TIME_FOR_COMPARE*2)
+
+/*
+  For sequential disk seeks the cost formula is:
+    DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip  
+  
+  The cost of average seek 
+    DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST*BLOCKS_IN_AVG_SEEK =1.0.
+*/
+#define DISK_SEEK_BASE_COST ((double)0.5)
+
+#define BLOCKS_IN_AVG_SEEK  128
+
+#define DISK_SEEK_PROP_COST ((double)0.5/BLOCKS_IN_AVG_SEEK)
+
+
+/**
+  Number of rows in a reference table when refereed through a not unique key.
+  This value is only used when we don't know anything about the key
+  distribution.
+*/
+#define MATCHING_ROWS_IN_OTHER_TABLE 10
+
+#define RAID_BLOCK_SIZE 1024
+
+#define MY_CHARSET_BIN_MB_MAXLEN 1
+
+/** Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used). */
+#define KEY_DEFAULT_PACK_LENGTH 8
+
+/** Characters shown for the command in 'show processlist'. */
+#define PROCESS_LIST_WIDTH 100
+/* Characters shown for the command in 'information_schema.processlist' */
+#define PROCESS_LIST_INFO_WIDTH 65535
+
+#define PRECISION_FOR_DOUBLE 53
+#define PRECISION_FOR_FLOAT  24
+
+/* -[digits].E+## */
+#define MAX_FLOAT_STR_LENGTH (FLT_DIG + 6)
+/* -[digits].E+### */
+#define MAX_DOUBLE_STR_LENGTH (DBL_DIG + 7)
+
+/*
+  Default time to wait before aborting a new client connection
+  that does not respond to "initial server greeting" timely
+*/
+#define CONNECT_TIMEOUT		10
+
+/* The following can also be changed from the command line */
+#define DEFAULT_CONCURRENCY	10
+#define DELAYED_LIMIT		100		/**< pause after xxx inserts */
+#define DELAYED_QUEUE_SIZE	1000
+#define DELAYED_WAIT_TIMEOUT	5*60		/**< Wait for delayed insert */
+#define FLUSH_TIME		0		/**< Don't flush tables */
+#define MAX_CONNECT_ERRORS	10		///< errors before disabling host
+
+/**
+  Maximum length of time zone name that we support (Time zone name is
+  char(64) in db). mysqlbinlog needs it.
+*/
+#define MAX_TIME_ZONE_NAME_LENGTH       (NAME_LEN + 1)
+
+/*
+   This is included in the server and in the client.
+   Options for select set by the yacc parser (stored in lex->options).
+
+   XXX:
+   log_event.h defines OPTIONS_WRITTEN_TO_BIN_LOG to specify what THD
+   options list are written into binlog. These options can NOT change their
+   values, or it will break replication between version.
+
+   context is encoded as following:
+   SELECT - SELECT_LEX_NODE::options
+   THD    - THD::options
+   intern - neither. used only as
+            func(..., select_node->options | thd->options | OPTION_XXX, ...)
+
+   TODO: separate three contexts above, move them to separate bitfields.
+*/
+
+#define SELECT_DISTINCT         (ULL(1) << 0)     // SELECT, user
+#define SELECT_STRAIGHT_JOIN    (ULL(1) << 1)     // SELECT, user
+#define SELECT_DESCRIBE         (ULL(1) << 2)     // SELECT, user
+#define SELECT_SMALL_RESULT     (ULL(1) << 3)     // SELECT, user
+#define SELECT_BIG_RESULT       (ULL(1) << 4)     // SELECT, user
+#define OPTION_FOUND_ROWS       (ULL(1) << 5)     // SELECT, user
+#define OPTION_TO_QUERY_CACHE   (ULL(1) << 6)     // SELECT, user
+#define SELECT_NO_JOIN_CACHE    (ULL(1) << 7)     // intern
+#define OPTION_BIG_TABLES       (ULL(1) << 8)     // THD, user
+#define OPTION_BIG_SELECTS      (ULL(1) << 9)     // THD, user
+#define OPTION_LOG_OFF          (ULL(1) << 10)    // THD, user
+#define OPTION_QUOTE_SHOW_CREATE (ULL(1) << 11)   // THD, user, unused
+#define TMP_TABLE_ALL_COLUMNS   (ULL(1) << 12)    // SELECT, intern
+#define OPTION_WARNINGS         (ULL(1) << 13)    // THD, user
+#define OPTION_AUTO_IS_NULL     (ULL(1) << 14)    // THD, user, binlog
+#define OPTION_FOUND_COMMENT    (ULL(1) << 15)    // SELECT, intern, parser
+#define OPTION_SAFE_UPDATES     (ULL(1) << 16)    // THD, user
+#define OPTION_BUFFER_RESULT    (ULL(1) << 17)    // SELECT, user
+#define OPTION_BIN_LOG          (ULL(1) << 18)    // THD, user
+#define OPTION_NOT_AUTOCOMMIT   (ULL(1) << 19)    // THD, user
+#define OPTION_BEGIN            (ULL(1) << 20)    // THD, intern
+#define OPTION_TABLE_LOCK       (ULL(1) << 21)    // THD, intern
+#define OPTION_QUICK            (ULL(1) << 22)    // SELECT (for DELETE)
+#define OPTION_KEEP_LOG         (ULL(1) << 23)    // THD, user
+
+/* The following is used to detect a conflict with DISTINCT */
+#define SELECT_ALL              (ULL(1) << 24)    // SELECT, user, parser
+
+/** The following can be set when importing tables in a 'wrong order'
+   to suppress foreign key checks */
+#define OPTION_NO_FOREIGN_KEY_CHECKS    (ULL(1) << 26) // THD, user, binlog
+/** The following speeds up inserts to InnoDB tables by suppressing unique
+   key checks in some cases */
+#define OPTION_RELAXED_UNIQUE_CHECKS    (ULL(1) << 27) // THD, user, binlog
+#define SELECT_NO_UNLOCK                (ULL(1) << 28) // SELECT, intern
+#define OPTION_SCHEMA_TABLE             (ULL(1) << 29) // SELECT, intern
+/** Flag set if setup_tables already done */
+#define OPTION_SETUP_TABLES_DONE        (ULL(1) << 30) // intern
+/** If not set then the thread will ignore all warnings with level notes. */
+#define OPTION_SQL_NOTES                (ULL(1) << 31) // THD, user
+/**
+  Force the used temporary table to be a MyISAM table (because we will use
+  fulltext functions when reading from it.
+*/
+#define TMP_TABLE_FORCE_MYISAM          (ULL(1) << 32)
+#define OPTION_PROFILING                (ULL(1) << 33)
+
+#if defined(__WIN__)
+#undef	FLUSH_TIME
+#define FLUSH_TIME	1800			/**< Flush every half hour */
+
+#define INTERRUPT_PRIOR -2
+#define CONNECT_PRIOR	-1
+#define WAIT_PRIOR	0
+#define QUERY_PRIOR	2
+#else
+#define INTERRUPT_PRIOR 10
+#define CONNECT_PRIOR	9
+#define WAIT_PRIOR	8
+#define QUERY_PRIOR	6
+#endif /* __WIN92__ */
+
+#endif /* SQL_CONST_INCLUDED */

=== modified file 'sql/sql_crypt.cc'
--- a/sql/sql_crypt.cc	2009-04-23 07:43:42 +0000
+++ b/sql/sql_crypt.cc	2009-11-18 08:54:54 +0000
@@ -26,7 +26,9 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "sql_crypt.h"
+#include "password.h"
 
 SQL_CRYPT::SQL_CRYPT(const char *password, uint length)
 {

=== modified file 'sql/sql_crypt.h'
--- a/sql/sql_crypt.h	2009-09-23 21:32:31 +0000
+++ b/sql/sql_crypt.h	2009-11-18 08:54:54 +0000
@@ -21,6 +21,9 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
+#include "sql_list.h"                           /* Sql_alloc */
+#include "mysql_com.h"                          /* rand_struct */
+
 class SQL_CRYPT :public Sql_alloc
 {
   struct rand_struct rand,org_rand;

=== modified file 'sql/sql_cursor.cc'
--- a/sql/sql_cursor.cc	2009-11-06 15:28:25 +0000
+++ b/sql/sql_cursor.cc	2009-11-18 08:54:54 +0000
@@ -16,10 +16,12 @@
 #pragma implementation                         /* gcc class implementation */
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #include "sql_cursor.h"
 #include "sql_select.h"
 #include "probes_mysql.h"
+#include "sql_parse.h"                        // mysql_execute_command
 
 /****************************************************************************
   Declarations.

=== modified file 'sql/sql_cursor.h'
--- a/sql/sql_cursor.h	2007-10-16 20:11:50 +0000
+++ b/sql/sql_cursor.h	2009-11-18 08:54:54 +0000
@@ -20,6 +20,10 @@
 #pragma interface                              /* gcc class interface */
 #endif
 
+#include "sql_class.h"                          /* Query_arena */
+
+class JOIN;
+
 /**
   @file
 

=== modified file 'sql/sql_db.cc'
--- a/sql/sql_db.cc	2009-11-05 20:28:35 +0000
+++ b/sql/sql_db.cc	2009-11-18 08:54:54 +0000
@@ -16,7 +16,19 @@
 
 /* create and drop of databases */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_db.h"
+#include "sql_cache.h"                   // query_cache_*
+#include "lock.h"                        // wait_if_global_read_lock,
+                                         // start_waiting_global_read_lock
+#include "sql_table.h"                   // build_table_filename,
+                                         // filename_to_tablename
+#include "sql_rename.h"                  // mysql_rename_tables
+#include "sql_acl.h"                     // SELECT_ACL, DB_ACLS,
+                                         // acl_get, check_grant_db
+#include "sql_base.h"                    // wait_for_condition
+#include "log_event.h"                   // Query_log_event
 #include <mysys_err.h>
 #include "sp.h"
 #include "events.h"

=== added file 'sql/sql_db.h'
--- a/sql/sql_db.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_db.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,53 @@
+#ifndef SQL_DB_INCLUDED
+#define SQL_DB_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "hash.h"                               /* HASH */
+
+class THD;
+typedef struct charset_info_st CHARSET_INFO;
+typedef struct st_ha_create_information HA_CREATE_INFO;
+typedef struct st_mysql_lex_string LEX_STRING;
+
+int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent);
+bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create);
+bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent);
+bool mysql_upgrade_db(THD *thd, LEX_STRING *old_db);
+bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name,
+                     bool force_switch);
+
+bool mysql_opt_change_db(THD *thd,
+                         const LEX_STRING *new_db_name,
+                         LEX_STRING *saved_db_name,
+                         bool force_switch,
+                         bool *cur_db_changed);
+bool my_database_names_init(void);
+void my_database_names_free(void);
+bool check_db_dir_existence(const char *db_name);
+bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create);
+bool load_db_opt_by_name(THD *thd, const char *db_name,
+                         HA_CREATE_INFO *db_create_info);
+CHARSET_INFO *get_default_db_collation(THD *thd, const char *db_name);
+bool my_dbopt_init(void);
+void my_dbopt_cleanup(void);
+
+extern int creating_database; // How many database locks are made
+extern HASH lock_db_cache;
+
+#define MY_DB_OPT_FILE "db.opt"
+
+#endif /* SQL_DB_INCLUDED */

=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc	2009-11-05 20:28:35 +0000
+++ b/sql/sql_delete.cc	2009-11-18 08:54:54 +0000
@@ -19,10 +19,24 @@
   Multi-table deletes were introduced by Monty and Sinisa
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_delete.h"
+#include "sql_cache.h"                          // query_cache_*
+#include "sql_base.h"                           // open_temprary_table
+#include "sql_table.h"                         // build_table_filename
+#include "lock.h"                              // lock_and_wait_for_table_name,
+                                               // unlock_table_name
+#include "sql_view.h"             // check_key_in_view, mysql_frm_type
+#include "sql_parse.h"            // mysql_init_select
+#include "sql_acl.h"              // *_ACL
+#include "filesort.h"             // filesort
+#include "sql_handler.h"          // mysql_ha_rm_tables
 #include "sql_select.h"
 #include "sp_head.h"
 #include "sql_trigger.h"
+#include "records.h"                            // init_read_record,
+                                                // end_read_record
 
 /**
   Implement DELETE SQL word.

=== added file 'sql/sql_delete.h'
--- a/sql/sql_delete.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_delete.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,34 @@
+#ifndef SQL_DELETE_INCLUDED
+#define SQL_DELETE_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "my_base.h"                            /* ha_rows */
+
+class THD;
+class TABLE_LIST;
+class Item;
+
+typedef class Item COND;
+typedef struct st_sql_list SQL_LIST;
+
+int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds);
+bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
+                  SQL_LIST *order, ha_rows rows, ulonglong options,
+                  bool reset_auto_increment);
+bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok);
+
+#endif /* SQL_DELETE_INCLUDED */

=== modified file 'sql/sql_derived.cc'
--- a/sql/sql_derived.cc	2009-09-10 09:18:29 +0000
+++ b/sql/sql_derived.cc	2009-11-18 08:54:54 +0000
@@ -20,9 +20,12 @@
 */
 
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_derived.h"
 #include "sql_select.h"
-
+#include "sql_view.h"                         // check_duplicate_names
+#include "sql_acl.h"                          // SELECT_ACL
 
 
 /*

=== added file 'sql/sql_derived.h'
--- a/sql/sql_derived.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_derived.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,29 @@
+#ifndef SQL_DERIVED_INCLUDED
+#define SQL_DERIVED_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+class TABLE_LIST;
+class THD;
+struct LEX;
+
+bool mysql_handle_derived(LEX *lex, bool (*processor)(THD *thd,
+                                                      LEX *lex,
+                                                      TABLE_LIST *table));
+bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *t);
+bool mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *t);
+
+#endif /* SQL_DERIVED_INCLUDED */

=== modified file 'sql/sql_do.cc'
--- a/sql/sql_do.cc	2008-02-19 12:45:21 +0000
+++ b/sql/sql_do.cc	2009-11-18 08:54:54 +0000
@@ -16,7 +16,11 @@
 
 /* Execute DO statement */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_do.h"
+#include "sql_base.h"                           // setup_fields
+#include "sql_select.h"                         // free_underlaid_joins
 
 bool mysql_do(THD *thd, List<Item> &values)
 {

=== added file 'sql/sql_do.h'
--- a/sql/sql_do.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_do.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,26 @@
+#ifndef SQL_DO_INCLUDED
+#define SQL_DO_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "sql_list.h"                           /* List */
+
+class THD;
+class Item;
+
+bool mysql_do(THD *thd, List<Item> &values);
+
+#endif /* SQL_DO_INCLUDED */

=== modified file 'sql/sql_error.cc'
--- a/sql/sql_error.cc	2009-10-23 11:22:21 +0000
+++ b/sql/sql_error.cc	2009-11-18 08:54:54 +0000
@@ -42,7 +42,8 @@ This file contains the implementation of
 
 ***********************************************************************/
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #include "sql_error.h"
 #include "sp_rcontext.h"
 

=== modified file 'sql/sql_error.h'
--- a/sql/sql_error.h	2009-10-15 12:23:43 +0000
+++ b/sql/sql_error.h	2009-11-18 08:54:54 +0000
@@ -19,6 +19,7 @@
 
 #include "sql_list.h" /* Sql_alloc, MEM_ROOT */
 #include "m_string.h" /* LEX_STRING */
+#include "sql_string.h"                        /* String */
 #include "mysql_com.h" /* MYSQL_ERRMSG_SIZE */
 
 class THD;

=== modified file 'sql/sql_handler.cc'
--- a/sql/sql_handler.cc	2009-11-02 11:10:04 +0000
+++ b/sql/sql_handler.cc	2009-11-18 08:54:54 +0000
@@ -56,7 +56,13 @@
   second container. When the table is flushed, the pointer is cleared.
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "sql_handler.h"
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "sql_base.h"                           // close_thread_tables
+#include "lock.h"            // broadcast_refresh, mysql_unlock_tables
+#include "key.h"                                // key_copy
+#include "sql_base.h"                           // insert_fields
 #include "sql_select.h"
 #include <assert.h>
 

=== added file 'sql/sql_handler.h'
--- a/sql/sql_handler.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_handler.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,34 @@
+#ifndef SQL_HANDLER_INCLUDED
+#define SQL_HANDLER_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "sql_class.h"                 /* enum_ha_read_mode */
+#include "my_base.h"                   /* ha_rkey_function, ha_rows */
+#include "sql_list.h"                  /* List */
+
+class THD;
+class TABLE_LIST;
+
+bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen);
+bool mysql_ha_close(THD *thd, TABLE_LIST *tables);
+bool mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *,
+                   List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
+void mysql_ha_flush(THD *thd);
+void mysql_ha_rm_tables(THD *thd, TABLE_LIST *tables, bool is_locked);
+void mysql_ha_cleanup(THD *thd);
+
+#endif /* SQL_HANDLER_INCLUDED */

=== modified file 'sql/sql_help.cc'
--- a/sql/sql_help.cc	2009-10-21 20:02:06 +0000
+++ b/sql/sql_help.cc	2009-11-18 08:54:54 +0000
@@ -13,7 +13,13 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_help.h"
+#include "sql_table.h"                          // primary_key_name
+#include "sql_base.h"               // REPORT_ALL_ERRORS, setup_tables
+#include "opt_range.h"              // SQL_SELECT
+#include "records.h"          // init_read_record, end_read_record
 
 struct st_find_field
 {

=== added file 'sql/sql_help.h'
--- a/sql/sql_help.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_help.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,28 @@
+#ifndef SQL_HELP_INCLUDED
+#define SQL_HELP_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+class THD;
+
+
+/*
+  Function prototypes
+*/
+
+bool mysqld_help (THD *thd, const char *text);
+
+#endif /* SQL_HELP_INCLUDED */

=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc	2009-11-05 20:28:35 +0000
+++ b/sql/sql_insert.cc	2009-11-18 08:54:54 +0000
@@ -54,12 +54,23 @@
 
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "sql_insert.h"
+#include "sql_update.h"                         // compare_record
+#include "sql_base.h"                           // close_thread_tables
+#include "sql_cache.h"                          // query_cache_*
+#include "key.h"                                // key_copy
+#include "lock.h"                               // mysql_unlock_tables
 #include "sp_head.h"
+#include "sql_view.h"         // check_key_in_view, insert_view_fields
+#include "sql_table.h"        // mysql_create_table_no_lock
+#include "sql_acl.h"          // *_ACL, check_grant_all_columns
 #include "sql_trigger.h"
 #include "sql_select.h"
 #include "sql_show.h"
 #include "slave.h"
+#include "sql_parse.h"                          // end_active_trans
 #include "rpl_mi.h"
 
 #ifndef EMBEDDED_LIBRARY

=== added file 'sql/sql_insert.h'
--- a/sql/sql_insert.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_insert.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,49 @@
+#ifndef SQL_INSERT_INCLUDED
+#define SQL_INSERT_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "sql_class.h"                          /* enum_duplicates */
+#include "sql_list.h"
+
+/* Instead of including sql_lex.h we add this typedef here */
+typedef List<Item> List_item;
+typedef struct st_copy_info COPY_INFO;
+
+bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table,
+                          List<Item> &fields, List_item *values,
+                          List<Item> &update_fields,
+                          List<Item> &update_values, enum_duplicates duplic,
+                          COND **where, bool select_insert,
+                          bool check_fields, bool abort_on_warning);
+bool mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields,
+                  List<List_item> &values, List<Item> &update_fields,
+                  List<Item> &update_values, enum_duplicates flag,
+                  bool ignore);
+void upgrade_lock_type_for_insert(THD *thd, thr_lock_type *lock_type,
+                                  enum_duplicates duplic,
+                                  bool is_multi_insert);
+int check_that_all_fields_are_given_values(THD *thd, TABLE *entry,
+                                           TABLE_LIST *table_list);
+void prepare_triggers_for_insert_stmt(TABLE *table);
+int write_record(THD *thd, TABLE *table, COPY_INFO *info);
+void kill_delayed_threads(void);
+
+#ifdef EMBEDDED_LIBRARY
+inline void kill_delayed_threads(void) {}
+#endif
+
+#endif /* SQL_INSERT_INCLUDED */

=== modified file 'sql/sql_lex.cc'
--- a/sql/sql_lex.cc	2009-11-03 11:37:02 +0000
+++ b/sql/sql_lex.cc	2009-11-18 08:54:54 +0000
@@ -17,7 +17,11 @@
 /* A lexical scanner on a temporary buffer with a yacc interface */
 
 #define MYSQL_LEX 1
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "sql_class.h"                          // sql_lex.h: SQLCOM_END
+#include "sql_lex.h"
+#include "sql_parse.h"                          // add_to_list
 #include "item_create.h"
 #include <m_ctype.h>
 #include <hash.h>

=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h	2009-11-03 11:37:02 +0000
+++ b/sql/sql_lex.h	2009-11-18 08:54:54 +0000
@@ -20,6 +20,11 @@
 #ifndef SQL_LEX_INCLUDED
 #define SQL_LEX_INCLUDED
 
+#include "violite.h"                            /* SSL_type */
+#include "sql_trigger.h"
+#include "set_var.h" /* From item_subselect.h: subselect_union_engine */
+#include "thr_lock.h"                  /* thr_lock_type, TL_UNLOCK */
+
 /* YACC and LEX Definitions */
 
 /* These may not be declared yet */
@@ -33,6 +38,12 @@ class sp_pcontext;
 class st_alter_tablespace;
 class partition_info;
 class Event_parse_data;
+class Item_func_match;
+class Alter_drop;
+class Alter_column;
+class Key;
+class File_parser;
+class Key_part_spec;
 
 #ifdef MYSQL_SERVER
 /*
@@ -47,6 +58,7 @@ class Event_parse_data;
 #else
 #include "lex_symbol.h"
 #if MYSQL_LEX
+#include "item_func.h"            /* Cast_target used in sql_yacc.h */
 #include "sql_yacc.h"
 #define LEX_YYSTYPE YYSTYPE *
 #else
@@ -184,6 +196,12 @@ enum enum_drop_mode
   DROP_RESTRICT // RESTRICT option
 };
 
+/* Options to add_table_to_list() */
+#define TL_OPTION_UPDATING	1
+#define TL_OPTION_FORCE_INDEX	2
+#define TL_OPTION_IGNORE_LEAVES 4
+#define TL_OPTION_ALIAS         8
+
 typedef List<Item> List_item;
 
 /* SERVERS CACHE CHANGES */
@@ -2078,6 +2096,7 @@ extern bool is_lex_native_function(const
 */
 
 void my_missing_function_error(const LEX_STRING &token, const char *name);
+bool is_keyword(const char *name, uint len);
 
 #endif /* MYSQL_SERVER */
 #endif /* SQL_LEX_INCLUDED */

=== modified file 'sql/sql_list.cc'
--- a/sql/sql_list.cc	2009-10-21 20:02:06 +0000
+++ b/sql/sql_list.cc	2009-11-18 08:54:54 +0000
@@ -18,6 +18,7 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
+#include "unireg.h"
 #include "sql_list.h"
 
 list_node end_of_list;

=== modified file 'sql/sql_list.h'
--- a/sql/sql_list.h	2009-10-22 19:31:06 +0000
+++ b/sql/sql_list.h	2009-11-18 08:54:54 +0000
@@ -26,6 +26,11 @@
 
 void *sql_alloc(size_t);
 
+#include "my_sys.h"                    /* alloc_root, TRASH, MY_WME,
+                                          MY_FAE, MY_ALLOW_ZERO_PTR */
+#include "m_string.h"                           /* bfill */
+#include "thr_malloc.h"                         /* sql_alloc */
+
 /* mysql standard class memory allocator */
 
 class Sql_alloc
@@ -61,6 +66,57 @@ public:
 };
 
 
+/**
+   Struct to handle simple linked lists.
+
+   @todo What is the relation between this class and list_node, below?
+   /Matz
+
+   @see list_node, base_list, List
+
+*/
+typedef struct st_sql_list {
+  uint elements;
+  uchar *first;
+  uchar **next;
+
+  st_sql_list() {}                              /* Remove gcc warning */
+  inline void empty()
+  {
+    elements=0;
+    first=0;
+    next= &first;
+  }
+  inline void link_in_list(uchar *element,uchar **next_ptr)
+  {
+    elements++;
+    (*next)=element;
+    next= next_ptr;
+    *next=0;
+  }
+  inline void save_and_clear(struct st_sql_list *save)
+  {
+    *save= *this;
+    empty();
+  }
+  inline void push_front(struct st_sql_list *save)
+  {
+    *save->next= first;				/* link current list last */
+    first= save->first;
+    elements+= save->elements;
+  }
+  inline void push_back(struct st_sql_list *save)
+  {
+    if (save->first)
+    {
+      *next= save->first;
+      next= save->next;
+      elements+= save->elements;
+    }
+  }
+} SQL_LIST;
+
+
 /*
   Basic single linked list
   Used for item and item_buffs.
@@ -613,4 +669,7 @@ list_copy_and_replace_each_value(List<T>
     it.replace(el->clone(mem_root));
 }
 
+void free_list(I_List <i_string_pair> *list);
+void free_list(I_List <i_string> *list);
+
 #endif // INCLUDES_MYSQL_SQL_LIST_H

=== modified file 'sql/sql_load.cc'
--- a/sql/sql_load.cc	2009-11-06 14:20:27 +0000
+++ b/sql/sql_load.cc	2009-11-18 08:54:54 +0000
@@ -17,8 +17,21 @@
 /* Copy data from a textfile to table */
 /* 2006-12 Erik Wetterberg : LOAD XML added */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_load.h"
+#include "sql_load.h"
+#include "sql_cache.h"                          // query_cache_*
+#include "sql_base.h"          // fill_record_n_invoke_before_triggers
 #include <my_dir.h>
+#include "sql_view.h"                           // check_key_in_view
+#include "sql_insert.h" // check_that_all_fields_are_given_values,
+                        // prepare_triggers_for_insert_stmt,
+                        // write_record
+#include "sql_acl.h"    // INSERT_ACL, UPDATE_ACL
+#include "log_event.h"  // Delete_file_log_event,
+                        // Execute_load_query_log_event,
+                        // LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F
 #include <m_ctype.h>
 #include "rpl_mi.h"
 #include "sql_repl.h"

=== added file 'sql/sql_load.h'
--- a/sql/sql_load.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_load.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,34 @@
+#ifndef SQL_LOAD_INCLUDED
+#define SQL_LOAD_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "sql_list.h"                           /* List */
+
+class Item;
+
+#include "sql_class.h"                          /* enum_duplicates */
+
+class sql_exchange;
+
+int mysql_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list,
+	        List<Item> &fields_vars, List<Item> &set_fields,
+                List<Item> &set_values_list,
+                enum enum_duplicates handle_duplicates, bool ignore,
+                bool local_file);
+
+
+#endif /* SQL_LOAD_INCLUDED */

=== modified file 'sql/sql_locale.cc'
--- a/sql/sql_locale.cc	2009-11-06 09:52:45 +0000
+++ b/sql/sql_locale.cc	2009-11-18 08:54:54 +0000
@@ -20,7 +20,11 @@
   !! This file is built from my_locale.pl !!
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_locale.h"
+#include "sql_class.h"                          // THD
+#include "my_sys.h"                             // MY_*, NullS, NULL
 
 
 enum err_msgs_index

=== added file 'sql/sql_locale.h'
--- a/sql/sql_locale.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_locale.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,79 @@
+#ifndef SQL_LOCALE_INCLUDED
+#define SQL_LOCALE_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+typedef struct my_locale_errmsgs
+{
+  const char *language;
+  const char **errmsgs;
+} MY_LOCALE_ERRMSGS;
+
+#include "my_global.h"                          /* uint */
+
+typedef struct st_typelib TYPELIB;
+
+typedef struct my_locale_st
+{
+  uint  number;
+  const char *name;
+  const char *description;
+  const bool is_ascii;
+  TYPELIB *month_names;
+  TYPELIB *ab_month_names;
+  TYPELIB *day_names;
+  TYPELIB *ab_day_names;
+  uint max_month_name_length;
+  uint max_day_name_length;
+  uint decimal_point;
+  uint thousand_sep;
+  const char *grouping;
+  MY_LOCALE_ERRMSGS *errmsgs;
+#ifdef __cplusplus
+  my_locale_st(uint number_par,
+               const char *name_par, const char *descr_par, bool is_ascii_par,
+               TYPELIB *month_names_par, TYPELIB *ab_month_names_par,
+               TYPELIB *day_names_par, TYPELIB *ab_day_names_par,
+               uint max_month_name_length_par, uint max_day_name_length_par,
+               uint decimal_point_par, uint thousand_sep_par,
+               const char *grouping_par, MY_LOCALE_ERRMSGS *errmsgs_par) :
+    number(number_par),
+    name(name_par), description(descr_par), is_ascii(is_ascii_par),
+    month_names(month_names_par), ab_month_names(ab_month_names_par),
+    day_names(day_names_par), ab_day_names(ab_day_names_par),
+    max_month_name_length(max_month_name_length_par),
+    max_day_name_length(max_day_name_length_par),
+    decimal_point(decimal_point_par),
+    thousand_sep(thousand_sep_par),
+    grouping(grouping_par),
+    errmsgs(errmsgs_par)
+  {}
+#endif
+} MY_LOCALE;
+/* Exported variables */
+
+extern MY_LOCALE my_locale_en_US;
+extern MY_LOCALE *my_locales[];
+extern MY_LOCALE *my_default_lc_messages;
+extern MY_LOCALE *my_default_lc_time_names;
+
+/* Exported functions */
+
+MY_LOCALE *my_locale_by_name(const char *name);
+MY_LOCALE *my_locale_by_number(uint number);
+void cleanup_errmsgs(void);
+
+#endif /* SQL_LOCALE_INCLUDED */

=== modified file 'sql/sql_manager.cc'
--- a/sql/sql_manager.cc	2008-12-04 18:41:53 +0000
+++ b/sql/sql_manager.cc	2009-11-18 08:54:54 +0000
@@ -21,8 +21,10 @@
  *   o Berkeley DB: removing unneeded log files.
  */
 
-#include "mysql_priv.h"
-
+#include "sql_priv.h"
+#include "sql_manager.h"
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "sql_base.h"                           // flush_tables
 
 static bool volatile manager_thread_in_use;
 static bool abort_manager;

=== added file 'sql/sql_manager.h'
--- a/sql/sql_manager.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_manager.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,23 @@
+#ifndef SQL_MANAGER_INCLUDED
+#define SQL_MANAGER_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+void start_handle_manager();
+void stop_handle_manager();
+bool mysql_manager_submit(void (*action)());
+
+#endif /* SQL_MANAGER_INCLUDED */

=== modified file 'sql/sql_map.cc'
--- a/sql/sql_map.cc	2007-10-23 09:29:20 +0000
+++ b/sql/sql_map.cc	2009-11-18 08:54:54 +0000
@@ -18,7 +18,11 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "sql_map.h"                            // mapped_files
+#include "sql_class.h"                          // THD
+
 #include <sys/stat.h>
 #ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>

=== modified file 'sql/sql_map.h'
--- a/sql/sql_map.h	2009-09-23 21:32:31 +0000
+++ b/sql/sql_map.h	2009-11-18 08:54:54 +0000
@@ -23,6 +23,9 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
+#include "my_base.h"                            /* ha_rows */
+#include "sql_list.h"                           /* ilink */
+
 class mapped_files;
 mapped_files *map_file(const char * name,uchar *magic,uint magic_length);
 void unmap_file(mapped_files *map);

=== modified file 'sql/sql_olap.cc'
--- a/sql/sql_olap.cc	2007-05-10 09:59:39 +0000
+++ b/sql/sql_olap.cc	2009-11-18 08:54:54 +0000
@@ -31,7 +31,8 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #include "sql_select.h"
 
 

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2009-11-06 15:28:25 +0000
+++ b/sql/sql_parse.cc	2009-11-18 08:54:54 +0000
@@ -14,7 +14,67 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 #define MYSQL_LEX 1
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "sql_parse.h"        // sql_kill, *_precheck, *_prepare
+#include "lock.h"             // wait_if_global_read_lock,
+                              // unlock_global_read_lock,
+                              // try_transactional_lock,
+                              // check_transactional_lock,
+                              // set_handler_table_locks,
+                              // start_waiting_global_read_lock,
+                              // lock_global_read_lock,
+                              // make_global_read_lock_block_commit
+#include "sql_base.h"         // find_temporary_tablesx
+#include "sql_cache.h"        // QUERY_CACHE_FLAGS_SIZE, query_cache_*
+#include "sql_show.h"         // mysqld_list_*, mysqld_show_*,
+                              // calc_sum_of_all_status
+#include "mysqld.h"
+#include "sql_locale.h"                         // my_locale_en_US
+#include "log.h"                                // flush_error_log
+#include "sql_view.h"         // mysql_create_view, mysql_drop_view
+#include "sql_delete.h"       // mysql_truncate, mysql_delete
+#include "sql_insert.h"       // mysql_insert
+#include "sql_update.h"       // mysql_update, mysql_multi_update
+#include "sql_partition.h"    // struct partition_info
+#include "sql_db.h"           // mysql_change_db, mysql_create_db,
+                              // mysql_rm_db, mysql_upgrade_db,
+                              // mysql_alter_db,
+                              // check_db_dir_existence,
+                              // my_dbopt_cleanup
+#include "sql_table.h"        // mysql_create_like_table,
+                              // mysql_create_table,
+                              // mysql_alter_table,
+                              // mysql_recreate_table,
+                              // mysql_backup_table,
+                              // mysql_restore_table
+#include "sql_connect.h"      // check_user,
+                              // decrease_user_connections,
+                              // thd_init_client_charset, check_mqh,
+                              // reset_mqh
+#include "sql_rename.h"       // mysql_rename_table
+#include "sql_tablespace.h"   // mysql_alter_tablespace
+#include "hostname.h"         // hostname_cache_refresh
+#include "sql_acl.h"          // *_ACL, check_grant, is_acl_user,
+                              // has_any_table_level_privileges,
+                              // mysql_drop_user, mysql_rename_user,
+                              // check_grant_routine,
+                              // mysql_routine_grant,
+                              // mysql_show_grants,
+                              // sp_grant_privileges, ...
+#include "sql_test.h"         // mysql_print_status
+#include "sql_select.h"       // handle_select, mysql_select,
+                              // mysql_explain_union
+#include "sql_load.h"         // mysql_load
+#include "sql_servers.h"      // create_servers, alter_servers,
+                              // drop_servers, servers_reload
+#include "sql_handler.h"      // mysql_ha_open, mysql_ha_close,
+                              // mysql_ha_read
+#include "sql_binlog.h"       // mysql_client_binlog_statement
+#include "sql_do.h"           // mysql_do
+#include "sql_help.h"         // mysqld_help
+#include "rpl_constants.h"    // Incident, INCIDENT_LOST_EVENTS
+#include "log_event.h"
 #include "sql_repl.h"
 #include "rpl_filter.h"
 #include "repl_failsafe.h"

=== added file 'sql/sql_parse.h'
--- a/sql/sql_parse.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_parse.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,205 @@
+#ifndef SQL_PARSE_INCLUDED
+#define SQL_PARSE_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "sql_acl.h"                            /* GLOBAL_ACLS */
+
+class Comp_creator;
+class Item;
+class Object_creation_ctx;
+class Parser_state;
+class TABLE_LIST;
+class THD;
+class Table_ident;
+struct LEX;
+
+enum enum_mysql_completiontype {
+  ROLLBACK_RELEASE=-2, ROLLBACK=1,  ROLLBACK_AND_CHAIN=7,
+  COMMIT_RELEASE=-1,   COMMIT=0,    COMMIT_AND_CHAIN=6
+};
+
+extern "C" int test_if_data_home_dir(const char *dir);
+
+bool multi_update_precheck(THD *thd, TABLE_LIST *tables);
+bool multi_delete_precheck(THD *thd, TABLE_LIST *tables);
+int mysql_multi_update_prepare(THD *thd);
+int mysql_multi_delete_prepare(THD *thd);
+bool mysql_insert_select_prepare(THD *thd);
+bool update_precheck(THD *thd, TABLE_LIST *tables);
+bool delete_precheck(THD *thd, TABLE_LIST *tables);
+bool insert_precheck(THD *thd, TABLE_LIST *tables);
+bool create_table_precheck(THD *thd, TABLE_LIST *tables,
+                           TABLE_LIST *create_table);
+
+bool parse_sql(THD *thd,
+               Parser_state *parser_state,
+               Object_creation_ctx *creation_ctx);
+
+uint kill_one_thread(THD *thd, ulong id, bool only_kill_query);
+void sql_kill(THD *thd, ulong id, bool only_kill_query);
+
+void free_items(Item *item);
+void cleanup_items(Item *item);
+
+Comp_creator *comp_eq_creator(bool invert);
+Comp_creator *comp_ge_creator(bool invert);
+Comp_creator *comp_gt_creator(bool invert);
+Comp_creator *comp_le_creator(bool invert);
+Comp_creator *comp_lt_creator(bool invert);
+Comp_creator *comp_ne_creator(bool invert);
+
+int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
+                         enum enum_schema_tables schema_table_idx);
+void get_default_definer(THD *thd, LEX_USER *definer);
+LEX_USER *create_default_definer(THD *thd);
+LEX_USER *create_definer(THD *thd, LEX_STRING *user_name, LEX_STRING *host_name);
+LEX_USER *get_current_user(THD *thd, LEX_USER *user);
+bool check_string_byte_length(LEX_STRING *str, const char *err_msg,
+                              uint max_byte_length);
+bool check_string_char_length(LEX_STRING *str, const char *err_msg,
+                              uint max_char_length, CHARSET_INFO *cs,
+                              bool no_error);
+bool check_host_name(LEX_STRING *str);
+bool check_identifier_name(LEX_STRING *str, uint max_char_length,
+                           uint err_code, const char *param_for_err_msg);
+bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
+bool is_update_query(enum enum_sql_command command);
+bool is_log_table_write_query(enum enum_sql_command command);
+bool alloc_query(THD *thd, const char *packet, uint packet_length);
+void mysql_init_select(LEX *lex);
+void mysql_parse(THD *thd, const char *inBuf, uint length,
+                 const char ** semicolon);
+void mysql_reset_thd_for_next_command(THD *thd);
+bool mysql_new_select(LEX *lex, bool move_down);
+void create_select_for_variable(const char *var_name);
+void mysql_init_multi_delete(LEX *lex);
+bool multi_delete_set_locks_and_link_aux_tables(LEX *lex);
+void create_table_set_open_action_and_adjust_tables(LEX *lex);
+pthread_handler_t handle_bootstrap(void *arg);
+bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables,
+                          bool *write_to_binlog);
+int mysql_execute_command(THD *thd);
+bool do_command(THD *thd);
+bool dispatch_command(enum enum_server_command command, THD *thd,
+		      char* packet, uint packet_length);
+void log_slow_statement(THD *thd);
+bool append_file_to_dir(THD *thd, const char **filename_ptr,
+                        const char *table_name);
+bool append_file_to_dir(THD *thd, const char **filename_ptr,
+                        const char *table_name);
+void execute_init_command(THD *thd, sys_var_str *init_command_var,
+			  rw_lock_t *var_mutex);
+bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum enum_field_types type,
+		       char *length, char *decimal,
+		       uint type_modifier,
+		       Item *default_value, Item *on_update_value,
+		       LEX_STRING *comment,
+		       char *change, List<String> *interval_list,
+		       CHARSET_INFO *cs,
+		       uint uint_geom_type);
+bool add_to_list(THD *thd, SQL_LIST &list,Item *group,bool asc);
+void add_join_on(TABLE_LIST *b,Item *expr);
+void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields,
+                      SELECT_LEX *lex);
+bool add_proc_to_list(THD *thd, Item *item);
+bool push_new_name_resolution_context(THD *thd,
+                                      TABLE_LIST *left_op,
+                                      TABLE_LIST *right_op);
+void store_position_for_column(const char *name);
+void init_update_queries(void);
+bool check_simple_select();
+Item *negate_expression(THD *thd, Item *expr);
+bool check_stack_overrun(THD *thd, long margin, uchar *dummy);
+
+bool begin_trans(THD *thd);
+bool end_active_trans(THD *thd);
+int end_trans(THD *thd, enum enum_mysql_completiontype completion);
+
+
+/* Variables */
+
+extern const char* any_db;
+extern uint sql_command_flags[];
+extern uint server_command_flags[];
+extern const LEX_STRING command_name[];
+
+/* Inline functions */
+inline bool check_identifier_name(LEX_STRING *str, uint err_code)
+{
+  return check_identifier_name(str, NAME_CHAR_LEN, err_code, "");
+}
+
+inline bool check_identifier_name(LEX_STRING *str)
+{
+  return check_identifier_name(str, NAME_CHAR_LEN, 0, "");
+}
+
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables);
+bool check_single_table_access(THD *thd, ulong privilege,
+			   TABLE_LIST *tables, bool no_errors);
+bool check_routine_access(THD *thd,ulong want_access,char *db,char *name,
+			  bool is_proc, bool no_errors);
+bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table);
+bool check_some_routine_access(THD *thd, const char *db, const char *name, bool is_proc);
+bool check_access(THD *thd, ulong access, const char *db, ulong *save_priv,
+		  bool no_grant, bool no_errors, bool schema_db);
+bool check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables,
+                        bool any_combination_of_privileges_will_do,
+                        uint number,
+                        bool no_errors);
+#else
+inline bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables)
+{ return false; }
+inline bool check_single_table_access(THD *thd, ulong privilege,
+			   TABLE_LIST *tables, bool no_errors)
+{ return false; }
+inline bool check_routine_access(THD *thd,ulong want_access,char *db,
+                                 char *name, bool is_proc, bool no_errors)
+{ return false; }
+inline bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table)
+{ return false; }
+inline bool check_merge_table_access(THD *thd, char *db, TABLE_LIST *table_list)
+{ return false; }
+inline bool check_some_routine_access(THD *thd, const char *db,
+                                      const char *name, bool is_proc)
+{ return false; }
+inline bool check_access(THD *thd, ulong access, const char *db,
+                         ulong *save_priv, bool no_grant, bool no_errors,
+                         bool schema_db)
+{
+  if (save_priv)
+    *save_priv= GLOBAL_ACLS;
+  return false;
+}
+inline bool
+check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables,
+                   bool no_errors,
+                   bool any_combination_of_privileges_will_do,
+                   uint number)
+{ return false; }
+#endif /*NO_EMBEDDED_ACCESS_CHECKS*/
+
+#ifdef EMBEDDED_LIBRARY
+#define check_stack_overrun(A, B, C) 0
+#endif /* EMBEDDED_LIBRARY */
+
+/* These were under the INNODB_COMPATIBILITY_HOOKS */
+
+bool check_global_access(THD *thd, ulong want_access);
+
+#endif /* SQL_PARSE_INCLUDED */

=== modified file 'sql/sql_partition.cc'
--- a/sql/sql_partition.cc	2009-11-05 20:28:35 +0000
+++ b/sql/sql_partition.cc	2009-11-18 08:54:54 +0000
@@ -46,11 +46,25 @@
 /* Some general useful functions */
 
 #define MYSQL_LEX 1
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "sql_partition.h"
+#include "key.h"                            // key_restore
+#include "sql_parse.h"                      // parse_sql
+#include "sql_cache.h"                      // query_cache_invalidate3
+#include "lock.h"                           // mysql_lock_remove
+#include "sql_show.h"                       // append_identifier
 #include <errno.h>
 #include <m_ctype.h>
 #include "my_md5.h"
 
+#include "sql_base.h"                           // close_thread_tables
+#include "sql_table.h"                  // build_table_filename,
+                                        // build_table_shadow_filename,
+                                        // table_to_filename
+#include "opt_range.h"                  // store_key_image_to_rec
+#include "sql_analyse.h"                // append_escaped
+
 #ifdef WITH_PARTITION_STORAGE_ENGINE
 #include "ha_partition.h"
 

=== modified file 'sql/sql_partition.h'
--- a/sql/sql_partition.h	2009-11-02 13:49:26 +0000
+++ b/sql/sql_partition.h	2009-11-18 08:54:54 +0000
@@ -20,12 +20,50 @@
 #pragma interface				/* gcc class implementation */
 #endif
 
+#include "sql_list.h"                           /* List */
+
+class Alter_info;
+class Field;
+class String;
+class handler;
+class partition_info;
+struct TABLE;
+struct TABLE_LIST;
+typedef struct st_bitmap MY_BITMAP;
+typedef struct st_ha_create_information HA_CREATE_INFO;
+typedef struct st_key KEY;
+typedef struct st_key_range key_range;
+
 /* Flags for partition handlers */
 #define HA_CAN_PARTITION       (1 << 0) /* Partition support */
 #define HA_CAN_UPDATE_PARTITION_KEY (1 << 1)
 #define HA_CAN_PARTITION_UNIQUE (1 << 2)
 #define HA_USE_AUTO_PARTITION (1 << 3)
 
+#define NORMAL_PART_NAME 0
+#define TEMP_PART_NAME 1
+#define RENAMED_PART_NAME 2
+
+typedef struct st_lock_param_type
+{
+  TABLE_LIST table_list;
+  ulonglong copied;
+  ulonglong deleted;
+  THD *thd;
+  HA_CREATE_INFO *create_info;
+  Alter_info *alter_info;
+  TABLE *table;
+  KEY *key_info_buffer;
+  const char *db;
+  const char *table_name;
+  uchar *pack_frm_data;
+  enum thr_lock_type old_lock_type;
+  uint key_count;
+  uint db_options;
+  size_t pack_frm_len;
+  partition_info *part_info;
+} ALTER_PARTITION_PARAM_TYPE;
+
 /*typedef struct {
   ulonglong data_file_length;
   ulonglong max_data_file_length;
@@ -104,6 +142,7 @@ bool fix_fields_part_func(THD *thd, Item
 bool check_part_func_fields(Field **ptr, bool ok_with_charsets);
 bool field_is_partition_charset(Field *field);
 Item* convert_charset_partition_constant(Item *item, CHARSET_INFO *cs);
+void mem_alloc_error(size_t size);
 
 /*
   A "Get next" function for partition iterator.
@@ -223,4 +262,39 @@ typedef int (*get_partitions_in_range_it
 
 #include "partition_info.h"
 
+#ifdef WITH_PARTITION_STORAGE_ENGINE
+uint fast_alter_partition_table(THD *thd, TABLE *table,
+                                Alter_info *alter_info,
+                                HA_CREATE_INFO *create_info,
+                                TABLE_LIST *table_list,
+                                char *db,
+                                const char *table_name,
+                                uint fast_alter_partition);
+uint set_part_state(Alter_info *alter_info, partition_info *tab_part_info,
+                    enum partition_state part_state);
+uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
+                           HA_CREATE_INFO *create_info,
+                           handlerton *old_db_type,
+                           bool *partition_changed,
+                           uint *fast_alter_partition);
+char *generate_partition_syntax(partition_info *part_info,
+                                uint *buf_length, bool use_sql_alloc,
+                                bool show_partition_options,
+                                HA_CREATE_INFO *create_info,
+                                Alter_info *alter_info);
+#endif
+
+void create_partition_name(char *out, const char *in1,
+                           const char *in2, uint name_variant,
+                           bool translate);
+void create_subpartition_name(char *out, const char *in1,
+                              const char *in2, const char *in3,
+                              uint name_variant);
+
+void set_field_ptr(Field **ptr, const uchar *new_buf, const uchar *old_buf);
+void set_key_field_ptr(KEY *key_info, const uchar *new_buf,
+                       const uchar *old_buf);
+
+extern const LEX_STRING partition_keywords[];
+
 #endif /* SQL_PARTITION_INCLUDED */

=== modified file 'sql/sql_plugin.cc'
--- a/sql/sql_plugin.cc	2009-11-10 07:31:33 +0000
+++ b/sql/sql_plugin.cc	2009-11-18 08:54:54 +0000
@@ -13,7 +13,18 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "my_global.h"                       // REQUIRED by m_string.h
+#include "sql_locale.h"
+#include "sql_plugin.h"
+#include "sql_parse.h"          // check_table_access
+#include "sql_base.h"                           // close_thread_tables
+#include "key.h"                                // key_copy
+#include "sql_show.h"           // remove_status_vars, add_status_vars
+#include "strfunc.h"            // find_set
+#include "sql_acl.h"                       // *_ACL
+#include "records.h"          // init_read_record, end_read_record
 #include <my_pthread.h>
 #include <my_getopt.h>
 #define REPORT_TO_LOG  1

=== modified file 'sql/sql_plugin.h'
--- a/sql/sql_plugin.h	2009-11-02 20:05:42 +0000
+++ b/sql/sql_plugin.h	2009-11-18 08:54:54 +0000
@@ -16,6 +16,22 @@
 #ifndef _sql_plugin_h
 #define _sql_plugin_h
 
+/*
+  the following #define adds server-only members to enum_mysql_show_type,
+  that is defined in plugin.h
+*/
+#define SHOW_always_last SHOW_KEY_CACHE_LONG, SHOW_KEY_CACHE_LONGLONG,  \
+    SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS, SHOW_HAVE,                    \
+    SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, SHOW_LONG_NOFLUSH,            \
+    SHOW_LONGLONG_STATUS
+#include <mysql/plugin.h>
+#undef SHOW_always_last
+
+#include "m_string.h"                       /* LEX_STRING */
+#include "my_alloc.h"                       /* MEM_ROOT */
+
+#include "my_sys.h"                         /* CALLER_INFO_PROTO */
+
 class sys_var;
 
 #ifdef DBUG_OFF

=== modified file 'sql/sql_prepare.cc'
--- a/sql/sql_prepare.cc	2009-11-06 15:28:25 +0000
+++ b/sql/sql_prepare.cc	2009-11-18 08:54:54 +0000
@@ -83,9 +83,21 @@ When one supplies long data for a placeh
     at statement execute.
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #include "sql_prepare.h"
+#include "sql_parse.h" // insert_precheck, update_precheck, delete_precheck
+#include "sql_base.h"  // close_thread_tables
+#include "sql_cache.h"                          // query_cache_*
+#include "sql_view.h"                          // create_view_precheck
+#include "sql_delete.h"                        // mysql_prepare_delete
 #include "sql_select.h" // for JOIN
+#include "sql_insert.h" // upgrade_lock_type_for_insert, mysql_prepare_insert
+#include "sql_update.h" // mysql_prepare_update
+#include "sql_db.h"     // mysql_opt_change_db, mysql_change_db
+#include "sql_acl.h"    // *_ACL
+#include "sql_derived.h" // mysql_derived_prepare,
+                         // mysql_handle_derived
 #include "sql_cursor.h"
 #include "sp_head.h"
 #include "sp.h"

=== renamed file 'sql/mysql_priv.h' => 'sql/sql_priv.h'
--- a/sql/mysql_priv.h	2009-11-10 07:31:33 +0000
+++ b/sql/sql_priv.h	2009-11-18 08:54:54 +0000
@@ -28,99 +28,6 @@
 
 #ifndef MYSQL_CLIENT
 
-/*
-  the following #define adds server-only members to enum_mysql_show_type,
-  that is defined in mysql/plugin.h
-  it has to be before mysql/plugin.h is included.
-*/
-#define SHOW_always_last SHOW_KEY_CACHE_LONG, \
-            SHOW_KEY_CACHE_LONGLONG, SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS, \
-            SHOW_HAVE, SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, \
-            SHOW_LONG_NOFLUSH, SHOW_LONGLONG_STATUS
-
-#include <my_global.h>
-#include <mysql_version.h>
-#include <mysql_embed.h>
-#include <my_sys.h>
-#include <my_time.h>
-#include <m_string.h>
-#include <hash.h>
-#include <signal.h>
-#include <thr_lock.h>
-#include <my_base.h>			/* Needed by field.h */
-#include <queues.h>
-#include "sql_bitmap.h"
-#include "sql_array.h"
-#include "sql_plugin.h"
-#include "scheduler.h"
-
-class Parser_state;
-
-/**
-  Query type constants.
-
-  QT_ORDINARY -- ordinary SQL query.
-  QT_IS -- SQL query to be shown in INFORMATION_SCHEMA (in utf8 and without
-  character set introducers).
-*/
-enum enum_query_type
-{
-  QT_ORDINARY,
-  QT_IS
-};
-
-/* TODO convert all these three maps to Bitmap classes */
-typedef ulonglong table_map;          /* Used for table bits in join */
-#if MAX_INDEXES <= 64
-typedef Bitmap<64>  key_map;          /* Used for finding keys */
-#else
-typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */
-#endif
-typedef ulong nesting_map;  /* Used for flags of nesting constructs */
-/*
-  Used to identify NESTED_JOIN structures within a join (applicable only to
-  structures that have not been simplified away and embed more the one
-  element)
-*/
-typedef ulonglong nested_join_map;
-
-/* query_id */
-typedef ulonglong query_id_t;
-extern query_id_t global_query_id;
-
-/* increment query_id and return it.  */
-inline query_id_t next_query_id() { return global_query_id++; }
-
-/* useful constants */
-extern MYSQL_PLUGIN_IMPORT const key_map key_map_empty;
-extern MYSQL_PLUGIN_IMPORT key_map key_map_full;          /* Should be threaded as const */
-extern MYSQL_PLUGIN_IMPORT const char *primary_key_name;
-
-#include "mysql_com.h"
-#include <violite.h>
-#include "unireg.h"
-
-void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size);
-void *sql_alloc(size_t);
-void *sql_calloc(size_t);
-char *sql_strdup(const char *str);
-char *sql_strmake(const char *str, size_t len);
-void *sql_memdup(const void * ptr, size_t size);
-void sql_element_free(void *ptr);
-char *sql_strmake_with_convert(const char *str, size_t arg_length,
-			       CHARSET_INFO *from_cs,
-			       size_t max_res_length,
-			       CHARSET_INFO *to_cs, size_t *result_length);
-uint kill_one_thread(THD *thd, ulong id, bool only_kill_query);
-void sql_kill(THD *thd, ulong id, bool only_kill_query);
-bool net_request_file(NET* net, const char* fname);
-char* query_table_status(THD *thd,const char *db,const char *table_name);
-
-#define x_free(A)	{ my_free((uchar*) (A),MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR)); }
-#define safeFree(x)	{ if(x) { my_free((uchar*) x,MYF(0)); x = NULL; } }
-#define PREV_BITS(type,A)	((type) (((type) 1 << (A)) -1))
-#define all_bits_set(A,B) ((A) & (B) != (B))
-
 #define WARN_DEPRECATED(Thd,Ver,Old,New)                                             \
   do {                                                                               \
     DBUG_ASSERT(strncmp(Ver, MYSQL_SERVER_VERSION, sizeof(Ver)-1) > 0);              \
@@ -133,438 +40,19 @@ char* query_table_status(THD *thd,const 
                         "in MySQL %s. Please use %s instead.", (Old), (Ver), (New)); \
   } while(0)
 
-extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *system_charset_info;
-extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *files_charset_info ;
-extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *national_charset_info;
-extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *table_alias_charset;
-
-/**
-  Character set of the buildin error messages loaded from errmsg.sys.
-*/
-extern CHARSET_INFO *error_message_charset_info;
-
-enum Derivation
-{
-  DERIVATION_IGNORABLE= 5,
-  DERIVATION_COERCIBLE= 4,
-  DERIVATION_SYSCONST= 3,
-  DERIVATION_IMPLICIT= 2,
-  DERIVATION_NONE= 1,
-  DERIVATION_EXPLICIT= 0
-};
-
-
-typedef struct my_locale_errmsgs
-{
-  const char *language;
-  const char **errmsgs;
-} MY_LOCALE_ERRMSGS;
-
-extern char err_shared_dir[];
-
-typedef struct my_locale_st
-{
-  uint  number;
-  const char *name;
-  const char *description;
-  const bool is_ascii;
-  TYPELIB *month_names;
-  TYPELIB *ab_month_names;
-  TYPELIB *day_names;
-  TYPELIB *ab_day_names;
-  uint max_month_name_length;
-  uint max_day_name_length;
-  uint decimal_point;
-  uint thousand_sep;
-  const char *grouping;
-  MY_LOCALE_ERRMSGS *errmsgs;
-#ifdef __cplusplus 
-  my_locale_st(uint number_par,
-               const char *name_par, const char *descr_par, bool is_ascii_par,
-               TYPELIB *month_names_par, TYPELIB *ab_month_names_par,
-               TYPELIB *day_names_par, TYPELIB *ab_day_names_par,
-               uint max_month_name_length_par, uint max_day_name_length_par,
-               uint decimal_point_par, uint thousand_sep_par,
-               const char *grouping_par, MY_LOCALE_ERRMSGS *errmsgs_par) :
-    number(number_par),
-    name(name_par), description(descr_par), is_ascii(is_ascii_par),
-    month_names(month_names_par), ab_month_names(ab_month_names_par),
-    day_names(day_names_par), ab_day_names(ab_day_names_par),
-    max_month_name_length(max_month_name_length_par),
-    max_day_name_length(max_day_name_length_par),
-    decimal_point(decimal_point_par),
-    thousand_sep(thousand_sep_par),
-    grouping(grouping_par),
-    errmsgs(errmsgs_par)
-  {}
-#endif
-} MY_LOCALE;
-
-extern MY_LOCALE my_locale_en_US;
-extern MY_LOCALE *my_locales[];
-extern MY_LOCALE *my_default_lc_messages;
-extern MY_LOCALE *my_default_lc_time_names;
-
-MY_LOCALE *my_locale_by_name(const char *name);
-MY_LOCALE *my_locale_by_number(uint number);
-
-void cleanup_errmsgs(void);
-
-/*************************************************************************/
-
-/**
- Object_creation_ctx -- interface for creation context of database objects
- (views, stored routines, events, triggers). Creation context -- is a set
- of attributes, that should be fixed at the creation time and then be used
- each time the object is parsed or executed.
-*/
-
-class Object_creation_ctx
-{
-public:
-  Object_creation_ctx *set_n_backup(THD *thd);
-
-  void restore_env(THD *thd, Object_creation_ctx *backup_ctx);
-
-protected:
-  Object_creation_ctx() {}
-  virtual Object_creation_ctx *create_backup_ctx(THD *thd) const = 0;
-
-  virtual void change_env(THD *thd) const = 0;
-
-public:
-  virtual ~Object_creation_ctx()
-  { }
-};
-
 /*************************************************************************/
 
-/**
- Default_object_creation_ctx -- default implementation of
- Object_creation_ctx.
-*/
-
-class Default_object_creation_ctx : public Object_creation_ctx
-{
-public:
-  CHARSET_INFO *get_client_cs()
-  {
-    return m_client_cs;
-  }
-
-  CHARSET_INFO *get_connection_cl()
-  {
-    return m_connection_cl;
-  }
-
-protected:
-  Default_object_creation_ctx(THD *thd);
-
-  Default_object_creation_ctx(CHARSET_INFO *client_cs,
-                              CHARSET_INFO *connection_cl);
-
-protected:
-  virtual Object_creation_ctx *create_backup_ctx(THD *thd) const;
-
-  virtual void change_env(THD *thd) const;
-
-protected:
-  /**
-    client_cs stores the value of character_set_client session variable.
-    The only character set attribute is used.
-
-    Client character set is included into query context, because we save
-    query in the original character set, which is client character set. So,
-    in order to parse the query properly we have to switch client character
-    set on parsing.
-  */
-  CHARSET_INFO *m_client_cs;
-
-  /**
-    connection_cl stores the value of collation_connection session
-    variable. Both character set and collation attributes are used.
-
-    Connection collation is included into query context, becase it defines
-    the character set and collation of text literals in internal
-    representation of query (item-objects).
-  */
-  CHARSET_INFO *m_connection_cl;
-};
-
-/***************************************************************************
-  Configuration parameters
-****************************************************************************/
-
-#define ACL_CACHE_SIZE		256
-#define MAX_PASSWORD_LENGTH	32
-#define HOST_CACHE_SIZE		128
-#define MAX_ACCEPT_RETRY	10	// Test accept this many times
-#define MAX_FIELDS_BEFORE_HASH	32
-#define USER_VARS_HASH_SIZE     16
-#define TABLE_OPEN_CACHE_MIN    400
-#define TABLE_OPEN_CACHE_DEFAULT 400
-#define TABLE_DEF_CACHE_DEFAULT 400
-/**
-  We must have room for at least 400 table definitions in the table
-  cache, since otherwise there is no chance prepared
-  statements that use these many tables can work.
-  Prepared statements use table definition cache ids (table_map_id)
-  as table version identifiers. If the table definition
-  cache size is less than the number of tables used in a statement,
-  the contents of the table definition cache is guaranteed to rotate
-  between a prepare and execute. This leads to stable validation
-  errors. In future we shall use more stable version identifiers,
-  for now the only solution is to ensure that the table definition
-  cache can contain at least all tables of a given statement.
-*/
-#define TABLE_DEF_CACHE_MIN     400
-
-/*
-  Stack reservation.
-  Feel free to raise this by the smallest amount you can to get the
-  "execution_constants" test to pass.
-*/
-#define STACK_MIN_SIZE          16000   // Abort if less stack during eval.
-
-#define STACK_MIN_SIZE_FOR_OPEN 1024*80
-#define STACK_BUFF_ALLOC        352     ///< For stack overrun checks
-#ifndef MYSQLD_NET_RETRY_COUNT
-#define MYSQLD_NET_RETRY_COUNT  10	///< Abort read after this many int.
-#endif
-#define TEMP_POOL_SIZE          128
-
-#define QUERY_ALLOC_BLOCK_SIZE		8192
-#define QUERY_ALLOC_PREALLOC_SIZE   	8192
-#define TRANS_ALLOC_BLOCK_SIZE		4096
-#define TRANS_ALLOC_PREALLOC_SIZE	4096
-#define RANGE_ALLOC_BLOCK_SIZE		4096
-#define ACL_ALLOC_BLOCK_SIZE		1024
-#define UDF_ALLOC_BLOCK_SIZE		1024
-#define TABLE_ALLOC_BLOCK_SIZE		1024
-#define BDB_LOG_ALLOC_BLOCK_SIZE	1024
-#define WARN_ALLOC_BLOCK_SIZE		2048
-#define WARN_ALLOC_PREALLOC_SIZE	1024
-#define PROFILE_ALLOC_BLOCK_SIZE  2048
-#define PROFILE_ALLOC_PREALLOC_SIZE 1024
-
-/*
-  The following parameters is to decide when to use an extra cache to
-  optimise seeks when reading a big table in sorted order
-*/
-#define MIN_FILE_LENGTH_TO_USE_ROW_CACHE (10L*1024*1024)
-#define MIN_ROWS_TO_USE_TABLE_CACHE	 100
-#define MIN_ROWS_TO_USE_BULK_INSERT	 100
-
-/**
-  The following is used to decide if MySQL should use table scanning
-  instead of reading with keys.  The number says how many evaluation of the
-  WHERE clause is comparable to reading one extra row from a table.
-*/
-#define TIME_FOR_COMPARE   5	// 5 compares == one read
-
-/**
-  Number of comparisons of table rowids equivalent to reading one row from a 
-  table.
-*/
-#define TIME_FOR_COMPARE_ROWID  (TIME_FOR_COMPARE*2)
-
-/*
-  For sequential disk seeks the cost formula is:
-    DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip  
-  
-  The cost of average seek 
-    DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST*BLOCKS_IN_AVG_SEEK =1.0.
-*/
-#define DISK_SEEK_BASE_COST ((double)0.5)
-
-#define BLOCKS_IN_AVG_SEEK  128
-
-#define DISK_SEEK_PROP_COST ((double)0.5/BLOCKS_IN_AVG_SEEK)
-
-
-/**
-  Number of rows in a reference table when refereed through a not unique key.
-  This value is only used when we don't know anything about the key
-  distribution.
-*/
-#define MATCHING_ROWS_IN_OTHER_TABLE 10
-
-/** Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used). */
-#define KEY_DEFAULT_PACK_LENGTH 8
-
-/** Characters shown for the command in 'show processlist'. */
-#define PROCESS_LIST_WIDTH 100
-/* Characters shown for the command in 'information_schema.processlist' */
-#define PROCESS_LIST_INFO_WIDTH 65535
-
-#define PRECISION_FOR_DOUBLE 53
-#define PRECISION_FOR_FLOAT  24
-
-/* -[digits].E+## */
-#define MAX_FLOAT_STR_LENGTH (FLT_DIG + 6)
-/* -[digits].E+### */
-#define MAX_DOUBLE_STR_LENGTH (DBL_DIG + 7)
-
-/*
-  Default time to wait before aborting a new client connection
-  that does not respond to "initial server greeting" timely
-*/
-#define CONNECT_TIMEOUT		10
-
-/* The following can also be changed from the command line */
-#define DEFAULT_CONCURRENCY	10
-#define DELAYED_LIMIT		100		/**< pause after xxx inserts */
-#define DELAYED_QUEUE_SIZE	1000
-#define DELAYED_WAIT_TIMEOUT	5*60		/**< Wait for delayed insert */
-#define FLUSH_TIME		0		/**< Don't flush tables */
-#define MAX_CONNECT_ERRORS	10		///< errors before disabling host
-
 #ifdef __NETWARE__
 #define IF_NETWARE(A,B) A
 #else
 #define IF_NETWARE(A,B) B
 #endif
 
-#if defined(__WIN__)
-#undef	FLUSH_TIME
-#define FLUSH_TIME	1800			/**< Flush every half hour */
-
-#define INTERRUPT_PRIOR -2
-#define CONNECT_PRIOR	-1
-#define WAIT_PRIOR	0
-#define QUERY_PRIOR	2
-#else
-#define INTERRUPT_PRIOR 10
-#define CONNECT_PRIOR	9
-#define WAIT_PRIOR	8
-#define QUERY_PRIOR	6
-#endif /* __WIN92__ */
-
-	/* Bits from testflag */
-#define TEST_PRINT_CACHED_TABLES 1
-#define TEST_NO_KEY_GROUP	 2
-#define TEST_MIT_THREAD		4
-#define TEST_BLOCKING		8
-#define TEST_KEEP_TMP_TABLES	16
-#define TEST_READCHECK		64	/**< Force use of readcheck */
-#define TEST_NO_EXTRA		128
-#define TEST_CORE_ON_SIGNAL	256	/**< Give core if signal */
-#define TEST_NO_STACKTRACE	512
-#define TEST_SIGINT		1024	/**< Allow sigint on threads */
-#define TEST_SYNCHRONIZATION    2048    /**< get server to do sleep in
-                                           some places */
 #endif
 
-/*
-   This is included in the server and in the client.
-   Options for select set by the yacc parser (stored in lex->options).
-
-   XXX:
-   log_event.h defines OPTIONS_WRITTEN_TO_BIN_LOG to specify what THD
-   options list are written into binlog. These options can NOT change their
-   values, or it will break replication between version.
-
-   context is encoded as following:
-   SELECT - SELECT_LEX_NODE::options
-   THD    - THD::options
-   intern - neither. used only as
-            func(..., select_node->options | thd->options | OPTION_XXX, ...)
-
-   TODO: separate three contexts above, move them to separate bitfields.
-*/
-
-#define SELECT_DISTINCT         (ULL(1) << 0)     // SELECT, user
-#define SELECT_STRAIGHT_JOIN    (ULL(1) << 1)     // SELECT, user
-#define SELECT_DESCRIBE         (ULL(1) << 2)     // SELECT, user
-#define SELECT_SMALL_RESULT     (ULL(1) << 3)     // SELECT, user
-#define SELECT_BIG_RESULT       (ULL(1) << 4)     // SELECT, user
-#define OPTION_FOUND_ROWS       (ULL(1) << 5)     // SELECT, user
-#define OPTION_TO_QUERY_CACHE   (ULL(1) << 6)     // SELECT, user
-#define SELECT_NO_JOIN_CACHE    (ULL(1) << 7)     // intern
-#define OPTION_BIG_TABLES       (ULL(1) << 8)     // THD, user
-#define OPTION_BIG_SELECTS      (ULL(1) << 9)     // THD, user
-#define OPTION_LOG_OFF          (ULL(1) << 10)    // THD, user
-#define OPTION_QUOTE_SHOW_CREATE (ULL(1) << 11)   // THD, user, unused
-#define TMP_TABLE_ALL_COLUMNS   (ULL(1) << 12)    // SELECT, intern
-#define OPTION_WARNINGS         (ULL(1) << 13)    // THD, user
-#define OPTION_AUTO_IS_NULL     (ULL(1) << 14)    // THD, user, binlog
-#define OPTION_FOUND_COMMENT    (ULL(1) << 15)    // SELECT, intern, parser
-#define OPTION_SAFE_UPDATES     (ULL(1) << 16)    // THD, user
-#define OPTION_BUFFER_RESULT    (ULL(1) << 17)    // SELECT, user
-#define OPTION_BIN_LOG          (ULL(1) << 18)    // THD, user
-#define OPTION_NOT_AUTOCOMMIT   (ULL(1) << 19)    // THD, user
-#define OPTION_BEGIN            (ULL(1) << 20)    // THD, intern
-#define OPTION_TABLE_LOCK       (ULL(1) << 21)    // THD, intern
-#define OPTION_QUICK            (ULL(1) << 22)    // SELECT (for DELETE)
-#define OPTION_KEEP_LOG         (ULL(1) << 23)    // THD, user
-
-/* The following is used to detect a conflict with DISTINCT */
-#define SELECT_ALL              (ULL(1) << 24)    // SELECT, user, parser
-
-/** The following can be set when importing tables in a 'wrong order'
-   to suppress foreign key checks */
-#define OPTION_NO_FOREIGN_KEY_CHECKS    (ULL(1) << 26) // THD, user, binlog
-/** The following speeds up inserts to InnoDB tables by suppressing unique
-   key checks in some cases */
-#define OPTION_RELAXED_UNIQUE_CHECKS    (ULL(1) << 27) // THD, user, binlog
-#define SELECT_NO_UNLOCK                (ULL(1) << 28) // SELECT, intern
-#define OPTION_SCHEMA_TABLE             (ULL(1) << 29) // SELECT, intern
-/** Flag set if setup_tables already done */
-#define OPTION_SETUP_TABLES_DONE        (ULL(1) << 30) // intern
-/** If not set then the thread will ignore all warnings with level notes. */
-#define OPTION_SQL_NOTES                (ULL(1) << 31) // THD, user
-/**
-  Force the used temporary table to be a MyISAM table (because we will use
-  fulltext functions when reading from it.
-*/
-#define TMP_TABLE_FORCE_MYISAM          (ULL(1) << 32)
-#define OPTION_PROFILING                (ULL(1) << 33)
-
-
-
-/**
-  Maximum length of time zone name that we support
-  (Time zone name is char(64) in db). mysqlbinlog needs it.
-*/
-#define MAX_TIME_ZONE_NAME_LENGTH       (NAME_LEN + 1)
-
 /* The rest of the file is included in the server only */
 #ifndef MYSQL_CLIENT
 
-/* Bits for different SQL modes modes (including ANSI mode) */
-#define MODE_REAL_AS_FLOAT              1
-#define MODE_PIPES_AS_CONCAT            2
-#define MODE_ANSI_QUOTES                4
-#define MODE_IGNORE_SPACE		8
-#define MODE_NOT_USED			16
-#define MODE_ONLY_FULL_GROUP_BY		32
-#define MODE_NO_UNSIGNED_SUBTRACTION	64
-#define MODE_NO_DIR_IN_CREATE		128
-#define MODE_POSTGRESQL			256
-#define MODE_ORACLE			512
-#define MODE_MSSQL			1024
-#define MODE_DB2			2048
-#define MODE_MAXDB			4096
-#define MODE_NO_KEY_OPTIONS             8192
-#define MODE_NO_TABLE_OPTIONS           16384
-#define MODE_NO_FIELD_OPTIONS           32768
-#define MODE_MYSQL323                   65536L
-#define MODE_MYSQL40                    (MODE_MYSQL323*2)
-#define MODE_ANSI	                (MODE_MYSQL40*2)
-#define MODE_NO_AUTO_VALUE_ON_ZERO      (MODE_ANSI*2)
-#define MODE_NO_BACKSLASH_ESCAPES       (MODE_NO_AUTO_VALUE_ON_ZERO*2)
-#define MODE_STRICT_TRANS_TABLES	(MODE_NO_BACKSLASH_ESCAPES*2)
-#define MODE_STRICT_ALL_TABLES		(MODE_STRICT_TRANS_TABLES*2)
-#define MODE_NO_ZERO_IN_DATE		(MODE_STRICT_ALL_TABLES*2)
-#define MODE_NO_ZERO_DATE		(MODE_NO_ZERO_IN_DATE*2)
-#define MODE_INVALID_DATES		(MODE_NO_ZERO_DATE*2)
-#define MODE_ERROR_FOR_DIVISION_BY_ZERO (MODE_INVALID_DATES*2)
-#define MODE_TRADITIONAL		(MODE_ERROR_FOR_DIVISION_BY_ZERO*2)
-#define MODE_NO_AUTO_CREATE_USER	(MODE_TRADITIONAL*2)
-#define MODE_HIGH_NOT_PRECEDENCE	(MODE_NO_AUTO_CREATE_USER*2)
-#define MODE_NO_ENGINE_SUBSTITUTION     (MODE_HIGH_NOT_PRECEDENCE*2)
-#define MODE_PAD_CHAR_TO_FULL_LENGTH    (ULL(1) << 31)
-
 /* @@optimizer_switch flags. These must be in sync with optimizer_switch_typelib */
 #define OPTIMIZER_SWITCH_INDEX_MERGE 1
 #define OPTIMIZER_SWITCH_INDEX_MERGE_UNION 2
@@ -591,10 +79,6 @@ protected:
 
 */
 
-#define RAID_BLOCK_SIZE 1024
-
-#define MY_CHARSET_BIN_MB_MAXLEN 1
-
 // uncachable cause
 #define UNCACHEABLE_DEPENDENT   1
 #define UNCACHEABLE_RAND        2
@@ -609,20 +93,6 @@ protected:
 
 /* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */
 #define UNDEF_POS (-1)
-#ifdef EXTRA_DEBUG
-/**
-  Sync points allow us to force the server to reach a certain line of code
-  and block there until the client tells the server it is ok to go on.
-  The client tells the server to block with SELECT GET_LOCK()
-  and unblocks it with SELECT RELEASE_LOCK(). Used for debugging difficult
-  concurrency problems
-*/
-#define DBUG_SYNC_POINT(lock_name,lock_timeout) \
- debug_sync_point(lock_name,lock_timeout)
-void debug_sync_point(const char* lock_name, uint lock_timeout);
-#else
-#define DBUG_SYNC_POINT(lock_name,lock_timeout)
-#endif /* EXTRA_DEBUG */
 
 /* BINLOG_DUMP options */
 
@@ -632,30 +102,6 @@ void debug_sync_point(const char* lock_n
 #define SHOW_LOG_STATUS_FREE "FREE"
 #define SHOW_LOG_STATUS_INUSE "IN USE"
 
-struct TABLE_LIST;
-class String;
-void view_store_options(THD *thd, TABLE_LIST *table, String *buff);
-
-/* Options to add_table_to_list() */
-#define TL_OPTION_UPDATING	1
-#define TL_OPTION_FORCE_INDEX	2
-#define TL_OPTION_IGNORE_LEAVES 4
-#define TL_OPTION_ALIAS         8
-
-/* Some portable defines */
-
-#define portable_sizeof_char_ptr 8
-
-#define tmp_file_prefix "#sql"			/**< Prefix for tmp tables */
-#define tmp_file_prefix_length 4
-
-/* Flags for calc_week() function.  */
-#define WEEK_MONDAY_FIRST    1
-#define WEEK_YEAR            2
-#define WEEK_FIRST_WEEKDAY   4
-
-#define STRING_BUFFER_USUAL_SIZE 80
-
 /*
   Some defines for exit codes for ::is_equal class functions.
 */
@@ -673,749 +119,12 @@ enum enum_parsing_place
 };
 
 
-#define thd_proc_info(thd, msg)  set_thd_proc_info(thd, msg, __func__, __FILE__, __LINE__)
-class THD;
-
-enum enum_check_fields
-{
-  CHECK_FIELD_IGNORE,
-  CHECK_FIELD_WARN,
-  CHECK_FIELD_ERROR_FOR_NULL
-};
-
-                                  
-/** Struct to handle simple linked lists. */
-typedef struct st_sql_list {
-  uint elements;
-  uchar *first;
-  uchar **next;
-
-  st_sql_list() {}                              /* Remove gcc warning */
-  inline void empty()
-  {
-    elements=0;
-    first=0;
-    next= &first;
-  }
-  inline void link_in_list(uchar *element,uchar **next_ptr)
-  {
-    elements++;
-    (*next)=element;
-    next= next_ptr;
-    *next=0;
-  }
-  inline void save_and_clear(struct st_sql_list *save)
-  {
-    *save= *this;
-    empty();
-  }
-  inline void push_front(struct st_sql_list *save)
-  {
-    *save->next= first;				/* link current list last */
-    first= save->first;
-    elements+= save->elements;
-  }
-  inline void push_back(struct st_sql_list *save)
-  {
-    if (save->first)
-    {
-      *next= save->first;
-      next= save->next;
-      elements+= save->elements;
-    }
-  }
-} SQL_LIST;
-
-#if defined(MYSQL_DYNAMIC_PLUGIN) && defined(_WIN32)
-extern "C" THD *_current_thd_noinline();
-#define _current_thd() _current_thd_noinline()
-#else
-extern pthread_key(THD*, THR_THD);
-inline THD *_current_thd(void)
-{
-  return my_pthread_getspecific_ptr(THD*,THR_THD);
-}
-#endif
-#define current_thd _current_thd()
-
-
-/** 
-  The meat of thd_proc_info(THD*, char*), a macro that packs the last
-  three calling-info parameters. 
-*/
-extern "C"
-const char *set_thd_proc_info(THD *thd, const char *info, 
-                              const char *calling_func, 
-                              const char *calling_file, 
-                              const unsigned int calling_line);
-
-/**
-  Enumerate possible types of a table from re-execution
-  standpoint.
-  TABLE_LIST class has a member of this type.
-  At prepared statement prepare, this member is assigned a value
-  as of the current state of the database. Before (re-)execution
-  of a prepared statement, we check that the value recorded at
-  prepare matches the type of the object we obtained from the
-  table definition cache.
-
-  @sa check_and_update_table_version()
-  @sa Execute_observer
-  @sa Prepared_statement::reprepare()
-*/
-
-enum enum_table_ref_type
-{
-  /** Initial value set by the parser */
-  TABLE_REF_NULL= 0,
-  TABLE_REF_VIEW,
-  TABLE_REF_BASE_TABLE,
-  TABLE_REF_I_S_TABLE,
-  TABLE_REF_TMP_TABLE
-};
-
-/*
-  External variables
-*/
-extern ulong server_id, concurrency;
-
-
-typedef my_bool (*qc_engine_callback)(THD *thd, char *table_key,
-                                      uint key_length,
-                                      ulonglong *engine_data);
-#include "sql_string.h"
-#include "sql_list.h"
-#include "sql_map.h"
-#include "my_decimal.h"
-#include "handler.h"
-#include "parse_file.h"
-#include "table.h"
-#include "sql_error.h"
-#include "field.h"				/* Field definitions */
-#include "protocol.h"
-#include "sql_udf.h"
-#include "sql_profile.h"
-#include "sql_partition.h"
-
-class user_var_entry;
-class Security_context;
-enum enum_var_type
-{
-  OPT_DEFAULT= 0, OPT_SESSION, OPT_GLOBAL
-};
-class sys_var;
-#ifdef MYSQL_SERVER
-class Comp_creator;
-typedef Comp_creator* (*chooser_compare_func_creator)(bool invert);
-#endif
-#include "item.h"
-extern my_decimal decimal_zero;
-
-/* sql_parse.cc */
-void free_items(Item *item);
-void cleanup_items(Item *item);
-class THD;
-void close_thread_tables(THD *thd);
-
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
-bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables);
-bool check_single_table_access(THD *thd, ulong privilege,
-			   TABLE_LIST *tables, bool no_errors);
-bool check_routine_access(THD *thd,ulong want_access,char *db,char *name,
-			  bool is_proc, bool no_errors);
-bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table);
-bool check_some_routine_access(THD *thd, const char *db, const char *name, bool is_proc);
-#else
-inline bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables)
-{ return false; }
-inline bool check_single_table_access(THD *thd, ulong privilege,
-			   TABLE_LIST *tables, bool no_errors)
-{ return false; }
-inline bool check_routine_access(THD *thd,ulong want_access,char *db,
-                                 char *name, bool is_proc, bool no_errors)
-{ return false; }
-inline bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table)
-{ return false; }
-inline bool check_merge_table_access(THD *thd, char *db, TABLE_LIST *table_list)
-{ return false; }
-inline bool check_some_routine_access(THD *thd, const char *db,
-                                      const char *name, bool is_proc)
-{ return false; }
-#endif /*NO_EMBEDDED_ACCESS_CHECKS*/
-
-bool multi_update_precheck(THD *thd, TABLE_LIST *tables);
-bool multi_delete_precheck(THD *thd, TABLE_LIST *tables);
-int mysql_multi_update_prepare(THD *thd);
-int mysql_multi_delete_prepare(THD *thd);
-bool mysql_insert_select_prepare(THD *thd);
-bool update_precheck(THD *thd, TABLE_LIST *tables);
-bool delete_precheck(THD *thd, TABLE_LIST *tables);
-bool insert_precheck(THD *thd, TABLE_LIST *tables);
-bool create_table_precheck(THD *thd, TABLE_LIST *tables,
-                           TABLE_LIST *create_table);
-int append_query_string(CHARSET_INFO *csinfo,
-                        String const *from, String *to);
-
-void get_default_definer(THD *thd, LEX_USER *definer);
-LEX_USER *create_default_definer(THD *thd);
-LEX_USER *create_definer(THD *thd, LEX_STRING *user_name, LEX_STRING *host_name);
-LEX_USER *get_current_user(THD *thd, LEX_USER *user);
-bool check_string_byte_length(LEX_STRING *str, const char *err_msg,
-                              uint max_byte_length);
-bool check_string_char_length(LEX_STRING *str, const char *err_msg,
-                              uint max_char_length, CHARSET_INFO *cs,
-                              bool no_error);
-bool check_host_name(LEX_STRING *str);
-
-bool parse_sql(THD *thd,
-               Parser_state *parser_state,
-               Object_creation_ctx *creation_ctx);
-
-enum enum_mysql_completiontype {
-  ROLLBACK_RELEASE=-2, ROLLBACK=1,  ROLLBACK_AND_CHAIN=7,
-  COMMIT_RELEASE=-1,   COMMIT=0,    COMMIT_AND_CHAIN=6
-};
-
-bool begin_trans(THD *thd);
-bool end_active_trans(THD *thd);
-int end_trans(THD *thd, enum enum_mysql_completiontype completion);
-
-Item *negate_expression(THD *thd, Item *expr);
-
-/* log.cc */
-int vprint_msg_to_log(enum loglevel level, const char *format, va_list args);
-void sql_print_error(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
-void sql_print_warning(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
-void sql_print_information(const char *format, ...)
-  ATTRIBUTE_FORMAT(printf, 1, 2);
-typedef void (*sql_print_message_func)(const char *format, ...)
-  ATTRIBUTE_FORMAT(printf, 1, 2);
-extern sql_print_message_func sql_print_message_handlers[];
-
-int error_log_print(enum loglevel level, const char *format,
-                    va_list args);
-
-bool slow_log_print(THD *thd, const char *query, uint query_length,
-                    ulonglong current_utime);
-
-bool general_log_print(THD *thd, enum enum_server_command command,
-                       const char *format,...);
-
-bool general_log_write(THD *thd, enum enum_server_command command,
-                       const char *query, uint query_length);
-
-#include "sql_class.h"
-#include "sql_acl.h"
-#include "tztime.h"
 #ifdef MYSQL_SERVER
-#include "sql_servers.h"
 #include "records.h"
-#include "opt_range.h"
-
-#ifdef HAVE_QUERY_CACHE
-struct Query_cache_query_flags
-{
-  unsigned int client_long_flag:1;
-  unsigned int client_protocol_41:1;
-  unsigned int protocol_type:2;
-  unsigned int more_results_exists:1;
-  unsigned int in_trans:1;
-  unsigned int autocommit:1;
-  unsigned int pkt_nr;
-  uint character_set_client_num;
-  uint character_set_results_num;
-  uint collation_connection_num;
-  ha_rows limit;
-  Time_zone *time_zone;
-  ulong sql_mode;
-  ulong max_sort_length;
-  ulong group_concat_max_len;
-  ulong default_week_format;
-  ulong div_precision_increment;
-  MY_LOCALE *lc_time_names;
-};
-#define QUERY_CACHE_FLAGS_SIZE sizeof(Query_cache_query_flags)
-#include "sql_cache.h"
-#define query_cache_abort(A) query_cache.abort(A)
-#define query_cache_end_of_result(A) query_cache.end_of_result(A)
-#define query_cache_store_query(A, B) query_cache.store_query(A, B)
-#define query_cache_destroy() query_cache.destroy()
-#define query_cache_result_size_limit(A) query_cache.result_size_limit(A)
-#define query_cache_init() query_cache.init()
-#define query_cache_resize(A) query_cache.resize(A)
-#define query_cache_set_min_res_unit(A) query_cache.set_min_res_unit(A)
-#define query_cache_invalidate3(A, B, C) query_cache.invalidate(A, B, C)
-#define query_cache_invalidate1(A) query_cache.invalidate(A)
-#define query_cache_send_result_to_client(A, B, C) \
-  query_cache.send_result_to_client(A, B, C)
-#define query_cache_invalidate_by_MyISAM_filename_ref \
-  &query_cache_invalidate_by_MyISAM_filename
-/* note the "maybe": it's a read without mutex */
-#define query_cache_maybe_disabled(T)                                 \
-  (T->variables.query_cache_type == 0 || query_cache.query_cache_size == 0)
-#define query_cache_is_cacheable_query(L) \
-  (((L)->sql_command == SQLCOM_SELECT) && (L)->safe_to_cache_query)
-#else
-#define QUERY_CACHE_FLAGS_SIZE 0
-#define query_cache_store_query(A, B)
-#define query_cache_destroy()
-#define query_cache_result_size_limit(A)
-#define query_cache_init()
-#define query_cache_resize(A)
-#define query_cache_set_min_res_unit(A)
-#define query_cache_invalidate3(A, B, C)
-#define query_cache_invalidate1(A)
-#define query_cache_send_result_to_client(A, B, C) 0
-#define query_cache_invalidate_by_MyISAM_filename_ref NULL
-
-#define query_cache_abort(A)
-#define query_cache_end_of_result(A)
-#define query_cache_invalidate_by_MyISAM_filename_ref NULL
-#define query_cache_maybe_disabled(T) 1
-#define query_cache_is_cacheable_query(L) 0
-#endif /*HAVE_QUERY_CACHE*/
-
-void write_bin_log(THD *thd, bool clear_error,
-                   char const *query, ulong query_length);
-
-/* sql_connect.cc */
-int check_user(THD *thd, enum enum_server_command command, 
-	       const char *passwd, uint passwd_len, const char *db,
-	       bool check_count);
-pthread_handler_t handle_one_connection(void *arg);
-bool init_new_connection_handler_thread();
-void reset_mqh(LEX_USER *lu, bool get_them);
-bool check_mqh(THD *thd, uint check_command);
-void time_out_user_resource_limits(THD *thd, USER_CONN *uc);
-void decrease_user_connections(USER_CONN *uc);
-void thd_init_client_charset(THD *thd, uint cs_number);
-bool setup_connection_thread_globals(THD *thd);
-
-int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent);
-bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create);
-bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent);
-bool mysql_upgrade_db(THD *thd, LEX_STRING *old_db);
-void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags);
-void mysql_client_binlog_statement(THD *thd);
-bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
-                    my_bool drop_temporary);
-int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
-                         bool drop_temporary, bool drop_view, bool log_query);
-bool quick_rm_table(handlerton *base,const char *db,
-                    const char *table_name, uint flags);
-void close_cached_table(THD *thd, TABLE *table);
-bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent);
-bool do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db,
-                      char *new_table_name, char *new_table_alias,
-                      bool skip_error);
-
-bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name,
-                     bool force_switch);
-
-bool mysql_opt_change_db(THD *thd,
-                         const LEX_STRING *new_db_name,
-                         LEX_STRING *saved_db_name,
-                         bool force_switch,
-                         bool *cur_db_changed);
-
-void mysql_parse(THD *thd, const char *inBuf, uint length,
-                 const char ** semicolon);
-
-bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
-bool is_update_query(enum enum_sql_command command);
-bool is_log_table_write_query(enum enum_sql_command command);
-bool alloc_query(THD *thd, const char *packet, uint packet_length);
-void mysql_init_select(LEX *lex);
-void mysql_reset_thd_for_next_command(THD *thd);
-bool mysql_new_select(LEX *lex, bool move_down);
-void create_select_for_variable(const char *var_name);
-void mysql_init_multi_delete(LEX *lex);
-bool multi_delete_set_locks_and_link_aux_tables(LEX *lex);
-void init_max_user_conn(void);
-void init_update_queries(void);
-void free_max_user_conn(void);
-pthread_handler_t handle_bootstrap(void *arg);
-int mysql_execute_command(THD *thd);
-bool do_command(THD *thd);
-bool dispatch_command(enum enum_server_command command, THD *thd,
-		      char* packet, uint packet_length);
-void log_slow_statement(THD *thd);
-bool check_dup(const char *db, const char *name, TABLE_LIST *tables);
-bool compare_record(TABLE *table);
-bool append_file_to_dir(THD *thd, const char **filename_ptr, 
-                        const char *table_name);
-void wait_while_table_is_used(THD *thd, TABLE *table,
-                              enum ha_extra_function function);
-bool table_cache_init(void);
-void table_cache_free(void);
-bool table_def_init(void);
-void table_def_free(void);
-void assign_new_table_id(TABLE_SHARE *share);
-uint cached_open_tables(void);
-uint cached_table_definitions(void);
-void kill_mysql(void);
-void close_connection(THD *thd, uint errcode, bool lock);
-bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables, 
-                          bool *write_to_binlog);
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
-bool check_access(THD *thd, ulong access, const char *db, ulong *save_priv,
-                  bool no_grant, bool no_errors, bool schema_db);
-bool check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables,
-                        bool any_combination_of_privileges_will_do,
-                        uint number,
-                        bool no_errors);
-#else
-inline bool check_access(THD *thd, ulong access, const char *db,
-                         ulong *save_priv, bool no_grant, bool no_errors,
-                         bool schema_db)
-{
-  if (save_priv)
-    *save_priv= GLOBAL_ACLS;
-  return false;
-}
-inline bool check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables,
-                               bool no_errors,
-                               bool any_combination_of_privileges_will_do,
-                               uint number)
-{ return false; }
-#endif /*NO_EMBEDDED_ACCESS_CHECKS*/
 
 #endif /* MYSQL_SERVER */
-#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
-bool check_global_access(THD *thd, ulong want_access);
-#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
-#ifdef MYSQL_SERVER
-
-/*
-  Support routine for SQL parser on partitioning syntax
-*/
-my_bool is_partition_management(LEX *lex);
-/*
-  General routine to change field->ptr of a NULL-terminated array of Field
-  objects. Useful when needed to call val_int, val_str or similar and the
-  field data is not in table->record[0] but in some other structure.
-  set_key_field_ptr changes all fields of an index using a key_info object.
-  All methods presume that there is at least one field to change.
-*/
-
-void set_field_ptr(Field **ptr, const uchar *new_buf, const uchar *old_buf);
-void set_key_field_ptr(KEY *key_info, const uchar *new_buf,
-                       const uchar *old_buf);
-
-bool mysql_backup_table(THD* thd, TABLE_LIST* table_list);
-bool mysql_restore_table(THD* thd, TABLE_LIST* table_list);
-
-bool mysql_checksum_table(THD* thd, TABLE_LIST* table_list,
-                          HA_CHECK_OPT* check_opt);
-bool mysql_check_table(THD* thd, TABLE_LIST* table_list,
-                       HA_CHECK_OPT* check_opt);
-bool mysql_repair_table(THD* thd, TABLE_LIST* table_list,
-                        HA_CHECK_OPT* check_opt);
-bool mysql_analyze_table(THD* thd, TABLE_LIST* table_list,
-                         HA_CHECK_OPT* check_opt);
-bool mysql_optimize_table(THD* thd, TABLE_LIST* table_list,
-                          HA_CHECK_OPT* check_opt);
-bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* table_list,
-                              LEX_STRING *key_cache_name);
-bool mysql_preload_keys(THD* thd, TABLE_LIST* table_list);
-int reassign_keycache_tables(THD* thd, KEY_CACHE *src_cache,
-                             KEY_CACHE *dst_cache);
-TABLE *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list);
-
-bool mysql_xa_recover(THD *thd);
-
-bool check_simple_select();
-int mysql_alter_tablespace(THD* thd, st_alter_tablespace *ts_info);
-
-SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length,
-                                  SORT_FIELD *sortorder);
-int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
-		List<Item> &fields, List <Item> &all_fields, ORDER *order);
-int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
-		List<Item> &fields, List<Item> &all_fields, ORDER *order,
-		bool *hidden_group_fields);
-bool fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select,
-                   Item **ref_pointer_array);
-
-bool handle_select(THD *thd, LEX *lex, select_result *result,
-                   ulong setup_tables_done_option);
-bool mysql_select(THD *thd, Item ***rref_pointer_array,
-                  TABLE_LIST *tables, uint wild_num,  List<Item> &list,
-                  COND *conds, uint og_num, ORDER *order, ORDER *group,
-                  Item *having, ORDER *proc_param, ulonglong select_type, 
-                  select_result *result, SELECT_LEX_UNIT *unit, 
-                  SELECT_LEX *select_lex);
-void free_underlaid_joins(THD *thd, SELECT_LEX *select);
-bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit,
-                         select_result *result);
-int mysql_explain_select(THD *thd, SELECT_LEX *sl, char const *type,
-			 select_result *result);
-bool mysql_union(THD *thd, LEX *lex, select_result *result,
-                 SELECT_LEX_UNIT *unit, ulong setup_tables_done_option);
-bool mysql_handle_derived(LEX *lex, bool (*processor)(THD *thd,
-                                                      LEX *lex,
-                                                      TABLE_LIST *table));
-bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *t);
-bool mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *t);
-Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
-			Item ***copy_func, Field **from_field,
-                        Field **def_field,
-			bool group, bool modify_item,
-			bool table_cant_handle_bit_fields,
-                        bool make_copy_field,
-                        uint convert_blob_length);
-void sp_prepare_create_field(THD *thd, Create_field *sql_field);
-int prepare_create_field(Create_field *sql_field, 
-			 uint *blob_columns, 
-			 int *timestamps, int *timestamps_with_niladic,
-			 longlong table_flags);
-CHARSET_INFO* get_sql_field_charset(Create_field *sql_field,
-                                    HA_CREATE_INFO *create_info);
-bool mysql_create_table(THD *thd,const char *db, const char *table_name,
-                        HA_CREATE_INFO *create_info,
-                        Alter_info *alter_info,
-                        bool tmp_table, uint select_field_count);
-bool mysql_create_table_no_lock(THD *thd, const char *db,
-                                const char *table_name,
-                                HA_CREATE_INFO *create_info,
-                                Alter_info *alter_info,
-                                bool tmp_table, uint select_field_count);
-
-bool mysql_alter_table(THD *thd, char *new_db, char *new_name,
-                       HA_CREATE_INFO *create_info,
-                       TABLE_LIST *table_list,
-                       Alter_info *alter_info,
-                       uint order_num, ORDER *order, bool ignore);
-bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list);
-bool mysql_create_like_table(THD *thd, TABLE_LIST *table,
-                             TABLE_LIST *src_table,
-                             HA_CREATE_INFO *create_info);
-bool mysql_rename_table(handlerton *base, const char *old_db,
-                        const char * old_name, const char *new_db,
-                        const char * new_name, uint flags);
-bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
-                          Item **conds, uint order_num, ORDER *order);
-int mysql_update(THD *thd,TABLE_LIST *tables,List<Item> &fields,
-		 List<Item> &values,COND *conds,
-		 uint order_num, ORDER *order, ha_rows limit,
-		 enum enum_duplicates handle_duplicates, bool ignore,
-                 ha_rows *found_return, ha_rows *updated_return);
-bool mysql_multi_update(THD *thd, TABLE_LIST *table_list,
-                        List<Item> *fields, List<Item> *values,
-                        COND *conds, ulonglong options,
-                        enum enum_duplicates handle_duplicates, bool ignore,
-                        SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex,
-                        multi_update **result);
-bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table,
-                          List<Item> &fields, List_item *values,
-                          List<Item> &update_fields,
-                          List<Item> &update_values, enum_duplicates duplic,
-                          COND **where, bool select_insert,
-                          bool check_fields, bool abort_on_warning);
-bool mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields,
-                  List<List_item> &values, List<Item> &update_fields,
-                  List<Item> &update_values, enum_duplicates flag,
-                  bool ignore);
-int check_that_all_fields_are_given_values(THD *thd, TABLE *entry,
-                                           TABLE_LIST *table_list);
-void prepare_triggers_for_insert_stmt(TABLE *table);
-int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds);
-bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
-                  SQL_LIST *order, ha_rows rows, ulonglong options,
-                  bool reset_auto_increment);
-bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok);
-bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create);
-uint create_table_def_key(THD *thd, char *key, TABLE_LIST *table_list,
-                          bool tmp_table);
-TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
-                             uint key_length, uint db_flags, int *error);
-void release_table_share(TABLE_SHARE *share, enum release_type type);
-TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
-TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update,
-                   uint lock_flags);
-TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT* mem,
-		  bool *refresh, uint flags);
-bool name_lock_locked_table(THD *thd, TABLE_LIST *tables);
-bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list, bool link_in);
-TABLE *table_cache_insert_placeholder(THD *thd, const char *key,
-                                      uint key_length);
-bool lock_table_name_if_not_cached(THD *thd, const char *db,
-                                   const char *table_name, TABLE **table);
-TABLE *find_locked_table(THD *thd, const char *db,const char *table_name);
-void detach_merge_children(TABLE *table, bool clear_refs);
-bool fix_merge_after_open(TABLE_LIST *old_child_list, TABLE_LIST **old_last,
-                          TABLE_LIST *new_child_list, TABLE_LIST **new_last);
-bool reopen_table(TABLE *table);
-bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
-thr_lock_type read_lock_type_for_table(THD *thd, TABLE *table);
-void close_data_files_and_morph_locks(THD *thd, const char *db,
-                                      const char *table_name);
-void close_handle_and_leave_table_as_lock(TABLE *table);
-bool wait_for_tables(THD *thd);
-bool table_is_used(TABLE *table, bool wait_for_name_lock);
-TABLE *drop_locked_tables(THD *thd,const char *db, const char *table_name);
-void abort_locked_tables(THD *thd,const char *db, const char *table_name);
-void execute_init_command(THD *thd, sys_var_str *init_command_var,
-			  rw_lock_t *var_mutex);
-extern Field *not_found_field;
-extern Field *view_ref_found;
-
-enum find_item_error_report_type {REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND,
-				  IGNORE_ERRORS, REPORT_EXCEPT_NON_UNIQUE,
-                                  IGNORE_EXCEPT_NON_UNIQUE};
-Field *
-find_field_in_tables(THD *thd, Item_ident *item,
-                     TABLE_LIST *first_table, TABLE_LIST *last_table,
-                     Item **ref, find_item_error_report_type report_error,
-                     bool check_privileges, bool register_tree_change);
-Field *
-find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
-                        const char *name, uint length,
-                        const char *item_name, const char *db_name,
-                        const char *table_name, Item **ref,
-                        bool check_privileges, bool allow_rowid,
-                        uint *cached_field_index_ptr,
-                        bool register_tree_change, TABLE_LIST **actual_table);
-Field *
-find_field_in_table(THD *thd, TABLE *table, const char *name, uint length,
-                    bool allow_rowid, uint *cached_field_index_ptr);
-Field *
-find_field_in_table_sef(TABLE *table, const char *name);
-
-#endif /* MYSQL_SERVER */
-
-#ifdef HAVE_OPENSSL
-#include <openssl/des.h>
-struct st_des_keyblock
-{
-  DES_cblock key1, key2, key3;
-};
-struct st_des_keyschedule
-{
-  DES_key_schedule ks1, ks2, ks3;
-};
-extern char *des_key_file;
-extern struct st_des_keyschedule des_keyschedule[10];
-extern uint des_default_key;
-extern pthread_mutex_t LOCK_des_key_file;
-bool load_des_key_file(const char *file_name);
-#endif /* HAVE_OPENSSL */
 
 #ifdef MYSQL_SERVER
-/* sql_do.cc */
-bool mysql_do(THD *thd, List<Item> &values);
-
-/* sql_analyse.h */
-bool append_escaped(String *to_str, String *from_str);
-
-/* sql_show.cc */
-bool mysqld_show_open_tables(THD *thd,const char *wild);
-bool mysqld_show_logs(THD *thd);
-void append_identifier(THD *thd, String *packet, const char *name,
-		       uint length);
-#endif /* MYSQL_SERVER */
-#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
-int get_quote_char_for_identifier(THD *thd, const char *name, uint length);
-#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
-#ifdef MYSQL_SERVER
-void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild);
-int mysqld_dump_create_info(THD *thd, TABLE_LIST *table_list, int fd);
-bool mysqld_show_create(THD *thd, TABLE_LIST *table_list);
-bool mysqld_show_create_db(THD *thd, char *dbname, HA_CREATE_INFO *create);
-
-void mysqld_list_processes(THD *thd,const char *user,bool verbose);
-int mysqld_show_status(THD *thd);
-int mysqld_show_variables(THD *thd,const char *wild);
-bool mysqld_show_storage_engines(THD *thd);
-bool mysqld_show_authors(THD *thd);
-bool mysqld_show_contributors(THD *thd);
-bool mysqld_show_privileges(THD *thd);
-bool mysqld_show_column_types(THD *thd);
-bool mysqld_help (THD *thd, const char *text);
-void calc_sum_of_all_status(STATUS_VAR *to);
-
-void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user,
-                    const LEX_STRING *definer_host);
-
-int add_status_vars(SHOW_VAR *list);
-void remove_status_vars(SHOW_VAR *list);
-void init_status_vars();
-void free_status_vars();
-void reset_status_vars();
-/* information schema */
-extern LEX_STRING INFORMATION_SCHEMA_NAME;
-/* log tables */
-extern LEX_STRING MYSQL_SCHEMA_NAME;
-extern LEX_STRING GENERAL_LOG_NAME;
-extern LEX_STRING SLOW_LOG_NAME;
-
-extern const LEX_STRING partition_keywords[];
-ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name);
-ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx);
-int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
-                         enum enum_schema_tables schema_table_idx);
-int make_schema_select(THD *thd,  SELECT_LEX *sel,
-                       enum enum_schema_tables schema_table_idx);
-int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list);
-int fill_schema_user_privileges(THD *thd, TABLE_LIST *tables, COND *cond);
-int fill_schema_schema_privileges(THD *thd, TABLE_LIST *tables, COND *cond);
-int fill_schema_table_privileges(THD *thd, TABLE_LIST *tables, COND *cond);
-int fill_schema_column_privileges(THD *thd, TABLE_LIST *tables, COND *cond);
-bool get_schema_tables_result(JOIN *join,
-                              enum enum_schema_table_state executed_place);
-enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
-
-#define is_schema_db(X) \
-  !my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X))
-
-/* sql_handler.cc */
-bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen);
-bool mysql_ha_close(THD *thd, TABLE_LIST *tables);
-bool mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *,
-                   List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
-void mysql_ha_flush(THD *thd);
-void mysql_ha_rm_tables(THD *thd, TABLE_LIST *tables, bool is_locked);
-void mysql_ha_cleanup(THD *thd);
-
-/* sql_base.cc */
-#define TMP_TABLE_KEY_EXTRA 8
-void set_item_name(Item *item,char *pos,uint length);
-bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum enum_field_types type,
-		       char *length, char *decimal,
-		       uint type_modifier,
-		       Item *default_value, Item *on_update_value,
-		       LEX_STRING *comment,
-		       char *change, List<String> *interval_list,
-		       CHARSET_INFO *cs,
-		       uint uint_geom_type);
-Create_field * new_create_field(THD *thd, char *field_name, enum_field_types type,
-				char *length, char *decimals,
-				uint type_modifier, 
-				Item *default_value, Item *on_update_value,
-				LEX_STRING *comment, char *change, 
-				List<String> *interval_list, CHARSET_INFO *cs,
-				uint uint_geom_type);
-void store_position_for_column(const char *name);
-bool add_to_list(THD *thd, SQL_LIST &list,Item *group,bool asc);
-bool push_new_name_resolution_context(THD *thd,
-                                      TABLE_LIST *left_op,
-                                      TABLE_LIST *right_op);
-void add_join_on(TABLE_LIST *b,Item *expr);
-void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields,
-                      SELECT_LEX *lex);
-bool add_proc_to_list(THD *thd, Item *item);
-void unlink_open_table(THD *thd, TABLE *find, bool unlock);
-void drop_open_table(THD *thd, TABLE *table, const char *db_name,
-                     const char *table_name);
-void update_non_unique_table_error(TABLE_LIST *update,
-                                   const char *operation,
-                                   TABLE_LIST *duplicate);
-
-SQL_SELECT *make_select(TABLE *head, table_map const_tables,
-			table_map read_tables, COND *conds,
-                        bool allow_null_cond,  int *error);
-extern Item **not_found_item;
-
 /*
   A set of constants used for checking non aggregated fields and sum
   functions mixture in the ONLY_FULL_GROUP_BY_MODE.
@@ -1424,962 +133,15 @@ extern Item **not_found_item;
 #define SUM_FUNC_USED       2
 
 /*
-  This enumeration type is used only by the function find_item_in_list
-  to return the info on how an item has been resolved against a list
-  of possibly aliased items.
-  The item can be resolved: 
-   - against an alias name of the list's element (RESOLVED_AGAINST_ALIAS)
-   - against non-aliased field name of the list  (RESOLVED_WITH_NO_ALIAS)
-   - against an aliased field name of the list   (RESOLVED_BEHIND_ALIAS)
-   - ignoring the alias name in cases when SQL requires to ignore aliases
-     (e.g. when the resolved field reference contains a table name or
-     when the resolved item is an expression)   (RESOLVED_IGNORING_ALIAS)    
-*/
-enum enum_resolution_type {
-  NOT_RESOLVED=0,
-  RESOLVED_IGNORING_ALIAS,
-  RESOLVED_BEHIND_ALIAS,
-  RESOLVED_WITH_NO_ALIAS,
-  RESOLVED_AGAINST_ALIAS
-};
-Item ** find_item_in_list(Item *item, List<Item> &items, uint *counter,
-                          find_item_error_report_type report_error,
-                          enum_resolution_type *resolution);
-bool get_key_map_from_key_list(key_map *map, TABLE *table,
-                               List<String> *index_list);
-bool insert_fields(THD *thd, Name_resolution_context *context,
-		   const char *db_name, const char *table_name,
-                   List_iterator<Item> *it, bool any_privileges);
-bool setup_tables(THD *thd, Name_resolution_context *context,
-                  List<TABLE_LIST> *from_clause, TABLE_LIST *tables,
-                  TABLE_LIST **leaves, bool select_insert);
-bool setup_tables_and_check_access(THD *thd, 
-                                   Name_resolution_context *context,
-                                   List<TABLE_LIST> *from_clause, 
-                                   TABLE_LIST *tables, 
-                                   TABLE_LIST **leaves, 
-                                   bool select_insert,
-                                   ulong want_access_first,
-                                   ulong want_access);
-int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
-	       List<Item> *sum_func_list, uint wild_num);
-bool setup_fields(THD *thd, Item** ref_pointer_array,
-                  List<Item> &item, enum_mark_columns mark_used_columns,
-                  List<Item> *sum_func_list, bool allow_sum_func);
-inline bool setup_fields_with_no_wrap(THD *thd, Item **ref_pointer_array,
-                                      List<Item> &item,
-                                      enum_mark_columns mark_used_columns,
-                                      List<Item> *sum_func_list,
-                                      bool allow_sum_func)
-{
-  bool res;
-  thd->lex->select_lex.no_wrap_view_item= TRUE;
-  res= setup_fields(thd, ref_pointer_array, item, mark_used_columns, sum_func_list,
-                    allow_sum_func);
-  thd->lex->select_lex.no_wrap_view_item= FALSE;
-  return res;
-}
-int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
-		COND **conds);
-int setup_ftfuncs(SELECT_LEX* select);
-int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order);
-void wait_for_condition(THD *thd, pthread_mutex_t *mutex,
-                        pthread_cond_t *cond);
-int open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags);
-/* open_and_lock_tables with optional derived handling */
-int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, bool derived);
-/* simple open_and_lock_tables without derived handling */
-inline int simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables)
-{
-  return open_and_lock_tables_derived(thd, tables, FALSE);
-}
-/* open_and_lock_tables with derived handling */
-inline int open_and_lock_tables(THD *thd, TABLE_LIST *tables)
-{
-  return open_and_lock_tables_derived(thd, tables, TRUE);
-}
-/* simple open_and_lock_tables without derived handling for single table */
-TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
-                                thr_lock_type lock_type);
-bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags);
-int lock_tables(THD *thd, TABLE_LIST *tables, uint counter, bool *need_reopen);
-int decide_logging_format(THD *thd, TABLE_LIST *tables);
-TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
-			    const char *table_name, bool link_in_list);
-bool rm_temporary_table(handlerton *base, char *path);
-void free_io_cache(TABLE *entry);
-void intern_close_table(TABLE *entry);
-bool close_thread_table(THD *thd, TABLE **table_ptr);
-void close_temporary_tables(THD *thd);
-void close_tables_for_reopen(THD *thd, TABLE_LIST **tables);
-TABLE_LIST *find_table_in_list(TABLE_LIST *table,
-                               TABLE_LIST *TABLE_LIST::*link,
-                               const char *db_name,
-                               const char *table_name);
-TABLE_LIST *unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
-                         bool check_alias);
-TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name);
-TABLE *find_temporary_table(THD *thd, TABLE_LIST *table_list);
-int drop_temporary_table(THD *thd, TABLE_LIST *table_list);
-void close_temporary_table(THD *thd, TABLE *table, bool free_share,
-                           bool delete_table);
-void close_temporary(TABLE *table, bool free_share, bool delete_table);
-bool rename_temporary_table(THD* thd, TABLE *table, const char *new_db,
-			    const char *table_name);
-void remove_db_from_cache(const char *db);
-void flush_tables();
-bool is_equal(const LEX_STRING *a, const LEX_STRING *b);
-char *make_default_log_name(char *buff,const char* log_ext);
-
-#ifdef WITH_PARTITION_STORAGE_ENGINE
-uint fast_alter_partition_table(THD *thd, TABLE *table,
-                                Alter_info *alter_info,
-                                HA_CREATE_INFO *create_info,
-                                TABLE_LIST *table_list,
-                                char *db,
-                                const char *table_name,
-                                uint fast_alter_partition);
-uint set_part_state(Alter_info *alter_info, partition_info *tab_part_info,
-                    enum partition_state part_state);
-uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
-                           HA_CREATE_INFO *create_info,
-                           handlerton *old_db_type,
-                           bool *partition_changed,
-                           uint *fast_alter_partition);
-char *generate_partition_syntax(partition_info *part_info,
-                                uint *buf_length, bool use_sql_alloc,
-                                bool show_partition_options,
-                                HA_CREATE_INFO *create_info,
-                                Alter_info *alter_info);
-#endif
-
-/* bits for last argument to remove_table_from_cache() */
-#define RTFC_NO_FLAG                0x0000
-#define RTFC_OWNED_BY_THD_FLAG      0x0001
-#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
-#define RTFC_CHECK_KILLED_FLAG      0x0004
-bool remove_table_from_cache(THD *thd, const char *db, const char *table,
-                             uint flags);
-
-#define NORMAL_PART_NAME 0
-#define TEMP_PART_NAME 1
-#define RENAMED_PART_NAME 2
-void create_partition_name(char *out, const char *in1,
-                           const char *in2, uint name_variant,
-                           bool translate);
-void create_subpartition_name(char *out, const char *in1,
-                              const char *in2, const char *in3,
-                              uint name_variant);
-
-typedef struct st_lock_param_type
-{
-  TABLE_LIST table_list;
-  ulonglong copied;
-  ulonglong deleted;
-  THD *thd;
-  HA_CREATE_INFO *create_info;
-  Alter_info *alter_info;
-  TABLE *table;
-  KEY *key_info_buffer;
-  const char *db;
-  const char *table_name;
-  uchar *pack_frm_data;
-  enum thr_lock_type old_lock_type;
-  uint key_count;
-  uint db_options;
-  size_t pack_frm_len;
-  partition_info *part_info;
-} ALTER_PARTITION_PARAM_TYPE;
-
-void mem_alloc_error(size_t size);
-
-enum ddl_log_entry_code
-{
-  /*
-    DDL_LOG_EXECUTE_CODE:
-      This is a code that indicates that this is a log entry to
-      be executed, from this entry a linked list of log entries
-      can be found and executed.
-    DDL_LOG_ENTRY_CODE:
-      An entry to be executed in a linked list from an execute log
-      entry.
-    DDL_IGNORE_LOG_ENTRY_CODE:
-      An entry that is to be ignored
-  */
-  DDL_LOG_EXECUTE_CODE = 'e',
-  DDL_LOG_ENTRY_CODE = 'l',
-  DDL_IGNORE_LOG_ENTRY_CODE = 'i'
-};
-
-enum ddl_log_action_code
-{
-  /*
-    The type of action that a DDL_LOG_ENTRY_CODE entry is to
-    perform.
-    DDL_LOG_DELETE_ACTION:
-      Delete an entity
-    DDL_LOG_RENAME_ACTION:
-      Rename an entity
-    DDL_LOG_REPLACE_ACTION:
-      Rename an entity after removing the previous entry with the
-      new name, that is replace this entry.
-  */
-  DDL_LOG_DELETE_ACTION = 'd',
-  DDL_LOG_RENAME_ACTION = 'r',
-  DDL_LOG_REPLACE_ACTION = 's'
-};
-
-
-typedef struct st_ddl_log_entry
-{
-  const char *name;
-  const char *from_name;
-  const char *handler_name;
-  uint next_entry;
-  uint entry_pos;
-  enum ddl_log_entry_code entry_type;
-  enum ddl_log_action_code action_type;
-  /*
-    Most actions have only one phase. REPLACE does however have two
-    phases. The first phase removes the file with the new name if
-    there was one there before and the second phase renames the
-    old name to the new name.
-  */
-  char phase;
-} DDL_LOG_ENTRY;
-
-typedef struct st_ddl_log_memory_entry
-{
-  uint entry_pos;
-  struct st_ddl_log_memory_entry *next_log_entry;
-  struct st_ddl_log_memory_entry *prev_log_entry;
-  struct st_ddl_log_memory_entry *next_active_log_entry;
-} DDL_LOG_MEMORY_ENTRY;
-
-
-bool write_ddl_log_entry(DDL_LOG_ENTRY *ddl_log_entry,
-                           DDL_LOG_MEMORY_ENTRY **active_entry);
-bool write_execute_ddl_log_entry(uint first_entry,
-                                   bool complete,
-                                   DDL_LOG_MEMORY_ENTRY **active_entry);
-bool deactivate_ddl_log_entry(uint entry_no);
-void release_ddl_log_memory_entry(DDL_LOG_MEMORY_ENTRY *log_entry);
-bool sync_ddl_log();
-void release_ddl_log();
-void execute_ddl_log_recovery();
-bool execute_ddl_log_entry(THD *thd, uint first_entry);
-
-extern pthread_mutex_t LOCK_gdl;
-
-#define WFRM_WRITE_SHADOW 1
-#define WFRM_INSTALL_SHADOW 2
-#define WFRM_PACK_FRM 4
-#define WFRM_KEEP_SHARE 8
-bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags);
-int abort_and_upgrade_lock(ALTER_PARTITION_PARAM_TYPE *lpt);
-void close_open_tables_and_downgrade(ALTER_PARTITION_PARAM_TYPE *lpt);
-void mysql_wait_completed_table(ALTER_PARTITION_PARAM_TYPE *lpt, TABLE *my_table);
-
-/* Functions to work with system tables. */
-bool open_system_tables_for_read(THD *thd, TABLE_LIST *table_list,
-                                 Open_tables_state *backup);
-void close_system_tables(THD *thd, Open_tables_state *backup);
-TABLE *open_system_table_for_update(THD *thd, TABLE_LIST *one_table);
-
-TABLE *open_performance_schema_table(THD *thd, TABLE_LIST *one_table,
-                                     Open_tables_state *backup);
-void close_performance_schema_table(THD *thd, Open_tables_state *backup);
-
-bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
-                         bool wait_for_refresh, bool wait_for_placeholders);
-bool close_cached_connection_tables(THD *thd, bool wait_for_refresh,
-                                    LEX_STRING *connect_string,
-                                    bool have_lock = FALSE);
-void copy_field_from_tmp_record(Field *field,int offset);
-bool fill_record(THD *thd, Field **field, List<Item> &values,
-                 bool ignore_errors);
-bool fill_record_n_invoke_before_triggers(THD *thd, List<Item> &fields,
-                                          List<Item> &values,
-                                          bool ignore_errors,
-                                          Table_triggers_list *triggers,
-                                          enum trg_event_type event);
-bool fill_record_n_invoke_before_triggers(THD *thd, Field **field,
-                                          List<Item> &values,
-                                          bool ignore_errors,
-                                          Table_triggers_list *triggers,
-                                          enum trg_event_type event);
-OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild);
-
-inline TABLE_LIST *find_table_in_global_list(TABLE_LIST *table,
-                                             const char *db_name,
-                                             const char *table_name)
-{
-  return find_table_in_list(table, &TABLE_LIST::next_global,
-                            db_name, table_name);
-}
-
-inline TABLE_LIST *find_table_in_local_list(TABLE_LIST *table,
-                                            const char *db_name,
-                                            const char *table_name)
-{
-  return find_table_in_list(table, &TABLE_LIST::next_local,
-                            db_name, table_name);
-}
-
-
-/* sql_calc.cc */
-bool eval_const_cond(COND *cond);
-
-/* sql_load.cc */
-int mysql_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list,
-	        List<Item> &fields_vars, List<Item> &set_fields,
-                List<Item> &set_values_list,
-                enum enum_duplicates handle_duplicates, bool ignore,
-                bool local_file);
-int write_record(THD *thd, TABLE *table, COPY_INFO *info);
-
-/* sql_manager.cc */
-extern bool volatile  mqh_used;
-void start_handle_manager();
-void stop_handle_manager();
-bool mysql_manager_submit(void (*action)());
-
-
-/* sql_test.cc */
-#ifndef DBUG_OFF
-void print_where(COND *cond,const char *info, enum_query_type query_type);
-void print_cached_tables(void);
-void TEST_filesort(SORT_FIELD *sortorder,uint s_length);
-void print_plan(JOIN* join,uint idx, double record_count, double read_time,
-                double current_read_time, const char *info);
-#endif
-void mysql_print_status();
-/* key.cc */
-int find_ref_key(KEY *key, uint key_count, uchar *record, Field *field,
-                 uint *key_length, uint *keypart);
-void key_copy(uchar *to_key, uchar *from_record, KEY *key_info, uint key_length);
-void key_restore(uchar *to_record, uchar *from_key, KEY *key_info,
-                 uint key_length);
-bool key_cmp_if_same(TABLE *form,const uchar *key,uint index,uint key_length);
-void key_unpack(String *to,TABLE *form,uint index);
-bool is_key_used(TABLE *table, uint idx, const MY_BITMAP *fields);
-int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length);
-extern "C" int key_rec_cmp(void *key_info, uchar *a, uchar *b);
-
-bool init_errmessage(void);
-#endif /* MYSQL_SERVER */
-void sql_perror(const char *message);
-bool read_texts(const char *file_name, const char *language,
-                const char ***point, uint error_messages);
-
-bool fn_format_relative_to_data_home(char * to, const char *name,
-				     const char *dir, const char *extension);
-#ifdef MYSQL_SERVER
-File open_binlog(IO_CACHE *log, const char *log_file_name,
-                 const char **errmsg);
-
-/* mysqld.cc */
-extern void MYSQLerror(const char*);
-void refresh_status(THD *thd);
-my_bool mysql_rm_tmp_tables(void);
-void handle_connection_in_main_thread(THD *thd);
-void create_thread_to_handle_connection(THD *thd);
-void unlink_thd(THD *thd);
-bool one_thread_per_connection_end(THD *thd, bool put_in_cache);
-void flush_thread_cache();
-
-/* item_func.cc */
-extern bool check_reserved_words(LEX_STRING *name);
-extern enum_field_types agg_field_type(Item **items, uint nitems);
-
-/* strfunc.cc */
-ulonglong find_set(TYPELIB *lib, const char *x, uint length, CHARSET_INFO *cs,
-		   char **err_pos, uint *err_len, bool *set_warning);
-ulonglong find_set_from_flags(TYPELIB *lib, uint default_name,
-                              ulonglong cur_set, ulonglong default_set,
-                              const char *str, uint length, CHARSET_INFO *cs,
-                              char **err_pos, uint *err_len, bool *set_warning);
-uint find_type(const TYPELIB *lib, const char *find, uint length,
-               bool part_match);
-uint find_type2(const TYPELIB *lib, const char *find, uint length,
-                CHARSET_INFO *cs);
-void unhex_type2(TYPELIB *lib);
-uint check_word(TYPELIB *lib, const char *val, const char *end,
-		const char **end_of_word);
-int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
-                         CHARSET_INFO * const cs);
-
-
-bool is_keyword(const char *name, uint len);
-
-#define MY_DB_OPT_FILE "db.opt"
-bool my_database_names_init(void);
-void my_database_names_free(void);
-bool check_db_dir_existence(const char *db_name);
-bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create);
-bool load_db_opt_by_name(THD *thd, const char *db_name,
-                         HA_CREATE_INFO *db_create_info);
-CHARSET_INFO *get_default_db_collation(THD *thd, const char *db_name);
-bool my_dbopt_init(void);
-void my_dbopt_cleanup(void);
-extern int creating_database; // How many database locks are made
-extern int creating_table;    // How many mysql_create_table() are running
-
-/*
   External variables
 */
 
-extern time_t server_start_time, flush_status_time;
-#endif /* MYSQL_SERVER */
-#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
-extern uint mysql_data_home_len;
-
-extern MYSQL_PLUGIN_IMPORT char  *mysql_data_home;
-extern char server_version[SERVER_VERSION_LENGTH];
-extern MYSQL_PLUGIN_IMPORT char mysql_real_data_home[];
-extern char mysql_unpacked_real_data_home[];
-
-extern CHARSET_INFO *character_set_filesystem;
-#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
-#ifdef MYSQL_SERVER
-extern char *opt_mysql_tmpdir, mysql_charsets_dir[],
-            def_ft_boolean_syntax[sizeof(ft_boolean_syntax)];
-extern int mysql_unpacked_real_data_home_len;
-#define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list))
-extern MYSQL_PLUGIN_IMPORT MY_TMPDIR mysql_tmpdir_list;
-extern const LEX_STRING command_name[];
-
-extern const char *first_keyword, *delayed_user, *binary_keyword;
-extern MYSQL_PLUGIN_IMPORT const char  *my_localhost;
-extern MYSQL_PLUGIN_IMPORT const char **errmesg;			/* Error messages */
-
-extern const char *myisam_recover_options_str;
-extern const char *in_left_expr_name, *in_additional_cond, *in_having_cond;
-extern const char * const TRG_EXT;
-extern const char * const TRN_EXT;
-extern Eq_creator eq_creator;
-extern Ne_creator ne_creator;
-extern Gt_creator gt_creator;
-extern Lt_creator lt_creator;
-extern Ge_creator ge_creator;
-extern Le_creator le_creator;
-extern char lc_messages_dir[FN_REFLEN];
-#endif /* MYSQL_SERVER */
-#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
-extern MYSQL_PLUGIN_IMPORT char reg_ext[FN_EXTLEN];
-extern MYSQL_PLUGIN_IMPORT uint reg_ext_length;
-#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
-#ifdef MYSQL_SERVER
-extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN];
-extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
-extern char default_logfile_name[FN_REFLEN];
-extern char log_error_file[FN_REFLEN], *opt_tc_log_file;
-extern ulonglong log_10_int[20];
-extern ulonglong keybuff_size;
-extern ulonglong thd_startup_options;
-extern ulong thread_id;
-extern ulong binlog_cache_use, binlog_cache_disk_use;
-extern ulong aborted_threads,aborted_connects;
-extern ulong delayed_insert_timeout;
-extern ulong delayed_insert_limit, delayed_queue_size;
-extern ulong delayed_insert_threads, delayed_insert_writes;
-extern ulong delayed_rows_in_use,delayed_insert_errors;
-extern ulong slave_open_temp_tables;
-extern ulong query_cache_size, query_cache_min_res_unit;
-extern ulong slow_launch_threads, slow_launch_time;
-extern ulong table_cache_size, table_def_size;
-extern MYSQL_PLUGIN_IMPORT ulong max_connections;
-extern ulong max_connect_errors, connect_timeout;
-extern ulong slave_net_timeout, slave_trans_retries;
-extern uint max_user_connections;
-extern ulong what_to_log,flush_time;
-extern ulong query_buff_size;
-extern ulong max_prepared_stmt_count, prepared_stmt_count;
-extern ulong binlog_cache_size, open_files_limit;
-extern ulonglong max_binlog_cache_size;
-extern ulong max_binlog_size, max_relay_log_size;
-extern ulong opt_binlog_rows_event_max_size;
-extern ulong rpl_recovery_rank, thread_cache_size, thread_pool_size;
-extern ulong back_log;
-#endif /* MYSQL_SERVER */
-#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
-extern ulong MYSQL_PLUGIN_IMPORT specialflag;
-#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
-#ifdef MYSQL_SERVER
-extern ulong current_pid;
-extern ulong expire_logs_days;
-extern uint sync_binlog_period, sync_relaylog_period, 
-            sync_relayloginfo_period, sync_masterinfo_period;
-extern ulong opt_tc_log_size, tc_log_max_pages_used, tc_log_page_size;
-extern ulong tc_log_page_waits;
-extern my_bool relay_log_purge, opt_innodb_safe_binlog, opt_innodb;
-extern my_bool relay_log_recovery;
-extern uint test_flags,select_errors,ha_open_options;
-extern uint protocol_version, mysqld_port, dropping_tables;
-extern uint delay_key_write_options;
-#endif /* MYSQL_SERVER */
-#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
-extern MYSQL_PLUGIN_IMPORT uint lower_case_table_names;
-#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
-#ifdef MYSQL_SERVER
-extern bool opt_endinfo, using_udf_functions;
-extern my_bool locked_in_memory;
-extern bool opt_using_transactions;
-#endif /* MYSQL_SERVER */
-#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
-extern MYSQL_PLUGIN_IMPORT bool mysqld_embedded;
-#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
-#ifdef MYSQL_SERVER
-extern bool opt_large_files, server_id_supplied;
-extern bool opt_update_log, opt_bin_log, opt_error_log;
-extern my_bool opt_log, opt_slow_log;
-extern ulong log_output_options;
-extern my_bool opt_log_queries_not_using_indexes;
-extern bool opt_disable_networking, opt_skip_show_db;
-extern bool opt_ignore_builtin_innodb;
-extern my_bool opt_character_set_client_handshake;
-extern bool volatile abort_loop, shutdown_in_progress;
-extern bool in_bootstrap;
-extern uint volatile thread_count, thread_running, global_read_lock;
-extern uint connection_count;
-extern my_bool opt_sql_bin_update, opt_safe_user_create, opt_no_mix_types;
-extern my_bool opt_safe_show_db, opt_local_infile, opt_myisam_use_mmap;
-extern my_bool opt_slave_compressed_protocol, use_temp_pool;
-extern ulong slave_exec_mode_options;
-extern my_bool opt_readonly, lower_case_file_system;
-extern my_bool opt_enable_named_pipe, opt_sync_frm, opt_allow_suspicious_udfs;
-extern my_bool opt_secure_auth;
-extern char* opt_secure_file_priv;
-extern my_bool opt_log_slow_admin_statements, opt_log_slow_slave_statements;
-extern my_bool sp_automatic_privileges, opt_noacl;
-extern my_bool opt_old_style_user_limits, trust_function_creators;
-extern uint opt_crash_binlog_innodb;
-extern char *shared_memory_base_name, *mysqld_unix_port;
-extern my_bool opt_enable_shared_memory;
-extern char *default_tz_name;
-#endif /* MYSQL_SERVER */
-#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
-extern my_bool opt_large_pages;
-extern uint opt_large_page_size;
-#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
-#ifdef MYSQL_SERVER
-extern char *opt_logname, *opt_slow_logname;
-extern const char *log_output_str;
-
-extern MYSQL_PLUGIN_IMPORT MYSQL_BIN_LOG mysql_bin_log;
-extern LOGGER logger;
-extern TABLE_LIST general_log, slow_log;
-extern FILE *bootstrap_file;
-extern int bootstrap_error;
-extern FILE *stderror_file;
-extern pthread_key(MEM_ROOT**,THR_MALLOC);
-extern pthread_mutex_t LOCK_mysql_create_db, LOCK_open, LOCK_lock_db,
-       LOCK_mapped_file,LOCK_user_locks, LOCK_status,
-       LOCK_error_log, LOCK_delayed_insert, LOCK_uuid_generator,
-       LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone,
-       LOCK_slave_list, LOCK_active_mi, LOCK_manager, LOCK_global_read_lock,
-       LOCK_global_system_variables, LOCK_user_conn,
-       LOCK_prepared_stmt_count, LOCK_error_messages, LOCK_connection_count;
-extern MYSQL_PLUGIN_IMPORT pthread_mutex_t LOCK_thread_count;
-#ifdef HAVE_OPENSSL
-extern pthread_mutex_t LOCK_des_key_file;
-#endif
-extern pthread_mutex_t LOCK_server_started;
-extern pthread_cond_t COND_server_started;
-extern int mysqld_server_started;
-extern rw_lock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave;
-extern rw_lock_t LOCK_system_variables_hash;
-extern pthread_cond_t COND_refresh, COND_thread_count, COND_manager;
-extern pthread_cond_t COND_global_read_lock;
-extern pthread_attr_t connection_attrib;
-extern I_List<THD> threads;
-extern I_List<NAMED_LIST> key_caches;
-extern MY_BITMAP temp_pool;
-extern String my_empty_string;
-extern const String my_null_string;
-extern SHOW_VAR status_vars[];
-#endif /* MYSQL_SERVER */
-#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
-extern MYSQL_PLUGIN_IMPORT struct system_variables global_system_variables;
-#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
-#ifdef MYSQL_SERVER
-extern struct system_variables max_system_variables;
-extern struct system_status_var global_status_var;
-extern struct rand_struct sql_rand;
-
-extern const char *opt_date_time_formats[];
-extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[];
-
-extern String null_string;
-extern HASH open_cache, lock_db_cache;
-extern TABLE *unused_tables;
-extern const char* any_db;
-extern struct my_option my_long_options[];
-extern const LEX_STRING view_type;
-extern scheduler_functions thread_scheduler;
-extern TYPELIB thread_handling_typelib;
-extern uint8 uc_update_queries[SQLCOM_END+1];
-extern uint sql_command_flags[];
-extern TYPELIB log_output_typelib;
-
-/* optional things, have_* variables */
-extern SHOW_COMP_OPTION have_profiling;
-
-extern handlerton *partition_hton;
-extern handlerton *myisam_hton;
-extern handlerton *heap_hton;
-
-extern SHOW_COMP_OPTION have_ssl, have_symlink, have_dlopen;
-extern SHOW_COMP_OPTION have_query_cache;
-extern SHOW_COMP_OPTION have_geometry, have_rtree_keys;
-extern SHOW_COMP_OPTION have_crypt;
-extern SHOW_COMP_OPTION have_compress;
-
-extern int orig_argc;
-extern char **orig_argv;
-extern const char *load_default_groups[];
-
-#ifndef __WIN__
-extern pthread_t signal_thread;
-#endif
-
-#ifdef HAVE_OPENSSL
-extern struct st_VioSSLFd * ssl_acceptor_fd;
-#endif /* HAVE_OPENSSL */
-
-MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **table, uint count,
-                              uint flags, bool *need_reopen);
-/* mysql_lock_tables() and open_table() flags bits */
-#define MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK      0x0001
-#define MYSQL_LOCK_IGNORE_FLUSH                 0x0002
-#define MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN        0x0004
-#define MYSQL_OPEN_TEMPORARY_ONLY               0x0008
-#define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY      0x0010
-#define MYSQL_LOCK_PERF_SCHEMA                  0x0020
-
-void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock);
-void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock);
-void mysql_unlock_some_tables(THD *thd, TABLE **table,uint count);
-void mysql_lock_remove(THD *thd, MYSQL_LOCK *locked,TABLE *table,
-                       bool always_unlock);
-void mysql_lock_abort(THD *thd, TABLE *table, bool upgrade_lock);
-void mysql_lock_downgrade_write(THD *thd, TABLE *table,
-                                thr_lock_type new_lock_type);
-bool mysql_lock_abort_for_thread(THD *thd, TABLE *table);
-MYSQL_LOCK *mysql_lock_merge(MYSQL_LOCK *a,MYSQL_LOCK *b);
-TABLE_LIST *mysql_lock_have_duplicate(THD *thd, TABLE_LIST *needle,
-                                      TABLE_LIST *haystack);
-bool lock_global_read_lock(THD *thd);
-void unlock_global_read_lock(THD *thd);
-bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh,
-                              bool is_not_commit);
-void start_waiting_global_read_lock(THD *thd);
-bool make_global_read_lock_block_commit(THD *thd);
-bool set_protect_against_global_read_lock(void);
-void unset_protect_against_global_read_lock(void);
-void broadcast_refresh(void);
-
-/* Lock based on name */
-int lock_and_wait_for_table_name(THD *thd, TABLE_LIST *table_list);
-int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use);
-void unlock_table_name(THD *thd, TABLE_LIST *table_list);
-bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list);
-bool lock_table_names(THD *thd, TABLE_LIST *table_list);
-void unlock_table_names(THD *thd, TABLE_LIST *table_list,
-			TABLE_LIST *last_table);
-bool lock_table_names_exclusively(THD *thd, TABLE_LIST *table_list);
-bool is_table_name_exclusively_locked_by_this_thread(THD *thd, 
-                                                     TABLE_LIST *table_list);
-bool is_table_name_exclusively_locked_by_this_thread(THD *thd, uchar *key,
-                                                     int key_length);
-
-
-/* old unireg functions */
-
-void unireg_init(ulong options);
-void unireg_end(void) __attribute__((noreturn));
-bool mysql_create_frm(THD *thd, const char *file_name,
-                      const char *db, const char *table,
-		      HA_CREATE_INFO *create_info,
-		      List<Create_field> &create_field,
-		      uint key_count,KEY *key_info,handler *db_type);
-int rea_create_table(THD *thd, const char *path,
-                     const char *db, const char *table_name,
-                     HA_CREATE_INFO *create_info,
-  		     List<Create_field> &create_field,
-                     uint key_count,KEY *key_info,
-                     handler *file);
-int format_number(uint inputflag,uint max_length,char * pos,uint length,
-		  char * *errpos);
-
-/* table.cc */
-TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key,
-                               uint key_length);
-void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
-                          uint key_length,
-                          const char *table_name, const char *path);
-void free_table_share(TABLE_SHARE *share);
-int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags);
-void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
-int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
-                          uint db_stat, uint prgflag, uint ha_open_flags,
-                          TABLE *outparam, bool is_create_table);
-int readfrm(const char *name, uchar **data, size_t *length);
-int writefrm(const char* name, const uchar* data, size_t len);
-int closefrm(TABLE *table, bool free_share);
-int read_string(File file, uchar* *to, size_t length);
-void free_blobs(TABLE *table);
-void free_field_buffers_larger_than(TABLE *table, uint32 size);
-int set_zone(int nr,int min_zone,int max_zone);
-ulong convert_period_to_month(ulong period);
-ulong convert_month_to_period(ulong month);
-void get_date_from_daynr(long daynr,uint *year, uint *month,
-			 uint *day);
-my_time_t TIME_to_timestamp(THD *thd, const MYSQL_TIME *t, my_bool *not_exist);
-bool str_to_time_with_warn(const char *str,uint length,MYSQL_TIME *l_time);
-timestamp_type str_to_datetime_with_warn(const char *str, uint length,
-                                         MYSQL_TIME *l_time, uint flags);
-void localtime_to_TIME(MYSQL_TIME *to, struct tm *from);
-void calc_time_from_sec(MYSQL_TIME *to, long seconds, long microseconds);
-
-void make_truncated_value_warning(THD *thd, MYSQL_ERROR::enum_warning_level level,
-                                  const char *str_val,
-				  uint str_length, timestamp_type time_type,
-                                  const char *field_name);
-
-bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, INTERVAL interval);
-bool calc_time_diff(MYSQL_TIME *l_time1, MYSQL_TIME *l_time2, int l_sign,
-                    longlong *seconds_out, long *microseconds_out);
-
-extern LEX_STRING interval_type_to_name[];
-
-extern DATE_TIME_FORMAT *date_time_format_make(timestamp_type format_type,
-					       const char *format_str,
-					       uint format_length);
-extern DATE_TIME_FORMAT *date_time_format_copy(THD *thd,
-					       DATE_TIME_FORMAT *format);
-const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
-				     timestamp_type type);
-extern bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
-			   timestamp_type type, String *str);
-void make_datetime(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
-                   String *str);
-void make_date(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
-               String *str);
-void make_time(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
-               String *str);
-int my_time_compare(MYSQL_TIME *a, MYSQL_TIME *b);
-longlong get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
-                            Item *warn_item, bool *is_null);
-
-int test_if_number(char *str,int *res,bool allow_wildcards);
-void change_byte(uchar *,uint,char,char);
-ha_rows filesort(THD *thd, TABLE *form,struct st_sort_field *sortorder,
-		 uint s_length, SQL_SELECT *select,
-		 ha_rows max_rows, bool sort_positions,
-                 ha_rows *examined_rows);
-void filesort_free_buffers(TABLE *table, bool full);
-void change_double_for_sort(double nr,uchar *to);
-double my_double_round(double value, longlong dec, bool dec_unsigned,
-                       bool truncate);
-int get_quick_record(SQL_SELECT *select);
-
-int calc_weekday(long daynr,bool sunday_first_day_of_week);
-uint calc_week(MYSQL_TIME *l_time, uint week_behaviour, uint *year);
-void find_date(char *pos,uint *vek,uint flag);
-TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
-TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings);
-ulong get_form_pos(File file, uchar *head, TYPELIB *save_names);
-ulong make_new_entry(File file,uchar *fileinfo,TYPELIB *formnames,
-		     const char *newname);
-ulong next_io_size(ulong pos);
-void append_unescaped(String *res, const char *pos, uint length);
-int create_frm(THD *thd, const char *name, const char *db, const char *table,
-               uint reclength, uchar *fileinfo,
-	       HA_CREATE_INFO *create_info, uint keys);
-void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form);
-int rename_file_ext(const char * from,const char * to,const char * ext);
-bool check_db_name(LEX_STRING *db);
-bool check_column_name(const char *name);
-bool check_table_name(const char *name, uint length);
-char *get_field(MEM_ROOT *mem, Field *field);
-bool get_field(MEM_ROOT *mem, Field *field, class String *res);
-int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr);
-char *fn_rext(char *name);
-
-/* Conversion functions */
-#endif /* MYSQL_SERVER */
-#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
-uint strconvert(CHARSET_INFO *from_cs, const char *from,
-                CHARSET_INFO *to_cs, char *to, uint to_length, uint *errors);
-/* depends on errmsg.txt Database `db`, Table `t` ... */
-#define EXPLAIN_FILENAME_MAX_EXTRA_LENGTH 63
-enum enum_explain_filename_mode
-{
-  EXPLAIN_ALL_VERBOSE= 0,
-  EXPLAIN_PARTITIONS_VERBOSE,
-  EXPLAIN_PARTITIONS_AS_COMMENT
-};
-uint explain_filename(THD* thd, const char *from, char *to, uint to_length,
-                      enum_explain_filename_mode explain_mode);
-uint filename_to_tablename(const char *from, char *to, uint to_length);
-uint tablename_to_filename(const char *from, char *to, uint to_length);
-uint check_n_cut_mysql50_prefix(const char *from, char *to, uint to_length);
-#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
-#ifdef MYSQL_SERVER
-uint build_table_filename(char *buff, size_t bufflen, const char *db,
-                          const char *table, const char *ext, uint flags);
-const char *get_canonical_filename(handler *file, const char *path,
-                                   char *tmp_path);
-
-#define MYSQL50_TABLE_NAME_PREFIX         "#mysql50#"
-#define MYSQL50_TABLE_NAME_PREFIX_LENGTH  9
-
-uint build_table_shadow_filename(char *buff, size_t bufflen, 
-                                 ALTER_PARTITION_PARAM_TYPE *lpt);
-/* Flags for conversion functions. */
-#define FN_FROM_IS_TMP  (1 << 0)
-#define FN_TO_IS_TMP    (1 << 1)
-#define FN_IS_TMP       (FN_FROM_IS_TMP | FN_TO_IS_TMP)
-#define NO_FRM_RENAME   (1 << 2)
-#define FRM_ONLY        (1 << 3)
-
-/* from hostname.cc */
-struct in_addr;
-char * ip_to_hostname(struct in_addr *in,uint *errors);
-void inc_host_errors(struct in_addr *in);
-void reset_host_errors(struct in_addr *in);
-bool hostname_cache_init();
-void hostname_cache_free();
-void hostname_cache_refresh(void);
-
-/* sql_cache.cc */
-extern bool sql_cache_init();
-extern void sql_cache_free();
-extern int sql_cache_hit(THD *thd, char *inBuf, uint length);
-
-/* item_func.cc */
-Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name,
-		     LEX_STRING component);
-int get_var_with_binlog(THD *thd, enum_sql_command sql_command,
-                        LEX_STRING &name, user_var_entry **out_entry);
-/* log.cc */
-bool flush_error_log(void);
-
-/* sql_list.cc */
-void free_list(I_List <i_string_pair> *list);
-void free_list(I_List <i_string> *list);
-
 /* sql_yacc.cc */
 #ifndef DBUG_OFF
 extern void turn_parser_debug_on();
-#endif
 
-/* frm_crypt.cc */
-#ifdef HAVE_CRYPTED_FRM
-SQL_CRYPT *get_crypt_for_frm(void);
 #endif
 
-/* password.c */
-extern "C" void my_make_scrambled_password_323(char *to, const char *password,
-                                               size_t pass_len);
-extern "C" void my_make_scrambled_password(char *to, const char *password,
-                                           size_t pass_len);
-
-#include "sql_view.h"
-
-/* Some inline functions for more speed */
-
-inline bool add_item_to_list(THD *thd, Item *item)
-{
-  return thd->lex->current_select->add_item_to_list(thd, item);
-}
-
-inline bool add_value_to_list(THD *thd, Item *value)
-{
-  return thd->lex->value_list.push_back(value);
-}
-
-inline bool add_order_to_list(THD *thd, Item *item, bool asc)
-{
-  return thd->lex->current_select->add_order_to_list(thd, item, asc);
-}
-
-inline bool add_group_to_list(THD *thd, Item *item, bool asc)
-{
-  return thd->lex->current_select->add_group_to_list(thd, item, asc);
-}
-
-inline void mark_as_null_row(TABLE *table)
-{
-  table->null_row=1;
-  table->status|=STATUS_NULL_ROW;
-  bfill(table->null_flags,table->s->null_bytes,255);
-}
-
-inline void table_case_convert(char * name, uint length)
-{
-  if (lower_case_table_names)
-    files_charset_info->cset->casedn(files_charset_info,
-                                     name, length, name, length);
-}
-
-inline const char *table_case_name(HA_CREATE_INFO *info, const char *name)
-{
-  return ((lower_case_table_names == 2 && info->alias) ? info->alias : name);
-}
-
-inline ulong sql_rnd_with_mutex()
-{
-  pthread_mutex_lock(&LOCK_thread_count);
-  ulong tmp=(ulong) (my_rnd(&sql_rand) * 0xffffffff); /* make all bits random */
-  pthread_mutex_unlock(&LOCK_thread_count);
-  return tmp;
-}
-
-Comp_creator *comp_eq_creator(bool invert);
-Comp_creator *comp_ge_creator(bool invert);
-Comp_creator *comp_gt_creator(bool invert);
-Comp_creator *comp_le_creator(bool invert);
-Comp_creator *comp_lt_creator(bool invert);
-Comp_creator *comp_ne_creator(bool invert);
-
-Item * all_any_subquery_creator(Item *left_expr,
-				chooser_compare_func_creator cmp,
-				bool all,
-				SELECT_LEX *select_lex);
-
-/**
-  clean/setup table fields and map.
-
-  @param table        TABLE structure pointer (which should be setup)
-  @param table_list   TABLE_LIST structure pointer (owner of TABLE)
-  @param tablenr     table number
-*/
-
-
-inline void setup_table_map(TABLE *table, TABLE_LIST *table_list, uint tablenr)
-{
-  table->used_fields= 0;
-  table->const_table= 0;
-  table->null_row= 0;
-  table->status= STATUS_NO_RECORD;
-  table->maybe_null= table_list->outer_join;
-  TABLE_LIST *embedding= table_list->embedding;
-  while (!table->maybe_null && embedding)
-  {
-    table->maybe_null= embedding->outer_join;
-    embedding= embedding->embedding;
-  }
-  table->tablenr= tablenr;
-  table->map= (table_map) 1 << tablenr;
-  table->force_index= table_list->force_index;
-  table->force_index_order= table->force_index_group= 0;
-  table->covering_keys= table->s->keys_for_keyread;
-  table->merge_keys.clear_all();
-}
-
-
 /**
   convert a hex digit into number.
 */
@@ -2394,97 +156,7 @@ inline int hexchar_to_int(char c)
   return -1;
 }
 
-/**
-  return true if the table was created explicitly.
-*/
-inline bool is_user_table(TABLE * table)
-{
-  const char *name= table->s->table_name.str;
-  return strncmp(name, tmp_file_prefix, tmp_file_prefix_length);
-}
-
-/*
-  Some functions that are different in the embedded library and the normal
-  server
-*/
-
-#ifndef EMBEDDED_LIBRARY
-extern "C" void unireg_abort(int exit_code) __attribute__((noreturn));
-void kill_delayed_threads(void);
-bool check_stack_overrun(THD *thd, long margin, uchar *dummy);
-#else
-extern "C" void unireg_clear(int exit_code);
-#define unireg_abort(exit_code) do { unireg_clear(exit_code); DBUG_RETURN(exit_code); } while(0)
-inline void kill_delayed_threads(void) {}
-#define check_stack_overrun(A, B, C) 0
-#endif
-
-/* Used by handlers to store things in schema tables */
-#define IS_FILES_FILE_ID              0
-#define IS_FILES_FILE_NAME            1
-#define IS_FILES_FILE_TYPE            2
-#define IS_FILES_TABLESPACE_NAME      3
-#define IS_FILES_TABLE_CATALOG        4
-#define IS_FILES_TABLE_SCHEMA         5
-#define IS_FILES_TABLE_NAME           6
-#define IS_FILES_LOGFILE_GROUP_NAME   7
-#define IS_FILES_LOGFILE_GROUP_NUMBER 8
-#define IS_FILES_ENGINE               9
-#define IS_FILES_FULLTEXT_KEYS       10
-#define IS_FILES_DELETED_ROWS        11
-#define IS_FILES_UPDATE_COUNT        12
-#define IS_FILES_FREE_EXTENTS        13
-#define IS_FILES_TOTAL_EXTENTS       14
-#define IS_FILES_EXTENT_SIZE         15
-#define IS_FILES_INITIAL_SIZE        16
-#define IS_FILES_MAXIMUM_SIZE        17
-#define IS_FILES_AUTOEXTEND_SIZE     18
-#define IS_FILES_CREATION_TIME       19
-#define IS_FILES_LAST_UPDATE_TIME    20
-#define IS_FILES_LAST_ACCESS_TIME    21
-#define IS_FILES_RECOVER_TIME        22
-#define IS_FILES_TRANSACTION_COUNTER 23
-#define IS_FILES_VERSION             24
-#define IS_FILES_ROW_FORMAT          25
-#define IS_FILES_TABLE_ROWS          26
-#define IS_FILES_AVG_ROW_LENGTH      27
-#define IS_FILES_DATA_LENGTH         28
-#define IS_FILES_MAX_DATA_LENGTH     29
-#define IS_FILES_INDEX_LENGTH        30
-#define IS_FILES_DATA_FREE           31
-#define IS_FILES_CREATE_TIME         32
-#define IS_FILES_UPDATE_TIME         33
-#define IS_FILES_CHECK_TIME          34
-#define IS_FILES_CHECKSUM            35
-#define IS_FILES_STATUS              36
-#define IS_FILES_EXTRA               37
-void init_fill_schema_files_row(TABLE* table);
-bool schema_table_store_record(THD *thd, TABLE *table);
-
-/* sql/item_create.cc */
-int item_create_init();
-void item_create_cleanup();
-
-bool show_create_trigger(THD *thd, const sp_name *trg_name);
-
-inline void lex_string_set(LEX_STRING *lex_str, const char *c_str)
-{
-  lex_str->str= (char *) c_str;
-  lex_str->length= strlen(c_str);
-}
-
-bool load_charset(MEM_ROOT *mem_root,
-                  Field *field,
-                  CHARSET_INFO *dflt_cs,
-                  CHARSET_INFO **cs);
-
-bool load_collation(MEM_ROOT *mem_root,
-                    Field *field,
-                    CHARSET_INFO *dflt_cl,
-                    CHARSET_INFO **cl);
-
 #endif /* MYSQL_SERVER */
-extern "C" int test_if_data_home_dir(const char *dir);
 
 #endif /* MYSQL_CLIENT */
 

=== renamed file 'sql/mysql_priv.h.pp' => 'sql/sql_priv.h.pp'
=== modified file 'sql/sql_profile.cc'
--- a/sql/sql_profile.cc	2009-10-21 20:02:06 +0000
+++ b/sql/sql_profile.cc	2009-11-18 08:54:54 +0000
@@ -29,8 +29,12 @@
 */
 
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "sql_profile.h"
 #include "my_sys.h"
+#include "sql_show.h"                     // schema_table_store_record
+#include "sql_class.h"                    // THD
 
 #define TIME_FLOAT_DIGITS 9
 /** two vals encoded: (dec*100)+len */

=== modified file 'sql/sql_profile.h'
--- a/sql/sql_profile.h	2009-10-09 13:59:25 +0000
+++ b/sql/sql_profile.h	2009-11-18 08:54:54 +0000
@@ -24,6 +24,12 @@
 #endif
 #endif
 
+class Item;
+class TABLE_LIST;
+class THD;
+typedef struct st_field_info ST_FIELD_INFO;
+typedef struct st_schema_table ST_SCHEMA_TABLE;
+
 extern ST_FIELD_INFO query_profile_statistics_info[];
 int fill_query_profile_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond);
 int make_profile_table_for_show(THD *thd, ST_SCHEMA_TABLE *schema_table);
@@ -42,7 +48,8 @@ int make_profile_table_for_show(THD *thd
 
 
 #if defined(ENABLED_PROFILING)
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 
 #ifdef HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>

=== modified file 'sql/sql_rename.cc'
--- a/sql/sql_rename.cc	2009-10-16 10:29:42 +0000
+++ b/sql/sql_rename.cc	2009-11-18 08:54:54 +0000
@@ -17,9 +17,18 @@
   Atomic rename of table;  RENAME TABLE t1 to t2, tmp to t1 [,...]
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_rename.h"
+#include "sql_cache.h"                          // query_cache_*
+#include "sql_table.h"                         // build_table_filename
+#include "sql_view.h"             // mysql_frm_type, mysql_rename_view
 #include "sql_trigger.h"
-
+#include "lock.h"       // wait_if_global_read_lock, lock_table_names,
+                        // unlock_table_names,
+                        // start_waiting_global_read_lock
+#include "sql_base.h"   // tdc_remove_table
+#include "sql_handler.h"                        // mysql_ha_rm_tables
 
 static TABLE_LIST *rename_tables(THD *thd, TABLE_LIST *table_list,
 				 bool skip_error);

=== added file 'sql/sql_rename.h'
--- a/sql/sql_rename.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_rename.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,27 @@
+#ifndef SQL_RENAME_INCLUDED
+#define SQL_RENAME_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+class THD;
+struct TABLE_LIST;
+
+bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent);
+bool do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db,
+               char *new_table_name, char *new_table_alias,
+               bool skip_error);
+
+#endif /* SQL_RENAME_INCLUDED */

=== modified file 'sql/sql_repl.cc'
--- a/sql/sql_repl.cc	2009-11-02 11:10:04 +0000
+++ b/sql/sql_repl.cc	2009-11-18 08:54:54 +0000
@@ -13,11 +13,14 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_parse.h"                          // check_access
 #ifdef HAVE_REPLICATION
 
 #include "rpl_mi.h"
 #include "sql_repl.h"
+#include "sql_acl.h"                            // SUPER_ACL
 #include "log_event.h"
 #include "rpl_filter.h"
 #include <my_dir.h>

=== modified file 'sql/sql_repl.h'
--- a/sql/sql_repl.h	2009-09-23 21:32:31 +0000
+++ b/sql/sql_repl.h	2009-11-18 08:54:54 +0000
@@ -65,6 +65,7 @@ typedef struct st_load_file_info
 
 int log_loaded_block(IO_CACHE* file);
 int init_replication_sys_vars();
+void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags);
 
 #endif /* HAVE_REPLICATION */
 

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2009-11-10 07:31:33 +0000
+++ b/sql/sql_select.cc	2009-11-18 08:54:54 +0000
@@ -28,16 +28,33 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #include "sql_select.h"
+#include "sql_cache.h"                          // query_cache_*
+#include "sql_table.h"                          // primary_key_name
 #include "sql_cursor.h"
 #include "probes_mysql.h"
-
+#include "key.h"                 // key_copy, key_cmp, key_cmp_if_same
+#include "lock.h"                // mysql_unlock_some_tables,
+                                 // mysql_unlock_read_tables
+#include "sql_show.h"            // append_identifier
+#include "sql_base.h"            // setup_wild, setup_fields, fill_record
+#include "sql_parse.h"                          // check_stack_overrun
+#include "sql_partition.h"       // make_used_partitions_str
+#include "sql_acl.h"             // *_ACL
+#include "sql_test.h"            // print_where, print_keyuse_array,
+                                 // print_sjm, print_plan
+#include "records.h"             // init_read_record, end_read_record
+#include "filesort.h"            // filesort_free_buffers
+#include "sql_union.h"           // mysql_union
 #include <m_ctype.h>
 #include <my_bit.h>
 #include <hash.h>
 #include <ft_global.h>
 
+#define PREV_BITS(type,A)	((type) (((type) 1 << (A)) -1))
+
 const char *join_type_str[]={ "UNKNOWN","system","const","eq_ref","ref",
 			      "MAYBE_REF","ALL","range","index","fulltext",
 			      "ref_or_null","unique_subquery","index_subquery",

=== modified file 'sql/sql_select.h'
--- a/sql/sql_select.h	2009-11-06 16:13:33 +0000
+++ b/sql/sql_select.h	2009-11-18 08:54:54 +0000
@@ -30,6 +30,10 @@
 
 #include "procedure.h"
 #include <myisam.h>
+#include "sql_array.h"                        /* Array */
+#include "records.h"                          /* READ_RECORD */
+#include "opt_range.h"                /* SQL_SELECT, QUICK_SELECT_I */
+
 
 typedef struct keyuse_t {
   TABLE *table;
@@ -762,6 +766,46 @@ bool error_if_full_join(JOIN *join);
 int report_error(TABLE *table, int error);
 int safe_index_read(JOIN_TAB *tab);
 COND *remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value);
+int get_quick_record(SQL_SELECT *select);
+SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length,
+                                  SORT_FIELD *sortorder);
+int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
+		List<Item> &fields, List <Item> &all_fields, ORDER *order);
+int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
+		List<Item> &fields, List<Item> &all_fields, ORDER *order,
+		bool *hidden_group_fields);
+bool fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select,
+                   Item **ref_pointer_array);
+
+bool handle_select(THD *thd, LEX *lex, select_result *result,
+                   ulong setup_tables_done_option);
+bool mysql_select(THD *thd, Item ***rref_pointer_array,
+                  TABLE_LIST *tables, uint wild_num,  List<Item> &list,
+                  COND *conds, uint og_num, ORDER *order, ORDER *group,
+                  Item *having, ORDER *proc_param, ulonglong select_type, 
+                  select_result *result, SELECT_LEX_UNIT *unit, 
+                  SELECT_LEX *select_lex);
+void free_underlaid_joins(THD *thd, SELECT_LEX *select);
+bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit,
+                         select_result *result);
+Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
+			Item ***copy_func, Field **from_field,
+                        Field **def_field,
+			bool group, bool modify_item,
+			bool table_cant_handle_bit_fields,
+                        bool make_copy_field,
+                        uint convert_blob_length);
+
+/*
+  General routine to change field->ptr of a NULL-terminated array of Field
+  objects. Useful when needed to call val_int, val_str or similar and the
+  field data is not in table->record[0] but in some other structure.
+  set_key_field_ptr changes all fields of an index using a key_info object.
+  All methods presume that there is at least one field to change.
+*/
+
+TABLE *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list);
+
 
 inline bool optimizer_flag(THD *thd, uint flag)
 { 

=== modified file 'sql/sql_servers.cc'
--- a/sql/sql_servers.cc	2009-10-14 16:37:38 +0000
+++ b/sql/sql_servers.cc	2009-11-18 08:54:54 +0000
@@ -33,7 +33,11 @@
   currently running transactions etc will not be disrupted.
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "sql_servers.h"
+#include "unireg.h"
+#include "sql_base.h"                           // close_thread_tables
+#include "records.h"          // init_read_record, end_read_record
 #include "hash_filo.h"
 #include <m_ctype.h>
 #include <stdarg.h>

=== modified file 'sql/sql_servers.h'
--- a/sql/sql_servers.h	2009-09-23 21:32:31 +0000
+++ b/sql/sql_servers.h	2009-11-18 08:54:54 +0000
@@ -16,8 +16,13 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
+#include "my_global.h"                  /* uint */
 #include "slave.h" // for tables_ok(), rpl_filter
 
+class THD;
+typedef struct st_lex_server_options LEX_SERVER_OPTIONS;
+typedef struct st_mem_root MEM_ROOT;
+
 /* structs */
 typedef struct st_federated_server
 {

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2009-11-10 09:32:29 +0000
+++ b/sql/sql_show.cc	2009-11-18 08:54:54 +0000
@@ -16,10 +16,25 @@
 
 /* Function with list databases, tables or fields */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_acl.h"                        // fill_schema_*_privileges
 #include "sql_select.h"                         // For select_describe
+#include "sql_base.h"                       // close_tables_for_reopen
 #include "sql_show.h"
+#include "sql_table.h"                        // filename_to_tablename,
+                                              // primary_key_name,
+                                              // build_table_filename
 #include "repl_failsafe.h"
+#include "sql_view.h"                           // mysql_frm_type
+#include "sql_parse.h"             // check_access, check_table_access
+#include "sql_partition.h"         // partition_element
+#include "sql_db.h"     // check_db_dir_existence, load_db_opt_by_name
+#include "sql_time.h"   // interval_type_to_name
+#include "tztime.h"                             // struct Time_zone
+#include "sql_acl.h"     // TABLE_ACLS, check_grant, DB_ACLS, acl_get,
+                         // check_grant_db
+#include "filesort.h"    // filesort_free_buffers
 #include "sp.h"
 #include "sp_head.h"
 #include "sql_trigger.h"
@@ -31,6 +46,7 @@
 #include "event_data_objects.h"
 #endif
 #include <my_dir.h>
+#include "lock.h"                           // MYSQL_LOCK_IGNORE_FLUSH
 
 #define STR_OR_NIL(S) ((S) ? (S) : "<nil>")
 

=== modified file 'sql/sql_show.h'
--- a/sql/sql_show.h	2009-01-08 19:03:56 +0000
+++ b/sql/sql_show.h	2009-11-18 08:54:54 +0000
@@ -16,12 +16,24 @@
 #ifndef SQL_SHOW_H
 #define SQL_SHOW_H
 
+#include "sql_list.h"                           /* List */
+#include "handler.h"                            /* enum_schema_tables */
+#include "table.h"                              /* enum_schema_table_state */
+
 /* Forward declarations */
+class JOIN;
 class String;
 class THD;
+class sp_name;
+struct TABLE_LIST;
 struct st_ha_create_information;
+typedef class st_select_lex SELECT_LEX;
 typedef st_ha_create_information HA_CREATE_INFO;
-struct TABLE_LIST;
+struct LEX;
+typedef struct st_mysql_show_var SHOW_VAR;
+typedef struct st_schema_table ST_SCHEMA_TABLE;
+struct TABLE;
+typedef struct system_status_var STATUS_VAR;
 
 enum find_files_result {
   FIND_FILES_OK,
@@ -29,6 +41,46 @@ enum find_files_result {
   FIND_FILES_DIR
 };
 
+/* Used by handlers to store things in schema tables */
+#define IS_FILES_FILE_ID              0
+#define IS_FILES_FILE_NAME            1
+#define IS_FILES_FILE_TYPE            2
+#define IS_FILES_TABLESPACE_NAME      3
+#define IS_FILES_TABLE_CATALOG        4
+#define IS_FILES_TABLE_SCHEMA         5
+#define IS_FILES_TABLE_NAME           6
+#define IS_FILES_LOGFILE_GROUP_NAME   7
+#define IS_FILES_LOGFILE_GROUP_NUMBER 8
+#define IS_FILES_ENGINE               9
+#define IS_FILES_FULLTEXT_KEYS       10
+#define IS_FILES_DELETED_ROWS        11
+#define IS_FILES_UPDATE_COUNT        12
+#define IS_FILES_FREE_EXTENTS        13
+#define IS_FILES_TOTAL_EXTENTS       14
+#define IS_FILES_EXTENT_SIZE         15
+#define IS_FILES_INITIAL_SIZE        16
+#define IS_FILES_MAXIMUM_SIZE        17
+#define IS_FILES_AUTOEXTEND_SIZE     18
+#define IS_FILES_CREATION_TIME       19
+#define IS_FILES_LAST_UPDATE_TIME    20
+#define IS_FILES_LAST_ACCESS_TIME    21
+#define IS_FILES_RECOVER_TIME        22
+#define IS_FILES_TRANSACTION_COUNTER 23
+#define IS_FILES_VERSION             24
+#define IS_FILES_ROW_FORMAT          25
+#define IS_FILES_TABLE_ROWS          26
+#define IS_FILES_AVG_ROW_LENGTH      27
+#define IS_FILES_DATA_LENGTH         28
+#define IS_FILES_MAX_DATA_LENGTH     29
+#define IS_FILES_INDEX_LENGTH        30
+#define IS_FILES_DATA_FREE           31
+#define IS_FILES_CREATE_TIME         32
+#define IS_FILES_UPDATE_TIME         33
+#define IS_FILES_CHECK_TIME          34
+#define IS_FILES_CHECKSUM            35
+#define IS_FILES_STATUS              36
+#define IS_FILES_EXTRA               37
+
 find_files_result find_files(THD *thd, List<LEX_STRING> *files, const char *db,
                              const char *path, const char *wild, bool dir);
 
@@ -38,4 +90,47 @@ int view_store_create_info(THD *thd, TAB
 
 int copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table);
 
+void append_identifier(THD *thd, String *packet, const char *name,
+		       uint length);
+void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild);
+int mysqld_dump_create_info(THD *thd, TABLE_LIST *table_list, int fd);
+bool mysqld_show_create(THD *thd, TABLE_LIST *table_list);
+bool mysqld_show_create_db(THD *thd, char *dbname, HA_CREATE_INFO *create);
+
+void mysqld_list_processes(THD *thd,const char *user,bool verbose);
+int mysqld_show_status(THD *thd);
+int mysqld_show_variables(THD *thd,const char *wild);
+bool mysqld_show_storage_engines(THD *thd);
+bool mysqld_show_authors(THD *thd);
+bool mysqld_show_contributors(THD *thd);
+bool mysqld_show_privileges(THD *thd);
+bool mysqld_show_column_types(THD *thd);
+char *make_default_log_name(char *buff,const char* log_ext);
+char *make_backup_log_name(char *buff, const char *name, const char* log_ext);
+void calc_sum_of_all_status(STATUS_VAR *to);
+void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user,
+                    const LEX_STRING *definer_host);
+int add_status_vars(SHOW_VAR *list);
+void remove_status_vars(SHOW_VAR *list);
+void init_status_vars();
+void free_status_vars();
+void reset_status_vars();
+bool show_create_trigger(THD *thd, const sp_name *trg_name);
+void view_store_options(THD *thd, TABLE_LIST *table, String *buff);
+
+void init_fill_schema_files_row(TABLE* table);
+bool schema_table_store_record(THD *thd, TABLE *table);
+
+ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name);
+ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx);
+int make_schema_select(THD *thd,  SELECT_LEX *sel,
+                       enum enum_schema_tables schema_table_idx);
+int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list);
+bool get_schema_tables_result(JOIN *join,
+                              enum enum_schema_table_state executed_place);
+enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
+
+/* These functions were under INNODB_COMPATIBILITY_HOOKS */
+int get_quote_char_for_identifier(THD *thd, const char *name, uint length);
+
 #endif /* SQL_SHOW_H */

=== modified file 'sql/sql_signal.cc'
--- a/sql/sql_signal.cc	2009-09-10 09:18:29 +0000
+++ b/sql/sql_signal.cc	2009-11-18 08:54:54 +0000
@@ -13,7 +13,7 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
 #include "sp_head.h"
 #include "sp_pcontext.h"
 #include "sp_rcontext.h"

=== modified file 'sql/sql_sort.h'
--- a/sql/sql_sort.h	2009-09-23 21:32:31 +0000
+++ b/sql/sql_sort.h	2009-11-18 08:54:54 +0000
@@ -16,6 +16,18 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
+#include "my_global.h"                          /* uchar */
+#include "my_base.h"                            /* ha_rows */
+#include "my_sys.h"                             /* qsort2_cmp */
+
+typedef struct st_buffpek BUFFPEK;
+typedef struct st_queue QUEUE;
+typedef struct st_sort_field SORT_FIELD;
+
+class Field;
+struct TABLE;
+
+
 /* Defines used by filesort and uniques */
 
 #define MERGEBUFF		7

=== modified file 'sql/sql_string.h'
--- a/sql/sql_string.h	2009-10-28 07:55:44 +0000
+++ b/sql/sql_string.h	2009-11-18 08:54:54 +0000
@@ -26,7 +26,15 @@
 #define NOT_FIXED_DEC			31
 #endif
 
+#include "m_ctype.h"                            /* my_charset_bin */
+#include "my_sys.h"              /* alloc_root, my_free, my_realloc */
+#include "m_string.h"                           /* TRASH */
+
 class String;
+typedef struct charset_info_st CHARSET_INFO;
+typedef struct st_io_cache IO_CACHE;
+typedef struct st_mem_root MEM_ROOT;
+
 int sortcmp(const String *a,const String *b, CHARSET_INFO *cs);
 String *copy_if_not_alloced(String *a,String *b,uint32 arg_length);
 uint32 copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs,

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2009-11-10 07:31:33 +0000
+++ b/sql/sql_table.cc	2009-11-18 08:54:54 +0000
@@ -15,7 +15,32 @@
 
 /* drop and alter of tables */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_table.h"
+#include "sql_rename.h" // do_rename
+#include "sql_parse.h"                        // test_if_data_home_dir
+#include "sql_cache.h"                          // query_cache_*
+#include "sql_base.h"                          // open_temporary_table
+#include "lock.h"       // wait_if_global_read_lock, lock_table_names,
+                        // start_waiting_global_read_lock,
+                        // unlock_table_names, mysql_unlock_tables
+#include "strfunc.h"    // find_type2, find_set
+#include "sql_view.h" // mysql_frm_type, view_checksum, mysql_frm_type
+#include "sql_delete.h"                         // mysql_truncate
+#include "sql_partition.h"                      // mem_alloc_error,
+                                                // generate_partition_syntax,
+                                                // partition_info
+#include "sql_db.h" // load_db_opt_by_name, lock_db_cache, creating_database
+#include "sql_time.h"                  // make_truncated_value_warning
+#include "records.h"             // init_read_record, end_read_record
+#include "filesort.h"            // filesort_free_buffers
+#include "sql_select.h"                // setup_order,
+                                       // make_unireg_sortorder
+#include "sql_handler.h"               // mysql_ha_rm_tables
+#include "discover.h"                  // readfrm
+#include "my_pthread.h"                // pthread_mutex_t
+#include "log_event.h"                 // Query_log_event
 #include <hash.h>
 #include <myisam.h>
 #include <my_dir.h>

=== added file 'sql/sql_table.h'
--- a/sql/sql_table.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_table.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,212 @@
+#ifndef SQL_TABLE_INCLUDED
+#define SQL_TABLE_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "my_global.h"                          /* my_bool */
+#include "my_sys.h"                             // pthread_mutex_t
+
+class Alter_info;
+class Create_field;
+class TABLE_LIST;
+class THD;
+struct TABLE;
+struct handlerton;
+
+typedef struct st_ha_check_opt HA_CHECK_OPT;
+typedef struct st_ha_create_information HA_CREATE_INFO;
+typedef struct st_key_cache KEY_CACHE;
+typedef struct st_lock_param_type ALTER_PARTITION_PARAM_TYPE;
+typedef struct st_mysql_lex_string LEX_STRING;
+typedef struct st_order ORDER;
+
+enum ddl_log_entry_code
+{
+  /*
+    DDL_LOG_EXECUTE_CODE:
+      This is a code that indicates that this is a log entry to
+      be executed, from this entry a linked list of log entries
+      can be found and executed.
+    DDL_LOG_ENTRY_CODE:
+      An entry to be executed in a linked list from an execute log
+      entry.
+    DDL_IGNORE_LOG_ENTRY_CODE:
+      An entry that is to be ignored
+  */
+  DDL_LOG_EXECUTE_CODE = 'e',
+  DDL_LOG_ENTRY_CODE = 'l',
+  DDL_IGNORE_LOG_ENTRY_CODE = 'i'
+};
+
+enum ddl_log_action_code
+{
+  /*
+    The type of action that a DDL_LOG_ENTRY_CODE entry is to
+    perform.
+    DDL_LOG_DELETE_ACTION:
+      Delete an entity
+    DDL_LOG_RENAME_ACTION:
+      Rename an entity
+    DDL_LOG_REPLACE_ACTION:
+      Rename an entity after removing the previous entry with the
+      new name, that is replace this entry.
+  */
+  DDL_LOG_DELETE_ACTION = 'd',
+  DDL_LOG_RENAME_ACTION = 'r',
+  DDL_LOG_REPLACE_ACTION = 's'
+};
+
+
+enum enum_explain_filename_mode
+{
+  EXPLAIN_ALL_VERBOSE= 0,
+  EXPLAIN_PARTITIONS_VERBOSE,
+  EXPLAIN_PARTITIONS_AS_COMMENT
+};
+
+/* depends on errmsg.txt Database `db`, Table `t` ... */
+#define EXPLAIN_FILENAME_MAX_EXTRA_LENGTH 63
+
+#define MYSQL50_TABLE_NAME_PREFIX         "#mysql50#"
+#define MYSQL50_TABLE_NAME_PREFIX_LENGTH  9
+
+#define WFRM_WRITE_SHADOW 1
+#define WFRM_INSTALL_SHADOW 2
+#define WFRM_PACK_FRM 4
+#define WFRM_KEEP_SHARE 8
+
+/* Flags for conversion functions. */
+#define FN_FROM_IS_TMP  (1 << 0)
+#define FN_TO_IS_TMP    (1 << 1)
+#define FN_IS_TMP       (FN_FROM_IS_TMP | FN_TO_IS_TMP)
+#define NO_FRM_RENAME   (1 << 2)
+#define FRM_ONLY        (1 << 3)
+
+typedef struct st_ddl_log_entry
+{
+  const char *name;
+  const char *from_name;
+  const char *handler_name;
+  uint next_entry;
+  uint entry_pos;
+  enum ddl_log_entry_code entry_type;
+  enum ddl_log_action_code action_type;
+  /*
+    Most actions have only one phase. REPLACE does however have two
+    phases. The first phase removes the file with the new name if
+    there was one there before and the second phase renames the
+    old name to the new name.
+  */
+  char phase;
+} DDL_LOG_ENTRY;
+
+typedef struct st_ddl_log_memory_entry
+{
+  uint entry_pos;
+  struct st_ddl_log_memory_entry *next_log_entry;
+  struct st_ddl_log_memory_entry *prev_log_entry;
+  struct st_ddl_log_memory_entry *next_active_log_entry;
+} DDL_LOG_MEMORY_ENTRY;
+
+uint filename_to_tablename(const char *from, char *to, uint to_length);
+uint tablename_to_filename(const char *from, char *to, uint to_length);
+uint check_n_cut_mysql50_prefix(const char *from, char *to, uint to_length);
+uint build_table_filename(char *buff, size_t bufflen, const char *db,
+                          const char *table, const char *ext, uint flags);
+uint build_table_shadow_filename(char *buff, size_t bufflen,
+                                 ALTER_PARTITION_PARAM_TYPE *lpt);
+bool mysql_create_table(THD *thd,const char *db, const char *table_name,
+                        HA_CREATE_INFO *create_info,
+                        Alter_info *alter_info,
+                        bool tmp_table, uint select_field_count);
+bool mysql_create_table_no_lock(THD *thd, const char *db,
+                                const char *table_name,
+                                HA_CREATE_INFO *create_info,
+                                Alter_info *alter_info,
+                                bool tmp_table, uint select_field_count);
+
+bool mysql_alter_table(THD *thd, char *new_db, char *new_name,
+                       HA_CREATE_INFO *create_info,
+                       TABLE_LIST *table_list,
+                       Alter_info *alter_info,
+                       uint order_num, ORDER *order, bool ignore);
+bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list);
+bool mysql_create_like_table(THD *thd, TABLE_LIST *table,
+                             TABLE_LIST *src_table,
+                             HA_CREATE_INFO *create_info);
+bool mysql_rename_table(handlerton *base, const char *old_db,
+                        const char * old_name, const char *new_db,
+                        const char * new_name, uint flags);
+
+bool mysql_backup_table(THD* thd, TABLE_LIST* table_list);
+bool mysql_restore_table(THD* thd, TABLE_LIST* table_list);
+
+bool mysql_checksum_table(THD* thd, TABLE_LIST* table_list,
+                          HA_CHECK_OPT* check_opt);
+bool mysql_check_table(THD* thd, TABLE_LIST* table_list,
+                       HA_CHECK_OPT* check_opt);
+bool mysql_repair_table(THD* thd, TABLE_LIST* table_list,
+                        HA_CHECK_OPT* check_opt);
+bool mysql_analyze_table(THD* thd, TABLE_LIST* table_list,
+                         HA_CHECK_OPT* check_opt);
+bool mysql_optimize_table(THD* thd, TABLE_LIST* table_list,
+                          HA_CHECK_OPT* check_opt);
+bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* table_list,
+                              LEX_STRING *key_cache_name);
+bool mysql_preload_keys(THD* thd, TABLE_LIST* table_list);
+int reassign_keycache_tables(THD* thd, KEY_CACHE *src_cache,
+                             KEY_CACHE *dst_cache);
+bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
+                    my_bool drop_temporary);
+int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
+                         bool drop_temporary, bool drop_view, bool log_query);
+bool quick_rm_table(handlerton *base,const char *db,
+                    const char *table_name, uint flags);
+void close_cached_table(THD *thd, TABLE *table);
+void sp_prepare_create_field(THD *thd, Create_field *sql_field);
+int prepare_create_field(Create_field *sql_field,
+			 uint *blob_columns,
+			 int *timestamps, int *timestamps_with_niladic,
+			 longlong table_flags);
+CHARSET_INFO* get_sql_field_charset(Create_field *sql_field,
+                                    HA_CREATE_INFO *create_info);
+bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags);
+void write_bin_log(THD *thd, bool clear_error,
+                   char const *query, ulong query_length);
+bool write_ddl_log_entry(DDL_LOG_ENTRY *ddl_log_entry,
+                           DDL_LOG_MEMORY_ENTRY **active_entry);
+bool write_execute_ddl_log_entry(uint first_entry,
+                                   bool complete,
+                                   DDL_LOG_MEMORY_ENTRY **active_entry);
+bool deactivate_ddl_log_entry(uint entry_no);
+void release_ddl_log_memory_entry(DDL_LOG_MEMORY_ENTRY *log_entry);
+bool sync_ddl_log();
+void release_ddl_log();
+void execute_ddl_log_recovery();
+bool execute_ddl_log_entry(THD *thd, uint first_entry);
+
+/*
+  These prototypes where under INNODB_COMPATIBILITY_HOOKS.
+*/
+uint explain_filename(THD* thd, const char *from, char *to, uint to_length,
+                      enum_explain_filename_mode explain_mode);
+
+
+extern MYSQL_PLUGIN_IMPORT const char *primary_key_name;
+extern int creating_table;    // How many mysql_create_table() are running
+extern pthread_mutex_t LOCK_gdl;
+
+#endif /* SQL_TABLE_INCLUDED */

=== modified file 'sql/sql_tablespace.cc'
--- a/sql/sql_tablespace.cc	2009-11-05 20:28:35 +0000
+++ b/sql/sql_tablespace.cc	2009-11-18 08:54:54 +0000
@@ -15,7 +15,11 @@
 
 /* drop and alter of tablespaces */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_tablespace.h"
+#include "sql_table.h"                          // write_bin_log
+#include "sql_class.h"                          // THD
 
 int mysql_alter_tablespace(THD *thd, st_alter_tablespace *ts_info)
 {

=== added file 'sql/sql_tablespace.h'
--- a/sql/sql_tablespace.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_tablespace.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,24 @@
+#ifndef SQL_TABLESPACE_INCLUDED
+#define SQL_TABLESPACE_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+class THD;
+class st_alter_tablespace;
+
+int mysql_alter_tablespace(THD* thd, st_alter_tablespace *ts_info);
+
+#endif /* SQL_TABLESPACE_INCLUDED */

=== modified file 'sql/sql_test.cc'
--- a/sql/sql_test.cc	2009-10-14 16:37:38 +0000
+++ b/sql/sql_test.cc	2009-11-18 08:54:54 +0000
@@ -17,7 +17,11 @@
 /* Write some debug info */
 
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_test.h"
+#include "sql_base.h" // table_def_cache, table_cache_count, unused_tables
+#include "sql_show.h" // calc_sum_of_all_status
 #include "sql_select.h"
 #include <hash.h>
 #include <thr_alarm.h>

=== added file 'sql/sql_test.h'
--- a/sql/sql_test.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_test.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,40 @@
+#ifndef SQL_TEST_INCLUDED
+#define SQL_TEST_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "mysqld.h"
+
+class JOIN;
+struct TABLE_LIST;
+typedef class Item COND;
+typedef class st_select_lex SELECT_LEX;
+typedef struct st_sort_field SORT_FIELD;
+
+#ifndef DBUG_OFF
+void print_where(COND *cond,const char *info, enum_query_type query_type);
+void print_cached_tables(void);
+void TEST_filesort(SORT_FIELD *sortorder,uint s_length);
+void print_plan(JOIN* join,uint idx, double record_count, double read_time,
+                double current_read_time, const char *info);
+#define EXTRA_DEBUG_DUMP_TABLE_LISTS
+#ifdef EXTRA_DEBUG_DUMP_TABLE_LISTS
+void dump_TABLE_LIST_graph(SELECT_LEX *select_lex, TABLE_LIST* tl);
+#endif
+#endif
+void mysql_print_status();
+
+#endif /* SQL_TEST_INCLUDED */

=== renamed file 'sql/time.cc' => 'sql/sql_time.cc'
--- a/sql/time.cc	2009-11-06 14:20:27 +0000
+++ b/sql/sql_time.cc	2009-11-18 08:54:54 +0000
@@ -16,7 +16,11 @@
 
 /* Functions to handle date and time */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"                      // REQUIRED by other includes
+#include "sql_time.h"
+#include "tztime.h"                             // struct Time_zone
+#include "sql_class.h"   // THD, MODE_INVALID_DATES, MODE_NO_ZERO_DATE
 #include <m_ctype.h>
 
 

=== added file 'sql/sql_time.h'
--- a/sql/sql_time.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_time.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,75 @@
+#ifndef SQL_TIME_INCLUDED
+#define SQL_TIME_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "my_global.h"                          /* ulong */
+#include "my_time.h"
+#include "mysql_time.h"                         /* timestamp_type */
+#include "sql_error.h"                          /* MYSQL_ERROR */
+#include "structs.h"                            /* INTERVAL */
+
+typedef enum enum_mysql_timestamp_type timestamp_type;
+typedef struct st_date_time_format DATE_TIME_FORMAT;
+typedef struct st_known_date_time_format KNOWN_DATE_TIME_FORMAT;
+
+/* Flags for calc_week() function.  */
+#define WEEK_MONDAY_FIRST    1
+#define WEEK_YEAR            2
+#define WEEK_FIRST_WEEKDAY   4
+
+ulong convert_period_to_month(ulong period);
+ulong convert_month_to_period(ulong month);
+void get_date_from_daynr(long daynr,uint *year, uint *month, uint *day);
+my_time_t TIME_to_timestamp(THD *thd, const MYSQL_TIME *t, my_bool *not_exist);
+bool str_to_time_with_warn(const char *str,uint length,MYSQL_TIME *l_time);
+timestamp_type str_to_datetime_with_warn(const char *str, uint length,
+                                         MYSQL_TIME *l_time, uint flags);
+void make_truncated_value_warning(THD *thd,
+                                  MYSQL_ERROR::enum_warning_level level,
+                                  const char *str_val, uint str_length,
+                                  timestamp_type time_type,
+                                  const char *field_name);
+extern DATE_TIME_FORMAT *date_time_format_make(timestamp_type format_type,
+					       const char *format_str,
+					       uint format_length);
+extern DATE_TIME_FORMAT *date_time_format_copy(THD *thd,
+					       DATE_TIME_FORMAT *format);
+const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
+				     timestamp_type type);
+void make_date(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
+               String *str);
+void make_time(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
+               String *str);
+void make_datetime(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
+                   String *str);
+
+/* MYSQL_TIME operations */
+bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type,
+                       INTERVAL interval);
+bool calc_time_diff(MYSQL_TIME *l_time1, MYSQL_TIME *l_time2, int l_sign,
+                    longlong *seconds_out, long *microseconds_out);
+int my_time_compare(MYSQL_TIME *a, MYSQL_TIME *b);
+void localtime_to_TIME(MYSQL_TIME *to, struct tm *from);
+void calc_time_from_sec(MYSQL_TIME *to, long seconds, long microseconds);
+uint calc_week(MYSQL_TIME *l_time, uint week_behaviour, uint *year);
+
+int calc_weekday(long daynr,bool sunday_first_day_of_week);
+
+extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[];
+extern LEX_STRING interval_type_to_name[];
+
+#endif /* SQL_TIME_INCLUDED */

=== modified file 'sql/sql_trigger.cc'
--- a/sql/sql_trigger.cc	2009-11-05 20:28:35 +0000
+++ b/sql/sql_trigger.cc	2009-11-18 08:54:54 +0000
@@ -15,10 +15,21 @@
 
 
 #define MYSQL_LEX 1
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #include "sp_head.h"
 #include "sql_trigger.h"
+#include "sql_parse.h"                          // parse_sql
 #include "parse_file.h"
+#include "sql_base.h"                          // find_temporary_table
+#include "lock.h"                    // wait_if_global_read_lock,
+                                     // start_waiting_global_read_lock
+#include "sql_show.h"                // append_definer, append_identifier
+#include "sql_table.h"                        // build_table_filename,
+                                              // check_n_cut_mysql50_prefix
+#include "sql_db.h"                        // get_default_db_collation
+#include "sql_acl.h"                       // *_ACL, is_acl_user
+#include "sql_handler.h"                        // mysql_ha_rm_tables
 
 /*************************************************************************/
 

=== modified file 'sql/sql_trigger.h'
--- a/sql/sql_trigger.h	2009-09-23 21:32:31 +0000
+++ b/sql/sql_trigger.h	2009-11-18 08:54:54 +0000
@@ -16,6 +16,38 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA */
 
+/* Forward declarations */
+
+class Item_trigger_field;
+class sp_head;
+class sp_name;
+class Query_tables_list;
+struct TABLE_LIST;
+class Query_tables_list;
+
+/** Event on which trigger is invoked. */
+enum trg_event_type
+{
+  TRG_EVENT_INSERT= 0,
+  TRG_EVENT_UPDATE= 1,
+  TRG_EVENT_DELETE= 2,
+  TRG_EVENT_MAX
+};
+
+#include "table.h"                              /* GRANT_INFO */
+
+/*
+  We need this two enums here instead of sql_lex.h because
+  at least one of them is used by Item_trigger_field interface.
+
+  Time when trigger is invoked (i.e. before or after row actually
+  inserted/updated/deleted).
+*/
+enum trg_action_time_type
+{
+  TRG_ACTION_BEFORE= 0, TRG_ACTION_AFTER= 1, TRG_ACTION_MAX
+};
+
 
 /**
   This class holds all information about triggers of table.
@@ -176,5 +208,9 @@ bool load_table_name_for_trigger(THD *th
                                  const sp_name *trg_name,
                                  const LEX_STRING *trn_path,
                                  LEX_STRING *tbl_name);
+bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create);
+
+extern const char * const TRG_EXT;
+extern const char * const TRN_EXT;
 
 #endif /* SQL_TRIGGER_INCLUDED */

=== modified file 'sql/sql_udf.cc'
--- a/sql/sql_udf.cc	2009-11-05 20:28:35 +0000
+++ b/sql/sql_udf.cc	2009-11-18 08:54:54 +0000
@@ -31,7 +31,12 @@
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_base.h"                           // close_thread_tables
+#include "sql_parse.h"                        // check_identifier_name
+#include "sql_table.h"                        // write_bin_log
+#include "records.h"          // init_read_record, end_read_record
 #include <my_pthread.h>
 
 #ifdef HAVE_DLOPEN

=== modified file 'sql/sql_union.cc'
--- a/sql/sql_union.cc	2009-05-15 07:11:07 +0000
+++ b/sql/sql_union.cc	2009-11-18 08:54:54 +0000
@@ -20,9 +20,13 @@
 */
 
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_union.h"
 #include "sql_select.h"
 #include "sql_cursor.h"
+#include "sql_base.h"                           // fill_record
+#include "filesort.h"                           // filesort_free_buffers
 
 bool mysql_union(THD *thd, LEX *lex, select_result *result,
                  SELECT_LEX_UNIT *unit, ulong setup_tables_done_option)

=== added file 'sql/sql_union.h'
--- a/sql/sql_union.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_union.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,31 @@
+#ifndef SQL_UNION_INCLUDED
+#define SQL_UNION_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "my_global.h"                          /* ulong */
+
+class THD;
+class select_result;
+struct LEX;
+
+typedef class st_select_lex_unit SELECT_LEX_UNIT;
+
+bool mysql_union(THD *thd, LEX *lex, select_result *result,
+                 SELECT_LEX_UNIT *unit, ulong setup_tables_done_option);
+
+
+#endif /* SQL_UNION_INCLUDED */

=== modified file 'sql/sql_update.cc'
--- a/sql/sql_update.cc	2009-11-06 14:20:27 +0000
+++ b/sql/sql_update.cc	2009-11-18 08:54:54 +0000
@@ -19,11 +19,26 @@
   Multi-table updates were introduced by Sinisa & Monty
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "sql_update.h"
+#include "sql_cache.h"                          // query_cache_*
+#include "sql_base.h"                       // close_tables_for_reopen
+#include "sql_parse.h"                          // cleanup_items
+#include "sql_partition.h"                   // partition_key_modified
 #include "sql_select.h"
+#include "sql_view.h"                           // check_key_in_view
 #include "sp_head.h"
 #include "sql_trigger.h"
 #include "probes_mysql.h"
+#include "key.h"                                // is_key_used
+#include "sql_acl.h"                            // *_ACL, check_grant
+#include "records.h"                            // init_read_record,
+                                                // end_read_record
+#include "filesort.h"                           // filesort
+#include "sql_derived.h" // mysql_derived_prepare,
+                         // mysql_handle_derived,
+                         // mysql_derived_filling
 
 /* Return 0 if row hasn't changed */
 

=== added file 'sql/sql_update.h'
--- a/sql/sql_update.h	1970-01-01 00:00:00 +0000
+++ b/sql/sql_update.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,43 @@
+#ifndef SQL_UPDATE_INCLUDED
+#define SQL_UPDATE_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "sql_class.h"                          /* enum_duplicates */
+
+class Item;
+class TABLE_LIST;
+class THD;
+
+typedef class st_select_lex SELECT_LEX;
+typedef class st_select_lex_unit SELECT_LEX_UNIT;
+
+bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
+                          Item **conds, uint order_num, ORDER *order);
+int mysql_update(THD *thd,TABLE_LIST *tables,List<Item> &fields,
+		 List<Item> &values,COND *conds,
+		 uint order_num, ORDER *order, ha_rows limit,
+		 enum enum_duplicates handle_duplicates, bool ignore,
+                 ha_rows *found_return, ha_rows *updated_return);
+bool mysql_multi_update(THD *thd, TABLE_LIST *table_list,
+                        List<Item> *fields, List<Item> *values,
+                        COND *conds, ulonglong options,
+                        enum enum_duplicates handle_duplicates, bool ignore,
+                        SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex,
+                        multi_update **result);
+bool compare_record(TABLE *table);
+
+#endif /* SQL_UPDATE_INCLUDED */

=== modified file 'sql/sql_view.cc'
--- a/sql/sql_view.cc	2009-11-05 20:28:35 +0000
+++ b/sql/sql_view.cc	2009-11-18 08:54:54 +0000
@@ -15,7 +15,17 @@
 */
 
 #define MYSQL_LEX 1
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_view.h"
+#include "sql_base.h"                     // find_table_in_global_list
+#include "sql_parse.h"                          // sql_parse
+#include "sql_cache.h"                          // query_cache_*
+#include "lock.h"        // wait_if_global_read_lock, lock_table_names
+#include "sql_show.h"    // append_identifier
+#include "sql_table.h"                         // build_table_filename
+#include "sql_db.h"            // mysql_opt_change_db, mysql_change_db
+#include "sql_acl.h"           // *_ACL, check_grant
 #include "sql_select.h"
 #include "parse_file.h"
 #include "sp.h"

=== modified file 'sql/sql_view.h'
--- a/sql/sql_view.h	2009-09-23 21:32:31 +0000
+++ b/sql/sql_view.h	2009-11-18 08:54:54 +0000
@@ -18,6 +18,16 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
+#include "sql_class.h"     /* Required by sql_lex.h */
+#include "sql_lex.h"       /* enum_view_create_mode, enum_drop_mode */
+
+/* Forward declarations */
+
+class File_parser;
+
+
+/* Function declarations */
+
 bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view,
                           enum_view_create_mode mode);
 
@@ -45,4 +55,6 @@ bool mysql_rename_view(THD *thd, const c
 
 #define VIEW_ANY_ACL (SELECT_ACL | UPDATE_ACL | INSERT_ACL | DELETE_ACL)
 
+extern const LEX_STRING view_type;
+
 #endif /* SQL_VIEW_INCLUDED */

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2009-11-06 14:20:27 +0000
+++ b/sql/sql_yacc.yy	2009-11-18 08:54:54 +0000
@@ -35,7 +35,14 @@
 #define YYMAXDEPTH 3200                        /* Because of 64K stack */
 #define Lex (YYTHD->lex)
 #define Select Lex->current_select
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "sql_parse.h"                        /* comp_*_creator */
+#include "sql_table.h"                        /* primary_key_name */
+#include "sql_partition.h"  /* mem_alloc_error, partition_info, HASH_PARTITION */
+#include "sql_acl.h"                          /* *_ACL */
+#include "password.h"       /* my_make_scrambled_password_323, my_make_scrambled_password */
+#include "sql_class.h"      /* Key_part_spec, enum_filetype, Diag_condition_item_name */
 #include "slave.h"
 #include "lex_symbol.h"
 #include "item_create.h"

=== modified file 'sql/strfunc.cc'
--- a/sql/strfunc.cc	2009-09-23 13:21:29 +0000
+++ b/sql/strfunc.cc	2009-11-18 08:54:54 +0000
@@ -15,7 +15,12 @@
 
 /* Some useful string utility functions used by the MySQL server */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "strfunc.h"
+#include "typelib.h"                            // TYPELIB
+#include "m_ctype.h"                            // my_charset_latin1
+#include "mysqld.h"                             // system_charset_info
 
 /*
   Return bitmap for strings used in a set

=== added file 'sql/strfunc.h'
--- a/sql/strfunc.h	1970-01-01 00:00:00 +0000
+++ b/sql/strfunc.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,47 @@
+#ifndef STRFUNC_INCLUDED
+#define STRFUNC_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "my_global.h"                          /* ulonglong, uint */
+
+typedef struct charset_info_st CHARSET_INFO;
+typedef struct st_mysql_lex_string LEX_STRING;
+typedef struct st_typelib TYPELIB;
+
+ulonglong find_set(TYPELIB *lib, const char *x, uint length, CHARSET_INFO *cs,
+		   char **err_pos, uint *err_len, bool *set_warning);
+ulonglong find_set_from_flags(TYPELIB *lib, uint default_name,
+                              ulonglong cur_set, ulonglong default_set,
+                              const char *str, uint length, CHARSET_INFO *cs,
+                              char **err_pos, uint *err_len, bool *set_warning);
+uint find_type(const TYPELIB *lib, const char *find, uint length,
+               bool part_match);
+uint find_type2(const TYPELIB *lib, const char *find, uint length,
+                CHARSET_INFO *cs);
+void unhex_type2(TYPELIB *lib);
+uint check_word(TYPELIB *lib, const char *val, const char *end,
+		const char **end_of_word);
+int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
+                         CHARSET_INFO * const cs);
+
+/*
+  These functions were protected by INNODB_COMPATIBILITY_HOOKS
+ */
+uint strconvert(CHARSET_INFO *from_cs, const char *from,
+                CHARSET_INFO *to_cs, char *to, uint to_length, uint *errors);
+
+#endif /* STRFUNC_INCLUDED */

=== modified file 'sql/structs.h'
--- a/sql/structs.h	2009-11-06 16:13:33 +0000
+++ b/sql/structs.h	2009-11-18 08:54:54 +0000
@@ -17,10 +17,18 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 
+
 /* The old structures from unireg */
 
+#include "sql_plugin.h"                         /* plugin_ref */
+#include "sql_const.h"                          /* MAX_REFLENGTH */
+#include "my_time.h"                   /* enum_mysql_timestamp_type */
+#include "thr_lock.h"                  /* thr_lock_type */
+#include "my_base.h"                   /* ha_rows, ha_key_alg */
+
 struct TABLE;
 class Field;
+
 class THD;
 
 typedef struct st_date_time_format {

=== modified file 'sql/table.cc'
--- a/sql/table.cc	2009-11-02 11:10:04 +0000
+++ b/sql/table.cc	2009-11-18 08:54:54 +0000
@@ -16,8 +16,20 @@
 
 /* Some general useful functions */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"                    // REQUIRED: for other includes
+#include "table.h"
+#include "frm_crypt.h"           // get_crypt_for_frm
+#include "key.h"                                // find_ref_key
+#include "sql_table.h"                          // build_table_filename,
+                                                // primary_key_name
 #include "sql_trigger.h"
+#include "sql_parse.h"                          // free_items
+#include "strfunc.h"                            // unhex_type2
+#include "sql_partition.h"       // mysql_unpack_partition,
+                                 // fix_partition_func, partition_info
+#include "sql_acl.h"             // *_ACL, acl_getroot_no_password
+#include "sql_base.h"            // release_table_share
 #include <m_ctype.h>
 #include "my_md5.h"
 

=== modified file 'sql/table.h'
--- a/sql/table.h	2009-11-02 11:10:04 +0000
+++ b/sql/table.h	2009-11-18 08:54:54 +0000
@@ -16,6 +16,12 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
+#ifndef MYSQL_CLIENT
+
+#include "hash.h"                               /* HASH */
+#include "handler.h"                /* row_type, ha_choice, handler */
+#include "mysql_com.h"              /* enum_field_types */
+#include "thr_lock.h"                  /* thr_lock_type */
 
 /* Structs that defines the TABLE */
 
@@ -28,10 +34,140 @@ class st_select_lex;
 class partition_info;
 class COND_EQUAL;
 class Security_context;
+class TABLE_LIST;
+
+/*
+  Used to identify NESTED_JOIN structures within a join (applicable only to
+  structures that have not been simplified away and embed more the one
+  element)
+*/
+typedef ulonglong nested_join_map;
+
+
+#define tmp_file_prefix "#sql"			/**< Prefix for tmp tables */
+#define tmp_file_prefix_length 4
+
+/**
+  Enumerate possible types of a table from re-execution
+  standpoint.
+  TABLE_LIST class has a member of this type.
+  At prepared statement prepare, this member is assigned a value
+  as of the current state of the database. Before (re-)execution
+  of a prepared statement, we check that the value recorded at
+  prepare matches the type of the object we obtained from the
+  table definition cache.
+
+  @sa check_and_update_table_version()
+  @sa Execute_observer
+  @sa Prepared_statement::reprepare()
+*/
+
+enum enum_table_ref_type
+{
+  /** Initial value set by the parser */
+  TABLE_REF_NULL= 0,
+  TABLE_REF_VIEW,
+  TABLE_REF_BASE_TABLE,
+  TABLE_REF_I_S_TABLE,
+  TABLE_REF_TMP_TABLE
+};
+
+
+/**
+  Opening modes for open_temporary_table and open_table_from_share
+*/
+
+enum open_table_mode
+{
+  OTM_OPEN= 0,
+  OTM_CREATE= 1,
+  OTM_ALTER= 2
+};
+
 
 /*************************************************************************/
 
 /**
+ Object_creation_ctx -- interface for creation context of database objects
+ (views, stored routines, events, triggers). Creation context -- is a set
+ of attributes, that should be fixed at the creation time and then be used
+ each time the object is parsed or executed.
+*/
+
+class Object_creation_ctx
+{
+public:
+  Object_creation_ctx *set_n_backup(THD *thd);
+
+  void restore_env(THD *thd, Object_creation_ctx *backup_ctx);
+
+protected:
+  Object_creation_ctx() {}
+  virtual Object_creation_ctx *create_backup_ctx(THD *thd) const = 0;
+
+  virtual void change_env(THD *thd) const = 0;
+
+public:
+  virtual ~Object_creation_ctx()
+  { }
+};
+
+/*************************************************************************/
+
+/**
+ Default_object_creation_ctx -- default implementation of
+ Object_creation_ctx.
+*/
+
+class Default_object_creation_ctx : public Object_creation_ctx
+{
+public:
+  CHARSET_INFO *get_client_cs()
+  {
+    return m_client_cs;
+  }
+
+  CHARSET_INFO *get_connection_cl()
+  {
+    return m_connection_cl;
+  }
+
+protected:
+  Default_object_creation_ctx(THD *thd);
+
+  Default_object_creation_ctx(CHARSET_INFO *client_cs,
+                              CHARSET_INFO *connection_cl);
+
+protected:
+  virtual Object_creation_ctx *create_backup_ctx(THD *thd) const;
+
+  virtual void change_env(THD *thd) const;
+
+protected:
+  /**
+    client_cs stores the value of character_set_client session variable.
+    The only character set attribute is used.
+
+    Client character set is included into query context, because we save
+    query in the original character set, which is client character set. So,
+    in order to parse the query properly we have to switch client character
+    set on parsing.
+  */
+  CHARSET_INFO *m_client_cs;
+
+  /**
+    connection_cl stores the value of collation_connection session
+    variable. Both character set and collation attributes are used.
+
+    Connection collation is included into query context, becase it defines
+    the character set and collation of text literals in internal
+    representation of query (item-objects).
+  */
+  CHARSET_INFO *m_connection_cl;
+};
+
+
+/**
  View_creation_ctx -- creation context of view objects.
 */
 
@@ -139,15 +275,6 @@ enum tmp_table_type
   INTERNAL_TMP_TABLE, SYSTEM_TMP_TABLE
 };
 
-/** Event on which trigger is invoked. */
-enum trg_event_type
-{
-  TRG_EVENT_INSERT= 0,
-  TRG_EVENT_UPDATE= 1,
-  TRG_EVENT_DELETE= 2,
-  TRG_EVENT_MAX
-};
-
 enum frm_type_enum
 {
   FRMTYPE_ERROR= 0,
@@ -1740,4 +1867,69 @@ static inline void dbug_tmp_restore_colu
 
 size_t max_row_length(TABLE *table, const uchar *data);
 
+int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
+                          uint db_stat, uint prgflag, uint ha_open_flags,
+                          TABLE *outparam, bool is_create_table);
+TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key,
+                               uint key_length);
+void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
+                          uint key_length,
+                          const char *table_name, const char *path);
+void free_table_share(TABLE_SHARE *share);
+int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags);
+void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
+void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form);
+bool check_and_convert_db_name(LEX_STRING *db, bool preserve_lettercase);
+bool check_db_name(LEX_STRING *db);
+bool check_column_name(const char *name);
+bool check_table_name(const char *name, uint length);
+int rename_file_ext(const char * from,const char * to,const char * ext);
+char *get_field(MEM_ROOT *mem, Field *field);
+bool get_field(MEM_ROOT *mem, Field *field, class String *res);
+
+int closefrm(TABLE *table, bool free_share);
+int read_string(File file, uchar* *to, size_t length);
+void free_blobs(TABLE *table);
+void free_field_buffers_larger_than(TABLE *table, uint32 size);
+int set_zone(int nr,int min_zone,int max_zone);
+ulong get_form_pos(File file, uchar *head, TYPELIB *save_names);
+ulong make_new_entry(File file,uchar *fileinfo,TYPELIB *formnames,
+		     const char *newname);
+ulong next_io_size(ulong pos);
+void append_unescaped(String *res, const char *pos, uint length);
+int create_frm(THD *thd, const char *name, const char *db, const char *table,
+               uint reclength, uchar *fileinfo,
+	       HA_CREATE_INFO *create_info, uint keys);
+char *fn_rext(char *name);
+
+extern LEX_STRING GENERAL_LOG_NAME;
+extern LEX_STRING SLOW_LOG_NAME;
+
+/* information schema */
+extern LEX_STRING INFORMATION_SCHEMA_NAME;
+extern LEX_STRING MYSQL_SCHEMA_NAME;
+
+#define is_schema_db(X) \
+  !my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X))
+
+TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings);
+
+/**
+  return true if the table was created explicitly.
+*/
+inline bool is_user_table(TABLE * table)
+{
+  const char *name= table->s->table_name.str;
+  return strncmp(name, tmp_file_prefix, tmp_file_prefix_length);
+}
+
+inline void mark_as_null_row(TABLE *table)
+{
+  table->null_row=1;
+  table->status|=STATUS_NULL_ROW;
+  bfill(table->null_flags,table->s->null_bytes,255);
+}
+
+#endif /* MYSQL_CLIENT */
+
 #endif /* TABLE_INCLUDED */

=== modified file 'sql/thr_malloc.cc'
--- a/sql/thr_malloc.cc	2009-09-10 09:18:29 +0000
+++ b/sql/thr_malloc.cc	2009-11-18 08:54:54 +0000
@@ -16,7 +16,10 @@
 
 /* Mallocs for used in threads */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "thr_malloc.h"
+#include "sql_class.h"
 
 extern "C" {
   void sql_alloc_error_handler(void)

=== added file 'sql/thr_malloc.h'
--- a/sql/thr_malloc.h	1970-01-01 00:00:00 +0000
+++ b/sql/thr_malloc.h	2009-11-18 08:54:54 +0000
@@ -0,0 +1,36 @@
+#ifndef THR_MALLOC_INCLUDED
+#define THR_MALLOC_INCLUDED
+
+/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+#include "my_global.h"                          // uint, size_t
+
+typedef struct charset_info_st CHARSET_INFO;
+typedef struct st_mem_root MEM_ROOT;
+
+void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size);
+void *sql_alloc(size_t);
+void *sql_calloc(size_t);
+char *sql_strdup(const char *str);
+char *sql_strmake(const char *str, size_t len);
+void *sql_memdup(const void * ptr, size_t size);
+void sql_element_free(void *ptr);
+char *sql_strmake_with_convert(const char *str, size_t arg_length,
+			       CHARSET_INFO *from_cs,
+			       size_t max_res_length,
+			       CHARSET_INFO *to_cs, size_t *result_length);
+
+#endif /* THR_MALLOC_INCLUDED */

=== modified file 'sql/tztime.cc'
--- a/sql/tztime.cc	2009-10-14 16:37:38 +0000
+++ b/sql/tztime.cc	2009-11-18 08:54:54 +0000
@@ -20,7 +20,7 @@
 */
 
 /*
-  We should not include mysql_priv.h in mysql_tzinfo_to_sql utility since
+  We should not include sql_priv.h in mysql_tzinfo_to_sql utility since
   it creates unsolved link dependencies on some platforms.
 */
 
@@ -30,7 +30,12 @@
 
 #include <my_global.h>
 #if !defined(TZINFO2SQL) && !defined(TESTTIME)
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "tztime.h"
+#include "sql_time.h"                           // localtime_to_TIME
+#include "sql_base.h"                           // open_system_tables_for_read,
+                                                // close_system_tables
 #else
 #include <my_time.h>
 #include "tztime.h"

=== modified file 'sql/tztime.h'
--- a/sql/tztime.h	2009-09-23 21:32:31 +0000
+++ b/sql/tztime.h	2009-11-18 08:54:54 +0000
@@ -21,8 +21,17 @@
 #pragma interface			/* gcc class interface */
 #endif
 
+#include "my_time.h"                            /* my_time_t */
+#include "mysql_time.h"                         /* MYSQL_TIME */
+#include "sql_list.h"                           /* Sql_alloc */
+#include "sql_string.h"                         /* String */
+
+class THD;
+
 #if !defined(TESTTIME) && !defined(TZINFO2SQL)
 
+class THD;
+
 /**
   This class represents abstract time zone and provides 
   basic interface for MYSQL_TIME <-> my_time_t conversion.

=== modified file 'sql/uniques.cc'
--- a/sql/uniques.cc	2009-06-17 14:56:44 +0000
+++ b/sql/uniques.cc	2009-11-18 08:54:54 +0000
@@ -30,9 +30,12 @@
   deletes in disk order.
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #include "sql_sort.h"
-
+#include "queues.h"                             // QUEUE
+#include "my_tree.h"                            // element_count
+#include "sql_class.h"                          // Unique
 
 int unique_write_to_file(uchar* key, element_count count, Unique *unique)
 {

=== modified file 'sql/unireg.cc'
--- a/sql/unireg.cc	2009-10-15 10:17:32 +0000
+++ b/sql/unireg.cc	2009-11-18 08:54:54 +0000
@@ -23,7 +23,10 @@
     str is a (long) to record position where 0 is the first position.
 */
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_partition.h"                      // struct partition_info
+#include "sql_class.h"                  // THD, Internal_error_handler
 #include <m_ctype.h>
 #include <assert.h>
 

=== modified file 'sql/unireg.h'
--- a/sql/unireg.h	2009-10-22 22:30:28 +0000
+++ b/sql/unireg.h	2009-11-18 08:54:54 +0000
@@ -17,8 +17,13 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 
+#include "my_global.h"                          /* ulonglong */
+#include "mysql_version.h"                      /* FRM_VER */
+
 /*  Extra functions used by unireg library */
 
+typedef struct st_ha_create_information HA_CREATE_INFO;
+
 #ifndef NO_ALARM_LOOP
 #define NO_ALARM_LOOP		/* lib5 and popen can't use alarm */
 #endif
@@ -49,71 +54,6 @@
 
 
 #define ERRMAPP 1				/* Errormap f|r my_error */
-#define LIBLEN FN_REFLEN-FN_LEN			/* Max l{ngd p} dev */
-/* extra 4+4 bytes for slave tmp tables */
-#define MAX_DBKEY_LENGTH (NAME_LEN*2+1+1+4+4)
-#define MAX_ALIAS_NAME 256
-#define MAX_FIELD_NAME 34			/* Max colum name length +2 */
-#define MAX_SYS_VAR_LENGTH 32
-#define MAX_KEY MAX_INDEXES                     /* Max used keys */
-#define MAX_REF_PARTS 16			/* Max parts used as ref */
-#define MAX_KEY_LENGTH 3072			/* max possible key */
-#if SIZEOF_OFF_T > 4
-#define MAX_REFLENGTH 8				/* Max length for record ref */
-#else
-#define MAX_REFLENGTH 4				/* Max length for record ref */
-#endif
-#define MAX_HOSTNAME  61			/* len+1 in mysql.user */
-
-#define MAX_MBWIDTH		3		/* Max multibyte sequence */
-#define MAX_FIELD_CHARLENGTH	255
-#define MAX_FIELD_VARCHARLENGTH	65535
-#define MAX_FIELD_BLOBLENGTH UINT_MAX32     /* cf field_blob::get_length() */
-#define CONVERT_IF_BIGGER_TO_BLOB 512		/* Used for CREATE ... SELECT */
-
-/* Max column width +1 */
-#define MAX_FIELD_WIDTH		(MAX_FIELD_CHARLENGTH*MAX_MBWIDTH+1)
-
-#define MAX_BIT_FIELD_LENGTH    64      /* Max length in bits for bit fields */
-
-#define MAX_DATE_WIDTH		10	/* YYYY-MM-DD */
-#define MAX_TIME_WIDTH		23	/* -DDDDDD HH:MM:SS.###### */
-#define MAX_DATETIME_FULL_WIDTH 29	/* YYYY-MM-DD HH:MM:SS.###### AM */
-#define MAX_DATETIME_WIDTH	19	/* YYYY-MM-DD HH:MM:SS */
-#define MAX_DATETIME_COMPRESSED_WIDTH 14  /* YYYYMMDDHHMMSS */
-
-#define MAX_TABLES	(sizeof(table_map)*8-3)	/* Max tables in join */
-#define PARAM_TABLE_BIT	(((table_map) 1) << (sizeof(table_map)*8-3))
-#define OUTER_REF_TABLE_BIT	(((table_map) 1) << (sizeof(table_map)*8-2))
-#define RAND_TABLE_BIT	(((table_map) 1) << (sizeof(table_map)*8-1))
-#define PSEUDO_TABLE_BITS (PARAM_TABLE_BIT | OUTER_REF_TABLE_BIT | \
-                           RAND_TABLE_BIT)
-#define MAX_FIELDS	4096			/* Limit in the .frm file */
-#define MAX_PARTITIONS  1024
-
-#define MAX_SELECT_NESTING (sizeof(nesting_map)*8-1)
-
-#define MAX_SORT_MEMORY (2048*1024-MALLOC_OVERHEAD)
-#define MIN_SORT_MEMORY (32*1024-MALLOC_OVERHEAD)
-
-/* Memory allocated when parsing a statement / saving a statement */
-#define MEM_ROOT_BLOCK_SIZE       8192
-#define MEM_ROOT_PREALLOC         8192
-#define TRANS_MEM_ROOT_BLOCK_SIZE 4096
-#define TRANS_MEM_ROOT_PREALLOC   4096
-
-#define DEFAULT_ERROR_COUNT	64
-#define EXTRA_RECORDS	10			/* Extra records in sort */
-#define SCROLL_EXTRA	5			/* Extra scroll-rows. */
-#define FIELD_NAME_USED ((uint) 32768)		/* Bit set if fieldname used */
-#define FORM_NAME_USED	((uint) 16384)		/* Bit set if formname used */
-#define FIELD_NR_MASK	16383			/* To get fieldnumber */
-#define FERR		-1			/* Error from my_functions */
-#define CREATE_MODE	0			/* Default mode on new files */
-#define NAMES_SEP_CHAR	'\377'			/* Char to sep. names */
-
-#define READ_RECORD_BUFFER	(uint) (IO_SIZE*8) /* Pointer_buffer_size */
-#define DISK_BUFFER_SIZE	(uint) (IO_SIZE*16) /* Size of diskbuffer */
 
 #define ME_INFO (ME_HOLDTANG+ME_OLDWIN+ME_NOREFRESH)
 #define ME_ERROR (ME_BELL+ME_OLDWIN+ME_NOREFRESH)
@@ -198,7 +138,6 @@
 #define TE_INFO_LENGTH 3
 #define MTYP_NOEMPTY_BIT 128
 
-#define FRM_VER_TRUE_VARCHAR (FRM_VER+4) /* 10 */
 /*
   Minimum length pattern before Turbo Boyer-Moore is used
   for SELECT "text" LIKE "%pattern%", excluding the two
@@ -221,5 +160,18 @@
 
 #include "mysqld_error.h"
 #include "structs.h"				/* All structs we need */
+#include "sql_list.h"                           /* List<> */
+#include "field.h"                              /* Create_field */
 
+bool mysql_create_frm(THD *thd, const char *file_name,
+                      const char *db, const char *table,
+		      HA_CREATE_INFO *create_info,
+		      List<Create_field> &create_field,
+		      uint key_count,KEY *key_info,handler *db_type);
+int rea_create_table(THD *thd, const char *path,
+                     const char *db, const char *table_name,
+                     HA_CREATE_INFO *create_info,
+  		     List<Create_field> &create_field,
+                     uint key_count,KEY *key_info,
+                     handler *file);
 #endif

=== modified file 'storage/archive/ha_archive.cc'
--- a/storage/archive/ha_archive.cc	2009-10-23 11:22:21 +0000
+++ b/storage/archive/ha_archive.cc	2009-11-18 08:54:54 +0000
@@ -17,8 +17,11 @@
 #pragma implementation        // gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#define MYSQL_SERVER 1
+
+#include "sql_priv.h"
 #include "probes_mysql.h"
+#include "sql_class.h"                          // SSV
 #include <myisam.h>
 
 #include "ha_archive.h"

=== modified file 'storage/blackhole/ha_blackhole.cc'
--- a/storage/blackhole/ha_blackhole.cc	2009-11-05 20:28:35 +0000
+++ b/storage/blackhole/ha_blackhole.cc	2009-11-18 08:54:54 +0000
@@ -19,9 +19,11 @@
 #endif
 
 #define MYSQL_SERVER 1
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
 #include "probes_mysql.h"
 #include "ha_blackhole.h"
+#include "sql_class.h"                          // THD, SYSTEM_THREAD_SLAVE_SQL
 
 /* Static declarations for handlerton */
 

=== modified file 'storage/blackhole/ha_blackhole.h'
--- a/storage/blackhole/ha_blackhole.h	2008-11-10 20:21:49 +0000
+++ b/storage/blackhole/ha_blackhole.h	2009-11-18 08:54:54 +0000
@@ -17,6 +17,10 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
+#include "thr_lock.h"                           /* THR_LOCK */
+#include "handler.h"                            /* handler */
+#include "table.h"                              /* TABLE_SHARE */
+
 /*
   Shared structure for correct LOCK operation
 */

=== modified file 'storage/csv/ha_tina.cc'
--- a/storage/csv/ha_tina.cc	2009-10-23 11:22:21 +0000
+++ b/storage/csv/ha_tina.cc	2009-11-18 08:54:54 +0000
@@ -45,7 +45,10 @@ TODO:
 #pragma implementation        // gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#define MYSQL_SERVER 1
+
+#include "sql_priv.h"
+#include "sql_class.h"                          // SSV
 #include <mysql/plugin.h>
 #include "ha_tina.h"
 #include "probes_mysql.h"

=== modified file 'storage/csv/transparent_file.cc'
--- a/storage/csv/transparent_file.cc	2009-03-24 09:02:01 +0000
+++ b/storage/csv/transparent_file.cc	2009-11-18 08:54:54 +0000
@@ -17,8 +17,9 @@
 #pragma implementation        // gcc: Class implementation
 #endif
 
-#include "mysql_priv.h"
+#include "sql_priv.h"
 #include "transparent_file.h"
+#include "my_sys.h"          // MY_WME, MY_ALLOW_ZERO_PTR, MY_SEEK_SET
 
 Transparent_file::Transparent_file() : lower_bound(0), buff_size(IO_SIZE)
 { 

=== modified file 'storage/example/ha_example.cc'
--- a/storage/example/ha_example.cc	2009-11-05 12:08:37 +0000
+++ b/storage/example/ha_example.cc	2009-11-18 08:54:54 +0000
@@ -92,10 +92,10 @@
 #endif
 
 #define MYSQL_SERVER 1
-#include "mysql_priv.h"
+#include "sql_priv.h"
 #include "ha_example.h"
 #include "probes_mysql.h"
-#include <mysql/plugin.h>
+#include "sql_plugin.h"
 
 static handler *example_create_handler(handlerton *hton,
                                        TABLE_SHARE *table, 

=== modified file 'storage/example/ha_example.h'
--- a/storage/example/ha_example.h	2007-08-13 13:11:25 +0000
+++ b/storage/example/ha_example.h	2009-11-18 08:54:54 +0000
@@ -35,6 +35,11 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
+#include "my_global.h"                   /* ulonglong */
+#include "thr_lock.h"                    /* THR_LOCK, THR_LOCK_DATA */
+#include "handler.h"                     /* handler */
+#include "my_base.h"                     /* ha_rows */
+
 /** @brief
   EXAMPLE_SHARE is a structure that will be shared among all open handlers.
   This example implements the minimum of what you will probably need.

=== modified file 'storage/federated/ha_federated.cc'
--- a/storage/federated/ha_federated.cc	2009-10-15 20:56:17 +0000
+++ b/storage/federated/ha_federated.cc	2009-11-18 08:54:54 +0000
@@ -372,7 +372,10 @@
 
 
 #define MYSQL_SERVER 1
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "sql_servers.h"         // FOREIGN_SERVER, get_server_by_name
+#include "sql_class.h"           // SSV
+#include "sql_analyse.h"         // append_escaped
 #include <mysql/plugin.h>
 
 #ifdef USE_PRAGMA_IMPLEMENTATION
@@ -383,6 +386,7 @@
 #include "probes_mysql.h"
 
 #include "m_string.h"
+#include "key.h"                                // key_copy
 
 #include <mysql/plugin.h>
 

=== modified file 'storage/heap/ha_heap.cc'
--- a/storage/heap/ha_heap.cc	2009-08-04 11:25:19 +0000
+++ b/storage/heap/ha_heap.cc	2009-11-18 08:54:54 +0000
@@ -19,9 +19,9 @@
 #endif
 
 #define MYSQL_SERVER 1
-#include "mysql_priv.h"
+#include "sql_priv.h"
 #include "probes_mysql.h"
-#include <mysql/plugin.h>
+#include "sql_plugin.h"
 #include "ha_heap.h"
 #include "heapdef.h"
 

=== modified file 'storage/heap/ha_heap.h'
--- a/storage/heap/ha_heap.h	2009-07-08 12:11:34 +0000
+++ b/storage/heap/ha_heap.h	2009-11-18 08:54:54 +0000
@@ -21,6 +21,7 @@
 /* class for the the heap handler */
 
 #include <heap.h>
+#include "sql_class.h"                          /* THD */
 
 class ha_heap: public handler
 {

=== modified file 'storage/innobase/handler/ha_innodb.cc'
--- a/storage/innobase/handler/ha_innodb.cc	2009-11-06 15:19:24 +0000
+++ b/storage/innobase/handler/ha_innodb.cc	2009-11-18 08:54:54 +0000
@@ -61,8 +61,11 @@ with this program; if not, write to the 
 #pragma implementation				// gcc: Class implementation
 #endif
 
-#include <mysql_priv.h>
+#define MYSQL_SERVER
 
+#include <sql_priv.h>
+
+#include <sql_acl.h>                            // PROCESS_ACL
 #include <m_ctype.h>
 #include <mysys_err.h>
 #include <mysql/plugin.h>
@@ -106,20 +109,25 @@ extern "C" {
 #include "ha_innodb.h"
 #include "i_s.h"
 
-#ifndef MYSQL_SERVER
 # ifndef MYSQL_PLUGIN_IMPORT
 #  define MYSQL_PLUGIN_IMPORT /* nothing */
 # endif /* MYSQL_PLUGIN_IMPORT */
 /* This is needed because of Bug #3596. Let us hope that pthread_mutex_t
 is defined the same in both builds: the MySQL server and the InnoDB plugin. */
 extern MYSQL_PLUGIN_IMPORT pthread_mutex_t LOCK_thread_count;
+extern uint filename_to_tablename(const char *from, char *to, uint to_length);
 
 #if MYSQL_VERSION_ID < 50124
 /* this is defined in mysql_priv.h inside #ifdef MYSQL_SERVER
 but we need it here */
 bool check_global_access(THD *thd, ulong want_access);
 #endif /* MYSQL_VERSION_ID < 50124 */
-#endif /* MYSQL_SERVER */
+
+/*
+  Prototypes for server-internal functions used in this file.
+ */
+extern int get_quote_char_for_identifier(THD *thd, const char *name, uint length);
+extern bool check_global_access(THD *thd, ulong want_access);
 
 /** to protect innobase_open_files */
 static pthread_mutex_t innobase_share_mutex;

=== modified file 'storage/innobase/handler/ha_innodb.h'
--- a/storage/innobase/handler/ha_innodb.h	2009-11-03 10:07:51 +0000
+++ b/storage/innobase/handler/ha_innodb.h	2009-11-18 08:54:54 +0000
@@ -266,6 +266,22 @@ void thd_mark_transaction_to_rollback(MY
 bool thd_binlog_filter_ok(const MYSQL_THD thd);
 }
 
+/**
+  Convert a string between character sets.
+
+  @note This is a server-internal C++ function.
+ */
+uint strconvert(CHARSET_INFO *from_cs, const char *from,
+                CHARSET_INFO *to_cs, char *to, uint to_length,
+                uint *errors);
+
+/**
+  Print an SQL error.
+
+  @note This is a server-internal C++ function.
+ */
+void sql_print_error(const char *format, ...);
+
 typedef struct trx_struct trx_t;
 /********************************************************************//**
 @file handler/ha_innodb.h

=== modified file 'storage/innobase/handler/handler0alter.cc'
--- a/storage/innobase/handler/handler0alter.cc	2009-11-05 12:29:58 +0000
+++ b/storage/innobase/handler/handler0alter.cc	2009-11-18 08:54:54 +0000
@@ -21,8 +21,10 @@ Place, Suite 330, Boston, MA 02111-1307 
 Smart ALTER TABLE
 *******************************************************/
 
-#include <mysql_priv.h>
+#include <sql_priv.h>
+#include <unireg.h>
 #include <mysqld_error.h>
+#include <sql_lex.h>                            // SQLCOM_CREATE_INDEX
 
 extern "C" {
 #include "log0log.h"

=== modified file 'storage/innobase/handler/i_s.cc'
--- a/storage/innobase/handler/i_s.cc	2009-10-19 13:10:22 +0000
+++ b/storage/innobase/handler/i_s.cc	2009-11-18 08:54:54 +0000
@@ -23,8 +23,11 @@ InnoDB INFORMATION SCHEMA tables interfa
 Created July 18, 2007 Vasil Dimov
 *******************************************************/
 
-#include <mysql_priv.h>
+#define MYSQL_SERVER 1
+
+#include <sql_priv.h>
 #include <mysqld_error.h>
+#include "sql_acl.h"                            // PROCESS_ACL
 
 #include <m_ctype.h>
 #include <hash.h>
@@ -32,7 +35,7 @@ Created July 18, 2007 Vasil Dimov
 #include <mysys_err.h>
 #include <my_sys.h>
 #include "i_s.h"
-#include <mysql/plugin.h>
+#include "sql_plugin.h"
 
 extern "C" {
 #include "trx0i_s.h"

=== modified file 'storage/innobase/handler/mysql_addons.cc'
--- a/storage/innobase/handler/mysql_addons.cc	2009-05-27 09:45:59 +0000
+++ b/storage/innobase/handler/mysql_addons.cc	2009-11-18 08:54:54 +0000
@@ -36,7 +36,7 @@ Created November 07, 2007 Vasil Dimov
 #define MYSQL_SERVER
 #endif /* MYSQL_SERVER */
 
-#include <mysql_priv.h>
+#include <sql_priv.h>
 
 #include "mysql_addons.h"
 #include "univ.i"

=== modified file 'storage/myisam/ha_myisam.cc'
--- a/storage/myisam/ha_myisam.cc	2009-11-05 09:23:55 +0000
+++ b/storage/myisam/ha_myisam.cc	2009-11-18 08:54:54 +0000
@@ -19,9 +19,10 @@
 #endif
 
 #define MYSQL_SERVER 1
-#include "mysql_priv.h"
+#include "sql_priv.h"
 #include "probes_mysql.h"
-#include <mysql/plugin.h>
+#include "key.h"                                // key_copy
+#include "sql_plugin.h"
 #include <m_ctype.h>
 #include <my_bit.h>
 #include <myisampack.h>
@@ -29,6 +30,8 @@
 #include <stdarg.h>
 #include "myisamdef.h"
 #include "rt_index.h"
+#include "sql_table.h"                          // tablename_to_filename
+#include "sql_class.h"                          // THD
 
 ulong myisam_recover_options= HA_RECOVER_NONE;
 

=== modified file 'storage/myisam/ha_myisam.h'
--- a/storage/myisam/ha_myisam.h	2009-07-08 12:11:34 +0000
+++ b/storage/myisam/ha_myisam.h	2009-11-18 08:54:54 +0000
@@ -22,6 +22,11 @@
 
 #include <myisam.h>
 #include <ft_global.h>
+#include "handler.h"                            /* handler */
+#include "table.h"                              /* TABLE_SHARE */
+
+struct TABLE_SHARE;
+typedef struct st_ha_create_information HA_CREATE_INFO;
 
 #define HA_RECOVER_NONE		0	/* No automatic recover */
 #define HA_RECOVER_DEFAULT	1	/* Automatic recover active */

=== modified file 'storage/myisammrg/ha_myisammrg.cc'
--- a/storage/myisammrg/ha_myisammrg.cc	2009-09-17 09:20:11 +0000
+++ b/storage/myisammrg/ha_myisammrg.cc	2009-11-18 08:54:54 +0000
@@ -95,14 +95,19 @@
 #endif
 
 #define MYSQL_SERVER 1
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "unireg.h"
+#include "sql_cache.h"                          // query_cache_*
+#include "sql_show.h"                           // append_identifier
+#include "sql_table.h"                         // build_table_filename
 #include "probes_mysql.h"
 #include <mysql/plugin.h>
 #include <m_ctype.h>
 #include "../myisam/ha_myisam.h"
 #include "ha_myisammrg.h"
 #include "myrg_def.h"
-
+#include "thr_malloc.h"                         // int_sql_alloc
+#include "sql_class.h"                          // THD
 
 static handler *myisammrg_create_handler(handlerton *hton,
                                          TABLE_SHARE *table,


Attachment: [text/bzr-bundle] bzr/mats@sun.com-20091118085454-06f8qaux935vaxvx.bundle
Thread
bzr push into mysql-5.5-trunk branch (mats:2921 to 2922) WL#5030Mats Kindahl9 Dec