summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2010-11-25 18:17:28 +0100
committerSergei Golubchik <sergii@pisem.net>2010-11-25 18:17:28 +0100
commit65ca700def99289cc31a7040537f5aa6e12bf485 (patch)
tree97b3a07299b626c519da0e80c122b5b79b933914 /include
parent2ab57de38d13d927ddff2d51aed4af34e13998f5 (diff)
parent6e5bcca7935d3c62f84bb640e5357664a210ee12 (diff)
downloadmariadb-git-65ca700def99289cc31a7040537f5aa6e12bf485.tar.gz
merge.
checkpoint. does not compile.
Diffstat (limited to 'include')
-rw-r--r--include/Makefile.am23
-rw-r--r--include/errmsg.h3
-rw-r--r--include/ft_global.h16
-rw-r--r--include/hash.h2
-rw-r--r--include/keycache.h214
-rw-r--r--include/lf.h14
-rw-r--r--include/m_ctype.h248
-rw-r--r--include/m_string.h32
-rw-r--r--include/maria.h481
-rw-r--r--include/my_alloc.h4
-rw-r--r--include/my_atomic.h6
-rw-r--r--include/my_base.h50
-rw-r--r--include/my_bitmap.h6
-rw-r--r--include/my_dbug.h5
-rw-r--r--include/my_global.h133
-rw-r--r--include/my_handler.h54
-rw-r--r--include/my_no_pthread.h1
-rw-r--r--include/my_pthread.h178
-rw-r--r--include/my_sys.h79
-rw-r--r--include/my_tree.h9
-rw-r--r--include/my_valgrind.h37
-rw-r--r--include/myisam.h267
-rw-r--r--include/myisamchk.h180
-rw-r--r--include/myisampack.h220
-rw-r--r--include/mysql.h58
-rw-r--r--include/mysql.h.pp70
-rw-r--r--include/mysql/client_plugin.h166
-rw-r--r--include/mysql/client_plugin.h.pp39
-rw-r--r--include/mysql/plugin.h73
-rw-r--r--include/mysql/plugin_auth.h83
-rw-r--r--include/mysql/plugin_auth.h.pp209
-rw-r--r--include/mysql/plugin_auth_common.h105
-rw-r--r--include/mysql/service_my_snprintf.h2
-rw-r--r--include/mysql_com.h66
-rw-r--r--include/mysql_version.h.in1
-rw-r--r--include/mysys_err.h5
-rw-r--r--include/queues.h61
-rw-r--r--include/sql_common.h68
-rw-r--r--include/thr_alarm.h5
-rw-r--r--include/thr_lock.h31
-rw-r--r--include/typelib.h6
-rw-r--r--include/violite.h4
-rw-r--r--include/waiting_threads.h130
-rw-r--r--include/wqueue.h27
44 files changed, 2606 insertions, 865 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index 909f68936dc..4282acb0c99 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -29,15 +29,17 @@ pkginclude_HEADERS = $(HEADERS_ABI) my_dbug.h m_string.h my_sys.h \
mysql/service_thread_scheduler.h \
mysql/service_thd_wait.h \
my_pthread.h my_no_pthread.h \
- decimal.h errmsg.h my_global.h my_net.h \
+ mysql/plugin_auth.h mysql/client_plugin.h \
+ mysql/plugin_auth_common.h \
+ decimal.h errmsg.h my_global.h my_valgrind.h my_net.h \
my_getopt.h sslopt-longopts.h my_dir.h \
sslopt-vars.h sslopt-case.h sql_common.h keycache.h \
m_ctype.h my_attribute.h my_compiler.h \
$(HEADERS_GEN_CONFIGURE) $(HEADERS_GEN_MAKE) \
probes_mysql.h probes_mysql_nodtrace.h
-noinst_HEADERS = lf.h my_bit.h \
- heap.h my_bitmap.h my_uctype.h password.h \
+noinst_HEADERS = lf.h my_bit.h password.h \
+ heap.h maria.h myisamchk.h my_bitmap.h my_uctype.h \
myisam.h myisampack.h myisammrg.h ft_global.h\
mysys_err.h my_base.h \
my_nosys.h my_alarm.h queues.h rijndael.h sha1.h sha2.h \
@@ -48,16 +50,19 @@ noinst_HEADERS = lf.h my_bit.h \
my_user.h my_atomic.h atomic/nolock.h \
atomic/rwlock.h atomic/x86-gcc.h atomic/generic-msvc.h \
atomic/gcc_builtins.h my_libwrap.h my_stacktrace.h \
- atomic/solaris.h mysql/innodb_priv.h
+ atomic/solaris.h mysql/innodb_priv.h \
+ wqueue.h waiting_threads.h
-pkgpsiinclude_HEADERS = mysql/psi/psi.h mysql/psi/mysql_thread.h \
- mysql/psi/mysql_file.h
-
-EXTRA_DIST = mysql.h.pp mysql/plugin.h.pp probes_mysql.d.base \
+EXTRA_DIST = mysql.h.pp probes_mysql.d.base \
CMakeLists.txt \
+ mysql/plugin_auth.h.pp mysql/client_plugin.h.pp \
+ mysql/plugin_audit.h.pp mysql/plugin_ftparser.h.pp \
mysql/psi/psi_abi_v1.h.pp \
mysql/psi/psi_abi_v2.h.pp
+pkgpsiinclude_HEADERS = mysql/psi/psi.h mysql/psi/mysql_thread.h \
+ mysql/psi/mysql_file.h
+
# Remove built files and the symlinked directories
CLEANFILES = $(BUILT_SOURCES) readline openssl probes_mysql.d probes_mysql_nodtrace.h
@@ -74,6 +79,8 @@ link_sources:
# We want both "my_config.h" and "config.h" that are identical, as
# MySQL sources assumes the name "my_config.h", and 3rd party sources
# assumes the name "config.h".
+# Normally this is generated by configure; This rule is left here in case
+# someone deletes my_config.h and expect it to be generated by make
my_config.h: config.h
$(CP) config.h my_config.h
diff --git a/include/errmsg.h b/include/errmsg.h
index c55c94af169..f1d7dd65f97 100644
--- a/include/errmsg.h
+++ b/include/errmsg.h
@@ -101,7 +101,8 @@ extern const char *client_errors[]; /* Error messages */
#define CR_STMT_CLOSED 2056
#define CR_NEW_STMT_METADATA 2057
#define CR_ALREADY_CONNECTED 2058
-#define CR_ERROR_LAST /*Copy last error nr:*/ 2058
+#define CR_AUTH_PLUGIN_CANNOT_LOAD 2059
+#define CR_ERROR_LAST /*Copy last error nr:*/ 2059
/* Add error numbers before CR_ERROR_LAST and change it accordingly. */
#endif /* ERRMSG_INCLUDED */
diff --git a/include/ft_global.h b/include/ft_global.h
index ad56bce678b..5e10cb09598 100644
--- a/include/ft_global.h
+++ b/include/ft_global.h
@@ -64,9 +64,23 @@ void ft_free_stopwords(void);
#define FT_SORTED 2
#define FT_EXPAND 4 /* query expansion */
-FT_INFO *ft_init_search(uint,void *, uint, uchar *, uint,CHARSET_INFO *, uchar *);
+FT_INFO *ft_init_search(uint,void *, uint, uchar *, size_t,
+ CHARSET_INFO *, uchar *);
my_bool ft_boolean_check_syntax_string(const uchar *);
+/* Internal symbols for fulltext between maria and MyISAM */
+
+#define HA_FT_WTYPE HA_KEYTYPE_FLOAT
+#define HA_FT_WLEN 4
+#define FT_SEGS 2
+
+#define ft_sintXkorr(A) mi_sint4korr(A)
+#define ft_intXstore(T,A) mi_int4store(T,A)
+
+extern const HA_KEYSEG ft_keysegs[FT_SEGS];
+
+typedef union {int32 i; float f;} FT_WEIGTH;
+
#ifdef __cplusplus
}
#endif
diff --git a/include/hash.h b/include/hash.h
index d390cb7d4e6..f3d9d82f187 100644
--- a/include/hash.h
+++ b/include/hash.h
@@ -48,6 +48,7 @@ extern "C" {
typedef uint my_hash_value_type;
typedef uchar *(*my_hash_get_key)(const uchar *,size_t*,my_bool);
typedef void (*my_hash_free_key)(void *);
+typedef my_bool (*my_hash_walk_action)(void *,void *);
typedef struct st_hash {
size_t key_offset,key_length; /* Length of key if const length */
@@ -96,6 +97,7 @@ my_bool my_hash_update(HASH *hash, uchar *record, uchar *old_key,
size_t old_key_length);
void my_hash_replace(HASH *hash, HASH_SEARCH_STATE *state, uchar *new_row);
my_bool my_hash_check(HASH *hash); /* Only in debug library */
+my_bool my_hash_iterate(HASH *hash, my_hash_walk_action action, void *argument);
#define my_hash_clear(H) bzero((char*) (H), sizeof(*(H)))
#define my_hash_inited(H) ((H)->blength != 0)
diff --git a/include/keycache.h b/include/keycache.h
index fefa31afd87..6220f6266fa 100644
--- a/include/keycache.h
+++ b/include/keycache.h
@@ -22,96 +22,144 @@
C_MODE_START
-/* declare structures that is used by st_key_cache */
+/*
+ Currently the default key cache is created as non-partitioned at
+ the start of the server unless the server is started with the parameter
+ --key-cache-partitions that is greater than 0
+*/
-struct st_block_link;
-typedef struct st_block_link BLOCK_LINK;
-struct st_keycache_page;
-typedef struct st_keycache_page KEYCACHE_PAGE;
-struct st_hash_link;
-typedef struct st_hash_link HASH_LINK;
+#define DEFAULT_KEY_CACHE_PARTITIONS 0
-/* info about requests in a waiting queue */
-typedef struct st_keycache_wqueue
-{
- struct st_my_thread_var *last_thread; /* circular list of waiting threads */
-} KEYCACHE_WQUEUE;
+/*
+ MAX_KEY_CACHE_PARTITIONS cannot be greater than
+ sizeof(MYISAM_SHARE::dirty_part_map)
+ Currently sizeof(MYISAM_SHARE::dirty_part_map)=sizeof(ulonglong)
+*/
+
+#define MAX_KEY_CACHE_PARTITIONS 64
+
+/* The structure to get statistical data about a key cache */
-#define CHANGED_BLOCKS_HASH 128 /* must be power of 2 */
+typedef struct st_key_cache_statistics
+{
+ ulonglong mem_size; /* memory for cache buffers/auxiliary structures */
+ ulonglong block_size; /* size of the each buffers in the key cache */
+ ulonglong blocks_used; /* maximum number of used blocks/buffers */
+ ulonglong blocks_unused; /* number of currently unused blocks */
+ ulonglong blocks_changed; /* number of currently dirty blocks */
+ ulonglong blocks_warm; /* number of blocks in warm sub-chain */
+ ulonglong read_requests; /* number of read requests (read hits) */
+ ulonglong reads; /* number of actual reads from files into buffers */
+ ulonglong write_requests; /* number of write requests (write hits) */
+ ulonglong writes; /* number of actual writes from buffers into files */
+} KEY_CACHE_STATISTICS;
+
+#define NUM_LONG_KEY_CACHE_STAT_VARIABLES 3
+
+/* The type of a key cache object */
+typedef enum key_cache_type
+{
+ SIMPLE_KEY_CACHE,
+ PARTITIONED_KEY_CACHE
+} KEY_CACHE_TYPE;
+
+
+typedef
+ int (*INIT_KEY_CACHE)
+ (void *, uint key_cache_block_size,
+ size_t use_mem, uint division_limit, uint age_threshold);
+typedef
+ int (*RESIZE_KEY_CACHE)
+ (void *, uint key_cache_block_size,
+ size_t use_mem, uint division_limit, uint age_threshold);
+typedef
+ void (*CHANGE_KEY_CACHE_PARAM)
+ (void *keycache_cb,
+ uint division_limit, uint age_threshold);
+typedef
+ uchar* (*KEY_CACHE_READ)
+ (void *keycache_cb,
+ File file, my_off_t filepos, int level,
+ uchar *buff, uint length,
+ uint block_length, int return_buffer);
+typedef
+ int (*KEY_CACHE_INSERT)
+ (void *keycache_cb,
+ File file, my_off_t filepos, int level,
+ uchar *buff, uint length);
+typedef
+ int (*KEY_CACHE_WRITE)
+ (void *keycache_cb,
+ File file, void *file_extra,
+ my_off_t filepos, int level,
+ uchar *buff, uint length,
+ uint block_length, int force_write);
+typedef
+ int (*FLUSH_KEY_BLOCKS)
+ (void *keycache_cb,
+ int file, void *file_extra,
+ enum flush_type type);
+typedef
+ int (*RESET_KEY_CACHE_COUNTERS)
+ (const char *name, void *keycache_cb);
+typedef
+ void (*END_KEY_CACHE)
+ (void *keycache_cb, my_bool cleanup);
+typedef
+ void (*GET_KEY_CACHE_STATISTICS)
+ (void *keycache_cb, uint partition_no,
+ KEY_CACHE_STATISTICS *key_cache_stats);
/*
- The key cache structure
- It also contains read-only statistics parameters.
+ An object of the type KEY_CACHE_FUNCS contains pointers to all functions
+ from the key cache interface.
+ Currently a key cache can be of two types: simple and partitioned.
+ For each of them its own static structure of the type KEY_CACHE_FUNCS is
+ defined . The structures contain the pointers to the implementations of
+ the interface functions used by simple key caches and partitioned key
+ caches respectively. Pointers to these structures are assigned to key cache
+ objects at the time of their creation.
*/
+typedef struct st_key_cache_funcs
+{
+ INIT_KEY_CACHE init;
+ RESIZE_KEY_CACHE resize;
+ CHANGE_KEY_CACHE_PARAM change_param;
+ KEY_CACHE_READ read;
+ KEY_CACHE_INSERT insert;
+ KEY_CACHE_WRITE write;
+ FLUSH_KEY_BLOCKS flush;
+ RESET_KEY_CACHE_COUNTERS reset_counters;
+ END_KEY_CACHE end;
+ GET_KEY_CACHE_STATISTICS get_stats;
+} KEY_CACHE_FUNCS;
+
+
typedef struct st_key_cache
{
- my_bool key_cache_inited;
- my_bool in_resize; /* true during resize operation */
- my_bool resize_in_flush; /* true during flush of resize operation */
+ KEY_CACHE_TYPE key_cache_type; /* type of the key cache used for debugging */
+ void *keycache_cb; /* control block of the used key cache */
+ KEY_CACHE_FUNCS *interface_funcs; /* interface functions of the key cache */
+ ulonglong param_buff_size; /* size the memory allocated for the cache */
+ ulonglong param_block_size; /* size of the blocks in the key cache */
+ ulonglong param_division_limit;/* min. percentage of warm blocks */
+ ulonglong param_age_threshold; /* determines when hot block is downgraded */
+ ulonglong param_partitions; /* number of the key cache partitions */
+ my_bool key_cache_inited; /* <=> key cache has been created */
my_bool can_be_used; /* usage of cache for read/write is allowed */
- size_t key_cache_mem_size; /* specified size of the cache memory */
- uint key_cache_block_size; /* size of the page buffer of a cache block */
- ulong min_warm_blocks; /* min number of warm blocks; */
- ulong age_threshold; /* age threshold for hot blocks */
- ulonglong keycache_time; /* total number of block link operations */
- uint hash_entries; /* max number of entries in the hash table */
- int hash_links; /* max number of hash links */
- int hash_links_used; /* number of hash links currently used */
- int disk_blocks; /* max number of blocks in the cache */
- ulong blocks_used; /* maximum number of concurrently used blocks */
- ulong blocks_unused; /* number of currently unused blocks */
- ulong blocks_changed; /* number of currently dirty blocks */
- ulong warm_blocks; /* number of blocks in warm sub-chain */
- ulong cnt_for_resize_op; /* counter to block resize operation */
- long blocks_available; /* number of blocks available in the LRU chain */
- HASH_LINK **hash_root; /* arr. of entries into hash table buckets */
- HASH_LINK *hash_link_root; /* memory for hash table links */
- HASH_LINK *free_hash_list; /* list of free hash links */
- BLOCK_LINK *free_block_list; /* list of free blocks */
- BLOCK_LINK *block_root; /* memory for block links */
- uchar *block_mem; /* memory for block buffers */
- BLOCK_LINK *used_last; /* ptr to the last block of the LRU chain */
- BLOCK_LINK *used_ins; /* ptr to the insertion block in LRU chain */
- mysql_mutex_t cache_lock; /* to lock access to the cache structure */
- KEYCACHE_WQUEUE resize_queue; /* threads waiting during resize operation */
- /*
- Waiting for a zero resize count. Using a queue for symmetry though
- only one thread can wait here.
- */
- KEYCACHE_WQUEUE waiting_for_resize_cnt;
- KEYCACHE_WQUEUE waiting_for_hash_link; /* waiting for a free hash link */
- KEYCACHE_WQUEUE waiting_for_block; /* requests waiting for a free block */
- BLOCK_LINK *changed_blocks[CHANGED_BLOCKS_HASH]; /* hash for dirty file bl.*/
- BLOCK_LINK *file_blocks[CHANGED_BLOCKS_HASH]; /* hash for other file bl.*/
-
- /*
- The following variables are and variables used to hold parameters for
- initializing the key cache.
- */
-
- ulonglong param_buff_size; /* size the memory allocated for the cache */
- ulonglong param_block_size; /* size of the blocks in the key cache */
- ulonglong param_division_limit; /* min. percentage of warm blocks */
- ulonglong param_age_threshold; /* determines when hot block is downgraded */
-
- /* Statistics variables. These are reset in reset_key_cache_counters(). */
- ulong global_blocks_changed; /* number of currently dirty blocks */
- ulonglong global_cache_w_requests;/* number of write requests (write hits) */
- ulonglong global_cache_write; /* number of writes from cache to files */
- ulonglong global_cache_r_requests;/* number of read requests (read hits) */
- ulonglong global_cache_read; /* number of reads from files to cache */
-
- int blocks; /* max number of blocks in the cache */
- my_bool in_init; /* Set to 1 in MySQL during init/resize */
+ my_bool in_init; /* Set to 1 in MySQL during init/resize */
+ uint partitions; /* actual number of partitions */
+ size_t key_cache_mem_size; /* specified size of the cache memory */
} KEY_CACHE;
+
/* The default key cache */
extern KEY_CACHE dflt_key_cache_var, *dflt_key_cache;
extern int init_key_cache(KEY_CACHE *keycache, uint key_cache_block_size,
size_t use_mem, uint division_limit,
- uint age_threshold);
+ uint age_threshold, uint partitions);
extern int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size,
size_t use_mem, uint division_limit,
uint age_threshold);
@@ -125,22 +173,34 @@ extern int key_cache_insert(KEY_CACHE *keycache,
File file, my_off_t filepos, int level,
uchar *buff, uint length);
extern int key_cache_write(KEY_CACHE *keycache,
- File file, my_off_t filepos, int level,
+ File file, void *file_extra,
+ my_off_t filepos, int level,
uchar *buff, uint length,
- uint block_length,int force_write);
+ uint block_length, int force_write);
extern int flush_key_blocks(KEY_CACHE *keycache,
- int file, enum flush_type type);
+ int file, void *file_extra,
+ enum flush_type type);
extern void end_key_cache(KEY_CACHE *keycache, my_bool cleanup);
+extern void get_key_cache_statistics(KEY_CACHE *keycache,
+ uint partition_no,
+ KEY_CACHE_STATISTICS *key_cache_stats);
/* Functions to handle multiple key caches */
extern my_bool multi_keycache_init(void);
extern void multi_keycache_free(void);
-extern KEY_CACHE *multi_key_cache_search(uchar *key, uint length);
+extern KEY_CACHE *multi_key_cache_search(uchar *key, uint length,
+ KEY_CACHE *def);
extern my_bool multi_key_cache_set(const uchar *key, uint length,
KEY_CACHE *key_cache);
extern void multi_key_cache_change(KEY_CACHE *old_data,
KEY_CACHE *new_data);
extern int reset_key_cache_counters(const char *name,
KEY_CACHE *key_cache);
+extern int repartition_key_cache(KEY_CACHE *keycache,
+ uint key_cache_block_size,
+ size_t use_mem,
+ uint division_limit,
+ uint age_threshold,
+ uint partitions);
C_MODE_END
#endif /* _keycache_h */
diff --git a/include/lf.h b/include/lf.h
index e9fb094493f..9698086bacf 100644
--- a/include/lf.h
+++ b/include/lf.h
@@ -115,10 +115,11 @@ typedef struct {
void *purgatory;
uint32 purgatory_count;
uint32 volatile link;
-/* we want sizeof(LF_PINS) to be 64 to avoid false sharing */
-#if SIZEOF_INT*2+SIZEOF_CHARP*(LF_PINBOX_PINS+3) != 64
- char pad[64-sizeof(uint32)*2-sizeof(void*)*(LF_PINBOX_PINS+3)];
-#endif
+/* we want sizeof(LF_PINS) to be 128 to avoid false sharing */
+ char pad[128-sizeof(uint32)*2
+ -sizeof(LF_PINBOX *)
+ -sizeof(void*)
+ -sizeof(void *)*(LF_PINBOX_PINS+1)];
} LF_PINS;
/*
@@ -187,6 +188,8 @@ typedef struct st_lf_allocator {
uchar * volatile top;
uint element_size;
uint32 volatile mallocs;
+ void (*constructor)(uchar *); /* called, when an object is malloc()'ed */
+ void (*destructor)(uchar *); /* called, when an object is free()'d */
} LF_ALLOCATOR;
void lf_alloc_init(LF_ALLOCATOR *allocator, uint size, uint free_ptr_offset);
@@ -220,7 +223,8 @@ C_MODE_START
#define LF_HASH_UNIQUE 1
-/* lf_hash overhead per element is sizeof(LF_SLIST). */
+/* lf_hash overhead per element (that is, sizeof(LF_SLIST) */
+extern const int LF_HASH_OVERHEAD;
typedef struct {
LF_DYNARRAY array; /* hash itself */
diff --git a/include/m_ctype.h b/include/m_ctype.h
index 42e8f88cc0e..93c7e84e8a0 100644
--- a/include/m_ctype.h
+++ b/include/m_ctype.h
@@ -54,24 +54,46 @@ extern "C" {
#define MY_PUT_MB2(s, code) { (s)[0]= code >> 8; (s)[1]= code & 0xFF; }
#endif
+typedef const struct charset_info_st CHARSET_INFO;
+typedef const struct my_charset_handler_st MY_CHARSET_HANDLER;
+typedef const struct my_collation_handler_st MY_COLLATION_HANDLER;
+typedef const struct unicase_info_st MY_UNICASE_INFO;
+typedef const struct uni_ctype_st MY_UNI_CTYPE;
+typedef const struct my_uni_idx_st MY_UNI_IDX;
-typedef struct unicase_info_st
+struct unicase_info_st
{
uint32 toupper;
uint32 tolower;
uint32 sort;
-} MY_UNICASE_INFO;
+};
+
+extern MY_UNICASE_INFO *const my_unicase_default[256];
+extern MY_UNICASE_INFO *const my_unicase_turkish[256];
+
+#define MY_UCA_MAX_CONTRACTION 4
+#define MY_UCA_MAX_WEIGHT_SIZE 8
+
+typedef struct my_contraction_t
+{
+ my_wc_t ch[MY_UCA_MAX_CONTRACTION]; /* Character sequence */
+ uint16 weight[MY_UCA_MAX_WEIGHT_SIZE];/* Its weight string, 0-terminated */
+} MY_CONTRACTION;
-extern MY_UNICASE_INFO *my_unicase_default[256];
-extern MY_UNICASE_INFO *my_unicase_turkish[256];
+typedef struct my_contraction_list_t
+{
+ size_t nitems; /* Number of items in the list */
+ MY_CONTRACTION *item; /* List of contractions */
+ char *flags; /* Character flags, e.g. "is contraction head") */
+} MY_CONTRACTIONS;
-typedef struct uni_ctype_st
+struct uni_ctype_st
{
uchar pctype;
- uchar *ctype;
-} MY_UNI_CTYPE;
+ const uchar *ctype;
+};
extern MY_UNI_CTYPE my_uni_ctype[256];
@@ -114,12 +136,12 @@ extern MY_UNI_CTYPE my_uni_ctype[256];
#define MY_REPERTOIRE_EXTENDED 2 /* Extended characters: U+0080..U+FFFF */
#define MY_REPERTOIRE_UNICODE30 3 /* ASCII | EXTENDED: U+0000..U+FFFF */
-typedef struct my_uni_idx_st
+struct my_uni_idx_st
{
uint16 from;
uint16 to;
- uchar *tab;
-} MY_UNI_IDX;
+ const uchar *tab;
+};
typedef struct
{
@@ -148,41 +170,41 @@ struct charset_info_st;
/* See strings/CHARSET_INFO.txt for information about this structure */
-typedef struct my_collation_handler_st
+struct my_collation_handler_st
{
my_bool (*init)(struct charset_info_st *, void *(*alloc)(size_t));
/* Collation routines */
- int (*strnncoll)(struct charset_info_st *,
+ int (*strnncoll)(CHARSET_INFO *,
const uchar *, size_t, const uchar *, size_t, my_bool);
- int (*strnncollsp)(struct charset_info_st *,
+ int (*strnncollsp)(CHARSET_INFO *,
const uchar *, size_t, const uchar *, size_t,
my_bool diff_if_only_endspace_difference);
- size_t (*strnxfrm)(struct charset_info_st *,
+ size_t (*strnxfrm)(CHARSET_INFO *,
uchar *, size_t, const uchar *, size_t);
- size_t (*strnxfrmlen)(struct charset_info_st *, size_t);
- my_bool (*like_range)(struct charset_info_st *,
+ size_t (*strnxfrmlen)(CHARSET_INFO *, size_t);
+ my_bool (*like_range)(CHARSET_INFO *,
const char *s, size_t s_length,
pchar w_prefix, pchar w_one, pchar w_many,
size_t res_length,
char *min_str, char *max_str,
size_t *min_len, size_t *max_len);
- int (*wildcmp)(struct charset_info_st *,
+ int (*wildcmp)(CHARSET_INFO *,
const char *str,const char *str_end,
const char *wildstr,const char *wildend,
int escape,int w_one, int w_many);
- int (*strcasecmp)(struct charset_info_st *, const char *, const char *);
+ int (*strcasecmp)(CHARSET_INFO *, const char *, const char *);
- uint (*instr)(struct charset_info_st *,
+ uint (*instr)(CHARSET_INFO *,
const char *b, size_t b_length,
const char *s, size_t s_length,
my_match_t *match, uint nmatch);
/* Hash calculation */
- void (*hash_sort)(struct charset_info_st *cs, const uchar *key, size_t len,
+ void (*hash_sort)(CHARSET_INFO *cs, const uchar *key, size_t len,
ulong *nr1, ulong *nr2);
- my_bool (*propagate)(struct charset_info_st *cs, const uchar *str, size_t len);
-} MY_COLLATION_HANDLER;
+ my_bool (*propagate)(CHARSET_INFO *cs, const uchar *str, size_t len);
+};
extern MY_COLLATION_HANDLER my_collation_mb_bin_handler;
extern MY_COLLATION_HANDLER my_collation_8bit_bin_handler;
@@ -190,76 +212,76 @@ extern MY_COLLATION_HANDLER my_collation_8bit_simple_ci_handler;
extern MY_COLLATION_HANDLER my_collation_ucs2_uca_handler;
/* Some typedef to make it easy for C++ to make function pointers */
-typedef int (*my_charset_conv_mb_wc)(struct charset_info_st *, my_wc_t *,
+typedef int (*my_charset_conv_mb_wc)(CHARSET_INFO *, my_wc_t *,
const uchar *, const uchar *);
-typedef int (*my_charset_conv_wc_mb)(struct charset_info_st *, my_wc_t,
+typedef int (*my_charset_conv_wc_mb)(CHARSET_INFO *, my_wc_t,
uchar *, uchar *);
-typedef size_t (*my_charset_conv_case)(struct charset_info_st *,
+typedef size_t (*my_charset_conv_case)(CHARSET_INFO *,
char *, size_t, char *, size_t);
/* See strings/CHARSET_INFO.txt about information on this structure */
-typedef struct my_charset_handler_st
+struct my_charset_handler_st
{
my_bool (*init)(struct charset_info_st *, void *(*alloc)(size_t));
/* Multibyte routines */
- uint (*ismbchar)(struct charset_info_st *, const char *, const char *);
- uint (*mbcharlen)(struct charset_info_st *, uint c);
- size_t (*numchars)(struct charset_info_st *, const char *b, const char *e);
- size_t (*charpos)(struct charset_info_st *, const char *b, const char *e,
+ uint (*ismbchar)(CHARSET_INFO *, const char *, const char *);
+ uint (*mbcharlen)(CHARSET_INFO *, uint c);
+ size_t (*numchars)(CHARSET_INFO *, const char *b, const char *e);
+ size_t (*charpos)(CHARSET_INFO *, const char *b, const char *e,
size_t pos);
- size_t (*well_formed_len)(struct charset_info_st *,
+ size_t (*well_formed_len)(CHARSET_INFO *,
const char *b,const char *e,
size_t nchars, int *error);
- size_t (*lengthsp)(struct charset_info_st *, const char *ptr, size_t length);
- size_t (*numcells)(struct charset_info_st *, const char *b, const char *e);
+ size_t (*lengthsp)(CHARSET_INFO *, const char *ptr, size_t length);
+ size_t (*numcells)(CHARSET_INFO *, const char *b, const char *e);
/* Unicode conversion */
my_charset_conv_mb_wc mb_wc;
my_charset_conv_wc_mb wc_mb;
/* CTYPE scanner */
- int (*ctype)(struct charset_info_st *cs, int *ctype,
+ int (*ctype)(CHARSET_INFO *cs, int *ctype,
const uchar *s, const uchar *e);
/* Functions for case and sort conversion */
- size_t (*caseup_str)(struct charset_info_st *, char *);
- size_t (*casedn_str)(struct charset_info_st *, char *);
+ size_t (*caseup_str)(CHARSET_INFO *, char *);
+ size_t (*casedn_str)(CHARSET_INFO *, char *);
my_charset_conv_case caseup;
my_charset_conv_case casedn;
/* Charset dependant snprintf() */
- size_t (*snprintf)(struct charset_info_st *, char *to, size_t n,
+ size_t (*snprintf)(CHARSET_INFO *, char *to, size_t n,
const char *fmt,
...) ATTRIBUTE_FORMAT_FPTR(printf, 4, 5);
- size_t (*long10_to_str)(struct charset_info_st *, char *to, size_t n,
+ size_t (*long10_to_str)(CHARSET_INFO *, char *to, size_t n,
int radix, long int val);
- size_t (*longlong10_to_str)(struct charset_info_st *, char *to, size_t n,
+ size_t (*longlong10_to_str)(CHARSET_INFO *, char *to, size_t n,
int radix, longlong val);
- void (*fill)(struct charset_info_st *, char *to, size_t len, int fill);
+ void (*fill)(CHARSET_INFO *, char *to, size_t len, int fill);
/* String-to-number conversion routines */
- long (*strntol)(struct charset_info_st *, const char *s, size_t l,
+ long (*strntol)(CHARSET_INFO *, const char *s, size_t l,
int base, char **e, int *err);
- ulong (*strntoul)(struct charset_info_st *, const char *s, size_t l,
+ ulong (*strntoul)(CHARSET_INFO *, const char *s, size_t l,
int base, char **e, int *err);
- longlong (*strntoll)(struct charset_info_st *, const char *s, size_t l,
+ longlong (*strntoll)(CHARSET_INFO *, const char *s, size_t l,
int base, char **e, int *err);
- ulonglong (*strntoull)(struct charset_info_st *, const char *s, size_t l,
+ ulonglong (*strntoull)(CHARSET_INFO *, const char *s, size_t l,
int base, char **e, int *err);
- double (*strntod)(struct charset_info_st *, char *s, size_t l, char **e,
+ double (*strntod)(CHARSET_INFO *, char *s, size_t l, char **e,
int *err);
- longlong (*strtoll10)(struct charset_info_st *cs,
+ longlong (*strtoll10)(CHARSET_INFO *cs,
const char *nptr, char **endptr, int *error);
- ulonglong (*strntoull10rnd)(struct charset_info_st *cs,
+ ulonglong (*strntoull10rnd)(CHARSET_INFO *cs,
const char *str, size_t length,
int unsigned_fl,
char **endptr, int *error);
- size_t (*scan)(struct charset_info_st *, const char *b, const char *e,
+ size_t (*scan)(CHARSET_INFO *, const char *b, const char *e,
int sq);
-} MY_CHARSET_HANDLER;
+};
extern MY_CHARSET_HANDLER my_charset_8bit_handler;
extern MY_CHARSET_HANDLER my_charset_ucs2_handler;
@@ -272,7 +294,7 @@ extern MY_CHARSET_HANDLER my_charset_ucs2_handler;
#define CHARSET_INFO_DEFINED
/* See strings/CHARSET_INFO.txt about information on this structure */
-typedef struct charset_info_st
+struct charset_info_st
{
uint number;
uint primary_number;
@@ -282,17 +304,17 @@ typedef struct charset_info_st
const char *name;
const char *comment;
const char *tailoring;
- uchar *ctype;
- uchar *to_lower;
- uchar *to_upper;
- uchar *sort_order;
- uint16 *contractions;
- uint16 **sort_order_big;
- uint16 *tab_to_uni;
- MY_UNI_IDX *tab_from_uni;
- MY_UNICASE_INFO **caseinfo;
- uchar *state_map;
- uchar *ident_map;
+ const uchar *ctype;
+ const uchar *to_lower;
+ const uchar *to_upper;
+ const uchar *sort_order;
+ const MY_CONTRACTIONS *contractions;
+ const uint16 *const *sort_order_big;
+ const uint16 *tab_to_uni;
+ MY_UNI_IDX *tab_from_uni;
+ MY_UNICASE_INFO *const *caseinfo;
+ const uchar *state_map;
+ const uchar *ident_map;
uint strxfrm_multiply;
uchar caseup_multiply;
uchar casedn_multiply;
@@ -306,56 +328,53 @@ typedef struct charset_info_st
MY_CHARSET_HANDLER *cset;
MY_COLLATION_HANDLER *coll;
-} CHARSET_INFO;
+};
#define ILLEGAL_CHARSET_INFO_NUMBER (~0U)
-
-extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_bin;
-extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_latin1;
-extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_filename;
-
-extern CHARSET_INFO my_charset_big5_chinese_ci;
-extern CHARSET_INFO my_charset_big5_bin;
-extern CHARSET_INFO my_charset_cp932_japanese_ci;
-extern CHARSET_INFO my_charset_cp932_bin;
-extern CHARSET_INFO my_charset_cp1250_czech_ci;
-extern CHARSET_INFO my_charset_eucjpms_japanese_ci;
-extern CHARSET_INFO my_charset_eucjpms_bin;
-extern CHARSET_INFO my_charset_euckr_korean_ci;
-extern CHARSET_INFO my_charset_euckr_bin;
-extern CHARSET_INFO my_charset_gb2312_chinese_ci;
-extern CHARSET_INFO my_charset_gb2312_bin;
-extern CHARSET_INFO my_charset_gbk_chinese_ci;
-extern CHARSET_INFO my_charset_gbk_bin;
-extern CHARSET_INFO my_charset_latin1_german2_ci;
-extern CHARSET_INFO my_charset_latin1_bin;
-extern CHARSET_INFO my_charset_latin2_czech_ci;
-extern CHARSET_INFO my_charset_sjis_japanese_ci;
-extern CHARSET_INFO my_charset_sjis_bin;
-extern CHARSET_INFO my_charset_tis620_thai_ci;
-extern CHARSET_INFO my_charset_tis620_bin;
-extern CHARSET_INFO my_charset_ucs2_general_ci;
-extern CHARSET_INFO my_charset_ucs2_bin;
-extern CHARSET_INFO my_charset_ucs2_unicode_ci;
-extern CHARSET_INFO my_charset_ujis_japanese_ci;
-extern CHARSET_INFO my_charset_ujis_bin;
-extern CHARSET_INFO my_charset_utf16_bin;
-extern CHARSET_INFO my_charset_utf16_general_ci;
-extern CHARSET_INFO my_charset_utf16_unicode_ci;
-extern CHARSET_INFO my_charset_utf32_bin;
-extern CHARSET_INFO my_charset_utf32_general_ci;
-extern CHARSET_INFO my_charset_utf32_unicode_ci;
-
-extern CHARSET_INFO my_charset_utf8_general_ci;
-extern CHARSET_INFO my_charset_utf8_unicode_ci;
-extern CHARSET_INFO my_charset_utf8_bin;
-extern CHARSET_INFO my_charset_utf8mb4_bin;
-extern CHARSET_INFO my_charset_utf8mb4_general_ci;
-extern CHARSET_INFO my_charset_utf8mb4_unicode_ci;
+extern MYSQL_PLUGIN_IMPORT struct charset_info_st my_charset_bin;
+extern MYSQL_PLUGIN_IMPORT struct charset_info_st my_charset_latin1;
+extern MYSQL_PLUGIN_IMPORT struct charset_info_st my_charset_filename;
+
+extern struct charset_info_st my_charset_big5_bin;
+extern struct charset_info_st my_charset_big5_chinese_ci;
+extern struct charset_info_st my_charset_cp1250_czech_ci;
+extern struct charset_info_st my_charset_cp932_bin;
+extern struct charset_info_st my_charset_cp932_japanese_ci;
+extern struct charset_info_st my_charset_eucjpms_bin;
+extern struct charset_info_st my_charset_eucjpms_japanese_ci;
+extern struct charset_info_st my_charset_euckr_bin;
+extern struct charset_info_st my_charset_euckr_korean_ci;
+extern struct charset_info_st my_charset_gb2312_bin;
+extern struct charset_info_st my_charset_gb2312_chinese_ci;
+extern struct charset_info_st my_charset_gbk_bin;
+extern struct charset_info_st my_charset_gbk_chinese_ci;
+extern struct charset_info_st my_charset_latin1_bin;
+extern struct charset_info_st my_charset_latin1_german2_ci;
+extern struct charset_info_st my_charset_latin2_czech_ci;
+extern struct charset_info_st my_charset_sjis_bin;
+extern struct charset_info_st my_charset_sjis_japanese_ci;
+extern struct charset_info_st my_charset_tis620_bin;
+extern struct charset_info_st my_charset_tis620_thai_ci;
+extern struct charset_info_st my_charset_ucs2_bin;
+extern struct charset_info_st my_charset_ucs2_general_ci;
+extern struct charset_info_st my_charset_ucs2_unicode_ci;
+extern struct charset_info_st my_charset_ujis_bin;
+extern struct charset_info_st my_charset_ujis_japanese_ci;
+extern struct charset_info_st my_charset_utf16_bin;
+extern struct charset_info_st my_charset_utf16_general_ci;
+extern struct charset_info_st my_charset_utf16_unicode_ci;
+extern struct charset_info_st my_charset_utf32_bin;
+extern struct charset_info_st my_charset_utf32_general_ci;
+extern struct charset_info_st my_charset_utf32_unicode_ci;
+extern struct charset_info_st my_charset_utf8_bin;
+extern struct charset_info_st my_charset_utf8_general_ci;
+extern struct charset_info_st my_charset_utf8_unicode_ci;
+extern struct charset_info_st my_charset_utf8mb4_bin;
+extern struct charset_info_st my_charset_utf8mb4_general_ci;
+extern struct charset_info_st my_charset_utf8mb4_unicode_ci;
#define MY_UTF8MB3 "utf8"
#define MY_UTF8MB4 "utf8mb4"
-
/* declarations for simple charsets */
extern size_t my_strnxfrm_simple(CHARSET_INFO *, uchar *, size_t,
const uchar *, size_t);
@@ -373,7 +392,7 @@ extern void my_hash_sort_simple(CHARSET_INFO *cs,
extern size_t my_lengthsp_8bit(CHARSET_INFO *cs, const char *ptr, size_t length);
-extern uint my_instr_simple(struct charset_info_st *,
+extern uint my_instr_simple(CHARSET_INFO *,
const char *b, size_t b_length,
const char *s, size_t s_length,
my_match_t *match, uint nmatch);
@@ -397,7 +416,7 @@ int my_mb_ctype_mb(CHARSET_INFO *,int *, const uchar *,const uchar *);
size_t my_scan_8bit(CHARSET_INFO *cs, const char *b, const char *e, int sq);
-size_t my_snprintf_8bit(struct charset_info_st *, char *to, size_t n,
+size_t my_snprintf_8bit(CHARSET_INFO *, char *to, size_t n,
const char *fmt, ...)
ATTRIBUTE_FORMAT(printf, 4, 5);
@@ -509,7 +528,7 @@ size_t my_numcells_mb(CHARSET_INFO *, const char *b, const char *e);
size_t my_charpos_mb(CHARSET_INFO *, const char *b, const char *e, size_t pos);
size_t my_well_formed_len_mb(CHARSET_INFO *, const char *b, const char *e,
size_t pos, int *error);
-uint my_instr_mb(struct charset_info_st *,
+uint my_instr_mb(CHARSET_INFO *,
const char *b, size_t b_length,
const char *s, size_t s_length,
my_match_t *match, uint nmatch);
@@ -548,10 +567,10 @@ int my_wildcmp_unicode(CHARSET_INFO *cs,
const char *str, const char *str_end,
const char *wildstr, const char *wildend,
int escape, int w_one, int w_many,
- MY_UNICASE_INFO **weights);
+ MY_UNICASE_INFO *const *weights);
extern my_bool my_parse_charset_xml(const char *bug, size_t len,
- int (*add)(CHARSET_INFO *cs));
+ int (*add)(struct charset_info_st *cs));
extern char *my_strchr(CHARSET_INFO *cs, const char *str, const char *end,
pchar c);
@@ -566,6 +585,12 @@ uint my_charset_repertoire(CHARSET_INFO *cs);
my_bool my_charset_is_ascii_compatible(CHARSET_INFO *cs);
+my_bool my_uca_have_contractions(CHARSET_INFO *cs);
+my_bool my_uca_can_be_contraction_head(CHARSET_INFO *cs, my_wc_t wc);
+my_bool my_uca_can_be_contraction_tail(CHARSET_INFO *cs, my_wc_t wc);
+const uint16 *my_uca_contraction2_weight(CHARSET_INFO *cs, my_wc_t wc1,
+ my_wc_t wc2);
+
extern size_t my_vsnprintf_ex(CHARSET_INFO *cs, char *to, size_t n,
const char* fmt, va_list ap);
@@ -611,7 +636,6 @@ extern size_t my_vsnprintf_ex(CHARSET_INFO *cs, char *to, size_t n,
#define my_strcasecmp(s, a, b) ((s)->coll->strcasecmp((s), (a), (b)))
#define my_charpos(cs, b, e, num) (cs)->cset->charpos((cs), (const char*) (b), (const char *)(e), (num))
-
#define use_mb(s) ((s)->cset->ismbchar != NULL)
#define my_ismbchar(s, a, b) ((s)->cset->ismbchar((s), (a), (b)))
#ifdef USE_MB
diff --git a/include/m_string.h b/include/m_string.h
index 2ec4eb64c8e..c8200ba33ed 100644
--- a/include/m_string.h
+++ b/include/m_string.h
@@ -59,10 +59,14 @@
/* Unixware 7 */
#if !defined(HAVE_BFILL)
# define bfill(A,B,C) memset((A),(C),(B))
+# define bmove_align(A,B,C) memcpy((A),(B),(C))
#endif
-#if !defined(bzero) && !defined(HAVE_BZERO)
-# define bzero(A,B) memset((A),0,(B))
+#if !defined(HAVE_BCMP)
+# define bcopy(s, d, n) memcpy((d), (s), (n))
+# define bcmp(A,B,C) memcmp((A),(B),(C))
+# define bzero(A,B) memset((A),0,(B))
+# define bmove_align(A,B,C) memcpy((A),(B),(C))
#endif
#if defined(__cplusplus)
@@ -78,21 +82,15 @@ extern void (*my_str_free)(void *);
#if defined(HAVE_STPCPY)
#define strmov(A,B) stpcpy((A),(B))
-#ifndef stpcpy
-extern char *stpcpy(char *, const char *); /* For AIX with gcc 2.95.3 */
-#endif
#endif
/* Declared in int2str() */
-extern char _dig_vec_upper[];
-extern char _dig_vec_lower[];
+extern const char _dig_vec_upper[];
+extern const char _dig_vec_lower[];
-#ifndef strmov
-#define strmov_overlapp(A,B) strmov(A,B)
-#define strmake_overlapp(A,B,C) strmake(A,B,C)
-#endif
+extern char *strmov_overlapp(char *dest, const char *src);
- /* Prototypes for string functions */
+/* Prototypes for string functions */
#if !defined(bfill) && !defined(HAVE_BFILL)
extern void bfill(uchar *dst,size_t len,pchar fill);
@@ -113,8 +111,6 @@ extern char *strmake(char *dst,const char *src,size_t length);
#ifndef strmov
extern char *strmov(char *dst,const char *src);
-#else
-extern char *strmov_overlapp(char *dst,const char *src);
#endif
extern char *strnmov(char *dst, const char *src, size_t n);
extern char *strcont(const char *src, const char *set);
@@ -230,6 +226,14 @@ struct st_mysql_const_lex_string
};
typedef struct st_mysql_const_lex_string LEX_CSTRING;
+/* A variant with const and unsigned */
+struct st_mysql_const_unsigned_lex_string
+{
+ const uchar *str;
+ size_t length;
+};
+typedef struct st_mysql_const_unsigned_lex_string LEX_CUSTRING;
+
/* SPACE_INT is a word that contains only spaces */
#if SIZEOF_INT == 4
#define SPACE_INT 0x20202020
diff --git a/include/maria.h b/include/maria.h
new file mode 100644
index 00000000000..8e5c485767a
--- /dev/null
+++ b/include/maria.h
@@ -0,0 +1,481 @@
+/* Copyright (C) 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; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/* This file should be included when using maria functions */
+
+#ifndef _maria_h
+#define _maria_h
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include <my_base.h>
+#include <my_sys.h>
+#include <m_ctype.h>
+#include "../storage/maria/ma_pagecache.h"
+#include "my_handler.h"
+#include "ft_global.h"
+#include <myisamchk.h>
+#include <mysql/plugin.h>
+
+#define MARIA_CANNOT_ROLLBACK
+
+/*
+ Limit max keys according to HA_MAX_POSSIBLE_KEY; See myisamchk.h for details
+*/
+
+#if MAX_INDEXES > HA_MAX_POSSIBLE_KEY
+#define MARIA_MAX_KEY HA_MAX_POSSIBLE_KEY /* Max allowed keys */
+#else
+#define MARIA_MAX_KEY MAX_INDEXES /* Max allowed keys */
+#endif
+
+#define MARIA_NAME_IEXT ".MAI"
+#define MARIA_NAME_DEXT ".MAD"
+/* Max extra space to use when sorting keys */
+#define MARIA_MAX_TEMP_LENGTH 2*1024L*1024L*1024L
+/* Possible values for maria_block_size (must be power of 2) */
+#define MARIA_KEY_BLOCK_LENGTH 8192 /* default key block length */
+#define MARIA_MIN_KEY_BLOCK_LENGTH 1024 /* Min key block length */
+#define MARIA_MAX_KEY_BLOCK_LENGTH 32768
+/* Minimal page cache when we only want to be able to scan a table */
+#define MARIA_MIN_PAGE_CACHE_SIZE (8192L*16L)
+
+/*
+ In the following macros '_keyno_' is 0 .. keys-1.
+ If there can be more keys than bits in the key_map, the highest bit
+ is for all upper keys. They cannot be switched individually.
+ This means that clearing of high keys is ignored, setting one high key
+ sets all high keys.
+*/
+#define MARIA_KEYMAP_BITS (8 * SIZEOF_LONG_LONG)
+#define MARIA_KEYMAP_HIGH_MASK (ULL(1) << (MARIA_KEYMAP_BITS - 1))
+#define maria_get_mask_all_keys_active(_keys_) \
+ (((_keys_) < MARIA_KEYMAP_BITS) ? \
+ ((ULL(1) << (_keys_)) - ULL(1)) : \
+ (~ ULL(0)))
+#if MARIA_MAX_KEY > MARIA_KEYMAP_BITS
+#define maria_is_key_active(_keymap_,_keyno_) \
+ (((_keyno_) < MARIA_KEYMAP_BITS) ? \
+ test((_keymap_) & (ULL(1) << (_keyno_))) : \
+ test((_keymap_) & MARIA_KEYMAP_HIGH_MASK))
+#define maria_set_key_active(_keymap_,_keyno_) \
+ (_keymap_)|= (((_keyno_) < MARIA_KEYMAP_BITS) ? \
+ (ULL(1) << (_keyno_)) : \
+ MARIA_KEYMAP_HIGH_MASK)
+#define maria_clear_key_active(_keymap_,_keyno_) \
+ (_keymap_)&= (((_keyno_) < MARIA_KEYMAP_BITS) ? \
+ (~ (ULL(1) << (_keyno_))) : \
+ (~ (ULL(0))) /*ignore*/ )
+#else
+#define maria_is_key_active(_keymap_,_keyno_) \
+ test((_keymap_) & (ULL(1) << (_keyno_)))
+#define maria_set_key_active(_keymap_,_keyno_) \
+ (_keymap_)|= (ULL(1) << (_keyno_))
+#define maria_clear_key_active(_keymap_,_keyno_) \
+ (_keymap_)&= (~ (ULL(1) << (_keyno_)))
+#endif
+#define maria_is_any_key_active(_keymap_) \
+ test((_keymap_))
+#define maria_is_all_keys_active(_keymap_,_keys_) \
+ ((_keymap_) == maria_get_mask_all_keys_active(_keys_))
+#define maria_set_all_keys_active(_keymap_,_keys_) \
+ (_keymap_)= maria_get_mask_all_keys_active(_keys_)
+#define maria_clear_all_keys_active(_keymap_) \
+ (_keymap_)= 0
+#define maria_intersect_keys_active(_to_,_from_) \
+ (_to_)&= (_from_)
+#define maria_is_any_intersect_keys_active(_keymap1_,_keys_,_keymap2_) \
+ ((_keymap1_) & (_keymap2_) & \
+ maria_get_mask_all_keys_active(_keys_))
+#define maria_copy_keys_active(_to_,_maxkeys_,_from_) \
+ (_to_)= (maria_get_mask_all_keys_active(_maxkeys_) & \
+ (_from_))
+
+ /* Param to/from maria_info */
+
+typedef ulonglong MARIA_RECORD_POS;
+
+typedef struct st_maria_info
+{
+ ha_rows records; /* Records in database */
+ ha_rows deleted; /* Deleted records in database */
+ MARIA_RECORD_POS recpos; /* Pos for last used record */
+ MARIA_RECORD_POS newrecpos; /* Pos if we write new record */
+ MARIA_RECORD_POS dup_key_pos; /* Position to record with dup key */
+ my_off_t data_file_length; /* Length of data file */
+ my_off_t max_data_file_length, index_file_length;
+ my_off_t max_index_file_length, delete_length;
+ ulonglong auto_increment;
+ ulonglong key_map; /* Which keys are used */
+ time_t create_time; /* When table was created */
+ time_t check_time;
+ time_t update_time;
+ ulong record_offset;
+ double *rec_per_key; /* for sql optimizing */
+ ulong reclength; /* Recordlength */
+ ulong mean_reclength; /* Mean recordlength (if packed) */
+ char *data_file_name, *index_file_name;
+ enum data_file_type data_file_type;
+ uint keys; /* Number of keys in use */
+ uint options; /* HA_OPTION_... used */
+ uint reflength;
+ int errkey, /* With key was dupplicated on err */
+ sortkey; /* clustered by this key */
+ File filenr; /* (uniq) filenr for datafile */
+} MARIA_INFO;
+
+
+typedef struct st_maria_create_info
+{
+ const char *index_file_name, *data_file_name; /* If using symlinks */
+ ha_rows max_rows;
+ ha_rows reloc_rows;
+ ulonglong auto_increment;
+ ulonglong data_file_length;
+ ulonglong key_file_length;
+ /* Size of null bitmap at start of row */
+ uint null_bytes;
+ uint old_options;
+ enum data_file_type org_data_file_type;
+ uint8 language;
+ my_bool with_auto_increment, transactional;
+} MARIA_CREATE_INFO;
+
+struct st_maria_share;
+struct st_maria_handler; /* For referense */
+typedef struct st_maria_handler MARIA_HA;
+struct st_maria_s_param;
+struct st_maria_keydef;
+struct st_maria_page;
+
+typedef struct st_maria_key /* Internal info about a key */
+{
+ uchar *data; /* Data for key */
+ struct st_maria_keydef *keyinfo; /* Definition for key */
+ uint data_length; /* Length of key data */
+ uint ref_length; /* record ref + transid */
+ uint32 flag; /* 0 or SEARCH_PART_KEY */
+} MARIA_KEY;
+
+
+typedef struct st_maria_keydef /* Key definition with open & info */
+{
+ struct st_maria_share *share; /* Pointer to base (set in open) */
+#ifdef THREAD
+ rw_lock_t root_lock; /* locking of tree */
+#endif
+ uint16 keysegs; /* Number of key-segment */
+ uint16 flag; /* NOSAME, PACK_USED */
+
+ uint8 key_alg; /* BTREE, RTREE */
+ uint8 key_nr; /* key number (auto) */
+ uint16 block_length; /* Length of keyblock (auto) */
+ uint16 underflow_block_length; /* When to execute underflow */
+ uint16 keylength; /* Tot length of keyparts (auto) */
+ uint16 minlength; /* min length of (packed) key (auto) */
+ uint16 maxlength; /* max length of (packed) key (auto) */
+ uint32 write_comp_flag; /* compare flag for write key (auto) */
+ uint32 version; /* For concurrent read/write */
+ uint32 ftkey_nr; /* full-text index number */
+
+ HA_KEYSEG *seg, *end;
+ struct st_mysql_ftparser *parser; /* Fulltext [pre]parser */
+ int (*bin_search)(const MARIA_KEY *key, const struct st_maria_page *page,
+ uint32 comp_flag, uchar **ret_pos, uchar *buff,
+ my_bool *was_last_key);
+ uint (*get_key)(MARIA_KEY *key, uint page_flag, uint nod_flag,
+ uchar **page);
+ uchar *(*skip_key)(MARIA_KEY *key, uint page_flag, uint nod_flag,
+ uchar *page);
+ int (*pack_key)(const MARIA_KEY *key, uint nod_flag,
+ uchar *next_key, uchar *org_key, uchar *prev_key,
+ struct st_maria_s_param *s_temp);
+ void (*store_key)(struct st_maria_keydef *keyinfo, uchar *key_pos,
+ struct st_maria_s_param *s_temp);
+ my_bool (*ck_insert)(MARIA_HA *inf, MARIA_KEY *key);
+ my_bool (*ck_delete)(MARIA_HA *inf, MARIA_KEY *klen);
+ MARIA_KEY *(*make_key)(MARIA_HA *info, MARIA_KEY *int_key, uint keynr,
+ uchar *key, const uchar *record,
+ MARIA_RECORD_POS filepos, ulonglong trid);
+} MARIA_KEYDEF;
+
+
+#define MARIA_UNIQUE_HASH_LENGTH 4
+
+typedef struct st_maria_unique_def /* Segment definition of unique */
+{
+ uint16 keysegs; /* Number of key-segment */
+ uint8 key; /* Mapped to which key */
+ uint8 null_are_equal;
+ HA_KEYSEG *seg, *end;
+} MARIA_UNIQUEDEF;
+
+typedef struct st_maria_decode_tree /* Decode huff-table */
+{
+ uint16 *table;
+ uint quick_table_bits;
+ uchar *intervalls;
+} MARIA_DECODE_TREE;
+
+
+struct st_maria_bit_buff;
+
+/*
+ Note that null markers should always be first in a row !
+ When creating a column, one should only specify:
+ type, length, null_bit and null_pos
+*/
+
+typedef struct st_maria_columndef /* column information */
+{
+ enum en_fieldtype type;
+ uint32 offset; /* Offset to position in row */
+ uint16 length; /* length of field */
+ uint16 column_nr;
+ /* Intern variable (size of total storage area for the row) */
+ uint16 fill_length;
+ uint16 null_pos; /* Position for null marker */
+ uint16 empty_pos; /* Position for empty marker */
+ uint8 null_bit; /* If column may be NULL */
+ /* Intern. Set if column should be zero packed (part of empty_bits) */
+ uint8 empty_bit;
+
+#ifndef NOT_PACKED_DATABASES
+ void(*unpack)(struct st_maria_columndef *rec,
+ struct st_maria_bit_buff *buff,
+ uchar *start, uchar *end);
+ enum en_fieldtype base_type;
+ uint space_length_bits, pack_type;
+ MARIA_DECODE_TREE *huff_tree;
+#endif
+} MARIA_COLUMNDEF;
+
+
+extern ulong maria_block_size, maria_checkpoint_frequency;
+extern ulong maria_concurrent_insert;
+extern my_bool maria_flush, maria_single_user, maria_page_checksums;
+extern my_bool maria_delay_key_write;
+extern my_off_t maria_max_temp_length;
+extern ulong maria_bulk_insert_tree_size, maria_data_pointer_size;
+extern PAGECACHE maria_pagecache_var, *maria_pagecache;
+extern MY_TMPDIR *maria_tmpdir;
+/*
+ This is used to check if a symlink points into the mysql data home,
+ which is normally forbidden as it can be used to get access to
+ not privileged data
+*/
+extern int (*maria_test_invalid_symlink)(const char *filename);
+
+ /* Prototypes for maria-functions */
+
+extern int maria_init(void);
+extern void maria_end(void);
+extern my_bool maria_upgrade(void);
+extern int maria_close(MARIA_HA *file);
+extern int maria_delete(MARIA_HA *file, const uchar *buff);
+extern MARIA_HA *maria_open(const char *name, int mode,
+ uint wait_if_locked);
+extern MARIA_HA *maria_clone(struct st_maria_share *share, int mode);
+extern int maria_panic(enum ha_panic_function function);
+extern int maria_rfirst(MARIA_HA *file, uchar *buf, int inx);
+extern int maria_rkey(MARIA_HA *file, uchar *buf, int inx,
+ const uchar *key, key_part_map keypart_map,
+ enum ha_rkey_function search_flag);
+extern int maria_rlast(MARIA_HA *file, uchar *buf, int inx);
+extern int maria_rnext(MARIA_HA *file, uchar *buf, int inx);
+extern int maria_rnext_same(MARIA_HA *info, uchar *buf);
+extern int maria_rprev(MARIA_HA *file, uchar *buf, int inx);
+extern int maria_rrnd(MARIA_HA *file, uchar *buf,
+ MARIA_RECORD_POS pos);
+extern int maria_scan_init(MARIA_HA *file);
+extern int maria_scan(MARIA_HA *file, uchar *buf);
+extern void maria_scan_end(MARIA_HA *file);
+extern int maria_rsame(MARIA_HA *file, uchar *record, int inx);
+extern int maria_rsame_with_pos(MARIA_HA *file, uchar *record,
+ int inx, MARIA_RECORD_POS pos);
+extern int maria_update(MARIA_HA *file, const uchar *old,
+ uchar *new_record);
+extern int maria_write(MARIA_HA *file, uchar *buff);
+extern MARIA_RECORD_POS maria_position(MARIA_HA *file);
+extern int maria_status(MARIA_HA *info, MARIA_INFO *x, uint flag);
+extern int maria_lock_database(MARIA_HA *file, int lock_type);
+extern int maria_create(const char *name, enum data_file_type record_type,
+ uint keys, MARIA_KEYDEF *keydef,
+ uint columns, MARIA_COLUMNDEF *columndef,
+ uint uniques, MARIA_UNIQUEDEF *uniquedef,
+ MARIA_CREATE_INFO *create_info, uint flags);
+extern int maria_delete_table(const char *name);
+extern int maria_rename(const char *from, const char *to);
+extern int maria_extra(MARIA_HA *file,
+ enum ha_extra_function function, void *extra_arg);
+extern int maria_reset(MARIA_HA *file);
+extern ha_rows maria_records_in_range(MARIA_HA *info, int inx,
+ key_range *min_key, key_range *max_key);
+extern int maria_is_changed(MARIA_HA *info);
+extern int maria_delete_all_rows(MARIA_HA *info);
+extern uint maria_get_pointer_length(ulonglong file_length, uint def);
+extern int maria_commit(MARIA_HA *info);
+extern int maria_begin(MARIA_HA *info);
+extern void maria_disable_logging(MARIA_HA *info);
+extern void maria_enable_logging(MARIA_HA *info);
+
+#define HA_RECOVER_NONE 0 /* No automatic recover */
+#define HA_RECOVER_DEFAULT 1 /* Automatic recover active */
+#define HA_RECOVER_BACKUP 2 /* Make a backupfile on recover */
+#define HA_RECOVER_FORCE 4 /* Recover even if we loose rows */
+#define HA_RECOVER_QUICK 8 /* Don't check rows in data file */
+
+/* this is used to pass to mysql_mariachk_table */
+
+#define MARIA_CHK_REPAIR 1 /* equivalent to mariachk -r */
+#define MARIA_CHK_VERIFY 2 /* Verify, run repair if failure */
+
+typedef uint maria_bit_type;
+
+typedef struct st_maria_bit_buff
+{ /* Used for packing of record */
+ maria_bit_type current_byte;
+ uint bits;
+ uchar *pos, *end, *blob_pos, *blob_end;
+ uint error;
+} MARIA_BIT_BUFF;
+
+
+typedef struct st_maria_sort_info
+{
+#ifdef THREAD
+ /* sync things */
+ pthread_mutex_t mutex;
+ pthread_cond_t cond;
+#endif
+ MARIA_HA *info, *new_info;
+ HA_CHECK *param;
+ char *buff;
+ SORT_KEY_BLOCKS *key_block, *key_block_end;
+ SORT_FT_BUF *ft_buf;
+ my_off_t filelength, dupp, buff_length;
+ pgcache_page_no_t page;
+ ha_rows max_records;
+ uint current_key, total_keys;
+ uint got_error, threads_running;
+ myf myf_rw;
+ enum data_file_type new_data_file_type, org_data_file_type;
+} MARIA_SORT_INFO;
+
+typedef struct st_maria_sort_param
+{
+ pthread_t thr;
+ IO_CACHE read_cache, tempfile, tempfile_for_exceptions;
+ DYNAMIC_ARRAY buffpek;
+ MARIA_BIT_BUFF bit_buff; /* For parallel repair of packrec. */
+
+ MARIA_KEYDEF *keyinfo;
+ MARIA_SORT_INFO *sort_info;
+ HA_KEYSEG *seg;
+ uchar **sort_keys;
+ uchar *rec_buff;
+ void *wordlist, *wordptr;
+ MEM_ROOT wordroot;
+ uchar *record;
+ MY_TMPDIR *tmpdir;
+
+ /*
+ The next two are used to collect statistics, see maria_update_key_parts for
+ description.
+ */
+ ulonglong unique[HA_MAX_KEY_SEG+1];
+ ulonglong notnull[HA_MAX_KEY_SEG+1];
+
+ MARIA_RECORD_POS pos,max_pos,filepos,start_recpos, current_filepos;
+ uint key, key_length,real_key_length,sortbuff_size;
+ uint maxbuffers, keys, find_length, sort_keys_length;
+ my_bool fix_datafile, master;
+ my_bool calc_checksum; /* calculate table checksum */
+ size_t rec_buff_size;
+
+ int (*key_cmp)(struct st_maria_sort_param *, const void *, const void *);
+ int (*key_read)(struct st_maria_sort_param *, uchar *);
+ int (*key_write)(struct st_maria_sort_param *, const uchar *);
+ void (*lock_in_memory)(HA_CHECK *);
+ int (*write_keys)(struct st_maria_sort_param *, register uchar **,
+ uint , struct st_buffpek *, IO_CACHE *);
+ uint (*read_to_buffer)(IO_CACHE *,struct st_buffpek *, uint);
+ int (*write_key)(struct st_maria_sort_param *, IO_CACHE *,uchar *,
+ uint, uint);
+} MARIA_SORT_PARAM;
+
+
+/* functions in maria_check */
+void maria_chk_init(HA_CHECK *param);
+void maria_chk_init_for_check(HA_CHECK *param, MARIA_HA *info);
+int maria_chk_status(HA_CHECK *param, MARIA_HA *info);
+int maria_chk_del(HA_CHECK *param, MARIA_HA *info, ulonglong test_flag);
+int maria_chk_size(HA_CHECK *param, MARIA_HA *info);
+int maria_chk_key(HA_CHECK *param, MARIA_HA *info);
+int maria_chk_data_link(HA_CHECK *param, MARIA_HA *info, my_bool extend);
+int maria_repair(HA_CHECK *param, MARIA_HA *info, char * name, my_bool);
+int maria_sort_index(HA_CHECK *param, MARIA_HA *info, char * name);
+int maria_zerofill(HA_CHECK *param, MARIA_HA *info, const char *name);
+int maria_repair_by_sort(HA_CHECK *param, MARIA_HA *info,
+ const char *name, my_bool rep_quick);
+int maria_repair_parallel(HA_CHECK *param, register MARIA_HA *info,
+ const char *name, my_bool rep_quick);
+int maria_change_to_newfile(const char *filename, const char *old_ext,
+ const char *new_ext, myf myflags);
+void maria_lock_memory(HA_CHECK *param);
+int maria_update_state_info(HA_CHECK *param, MARIA_HA *info, uint update);
+void maria_update_key_parts(MARIA_KEYDEF *keyinfo, double *rec_per_key_part,
+ ulonglong *unique, ulonglong *notnull,
+ ulonglong records);
+int maria_filecopy(HA_CHECK *param, File to, File from, my_off_t start,
+ my_off_t length, const char *type);
+int maria_movepoint(MARIA_HA *info, uchar *record, my_off_t oldpos,
+ my_off_t newpos, uint prot_key);
+int maria_write_data_suffix(MARIA_SORT_INFO *sort_info, my_bool fix_datafile);
+int maria_test_if_almost_full(MARIA_HA *info);
+int maria_recreate_table(HA_CHECK *param, MARIA_HA **org_info, char *filename);
+int maria_disable_indexes(MARIA_HA *info);
+int maria_enable_indexes(MARIA_HA *info);
+int maria_indexes_are_disabled(MARIA_HA *info);
+void maria_disable_non_unique_index(MARIA_HA *info, ha_rows rows);
+my_bool maria_test_if_sort_rep(MARIA_HA *info, ha_rows rows, ulonglong key_map,
+ my_bool force);
+
+int maria_init_bulk_insert(MARIA_HA *info, ulong cache_size, ha_rows rows);
+void maria_flush_bulk_insert(MARIA_HA *info, uint inx);
+void maria_end_bulk_insert(MARIA_HA *info);
+int maria_assign_to_pagecache(MARIA_HA *info, ulonglong key_map,
+ PAGECACHE *key_cache);
+void maria_change_pagecache(PAGECACHE *old_key_cache,
+ PAGECACHE *new_key_cache);
+int maria_preload(MARIA_HA *info, ulonglong key_map, my_bool ignore_leaves);
+void maria_versioning(MARIA_HA *info, my_bool versioning);
+void maria_ignore_trids(MARIA_HA *info);
+
+/* fulltext functions */
+FT_INFO *maria_ft_init_search(uint,void *, uint, uchar *, size_t,
+ CHARSET_INFO *, uchar *);
+
+/* 'Almost-internal' Maria functions */
+
+void _ma_update_auto_increment_key(HA_CHECK *param, MARIA_HA *info,
+ my_bool repair);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/include/my_alloc.h b/include/my_alloc.h
index 4b1ffd3d444..11e1331988b 100644
--- a/include/my_alloc.h
+++ b/include/my_alloc.h
@@ -30,8 +30,8 @@ extern "C" {
typedef struct st_used_mem
{ /* struct for once_alloc (block) */
struct st_used_mem *next; /* Next block in use */
- unsigned int left; /* memory left in block */
- unsigned int size; /* size of block */
+ size_t left; /* memory left in block */
+ size_t size; /* size of block */
} USED_MEM;
diff --git a/include/my_atomic.h b/include/my_atomic.h
index c2d514012d9..48bbe8c2946 100644
--- a/include/my_atomic.h
+++ b/include/my_atomic.h
@@ -1,6 +1,3 @@
-#ifndef MY_ATOMIC_INCLUDED
-#define MY_ATOMIC_INCLUDED
-
/* Copyright (C) 2006 MySQL AB
This program is free software; you can redistribute it and/or modify
@@ -28,10 +25,9 @@
store 'what' in *var, and return the old value of *var
my_atomic_cas#(&var, &old, new)
- An odd variation of 'Compare And Set/Swap'
+ 'Compare And Swap'
if *var is equal to *old, then store 'new' in *var, and return TRUE
otherwise store *var in *old, and return FALSE
- Usually, &old should not be accessed if the operation is successful.
my_atomic_load#(&var)
return *var
diff --git a/include/my_base.h b/include/my_base.h
index 28dc55b1b84..75deb89a08d 100644
--- a/include/my_base.h
+++ b/include/my_base.h
@@ -50,6 +50,7 @@
#define HA_OPEN_COPY 256 /* Open copy (for repair) */
/* Internal temp table, used for temporary results */
#define HA_OPEN_INTERNAL_TABLE 512
+#define HA_OPEN_MERGE_TABLE 1024
/* The following is parameter to ha_rkey() how to use key */
@@ -111,7 +112,7 @@ enum ha_storage_media {
enum ha_extra_function {
HA_EXTRA_NORMAL=0, /* Optimize for space (def) */
HA_EXTRA_QUICK=1, /* Optimize for speed */
- HA_EXTRA_NOT_USED=2,
+ HA_EXTRA_NOT_USED=2, /* Should be ignored by handler */
HA_EXTRA_CACHE=3, /* Cache record in HA_rrnd() */
HA_EXTRA_NO_CACHE=4, /* End caching of records (def) */
HA_EXTRA_NO_READCHECK=5, /* No readcheck on update */
@@ -196,7 +197,10 @@ enum ha_extra_function {
HA_EXTRA_ADD_CHILDREN_LIST,
HA_EXTRA_ATTACH_CHILDREN,
HA_EXTRA_IS_ATTACHED_CHILDREN,
- HA_EXTRA_DETACH_CHILDREN
+ HA_EXTRA_DETACH_CHILDREN,
+ HA_EXTRA_DETACH_CHILD,
+ /* Inform handler we will force a close as part of flush */
+ HA_EXTRA_PREPARE_FOR_FORCED_CLOSE
};
/* Compatible option, to be deleted in 6.0 */
@@ -239,7 +243,10 @@ enum ha_base_keytype {
#define HA_MAX_KEYTYPE 31 /* Must be log2-1 */
- /* These flags kan be OR:ed to key-flag */
+/*
+ These flags kan be OR:ed to key-flag
+ Note that these can only be up to 16 bits!
+*/
#define HA_NOSAME 1 /* Set if not dupplicated records */
#define HA_PACK_KEY 2 /* Pack string key to previous key */
@@ -250,11 +257,13 @@ enum ha_base_keytype {
#define HA_SPATIAL 1024 /* For spatial search */
#define HA_NULL_ARE_EQUAL 2048 /* NULL in key are cmp as equal */
#define HA_GENERATED_KEY 8192 /* Automaticly generated key */
+#define HA_RTREE_INDEX 16384 /* For RTREE search */
/* The combination of the above can be used for key type comparison. */
#define HA_KEYFLAG_MASK (HA_NOSAME | HA_PACK_KEY | HA_AUTO_KEY | \
HA_BINARY_PACK_KEY | HA_FULLTEXT | HA_UNIQUE_CHECK | \
- HA_SPATIAL | HA_NULL_ARE_EQUAL | HA_GENERATED_KEY)
+ HA_SPATIAL | HA_NULL_ARE_EQUAL | HA_GENERATED_KEY | \
+ HA_RTREE_INDEX)
/*
Key contains partial segments.
@@ -294,6 +303,7 @@ enum ha_base_keytype {
*/
#define HA_END_SPACE_ARE_EQUAL 512
#define HA_BIT_PART 1024
+#define HA_CAN_MEMCMP 2048 /* internal, never stored in frm */
/* optionbits for database */
#define HA_OPTION_PACK_RECORD 1
@@ -308,8 +318,12 @@ enum ha_base_keytype {
#define HA_OPTION_RELIES_ON_SQL_LAYER 512
#define HA_OPTION_NULL_FIELDS 1024
#define HA_OPTION_PAGE_CHECKSUM 2048
-#define HA_OPTION_TEMP_COMPRESS_RECORD ((uint) 16384) /* set by isamchk */
-#define HA_OPTION_READ_ONLY_DATA ((uint) 32768) /* Set by isamchk */
+/* .frm has extra create options in linked-list format */
+#define HA_OPTION_TEXT_CREATE_OPTIONS (1L << 14)
+#define HA_OPTION_TEMP_COMPRESS_RECORD (1L << 15) /* set by isamchk */
+#define HA_OPTION_READ_ONLY_DATA (1L << 16) /* Set by isamchk */
+#define HA_OPTION_NO_CHECKSUM (1L << 17)
+#define HA_OPTION_NO_DELAY_KEY_WRITE (1L << 18)
/* Bits in flag to create() */
@@ -432,18 +446,18 @@ enum ha_base_keytype {
/* row not actually updated: new values same as the old values */
#define HA_ERR_RECORD_IS_THE_SAME 169
/* It is not possible to log this statement */
-#define HA_ERR_LOGGING_IMPOSSIBLE 170 /* It is not possible to log this
- statement */
-#define HA_ERR_CORRUPT_EVENT 171 /* The event was corrupt, leading to
- illegal data being read */
+#define HA_ERR_LOGGING_IMPOSSIBLE 170
+/* The event was corrupt, leading to illegal data being read */
+#define HA_ERR_CORRUPT_EVENT 171
#define HA_ERR_NEW_FILE 172 /* New file format */
-#define HA_ERR_ROWS_EVENT_APPLY 173 /* The event could not be processed
- no other hanlder error happened */
+/* The event could not be processed no other handler error happened */
+#define HA_ERR_ROWS_EVENT_APPLY 173
#define HA_ERR_INITIALIZATION 174 /* Error during initialization */
#define HA_ERR_FILE_TOO_SHORT 175 /* File too short */
#define HA_ERR_WRONG_CRC 176 /* Wrong CRC on page */
-#define HA_ERR_TOO_MANY_CONCURRENT_TRXS 177 /*Too many active concurrent transactions */
-#define HA_ERR_LAST 177 /* Copy of last error nr */
+#define HA_ERR_ROW_NOT_VISIBLE 177
+#define HA_ERR_TOO_MANY_CONCURRENT_TRXS 178 /*Too many active concurrent transactions */
+#define HA_ERR_LAST 178 /* Copy of last error nr */
/* Number of different errors */
#define HA_ERR_ERRORS (HA_ERR_LAST - HA_ERR_FIRST + 1)
@@ -476,6 +490,14 @@ typedef ulong key_part_map;
#define MBR_DATA 16384
#define SEARCH_NULL_ARE_EQUAL 32768 /* NULL in keys are equal */
#define SEARCH_NULL_ARE_NOT_EQUAL 65536 /* NULL in keys are not equal */
+/* Use this when inserting a key in position order */
+#define SEARCH_INSERT SEARCH_NULL_ARE_NOT_EQUAL*2
+/* Only part of the key is specified while reading */
+#define SEARCH_PART_KEY SEARCH_INSERT*2
+/* Used when user key (key 2) contains transaction id's */
+#define SEARCH_USER_KEY_HAS_TRANSID SEARCH_PART_KEY*2
+/* Used when page key (key 1) contains transaction id's */
+#define SEARCH_PAGE_KEY_HAS_TRANSID SEARCH_USER_KEY_HAS_TRANSID*2
/* bits in opt_flag */
#define QUICK_USED 1
diff --git a/include/my_bitmap.h b/include/my_bitmap.h
index 548eec14d6e..cd082cc1ada 100644
--- a/include/my_bitmap.h
+++ b/include/my_bitmap.h
@@ -25,8 +25,6 @@ typedef uint32 my_bitmap_map;
typedef struct st_bitmap
{
my_bitmap_map *bitmap;
- uint n_bits; /* number of bits occupied by the above */
- my_bitmap_map last_word_mask;
my_bitmap_map *last_word_ptr;
/*
mutex will be acquired for the duration of each bitmap operation if
@@ -36,6 +34,8 @@ typedef struct st_bitmap
#ifdef THREAD
mysql_mutex_t *mutex;
#endif
+ my_bitmap_map last_word_mask;
+ uint32 n_bits; /* number of bits occupied by the above */
} MY_BITMAP;
#ifdef __cplusplus
@@ -53,6 +53,8 @@ extern my_bool bitmap_is_overlapping(const MY_BITMAP *map1,
extern my_bool bitmap_test_and_set(MY_BITMAP *map, uint bitmap_bit);
extern my_bool bitmap_test_and_clear(MY_BITMAP *map, uint bitmap_bit);
extern my_bool bitmap_fast_test_and_set(MY_BITMAP *map, uint bitmap_bit);
+extern my_bool bitmap_union_is_set_all(const MY_BITMAP *map1,
+ const MY_BITMAP *map2);
extern uint bitmap_set_next(MY_BITMAP *map);
extern uint bitmap_get_first(const MY_BITMAP *map);
extern uint bitmap_get_first_set(const MY_BITMAP *map);
diff --git a/include/my_dbug.h b/include/my_dbug.h
index 19570ac2a67..ab02433ec4e 100644
--- a/include/my_dbug.h
+++ b/include/my_dbug.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB & 2009 Monty Program Ab
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
@@ -59,6 +59,7 @@ extern const char* _db_get_func_(void);
#define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_; \
_db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_)
#define DBUG_LEAVE _db_return_ (__LINE__, &_db_stack_frame_)
+
#define DBUG_RETURN(a1) do {DBUG_LEAVE; return(a1);} while(0)
#define DBUG_VOID_RETURN do {DBUG_LEAVE; return;} while(0)
#define DBUG_EXECUTE(keyword,a1) \
@@ -110,10 +111,10 @@ extern const char* _db_get_func_(void);
DBUG_CHECK_CRASH(_db_get_func_(), "_crash_return")
#define DBUG_CRASH_VOID_RETURN \
DBUG_CHECK_CRASH (_db_get_func_(), "_crash_return")
-
#else /* No debugger */
#define DBUG_ENTER(a1)
+#define DBUG_VIOLATION_HELPER_LEAVE do { } while(0)
#define DBUG_LEAVE
#define DBUG_RETURN(a1) do { return(a1); } while(0)
#define DBUG_VOID_RETURN do { return; } while(0)
diff --git a/include/my_global.h b/include/my_global.h
index 1c615cc5ca2..ad8607de2a3 100644
--- a/include/my_global.h
+++ b/include/my_global.h
@@ -195,8 +195,28 @@
#define __builtin_expect(x, expected_value) (x)
#endif
-#define likely(x) __builtin_expect((x),1)
-#define unlikely(x) __builtin_expect((x),0)
+/**
+ The semantics of builtin_expect() are that
+ 1) its two arguments are long
+ 2) it's likely that they are ==
+ Those of our likely(x) are that x can be bool/int/longlong/pointer.
+*/
+#define likely(x) __builtin_expect(((x) != 0),1)
+#define unlikely(x) __builtin_expect(((x) != 0),0)
+
+/*
+ now let's figure out if inline functions are supported
+ autoconf defines 'inline' to be empty, if not
+*/
+#define inline_test_1(X) X ## 1
+#define inline_test_2(X) inline_test_1(X)
+#if inline_test_2(inline) != 1
+#define HAVE_INLINE
+#else
+#error Compiler does not support inline!
+#endif
+#undef inline_test_2
+#undef inline_test_1
/* Fix problem with S_ISLNK() on Linux */
#if defined(TARGET_OS_LINUX) || defined(__GLIBC__)
@@ -356,6 +376,9 @@ C_MODE_END
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
#ifdef HAVE_SYS_TIMEB_H
#include <sys/timeb.h> /* Avoid warnings on SCO */
#endif
@@ -394,7 +417,7 @@ C_MODE_END
#include <assert.h>
/* an assert that works at compile-time. only for constant expression */
-#ifndef __GNUC__
+#ifdef _some_old_compiler_that_does_not_understand_the_construct_below_
#define compile_time_assert(X) do { } while(0)
#else
#define compile_time_assert(X) \
@@ -452,6 +475,14 @@ extern "C" int madvise(void *addr, size_t len, int behav);
#define LINT_INIT(var)
#endif
+#ifdef _WIN32
+#define SO_EXT ".dll"
+#elif defined(__APPLE__)
+#define SO_EXT ".dylib"
+#else
+#define SO_EXT ".so"
+#endif
+
/*
Suppress uninitialized variable warning without generating code.
@@ -477,6 +508,7 @@ typedef unsigned short ushort;
#define test(a) ((a) ? 1 : 0)
#define set_if_bigger(a,b) do { if ((a) < (b)) (a)=(b); } while(0)
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
+#define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
#define test_all_bits(a,b) (((a) & (b)) == (b))
#define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
@@ -662,15 +694,14 @@ typedef SOCKET_SIZE_TYPE size_socket;
#define MALLOC_OVERHEAD 8
/* get memory in huncs */
-#define ONCE_ALLOC_INIT (uint) (4096-MALLOC_OVERHEAD)
- /* Typical record cash */
-#define RECORD_CACHE_SIZE (uint) (64*1024-MALLOC_OVERHEAD)
- /* Typical key cash */
-#define KEY_CACHE_SIZE (uint) (8*1024*1024)
+#define ONCE_ALLOC_INIT (uint) 4096
+ /* Typical record cache */
+#define RECORD_CACHE_SIZE (uint) (128*1024)
+ /* Typical key cache */
+#define KEY_CACHE_SIZE (uint) (128L*1024L*1024L)
/* Default size of a key cache block */
#define KEY_CACHE_BLOCK_SIZE (uint) 1024
-
/* Some things that this system doesn't have */
#ifdef _WIN32
@@ -821,6 +852,17 @@ static inline double my_isinf(double x)
#define M_LN2 0.69314718055994530942
#endif
+#ifndef HAVE_LOG2
+/*
+ This will be slightly slower and perhaps a tiny bit less accurate than
+ doing it the IEEE754 way but log2() should be available on C99 systems.
+*/
+inline double log2(double x)
+{
+ return (log(x) / M_LN2);
+}
+#endif
+
/*
Max size that must be added to a so that we know Size to make
adressable obj.
@@ -833,7 +875,9 @@ typedef long long my_ptrdiff_t;
#define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1))
#define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double))
+#define ALIGN_MAX_UNIT (sizeof(double))
/* Size to make adressable obj. */
+#define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A), sizeof(double)))
#define ADD_TO_PTR(ptr,size,type) (type) ((uchar*) (ptr)+size)
#define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((uchar*) (A) - (uchar*) (B))
@@ -1035,9 +1079,7 @@ typedef char my_bool; /* Small bool */
#define YESNO(X) ((X) ? "yes" : "no")
#define MY_HOW_OFTEN_TO_ALARM 2 /* How often we want info on screen */
-#define MY_HOW_OFTEN_TO_WRITE 1000 /* How often we want info on screen */
-
-
+#define MY_HOW_OFTEN_TO_WRITE 10000 /* How often we want info on screen */
/*
Define-funktions for reading and storing in machine independent format
@@ -1046,7 +1088,7 @@ typedef char my_bool; /* Small bool */
/* Optimized store functions for Intel x86 */
#if defined(__i386__) || defined(_WIN32)
-#define sint2korr(A) (*((int16 *) (A)))
+#define sint2korr(A) (*((const int16 *) (A)))
#define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \
(((uint32) 255L << 24) | \
(((uint32) (uchar) (A)[2]) << 16) |\
@@ -1055,9 +1097,9 @@ typedef char my_bool; /* Small bool */
(((uint32) (uchar) (A)[2]) << 16) |\
(((uint32) (uchar) (A)[1]) << 8) | \
((uint32) (uchar) (A)[0])))
-#define sint4korr(A) (*((long *) (A)))
-#define uint2korr(A) (*((uint16 *) (A)))
-#if defined(HAVE_purify) && !defined(_WIN32)
+#define sint4korr(A) (*((const long *) (A)))
+#define uint2korr(A) (*((const uint16 *) (A)))
+#if defined(HAVE_valgrind) && !defined(_WIN32)
#define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
(((uint32) ((uchar) (A)[1])) << 8) +\
(((uint32) ((uchar) (A)[2])) << 16))
@@ -1068,9 +1110,9 @@ typedef char my_bool; /* Small bool */
Please, note, uint3korr reads 4 bytes (not 3) !
It means, that you have to provide enough allocated space !
*/
-#define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF)
-#endif /* HAVE_purify && !_WIN32 */
-#define uint4korr(A) (*((uint32 *) (A)))
+#define uint3korr(A) (long) (*((const unsigned int *) (A)) & 0xFFFFFF)
+#endif /* HAVE_valgrind && !_WIN32 */
+#define uint4korr(A) (*((const uint32 *) (A)))
#define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
(((uint32) ((uchar) (A)[1])) << 8) +\
(((uint32) ((uchar) (A)[2])) << 16) +\
@@ -1082,8 +1124,8 @@ typedef char my_bool; /* Small bool */
(((uint32) ((uchar) (A)[3])) << 24)) + \
(((ulonglong) ((uchar) (A)[4])) << 32) + \
(((ulonglong) ((uchar) (A)[5])) << 40))
-#define uint8korr(A) (*((ulonglong *) (A)))
-#define sint8korr(A) (*((longlong *) (A)))
+#define uint8korr(A) (*((const ulonglong *) (A)))
+#define sint8korr(A) (*((const longlong *) (A)))
#define int2store(T,A) *((uint16*) (T))= (uint16) (A)
#define int3store(T,A) do { *(T)= (uchar) ((A));\
*(T+1)=(uchar) (((uint) (A) >> 8));\
@@ -1108,13 +1150,13 @@ typedef union {
} doubleget_union;
#define doubleget(V,M) \
do { doubleget_union _tmp; \
- _tmp.m[0] = *((long*)(M)); \
- _tmp.m[1] = *(((long*) (M))+1); \
+ _tmp.m[0] = *((const long*)(M)); \
+ _tmp.m[1] = *(((const long*) (M))+1); \
(V) = _tmp.v; } while(0)
-#define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \
- *(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \
+#define doublestore(T,V) do { *((long *) T) = ((const doubleget_union *)&V)->m[0]; \
+ *(((long *) T)+1) = ((const doubleget_union *)&V)->m[1]; \
} while (0)
-#define float4get(V,M) do { *((float *) &(V)) = *((float*) (M)); } while(0)
+#define float4get(V,M) do { *((float *) &(V)) = *((const float*) (M)); } while(0)
#define float8get(V,M) doubleget((V),(M))
#define float4store(V,M) memcpy((uchar*) V,(uchar*) (&M),sizeof(float))
#define floatstore(T,V) memcpy((uchar*)(T), (uchar*)(&V),sizeof(float))
@@ -1330,6 +1372,17 @@ do { doubleget_union _tmp; \
#endif /* WORDS_BIGENDIAN */
+/* sprintf does not always return the number of bytes :- */
+#ifdef SPRINTF_RETURNS_INT
+#define my_sprintf(buff,args) sprintf args
+#else
+#ifdef SPRINTF_RETURNS_PTR
+#define my_sprintf(buff,args) ((int)(sprintf args - buff))
+#else
+#define my_sprintf(buff,args) ((ulong) sprintf args, (ulong) strlen(buff))
+#endif
+#endif
+
#ifndef THREAD
#define thread_safe_increment(V,L) (V)++
#define thread_safe_decrement(V,L) (V)--
@@ -1359,16 +1412,19 @@ do { doubleget_union _tmp; \
#endif
#ifdef HAVE_DLOPEN
-#if defined(HAVE_DLFCN_H)
-#include <dlfcn.h>
-#endif
-#endif
-
-#ifndef HAVE_DLERROR
-#define dlerror() ""
+# if defined(HAVE_DLFCN_H)
+# include <dlfcn.h>
+# endif
+# ifndef HAVE_DLERROR
+# define dlerror() ""
+# endif
+#else
+# define dlerror() "No support for dynamic loading (static build?)"
+# define dlopen(A,B) 0
+# define dlsym(A,B) 0
+# define dlclose(A) 0
#endif
-
/*
* Include standard definitions of operator new and delete.
*/
@@ -1394,6 +1450,15 @@ do { doubleget_union _tmp; \
*/
#ifdef TARGET_OS_LINUX
#define NEED_EXPLICIT_SYNC_DIR 1
+#else
+/*
+ On linux default rwlock scheduling policy is good enough for
+ waiting_threads.c, on other systems use our special implementation
+ (which is slower).
+
+ QQ perhaps this should be tested in configure ? how ?
+*/
+#define WT_RWLOCKS_USE_MUTEXES 1
#endif
#if !defined(__cplusplus) && !defined(bool)
diff --git a/include/my_handler.h b/include/my_handler.h
index 977c0042938..970e74d2ace 100644
--- a/include/my_handler.h
+++ b/include/my_handler.h
@@ -19,6 +19,7 @@
#define _my_handler_h
#include "myisampack.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -38,14 +39,15 @@ extern "C" {
#define HA_MAX_POSSIBLE_KEY 255 /* For myisamchk */
/*
The following defines can be increased if necessary.
- But beware the dependency of MI_MAX_POSSIBLE_KEY_BUFF and HA_MAX_KEY_LENGTH.
+ But beware the dependency of HA_MAX_POSSIBLE_KEY_BUFF and HA_MAX_KEY_LENGTH.
*/
#define HA_MAX_KEY_LENGTH 1000 /* Max length in bytes */
-#define HA_MAX_KEY_SEG 16 /* Max segments for key */
+#define HA_MAX_KEY_SEG 32 /* Max segments for key */
-#define HA_MAX_POSSIBLE_KEY_BUFF (HA_MAX_KEY_LENGTH + 24+ 6+6)
+#define HA_MAX_POSSIBLE_KEY_BUFF (HA_MAX_KEY_LENGTH + 24+ 6+6)
#define HA_MAX_KEY_BUFF (HA_MAX_KEY_LENGTH+HA_MAX_KEY_SEG*6+8+8)
+#define HA_MAX_MSG_BUF 1024 /* used in CHECK TABLE, REPAIR TABLE */
typedef struct st_HA_KEYSEG /* Key-portion */
{
@@ -63,22 +65,22 @@ typedef struct st_HA_KEYSEG /* Key-portion */
} HA_KEYSEG;
#define get_key_length(length,key) \
-{ if (*(uchar*) (key) != 255) \
- length= (uint) *(uchar*) ((key)++); \
+{ if (*(const uchar*) (key) != 255) \
+ length= (uint) *(const uchar*) ((key)++); \
else \
{ length= mi_uint2korr((key)+1); (key)+=3; } \
}
#define get_key_length_rdonly(length,key) \
-{ if (*(uchar*) (key) != 255) \
- length= ((uint) *(uchar*) ((key))); \
+{ if (*(const uchar*) (key) != 255) \
+ length= ((uint) *(const uchar*) ((key))); \
else \
{ length= mi_uint2korr((key)+1); } \
}
#define get_key_pack_length(length,length_pack,key) \
-{ if (*(uchar*) (key) != 255) \
- { length= (uint) *(uchar*) ((key)++); length_pack= 1; }\
+{ if (*(const uchar*) (key) != 255) \
+ { length= (uint) *(const uchar*) ((key)++); length_pack= 1; }\
else \
{ length=mi_uint2korr((key)+1); (key)+= 3; length_pack= 3; } \
}
@@ -108,13 +110,13 @@ typedef struct st_HA_KEYSEG /* Key-portion */
#define clr_rec_bits(bit_ptr, bit_ofs, bit_len) \
set_rec_bits(0, bit_ptr, bit_ofs, bit_len)
-extern int ha_compare_text(CHARSET_INFO *, uchar *, uint, uchar *, uint ,
- my_bool, my_bool);
-extern int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a,
- register uchar *b, uint key_length, uint nextflag,
- uint *diff_pos);
+extern int ha_compare_text(CHARSET_INFO *, const uchar *, uint,
+ const uchar *, uint , my_bool, my_bool);
+extern int ha_key_cmp(register HA_KEYSEG *keyseg, register const uchar *a,
+ register const uchar *b, uint key_length,
+ uint32 nextflag, uint *diff_pos);
-extern HA_KEYSEG *ha_find_null(HA_KEYSEG *keyseg, uchar *a);
+extern HA_KEYSEG *ha_find_null(HA_KEYSEG *keyseg, const uchar *a);
extern void my_handler_error_register(void);
extern void my_handler_error_unregister(void);
/*
@@ -123,6 +125,28 @@ extern void my_handler_error_unregister(void);
this amount of bytes.
*/
#define portable_sizeof_char_ptr 8
+
+/**
+ Return values of index_cond_func_xxx functions.
+
+ 0=ICP_NO_MATCH - index tuple doesn't satisfy the pushed index condition (the
+ engine should discard the tuple and go to the next one)
+ 1=ICP_MATCH - index tuple satisfies the pushed index condition (the engine
+ should fetch and return the record)
+ 2=ICP_OUT_OF_RANGE - index tuple is out range that we're scanning, e.g. this
+ if we're scanning "t.key BETWEEN 10 AND 20" and got a
+ "t.key=21" tuple (the engine should stop scanning and return
+ HA_ERR_END_OF_FILE right away).
+*/
+
+typedef enum icp_result {
+ ICP_ERROR=-1,
+ ICP_NO_MATCH=0,
+ ICP_MATCH=1,
+ ICP_OUT_OF_RANGE=2
+} ICP_RESULT;
+
+
#ifdef __cplusplus
}
#endif
diff --git a/include/my_no_pthread.h b/include/my_no_pthread.h
index a805a9151f8..633a5b94a6c 100644
--- a/include/my_no_pthread.h
+++ b/include/my_no_pthread.h
@@ -47,6 +47,7 @@
#define rw_wrlock(A)
#define rw_unlock(A)
#define rwlock_destroy(A)
+#define safe_mutex_assert_owner(mp)
#define mysql_mutex_init(A, B, C) do {} while (0)
#define mysql_mutex_lock(A) do {} while (0)
diff --git a/include/my_pthread.h b/include/my_pthread.h
index 5cf181596ad..ddf1d58ff8f 100644
--- a/include/my_pthread.h
+++ b/include/my_pthread.h
@@ -84,25 +84,27 @@ typedef volatile LONG my_pthread_once_t;
so it can be used directly as a 64 bit value. The value
stored is in 100ns units.
*/
- union ft64 {
+union ft64 {
FILETIME ft;
__int64 i64;
- };
+};
+
struct timespec {
union ft64 tv;
/* The max timeout value in millisecond for pthread_cond_timedwait */
long max_timeout_msec;
};
-#define set_timespec(ABSTIME,SEC) { \
- GetSystemTimeAsFileTime(&((ABSTIME).tv.ft)); \
- (ABSTIME).tv.i64+= (__int64)(SEC)*10000000; \
- (ABSTIME).max_timeout_msec= (long)((SEC)*1000); \
-}
-#define set_timespec_nsec(ABSTIME,NSEC) { \
- GetSystemTimeAsFileTime(&((ABSTIME).tv.ft)); \
- (ABSTIME).tv.i64+= (__int64)(NSEC)/100; \
- (ABSTIME).max_timeout_msec= (long)((NSEC)/1000000); \
-}
+
+#define set_timespec_time_nsec(ABSTIME,TIME,NSEC) do { \
+ (ABSTIME).tv.i64= (TIME)+(__int64)(NSEC)/100; \
+ (ABSTIME).max_timeout_msec= (long)((NSEC)/1000000); \
+} while(0)
+
+#define set_timespec_nsec(ABSTIME,NSEC) do { \
+ union ft64 tv; \
+ GetSystemTimeAsFileTime(&tv.ft); \
+ set_timespec_time_nsec((ABSTIME), tv.i64, (NSEC)); \
+} while(0)
/**
Compare two timespec structs.
@@ -141,10 +143,12 @@ int pthread_cancel(pthread_t thread);
#ifndef ETIMEDOUT
#define ETIMEDOUT 145 /* Win32 doesn't have this */
#endif
+
+#define getpid() GetCurrentThreadId()
#define HAVE_LOCALTIME_R 1
#define _REENTRANT 1
#define HAVE_PTHREAD_ATTR_SETSTACKSIZE 1
-
+#define PTHREAD_STACK_MIN 65536
#undef SAFE_MUTEX /* This will cause conflicts */
#define pthread_key(T,V) DWORD V
@@ -164,7 +168,6 @@ int pthread_cancel(pthread_t thread);
#define pthread_mutex_destroy(A) (DeleteCriticalSection(A), 0)
#define pthread_kill(A,B) pthread_dummy((A) ? 0 : ESRCH)
-
/* Dummy defines for easier code */
#define pthread_attr_setdetachstate(A,B) pthread_dummy(0)
#define pthread_attr_setscope(A,B)
@@ -230,13 +233,13 @@ int my_sigwait(const sigset_t *set,int *sig);
#ifdef HAVE_NONPOSIX_PTHREAD_MUTEX_INIT
#ifndef SAFE_MUTEX
-#define pthread_mutex_init(a,b) my_pthread_mutex_init((a),(b))
-extern int my_pthread_mutex_init(pthread_mutex_t *mp,
- const pthread_mutexattr_t *attr);
+#define pthread_mutex_init(a,b) my_pthread_mutex_noposix_init((a),(b))
+extern int my_pthread_mutex_noposix_init(pthread_mutex_t *mp,
+ const pthread_mutexattr_t *attr);
#endif /* SAFE_MUTEX */
-#define pthread_cond_init(a,b) my_pthread_cond_init((a),(b))
-extern int my_pthread_cond_init(pthread_cond_t *mp,
- const pthread_condattr_t *attr);
+#define pthread_cond_init(a,b) my_pthread_cond_noposix_init((a),(b))
+extern int my_pthread_cond_noposix_init(pthread_cond_t *mp,
+ const pthread_condattr_t *attr);
#endif /* HAVE_NONPOSIX_PTHREAD_MUTEX_INIT */
#if defined(HAVE_SIGTHREADMASK) && !defined(HAVE_PTHREAD_SIGMASK)
@@ -390,40 +393,21 @@ int my_pthread_mutex_trylock(pthread_mutex_t *mutex);
for calculating an absolute time at which
pthread_cond_timedwait should timeout
*/
-#ifdef HAVE_TIMESPEC_TS_SEC
-#ifndef set_timespec
-#define set_timespec(ABSTIME,SEC) \
-{ \
- (ABSTIME).ts_sec=time(0) + (time_t) (SEC); \
- (ABSTIME).ts_nsec=0; \
-}
-#endif /* !set_timespec */
+
+#define set_timespec(ABSTIME,SEC) set_timespec_nsec((ABSTIME),(SEC)*1000000000ULL)
+
#ifndef set_timespec_nsec
-#define set_timespec_nsec(ABSTIME,NSEC) \
-{ \
- ulonglong now= my_getsystime() + (NSEC/100); \
- (ABSTIME).ts_sec= (now / ULL(10000000)); \
- (ABSTIME).ts_nsec= (now % ULL(10000000) * 100 + ((NSEC) % 100)); \
-}
+#define set_timespec_nsec(ABSTIME,NSEC) \
+ set_timespec_time_nsec((ABSTIME),my_getsystime(),(NSEC))
#endif /* !set_timespec_nsec */
+
+/* adapt for two different flavors of struct timespec */
+#ifdef HAVE_TIMESPEC_TS_SEC
+#define MY_tv_sec ts_sec
+#define MY_tv_nsec ts_nsec
#else
-#ifndef set_timespec
-#define set_timespec(ABSTIME,SEC) \
-{\
- struct timeval tv;\
- gettimeofday(&tv,0);\
- (ABSTIME).tv_sec=tv.tv_sec+(time_t) (SEC);\
- (ABSTIME).tv_nsec=tv.tv_usec*1000;\
-}
-#endif /* !set_timespec */
-#ifndef set_timespec_nsec
-#define set_timespec_nsec(ABSTIME,NSEC) \
-{\
- ulonglong now= my_getsystime() + (NSEC/100); \
- (ABSTIME).tv_sec= (time_t) (now / ULL(10000000)); \
- (ABSTIME).tv_nsec= (long) (now % ULL(10000000) * 100 + ((NSEC) % 100)); \
-}
-#endif /* !set_timespec_nsec */
+#define MY_tv_sec tv_sec
+#define MY_tv_nsec tv_nsec
#endif /* HAVE_TIMESPEC_TS_SEC */
/**
@@ -435,37 +419,50 @@ int my_pthread_mutex_trylock(pthread_mutex_t *mutex);
@retval -1 If TS1 ends before TS2.
*/
-#ifdef HAVE_TIMESPEC_TS_SEC
-#ifndef cmp_timespec
-#define cmp_timespec(TS1, TS2) \
- ((TS1.ts_sec > TS2.ts_sec || \
- (TS1.ts_sec == TS2.ts_sec && TS1.ts_nsec > TS2.ts_nsec)) ? 1 : \
- ((TS1.ts_sec < TS2.ts_sec || \
- (TS1.ts_sec == TS2.ts_sec && TS1.ts_nsec < TS2.ts_nsec)) ? -1 : 0))
-#endif /* !cmp_timespec */
-#else
#ifndef cmp_timespec
#define cmp_timespec(TS1, TS2) \
- ((TS1.tv_sec > TS2.tv_sec || \
- (TS1.tv_sec == TS2.tv_sec && TS1.tv_nsec > TS2.tv_nsec)) ? 1 : \
- ((TS1.tv_sec < TS2.tv_sec || \
- (TS1.tv_sec == TS2.tv_sec && TS1.tv_nsec < TS2.tv_nsec)) ? -1 : 0))
+ ((TS1.MY_tv_sec > TS2.MY_tv_sec || \
+ (TS1.MY_tv_sec == TS2.MY_tv_sec && TS1.MY_tv_nsec > TS2.MY_tv_nsec)) ? 1 : \
+ ((TS1.MY_tv_sec < TS2.MY_tv_sec || \
+ (TS1.MY_tv_sec == TS2.MY_tv_sec && TS1.MY_tv_nsec < TS2.MY_tv_nsec)) ? -1 : 0))
#endif /* !cmp_timespec */
-#endif /* HAVE_TIMESPEC_TS_SEC */
-
- /* safe_mutex adds checking to mutex for easier debugging */
+#ifndef set_timespec_time_nsec
+#define set_timespec_time_nsec(ABSTIME,TIME,NSEC) do { \
+ ulonglong nsec= (NSEC); \
+ ulonglong now= (TIME) + (nsec/100); \
+ (ABSTIME).MY_tv_sec= (now / ULL(10000000)); \
+ (ABSTIME).MY_tv_nsec= (now % ULL(10000000) * 100 + (nsec % 100)); \
+} while(0)
+#endif /* !set_timespec_time_nsec */
+
+/* safe_mutex adds checking to mutex for easier debugging */
+struct st_hash;
typedef struct st_safe_mutex_t
{
pthread_mutex_t global,mutex;
- const char *file;
+ const char *file, *name;
uint line,count;
+ myf create_flags, active_flags;
+ ulong id;
pthread_t thread;
+ struct st_hash *locked_mutex, *used_mutex;
+ struct st_safe_mutex_t *prev, *next;
#ifdef SAFE_MUTEX_DETECT_DESTROY
struct st_safe_mutex_info_t *info; /* to track destroying of mutexes */
#endif
} safe_mutex_t;
+typedef struct st_safe_mutex_deadlock_t
+{
+ const char *file, *name;
+ safe_mutex_t *mutex;
+ uint line;
+ ulong count;
+ ulong id;
+ my_bool warning_only;
+} safe_mutex_deadlock_t;
+
#ifdef SAFE_MUTEX_DETECT_DESTROY
/*
Used to track the destroying of mutexes. This needs to be a seperate
@@ -483,8 +480,10 @@ typedef struct st_safe_mutex_info_t
#endif /* SAFE_MUTEX_DETECT_DESTROY */
int safe_mutex_init(safe_mutex_t *mp, const pthread_mutexattr_t *attr,
+ const char *name, myf my_flags,
const char *file, uint line);
-int safe_mutex_lock(safe_mutex_t *mp, my_bool try_lock, const char *file, uint line);
+int safe_mutex_lock(safe_mutex_t *mp, myf my_flags, const char *file,
+ uint line);
int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint line);
int safe_mutex_destroy(safe_mutex_t *mp,const char *file, uint line);
int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp,const char *file,
@@ -493,8 +492,12 @@ int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
struct timespec *abstime, const char *file, uint line);
void safe_mutex_global_init(void);
void safe_mutex_end(FILE *file);
+void safe_mutex_free_deadlock_data(safe_mutex_t *mp);
/* Wrappers if safe mutex is actually used */
+#define MYF_TRY_LOCK 1
+#define MYF_NO_DEADLOCK_DETECTION 2
+
#ifdef SAFE_MUTEX
#undef pthread_mutex_init
#undef pthread_mutex_lock
@@ -506,13 +509,15 @@ void safe_mutex_end(FILE *file);
#undef pthread_cond_wait
#undef pthread_cond_timedwait
#undef pthread_mutex_trylock
-#define pthread_mutex_init(A,B) safe_mutex_init((A),(B),__FILE__,__LINE__)
-#define pthread_mutex_lock(A) safe_mutex_lock((A), FALSE, __FILE__, __LINE__)
+#define my_pthread_mutex_init(A,B,C,D) safe_mutex_init((A),(B),(C),(D),__FILE__,__LINE__)
+#define pthread_mutex_init(A,B) safe_mutex_init((A),(B),#A,0,__FILE__,__LINE__)
+#define pthread_mutex_lock(A) safe_mutex_lock((A), 0, __FILE__, __LINE__)
+#define my_pthread_mutex_lock(A,B) safe_mutex_lock((A), (B), __FILE__, __LINE__)
#define pthread_mutex_unlock(A) safe_mutex_unlock((A),__FILE__,__LINE__)
#define pthread_mutex_destroy(A) safe_mutex_destroy((A),__FILE__,__LINE__)
#define pthread_cond_wait(A,B) safe_cond_wait((A),(B),__FILE__,__LINE__)
#define pthread_cond_timedwait(A,B,C) safe_cond_timedwait((A),(B),(C),__FILE__,__LINE__)
-#define pthread_mutex_trylock(A) safe_mutex_lock((A), TRUE, __FILE__, __LINE__)
+#define pthread_mutex_trylock(A) safe_mutex_lock((A), MYF_TRY_LOCK, __FILE__, __LINE__)
#define pthread_mutex_t safe_mutex_t
#define safe_mutex_assert_owner(mp) \
DBUG_ASSERT((mp)->count > 0 && \
@@ -521,8 +526,11 @@ void safe_mutex_end(FILE *file);
DBUG_ASSERT(! (mp)->count || \
! pthread_equal(pthread_self(), (mp)->thread))
#else
-#define safe_mutex_assert_owner(mp)
-#define safe_mutex_assert_not_owner(mp)
+#define my_pthread_mutex_init(A,B,C,D) pthread_mutex_init((A),(B))
+#define my_pthread_mutex_lock(A,B) pthread_mutex_lock(A)
+#define safe_mutex_assert_owner(mp) do {} while(0)
+#define safe_mutex_assert_not_owner(mp) do {} while(0)
+#define safe_mutex_free_deadlock_data(mp) do {} while(0)
#endif /* SAFE_MUTEX */
#if defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX)
@@ -714,6 +722,7 @@ extern pthread_mutexattr_t my_errorcheck_mutexattr;
typedef ulong my_thread_id;
+extern void my_threadattr_global_init(void);
extern my_bool my_thread_global_init(void);
extern my_bool my_thread_basic_global_init(void);
extern void my_thread_basic_global_reinit(void);
@@ -723,22 +732,23 @@ extern void my_thread_end(void);
extern const char *my_thread_name(void);
extern my_thread_id my_thread_dbug_id(void);
extern int pthread_dummy(int);
+extern void my_mutex_init();
+extern void my_mutex_end();
/* All thread specific variables are in the following struct */
#define THREAD_NAME_SIZE 10
#ifndef DEFAULT_THREAD_STACK
-#if SIZEOF_CHARP > 4
/*
- MySQL can survive with 32K, but some glibc libraries require > 128K stack
- To resolve hostnames. Also recursive stored procedures needs stack.
+ We need to have at least 256K stack to handle calls to myisamchk_init()
+ with the current number of keys and key parts.
*/
-#define DEFAULT_THREAD_STACK (256*1024L)
-#else
-#define DEFAULT_THREAD_STACK (192*1024)
-#endif
+#define DEFAULT_THREAD_STACK (288*1024L)
#endif
+#define MY_PTHREAD_LOCK_READ 0
+#define MY_PTHREAD_LOCK_WRITE 1
+
#include <mysql/psi/mysql_thread.h>
#define INSTRUMENT_ME 0
@@ -757,7 +767,11 @@ struct st_my_thread_var
my_bool init;
struct st_my_thread_var *next,**prev;
void *opt_info;
+ //uint lock_type; /* used by conditional release the queue */
void *stack_ends_here;
+ safe_mutex_t *mutex_in_use;
+ void (*scheduler_before_lock_wait)(void);
+ void (*scheduler_after_lock_wait)(void);
#ifndef DBUG_OFF
void *dbug;
char name[THREAD_NAME_SIZE+1];
@@ -766,7 +780,9 @@ struct st_my_thread_var
extern struct st_my_thread_var *_my_thread_var(void) __attribute__ ((const));
extern void **my_thread_var_dbug();
+extern safe_mutex_t **my_thread_var_mutex_in_use();
extern uint my_thread_end_wait_time;
+extern my_bool safe_mutex_deadlock_detector;
#define my_thread_var (_my_thread_var())
#define my_errno my_thread_var->thr_errno
/*
diff --git a/include/my_sys.h b/include/my_sys.h
index 95689535be5..e3aa7ed8d7c 100644
--- a/include/my_sys.h
+++ b/include/my_sys.h
@@ -28,19 +28,6 @@ typedef struct my_aio_result {
} my_aio_result;
#endif
-#ifdef HAVE_VALGRIND
-# include <valgrind/memcheck.h>
-# define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len)
-# define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len)
-# define MEM_CHECK_ADDRESSABLE(a,len) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,len)
-# define MEM_CHECK_DEFINED(a,len) VALGRIND_CHECK_MEM_IS_DEFINED(a,len)
-#else /* HAVE_VALGRIND */
-# define MEM_UNDEFINED(a,len) ((void) 0)
-# define MEM_NOACCESS(a,len) ((void) 0)
-# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
-# define MEM_CHECK_DEFINED(a,len) ((void) 0)
-#endif /* HAVE_VALGRIND */
-
#ifndef THREAD
extern int my_errno; /* Last error in mysys */
#else
@@ -88,12 +75,14 @@ extern int my_errno; /* Last error in mysys */
#define MY_HOLD_ORIGINAL_MODES 128 /* my_copy() holds to file modes */
#define MY_REDEL_MAKE_BACKUP 256
#define MY_SEEK_NOT_DONE 32 /* my_lock may have to do a seek */
-#define MY_DONT_WAIT 64 /* my_lock() don't wait if can't lock */
+#define MY_SHORT_WAIT 64 /* my_lock() don't wait if can't lock */
+#define MY_FORCE_LOCK 128 /* use my_lock() even if disable_locking */
+#define MY_NO_WAIT 256 /* my_lock() don't wait at all */
#define MY_ZEROFILL 32 /* my_malloc(), fill array with zero */
#define MY_ALLOW_ZERO_PTR 64 /* my_realloc() ; zero ptr -> malloc */
#define MY_FREE_ON_ERROR 128 /* my_realloc() ; Free old ptr on error */
#define MY_HOLD_ON_ERROR 256 /* my_realloc() ; Return old ptr on error */
-#define MY_DONT_OVERWRITE_FILE 1024 /* my_copy: Don't overwrite file */
+#define MY_DONT_OVERWRITE_FILE 2048 /* my_copy: Don't overwrite file */
#define MY_THREADSAFE 2048 /* my_seek(): lock fd mutex */
#define MY_SYNC 4096 /* my_copy(): sync dst file */
@@ -195,12 +184,15 @@ extern void my_large_free(uchar *ptr);
#define alloca __builtin_alloca
#endif /* GNUC */
#define my_alloca(SZ) alloca((size_t) (SZ))
-#define my_afree(PTR) {}
+#define my_afree(PTR) ((void)0)
#else
-#define my_alloca(SZ) my_malloc(SZ,MYF(0))
+#define my_alloca(SZ) my_malloc(SZ,MYF(MY_FAE))
#define my_afree(PTR) my_free(PTR)
#endif /* HAVE_ALLOCA */
+#define my_safe_alloca(size, min_length) ((size <= min_length) ? my_alloca(size) : my_malloc(size,MYF(MY_FAE)))
+#define my_safe_afree(ptr, size, min_length) ((size <= min_length) ? (void)0 : my_free(ptr)
+
#ifndef errno /* did we already get it? */
#ifdef HAVE_ERRNO_AS_DEFINE
#include <errno.h> /* errno is a define */
@@ -210,6 +202,7 @@ extern int errno; /* declare errno */
#endif /* #ifndef errno */
extern char *home_dir; /* Home directory for user */
extern const char *my_progname; /* program-name (printed in errors) */
+extern const char *my_progname_short; /* like above but without directory */
extern char curr_dir[]; /* Current directory for user */
extern void (*error_handler_hook)(uint my_err, const char *str,myf MyFlags);
extern void (*fatal_error_handler_hook)(uint my_err, const char *str,
@@ -229,11 +222,12 @@ extern uint my_large_page_size;
#define MY_ALL_CHARSETS_SIZE 2048
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *default_charset_info;
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *all_charsets[MY_ALL_CHARSETS_SIZE];
-extern CHARSET_INFO compiled_charsets[];
+extern struct charset_info_st compiled_charsets[];
/* statistics */
extern ulong my_file_opened,my_stream_opened, my_tmp_file_created;
extern ulong my_file_total_opened;
+extern ulong my_sync_count;
extern uint mysys_usage_id;
extern my_bool my_init_done;
@@ -253,6 +247,7 @@ extern my_bool my_use_symdir;
extern ulong my_default_record_cache_size;
extern my_bool my_disable_locking, my_disable_async_io,
my_disable_flush_key_blocks, my_disable_symlinks;
+extern my_bool my_disable_sync;
extern char wild_many,wild_one,wild_prefix;
extern const char *charsets_dir;
/* from default.c */
@@ -283,7 +278,13 @@ enum flush_type
As my_disable_flush_pagecache_blocks is always 0, the following option
is strictly equivalent to FLUSH_KEEP
*/
- FLUSH_FORCE_WRITE
+ FLUSH_FORCE_WRITE,
+ /**
+ @brief like FLUSH_KEEP but return immediately if file is already being
+ flushed (even partially) by another thread; only for page cache,
+ forbidden for key cache.
+ */
+ FLUSH_KEEP_LAZY
};
typedef struct st_record_cache /* Used when cacheing records */
@@ -546,6 +547,7 @@ my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */
*(info)->current_pos)
typedef uint32 ha_checksum;
+extern ha_checksum my_crc_dbug_check;
/* Define the type of function to be passed to process_default_option_files */
typedef int (*Process_option_func)(void *ctx, const char *group_name,
@@ -633,6 +635,7 @@ extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags);
extern int my_fclose(FILE *fd,myf MyFlags);
extern File my_fileno(FILE *fd);
extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags);
+extern int my_chmod(const char *name, mode_t mode, myf my_flags);
extern int my_sync(File fd, myf my_flags);
extern int my_sync_dir(const char *dir_name, myf my_flags);
extern int my_sync_dir_by_file(const char *file_name, myf my_flags);
@@ -761,6 +764,9 @@ extern size_t my_b_gets(IO_CACHE *info, char *to, size_t max_length);
extern my_off_t my_b_filelength(IO_CACHE *info);
extern size_t my_b_printf(IO_CACHE *info, const char* fmt, ...);
extern size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap);
+extern int init_strvar_from_file(char *var, int max_size, IO_CACHE *f,
+ const char *default_val);
+extern int init_intvar_from_file(int* var, IO_CACHE* f, int default_val);
extern my_bool open_cached_file(IO_CACHE *cache,const char *dir,
const char *prefix, size_t cache_size,
myf cache_myflags);
@@ -778,7 +784,7 @@ extern my_bool init_dynamic_array2(DYNAMIC_ARRAY *array, uint element_size,
/* init_dynamic_array() function is deprecated */
extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size,
uint init_alloc, uint alloc_increment);
-extern my_bool insert_dynamic(DYNAMIC_ARRAY *array,uchar * element);
+extern my_bool insert_dynamic(DYNAMIC_ARRAY *array, const uchar * element);
extern uchar *alloc_dynamic(DYNAMIC_ARRAY *array);
extern uchar *pop_dynamic(DYNAMIC_ARRAY*);
extern my_bool set_dynamic(DYNAMIC_ARRAY *array,uchar * element,uint array_index);
@@ -824,6 +830,10 @@ extern void set_prealloc_root(MEM_ROOT *root, char *ptr);
extern void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
size_t prealloc_size);
extern char *strdup_root(MEM_ROOT *root,const char *str);
+static inline char *safe_strdup_root(MEM_ROOT *root, const char *str)
+{
+ return str ? strdup_root(root, str) : 0;
+}
extern char *strmake_root(MEM_ROOT *root,const char *str,size_t len);
extern void *memdup_root(MEM_ROOT *root,const void *str, size_t len);
extern int get_defaults_options(int argc, char **argv,
@@ -845,11 +855,21 @@ extern my_bool my_compress(uchar *, size_t *, size_t *);
extern my_bool my_uncompress(uchar *, size_t , size_t *);
extern uchar *my_compress_alloc(const uchar *packet, size_t *len,
size_t *complen);
+extern void *my_az_allocator(void *dummy, unsigned int items, unsigned int size);
+extern void my_az_free(void *dummy, void *address);
+extern int my_compress_buffer(uchar *dest, size_t *destLen,
+ const uchar *source, size_t sourceLen);
extern int packfrm(uchar *, size_t, uchar **, size_t *);
extern int unpackfrm(uchar **, size_t *, const uchar *);
extern ha_checksum my_checksum(ha_checksum crc, const uchar *mem,
size_t count);
+#ifndef DBUG_OFF
+extern void my_debug_put_break_here(void);
+#else
+#define my_debug_put_break_here() do {} while(0)
+#endif
+
extern void my_sleep(ulong m_seconds);
extern ulong crc32(ulong crc, const uchar *buf, uint len);
extern uint my_set_max_open_files(uint files);
@@ -857,6 +877,7 @@ void my_free_open_file_info(void);
extern time_t my_time(myf flags);
extern ulonglong my_getsystime(void);
+extern ulonglong my_getcputime(void);
extern ulonglong my_micro_time();
extern ulonglong my_micro_time_and_time(time_t *time_arg);
time_t my_time_possible_from_micro(ulonglong microtime);
@@ -905,6 +926,22 @@ int my_getpagesize(void);
int my_msync(int, void *, size_t, int);
+#define MY_UUID_SIZE 16
+#define MY_UUID_STRING_LENGTH (8+1+4+1+4+1+4+1+12)
+
+void my_uuid_init(ulong seed1, ulong seed2);
+void my_uuid(uchar *guid);
+void my_uuid2str(const uchar *guid, char *s);
+void my_uuid_end();
+
+struct my_rnd_struct {
+ unsigned long seed1,seed2,max_value;
+ double max_value_dbl;
+};
+
+void my_rnd_init(struct my_rnd_struct *rand_st, ulong seed1, ulong seed2);
+double my_rnd(struct my_rnd_struct *rand_st);
+
/* character sets */
extern uint get_charset_number(const char *cs_name, uint cs_flags);
extern uint get_collation_number(const char *name);
@@ -925,7 +962,7 @@ extern void free_charsets(void);
extern char *get_charsets_dir(char *buf);
extern my_bool my_charset_same(CHARSET_INFO *cs1, CHARSET_INFO *cs2);
extern my_bool init_compiled_charsets(myf flags);
-extern void add_compiled_collation(CHARSET_INFO *cs);
+extern void add_compiled_collation(struct charset_info_st *cs);
extern size_t escape_string_for_mysql(CHARSET_INFO *charset_info,
char *to, size_t to_length,
const char *from, size_t length);
diff --git a/include/my_tree.h b/include/my_tree.h
index 0958a37fb4c..b4f2c07c794 100644
--- a/include/my_tree.h
+++ b/include/my_tree.h
@@ -52,7 +52,7 @@ typedef struct st_tree {
TREE_ELEMENT *root,null_element;
TREE_ELEMENT **parents[MAX_TREE_HEIGHT];
uint offset_to_key,elements_in_tree,size_of_element;
- ulong memory_limit, allocated;
+ size_t memory_limit, allocated;
qsort_cmp2 compare;
void *custom_arg;
MEM_ROOT mem_root;
@@ -62,13 +62,13 @@ typedef struct st_tree {
} TREE;
/* Functions on whole tree */
-void init_tree(TREE *tree, ulong default_alloc_size, ulong memory_limit,
+void init_tree(TREE *tree, size_t default_alloc_size, size_t memory_limit,
int size, qsort_cmp2 compare, my_bool with_delete,
tree_element_free free_element, void *custom_arg);
void delete_tree(TREE*);
void reset_tree(TREE*);
- /* similar to delete tree, except we do not my_free() blocks in mem_root
- */
+
+ /* similar to delete tree, except we do not my_free() blocks in mem_root */
#define is_tree_inited(tree) ((tree)->root != 0)
/* Functions on leafs */
@@ -87,6 +87,7 @@ void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs,
int r_offs);
ha_rows tree_record_pos(TREE *tree, const void *key,
enum ha_rkey_function search_flag, void *custom_arg);
+#define reset_free_element(tree) (tree)->free= 0
#define TREE_ELEMENT_EXTRA_SIZE (sizeof(TREE_ELEMENT) + sizeof(void*))
diff --git a/include/my_valgrind.h b/include/my_valgrind.h
new file mode 100644
index 00000000000..63e185ebc53
--- /dev/null
+++ b/include/my_valgrind.h
@@ -0,0 +1,37 @@
+/* Copyright (C) 2010 Monty Program Ab
+
+ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+
+/* Some defines to make it easier to use valgrind */
+
+#ifdef HAVE_valgrind
+#define IF_VALGRIND(A,B) (A)
+#else
+#define IF_VALGRIND(A,B) (B)
+#endif
+
+#if defined(HAVE_valgrind)&& defined(HAVE_VALGRIND_MEMCHECK_H)
+#include <valgrind/memcheck.h>
+#define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len)
+#define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len)
+#define MEM_CHECK_ADDRESSABLE(a,len) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,len)
+#define MEM_CHECK_DEFINED(a,len) VALGRIND_CHECK_MEM_IS_DEFINED(a,len)
+#else /* HAVE_VALGRIND */
+# define MEM_UNDEFINED(a,len) bfill(A, B, 0x8F)
+# define MEM_NOACCESS(a,len) ((void) 0)
+# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
+# define MEM_CHECK_DEFINED(a,len) ((void) 0)
+#endif /* HAVE_VALGRIND */
+
diff --git a/include/myisam.h b/include/myisam.h
index c4076ead403..b54950fa1cc 100644
--- a/include/myisam.h
+++ b/include/myisam.h
@@ -31,10 +31,11 @@ extern "C" {
#include "keycache.h"
#endif
#include "my_handler.h"
+#include <myisamchk.h>
#include <mysql/plugin.h>
/*
- Limit max keys according to HA_MAX_POSSIBLE_KEY
+ Limit max keys according to HA_MAX_POSSIBLE_KEY; See myisamchk.h for details
*/
#if MAX_INDEXES > HA_MAX_POSSIBLE_KEY
@@ -44,15 +45,7 @@ extern "C" {
#endif
#define MI_MAX_POSSIBLE_KEY_BUFF HA_MAX_POSSIBLE_KEY_BUFF
-/*
- The following defines can be increased if necessary.
- But beware the dependency of MI_MAX_POSSIBLE_KEY_BUFF and MI_MAX_KEY_LENGTH.
-*/
-#define MI_MAX_KEY_LENGTH 1000 /* Max length in bytes */
-#define MI_MAX_KEY_SEG 16 /* Max segments for key */
-#define MI_MAX_KEY_BUFF (MI_MAX_KEY_LENGTH+MI_MAX_KEY_SEG*6+8+8)
-#define MI_MAX_MSG_BUF 1024 /* used in CHECK TABLE, REPAIR TABLE */
#define MI_NAME_IEXT ".MYI"
#define MI_NAME_DEXT ".MYD"
@@ -231,7 +224,7 @@ struct st_mi_bit_buff;
typedef struct st_columndef /* column information */
{
- int16 type; /* en_fieldtype */
+ enum en_fieldtype type;
uint16 length; /* length of field */
uint32 offset; /* Offset to position in row */
uint8 null_bit; /* If column may be 0 */
@@ -246,7 +239,6 @@ typedef struct st_columndef /* column information */
#endif
} MI_COLUMNDEF;
-
extern char * myisam_log_filename; /* Name of logfile */
extern ulong myisam_block_size;
extern ulong myisam_concurrent_insert;
@@ -296,7 +288,7 @@ extern int mi_extra(struct st_myisam_info *file,
enum ha_extra_function function,
void *extra_arg);
extern int mi_reset(struct st_myisam_info *file);
-extern ha_rows mi_records_in_range(MI_INFO *info, int inx,
+extern ha_rows mi_records_in_range(MI_INFO *info,int inx,
key_range *min_key, key_range *max_key);
extern int mi_log(int activate_log);
extern int mi_is_changed(struct st_myisam_info *info);
@@ -310,194 +302,110 @@ extern uint mi_get_pointer_length(ulonglong file_length, uint def);
#define MYISAMCHK_REPAIR 1 /* equivalent to myisamchk -r */
#define MYISAMCHK_VERIFY 2 /* Verify, run repair if failure */
-/*
- Definitions needed for myisamchk.c
-
- Entries marked as "QQ to be removed" are NOT used to
- pass check/repair options to mi_check.c. They are used
- internally by myisamchk.c or/and ha_myisam.cc and should NOT
- be stored together with other flags. They should be removed
- from the following list to make addition of new flags possible.
-*/
-
-#define T_AUTO_INC 1
-#define T_AUTO_REPAIR 2 /* QQ to be removed */
-#define T_BACKUP_DATA 4
-#define T_CALC_CHECKSUM 8
-#define T_CHECK 16 /* QQ to be removed */
-#define T_CHECK_ONLY_CHANGED 32 /* QQ to be removed */
-#define T_CREATE_MISSING_KEYS 64
-#define T_DESCRIPT 128
-#define T_DONT_CHECK_CHECKSUM 256
-#define T_EXTEND 512
-#define T_FAST (1L << 10) /* QQ to be removed */
-#define T_FORCE_CREATE (1L << 11) /* QQ to be removed */
-#define T_FORCE_UNIQUENESS (1L << 12)
-#define T_INFO (1L << 13)
-#define T_MEDIUM (1L << 14)
-#define T_QUICK (1L << 15) /* QQ to be removed */
-#define T_READONLY (1L << 16) /* QQ to be removed */
-#define T_REP (1L << 17)
-#define T_REP_BY_SORT (1L << 18) /* QQ to be removed */
-#define T_REP_PARALLEL (1L << 19) /* QQ to be removed */
-#define T_RETRY_WITHOUT_QUICK (1L << 20)
-#define T_SAFE_REPAIR (1L << 21)
-#define T_SILENT (1L << 22)
-#define T_SORT_INDEX (1L << 23) /* QQ to be removed */
-#define T_SORT_RECORDS (1L << 24) /* QQ to be removed */
-#define T_STATISTICS (1L << 25)
-#define T_UNPACK (1L << 26)
-#define T_UPDATE_STATE (1L << 27)
-#define T_VERBOSE (1L << 28)
-#define T_VERY_SILENT (1L << 29)
-#define T_WAIT_FOREVER (1L << 30)
-#define T_WRITE_LOOP ((ulong) 1L << 31)
-
-#define T_REP_ANY (T_REP | T_REP_BY_SORT | T_REP_PARALLEL)
+typedef uint mi_bit_type;
-/*
- Flags used by myisamchk.c or/and ha_myisam.cc that are NOT passed
- to mi_check.c follows:
-*/
-
-#define TT_USEFRM 1
-#define TT_FOR_UPGRADE 2
-
-#define O_NEW_INDEX 1 /* Bits set in out_flag */
-#define O_NEW_DATA 2
-#define O_DATA_LOST 4
-
-/* these struct is used by my_check to tell it what to do */
-
-typedef struct st_sort_key_blocks /* Used when sorting */
-{
- uchar *buff,*end_pos;
- uchar lastkey[MI_MAX_POSSIBLE_KEY_BUFF];
- uint last_length;
- int inited;
-} SORT_KEY_BLOCKS;
+typedef struct st_mi_bit_buff
+{ /* Used for packing of record */
+ mi_bit_type current_byte;
+ uint bits;
+ uchar *pos, *end, *blob_pos, *blob_end;
+ uint error;
+} MI_BIT_BUFF;
-/*
- MyISAM supports several statistics collection methods. Currently statistics
- collection method is not stored in MyISAM file and has to be specified for
- each table analyze/repair operation in MI_CHECK::stats_method.
-*/
-
-typedef enum
-{
- /* Treat NULLs as inequal when collecting statistics (default for 4.1/5.0) */
- MI_STATS_METHOD_NULLS_NOT_EQUAL,
- /* Treat NULLs as equal when collecting statistics (like 4.0 did) */
- MI_STATS_METHOD_NULLS_EQUAL,
- /* Ignore NULLs - count only tuples without NULLs in the index components */
- MI_STATS_METHOD_IGNORE_NULLS
-} enum_mi_stats_method;
-
-typedef struct st_mi_check_param
+typedef struct st_sort_info
{
- ulonglong auto_increment_value;
- ulonglong max_data_file_length;
- ulonglong keys_in_use;
- ulonglong max_record_length;
- my_off_t search_after_block;
- my_off_t new_file_pos,key_file_blocks;
- my_off_t keydata,totaldata,key_blocks,start_check_pos;
- ha_rows total_records,total_deleted;
- ha_checksum record_checksum,glob_crc;
- ulonglong use_buffers;
- ulong read_buffer_length,write_buffer_length,
- sort_buffer_length,sort_key_blocks;
- uint out_flag,warning_printed,error_printed,verbose;
- uint opt_sort_key,total_files,max_level;
- uint testflag, key_cache_block_size;
- uint16 language;
- my_bool using_global_keycache, opt_lock_memory, opt_follow_links;
- my_bool retry_repair, force_sort;
- char temp_filename[FN_REFLEN],*isam_file_name;
- MY_TMPDIR *tmpdir;
- int tmpfile_createflag;
- myf myf_rw;
- IO_CACHE read_cache;
-
- /*
- The next two are used to collect statistics, see update_key_parts for
- description.
- */
- ulonglong unique_count[MI_MAX_KEY_SEG+1];
- ulonglong notnull_count[MI_MAX_KEY_SEG+1];
-
- ha_checksum key_crc[HA_MAX_POSSIBLE_KEY];
- ulong rec_per_key_part[MI_MAX_KEY_SEG*HA_MAX_POSSIBLE_KEY];
- void *thd;
- const char *db_name, *table_name;
- const char *op_name;
- enum_mi_stats_method stats_method;
#ifdef THREAD
- mysql_mutex_t print_msg_mutex;
- my_bool need_print_msg_lock;
+ /* sync things */
+ mysql_mutex_t mutex;
+ mysql_cond_t cond;
#endif
-} MI_CHECK;
-
-typedef struct st_sort_ft_buf
-{
- uchar *buf, *end;
- int count;
- uchar lastkey[MI_MAX_KEY_BUFF];
-} SORT_FT_BUF;
-
-typedef struct st_sort_info
-{
- my_off_t filelength,dupp,buff_length;
- ha_rows max_records;
- uint current_key, total_keys;
- myf myf_rw;
- enum data_file_type new_data_file_type;
MI_INFO *info;
- MI_CHECK *param;
+ HA_CHECK *param;
uchar *buff;
- SORT_KEY_BLOCKS *key_block,*key_block_end;
+ SORT_KEY_BLOCKS *key_block, *key_block_end;
SORT_FT_BUF *ft_buf;
- /* sync things */
+ my_off_t filelength, dupp, buff_length;
+ ha_rows max_records;
+ uint current_key, total_keys;
uint got_error, threads_running;
-#ifdef THREAD
- mysql_mutex_t mutex;
- mysql_cond_t cond;
-#endif
-} SORT_INFO;
+ myf myf_rw;
+ enum data_file_type new_data_file_type;
+} MI_SORT_INFO;
+
+typedef struct st_mi_sort_param
+{
+ pthread_t thr;
+ IO_CACHE read_cache, tempfile, tempfile_for_exceptions;
+ DYNAMIC_ARRAY buffpek;
+ MI_BIT_BUFF bit_buff; /* For parallel repair of packrec. */
+
+ MI_KEYDEF *keyinfo;
+ MI_SORT_INFO *sort_info;
+ HA_KEYSEG *seg;
+ uchar **sort_keys;
+ uchar *rec_buff;
+ void *wordlist, *wordptr;
+ MEM_ROOT wordroot;
+ uchar *record;
+ MY_TMPDIR *tmpdir;
+
+ /*
+ The next two are used to collect statistics, see update_key_parts for
+ description.
+ */
+ ulonglong unique[HA_MAX_KEY_SEG+1];
+ ulonglong notnull[HA_MAX_KEY_SEG+1];
+
+ my_off_t pos,max_pos,filepos,start_recpos;
+ uint key, key_length,real_key_length,sortbuff_size;
+ uint maxbuffers, keys, find_length, sort_keys_length;
+ my_bool fix_datafile, master;
+ my_bool calc_checksum; /* calculate table checksum */
+
+ int (*key_cmp)(struct st_mi_sort_param *, const void *, const void *);
+ int (*key_read)(struct st_mi_sort_param *,void *);
+ int (*key_write)(struct st_mi_sort_param *, const void *);
+ void (*lock_in_memory)(HA_CHECK *);
+ int (*write_keys)(struct st_mi_sort_param *, register uchar **,
+ uint , struct st_buffpek *, IO_CACHE *);
+ uint (*read_to_buffer)(IO_CACHE *,struct st_buffpek *, uint);
+ int (*write_key)(struct st_mi_sort_param *, IO_CACHE *,uchar *,
+ uint, uint);
+} MI_SORT_PARAM;
/* functions in mi_check */
-void myisamchk_init(MI_CHECK *param);
-int chk_status(MI_CHECK *param, MI_INFO *info);
-int chk_del(MI_CHECK *param, register MI_INFO *info, uint test_flag);
-int chk_size(MI_CHECK *param, MI_INFO *info);
-int chk_key(MI_CHECK *param, MI_INFO *info);
-int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend);
-int mi_repair(MI_CHECK *param, register MI_INFO *info,
+void myisamchk_init(HA_CHECK *param);
+int chk_status(HA_CHECK *param, MI_INFO *info);
+int chk_del(HA_CHECK *param, register MI_INFO *info, ulonglong test_flag);
+int chk_size(HA_CHECK *param, MI_INFO *info);
+int chk_key(HA_CHECK *param, MI_INFO *info);
+int chk_data_link(HA_CHECK *param, MI_INFO *info, my_bool extend);
+int mi_repair(HA_CHECK *param, register MI_INFO *info,
char * name, int rep_quick);
-int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name);
-int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
+int mi_sort_index(HA_CHECK *param, register MI_INFO *info, char * name);
+int mi_repair_by_sort(HA_CHECK *param, register MI_INFO *info,
const char * name, int rep_quick);
-int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
+int mi_repair_parallel(HA_CHECK *param, register MI_INFO *info,
const char * name, int rep_quick);
int change_to_newfile(const char * filename, const char * old_ext,
const char * new_ext, myf myflags);
-int lock_file(MI_CHECK *param, File file, my_off_t start, int lock_type,
+int lock_file(HA_CHECK *param, File file, my_off_t start, int lock_type,
const char *filetype, const char *filename);
-void lock_memory(MI_CHECK *param);
-void update_auto_increment_key(MI_CHECK *param, MI_INFO *info,
+void lock_memory(HA_CHECK *param);
+void update_auto_increment_key(HA_CHECK *param, MI_INFO *info,
my_bool repair);
-int update_state_info(MI_CHECK *param, MI_INFO *info,uint update);
+int update_state_info(HA_CHECK *param, MI_INFO *info,uint update);
void update_key_parts(MI_KEYDEF *keyinfo, ulong *rec_per_key_part,
- ulonglong *unique, ulonglong *notnull,
+ ulonglong *unique, ulonglong *notnull,
ulonglong records);
-int filecopy(MI_CHECK *param, File to,File from,my_off_t start,
+int filecopy(HA_CHECK *param, File to,File from,my_off_t start,
my_off_t length, const char *type);
int movepoint(MI_INFO *info,uchar *record,my_off_t oldpos,
my_off_t newpos, uint prot_key);
-int write_data_suffix(SORT_INFO *sort_info, my_bool fix_datafile);
+int write_data_suffix(MI_SORT_INFO *sort_info, my_bool fix_datafile);
int test_if_almost_full(MI_INFO *info);
-int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename);
+int recreate_table(HA_CHECK *param, MI_INFO **org_info, char *filename);
void mi_disable_non_unique_index(MI_INFO *info, ha_rows rows);
my_bool mi_test_if_sort_rep(MI_INFO *info, ha_rows rows, ulonglong key_map,
my_bool force);
@@ -505,12 +413,19 @@ my_bool mi_test_if_sort_rep(MI_INFO *info, ha_rows rows, ulonglong key_map,
int mi_init_bulk_insert(MI_INFO *info, ulong cache_size, ha_rows rows);
void mi_flush_bulk_insert(MI_INFO *info, uint inx);
void mi_end_bulk_insert(MI_INFO *info);
-int mi_assign_to_key_cache(MI_INFO *info, ulonglong key_map,
+int mi_assign_to_key_cache(MI_INFO *info, ulonglong key_map,
KEY_CACHE *key_cache);
void mi_change_key_cache(KEY_CACHE *old_key_cache,
KEY_CACHE *new_key_cache);
int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves);
+int write_data_suffix(MI_SORT_INFO *sort_info, my_bool fix_datafile);
+int flush_pending_blocks(MI_SORT_PARAM *param);
+int sort_ft_buf_flush(MI_SORT_PARAM *sort_param);
+int thr_write_keys(MI_SORT_PARAM *sort_param);
+int sort_write_record(MI_SORT_PARAM *sort_param);
+int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, ulong);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/myisamchk.h b/include/myisamchk.h
new file mode 100644
index 00000000000..f6acaa7cf00
--- /dev/null
+++ b/include/myisamchk.h
@@ -0,0 +1,180 @@
+/* Copyright (C) 2006 MySQL AB
+
+ 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; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/* Definitions needed for myisamchk/mariachk.c */
+
+/*
+ Entries marked as "QQ to be removed" are NOT used to
+ pass check/repair options to xxx_check.c. They are used
+ internally by xxxchk.c or/and ha_xxxx.cc and should NOT
+ be stored together with other flags. They should be removed
+ from the following list to make addition of new flags possible.
+*/
+
+#ifndef _myisamchk_h
+#define _myisamchk_h
+
+#define T_AUTO_INC 1
+#define T_AUTO_REPAIR 2 /* QQ to be removed */
+#define T_BACKUP_DATA 4
+#define T_CALC_CHECKSUM 8
+#define T_CHECK 16 /* QQ to be removed */
+#define T_CHECK_ONLY_CHANGED 32 /* QQ to be removed */
+#define T_CREATE_MISSING_KEYS 64
+#define T_DESCRIPT 128
+#define T_DONT_CHECK_CHECKSUM 256
+#define T_EXTEND 512
+#define T_FAST (1L << 10) /* QQ to be removed */
+#define T_FORCE_CREATE (1L << 11) /* QQ to be removed */
+#define T_FORCE_UNIQUENESS (1L << 12)
+#define T_INFO (1L << 13)
+#define T_MEDIUM (1L << 14)
+#define T_QUICK (1L << 15) /* QQ to be removed */
+#define T_READONLY (1L << 16) /* QQ to be removed */
+#define T_REP (1L << 17)
+#define T_REP_BY_SORT (1L << 18) /* QQ to be removed */
+#define T_REP_PARALLEL (1L << 19) /* QQ to be removed */
+#define T_RETRY_WITHOUT_QUICK (1L << 20)
+#define T_SAFE_REPAIR (1L << 21)
+#define T_SILENT (1L << 22)
+#define T_SORT_INDEX (1L << 23) /* QQ to be removed */
+#define T_SORT_RECORDS (1L << 24) /* QQ to be removed */
+#define T_STATISTICS (1L << 25)
+#define T_UNPACK (1L << 26)
+#define T_UPDATE_STATE (1L << 27)
+#define T_VERBOSE (1L << 28)
+#define T_VERY_SILENT (1L << 29)
+#define T_WAIT_FOREVER (1L << 30)
+#define T_WRITE_LOOP ((ulong) 1L << 31)
+#define T_ZEROFILL ((ulonglong) 1L << 32)
+#define T_ZEROFILL_KEEP_LSN ((ulonglong) 1L << 33)
+/** If repair should not bump create_rename_lsn */
+#define T_NO_CREATE_RENAME_LSN ((ulonglong) 1L << 33)
+
+#define T_REP_ANY (T_REP | T_REP_BY_SORT | T_REP_PARALLEL)
+
+/*
+ Flags used by xxxxchk.c or/and ha_xxxx.cc that are NOT passed
+ to xxxcheck.c follows:
+*/
+
+#define TT_USEFRM 1
+#define TT_FOR_UPGRADE 2
+
+#define O_NEW_INDEX 1 /* Bits set in out_flag */
+#define O_NEW_DATA 2
+#define O_DATA_LOST 4
+
+typedef struct st_sort_key_blocks /* Used when sorting */
+{
+ uchar *buff, *end_pos;
+ uchar lastkey[HA_MAX_POSSIBLE_KEY_BUFF];
+ uint last_length;
+ int inited;
+} SORT_KEY_BLOCKS;
+
+
+/*
+ MARIA/MYISAM supports several statistics collection
+ methods. Currently statistics collection method is not stored in
+ MARIA file and has to be specified for each table analyze/repair
+ operation in MI_CHECK::stats_method.
+*/
+
+typedef enum
+{
+ /* Treat NULLs as inequal when collecting statistics (default for 4.1/5.0) */
+ MI_STATS_METHOD_NULLS_NOT_EQUAL,
+ /* Treat NULLs as equal when collecting statistics (like 4.0 did) */
+ MI_STATS_METHOD_NULLS_EQUAL,
+ /* Ignore NULLs - count only tuples without NULLs in the index components */
+ MI_STATS_METHOD_IGNORE_NULLS
+} enum_handler_stats_method;
+
+
+typedef struct st_handler_check_param
+{
+ char *isam_file_name;
+ MY_TMPDIR *tmpdir;
+ void *thd;
+ const char *db_name, *table_name, *op_name;
+ ulonglong auto_increment_value;
+ ulonglong max_data_file_length;
+ ulonglong keys_in_use;
+ ulonglong max_record_length;
+ /*
+ The next two are used to collect statistics, see update_key_parts for
+ description.
+ */
+ ulonglong unique_count[HA_MAX_KEY_SEG + 1];
+ ulonglong notnull_count[HA_MAX_KEY_SEG + 1];
+
+ my_off_t search_after_block;
+ my_off_t new_file_pos, key_file_blocks;
+ my_off_t keydata, totaldata, key_blocks, start_check_pos;
+ my_off_t used, empty, splits, del_length, link_used, lost;
+ ha_rows total_records, total_deleted, records,del_blocks;
+ ha_rows full_page_count, tail_count;
+ ha_checksum record_checksum, glob_crc;
+ ha_checksum key_crc[HA_MAX_POSSIBLE_KEY];
+ ha_checksum tmp_key_crc[HA_MAX_POSSIBLE_KEY];
+ ha_checksum tmp_record_checksum;
+ ulonglong org_key_map;
+ ulonglong testflag;
+
+ /* Following is used to check if rows are visible */
+ ulonglong max_trid, max_found_trid;
+ ulonglong not_visible_rows_found;
+ ulonglong use_buffers; /* Used as param to getopt() */
+ size_t read_buffer_length, write_buffer_length;
+ size_t sort_buffer_length, sort_key_blocks;
+ ulong rec_per_key_part[HA_MAX_KEY_SEG * HA_MAX_POSSIBLE_KEY];
+ double new_rec_per_key_part[HA_MAX_KEY_SEG * HA_MAX_POSSIBLE_KEY];
+ uint out_flag, warning_printed, error_printed, verbose;
+ uint opt_sort_key, total_files, max_level;
+ uint key_cache_block_size, pagecache_block_size;
+ int tmpfile_createflag, err_count;
+ myf myf_rw;
+ uint16 language;
+ my_bool using_global_keycache, opt_lock_memory, opt_follow_links;
+ my_bool retry_repair, force_sort, calc_checksum, static_row_size;
+ char temp_filename[FN_REFLEN];
+ IO_CACHE read_cache;
+ enum_handler_stats_method stats_method;
+#ifdef THREAD
+ pthread_mutex_t print_msg_mutex;
+ my_bool need_print_msg_lock;
+#endif
+} HA_CHECK;
+
+
+typedef struct st_sort_ftbuf
+{
+ uchar *buf, *end;
+ int count;
+ uchar lastkey[HA_MAX_KEY_BUFF];
+} SORT_FT_BUF;
+
+
+typedef struct st_buffpek {
+ my_off_t file_pos; /* Where we are in the sort file */
+ uchar *base, *key; /* Key pointers */
+ ha_rows count; /* Number of rows in table */
+ ulong mem_count; /* numbers of keys in memory */
+ ulong max_keys; /* Max keys in buffert */
+} BUFFPEK;
+
+#endif /* _myisamchk_h */
diff --git a/include/myisampack.h b/include/myisampack.h
index ecf35520a88..41b53f26a5f 100644
--- a/include/myisampack.h
+++ b/include/myisampack.h
@@ -27,58 +27,58 @@
#define mi_sint1korr(A) ((int8)(*A))
#define mi_uint1korr(A) ((uint8)(*A))
-#define mi_sint2korr(A) ((int16) (((int16) (((uchar*) (A))[1])) +\
- ((int16) ((int16) ((char*) (A))[0]) << 8)))
-#define mi_sint3korr(A) ((int32) (((((uchar*) (A))[0]) & 128) ? \
+#define mi_sint2korr(A) ((int16) (((int16) (((const uchar*) (A))[1])) +\
+ ((int16) ((int16) ((const char*) (A))[0]) << 8)))
+#define mi_sint3korr(A) ((int32) (((((const uchar*) (A))[0]) & 128) ? \
(((uint32) 255L << 24) | \
- (((uint32) ((uchar*) (A))[0]) << 16) |\
- (((uint32) ((uchar*) (A))[1]) << 8) | \
- ((uint32) ((uchar*) (A))[2])) : \
- (((uint32) ((uchar*) (A))[0]) << 16) |\
- (((uint32) ((uchar*) (A))[1]) << 8) | \
- ((uint32) ((uchar*) (A))[2])))
-#define mi_sint4korr(A) ((int32) (((int32) (((uchar*) (A))[3])) +\
- ((int32) (((uchar*) (A))[2]) << 8) +\
- ((int32) (((uchar*) (A))[1]) << 16) +\
- ((int32) ((int16) ((char*) (A))[0]) << 24)))
+ (((uint32) ((const uchar*) (A))[0]) << 16) |\
+ (((uint32) ((const uchar*) (A))[1]) << 8) | \
+ ((uint32) ((const uchar*) (A))[2])) : \
+ (((uint32) ((const uchar*) (A))[0]) << 16) |\
+ (((uint32) ((const uchar*) (A))[1]) << 8) | \
+ ((uint32) ((const uchar*) (A))[2])))
+#define mi_sint4korr(A) ((int32) (((int32) (((const uchar*) (A))[3])) +\
+ ((int32) (((const uchar*) (A))[2]) << 8) +\
+ ((int32) (((const uchar*) (A))[1]) << 16) +\
+ ((int32) ((int16) ((const char*) (A))[0]) << 24)))
#define mi_sint8korr(A) ((longlong) mi_uint8korr(A))
-#define mi_uint2korr(A) ((uint16) (((uint16) (((uchar*) (A))[1])) +\
- ((uint16) (((uchar*) (A))[0]) << 8)))
-#define mi_uint3korr(A) ((uint32) (((uint32) (((uchar*) (A))[2])) +\
- (((uint32) (((uchar*) (A))[1])) << 8) +\
- (((uint32) (((uchar*) (A))[0])) << 16)))
-#define mi_uint4korr(A) ((uint32) (((uint32) (((uchar*) (A))[3])) +\
- (((uint32) (((uchar*) (A))[2])) << 8) +\
- (((uint32) (((uchar*) (A))[1])) << 16) +\
- (((uint32) (((uchar*) (A))[0])) << 24)))
-#define mi_uint5korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[4])) +\
- (((uint32) (((uchar*) (A))[3])) << 8) +\
- (((uint32) (((uchar*) (A))[2])) << 16) +\
- (((uint32) (((uchar*) (A))[1])) << 24)) +\
- (((ulonglong) (((uchar*) (A))[0])) << 32))
-#define mi_uint6korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[5])) +\
- (((uint32) (((uchar*) (A))[4])) << 8) +\
- (((uint32) (((uchar*) (A))[3])) << 16) +\
- (((uint32) (((uchar*) (A))[2])) << 24)) +\
- (((ulonglong) (((uint32) (((uchar*) (A))[1])) +\
- (((uint32) (((uchar*) (A))[0]) << 8)))) <<\
+#define mi_uint2korr(A) ((uint16) (((uint16) (((const uchar*) (A))[1])) +\
+ ((uint16) (((const uchar*) (A))[0]) << 8)))
+#define mi_uint3korr(A) ((uint32) (((uint32) (((const uchar*) (A))[2])) +\
+ (((uint32) (((const uchar*) (A))[1])) << 8) +\
+ (((uint32) (((const uchar*) (A))[0])) << 16)))
+#define mi_uint4korr(A) ((uint32) (((uint32) (((const uchar*) (A))[3])) +\
+ (((uint32) (((const uchar*) (A))[2])) << 8) +\
+ (((uint32) (((const uchar*) (A))[1])) << 16) +\
+ (((uint32) (((const uchar*) (A))[0])) << 24)))
+#define mi_uint5korr(A) ((ulonglong)(((uint32) (((const uchar*) (A))[4])) +\
+ (((uint32) (((const uchar*) (A))[3])) << 8) +\
+ (((uint32) (((const uchar*) (A))[2])) << 16) +\
+ (((uint32) (((const uchar*) (A))[1])) << 24)) +\
+ (((ulonglong) (((const uchar*) (A))[0])) << 32))
+#define mi_uint6korr(A) ((ulonglong)(((uint32) (((const uchar*) (A))[5])) +\
+ (((uint32) (((const uchar*) (A))[4])) << 8) +\
+ (((uint32) (((const uchar*) (A))[3])) << 16) +\
+ (((uint32) (((const uchar*) (A))[2])) << 24)) +\
+ (((ulonglong) (((uint32) (((const uchar*) (A))[1])) +\
+ (((uint32) (((const uchar*) (A))[0]) << 8)))) <<\
32))
-#define mi_uint7korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[6])) +\
- (((uint32) (((uchar*) (A))[5])) << 8) +\
- (((uint32) (((uchar*) (A))[4])) << 16) +\
- (((uint32) (((uchar*) (A))[3])) << 24)) +\
- (((ulonglong) (((uint32) (((uchar*) (A))[2])) +\
- (((uint32) (((uchar*) (A))[1])) << 8) +\
- (((uint32) (((uchar*) (A))[0])) << 16))) <<\
+#define mi_uint7korr(A) ((ulonglong)(((uint32) (((const uchar*) (A))[6])) +\
+ (((uint32) (((const uchar*) (A))[5])) << 8) +\
+ (((uint32) (((const uchar*) (A))[4])) << 16) +\
+ (((uint32) (((const uchar*) (A))[3])) << 24)) +\
+ (((ulonglong) (((uint32) (((const uchar*) (A))[2])) +\
+ (((uint32) (((const uchar*) (A))[1])) << 8) +\
+ (((uint32) (((const uchar*) (A))[0])) << 16))) <<\
32))
-#define mi_uint8korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[7])) +\
- (((uint32) (((uchar*) (A))[6])) << 8) +\
- (((uint32) (((uchar*) (A))[5])) << 16) +\
- (((uint32) (((uchar*) (A))[4])) << 24)) +\
- (((ulonglong) (((uint32) (((uchar*) (A))[3])) +\
- (((uint32) (((uchar*) (A))[2])) << 8) +\
- (((uint32) (((uchar*) (A))[1])) << 16) +\
- (((uint32) (((uchar*) (A))[0])) << 24))) <<\
+#define mi_uint8korr(A) ((ulonglong)(((uint32) (((const uchar*) (A))[7])) +\
+ (((uint32) (((const uchar*) (A))[6])) << 8) +\
+ (((uint32) (((const uchar*) (A))[5])) << 16) +\
+ (((uint32) (((const uchar*) (A))[4])) << 24)) +\
+ (((ulonglong) (((uint32) (((const uchar*) (A))[3])) +\
+ (((uint32) (((const uchar*) (A))[2])) << 8) +\
+ (((uint32) (((const uchar*) (A))[1])) << 16) +\
+ (((uint32) (((const uchar*) (A))[0])) << 24))) <<\
32))
/* This one is for uniformity */
@@ -135,85 +135,85 @@
((uchar*) (T))[3]= ((uchar*) &A)[3]; }
#define mi_float4get(V,M) { float def_temp;\
- ((uchar*) &def_temp)[0]= ((uchar*) (M))[0];\
- ((uchar*) &def_temp)[1]= ((uchar*) (M))[1];\
- ((uchar*) &def_temp)[2]= ((uchar*) (M))[2];\
- ((uchar*) &def_temp)[3]= ((uchar*) (M))[3];\
+ ((uchar*) &def_temp)[0]= ((const uchar*) (M))[0];\
+ ((uchar*) &def_temp)[1]= ((const uchar*) (M))[1]; \
+ ((uchar*) &def_temp)[2]= ((const uchar*) (M))[2];\
+ ((uchar*) &def_temp)[3]= ((const uchar*) (M))[3];\
(V)= def_temp; }
-#define mi_float8store(T,V) { ((uchar*) (T))[0]= ((uchar*) &V)[0];\
- ((uchar*) (T))[1]= ((uchar*) &V)[1];\
- ((uchar*) (T))[2]= ((uchar*) &V)[2];\
- ((uchar*) (T))[3]= ((uchar*) &V)[3];\
- ((uchar*) (T))[4]= ((uchar*) &V)[4];\
- ((uchar*) (T))[5]= ((uchar*) &V)[5];\
- ((uchar*) (T))[6]= ((uchar*) &V)[6];\
- ((uchar*) (T))[7]= ((uchar*) &V)[7]; }
+#define mi_float8store(T,V) { ((uchar*) (T))[0]= ((const uchar*) &V)[0];\
+ ((uchar*) (T))[1]= ((const uchar*) &V)[1];\
+ ((uchar*) (T))[2]= ((const uchar*) &V)[2];\
+ ((uchar*) (T))[3]= ((const uchar*) &V)[3];\
+ ((uchar*) (T))[4]= ((const uchar*) &V)[4];\
+ ((uchar*) (T))[5]= ((const uchar*) &V)[5];\
+ ((uchar*) (T))[6]= ((const uchar*) &V)[6];\
+ ((uchar*) (T))[7]= ((const uchar*) &V)[7]; }
#define mi_float8get(V,M) { double def_temp;\
- ((uchar*) &def_temp)[0]= ((uchar*) (M))[0];\
- ((uchar*) &def_temp)[1]= ((uchar*) (M))[1];\
- ((uchar*) &def_temp)[2]= ((uchar*) (M))[2];\
- ((uchar*) &def_temp)[3]= ((uchar*) (M))[3];\
- ((uchar*) &def_temp)[4]= ((uchar*) (M))[4];\
- ((uchar*) &def_temp)[5]= ((uchar*) (M))[5];\
- ((uchar*) &def_temp)[6]= ((uchar*) (M))[6];\
- ((uchar*) &def_temp)[7]= ((uchar*) (M))[7]; \
+ ((uchar*) &def_temp)[0]= ((const uchar*) (M))[0];\
+ ((uchar*) &def_temp)[1]= ((const uchar*) (M))[1];\
+ ((uchar*) &def_temp)[2]= ((const uchar*) (M))[2];\
+ ((uchar*) &def_temp)[3]= ((const uchar*) (M))[3];\
+ ((uchar*) &def_temp)[4]= ((const uchar*) (M))[4];\
+ ((uchar*) &def_temp)[5]= ((const uchar*) (M))[5];\
+ ((uchar*) &def_temp)[6]= ((const uchar*) (M))[6];\
+ ((uchar*) &def_temp)[7]= ((const uchar*) (M))[7]; \
(V)= def_temp; }
#else
-#define mi_float4store(T,A) { ((uchar*) (T))[0]= ((uchar*) &A)[3];\
- ((uchar*) (T))[1]= ((uchar*) &A)[2];\
- ((uchar*) (T))[2]= ((uchar*) &A)[1];\
- ((uchar*) (T))[3]= ((uchar*) &A)[0]; }
+#define mi_float4store(T,A) { ((uchar*) (T))[0]= ((const uchar*) &A)[3];\
+ ((uchar*) (T))[1]= ((const uchar*) &A)[2];\
+ ((uchar*) (T))[2]= ((const uchar*) &A)[1];\
+ ((uchar*) (T))[3]= ((const uchar*) &A)[0]; }
#define mi_float4get(V,M) { float def_temp;\
- ((uchar*) &def_temp)[0]= ((uchar*) (M))[3];\
- ((uchar*) &def_temp)[1]= ((uchar*) (M))[2];\
- ((uchar*) &def_temp)[2]= ((uchar*) (M))[1];\
- ((uchar*) &def_temp)[3]= ((uchar*) (M))[0];\
+ ((uchar*) &def_temp)[0]= ((const uchar*) (M))[3];\
+ ((uchar*) &def_temp)[1]= ((const uchar*) (M))[2];\
+ ((uchar*) &def_temp)[2]= ((const uchar*) (M))[1];\
+ ((uchar*) &def_temp)[3]= ((const uchar*) (M))[0];\
(V)= def_temp; }
#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
-#define mi_float8store(T,V) { ((uchar*) (T))[0]= ((uchar*) &V)[3];\
- ((uchar*) (T))[1]= ((uchar*) &V)[2];\
- ((uchar*) (T))[2]= ((uchar*) &V)[1];\
- ((uchar*) (T))[3]= ((uchar*) &V)[0];\
- ((uchar*) (T))[4]= ((uchar*) &V)[7];\
- ((uchar*) (T))[5]= ((uchar*) &V)[6];\
- ((uchar*) (T))[6]= ((uchar*) &V)[5];\
- ((uchar*) (T))[7]= ((uchar*) &V)[4];}
+#define mi_float8store(T,V) { ((uchar*) (T))[0]= ((const uchar*) &V)[3];\
+ ((uchar*) (T))[1]= ((const uchar*) &V)[2];\
+ ((uchar*) (T))[2]= ((const uchar*) &V)[1];\
+ ((uchar*) (T))[3]= ((const uchar*) &V)[0];\
+ ((uchar*) (T))[4]= ((const uchar*) &V)[7];\
+ ((uchar*) (T))[5]= ((const uchar*) &V)[6];\
+ ((uchar*) (T))[6]= ((const uchar*) &V)[5];\
+ ((uchar*) (T))[7]= ((const uchar*) &V)[4];}
#define mi_float8get(V,M) { double def_temp;\
- ((uchar*) &def_temp)[0]= ((uchar*) (M))[3];\
- ((uchar*) &def_temp)[1]= ((uchar*) (M))[2];\
- ((uchar*) &def_temp)[2]= ((uchar*) (M))[1];\
- ((uchar*) &def_temp)[3]= ((uchar*) (M))[0];\
- ((uchar*) &def_temp)[4]= ((uchar*) (M))[7];\
- ((uchar*) &def_temp)[5]= ((uchar*) (M))[6];\
- ((uchar*) &def_temp)[6]= ((uchar*) (M))[5];\
- ((uchar*) &def_temp)[7]= ((uchar*) (M))[4];\
+ ((uchar*) &def_temp)[0]= ((const uchar*) (M))[3];\
+ ((uchar*) &def_temp)[1]= ((const uchar*) (M))[2];\
+ ((uchar*) &def_temp)[2]= ((const uchar*) (M))[1];\
+ ((uchar*) &def_temp)[3]= ((const uchar*) (M))[0];\
+ ((uchar*) &def_temp)[4]= ((const uchar*) (M))[7];\
+ ((uchar*) &def_temp)[5]= ((const uchar*) (M))[6];\
+ ((uchar*) &def_temp)[6]= ((const uchar*) (M))[5];\
+ ((uchar*) &def_temp)[7]= ((const uchar*) (M))[4];\
(V)= def_temp; }
#else
-#define mi_float8store(T,V) { ((uchar*) (T))[0]= ((uchar*) &V)[7];\
- ((uchar*) (T))[1]= ((uchar*) &V)[6];\
- ((uchar*) (T))[2]= ((uchar*) &V)[5];\
- ((uchar*) (T))[3]= ((uchar*) &V)[4];\
- ((uchar*) (T))[4]= ((uchar*) &V)[3];\
- ((uchar*) (T))[5]= ((uchar*) &V)[2];\
- ((uchar*) (T))[6]= ((uchar*) &V)[1];\
- ((uchar*) (T))[7]= ((uchar*) &V)[0];}
+#define mi_float8store(T,V) { ((uchar*) (T))[0]= ((const uchar*) &V)[7];\
+ ((uchar*) (T))[1]= ((const uchar*) &V)[6];\
+ ((uchar*) (T))[2]= ((const uchar*) &V)[5];\
+ ((uchar*) (T))[3]= ((const uchar*) &V)[4];\
+ ((uchar*) (T))[4]= ((const uchar*) &V)[3];\
+ ((uchar*) (T))[5]= ((const uchar*) &V)[2];\
+ ((uchar*) (T))[6]= ((const uchar*) &V)[1];\
+ ((uchar*) (T))[7]= ((const uchar*) &V)[0];}
#define mi_float8get(V,M) { double def_temp;\
- ((uchar*) &def_temp)[0]= ((uchar*) (M))[7];\
- ((uchar*) &def_temp)[1]= ((uchar*) (M))[6];\
- ((uchar*) &def_temp)[2]= ((uchar*) (M))[5];\
- ((uchar*) &def_temp)[3]= ((uchar*) (M))[4];\
- ((uchar*) &def_temp)[4]= ((uchar*) (M))[3];\
- ((uchar*) &def_temp)[5]= ((uchar*) (M))[2];\
- ((uchar*) &def_temp)[6]= ((uchar*) (M))[1];\
- ((uchar*) &def_temp)[7]= ((uchar*) (M))[0];\
+ ((uchar*) &def_temp)[0]= ((const uchar*) (M))[7];\
+ ((uchar*) &def_temp)[1]= ((const uchar*) (M))[6];\
+ ((uchar*) &def_temp)[2]= ((const uchar*) (M))[5];\
+ ((uchar*) &def_temp)[3]= ((const uchar*) (M))[4];\
+ ((uchar*) &def_temp)[4]= ((const uchar*) (M))[3];\
+ ((uchar*) &def_temp)[5]= ((const uchar*) (M))[2];\
+ ((uchar*) &def_temp)[6]= ((const uchar*) (M))[1];\
+ ((uchar*) &def_temp)[7]= ((const uchar*) (M))[0];\
(V)= def_temp; }
#endif /* __FLOAT_WORD_ORDER */
#endif /* WORDS_BIGENDIAN */
@@ -226,7 +226,7 @@
#else
#define mi_rowstore(T,A) { mi_int4store(T, 0);\
mi_int4store(((uchar*) (T) + 4), A); }
-#define mi_rowkorr(T) mi_uint4korr((uchar*) (T) + 4)
+#define mi_rowkorr(T) mi_uint4korr((const uchar*) (T) + 4)
#endif
#if SIZEOF_OFF_T > 4
@@ -237,6 +237,6 @@
bfill((char*) (T), 8, 255);\
else { mi_int4store((T), 0);\
mi_int4store(((T) + 4), A); }}
-#define mi_sizekorr(T) mi_uint4korr((uchar*) (T) + 4)
+#define mi_sizekorr(T) mi_uint4korr((const uchar*) (T) + 4)
#endif
#endif /* MYISAMPACK_INCLUDED */
diff --git a/include/mysql.h b/include/mysql.h
index fdb29124d68..cfaf1c7881b 100644
--- a/include/mysql.h
+++ b/include/mysql.h
@@ -167,9 +167,15 @@ enum mysql_option
MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
- MYSQL_OPT_SSL_VERIFY_SERVER_CERT
+ MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH
};
+/**
+ @todo remove the "extension", move st_mysql_options completely
+ out of mysql.h
+*/
+struct st_mysql_options_extention;
+
struct st_mysql_options {
unsigned int connect_timeout, read_timeout, write_timeout;
unsigned int port, protocol;
@@ -203,7 +209,7 @@ struct st_mysql_options {
void (*local_infile_end)(void *);
int (*local_infile_error)(void *, char *, unsigned int);
void *local_infile_userdata;
- void *extension;
+ struct st_mysql_options_extention *extension;
};
enum mysql_status
@@ -239,7 +245,7 @@ typedef struct st_mysql
unsigned char *connector_fd; /* ConnectorFd for SSL */
char *host,*user,*passwd,*unix_socket,*server_version,*host_info;
char *info, *db;
- struct charset_info_st *charset;
+ const struct charset_info_st *charset;
MYSQL_FIELD *fields;
MEM_ROOT field_alloc;
my_ulonglong affected_rows;
@@ -428,6 +434,7 @@ int STDCALL mysql_set_server_option(MYSQL *mysql,
int STDCALL mysql_ping(MYSQL *mysql);
const char * STDCALL mysql_stat(MYSQL *mysql);
const char * STDCALL mysql_get_server_info(MYSQL *mysql);
+const char * STDCALL mysql_get_server_name(MYSQL *mysql);
const char * STDCALL mysql_get_client_info(void);
unsigned long STDCALL mysql_get_client_version(void);
const char * STDCALL mysql_get_host_info(MYSQL *mysql);
@@ -461,6 +468,7 @@ void STDCALL mysql_debug(const char *debug);
void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name);
unsigned int STDCALL mysql_thread_safe(void);
my_bool STDCALL mysql_embedded(void);
+my_bool STDCALL mariadb_connection(MYSQL *mysql);
my_bool STDCALL mysql_read_query_result(MYSQL *mysql);
@@ -639,38 +647,6 @@ enum enum_stmt_attr_type
};
-typedef struct st_mysql_methods
-{
- my_bool (*read_query_result)(MYSQL *mysql);
- my_bool (*advanced_command)(MYSQL *mysql,
- enum enum_server_command command,
- const unsigned char *header,
- unsigned long header_length,
- const unsigned char *arg,
- unsigned long arg_length,
- my_bool skip_check,
- MYSQL_STMT *stmt);
- MYSQL_DATA *(*read_rows)(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
- unsigned int fields);
- MYSQL_RES * (*use_result)(MYSQL *mysql);
- void (*fetch_lengths)(unsigned long *to,
- MYSQL_ROW column, unsigned int field_count);
- void (*flush_use_result)(MYSQL *mysql, my_bool flush_all_results);
-#if !defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY)
- MYSQL_FIELD * (*list_fields)(MYSQL *mysql);
- my_bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
- int (*stmt_execute)(MYSQL_STMT *stmt);
- int (*read_binary_rows)(MYSQL_STMT *stmt);
- int (*unbuffered_fetch)(MYSQL *mysql, char **row);
- void (*free_embedded_thd)(MYSQL *mysql);
- const char *(*read_statistics)(MYSQL *mysql);
- my_bool (*next_result)(MYSQL *mysql);
- int (*read_change_user_result)(MYSQL *mysql, char *buff, const char *passwd);
- int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
-#endif
-} MYSQL_METHODS;
-
-
MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql);
int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query,
unsigned long length);
@@ -733,18 +709,6 @@ int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
#endif
#define HAVE_MYSQL_REAL_CONNECT
-/*
- The following functions are mainly exported because of mysqlbinlog;
- They are not for general usage
-*/
-
-#define simple_command(mysql, command, arg, length, skip_check) \
- (*(mysql)->methods->advanced_command)(mysql, command, 0, \
- 0, arg, length, skip_check, NULL)
-#define stmt_command(mysql, command, arg, length, stmt) \
- (*(mysql)->methods->advanced_command)(mysql, command, 0, \
- 0, arg, length, 1, stmt)
-
#ifdef __cplusplus
}
#endif
diff --git a/include/mysql.h.pp b/include/mysql.h.pp
index c7bc5c294ce..a2300dca112 100644
--- a/include/mysql.h.pp
+++ b/include/mysql.h.pp
@@ -27,8 +27,8 @@ typedef struct st_net {
unsigned int *return_status;
unsigned char reading_or_writing;
char save_char;
- my_bool unused1;
- my_bool unused2;
+ char net_skip_rest_factor;
+ my_bool unused;
my_bool compress;
my_bool unused3;
unsigned char *unused;
@@ -97,12 +97,11 @@ unsigned long my_net_read(NET *net);
struct sockaddr;
int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen,
unsigned int timeout);
-struct rand_struct {
- unsigned long seed1,seed2,max_value;
- double max_value_dbl;
+struct my_rnd_struct;
+enum Item_result
+{
+ STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT, DECIMAL_RESULT
};
-enum Item_result {STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT,
- DECIMAL_RESULT};
typedef struct st_udf_args
{
unsigned int arg_count;
@@ -123,20 +122,18 @@ typedef struct st_udf_init
my_bool const_item;
void *extension;
} UDF_INIT;
-void randominit(struct rand_struct *, unsigned long seed1,
- unsigned long seed2);
-double my_rnd(struct rand_struct *);
-void create_random_string(char *to, unsigned int length, struct rand_struct *rand_st);
+void create_random_string(char *to, unsigned int length,
+ struct my_rnd_struct *rand_st);
void hash_password(unsigned long *to, const char *password, unsigned int password_len);
void make_scrambled_password_323(char *to, const char *password);
void scramble_323(char *to, const char *message, const char *password);
-my_bool check_scramble_323(const char *, const char *message,
+my_bool check_scramble_323(const unsigned char *reply, const char *message,
unsigned long *salt);
void get_salt_from_password_323(unsigned long *res, const char *password);
void make_password_from_salt_323(char *to, const unsigned long *salt);
void make_scrambled_password(char *to, const char *password);
void scramble(char *to, const char *message, const char *password);
-my_bool check_scramble(const char *reply, const char *message,
+my_bool check_scramble(const unsigned char *reply, const char *message,
const unsigned char *hash_stage2);
void get_salt_from_password(unsigned char *res, const char *password);
void make_password_from_salt(char *to, const unsigned char *hash_stage2);
@@ -204,8 +201,8 @@ typedef unsigned long long my_ulonglong;
typedef struct st_used_mem
{
struct st_used_mem *next;
- unsigned int left;
- unsigned int size;
+ size_t left;
+ size_t size;
} USED_MEM;
typedef struct st_mem_root
{
@@ -225,8 +222,10 @@ typedef struct st_typelib {
unsigned int *type_lengths;
} TYPELIB;
extern my_ulonglong find_typeset(char *x, TYPELIB *typelib,int *error_position);
-extern int find_type_or_exit(const char *x, TYPELIB *typelib,
- const char *option);
+extern int find_type_with_warning(const char *x, TYPELIB *typelib,
+ const char *option);
+extern uint find_type_or_exit(const char *x, TYPELIB *typelib,
+ const char *option);
extern int find_type(char *x, const TYPELIB *typelib, unsigned int full_name);
extern void make_type(char *to,unsigned int nr,TYPELIB *typelib);
extern const char *get_type(TYPELIB *typelib,unsigned int nr);
@@ -262,8 +261,9 @@ enum mysql_option
MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
- MYSQL_OPT_SSL_VERIFY_SERVER_CERT
+ MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH
};
+struct st_mysql_options_extention;
struct st_mysql_options {
unsigned int connect_timeout, read_timeout, write_timeout;
unsigned int port, protocol;
@@ -293,7 +293,7 @@ struct st_mysql_options {
void (*local_infile_end)(void *);
int (*local_infile_error)(void *, char *, unsigned int);
void *local_infile_userdata;
- void *extension;
+ struct st_mysql_options_extention *extension;
};
enum mysql_status
{
@@ -324,7 +324,7 @@ typedef struct st_mysql
unsigned char *connector_fd;
char *host,*user,*passwd,*unix_socket,*server_version,*host_info;
char *info, *db;
- struct charset_info_st *charset;
+ const struct charset_info_st *charset;
MYSQL_FIELD *fields;
MEM_ROOT field_alloc;
my_ulonglong affected_rows;
@@ -448,6 +448,7 @@ int mysql_set_server_option(MYSQL *mysql,
int mysql_ping(MYSQL *mysql);
const char * mysql_stat(MYSQL *mysql);
const char * mysql_get_server_info(MYSQL *mysql);
+const char * mysql_get_server_name(MYSQL *mysql);
const char * mysql_get_client_info(void);
unsigned long mysql_get_client_version(void);
const char * mysql_get_host_info(MYSQL *mysql);
@@ -481,6 +482,7 @@ void mysql_debug(const char *debug);
void myodbc_remove_escape(MYSQL *mysql,char *name);
unsigned int mysql_thread_safe(void);
my_bool mysql_embedded(void);
+my_bool mariadb_connection(MYSQL *mysql);
my_bool mysql_read_query_result(MYSQL *mysql);
enum enum_mysql_stmt_state
{
@@ -548,34 +550,6 @@ enum enum_stmt_attr_type
STMT_ATTR_CURSOR_TYPE,
STMT_ATTR_PREFETCH_ROWS
};
-typedef struct st_mysql_methods
-{
- my_bool (*read_query_result)(MYSQL *mysql);
- my_bool (*advanced_command)(MYSQL *mysql,
- enum enum_server_command command,
- const unsigned char *header,
- unsigned long header_length,
- const unsigned char *arg,
- unsigned long arg_length,
- my_bool skip_check,
- MYSQL_STMT *stmt);
- MYSQL_DATA *(*read_rows)(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
- unsigned int fields);
- MYSQL_RES * (*use_result)(MYSQL *mysql);
- void (*fetch_lengths)(unsigned long *to,
- MYSQL_ROW column, unsigned int field_count);
- void (*flush_use_result)(MYSQL *mysql, my_bool flush_all_results);
- MYSQL_FIELD * (*list_fields)(MYSQL *mysql);
- my_bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
- int (*stmt_execute)(MYSQL_STMT *stmt);
- int (*read_binary_rows)(MYSQL_STMT *stmt);
- int (*unbuffered_fetch)(MYSQL *mysql, char **row);
- void (*free_embedded_thd)(MYSQL *mysql);
- const char *(*read_statistics)(MYSQL *mysql);
- my_bool (*next_result)(MYSQL *mysql);
- int (*read_change_user_result)(MYSQL *mysql, char *buff, const char *passwd);
- int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
-} MYSQL_METHODS;
MYSQL_STMT * mysql_stmt_init(MYSQL *mysql);
int mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query,
unsigned long length);
diff --git a/include/mysql/client_plugin.h b/include/mysql/client_plugin.h
new file mode 100644
index 00000000000..9c7b1aee9f9
--- /dev/null
+++ b/include/mysql/client_plugin.h
@@ -0,0 +1,166 @@
+#ifndef MYSQL_CLIENT_PLUGIN_INCLUDED
+/* Copyright (C) 2010 Sergei Golubchik and Monty Program Ab
+
+ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/**
+ @file
+
+ MySQL Client Plugin API
+
+ This file defines the API for plugins that work on the client side
+*/
+#define MYSQL_CLIENT_PLUGIN_INCLUDED
+
+#ifndef MYSQL_ABI_CHECK
+#include <stdarg.h>
+#include <stdlib.h>
+#endif
+
+/* known plugin types */
+#define MYSQL_CLIENT_reserved1 0
+#define MYSQL_CLIENT_reserved2 1
+#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN 2
+
+#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION 0x0100
+
+#define MYSQL_CLIENT_MAX_PLUGINS 3
+
+#define mysql_declare_client_plugin(X) \
+ struct st_mysql_client_plugin_ ## X \
+ _mysql_client_plugin_declaration_ = { \
+ MYSQL_CLIENT_ ## X ## _PLUGIN, \
+ MYSQL_CLIENT_ ## X ## _PLUGIN_INTERFACE_VERSION,
+#define mysql_end_client_plugin }
+
+/* generic plugin header structure */
+#define MYSQL_CLIENT_PLUGIN_HEADER \
+ int type; \
+ unsigned int interface_version; \
+ const char *name; \
+ const char *author; \
+ const char *desc; \
+ unsigned int version[3]; \
+ int (*init)(char *, size_t, int, va_list); \
+ int (*deinit)();
+
+struct st_mysql_client_plugin
+{
+ MYSQL_CLIENT_PLUGIN_HEADER
+};
+
+struct st_mysql;
+
+/******** authentication plugin specific declarations *********/
+#include <mysql/plugin_auth_common.h>
+
+struct st_mysql_client_plugin_AUTHENTICATION
+{
+ MYSQL_CLIENT_PLUGIN_HEADER
+ int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql);
+};
+
+/**
+ type of the mysql_authentication_dialog_ask function
+
+ @param mysql mysql
+ @param type type of the input
+ 1 - ordinary string input
+ 2 - password string
+ @param prompt prompt
+ @param buf a buffer to store the use input
+ @param buf_len the length of the buffer
+
+ @retval a pointer to the user input string.
+ It may be equal to 'buf' or to 'mysql->password'.
+ In all other cases it is assumed to be an allocated
+ string, and the "dialog" plugin will free() it.
+*/
+typedef char *(*mysql_authentication_dialog_ask_t)(struct st_mysql *mysql,
+ int type, const char *prompt, char *buf, int buf_len);
+/******** using plugins ************/
+
+/**
+ loads a plugin and initializes it
+
+ @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used,
+ and last_errno/last_error, for error reporting
+ @param name a name of the plugin to load
+ @param type type of plugin that should be loaded, -1 to disable type check
+ @param argc number of arguments to pass to the plugin initialization
+ function
+ @param ... arguments for the plugin initialization function
+
+ @retval
+ a pointer to the loaded plugin, or NULL in case of a failure
+*/
+struct st_mysql_client_plugin *
+mysql_load_plugin(struct st_mysql *mysql, const char *name, int type,
+ int argc, ...);
+
+/**
+ loads a plugin and initializes it, taking va_list as an argument
+
+ This is the same as mysql_load_plugin, but take va_list instead of
+ a list of arguments.
+
+ @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used,
+ and last_errno/last_error, for error reporting
+ @param name a name of the plugin to load
+ @param type type of plugin that should be loaded, -1 to disable type check
+ @param argc number of arguments to pass to the plugin initialization
+ function
+ @param args arguments for the plugin initialization function
+
+ @retval
+ a pointer to the loaded plugin, or NULL in case of a failure
+*/
+struct st_mysql_client_plugin *
+mysql_load_plugin_v(struct st_mysql *mysql, const char *name, int type,
+ int argc, va_list args);
+
+/**
+ finds an already loaded plugin by name, or loads it, if necessary
+
+ @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used,
+ and last_errno/last_error, for error reporting
+ @param name a name of the plugin to load
+ @param type type of plugin that should be loaded
+
+ @retval
+ a pointer to the plugin, or NULL in case of a failure
+*/
+struct st_mysql_client_plugin *
+mysql_client_find_plugin(struct st_mysql *mysql, const char *name, int type);
+
+/**
+ adds a plugin structure to the list of loaded plugins
+
+ This is useful if an application has the necessary functionality
+ (for example, a special load data handler) statically linked into
+ the application binary. It can use this function to register the plugin
+ directly, avoiding the need to factor it out into a shared object.
+
+ @param mysql MYSQL structure. It is only used for error reporting
+ @param plugin an st_mysql_client_plugin structure to register
+
+ @retval
+ a pointer to the plugin, or NULL in case of a failure
+*/
+struct st_mysql_client_plugin *
+mysql_client_register_plugin(struct st_mysql *mysql,
+ struct st_mysql_client_plugin *plugin);
+
+#endif
+
diff --git a/include/mysql/client_plugin.h.pp b/include/mysql/client_plugin.h.pp
new file mode 100644
index 00000000000..ca477d83bb2
--- /dev/null
+++ b/include/mysql/client_plugin.h.pp
@@ -0,0 +1,39 @@
+struct st_mysql_client_plugin
+{
+ int type; unsigned int interface_version; const char *name; const char *author; const char *desc; unsigned int version[3]; int (*init)(char *, size_t, int, va_list); int (*deinit)();
+};
+struct st_mysql;
+#include <mysql/plugin_auth_common.h>
+typedef struct st_plugin_vio_info
+{
+ enum { MYSQL_VIO_INVALID, MYSQL_VIO_TCP, MYSQL_VIO_SOCKET,
+ MYSQL_VIO_PIPE, MYSQL_VIO_MEMORY } protocol;
+ int socket;
+} MYSQL_PLUGIN_VIO_INFO;
+typedef struct st_plugin_vio
+{
+ int (*read_packet)(struct st_plugin_vio *vio,
+ unsigned char **buf);
+ int (*write_packet)(struct st_plugin_vio *vio,
+ const unsigned char *packet,
+ int packet_len);
+ void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info);
+} MYSQL_PLUGIN_VIO;
+struct st_mysql_client_plugin_AUTHENTICATION
+{
+ int type; unsigned int interface_version; const char *name; const char *author; const char *desc; unsigned int version[3]; int (*init)(char *, size_t, int, va_list); int (*deinit)();
+ int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql);
+};
+typedef char *(*mysql_authentication_dialog_ask_t)(struct st_mysql *mysql,
+ int type, const char *prompt, char *buf, int buf_len);
+struct st_mysql_client_plugin *
+mysql_load_plugin(struct st_mysql *mysql, const char *name, int type,
+ int argc, ...);
+struct st_mysql_client_plugin *
+mysql_load_plugin_v(struct st_mysql *mysql, const char *name, int type,
+ int argc, va_list args);
+struct st_mysql_client_plugin *
+mysql_client_find_plugin(struct st_mysql *mysql, const char *name, int type);
+struct st_mysql_client_plugin *
+mysql_client_register_plugin(struct st_mysql *mysql,
+ struct st_mysql_client_plugin *plugin);
diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h
index 43de7deef74..04463c19090 100644
--- a/include/mysql/plugin.h
+++ b/include/mysql/plugin.h
@@ -71,8 +71,12 @@ typedef struct st_mysql_xid MYSQL_XID;
Plugin API. Common for all plugin types.
*/
+/* MySQL plugin interface version */
#define MYSQL_PLUGIN_INTERFACE_VERSION 0x0102
+/* MariaDB plugin interface version */
+#define MARIA_PLUGIN_INTERFACE_VERSION 0x0100
+
/*
The allowable types of plugins
*/
@@ -83,7 +87,8 @@ typedef struct st_mysql_xid MYSQL_XID;
#define MYSQL_INFORMATION_SCHEMA_PLUGIN 4 /* The I_S plugin type */
#define MYSQL_AUDIT_PLUGIN 5 /* The Audit plugin type */
#define MYSQL_REPLICATION_PLUGIN 6 /* The replication plugin type */
-#define MYSQL_MAX_PLUGIN_TYPE_NUM 7 /* The number of plugin types */
+#define MYSQL_AUTHENTICATION_PLUGIN 7 /* The authentication plugin type */
+#define MYSQL_MAX_PLUGIN_TYPE_NUM 8 /* The number of plugin types */
/* We use the following strings to define licenses for plugins */
#define PLUGIN_LICENSE_PROPRIETARY 0
@@ -94,6 +99,14 @@ typedef struct st_mysql_xid MYSQL_XID;
#define PLUGIN_LICENSE_GPL_STRING "GPL"
#define PLUGIN_LICENSE_BSD_STRING "BSD"
+/* definitions of code maturity for plugins */
+#define MariaDB_PLUGIN_MATURITY_UNKNOWN 0
+#define MariaDB_PLUGIN_MATURITY_EXPERIMENTAL 1
+#define MariaDB_PLUGIN_MATURITY_ALPHA 2
+#define MariaDB_PLUGIN_MATURITY_BETA 3
+#define MariaDB_PLUGIN_MATURITY_GAMMA 4
+#define MariaDB_PLUGIN_MATURITY_STABLE 5
+
/*
Macros for beginning and ending plugin declarations. Between
mysql_declare_plugin and mysql_declare_plugin_end there should
@@ -103,14 +116,26 @@ typedef struct st_mysql_xid MYSQL_XID;
#ifndef MYSQL_DYNAMIC_PLUGIN
#define __MYSQL_DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS) \
-MYSQL_PLUGIN_EXPORT int VERSION= MYSQL_PLUGIN_INTERFACE_VERSION; \
-MYSQL_PLUGIN_EXPORT int PSIZE= sizeof(struct st_mysql_plugin); \
-MYSQL_PLUGIN_EXPORT struct st_mysql_plugin DECLS[]= {
+int VERSION= MYSQL_PLUGIN_INTERFACE_VERSION; \
+int PSIZE= sizeof(struct st_mysql_plugin); \
+struct st_mysql_plugin DECLS[]= {
+
+#define MARIA_DECLARE_PLUGIN__(NAME, VERSION, PSIZE, DECLS) \
+int VERSION= MARIA_PLUGIN_INTERFACE_VERSION; \
+int PSIZE= sizeof(struct st_maria_plugin); \
+struct st_maria_plugin DECLS[]= {
#else
+
#define __MYSQL_DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS) \
MYSQL_PLUGIN_EXPORT int _mysql_plugin_interface_version_= MYSQL_PLUGIN_INTERFACE_VERSION; \
MYSQL_PLUGIN_EXPORT int _mysql_sizeof_struct_st_plugin_= sizeof(struct st_mysql_plugin); \
MYSQL_PLUGIN_EXPORT struct st_mysql_plugin _mysql_plugin_declarations_[]= {
+
+#define MARIA_DECLARE_PLUGIN__(NAME, VERSION, PSIZE, DECLS) \
+MYSQL_PLUGIN_EXPORT int _maria_plugin_interface_version_= MARIA_PLUGIN_INTERFACE_VERSION; \
+MYSQL_PLUGIN_EXPORT int _maria_sizeof_struct_st_plugin_= sizeof(struct st_maria_plugin); \
+MYSQL_PLUGIN_EXPORT struct st_maria_plugin _maria_plugin_declarations_[]= {
+
#endif
#define mysql_declare_plugin(NAME) \
@@ -119,7 +144,14 @@ __MYSQL_DECLARE_PLUGIN(NAME, \
builtin_ ## NAME ## _sizeof_struct_st_plugin, \
builtin_ ## NAME ## _plugin)
+#define maria_declare_plugin(NAME) \
+MARIA_DECLARE_PLUGIN__(NAME, \
+ builtin_maria_ ## NAME ## _plugin_interface_version, \
+ builtin_maria_ ## NAME ## _sizeof_struct_st_plugin, \
+ builtin_maria_ ## NAME ## _plugin)
+
#define mysql_declare_plugin_end ,{0,0,0,0,0,0,0,0,0,0,0,0}}
+#define maria_declare_plugin_end ,{0,0,0,0,0,0,0,0,0,0,0,0,0}}
/*
declarations for SHOW STATUS support in plugins
@@ -239,7 +271,7 @@ typedef void (*mysql_var_update_func)(MYSQL_THD thd,
#define DECLARE_MYSQL_SYSVAR_BASIC(name, type) struct { \
MYSQL_PLUGIN_VAR_HEADER; \
type *value; \
- const type def_val; \
+ const type def_val; \
} MYSQL_SYSVAR_NAME(name)
#define DECLARE_MYSQL_SYSVAR_SIMPLE(name, type) struct { \
@@ -276,7 +308,7 @@ typedef void (*mysql_var_update_func)(MYSQL_THD thd,
#define DECLARE_MYSQL_THDVAR_TYPELIB(name, type) struct { \
MYSQL_PLUGIN_VAR_HEADER; \
int offset; \
- type def_val; \
+ const type def_val; \
DECLARE_THDVAR_FUNC(type); \
TYPELIB *typelib; \
} MYSQL_SYSVAR_NAME(name)
@@ -416,6 +448,30 @@ struct st_mysql_plugin
void * __reserved1; /* reserved for dependency checking */
};
+/*
+ MariaDB extension for plugins declaration structure.
+
+ It also copy current MySQL plugin fields to have more independency
+ in plugins extension
+*/
+
+struct st_maria_plugin
+{
+ int type; /* the plugin type (a MYSQL_XXX_PLUGIN value) */
+ void *info; /* pointer to type-specific plugin descriptor */
+ const char *name; /* plugin name */
+ const char *author; /* plugin author (for SHOW PLUGINS) */
+ const char *descr; /* general descriptive text (for SHOW PLUGINS ) */
+ int license; /* the plugin license (PLUGIN_LICENSE_XXX) */
+ int (*init)(void *); /* the function to invoke when plugin is loaded */
+ int (*deinit)(void *);/* the function to invoke when plugin is unloaded */
+ unsigned int version; /* plugin version (for SHOW PLUGINS) */
+ struct st_mysql_show_var *status_vars;
+ struct st_mysql_sys_var **system_vars;
+ const char *version_info; /* plugin version string */
+ unsigned int maturity; /* MariaDB_PLUGIN_MATURITY_XXX */
+};
+
/*************************************************************************
API for Full-text parser plugin. (MYSQL_FTPARSER_PLUGIN)
*/
@@ -526,7 +582,6 @@ int thd_in_lock_tables(const MYSQL_THD thd);
int thd_tablespace_op(const MYSQL_THD thd);
long long thd_test_options(const MYSQL_THD thd, long long test_options);
int thd_sql_command(const MYSQL_THD thd);
-const char *thd_proc_info(MYSQL_THD thd, const char *info);
void **thd_ha_data(const MYSQL_THD thd, const struct handlerton *hton);
void thd_storage_lock_wait(MYSQL_THD thd, long long value);
int thd_tx_isolation(const MYSQL_THD thd);
@@ -535,6 +590,10 @@ char *thd_security_context(MYSQL_THD thd, char *buffer, unsigned int length,
/* Increments the row counter, see THD::row_count */
void thd_inc_row_count(MYSQL_THD thd);
+#define thd_proc_info(thd, msg) set_thd_proc_info(thd, msg, __func__, __FILE__, __LINE__)
+const char *set_thd_proc_info(MYSQL_THD, const char * info, const char *func,
+ const char *file, const unsigned int line);
+
/**
Create a temporary file.
diff --git a/include/mysql/plugin_auth.h b/include/mysql/plugin_auth.h
new file mode 100644
index 00000000000..2b84a6c73af
--- /dev/null
+++ b/include/mysql/plugin_auth.h
@@ -0,0 +1,83 @@
+#ifndef MYSQL_PLUGIN_AUTH_INCLUDED
+/* Copyright (C) 2010 Sergei Golubchik and Monty Program Ab
+
+ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/**
+ @file
+
+ Authentication Plugin API.
+
+ This file defines the API for server authentication plugins.
+*/
+
+#define MYSQL_PLUGIN_AUTH_INCLUDED
+
+#include <mysql/plugin.h>
+
+#define MYSQL_AUTHENTICATION_INTERFACE_VERSION 0x0100
+
+#include <mysql/plugin_auth_common.h>
+
+/**
+ Provides server plugin access to authentication information
+*/
+typedef struct st_mysql_server_auth_info
+{
+ /**
+ User name as sent by the client and shown in USER().
+ NULL if the client packet with the user name was not received yet.
+ */
+ const char *user_name;
+ /**
+ A corresponding column value from the mysql.user table for the
+ matching account name
+ */
+ const char *auth_string;
+
+ /**
+ Matching account name as found in the mysql.user table.
+ A plugin can override it with another name that will be
+ used by MySQL for authorization, and shown in CURRENT_USER()
+ */
+ char authenticated_as[MYSQL_USERNAME_LENGTH+1];
+ /**
+ This only affects the "Authentication failed. Password used: %s"
+ error message. If set, %s will be YES, otherwise - NO.
+ Set it as appropriate or ignore at will.
+ */
+ int password_used;
+} MYSQL_SERVER_AUTH_INFO;
+
+/**
+ Server authentication plugin descriptor
+*/
+struct st_mysql_auth
+{
+ int interface_version; /**< version plugin uses */
+ /**
+ A plugin that a client must use for authentication with this server
+ plugin. Can be NULL to mean "any plugin".
+ */
+ const char *client_auth_plugin;
+ /**
+ Function provided by the plugin which should perform authentication (using
+ the vio functions if necessary) and return 0 if successful. The plugin can
+ also fill the info.authenticated_as field if a different username should be
+ used for authorization.
+ */
+ int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info);
+};
+#endif
+
diff --git a/include/mysql/plugin_auth.h.pp b/include/mysql/plugin_auth.h.pp
new file mode 100644
index 00000000000..b0d5daf4c64
--- /dev/null
+++ b/include/mysql/plugin_auth.h.pp
@@ -0,0 +1,209 @@
+#include <mysql/plugin.h>
+#include <mysql/services.h>
+#include <mysql/service_my_snprintf.h>
+extern struct my_snprintf_service_st {
+ size_t (*my_snprintf_type)(char*, size_t, const char*, ...);
+ size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list);
+} *my_snprintf_service;
+size_t my_snprintf(char* to, size_t n, const char* fmt, ...);
+size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap);
+#include <mysql/service_thd_alloc.h>
+struct st_mysql_lex_string
+{
+ char *str;
+ size_t length;
+};
+typedef struct st_mysql_lex_string MYSQL_LEX_STRING;
+extern struct thd_alloc_service_st {
+ void *(*thd_alloc_func)(void*, unsigned int);
+ void *(*thd_calloc_func)(void*, unsigned int);
+ char *(*thd_strdup_func)(void*, const char *);
+ char *(*thd_strmake_func)(void*, const char *, unsigned int);
+ void *(*thd_memdup_func)(void*, const void*, unsigned int);
+ MYSQL_LEX_STRING *(*thd_make_lex_string_func)(void*, MYSQL_LEX_STRING *,
+ const char *, unsigned int, int);
+} *thd_alloc_service;
+void *thd_alloc(void* thd, unsigned int size);
+void *thd_calloc(void* thd, unsigned int size);
+char *thd_strdup(void* thd, const char *str);
+char *thd_strmake(void* thd, const char *str, unsigned int size);
+void *thd_memdup(void* thd, const void* str, unsigned int size);
+MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str,
+ const char *str, unsigned int size,
+ int allocate_lex_string);
+struct st_mysql_xid {
+ long formatID;
+ long gtrid_length;
+ long bqual_length;
+ char data[128];
+};
+typedef struct st_mysql_xid MYSQL_XID;
+enum enum_mysql_show_type
+{
+ SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG,
+ SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
+ SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE,
+ SHOW_always_last
+};
+struct st_mysql_show_var {
+ const char *name;
+ char *value;
+ enum enum_mysql_show_type type;
+};
+typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *);
+struct st_mysql_sys_var;
+struct st_mysql_value;
+typedef int (*mysql_var_check_func)(void* thd,
+ struct st_mysql_sys_var *var,
+ void *save, struct st_mysql_value *value);
+typedef void (*mysql_var_update_func)(void* thd,
+ struct st_mysql_sys_var *var,
+ void *var_ptr, const void *save);
+struct st_mysql_plugin
+{
+ int type;
+ void *info;
+ const char *name;
+ const char *author;
+ const char *descr;
+ int license;
+ int (*init)(void *);
+ int (*deinit)(void *);
+ unsigned int version;
+ struct st_mysql_show_var *status_vars;
+ struct st_mysql_sys_var **system_vars;
+ void * __reserved1;
+};
+struct st_maria_plugin
+{
+ int type;
+ void *info;
+ const char *name;
+ const char *author;
+ const char *descr;
+ int license;
+ int (*init)(void *);
+ int (*deinit)(void *);
+ unsigned int version;
+ struct st_mysql_show_var *status_vars;
+ struct st_mysql_sys_var **system_vars;
+ const char *version_info;
+ unsigned int maturity;
+};
+enum enum_ftparser_mode
+{
+ MYSQL_FTPARSER_SIMPLE_MODE= 0,
+ MYSQL_FTPARSER_WITH_STOPWORDS= 1,
+ MYSQL_FTPARSER_FULL_BOOLEAN_INFO= 2
+};
+enum enum_ft_token_type
+{
+ FT_TOKEN_EOF= 0,
+ FT_TOKEN_WORD= 1,
+ FT_TOKEN_LEFT_PAREN= 2,
+ FT_TOKEN_RIGHT_PAREN= 3,
+ FT_TOKEN_STOPWORD= 4
+};
+typedef struct st_mysql_ftparser_boolean_info
+{
+ enum enum_ft_token_type type;
+ int yesno;
+ int weight_adjust;
+ char wasign;
+ char trunc;
+ char prev;
+ char *quot;
+} MYSQL_FTPARSER_BOOLEAN_INFO;
+typedef int mysql_ft_size_t;
+typedef struct st_mysql_ftparser_param
+{
+ int (*mysql_parse)(struct st_mysql_ftparser_param *,
+ const unsigned char *doc, mysql_ft_size_t doc_len);
+ int (*mysql_add_word)(struct st_mysql_ftparser_param *,
+ const unsigned char *word, mysql_ft_size_t word_len,
+ MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info);
+ void *ftparser_state;
+ void *mysql_ftparam;
+ const struct charset_info_st *cs;
+ const unsigned char *doc;
+ mysql_ft_size_t length;
+ unsigned int flags;
+ enum enum_ftparser_mode mode;
+} MYSQL_FTPARSER_PARAM;
+struct st_mysql_ftparser
+{
+ int interface_version;
+ int (*parse)(MYSQL_FTPARSER_PARAM *param);
+ int (*init)(MYSQL_FTPARSER_PARAM *param);
+ int (*deinit)(MYSQL_FTPARSER_PARAM *param);
+};
+struct st_mysql_storage_engine
+{
+ int interface_version;
+};
+struct handlerton;
+struct st_mysql_daemon
+{
+ int interface_version;
+};
+struct st_mysql_information_schema
+{
+ int interface_version;
+};
+struct st_mysql_value
+{
+ int (*value_type)(struct st_mysql_value *);
+ const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
+ int (*val_real)(struct st_mysql_value *, double *realbuf);
+ int (*val_int)(struct st_mysql_value *, long long *intbuf);
+};
+int thd_in_lock_tables(const void* thd);
+int thd_tablespace_op(const void* thd);
+long long thd_test_options(const void* thd, long long test_options);
+int thd_sql_command(const void* thd);
+void **thd_ha_data(const void* thd, const struct handlerton *hton);
+int thd_tx_isolation(const void* thd);
+char *thd_security_context(void* thd, char *buffer, unsigned int length,
+ unsigned int max_query_len);
+void thd_inc_row_count(void* thd);
+const char *set_thd_proc_info(void*, const char * info, const char *func,
+ const char *file, const unsigned int line);
+int mysql_tmpfile(const char *prefix);
+int thd_killed(const void* thd);
+unsigned long thd_get_thread_id(const void* thd);
+void thd_get_xid(const void* thd, MYSQL_XID *xid);
+void mysql_query_cache_invalidate4(void* thd,
+ const char *key, unsigned int key_length,
+ int using_trx);
+void *thd_get_ha_data(const void* thd, const struct handlerton *hton);
+void thd_set_ha_data(void* thd, const struct handlerton *hton,
+ const void *ha_data);
+#include <mysql/plugin_auth_common.h>
+typedef struct st_plugin_vio_info
+{
+ enum { MYSQL_VIO_INVALID, MYSQL_VIO_TCP, MYSQL_VIO_SOCKET,
+ MYSQL_VIO_PIPE, MYSQL_VIO_MEMORY } protocol;
+ int socket;
+} MYSQL_PLUGIN_VIO_INFO;
+typedef struct st_plugin_vio
+{
+ int (*read_packet)(struct st_plugin_vio *vio,
+ unsigned char **buf);
+ int (*write_packet)(struct st_plugin_vio *vio,
+ const unsigned char *packet,
+ int packet_len);
+ void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info);
+} MYSQL_PLUGIN_VIO;
+typedef struct st_mysql_server_auth_info
+{
+ const char *user_name;
+ const char *auth_string;
+ char authenticated_as[48 +1];
+ int password_used;
+} MYSQL_SERVER_AUTH_INFO;
+struct st_mysql_auth
+{
+ int interface_version;
+ const char *client_auth_plugin;
+ int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info);
+};
diff --git a/include/mysql/plugin_auth_common.h b/include/mysql/plugin_auth_common.h
new file mode 100644
index 00000000000..b71591d6eb6
--- /dev/null
+++ b/include/mysql/plugin_auth_common.h
@@ -0,0 +1,105 @@
+#ifndef MYSQL_PLUGIN_AUTH_COMMON_INCLUDED
+/* Copyright (C) 2010 Sergei Golubchik and Monty Program Ab
+
+ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/**
+ @file
+
+ This file defines constants and data structures that are the same for
+ both client- and server-side authentication plugins.
+*/
+#define MYSQL_PLUGIN_AUTH_COMMON_INCLUDED
+
+/** the max allowed length for a user name */
+#define MYSQL_USERNAME_LENGTH 48
+
+/**
+ return values of the plugin authenticate_user() method.
+*/
+
+/**
+ Authentication failed. Additionally, all other CR_xxx values
+ (libmysql error code) can be used too.
+
+ The client plugin may set the error code and the error message directly
+ in the MYSQL structure and return CR_ERROR. If a CR_xxx specific error
+ code was returned, an error message in the MYSQL structure will be
+ overwritten. If CR_ERROR is returned without setting the error in MYSQL,
+ CR_UNKNOWN_ERROR will be user.
+*/
+#define CR_ERROR 0
+/**
+ Authentication (client part) was successful. It does not mean that the
+ authentication as a whole was successful, usually it only means
+ that the client was able to send the user name and the password to the
+ server. If CR_OK is returned, the libmysql reads the next packet expecting
+ it to be one of OK, ERROR, or CHANGE_PLUGIN packets.
+*/
+#define CR_OK -1
+/**
+ Authentication was successful.
+ It means that the client has done its part successfully and also that
+ a plugin has read the last packet (one of OK, ERROR, CHANGE_PLUGIN).
+ In this case, libmysql will not read a packet from the server,
+ but it will use the data at mysql->net.read_pos.
+
+ A plugin may return this value if the number of roundtrips in the
+ authentication protocol is not known in advance, and the client plugin
+ needs to read one packet more to determine if the authentication is finished
+ or not.
+*/
+#define CR_OK_HANDSHAKE_COMPLETE -2
+
+typedef struct st_plugin_vio_info
+{
+ enum { MYSQL_VIO_INVALID, MYSQL_VIO_TCP, MYSQL_VIO_SOCKET,
+ MYSQL_VIO_PIPE, MYSQL_VIO_MEMORY } protocol;
+ int socket; /**< it's set, if the protocol is SOCKET or TCP */
+#ifdef _WIN32
+ HANDLE handle; /**< it's set, if the protocol is PIPE or MEMORY */
+#endif
+} MYSQL_PLUGIN_VIO_INFO;
+
+/**
+ Provides plugin access to communication channel
+*/
+typedef struct st_plugin_vio
+{
+ /**
+ Plugin provides a pointer reference and this function sets it to the
+ contents of any incoming packet. Returns the packet length, or -1 if
+ the plugin should terminate.
+ */
+ int (*read_packet)(struct st_plugin_vio *vio,
+ unsigned char **buf);
+
+ /**
+ Plugin provides a buffer with data and the length and this
+ function sends it as a packet. Returns 0 on success, 1 on failure.
+ */
+ int (*write_packet)(struct st_plugin_vio *vio,
+ const unsigned char *packet,
+ int packet_len);
+
+ /**
+ Fills in a st_plugin_vio_info structure, providing the information
+ about the connection.
+ */
+ void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info);
+
+} MYSQL_PLUGIN_VIO;
+
+#endif
+
diff --git a/include/mysql/service_my_snprintf.h b/include/mysql/service_my_snprintf.h
index f6b4aa39dc5..4395ea17ab7 100644
--- a/include/mysql/service_my_snprintf.h
+++ b/include/mysql/service_my_snprintf.h
@@ -54,7 +54,7 @@
Supported formats are 's' (null pointer is accepted, printed as
"(null)"), 'b' (extension, see below), 'c', 'd', 'i', 'u', 'x', 'o',
- 'X', 'p' (works as 0x%x).
+ 'X', 'p' (works as 0x%x), 'f', 'g'.
Standard syntax for positional arguments $n is supported.
diff --git a/include/mysql_com.h b/include/mysql_com.h
index 90fe4ac1995..19888a492ed 100644
--- a/include/mysql_com.h
+++ b/include/mysql_com.h
@@ -29,8 +29,13 @@
#define MYSQL_AUTODETECT_CHARSET_NAME "auto"
+#define MYSQL50_TABLE_NAME_PREFIX "#mysql50#"
+#define MYSQL50_TABLE_NAME_PREFIX_LENGTH (sizeof(MYSQL50_TABLE_NAME_PREFIX)-1)
+#define SAFE_NAME_LEN (NAME_LEN + MYSQL50_TABLE_NAME_PREFIX_LENGTH)
+
#define SERVER_VERSION_LENGTH 60
#define SQLSTATE_LENGTH 5
+#define LIST_PROCESS_HOST_LEN 64
/*
Maximum length of comments
@@ -77,7 +82,8 @@ enum enum_server_command
COM_END
};
-
+/* sql type stored in .frm files for virtual fields */
+#define MYSQL_TYPE_VIRTUAL 245
/*
Length of random string sent by server on handshake; this is also length of
obfuscated password, recieved from client
@@ -125,6 +131,8 @@ enum enum_server_command
thread */
#define REFRESH_MASTER 128 /* Remove all bin logs in the index
and truncate the index */
+
+/* The following can't be set with mysql_refresh() */
#define REFRESH_ERROR_LOG 256 /* Rotate only the erorr log */
#define REFRESH_ENGINE_LOG 512 /* Flush all storage engine logs */
#define REFRESH_BINARY_LOG 1024 /* Flush the binary log */
@@ -132,7 +140,6 @@ enum enum_server_command
#define REFRESH_GENERAL_LOG 4096 /* Flush the general log */
#define REFRESH_SLOW_LOG 8192 /* Flush the slow query log */
-/* The following can't be set with mysql_refresh() */
#define REFRESH_READ_LOCK 16384 /* Lock tables for read */
#define REFRESH_FAST 32768 /* Intern flag */
@@ -142,6 +149,11 @@ enum enum_server_command
#define REFRESH_DES_KEY_FILE 0x40000L
#define REFRESH_USER_RESOURCES 0x80000L
+#define REFRESH_TABLE_STATS (1L << 20) /* Refresh table stats hash table */
+#define REFRESH_INDEX_STATS (1L << 21) /* Refresh index stats hash table */
+#define REFRESH_USER_STATS (1L << 22) /* Refresh user stats hash table */
+#define REFRESH_CLIENT_STATS (1L << 23) /* Refresh client stats hash table */
+
#define CLIENT_LONG_PASSWORD 1 /* new more secure passwords */
#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
#define CLIENT_LONG_FLAG 4 /* Get all column flags */
@@ -162,9 +174,17 @@ enum enum_server_command
#define CLIENT_MULTI_RESULTS (1UL << 17) /* Enable/disable multi-results */
#define CLIENT_PS_MULTI_RESULTS (1UL << 18) /* Multi-results in PS-protocol */
+#define CLIENT_PLUGIN_AUTH (1UL << 19) /* Client supports plugin authentication */
+
#define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30)
#define CLIENT_REMEMBER_OPTIONS (1UL << 31)
+#ifdef HAVE_COMPRESS
+#define CAN_CLIENT_COMPRESS CLIENT_COMPRESS
+#else
+#define CAN_CLIENT_COMPRESS 0
+#endif
+
/* Gather all possible capabilites (flags) supported by the server */
#define CLIENT_ALL_FLAGS (CLIENT_LONG_PASSWORD | \
CLIENT_FOUND_ROWS | \
@@ -186,7 +206,8 @@ enum enum_server_command
CLIENT_MULTI_RESULTS | \
CLIENT_PS_MULTI_RESULTS | \
CLIENT_SSL_VERIFY_SERVER_CERT | \
- CLIENT_REMEMBER_OPTIONS)
+ CLIENT_REMEMBER_OPTIONS | \
+ CLIENT_PLUGIN_AUTH)
/*
Switch off the flags that are optional and depending on build flags
@@ -285,8 +306,8 @@ typedef struct st_net {
unsigned int *return_status;
unsigned char reading_or_writing;
char save_char;
- my_bool unused1; /* Please remove with the next incompatible ABI change. */
- my_bool unused2; /* Please remove with the next incompatible ABI change */
+ char net_skip_rest_factor;
+ my_bool unused1; /* Please remove with the next incompatible ABI change */
my_bool compress;
my_bool unused3; /* Please remove with the next incompatible ABI change. */
/*
@@ -307,16 +328,6 @@ typedef struct st_net {
/** Client library sqlstate buffer. Set along with the error message. */
char sqlstate[SQLSTATE_LENGTH+1];
void *extension;
-#if defined(MYSQL_SERVER) && !defined(EMBEDDED_LIBRARY)
- /*
- Controls whether a big packet should be skipped.
-
- Initially set to FALSE by default. Unauthenticated sessions must have
- this set to FALSE so that the server can't be tricked to read packets
- indefinitely.
- */
- my_bool skip_big_packet;
-#endif
} NET;
@@ -452,11 +463,7 @@ void my_net_set_read_timeout(NET *net, uint timeout);
struct sockaddr;
int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen,
unsigned int timeout);
-
-struct rand_struct {
- unsigned long seed1,seed2,max_value;
- double max_value_dbl;
-};
+struct my_rnd_struct;
#ifdef __cplusplus
}
@@ -464,8 +471,13 @@ struct rand_struct {
/* The following is for user defined functions */
-enum Item_result {STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT,
- DECIMAL_RESULT};
+enum Item_result
+{
+ STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT, DECIMAL_RESULT
+#ifdef MYSQL_SERVER
+ ,IMPOSSIBLE_RESULT /* Yes, we know this is ugly, don't tell us */
+#endif
+};
typedef struct st_udf_args
{
@@ -510,22 +522,20 @@ extern "C" {
implemented in sql/password.c
*/
-void randominit(struct rand_struct *, unsigned long seed1,
- unsigned long seed2);
-double my_rnd(struct rand_struct *);
-void create_random_string(char *to, unsigned int length, struct rand_struct *rand_st);
+void create_random_string(char *to, unsigned int length,
+ struct my_rnd_struct *rand_st);
void hash_password(unsigned long *to, const char *password, unsigned int password_len);
void make_scrambled_password_323(char *to, const char *password);
void scramble_323(char *to, const char *message, const char *password);
-my_bool check_scramble_323(const char *, const char *message,
+my_bool check_scramble_323(const unsigned char *reply, const char *message,
unsigned long *salt);
void get_salt_from_password_323(unsigned long *res, const char *password);
void make_password_from_salt_323(char *to, const unsigned long *salt);
void make_scrambled_password(char *to, const char *password);
void scramble(char *to, const char *message, const char *password);
-my_bool check_scramble(const char *reply, const char *message,
+my_bool check_scramble(const unsigned char *reply, const char *message,
const unsigned char *hash_stage2);
void get_salt_from_password(unsigned char *res, const char *password);
void make_password_from_salt(char *to, const unsigned char *hash_stage2);
diff --git a/include/mysql_version.h.in b/include/mysql_version.h.in
index 04a43f2c968..c37e99d7a8c 100644
--- a/include/mysql_version.h.in
+++ b/include/mysql_version.h.in
@@ -11,6 +11,7 @@
#define PROTOCOL_VERSION @PROTOCOL_VERSION@
#define MYSQL_SERVER_VERSION "@VERSION@"
#define MYSQL_BASE_VERSION "mysqld-@MYSQL_BASE_VERSION@"
+#define MARIADB_BASE_VERSION "mariadb-@MYSQL_BASE_VERSION@"
#define MYSQL_SERVER_SUFFIX_DEF "@MYSQL_SERVER_SUFFIX@"
#define FRM_VER @DOT_FRM_VERSION@
#define MYSQL_VERSION_ID @MYSQL_VERSION_ID@
diff --git a/include/mysys_err.h b/include/mysys_err.h
index 4067a3cfbd1..8b6a12ba36e 100644
--- a/include/mysys_err.h
+++ b/include/mysys_err.h
@@ -65,7 +65,10 @@ extern const char *globerrs[]; /* my_error_messages is here */
#define EE_FILE_NOT_CLOSED 30
#define EE_CHANGE_OWNERSHIP 31
#define EE_CHANGE_PERMISSIONS 32
-#define EE_ERROR_LAST 32 /* Copy last error nr */
+#define EE_CANT_CHMOD 33
+#define EE_CANT_SEEK 34
+#define EE_CANT_COPY_OWNERSHIP 35
+#define EE_ERROR_LAST 35 /* Copy last error nr */
/* Add error numbers before EE_ERROR_LAST and change it accordingly. */
/* exit codes for all MySQL programs */
diff --git a/include/queues.h b/include/queues.h
index 07962f09201..4fef72b149c 100644
--- a/include/queues.h
+++ b/include/queues.h
@@ -1,23 +1,31 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2010 Monty Program Ab
+ All Rights reserved
- 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.
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the following disclaimer
+ in the documentation and/or other materials provided with the
+ distribution.
- 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+*/
/*
Code for generell handling of priority Queues.
Implemention of queues from "Algoritms in C" by Robert Sedgewick.
- Copyright Monty Program KB.
- By monty.
*/
#ifndef _queues_h
@@ -34,38 +42,43 @@ typedef struct st_queue {
void *first_cmp_arg;
uint elements;
uint max_elements;
- uint offset_to_key; /* compare is done on element+offset */
+ uint offset_to_key; /* compare is done on element+offset */
+ uint offset_to_queue_pos; /* If we want to store position in element */
+ uint auto_extent;
int max_at_top; /* Normally 1, set to -1 if queue_top gives max */
int (*compare)(void *, uchar *,uchar *);
- uint auto_extent;
} QUEUE;
+#define queue_first_element(queue) 1
+#define queue_last_element(queue) (queue)->elements
#define queue_top(queue) ((queue)->root[1])
-#define queue_element(queue,index) ((queue)->root[index+1])
+#define queue_element(queue,index) ((queue)->root[index])
#define queue_end(queue) ((queue)->root[(queue)->elements])
-#define queue_replaced(queue) _downheap(queue,1)
+#define queue_replace_top(queue) _downheap(queue, 1, (queue)->root[1])
#define queue_set_cmp_arg(queue, set_arg) (queue)->first_cmp_arg= set_arg
#define queue_set_max_at_top(queue, set_arg) \
(queue)->max_at_top= set_arg ? -1 : 1
+#define queue_remove_top(queue_arg) queue_remove((queue_arg), queue_first_element(queue_arg))
typedef int (*queue_compare)(void *,uchar *, uchar *);
int init_queue(QUEUE *queue,uint max_elements,uint offset_to_key,
pbool max_at_top, queue_compare compare,
- void *first_cmp_arg);
-int init_queue_ex(QUEUE *queue,uint max_elements,uint offset_to_key,
- pbool max_at_top, queue_compare compare,
- void *first_cmp_arg, uint auto_extent);
+ void *first_cmp_arg, uint offset_to_queue_pos,
+ uint auto_extent);
int reinit_queue(QUEUE *queue,uint max_elements,uint offset_to_key,
pbool max_at_top, queue_compare compare,
- void *first_cmp_arg);
+ void *first_cmp_arg, uint offset_to_queue_pos,
+ uint auto_extent);
int resize_queue(QUEUE *queue, uint max_elements);
void delete_queue(QUEUE *queue);
void queue_insert(QUEUE *queue,uchar *element);
int queue_insert_safe(QUEUE *queue, uchar *element);
uchar *queue_remove(QUEUE *queue,uint idx);
+void queue_replace(QUEUE *queue,uint idx);
+
#define queue_remove_all(queue) { (queue)->elements= 0; }
#define queue_is_full(queue) (queue->elements == queue->max_elements)
-void _downheap(QUEUE *queue,uint idx);
+void _downheap(QUEUE *queue, uint idx, uchar *element);
void queue_fix(QUEUE *queue);
#define is_queue_inited(queue) ((queue)->root != 0)
diff --git a/include/sql_common.h b/include/sql_common.h
index 5fd8778d62b..2fc66a559ba 100644
--- a/include/sql_common.h
+++ b/include/sql_common.h
@@ -1,29 +1,72 @@
#ifndef SQL_COMMON_INCLUDED
#define SQL_COMMON_INCLUDED
-
/* Copyright (C) 2003-2004, 2006 MySQL AB
-
+
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <mysql.h>
extern const char *unknown_sqlstate;
extern const char *cant_connect_sqlstate;
extern const char *not_error_sqlstate;
-#ifdef __cplusplus
-extern "C" {
+struct st_mysql_options_extention {
+ char *plugin_dir;
+ char *default_auth;
+};
+
+typedef struct st_mysql_methods
+{
+ my_bool (*read_query_result)(MYSQL *mysql);
+ my_bool (*advanced_command)(MYSQL *mysql,
+ enum enum_server_command command,
+ const unsigned char *header,
+ unsigned long header_length,
+ const unsigned char *arg,
+ unsigned long arg_length,
+ my_bool skip_check,
+ MYSQL_STMT *stmt);
+ MYSQL_DATA *(*read_rows)(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
+ unsigned int fields);
+ MYSQL_RES * (*use_result)(MYSQL *mysql);
+ void (*fetch_lengths)(unsigned long *to,
+ MYSQL_ROW column, unsigned int field_count);
+ void (*flush_use_result)(MYSQL *mysql, my_bool flush_all_results);
+ int (*read_change_user_result)(MYSQL *mysql);
+#if !defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY)
+ MYSQL_FIELD * (*list_fields)(MYSQL *mysql);
+ my_bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
+ int (*stmt_execute)(MYSQL_STMT *stmt);
+ int (*read_binary_rows)(MYSQL_STMT *stmt);
+ int (*unbuffered_fetch)(MYSQL *mysql, char **row);
+ void (*free_embedded_thd)(MYSQL *mysql);
+ const char *(*read_statistics)(MYSQL *mysql);
+ my_bool (*next_result)(MYSQL *mysql);
+ int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
#endif
+} MYSQL_METHODS;
+
+#define simple_command(mysql, command, arg, length, skip_check) \
+ (*(mysql)->methods->advanced_command)(mysql, command, 0, \
+ 0, arg, length, skip_check, NULL)
+#define stmt_command(mysql, command, arg, length, stmt) \
+ (*(mysql)->methods->advanced_command)(mysql, command, 0, \
+ 0, arg, length, 1, stmt)
extern CHARSET_INFO *default_client_charset_info;
MYSQL_FIELD *unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
@@ -45,6 +88,19 @@ void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net);
void set_stmt_error(MYSQL_STMT *stmt, int errcode, const char *sqlstate,
const char *err);
void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate);
+void set_mysql_extended_error(MYSQL *mysql, int errcode, const char *sqlstate,
+ const char *format, ...);
+
+/* client side of the pluggable authentication */
+struct st_plugin_vio_info;
+void mpvio_info(Vio *vio, struct st_plugin_vio_info *info);
+int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
+ const char *data_plugin, const char *db);
+int mysql_client_plugin_init();
+void mysql_client_plugin_deinit();
+struct st_mysql_client_plugin;
+extern struct st_mysql_client_plugin *mysql_client_builtins[];
+
#ifdef __cplusplus
}
#endif
diff --git a/include/thr_alarm.h b/include/thr_alarm.h
index 8d7f5bcdee0..2ff975607cd 100644
--- a/include/thr_alarm.h
+++ b/include/thr_alarm.h
@@ -34,7 +34,7 @@ extern "C" {
typedef struct st_alarm_info
{
- ulong next_alarm_time;
+ time_t next_alarm_time;
uint active_alarms;
uint max_used_alarms;
} ALARM_INFO;
@@ -78,10 +78,11 @@ typedef int thr_alarm_entry;
typedef thr_alarm_entry* thr_alarm_t;
typedef struct st_alarm {
- ulong expire_time;
+ time_t expire_time;
thr_alarm_entry alarmed; /* set when alarm is due */
pthread_t thread;
my_thread_id thread_id;
+ uint index_in_queue;
my_bool malloced;
} ALARM;
diff --git a/include/thr_lock.h b/include/thr_lock.h
index 91473737be3..562ed30afd7 100644
--- a/include/thr_lock.h
+++ b/include/thr_lock.h
@@ -76,6 +76,12 @@ enum enum_thr_lock_result { THR_LOCK_SUCCESS= 0, THR_LOCK_ABORTED= 1,
THR_LOCK_WAIT_TIMEOUT= 2, THR_LOCK_DEADLOCK= 3 };
+/* Priority for locks */
+#define THR_LOCK_LATE_PRIV 1 /* For locks to be merged with org lock */
+#define THR_LOCK_MERGE_PRIV 2 /* For merge tables */
+
+#define THR_UNLOCK_UPDATE_STATUS 1
+
extern ulong max_write_lock_count;
extern my_bool thr_lock_inited;
extern enum thr_lock_type thr_upgraded_concurrent_insert_lock;
@@ -97,10 +103,11 @@ typedef struct st_thr_lock_data {
struct st_thr_lock_data *next,**prev;
struct st_thr_lock *lock;
mysql_cond_t *cond;
- enum thr_lock_type type;
void *status_param; /* Param to status functions */
void *debug_print_param;
struct PSI_table *m_psi;
+ enum thr_lock_type type;
+ uint priority;
} THR_LOCK_DATA;
struct st_lock_list {
@@ -117,11 +124,14 @@ typedef struct st_thr_lock {
/* write_lock_count is incremented for write locks and reset on read locks */
ulong write_lock_count;
uint read_no_write_count;
- void (*get_status)(void*, int); /* When one gets a lock */
+ void (*get_status)(void*, my_bool); /* When one gets a lock */
void (*copy_status)(void*,void*);
void (*update_status)(void*); /* Before release of write */
- void (*restore_status)(void*); /* Before release of read */
+ void (*restore_status)(void*); /* Before release of read */
+ my_bool (*start_trans)(void*); /* When all locks are taken */
my_bool (*check_status)(void *);
+ void (*fix_status)(void *, void *);/* For thr_merge_locks() */
+ my_bool allow_multiple_concurrent_insert;
} THR_LOCK;
@@ -134,17 +144,14 @@ void thr_lock_init(THR_LOCK *lock);
void thr_lock_delete(THR_LOCK *lock);
void thr_lock_data_init(THR_LOCK *lock,THR_LOCK_DATA *data,
void *status_param);
-enum enum_thr_lock_result thr_lock(THR_LOCK_DATA *data,
- THR_LOCK_INFO *owner,
- enum thr_lock_type lock_type,
- ulong lock_wait_timeout);
-void thr_unlock(THR_LOCK_DATA *data);
+void thr_unlock(THR_LOCK_DATA *data, uint unlock_flags);
enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data,
uint count, THR_LOCK_INFO *owner,
ulong lock_wait_timeout);
-void thr_multi_unlock(THR_LOCK_DATA **data,uint count);
-void
-thr_lock_merge_status(THR_LOCK_DATA **data, uint count);
+void thr_multi_unlock(THR_LOCK_DATA **data,uint count, uint unlock_flags);
+#error keep both thr_merge* or what?
+void thr_lock_merge_status(THR_LOCK_DATA **data, uint count);
+void thr_merge_locks(THR_LOCK_DATA **data, uint org_count, uint new_count);
void thr_abort_locks(THR_LOCK *lock, my_bool upgrade_lock);
my_bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread);
void thr_print_locks(void); /* For debugging */
@@ -155,8 +162,6 @@ void thr_downgrade_write_lock(THR_LOCK_DATA *data,
enum thr_lock_type new_lock_type);
my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data,
ulong lock_wait_timeout);
-void thr_set_lock_wait_callback(void (*before_wait)(void),
- void (*after_wait)(void));
#ifdef __cplusplus
}
#endif
diff --git a/include/typelib.h b/include/typelib.h
index 3badb14c96e..2879c745a3f 100644
--- a/include/typelib.h
+++ b/include/typelib.h
@@ -27,8 +27,10 @@ typedef struct st_typelib { /* Different types saved here */
} TYPELIB;
extern my_ulonglong find_typeset(char *x, TYPELIB *typelib,int *error_position);
-extern int find_type_or_exit(const char *x, TYPELIB *typelib,
- const char *option);
+extern int find_type_with_warning(const char *x, TYPELIB *typelib,
+ const char *option);
+extern uint find_type_or_exit(const char *x, TYPELIB *typelib,
+ const char *option);
extern int find_type(char *x, const TYPELIB *typelib, unsigned int full_name);
extern void make_type(char *to,unsigned int nr,TYPELIB *typelib);
extern const char *get_type(TYPELIB *typelib,unsigned int nr);
diff --git a/include/violite.h b/include/violite.h
index f4083216894..896b024c8b7 100644
--- a/include/violite.h
+++ b/include/violite.h
@@ -132,8 +132,8 @@ struct st_VioSSLFd
SSL_CTX *ssl_context;
};
-int sslaccept(struct st_VioSSLFd*, Vio *, long timeout);
-int sslconnect(struct st_VioSSLFd*, Vio *, long timeout);
+int sslaccept(struct st_VioSSLFd*, Vio *, long timeout, char *error_string);
+int sslconnect(struct st_VioSSLFd*, Vio *, long timeout, char *error_string);
struct st_VioSSLFd
*new_VioSSLConnectorFd(const char *key_file, const char *cert_file,
diff --git a/include/waiting_threads.h b/include/waiting_threads.h
new file mode 100644
index 00000000000..1e580529938
--- /dev/null
+++ b/include/waiting_threads.h
@@ -0,0 +1,130 @@
+/* Copyright (C) 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef _waiting_threads_h
+#define _waiting_threads_h
+
+#include <my_global.h>
+#include <my_sys.h>
+
+#include <lf.h>
+
+C_MODE_START
+
+typedef struct st_wt_resource_id WT_RESOURCE_ID;
+typedef struct st_wt_resource WT_RESOURCE;
+
+typedef struct st_wt_resource_type {
+ my_bool (*compare)(const void *a, const void *b);
+ const void *(*make_key)(const WT_RESOURCE_ID *id, uint *len); /* not used */
+} WT_RESOURCE_TYPE;
+
+struct st_wt_resource_id {
+ ulonglong value;
+ const WT_RESOURCE_TYPE *type;
+};
+/* the below differs from sizeof(WT_RESOURCE_ID) by the amount of padding */
+#define sizeof_WT_RESOURCE_ID (sizeof(ulonglong)+sizeof(void*))
+
+#define WT_WAIT_STATS 24
+#define WT_CYCLE_STATS 32
+extern ulonglong wt_wait_table[WT_WAIT_STATS];
+extern uint32 wt_wait_stats[WT_WAIT_STATS+1];
+extern uint32 wt_cycle_stats[2][WT_CYCLE_STATS+1];
+extern uint32 wt_success_stats;
+
+typedef struct st_wt_thd {
+ /*
+ XXX
+ there's no protection (mutex) against concurrent access of the
+ dynarray below. it is assumed that a caller will have it anyway
+ (not to protect this array but to protect its own - caller's -
+ data structures), and we'll get it for free. A caller needs to
+ ensure that a blocker won't release a resource before a blocked
+ thread starts waiting, which is usually done with a mutex.
+
+ If the above assumption is wrong, we'll need to add a mutex here.
+ */
+ DYNAMIC_ARRAY my_resources;
+ /*
+ 'waiting_for' is modified under waiting_for->lock, and only by thd itself
+ 'waiting_for' is read lock-free (using pinning protocol), but a thd object
+ can read its own 'waiting_for' without any locks or tricks.
+ */
+ WT_RESOURCE *waiting_for;
+ LF_PINS *pins;
+
+ /* pointers to values */
+ const ulong *timeout_short;
+ const ulong *deadlock_search_depth_short;
+ const ulong *timeout_long;
+ const ulong *deadlock_search_depth_long;
+
+ /*
+ weight relates to the desirability of a transaction being killed if it's
+ part of a deadlock. In a deadlock situation transactions with lower weights
+ are killed first.
+
+ Examples of using the weight to implement different selection strategies:
+
+ 1. Latest
+ Keep all weights equal.
+ 2. Random
+ Assight weights at random.
+ (variant: modify a weight randomly before every lock request)
+ 3. Youngest
+ Set weight to -NOW()
+ 4. Minimum locks
+ count locks granted in your lock manager, store the value as a weight
+ 5. Minimum work
+ depends on the definition of "work". For example, store the number
+ of rows modifies in this transaction (or a length of REDO log for a
+ transaction) as a weight.
+
+ It is only statistically relevant and is not protected by any locks.
+ */
+ ulong volatile weight;
+ /*
+ 'killed' is indirectly protected by waiting_for->lock because
+ a killed thread needs to clear its 'waiting_for' and thus needs a lock.
+ That is a thread needs an exclusive lock to read 'killed' reliably.
+ But other threads may change 'killed' from 0 to 1, a shared
+ lock is enough for that.
+ */
+ my_bool killed;
+#ifndef DBUG_OFF
+ const char *name;
+#endif
+} WT_THD;
+
+#define WT_TIMEOUT ETIMEDOUT
+#define WT_OK 0
+#define WT_DEADLOCK -1
+#define WT_DEPTH_EXCEEDED -2
+#define WT_FREE_TO_GO -3
+
+void wt_init(void);
+void wt_end(void);
+void wt_thd_lazy_init(WT_THD *, const ulong *, const ulong *, const ulong *, const ulong *);
+void wt_thd_destroy(WT_THD *);
+int wt_thd_will_wait_for(WT_THD *, WT_THD *, const WT_RESOURCE_ID *);
+int wt_thd_cond_timedwait(WT_THD *, pthread_mutex_t *);
+void wt_thd_release(WT_THD *, const WT_RESOURCE_ID *);
+#define wt_thd_release_all(THD) wt_thd_release((THD), 0)
+my_bool wt_resource_id_memcmp(const void *, const void *);
+
+C_MODE_END
+
+#endif
diff --git a/include/wqueue.h b/include/wqueue.h
new file mode 100644
index 00000000000..658f3d66f12
--- /dev/null
+++ b/include/wqueue.h
@@ -0,0 +1,27 @@
+
+#ifndef _wqueue_h
+#define _wqueue_h
+
+#include <my_global.h>
+#include <my_pthread.h>
+
+/* info about requests in a waiting queue */
+typedef struct st_pagecache_wqueue
+{
+ struct st_my_thread_var *last_thread; /* circular list of waiting
+ threads */
+} WQUEUE;
+
+#ifdef THREAD
+void wqueue_link_into_queue(WQUEUE *wqueue, struct st_my_thread_var *thread);
+void wqueue_unlink_from_queue(WQUEUE *wqueue, struct st_my_thread_var *thread);
+void wqueue_add_to_queue(WQUEUE *wqueue, struct st_my_thread_var *thread);
+void wqueue_add_and_wait(WQUEUE *wqueue,
+ struct st_my_thread_var *thread,
+ pthread_mutex_t *lock);
+void wqueue_release_queue(WQUEUE *wqueue);
+void wqueue_release_one_locktype_from_queue(WQUEUE *wqueue);
+
+#endif
+
+#endif