summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BitKeeper/etc/logging_ok2
-rw-r--r--client/mysql.cc7
-rw-r--r--client/mysqltest.c3
-rw-r--r--include/my_global.h5
-rw-r--r--include/my_handler.h13
-rw-r--r--include/myisam.h9
-rw-r--r--include/mysql.h38
-rw-r--r--include/mysql_com.h19
-rw-r--r--include/violite.h2
-rw-r--r--libmysqld/embedded_priv.h8
-rw-r--r--libmysqld/lib_sql.cc600
-rw-r--r--libmysqld/lib_vio.c30
-rw-r--r--libmysqld/libmysqld.c934
-rw-r--r--myisam/ft_boolean_search.c199
-rw-r--r--myisam/ft_dump.c21
-rw-r--r--myisam/ft_nlq_search.c86
-rw-r--r--myisam/ft_parser.c32
-rw-r--r--myisam/ft_static.c18
-rw-r--r--myisam/ft_update.c10
-rw-r--r--myisam/ftdefs.h13
-rw-r--r--myisam/fulltext.h11
-rw-r--r--myisam/mi_check.c163
-rw-r--r--myisam/mi_create.c45
-rw-r--r--myisam/mi_delete.c97
-rw-r--r--myisam/mi_open.c64
-rw-r--r--myisam/mi_rnext.c18
-rw-r--r--myisam/mi_update.c2
-rw-r--r--myisam/mi_write.c77
-rw-r--r--myisam/myisamchk.c4
-rw-r--r--myisam/myisamdef.h25
-rw-r--r--myisam/sort.c23
-rw-r--r--mysql-test/r/analyse.result3
-rw-r--r--mysql-test/r/fulltext.result2
-rw-r--r--mysql-test/r/fulltext2.result871
-rw-r--r--mysql-test/r/handler.result2
-rw-r--r--mysql-test/r/subselect.result2
-rw-r--r--mysql-test/t/analyse.test1
-rw-r--r--mysql-test/t/fulltext.test1
-rw-r--r--mysql-test/t/fulltext2.test96
-rw-r--r--mysql-test/t/handler.test2
-rw-r--r--mysql-test/t/subselect.test3
-rw-r--r--mysys/mulalloc.c14
-rw-r--r--sql/convert.cc5
-rw-r--r--sql/field.cc17
-rw-r--r--sql/field.h2
-rw-r--r--sql/ha_berkeley.cc1
-rw-r--r--sql/ha_innodb.cc7
-rw-r--r--sql/ha_myisam.cc13
-rw-r--r--sql/ha_myisam.h2
-rw-r--r--sql/item.cc8
-rw-r--r--sql/item.h2
-rw-r--r--sql/item_cmpfunc.cc16
-rw-r--r--sql/item_cmpfunc.h3
-rw-r--r--sql/item_func.cc10
-rw-r--r--sql/item_func.h3
-rw-r--r--sql/item_strfunc.cc4
-rw-r--r--sql/item_strfunc.h12
-rw-r--r--sql/item_sum.cc4
-rw-r--r--sql/log.cc15
-rw-r--r--sql/log_event.cc144
-rw-r--r--sql/log_event.h35
-rw-r--r--sql/mf_iocache.cc4
-rw-r--r--sql/mini_client.cc4
-rw-r--r--sql/mysqld.cc524
-rw-r--r--sql/net_serv.cc4
-rw-r--r--sql/protocol.cc151
-rw-r--r--sql/protocol.h25
-rw-r--r--sql/repl_failsafe.cc5
-rw-r--r--sql/repl_failsafe.h2
-rw-r--r--sql/set_var.cc28
-rw-r--r--sql/set_var.h3
-rw-r--r--sql/slave.cc6
-rw-r--r--sql/slave.h6
-rw-r--r--sql/sql_acl.cc4
-rw-r--r--sql/sql_base.cc10
-rw-r--r--sql/sql_cache.cc4
-rw-r--r--sql/sql_class.cc15
-rw-r--r--sql/sql_class.h20
-rw-r--r--sql/sql_derived.cc2
-rw-r--r--sql/sql_handler.cc2
-rw-r--r--sql/sql_load.cc7
-rw-r--r--sql/sql_parse.cc99
-rw-r--r--sql/sql_prepare.cc16
-rw-r--r--sql/sql_repl.cc6
-rw-r--r--sql/sql_repl.h4
-rw-r--r--sql/sql_select.cc23
-rw-r--r--sql/sql_show.cc30
-rw-r--r--sql/sql_table.cc16
-rw-r--r--sql/sql_yacc.yy14
89 files changed, 2924 insertions, 1988 deletions
diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok
index 2e693cab134..c5970cdd45d 100644
--- a/BitKeeper/etc/logging_ok
+++ b/BitKeeper/etc/logging_ok
@@ -22,6 +22,8 @@ heikki@donna.mysql.fi
heikki@hundin.mysql.fi
heikki@rescue.
heikki@work.mysql.com
+hf@bison.(none)
+hf@bisonxp.(none)
hf@deer.mysql.r18.ru
hf@genie.(none)
jani@dsl-jkl1657.dial.inet.fi
diff --git a/client/mysql.cc b/client/mysql.cc
index 8724cb539f6..cef31b46b2c 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -2502,7 +2502,9 @@ sql_real_connect(char *host,char *database,char *user,char *password,
return -1; // Retryable
}
connected=1;
+#ifndef EMBEDDED_LIBRARY
mysql.reconnect=info_flag ? 1 : 0; // We want to know if this happens
+#endif
#ifdef HAVE_READLINE
build_completion_hash(rehash, 1);
#endif
@@ -2596,12 +2598,14 @@ com_status(String *buffer __attribute__((unused)),
tee_fprintf(stdout, "Client characterset:\t%s\n",
system_charset_info->name);
tee_fprintf(stdout, "Server characterset:\t%s\n", mysql.charset->name);
+#ifndef EMBEDDED_LIBRARY
if (strstr(mysql_get_host_info(&mysql),"TCP/IP") || ! mysql.unix_socket)
tee_fprintf(stdout, "TCP port:\t\t%d\n", mysql.port);
else
tee_fprintf(stdout, "UNIX socket:\t\t%s\n", mysql.unix_socket);
if (mysql.net.compress)
tee_fprintf(stdout, "Protocol:\t\tCompressed\n");
+#endif
if ((status=mysql_stat(&mysql)) && !mysql_error(&mysql)[0])
{
@@ -2867,11 +2871,13 @@ static const char* construct_prompt()
break;
}
case 'p':
+#ifndef EMBEDDED_LIBRARY
if (strstr(mysql_get_host_info(&mysql),"TCP/IP") ||
! mysql.unix_socket)
add_int_to_prompt(mysql.port);
else
processed_prompt.append(strrchr(mysql.unix_socket,'/')+1);
+#endif
break;
case 'U':
if (!full_username)
@@ -3013,4 +3019,3 @@ void sql_element_free(void *ptr)
}
#endif /* EMBEDDED_LIBRARY */
-
diff --git a/client/mysqltest.c b/client/mysqltest.c
index 8138450680e..c938ec5eec0 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -1328,6 +1328,7 @@ int close_connection(struct st_query* q)
{
if (!strcmp(con->name, name))
{
+#ifndef EMBEDDED_LIBRARY
if (q->type == Q_DIRTY_CLOSE)
{
if (con->mysql.net.vio)
@@ -1336,7 +1337,7 @@ int close_connection(struct st_query* q)
con->mysql.net.vio = 0;
}
}
-
+#endif
mysql_close(&con->mysql);
DBUG_RETURN(0);
}
diff --git a/include/my_global.h b/include/my_global.h
index 3b66b3cbc16..e2b59dc220f 100644
--- a/include/my_global.h
+++ b/include/my_global.h
@@ -19,6 +19,11 @@
#ifndef _global_h
#define _global_h
+#ifndef EMBEDDED_LIBRARY
+#define HAVE_REPLICATION
+#define HAVE_EXTERNAL_CLIENT
+#endif
+
#if defined( __EMX__) && !defined( MYSQL_SERVER)
/* moved here to use below VOID macro redefinition */
#define INCL_BASE
diff --git a/include/my_handler.h b/include/my_handler.h
index 629a0974d93..618d1df1a6e 100644
--- a/include/my_handler.h
+++ b/include/my_handler.h
@@ -1,15 +1,15 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
-
+
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
-
+
This library 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
Library General Public License for more details.
-
+
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
@@ -43,6 +43,13 @@ typedef struct st_HA_KEYSEG /* Key-portion */
{ length=mi_uint2korr((key)+1); (key)+=3; } \
}
+#define get_key_length_rdonly(length,key) \
+{ if ((uchar) *(key) != 255) \
+ length= ((uint) (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; }\
diff --git a/include/myisam.h b/include/myisam.h
index 5c4a5345d37..e06f9fc37ca 100644
--- a/include/myisam.h
+++ b/include/myisam.h
@@ -342,6 +342,12 @@ typedef struct st_mi_check_param
char *op_name;
} 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
{
@@ -354,7 +360,8 @@ typedef struct st_sort_info
MI_CHECK *param;
char *buff;
SORT_KEY_BLOCKS *key_block,*key_block_end;
- /* sync things*/
+ SORT_FT_BUF *ft_buf;
+ /* sync things */
uint got_error, threads_running;
pthread_mutex_t mutex;
pthread_cond_t cond;
diff --git a/include/mysql.h b/include/mysql.h
index 3935963e84c..d41b82172a9 100644
--- a/include/mysql.h
+++ b/include/mysql.h
@@ -114,6 +114,9 @@ typedef struct st_mysql_data {
unsigned int fields;
MYSQL_ROWS *data;
MEM_ROOT alloc;
+#ifdef EMBEDDED_LIBRARY
+ MYSQL_ROWS **prev_ptr;
+#endif
} MYSQL_DATA;
struct st_mysql_options {
@@ -146,6 +149,9 @@ struct st_mysql_options {
a read that is replication-aware
*/
my_bool no_master_reads;
+#ifdef EMBEDDED_LIBRARY
+ my_bool separate_thread;
+#endif
char *shared_memory_base_name;
unsigned int protocol;
};
@@ -155,6 +161,9 @@ enum mysql_option
MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE, MYSQL_INIT_COMMAND,
MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME,
MYSQL_OPT_LOCAL_INFILE, MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME
+#ifdef EMBEDDED_LIBRARY
+ , MYSQL_OPT_USE_RESULT
+#endif
};
enum mysql_status
@@ -178,12 +187,14 @@ enum mysql_rpl_type
};
+#ifndef EMBEDDED_LIBRARY
+
typedef struct st_mysql
{
NET net; /* Communication parameters */
gptr connector_fd; /* ConnectorFd for SSL */
- char *host,*user,*passwd,*unix_socket,*server_version,*host_info,
- *info,*db;
+ char *host,*user,*passwd,*unix_socket,*server_version,*host_info,*info;
+ char *db;
struct charset_info_st *charset;
MYSQL_FIELD *fields;
MEM_ROOT field_alloc;
@@ -223,6 +234,29 @@ typedef struct st_mysql
LIST *stmts; /* list of all statements */
} MYSQL;
+#else
+
+struct st_mysql_res;
+
+typedef struct st_mysql
+{
+ struct st_mysql_res *result;
+ void *thd;
+ struct charset_info_st *charset;
+ unsigned int server_language;
+ MYSQL_FIELD *fields;
+ MEM_ROOT field_alloc;
+ my_ulonglong affected_rows;
+ unsigned int field_count;
+ struct st_mysql_options options;
+ enum mysql_status status;
+ my_bool free_me; /* If free in mysql_close */
+ my_ulonglong insert_id; /* id if insert on table with NEXTNR */
+ unsigned int last_errno;
+ char *last_error;
+} MYSQL;
+
+#endif
typedef struct st_mysql_res {
my_ulonglong row_count;
diff --git a/include/mysql_com.h b/include/mysql_com.h
index ee3e026dae7..2e8c3f265b8 100644
--- a/include/mysql_com.h
+++ b/include/mysql_com.h
@@ -125,16 +125,15 @@ typedef struct st_vio Vio;
#define MAX_BLOB_WIDTH 8192 /* Default width for blob */
typedef struct st_net {
+#ifndef EMBEDDED_LIBRARY
Vio* vio;
unsigned char *buff,*buff_end,*write_pos,*read_pos;
my_socket fd; /* For Perl DBI/dbd */
unsigned long max_packet,max_packet_size;
- unsigned int last_errno,pkt_nr,compress_pkt_nr;
+ unsigned int pkt_nr,compress_pkt_nr;
unsigned int write_timeout, read_timeout, retry_count;
int fcntl;
- char last_error[MYSQL_ERRMSG_SIZE];
- unsigned char error;
- my_bool return_errno,compress;
+ my_bool compress;
/*
The following variable is set if we are doing several queries in one
command ( as in LOAD TABLE ... FROM MASTER ),
@@ -144,13 +143,18 @@ typedef struct st_net {
unsigned int *return_status;
unsigned char reading_or_writing;
char save_char;
- my_bool report_error; /* We should report error (we have unreported error) */
my_bool no_send_ok;
/*
Pointer to query object in query cache, do not equal NULL (0) for
queries in cache that have not stored its results yet
*/
+#endif
+ char last_error[MYSQL_ERRMSG_SIZE];
+ unsigned int last_errno;
+ unsigned char error;
gptr query_cache_query;
+ my_bool report_error; /* We should report error (we have unreported error) */
+ my_bool return_errno;
} NET;
#define packet_error (~(unsigned long) 0)
@@ -225,7 +229,12 @@ void my_net_local_init(NET *net);
void net_end(NET *net);
void net_clear(NET *net);
my_bool net_realloc(NET *net, unsigned long length);
+#ifndef EMBEDDED_LIBRARY
my_bool net_flush(NET *net);
+#else
+#define net_flush(A) (0)
+#endif
+
my_bool my_net_write(NET *net,const char *packet,unsigned long len);
my_bool net_write_command(NET *net,unsigned char command,
const char *header, unsigned long head_len,
diff --git a/include/violite.h b/include/violite.h
index 579043dcffa..c9e17cb05c1 100644
--- a/include/violite.h
+++ b/include/violite.h
@@ -32,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */
enum enum_vio_type { VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET,
- VIO_TYPE_NAMEDPIPE, VIO_TYPE_SSL,VIO_TYPE_SHARED_MEMORY};
+ VIO_TYPE_NAMEDPIPE, VIO_TYPE_SSL };
#ifndef __WIN__
#define HANDLE void *
diff --git a/libmysqld/embedded_priv.h b/libmysqld/embedded_priv.h
index e17b72e84d8..abbebec2aaa 100644
--- a/libmysqld/embedded_priv.h
+++ b/libmysqld/embedded_priv.h
@@ -23,9 +23,9 @@
#include <my_pthread.h>
C_MODE_START
-extern void start_embedded_connection(NET * net);
-extern void end_embedded_connection(NET * net);
extern void lib_connection_phase(NET *net, int phase);
-extern bool lib_dispatch_command(enum enum_server_command command, NET *net,
- const char *arg, ulong length);
+extern void init_embedded_mysql(MYSQL *mysql, int client_flag, char *db);
+extern void *create_embedded_thd(int client_flag, char *db);
+extern my_bool simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg,
+ ulong length, my_bool skipp_check);
C_MODE_END
diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc
index 963ceb1f432..04aeca71a20 100644
--- a/libmysqld/lib_sql.cc
+++ b/libmysqld/lib_sql.cc
@@ -23,6 +23,11 @@
#define mysql_unix_port mysql_inix_port1
#define mysql_port mysql_port1
+static int fake_argc= 1;
+static char *fake_argv[]= {(char *)"", 0};
+static const char *fake_groups[] = { "server", "embedded", 0 };
+static char inited, org_my_init_done;
+
#if defined (__WIN__)
#include "../sql/mysqld.cpp"
#else
@@ -31,7 +36,8 @@
#define SCRAMBLE_LENGTH 8
C_MODE_START
-#include "lib_vio.c"
+#include <mysql.h>
+#include "errmsg.h"
static int check_connections1(THD * thd);
static int check_connections2(THD * thd);
@@ -41,175 +47,42 @@ static bool check_user(THD *thd, enum_server_command command,
char * get_mysql_home(){ return mysql_home;};
char * get_mysql_real_data_home(){ return mysql_real_data_home;};
-bool lib_dispatch_command(enum enum_server_command command, NET *net,
- const char *arg, ulong length)
+my_bool simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg,
+ ulong length, my_bool skipp_check)
{
- THD *thd=(THD *) net->vio->dest_thd;
- thd->store_globals(); // Fix if more than one connect
- thd->net.last_error[0]=0; // Clear error message
- thd->net.last_errno=0;
-
- net_new_transaction(&thd->net);
- return dispatch_command(command, thd, (char *) arg, length + 1);
-}
-
+ my_bool result= 1;
+ THD *thd=(THD *) mysql->thd;
-void lib_connection_phase(NET * net, int phase)
-{
- THD * thd;
- thd = (THD *)(net->vio->dest_thd);
- if (thd)
+ /* Check that we are calling the client functions in right order */
+ if (mysql->status != MYSQL_STATUS_READY)
{
- switch (phase)
- {
- case 2:
- check_connections2(thd);
- break;
- }
- }
-}
-C_MODE_END
-
-
-void start_embedded_conn1(NET * net)
-{
- THD * thd = new THD;
- my_net_init(&thd->net,NULL);
- /* if (protocol_version>9) */
- thd->net.return_errno=1;
- thd->thread_id = thread_id++;
-
- Vio * v = net->vio;
- if (!v)
- {
- v = vio_new(0,VIO_CLOSED,0);
- net->vio = v;
- }
- if (v)
- {
- v -> dest_thd = thd;
- }
- thd->net.vio = v;
- if (thd->store_globals())
- {
- fprintf(stderr,"store_globals failed.\n");
- return;
+ strmov(thd->net.last_error,ER(thd->net.last_errno=CR_COMMANDS_OUT_OF_SYNC));
+ return 1;
}
- thd->mysys_var=my_thread_var;
- thd->dbug_thread_id=my_thread_id();
- thd->thread_stack= (char*) &thd;
-
- if (thd->variables.max_join_size == (ulong) HA_POS_ERROR)
- thd->options |= OPTION_BIG_SELECTS;
-
- thd->proc_info=0; // Remove 'login'
- thd->command=COM_SLEEP;
- thd->version=refresh_version;
- thd->set_time();
- bzero(thd->scramble, sizeof(thd->scramble));
- init_sql_alloc(&thd->mem_root,8192,8192);
-
- check_connections1(thd);
-}
-
+ /* Clear result variables */
+ thd->net.last_error[0]=0;
+ thd->net.last_errno=0;
+ mysql->affected_rows= ~(my_ulonglong) 0;
+ thd->store_globals(); // Fix if more than one connect
+ result= dispatch_command(command, thd, (char *) arg, length + 1);
+ if (!skipp_check)
+ result= thd->net.last_errno ? -1 : 0;
-static int
-check_connections1(THD *thd)
-{
- uint connect_errors=0;
- NET *net= &thd->net;
- /*
- ** store the connection details
- */
- DBUG_PRINT("info", (("check_connections called by thread %d"),
- thd->thread_id));
- DBUG_PRINT("general",("New connection received on %s",
- vio_description(net->vio)));
- if (!thd->host) // If TCP/IP connection
- {
- thd->host=(char*) localhost;
- }
- else /* Hostname given means that the connection was on a socket */
- {
- DBUG_PRINT("general",("Host: %s",thd->host));
- thd->ip=0;
- bzero((char*) &thd->remote,sizeof(struct sockaddr));
- }
- //vio_keepalive(net->vio, TRUE);
-
- /* nasty, but any other way? */
- uint pkt_len = 0;
-
- char buff[80],*end;
- int client_flags = CLIENT_LONG_FLAG | CLIENT_CONNECT_WITH_DB |
- CLIENT_TRANSACTIONS;
- LINT_INIT(pkt_len);
-
- end=strmov(buff,server_version)+1;
- int4store((uchar*) end,thd->thread_id);
- end+=4;
- memcpy(end,thd->scramble,SCRAMBLE_LENGTH+1);
- end+=SCRAMBLE_LENGTH +1;
- int2store(end,client_flags);
- end[2]=MY_CHARSET_CURRENT;
- int2store(end+3,thd->server_status);
- bzero(end+5,13);
- end+=18;
- if (net_write_command(net,protocol_version,
- NullS, 0,
- buff, (uint) (end-buff)))
- {
- inc_host_errors(&thd->remote.sin_addr);
- return(ER_HANDSHAKE_ERROR);
- }
- return 0;
+ mysql->last_error= thd->net.last_error;
+ mysql->last_errno= thd->net.last_errno;
+ return result;
}
-#define MIN_HANDSHAKE_SIZE 6
+C_MODE_END
-static int
-check_connections2(THD * thd)
+void THD::clear_error()
{
- uint connect_errors=0;
- uint pkt_len = 0;
- NET * net = &thd -> net;
- if (protocol_version>9) net -> return_errno=1;
-
- if ( (pkt_len=my_net_read(net)) == packet_error ||
- pkt_len < MIN_HANDSHAKE_SIZE)
- {
- inc_host_errors(&thd->remote.sin_addr);
- return(ER_HANDSHAKE_ERROR);
- }
-
-#ifdef _CUSTOMCONFIG_
-#include "_cust_sql_parse.h"
-#endif
- if (connect_errors)
- reset_host_errors(&thd->remote.sin_addr);
- if (thd->packet.alloc(thd->variables.net_buffer_length))
- return(ER_OUT_OF_RESOURCES);
-
- thd->client_capabilities=uint2korr(net->read_pos);
-
- thd->max_client_packet_length=uint3korr(net->read_pos+2);
- char *user= (char*) net->read_pos+5;
- char *passwd= strend(user)+1;
- char *db=0;
- if (passwd[0] && strlen(passwd) != SCRAMBLE_LENGTH)
- return ER_HANDSHAKE_ERROR;
- if (thd->client_capabilities & CLIENT_CONNECT_WITH_DB)
- db=strend(passwd)+1;
- if (thd->client_capabilities & CLIENT_TRANSACTIONS)
- thd->net.return_status= &thd->server_status;
- net->read_timeout=thd->variables.net_read_timeout;
- if (check_user(thd,COM_CONNECT, user, passwd, db, 1))
- return (-1);
- thd->password=test(passwd[0]);
- return 0;
+ net.last_error[0]= 0;
+ net.last_errno= 0;
+ net.report_error= 0;
}
static bool check_user(THD *thd,enum_server_command command, const char *user,
@@ -270,7 +143,6 @@ char **copy_arguments(int argc, char **argv)
extern "C"
{
-static my_bool inited, org_my_init_done;
ulong max_allowed_packet, net_buffer_length;
char ** copy_arguments_ptr= 0;
@@ -287,19 +159,17 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups)
const char *fake_groups[] = { "server", "embedded", 0 };
if (argc)
{
- argcp = &argc;
- argvp = (char***) &argv;
+ argcp= &argc;
+ argvp= (char***) &argv;
}
else
{
- argcp = &fake_argc;
- argvp = (char ***) &fake_argv;
+ argcp= &fake_argc;
+ argvp= (char ***) &fake_argv;
}
if (!groups)
- groups = (char**) fake_groups;
+ groups= (char**) fake_groups;
- my_umask=0660; // Default umask for new files
- my_umask_dir=0700; // Default umask for new directories
/* Only call MY_INIT() if it hasn't been called before */
if (!inited)
@@ -312,43 +182,12 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups)
MY_INIT((char *)"mysql_embedded"); // init my_sys library & pthreads
}
- /*
- Make a copy of the arguments to guard against applications that
- may change or move the initial arguments.
- */
- if (argvp == &argv)
- if (!(copy_arguments_ptr= argv= copy_arguments(argc, argv)))
- return 1;
-
- tzset(); // Set tzname
-
- start_time=time((time_t*) 0);
-#ifdef HAVE_TZNAME
-#if defined(HAVE_LOCALTIME_R) && defined(_REENTRANT)
- {
- struct tm tm_tmp;
- localtime_r(&start_time,&tm_tmp);
- strmov(time_zone,tzname[tm_tmp.tm_isdst != 0 ? 1 : 0]);
- }
-#else
+ if (init_common_variables("my", argc, argv, (const char **)groups))
{
- struct tm *start_tm;
- start_tm=localtime(&start_time);
- strmov(time_zone,tzname[start_tm->tm_isdst != 0 ? 1 : 0]);
+ mysql_server_end();
+ return 1;
}
-#endif
-#endif
-
- if (gethostname(glob_hostname,sizeof(glob_hostname)-4) < 0)
- strmov(glob_hostname,"mysql");
-#ifndef DBUG_OFF
- strxmov(strend(server_version),MYSQL_SERVER_SUFFIX,"-debug",NullS);
-#else
- strmov(strend(server_version),MYSQL_SERVER_SUFFIX);
-#endif
- load_defaults("my", (const char **) groups, argcp, argvp);
- defaults_argv=*argvp;
-
+
/* Get default temporary directory */
opt_mysql_tmpdir=getenv("TMPDIR"); /* Use this if possible */
#if defined( __WIN__) || defined(OS2)
@@ -360,161 +199,29 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups)
if (!opt_mysql_tmpdir || !opt_mysql_tmpdir[0])
opt_mysql_tmpdir=(char*) P_tmpdir; /* purecov: inspected */
- set_options();
- get_options(*argcp, *argvp);
-
- if (opt_log || opt_update_log || opt_slow_log || opt_bin_log)
- strcat(server_version,"-log");
- DBUG_PRINT("info",("%s Ver %s for %s on %s\n",my_progname,
- server_version, SYSTEM_TYPE,MACHINE_TYPE));
-
- /* These must be set early */
-
- (void) pthread_mutex_init(&LOCK_mysql_create_db,MY_MUTEX_INIT_SLOW);
- (void) pthread_mutex_init(&LOCK_Acl,MY_MUTEX_INIT_SLOW);
- (void) pthread_mutex_init(&LOCK_open,MY_MUTEX_INIT_FAST);
- (void) pthread_mutex_init(&LOCK_thread_count,MY_MUTEX_INIT_FAST);
- (void) pthread_mutex_init(&LOCK_mapped_file,MY_MUTEX_INIT_SLOW);
- (void) pthread_mutex_init(&LOCK_status,MY_MUTEX_INIT_FAST);
- (void) pthread_mutex_init(&LOCK_error_log,MY_MUTEX_INIT_FAST);
- (void) pthread_mutex_init(&LOCK_delayed_insert,MY_MUTEX_INIT_FAST);
- (void) pthread_mutex_init(&LOCK_delayed_status,MY_MUTEX_INIT_FAST);
- (void) pthread_mutex_init(&LOCK_delayed_create,MY_MUTEX_INIT_SLOW);
- (void) pthread_mutex_init(&LOCK_manager,MY_MUTEX_INIT_FAST);
- (void) pthread_mutex_init(&LOCK_crypt,MY_MUTEX_INIT_FAST);
- (void) pthread_mutex_init(&LOCK_bytes_sent,MY_MUTEX_INIT_FAST);
- (void) pthread_mutex_init(&LOCK_bytes_received,MY_MUTEX_INIT_FAST);
- (void) pthread_mutex_init(&LOCK_timezone,MY_MUTEX_INIT_FAST);
- (void) pthread_mutex_init(&LOCK_user_conn, MY_MUTEX_INIT_FAST);
- (void) pthread_mutex_init(&LOCK_rpl_status, MY_MUTEX_INIT_FAST);
- (void) pthread_mutex_init(&LOCK_active_mi, MY_MUTEX_INIT_FAST);
- (void) pthread_mutex_init(&LOCK_global_system_variables, MY_MUTEX_INIT_FAST);
- (void) my_rwlock_init(&LOCK_grant, NULL);
- (void) pthread_cond_init(&COND_thread_count,NULL);
- (void) pthread_cond_init(&COND_refresh,NULL);
- (void) pthread_cond_init(&COND_thread_cache,NULL);
- (void) pthread_cond_init(&COND_flush_thread_cache,NULL);
- (void) pthread_cond_init(&COND_manager,NULL);
- (void) pthread_cond_init(&COND_rpl_status, NULL);
-
- if (set_default_charset_by_name(sys_charset.value, MYF(MY_WME)))
+ if (init_thread_environement())
{
mysql_server_end();
return 1;
}
- charsets_list = list_charsets(MYF(MY_CS_COMPILED|MY_CS_CONFIG));
-
- /* Parameter for threads created for connections */
- (void) pthread_attr_init(&connection_attrib);
- (void) pthread_attr_setdetachstate(&connection_attrib,
- PTHREAD_CREATE_DETACHED);
- pthread_attr_setstacksize(&connection_attrib,thread_stack);
- pthread_attr_setscope(&connection_attrib, PTHREAD_SCOPE_SYSTEM);
-#if defined( SET_RLIMIT_NOFILE) || defined( OS2)
- /* connections and databases needs lots of files */
- {
- uint wanted_files=10+(uint) max(max_connections*5,
- max_connections+table_cache_size*2);
- set_if_bigger(wanted_files, open_files_limit);
- // Note that some system returns 0 if we succeed here:
- uint files=set_maximum_open_files(wanted_files);
- if (files && files < wanted_files && ! open_files_limit)
- {
- max_connections= (ulong) min((files-10),max_connections);
- table_cache_size= (ulong) max((files-10-max_connections)/2,64);
- DBUG_PRINT("warning",
- ("Changed limits: max_connections: %ld table_cache: %ld",
- max_connections,table_cache_size));
- sql_print_error("Warning: Changed limits: max_connections: %ld table_cache: %ld",max_connections,table_cache_size);
- }
- }
-#endif
- unireg_init(opt_specialflag); /* Set up extern variabels */
- init_errmessage(); /* Read error messages from file */
- lex_init();
- item_init();
- set_var_init();
- mysys_uses_curses=0;
-#ifdef USE_REGEX
- regex_init();
-#endif
- if (use_temp_pool && bitmap_init(&temp_pool,1024,1))
+ umask(((~my_umask) & 0666));
+ if (init_server_components())
{
mysql_server_end();
return 1;
}
- /*
- We have enough space for fiddling with the argv, continue
- */
- umask(((~my_umask) & 0666));
- table_cache_init();
- hostname_cache_init();
- query_cache_result_size_limit(query_cache_limit);
- query_cache_resize(query_cache_size);
- randominit(&sql_rand,(ulong) start_time,(ulong) start_time/2);
- reset_floating_point_exceptions();
- init_thr_lock();
- init_slave_list();
-
- /* Setup log files */
- if (opt_log)
- open_log(&mysql_log, glob_hostname, opt_logname, ".log", NullS,
- LOG_NORMAL);
- if (opt_update_log)
- {
- open_log(&mysql_update_log, glob_hostname, opt_update_logname, "",
- NullS, LOG_NEW);
- using_update_log=1;
- }
-
- if (opt_slow_log)
- open_log(&mysql_slow_log, glob_hostname, opt_slow_logname, "-slow.log",
- NullS, LOG_NORMAL);
- if (ha_init())
- {
- sql_print_error("Can't init databases");
- exit(1);
- }
- ha_key_cache();
-#if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT)
- if (locked_in_memory && !geteuid())
- {
- if (mlockall(MCL_CURRENT))
- {
- sql_print_error("Warning: Failed to lock memory. Errno: %d\n",errno);
- }
- else
- locked_in_memory=1;
- }
-#else
- locked_in_memory=0;
-#endif
-
- if (opt_myisam_log)
- (void) mi_log( 1 );
- ft_init_stopwords(ft_precompiled_stopwords);
-
- /*
- init signals & alarm
- After this we can't quit by a simple unireg_abort
- */
error_handler_hook = my_message_sql;
- if (pthread_key_create(&THR_THD,NULL) ||
- pthread_key_create(&THR_MALLOC,NULL))
- {
- sql_print_error("Can't create thread-keys");
- exit(1);
- }
+
opt_noacl = 1; // No permissions
- if (acl_init((THD*) 0,opt_noacl))
+ if (acl_init((THD *)0, opt_noacl))
{
mysql_server_end();
return 1;
}
if (!opt_noacl)
- (void) grant_init((THD*) 0);
+ (void) grant_init((THD *)0);
init_max_user_conn();
init_update_queries();
@@ -564,7 +271,6 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups)
return 0;
}
-
void STDCALL mysql_server_end()
{
my_free((char*) copy_arguments_ptr, MYF(MY_ALLOW_ZERO_PTR));
@@ -595,16 +301,218 @@ void STDCALL mysql_thread_end()
my_thread_end();
#endif
}
+} /* extern "C" */
-void start_embedded_connection(NET * net)
+C_MODE_START
+void init_embedded_mysql(MYSQL *mysql, int client_flag, char *db)
{
- start_embedded_conn1(net);
+ THD *thd = (THD *)mysql->thd;
+ thd->mysql= mysql;
+ mysql->last_error= thd->net.last_error;
}
-void end_embedded_connection(NET * net)
+void *create_embedded_thd(int client_flag, char *db)
{
- THD *thd = (THD *) net->vio->dest_thd;
- delete thd;
+ THD * thd= new THD;
+ thd->thread_id= thread_id++;
+
+ if (thd->store_globals())
+ {
+ fprintf(stderr,"store_globals failed.\n");
+ return NULL;
+ }
+
+ thd->mysys_var= my_thread_var;
+ thd->dbug_thread_id= my_thread_id();
+ thd->thread_stack= (char*) &thd;
+
+ thd->proc_info=0; // Remove 'login'
+ thd->command=COM_SLEEP;
+ thd->version=refresh_version;
+ thd->set_time();
+ init_sql_alloc(&thd->mem_root,8192,8192);
+ thd->client_capabilities= client_flag;
+
+ thd->db= db;
+ thd->db_length= db ? strip_sp(db) : 0;
+ thd->db_access= DB_ACLS;
+ thd->master_access= ~NO_ACCESS;
+ thd->net.query_cache_query= 0;
+
+ return thd;
}
-} /* extern "C" */
+C_MODE_END
+
+bool Protocol::send_fields(List<Item> *list, uint flag)
+{
+ List_iterator_fast<Item> it(*list);
+ Item *item;
+ MYSQL_FIELD *field, *client_field;
+ MYSQL *mysql= thd->mysql;
+
+ DBUG_ENTER("send_fields");
+
+ field_count= list->elements;
+ if (!(mysql->result=(MYSQL_RES*) my_malloc(sizeof(MYSQL_RES)+
+ sizeof(ulong) * (field_count + 1),
+ MYF(MY_WME | MY_ZEROFILL))))
+ goto err;
+ mysql->result->lengths= (ulong *)(mysql->result + 1);
+
+ mysql->field_count=field_count;
+ alloc= &mysql->field_alloc;
+ field= (MYSQL_FIELD *)alloc_root(alloc, sizeof(MYSQL_FIELD) * field_count);
+ if (!field)
+ goto err;
+
+ client_field= field;
+ while ((item= it++))
+ {
+ Send_field server_field;
+ item->make_field(&server_field);
+
+ client_field->table= strdup_root(alloc, server_field.table_name);
+ client_field->name= strdup_root(alloc,server_field.col_name);
+ client_field->length= server_field.length;
+ client_field->type= server_field.type;
+ client_field->flags= server_field.flags;
+ client_field->decimals= server_field.decimals;
+
+ if (INTERNAL_NUM_FIELD(client_field))
+ client_field->flags|= NUM_FLAG;
+
+ if (flag & 2)
+ {
+ char buff[80];
+ String tmp(buff, sizeof(buff), default_charset_info), *res;
+
+ if (!(res=item->val_str(&tmp)))
+ client_field->def= strdup_root(alloc, "");
+ else
+ client_field->def= strdup_root(alloc, tmp.ptr());
+ }
+ else
+ client_field->def=0;
+ client_field->max_length= 0;
+ ++client_field;
+ }
+ mysql->result->fields = field;
+
+ if (!(mysql->result->data= (MYSQL_DATA*) my_malloc(sizeof(MYSQL_DATA),
+ MYF(MY_WME | MY_ZEROFILL))))
+ goto err;
+
+ init_alloc_root(&mysql->result->data->alloc,8192,0); /* Assume rowlength < 8192 */
+ mysql->result->data->alloc.min_malloc=sizeof(MYSQL_ROWS);
+ mysql->result->data->rows=0;
+ mysql->result->data->fields=field_count;
+ mysql->result->field_count=field_count;
+ mysql->result->data->prev_ptr= &mysql->result->data->data;
+
+ mysql->result->field_alloc= mysql->field_alloc;
+ mysql->result->current_field=0;
+ mysql->result->current_row=0;
+
+ DBUG_RETURN(prepare_for_send(list));
+ err:
+ send_error(thd, ER_OUT_OF_RESOURCES); /* purecov: inspected */
+ DBUG_RETURN(1); /* purecov: inspected */
+}
+
+bool Protocol::send_records_num(List<Item> *list, ulonglong records)
+{
+ return false;
+}
+
+bool Protocol::write()
+{
+ *next_field= 0;
+ return false;
+}
+
+void
+send_ok(THD *thd,ha_rows affected_rows,ulonglong id,const char *message)
+{
+ DBUG_ENTER("send_ok");
+ MYSQL *mysql= current_thd->mysql;
+ mysql->affected_rows= affected_rows;
+ mysql->insert_id= id;
+ if (message)
+ {
+ strmake(thd->net.last_error, message, sizeof(thd->net.last_error)-1);
+ }
+ DBUG_VOID_RETURN;
+}
+
+void
+send_eof(THD *thd, bool no_flush)
+{
+}
+
+uint STDCALL mysql_warning_count(MYSQL *mysql)
+{
+ return ((THD *)mysql->thd)->total_warn_count;
+}
+
+void Protocol_simple::prepare_for_resend()
+{
+ MYSQL_ROWS *cur;
+ ulong len;
+ MYSQL_DATA *result= thd->mysql->result->data;
+
+ DBUG_ENTER("send_data");
+
+ alloc= &result->alloc;
+ result->rows++;
+ if (!(cur= (MYSQL_ROWS *)alloc_root(alloc, sizeof(MYSQL_ROWS)+(field_count + 1) * sizeof(char *))))
+ {
+ my_error(ER_OUT_OF_RESOURCES,MYF(0));
+ DBUG_VOID_RETURN;
+ }
+ cur->data= (MYSQL_ROW)(((char *)cur) + sizeof(MYSQL_ROWS));
+
+ *result->prev_ptr= cur;
+ result->prev_ptr= &cur->next;
+ next_field=cur->data;
+ next_mysql_field= thd->mysql->result->fields;
+
+ DBUG_VOID_RETURN;
+}
+
+bool Protocol_simple::store_null()
+{
+ *(next_field++)= NULL;
+ ++next_mysql_field;
+ return false;
+}
+
+bool Protocol::net_store_data(const char *from, uint length)
+{
+ if (!(*next_field=alloc_root(alloc, length + 1)))
+ return true;
+ memcpy(*next_field, from, length);
+ (*next_field)[length]= 0;
+ if (next_mysql_field->max_length < length)
+ next_mysql_field->max_length=length;
+ ++next_field;
+ ++next_mysql_field;
+
+ return false;
+}
+
+/* The same as Protocol::net_store_data but does the converstion
+*/
+bool Protocol::convert_str(const char *from, uint length)
+{
+ if (!(*next_field=alloc_root(alloc, length + 1)))
+ return true;
+ convert->store_dest(*next_field, from, length);
+ (*next_field)[length]= 0;
+ if (next_mysql_field->max_length < length)
+ next_mysql_field->max_length=length;
+ ++next_field;
+ ++next_mysql_field;
+
+ return false;
+}
diff --git a/libmysqld/lib_vio.c b/libmysqld/lib_vio.c
index 29a70b7acbb..e9f86cead80 100644
--- a/libmysqld/lib_vio.c
+++ b/libmysqld/lib_vio.c
@@ -20,6 +20,7 @@
we are working on. In this case we should just return read errors from
the file descriptior.
*/
+#ifdef DUMMY
#include <my_global.h>
#include "mysql_embed.h"
@@ -42,14 +43,7 @@
struct st_vio
{
- my_socket sd; /* my_socket - real or imaginary */
- HANDLE hPipe;
- my_bool localhost; /* Are we from localhost? */
- int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */
- struct sockaddr_in local; /* Local internet address */
- struct sockaddr_in remote; /* Remote internet address */
enum enum_vio_type type; /* Type of connection */
- char desc[30]; /* String description */
void *dest_thd;
char *packets, **last_packet;
char *where_in_packet, *end_of_packet;
@@ -57,6 +51,7 @@ struct st_vio
MEM_ROOT root;
};
+
/* Initialize the communication buffer */
Vio *vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost)
@@ -69,6 +64,7 @@ Vio *vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost)
init_alloc_root(&vio->root, 8192, 8192);
vio->root.min_malloc = sizeof(char *) + 4;
vio->last_packet = &vio->packets;
+ vio->type = type;
}
DBUG_RETURN(vio);
}
@@ -219,4 +215,24 @@ my_bool vio_poll_read(Vio *vio,uint timeout)
return 0;
}
+int create_vio(NET *net, int separate_thread)
+{
+ Vio * v = net->vio;
+ if (!v)
+ {
+ v = vio_new(0, separate_thread ? VIO_CLOSED : VIO_TYPE_TCPIP, 0);
+ net->vio = v;
+ }
+ return !v;
+}
+
+void set_thd(Vio *v, void *thd)
+{
+ if (v)
+ {
+ v -> dest_thd = thd;
+ }
+}
#endif /* HAVE_VIO */
+#endif /* DUMMY */
+
diff --git a/libmysqld/libmysqld.c b/libmysqld/libmysqld.c
index e8a2f4989a5..6f7a7e4b666 100644
--- a/libmysqld/libmysqld.c
+++ b/libmysqld/libmysqld.c
@@ -67,14 +67,8 @@ TYPELIB sql_protocol_typelib = {array_elements(sql_protocol_names_lib)-1,"",
#endif
static void mysql_once_init(void);
-static MYSQL_DATA *read_rows (MYSQL *mysql,MYSQL_FIELD *fields,
- uint field_count);
-static int read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row,
- ulong *lengths);
static void end_server(MYSQL *mysql);
-static void read_user_name(char *name);
static void append_wild(char *to,char *end,const char *wild);
-static int send_file_to_server(MYSQL *mysql,const char *filename);
static ulong mysql_sub_escape_string(CHARSET_INFO *charset_info, char *to,
const char *from, ulong length);
@@ -82,130 +76,6 @@ static ulong mysql_sub_escape_string(CHARSET_INFO *charset_info, char *to,
#define set_sigpipe(mysql)
#define reset_sigpipe(mysql)
-/*****************************************************************************
-** read a packet from server. Give error message if socket was down
-** or packet is an error message
-*****************************************************************************/
-
-ulong
-net_safe_read(MYSQL *mysql)
-{
- NET *net= &mysql->net;
- uint len=0;
- //init_sigpipe_variables
- /* Don't give sigpipe errors if the client doesn't want them */
- set_sigpipe(mysql);
- if (net->vio != 0)
- len=my_net_read(net);
- reset_sigpipe(mysql);
- if (len == packet_error || len == 0)
- {
- DBUG_PRINT("error",("Wrong connection or packet. fd: %s len: %d",
- vio_description(net->vio),len));
- end_server(mysql);
- net->last_errno=(net->last_errno == ER_NET_PACKET_TOO_LARGE ?
- CR_NET_PACKET_TOO_LARGE:
- CR_SERVER_LOST);
- strmov(net->last_error,ER(net->last_errno));
- return(packet_error);
- }
- if (net->read_pos[0] == 255)
- {
-
- if (len > 3)
- {
- char *pos=(char*) net->read_pos+1;
- if (mysql->protocol_version > 9)
- { /* New client protocol */
- net->last_errno=uint2korr(pos);
- pos+=2;
- len-=2;
- }
- else
- {
- net->last_errno=CR_UNKNOWN_ERROR;
- len--;
- }
- (void) strmake(net->last_error,(char*) pos,
- min(len,sizeof(net->last_error)-1));
- }
- else
- {
- net->last_errno=CR_UNKNOWN_ERROR;
- (void) strmov(net->last_error,ER(net->last_errno));
- }
- DBUG_PRINT("error",("Got error: %d (%s)", net->last_errno,
- net->last_error));
- return(packet_error);
- }
- return len;
-}
-
-
-/* Get the length of next field. Change parameter to point at fieldstart */
-static ulong
-net_field_length(uchar **packet)
-{
- reg1 uchar *pos= *packet;
- if (*pos < 251)
- {
- (*packet)++;
- return (ulong) *pos;
- }
- if (*pos == 251)
- {
- (*packet)++;
- return NULL_LENGTH;
- }
- if (*pos == 252)
- {
- (*packet)+=3;
- return (ulong) uint2korr(pos+1);
- }
- if (*pos == 253)
- {
- (*packet)+=4;
- return (ulong) uint3korr(pos+1);
- }
- (*packet)+=9; /* Must be 254 when here */
- return (ulong) uint4korr(pos+1);
-}
-
-/* Same as above, but returns ulonglong values */
-
-static my_ulonglong
-net_field_length_ll(uchar **packet)
-{
- reg1 uchar *pos= *packet;
- if (*pos < 251)
- {
- (*packet)++;
- return (my_ulonglong) *pos;
- }
- if (*pos == 251)
- {
- (*packet)++;
- return (my_ulonglong) NULL_LENGTH;
- }
- if (*pos == 252)
- {
- (*packet)+=3;
- return (my_ulonglong) uint2korr(pos+1);
- }
- if (*pos == 253)
- {
- (*packet)+=4;
- return (my_ulonglong) uint3korr(pos+1);
- }
- (*packet)+=9; /* Must be 254 when here */
-#ifdef NO_CLIENT_LONGLONG
- return (my_ulonglong) uint4korr(pos+1);
-#else
- return (my_ulonglong) uint8korr(pos+1);
-#endif
-}
-
-
static void free_rows(MYSQL_DATA *cur)
{
if (cur)
@@ -215,40 +85,6 @@ static void free_rows(MYSQL_DATA *cur)
}
}
-
-my_bool
-simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg,
- ulong length, my_bool skipp_check)
-{
- NET *net= &mysql->net;
- my_bool result= 1;
-
- /* Check that we are calling the client functions in right order */
- if (mysql->status != MYSQL_STATUS_READY)
- {
- strmov(net->last_error,ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC));
- goto end;
- }
-
- /* Clear result variables */
- mysql->net.last_error[0]=0;
- mysql->net.last_errno=0;
- mysql->info=0;
- mysql->affected_rows= ~(my_ulonglong) 0;
-
- /* Clear receive buffer and vio packet list */
- net_clear(net);
- vio_reset(net->vio);
-
- result = lib_dispatch_command(command, net, arg,length);
- if (!skipp_check)
- result= ((mysql->packet_length=net_safe_read(mysql)) == packet_error ?
- 1 : 0);
- end:
- return result;
-}
-
-
static void free_old_query(MYSQL *mysql)
{
DBUG_ENTER("free_old_query");
@@ -265,53 +101,6 @@ struct passwd *getpwuid(uid_t);
char* getlogin(void);
#endif
-#if !defined(MSDOS) && ! defined(VMS) && !defined(__WIN__)
-static void read_user_name(char *name)
-{
- DBUG_ENTER("read_user_name");
- if (geteuid() == 0)
- (void) strmov(name,"root"); /* allow use of surun */
- else
- {
-#ifdef HAVE_GETPWUID
- struct passwd *skr;
- const char *str;
-/*#ifdef __cplusplus
- extern "C" struct passwd *getpwuid(uid_t);
- extern "C" { char* getlogin(void); }
-#else
- char * getlogin();
- struct passwd *getpwuid(uid_t);
-#endif
-*/
- if ((str=getlogin()) == NULL)
- {
- if ((skr=getpwuid(geteuid())) != NULL)
- str=skr->pw_name;
- else if (!(str=getenv("USER")) && !(str=getenv("LOGNAME")) &&
- !(str=getenv("LOGIN")))
- str="UNKNOWN_USER";
- }
- (void) strmake(name,str,USERNAME_LENGTH);
-#elif HAVE_CUSERID
- (void) cuserid(name);
-#else
- strmov(name,"UNKNOWN_USER");
-#endif
- }
- DBUG_VOID_RETURN;
-}
-
-#else /* If MSDOS || VMS */
-
-static void read_user_name(char *name)
-{
- char *str=getenv("USER");
- strmov(name,str ? str : "ODBC"); /* ODBC will send user variable */
-}
-
-#endif
-
#ifdef __WIN__
static my_bool is_NT(void)
{
@@ -390,17 +179,10 @@ static void
end_server(MYSQL *mysql)
{
DBUG_ENTER("end_server");
- if (mysql->net.vio != 0)
- {
- end_embedded_connection(&mysql->net);
- mysql->net.vio= 0; /* Marker */
- }
- net_end(&mysql->net);
free_old_query(mysql);
DBUG_VOID_RETURN;
}
-
void STDCALL
mysql_free_result(MYSQL_RES *result)
{
@@ -408,19 +190,6 @@ mysql_free_result(MYSQL_RES *result)
DBUG_PRINT("enter",("mysql_res: %lx",result));
if (result)
{
- if (result->handle && result->handle->status == MYSQL_STATUS_USE_RESULT)
- {
- DBUG_PRINT("warning",("Not all rows in set were read; Ignoring rows"));
- for (;;)
- {
- uint pkt_len;
- if ((pkt_len=(uint) net_safe_read(result->handle)) == packet_error)
- break;
- if (pkt_len <= 8 && result->handle->net.read_pos[0] == 254)
- break; /* End of data */
- }
- result->handle->status=MYSQL_STATUS_READY;
- }
free_rows(result->data);
if (result->fields)
free_root(&result->field_alloc,MYF(0));
@@ -431,7 +200,6 @@ mysql_free_result(MYSQL_RES *result)
DBUG_VOID_RETURN;
}
-
/****************************************************************************
** Get options from my.cnf
****************************************************************************/
@@ -597,174 +365,6 @@ static void mysql_read_default_options(struct st_mysql_options *options,
}
-/***************************************************************************
-** Change field rows to field structs
-***************************************************************************/
-
-static MYSQL_FIELD *
-unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
- my_bool default_value, my_bool long_flag_protocol)
-{
- MYSQL_ROWS *row;
- MYSQL_FIELD *field,*result;
- DBUG_ENTER("unpack_fields");
-
- field=result=(MYSQL_FIELD*) alloc_root(alloc,sizeof(MYSQL_FIELD)*fields);
- if (!result)
- DBUG_RETURN(0);
-
- for (row=data->data; row ; row = row->next,field++)
- {
- field->table= strdup_root(alloc,(char*) row->data[0]);
- field->name= strdup_root(alloc,(char*) row->data[1]);
- field->length= (uint) uint3korr(row->data[2]);
- field->type= (enum enum_field_types) (uchar) row->data[3][0];
- if (long_flag_protocol)
- {
- field->flags= uint2korr(row->data[4]);
- field->decimals=(uint) (uchar) row->data[4][2];
- }
- else
- {
- field->flags= (uint) (uchar) row->data[4][0];
- field->decimals=(uint) (uchar) row->data[4][1];
- }
- if (INTERNAL_NUM_FIELD(field))
- field->flags|= NUM_FLAG;
- if (default_value && row->data[5])
- field->def=strdup_root(alloc,(char*) row->data[5]);
- else
- field->def=0;
- field->max_length= 0;
- }
- free_rows(data); /* Free old data */
- DBUG_RETURN(result);
-}
-
-
-/* Read all rows (fields or data) from server */
-
-static MYSQL_DATA *read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
- uint fields)
-{
- uint field,pkt_len;
- ulong len;
- uchar *cp;
- char *to;
- MYSQL_DATA *result;
- MYSQL_ROWS **prev_ptr,*cur;
- NET *net = &mysql->net;
- DBUG_ENTER("read_rows");
-
- if ((pkt_len=(uint) net_safe_read(mysql)) == packet_error)
- DBUG_RETURN(0);
- if (!(result=(MYSQL_DATA*) my_malloc(sizeof(MYSQL_DATA),
- MYF(MY_WME | MY_ZEROFILL))))
- {
- net->last_errno=CR_OUT_OF_MEMORY;
- strmov(net->last_error,ER(net->last_errno));
- DBUG_RETURN(0);
- }
- init_alloc_root(&result->alloc,8192,0); /* Assume rowlength < 8192 */
- result->alloc.min_malloc=sizeof(MYSQL_ROWS);
- prev_ptr= &result->data;
- result->rows=0;
- result->fields=fields;
-
- while (*(cp=net->read_pos) != 254 || pkt_len >= 8)
- {
- result->rows++;
- if (!(cur= (MYSQL_ROWS*) alloc_root(&result->alloc,
- sizeof(MYSQL_ROWS))) ||
- !(cur->data= ((MYSQL_ROW)
- alloc_root(&result->alloc,
- (fields+1)*sizeof(char *)+pkt_len))))
- {
- free_rows(result);
- net->last_errno=CR_OUT_OF_MEMORY;
- strmov(net->last_error,ER(net->last_errno));
- DBUG_RETURN(0);
- }
- *prev_ptr=cur;
- prev_ptr= &cur->next;
- to= (char*) (cur->data+fields+1);
- for (field=0 ; field < fields ; field++)
- {
- if ((len=(ulong) net_field_length(&cp)) == NULL_LENGTH)
- { /* null field */
- cur->data[field] = 0;
- }
- else
- {
- cur->data[field] = to;
- memcpy(to,(char*) cp,len); to[len]=0;
- to+=len+1;
- cp+=len;
- if (mysql_fields)
- {
- if (mysql_fields[field].max_length < len)
- mysql_fields[field].max_length=len;
- }
- }
- }
- cur->data[field]=to; /* End of last field */
- if ((pkt_len=net_safe_read(mysql)) == packet_error)
- {
- free_rows(result);
- DBUG_RETURN(0);
- }
- }
- *prev_ptr=0; /* last pointer is null */
- mysql->warning_count= uint2korr(cp+1);
- DBUG_PRINT("info",("warning_count: %ld", mysql->warning_count));
- DBUG_PRINT("exit",("Got %d rows",result->rows));
- DBUG_RETURN(result);
-}
-
-
-/*
-** Read one row. Uses packet buffer as storage for fields.
-** When next packet is read, the previous field values are destroyed
-*/
-
-
-static int
-read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths)
-{
- uint field;
- ulong pkt_len,len;
- uchar *pos,*prev_pos;
-
- if ((pkt_len=net_safe_read(mysql)) == packet_error)
- return -1;
- if (pkt_len <= 8 && mysql->net.read_pos[0] == 254)
- {
- mysql->warning_count= uint2korr(mysql->net.read_pos+1);
- return 1; /* End of data */
- }
- prev_pos= 0; /* allowed to write at packet[-1] */
- pos=mysql->net.read_pos;
- for (field=0 ; field < fields ; field++)
- {
- if ((len=(ulong) net_field_length(&pos)) == NULL_LENGTH)
- { /* null field */
- row[field] = 0;
- *lengths++=0;
- }
- else
- {
- row[field] = (char*) pos;
- pos+=len;
- *lengths++=len;
- }
- if (prev_pos)
- *prev_pos=0; /* Terminate prev field */
- prev_pos=pos;
- }
- row[field]=(char*) prev_pos+1; /* End of last field */
- *prev_pos=0; /* Terminate last field */
- return 0;
-}
/****************************************************************************
** Init MySQL structure or allocate one
@@ -779,7 +379,6 @@ mysql_init(MYSQL *mysql)
if (!(mysql=(MYSQL*) my_malloc(sizeof(*mysql),MYF(MY_WME | MY_ZEROFILL))))
return 0;
mysql->free_me=1;
- mysql->net.vio = 0;
}
else
bzero((char*) (mysql),sizeof(*(mysql)));
@@ -792,6 +391,7 @@ static void mysql_once_init()
if (!mysql_client_init)
{
mysql_client_init=1;
+
my_init(); /* Will init threads */
init_client_errs();
mysql_port = MYSQL_PORT;
@@ -825,100 +425,10 @@ mysql_connect(MYSQL *mysql,const char *host,
}
}
-
-/*
-** Note that the mysql argument must be initialized with mysql_init()
-** before calling mysql_real_connect !
-*/
-
-MYSQL * STDCALL
-mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
- const char *passwd, const char *db,
- uint port, const char *unix_socket,ulong client_flag)
+static inline int mysql_init_charset(MYSQL *mysql)
{
- char buff[100],charset_name_buff[16],*end,*host_info, *charset_name;
- uint pkt_length;
- ulong max_allowed_packet;
- NET *net= &mysql->net;
- DBUG_ENTER("mysql_real_connect");
- DBUG_PRINT("enter",("host: %s db: %s user: %s",
- host ? host : "(Null)",
- db ? db : "(Null)",
- user ? user : "(Null)"));
-
- net->vio = 0; /* If something goes wrong */
- /* use default options */
- if (mysql->options.my_cnf_file || mysql->options.my_cnf_group)
- {
- mysql_read_default_options(&mysql->options,
- (mysql->options.my_cnf_file ?
- mysql->options.my_cnf_file : "my"),
- mysql->options.my_cnf_group);
- my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
- my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
- mysql->options.my_cnf_file=mysql->options.my_cnf_group=0;
- }
-
- /* Some empty-string-tests are done because of ODBC */
- if (!host || !host[0])
- host=mysql->options.host;
- if (!user || !user[0])
- user=mysql->options.user;
- if (!passwd)
- {
- passwd=mysql->options.password;
- }
- if (!db || !db[0])
- db=mysql->options.db;
- port=0;
- unix_socket=0;
- mysql->reconnect=1; /* Reconnect as default */
- mysql->server_status=SERVER_STATUS_AUTOCOMMIT;
- host_info=(char*) ER(CR_EMBEDDED_CONNECTION);
- if (my_net_init(net, net->vio))
- {
- vio_delete(net->vio);
- net->last_errno=CR_OUT_OF_MEMORY;
- strmov(net->last_error,ER(net->last_errno));
- goto error;
- }
-
- /* Get version info */
- mysql->protocol_version= PROTOCOL_VERSION; /* Assume this */
- start_embedded_connection(net);
+ char charset_name_buff[16], *charset_name;
- if ((pkt_length=net_safe_read(mysql)) == packet_error)
- goto error;
-
- /* Check if version of protocoll matches current one */
-
- mysql->protocol_version= net->read_pos[0];
- DBUG_DUMP("packet",(char*) net->read_pos,10);
- DBUG_PRINT("info",("mysql protocol version %d, server=%d",
- PROTOCOL_VERSION, mysql->protocol_version));
- if (mysql->protocol_version != PROTOCOL_VERSION &&
- mysql->protocol_version != PROTOCOL_VERSION-1)
- {
- net->last_errno= CR_VERSION_ERROR;
- sprintf(net->last_error, ER(CR_VERSION_ERROR), mysql->protocol_version,
- PROTOCOL_VERSION);
- goto error;
- }
- end=strend((char*) net->read_pos+1);
- mysql->thread_id=uint4korr(end+1);
- end+=5;
- strmake(mysql->scramble_buff,end,8);
- end+=9;
- if (pkt_length >= (uint) (end+1 - (char*) net->read_pos))
- mysql->server_capabilities=uint2korr(end);
- if (pkt_length >= (uint) (end+18 - (char*) net->read_pos))
- {
- /* New protocol with 16 bytes to describe server characteristics */
- mysql->server_language=end[2];
- mysql->server_status=uint2korr(end+3);
- }
-
- /* Set character set */
if ((charset_name=mysql->options.charset_name))
{
const char *save=charsets_dir;
@@ -939,99 +449,79 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
if (!mysql->charset)
{
- net->last_errno=CR_CANT_READ_CHARSET;
+ mysql->last_errno=CR_CANT_READ_CHARSET;
if (mysql->options.charset_dir)
- sprintf(net->last_error,ER(net->last_errno),
+ sprintf(mysql->last_error,ER(mysql->last_errno),
charset_name ? charset_name : "unknown",
mysql->options.charset_dir);
else
{
char cs_dir_name[FN_REFLEN];
get_charsets_dir(cs_dir_name);
- sprintf(net->last_error,ER(net->last_errno),
+ sprintf(mysql->last_error,ER(mysql->last_errno),
charset_name ? charset_name : "unknown",
cs_dir_name);
}
- goto error;
+ return mysql->last_errno;
}
+ return 0;
+}
- /* Save connection information */
- if (!user) user="";
- if (!passwd) passwd="";
- host=LOCAL_HOST;
- if (!my_multi_malloc(MYF(0),
- &mysql->host_info, (uint) strlen(host_info)+1,
- &mysql->host, (uint) strlen(host)+1,
- &mysql->unix_socket,unix_socket ?
- (uint) strlen(unix_socket)+1 : (uint) 1,
- &mysql->server_version,
- (uint) (end - (char*) net->read_pos),
- NullS) ||
- !(mysql->user=my_strdup(user,MYF(0))) ||
- !(mysql->passwd=my_strdup(passwd,MYF(0))))
+/*
+** Note that the mysql argument must be initialized with mysql_init()
+** before calling mysql_real_connect !
+*/
+
+MYSQL * STDCALL
+mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
+ const char *passwd __attribute__((unused)), const char *db,
+ uint port, const char *unix_socket,ulong client_flag)
+{
+ char *db_name;
+ DBUG_ENTER("mysql_real_connect");
+ DBUG_PRINT("enter",("host: %s db: %s user: %s",
+ host ? host : "(Null)",
+ db ? db : "(Null)",
+ user ? user : "(Null)"));
+
+ /* use default options */
+ if (mysql->options.my_cnf_file || mysql->options.my_cnf_group)
{
- strmov(net->last_error, ER(net->last_errno=CR_OUT_OF_MEMORY));
- goto error;
+ mysql_read_default_options(&mysql->options,
+ (mysql->options.my_cnf_file ?
+ mysql->options.my_cnf_file : "my"),
+ mysql->options.my_cnf_group);
+ my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
+ my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
+ mysql->options.my_cnf_file=mysql->options.my_cnf_group=0;
}
- strmov(mysql->host_info,host_info);
- strmov(mysql->host,host);
- if (unix_socket)
- strmov(mysql->unix_socket,unix_socket);
- else
- mysql->unix_socket=0;
- strmov(mysql->server_version,(char*) net->read_pos+1);
- mysql->port=port;
- mysql->client_flag=client_flag | mysql->options.client_flag;
- DBUG_PRINT("info",("Server version = '%s' capabilites: %ld status: %d",
- mysql->server_version,mysql->server_capabilities,
- mysql->server_status));
- /* Send client information for access check */
- client_flag|=CLIENT_CAPABILITIES;
- client_flag&= ~CLIENT_COMPRESS;
- if (db)
- client_flag|=CLIENT_CONNECT_WITH_DB;
- int4store(buff,client_flag);
- mysql->client_flag=client_flag;
+ if (!db || !db[0])
+ db=mysql->options.db;
- max_allowed_packet=net->max_packet_size;
- int4store(buff+4,max_allowed_packet);
- if (user && user[0])
- strmake(buff+8,user,32);
- else
- read_user_name((char*) buff+8);
-#ifdef _CUSTOMCONFIG_
-#include "_cust_libmysql.h";
-#endif
- DBUG_PRINT("info",("user: %s",buff+8));
- end=scramble(strend(buff+8)+1, mysql->scramble_buff, passwd,
- (my_bool) (mysql->protocol_version == 9));
+ port=0;
+ unix_socket=0;
+ db_name = db ? my_strdup(db,MYF(MY_WME)) : NULL;
- if (db)
- {
- end=strmov(end+1,db);
- mysql->db=my_strdup(db,MYF(MY_WME));
- db=0;
- }
- if (my_net_write(net,buff,(ulong) (end-buff)) || net_flush(net))
- goto error;
+ mysql->thd= create_embedded_thd(client_flag, db_name);
- lib_connection_phase(net,2);
+ init_embedded_mysql(mysql, client_flag, db_name);
- if( net_safe_read(mysql) == packet_error)
- goto error;
- if (db && mysql_select_db(mysql,db))
+ if (mysql_init_charset(mysql))
goto error;
+ /* Send client information for access check */
+ client_flag|=CLIENT_CAPABILITIES;
+ client_flag&= ~CLIENT_COMPRESS;
+ if (db)
+ client_flag|=CLIENT_CONNECT_WITH_DB;
+
if (mysql->options.init_commands)
{
DYNAMIC_ARRAY *init_commands= mysql->options.init_commands;
char **ptr= (char**)init_commands->buffer;
char **end= ptr + init_commands->elements;
- my_bool reconnect=mysql->reconnect;
- mysql->reconnect=0;
-
for (; ptr<end; ptr++)
{
MYSQL_RES *res;
@@ -1044,8 +534,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
mysql_free_result(res);
}
}
-
- mysql->reconnect=reconnect;
}
DBUG_PRINT("exit",("Mysql handler: %lx",mysql));
@@ -1054,7 +542,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
error:
reset_sigpipe(mysql);
- DBUG_PRINT("error",("message: %u (%s)",net->last_errno,net->last_error));
+ DBUG_PRINT("error",("message: %u (%s)",mysql->last_errno,mysql->last_error));
{
/* Free alloced memory */
my_bool free_me=mysql->free_me;
@@ -1071,9 +559,10 @@ error:
** Change user and database
**************************************************************************/
-my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
- const char *passwd, const char *db)
+my_bool STDCALL mysql_change_user(MYSQL *mysql __attribute__((unused)), const char *user __attribute__((unused)),
+ const char *passwd __attribute__((unused)), const char *db __attribute__((unused)))
{
+#ifdef DUMMY
char buff[512],*pos=buff;
DBUG_ENTER("mysql_change_user");
@@ -1097,6 +586,8 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
mysql->passwd=my_strdup(passwd,MYF(MY_WME));
mysql->db= db ? my_strdup(db,MYF(MY_WME)) : 0;
DBUG_RETURN(0);
+#endif
+ return 0;
}
@@ -1113,8 +604,6 @@ mysql_select_db(MYSQL *mysql, const char *db)
if ((error=simple_command(mysql,COM_INIT_DB,db,(ulong) strlen(db),0)))
DBUG_RETURN(error);
- my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR));
- mysql->db=my_strdup(db,MYF(MY_WME));
DBUG_RETURN(0);
}
@@ -1130,17 +619,6 @@ mysql_close(MYSQL *mysql)
DBUG_ENTER("mysql_close");
if (mysql) /* Some simple safety */
{
- if (mysql->net.vio != 0)
- {
- free_old_query(mysql);
- mysql->status=MYSQL_STATUS_READY; /* Force command */
- simple_command(mysql,COM_QUIT,"",0,1);
- end_server(mysql);
- }
- my_free((gptr) mysql->host_info,MYF(MY_ALLOW_ZERO_PTR));
- my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR));
- my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR));
- my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.user,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.host,MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.password,MYF(MY_ALLOW_ZERO_PTR));
@@ -1161,9 +639,7 @@ mysql_close(MYSQL *mysql)
my_free((char*)init_commands,MYF(MY_WME));
}
/* Clear pointers for better safety */
- mysql->host_info=mysql->user=mysql->passwd=mysql->db=0;
bzero((char*) &mysql->options,sizeof(mysql->options));
- mysql->net.vio = 0;
#ifdef HAVE_OPENSSL
((VioConnectorFd*)(mysql->connector_fd))->delete();
mysql->connector_fd = 0;
@@ -1186,59 +662,20 @@ mysql_query(MYSQL *mysql, const char *query)
return mysql_real_query(mysql,query, (ulong) strlen(query));
}
-int STDCALL
-mysql_send_query(MYSQL* mysql, const char* query, ulong length)
-{
- return simple_command(mysql, COM_QUERY, query, length, 1);
-}
-
-
my_bool STDCALL
mysql_read_query_result(MYSQL *mysql)
{
- uchar *pos;
- ulong field_count;
- MYSQL_DATA *fields;
- uint length;
- DBUG_ENTER("mysql_read_query_result");
+ if (mysql->last_errno)
+ return -1;
- if ((length=net_safe_read(mysql)) == packet_error)
- DBUG_RETURN(1);
- free_old_query(mysql); /* Free old result */
-get_info:
- pos=(uchar*) mysql->net.read_pos;
- if ((field_count= net_field_length(&pos)) == 0)
- {
- mysql->affected_rows= net_field_length_ll(&pos);
- mysql->insert_id= net_field_length_ll(&pos);
- mysql->server_status=uint2korr(pos); pos+=2;
- mysql->warning_count=uint2korr(pos); pos+=2;
- if (pos < mysql->net.read_pos+length && net_field_length(&pos))
- mysql->info=(char*) pos;
- DBUG_RETURN(0);
- }
- if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */
+ if (mysql->field_count)
{
- int error=send_file_to_server(mysql,(char*) pos);
- if ((length=net_safe_read(mysql)) == packet_error || error)
- DBUG_RETURN(1);
- goto get_info; /* Get info packet */
+ mysql->status=MYSQL_STATUS_GET_RESULT;
+ mysql->affected_rows= mysql->result->row_count= mysql->result->data->rows;
+ mysql->result->data_cursor= mysql->result->data->data;
}
- if (!(mysql->server_status & SERVER_STATUS_AUTOCOMMIT))
- mysql->server_status|= SERVER_STATUS_IN_TRANS;
- mysql->extra_info= net_field_length_ll(&pos); /* Maybe number of rec */
- if (!(fields=read_rows(mysql,(MYSQL_FIELD*) 0,5)))
- DBUG_RETURN(1);
- if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc,
- (uint) field_count,0,
- (my_bool) test(mysql->server_capabilities &
- CLIENT_LONG_FLAG))))
- DBUG_RETURN(1);
- mysql->status=MYSQL_STATUS_GET_RESULT;
- mysql->field_count=field_count;
- mysql->warning_count= 0;
- DBUG_RETURN(0);
+ return 0;
}
/****************************************************************************
@@ -1341,6 +778,22 @@ my_bool my_connect(my_socket s, const struct sockaddr *name, uint namelen,
#endif
}
+int STDCALL
+mysql_send_query(MYSQL* mysql, const char* query, ulong length)
+{
+ DBUG_ENTER("mysql_send_query");
+
+ if (mysql->options.separate_thread)
+ {
+ return -1;
+ }
+
+ mysql->result= NULL;
+
+ free_old_query(mysql); /* Free old result */
+
+ DBUG_RETURN(simple_command(mysql, COM_QUERY, query, length, 1));
+}
int STDCALL
mysql_real_query(MYSQL *mysql, const char *query, ulong length)
@@ -1348,114 +801,43 @@ mysql_real_query(MYSQL *mysql, const char *query, ulong length)
DBUG_ENTER("mysql_real_query");
DBUG_PRINT("enter",("handle: %lx",mysql));
DBUG_PRINT("query",("Query = \"%s\"",query));
- if (mysql_send_query(mysql, query, length))
- DBUG_RETURN(-1);
- DBUG_RETURN(mysql_read_query_result(mysql));
-}
-
-static int
-send_file_to_server(MYSQL *mysql, const char *filename)
-{
- int fd, readcount;
- char buf[IO_SIZE*15],*tmp_name;
- DBUG_ENTER("send_file_to_server");
-
- fn_format(buf,filename,"","",4); /* Convert to client format */
- if (!(tmp_name=my_strdup(buf,MYF(0))))
- {
- strmov(mysql->net.last_error, ER(mysql->net.last_errno=CR_OUT_OF_MEMORY));
- DBUG_RETURN(-1);
- }
- if ((fd = my_open(tmp_name,O_RDONLY, MYF(0))) < 0)
+ if (mysql->options.separate_thread)
{
- mysql->net.last_errno=EE_FILENOTFOUND;
- sprintf(buf,EE(mysql->net.last_errno),tmp_name,errno);
- strmake(mysql->net.last_error,buf,sizeof(mysql->net.last_error)-1);
- my_net_write(&mysql->net,"",0); net_flush(&mysql->net);
- my_free(tmp_name,MYF(0));
- DBUG_RETURN(-1);
+ return -1;
}
- while ((readcount = (int) my_read(fd,buf,sizeof(buf),MYF(0))) > 0)
- {
- if (my_net_write(&mysql->net,buf,readcount))
- {
- mysql->net.last_errno=CR_SERVER_LOST;
- strmov(mysql->net.last_error,ER(mysql->net.last_errno));
- DBUG_PRINT("error",("Lost connection to MySQL server during LOAD DATA of local file"));
- (void) my_close(fd,MYF(0));
- my_free(tmp_name,MYF(0));
- DBUG_RETURN(-1);
- }
- }
- (void) my_close(fd,MYF(0));
- /* Send empty packet to mark end of file */
- if (my_net_write(&mysql->net,"",0) || net_flush(&mysql->net))
- {
- mysql->net.last_errno=CR_SERVER_LOST;
- sprintf(mysql->net.last_error,ER(mysql->net.last_errno),errno);
- my_free(tmp_name,MYF(0));
- DBUG_RETURN(-1);
- }
- if (readcount < 0)
- {
- mysql->net.last_errno=EE_READ; /* the errmsg for not entire file read */
- sprintf(buf,EE(mysql->net.last_errno),tmp_name,errno);
- strmake(mysql->net.last_error,buf,sizeof(mysql->net.last_error)-1);
- my_free(tmp_name,MYF(0));
+ mysql->result= NULL;
+
+ free_old_query(mysql); /* Free old result */
+
+ if (simple_command(mysql, COM_QUERY, query, length, 1))
DBUG_RETURN(-1);
- }
- DBUG_RETURN(0);
-}
+ DBUG_RETURN(mysql_read_query_result(mysql));
+}
/**************************************************************************
** Alloc result struct for buffered results. All rows are read to buffer.
** mysql_data_seek may be used.
**************************************************************************/
-
MYSQL_RES * STDCALL
mysql_store_result(MYSQL *mysql)
{
- MYSQL_RES *result;
- DBUG_ENTER("mysql_store_result");
+ MYSQL_RES *result= mysql->result;
+ if (!result)
+ return 0;
- if (!mysql->fields)
- DBUG_RETURN(0);
- if (mysql->status != MYSQL_STATUS_GET_RESULT)
- {
- strmov(mysql->net.last_error,
- ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC));
- DBUG_RETURN(0);
- }
- mysql->status=MYSQL_STATUS_READY; /* server is ready */
- if (!(result=(MYSQL_RES*) my_malloc(sizeof(MYSQL_RES)+
- sizeof(ulong)*mysql->field_count,
- MYF(MY_WME | MY_ZEROFILL))))
- {
- mysql->net.last_errno=CR_OUT_OF_MEMORY;
- strmov(mysql->net.last_error, ER(mysql->net.last_errno));
- DBUG_RETURN(0);
- }
- result->eof=1; /* Marker for buffered */
- result->lengths=(ulong*) (result+1);
- if (!(result->data=read_rows(mysql,mysql->fields,mysql->field_count)))
- {
- my_free((gptr) result,MYF(0));
- DBUG_RETURN(0);
- }
+ mysql->result= NULL;
+ *result->data->prev_ptr= 0;
+ result->eof= 1;
+ result->lengths= (ulong*)(result + 1);
mysql->affected_rows= result->row_count= result->data->rows;
- result->data_cursor= result->data->data;
- result->fields= mysql->fields;
- result->field_alloc= mysql->field_alloc;
- result->field_count= mysql->field_count;
- result->current_field=0;
- result->current_row=0; /* Must do a fetch first */
- mysql->fields=0; /* fields is now in result */
- DBUG_RETURN(result); /* Data fetched */
-}
+ result->data_cursor= result->data->data;
+ mysql->status=MYSQL_STATUS_READY; /* server is ready */
+ return result;
+}
/**************************************************************************
** Alloc struct for use with unbuffered reads. Data is fetched by domand
@@ -1470,40 +852,12 @@ mysql_store_result(MYSQL *mysql)
MYSQL_RES * STDCALL
mysql_use_result(MYSQL *mysql)
{
- MYSQL_RES *result;
DBUG_ENTER("mysql_use_result");
-
- if (!mysql->fields)
+ if (mysql->options.separate_thread)
DBUG_RETURN(0);
- if (mysql->status != MYSQL_STATUS_GET_RESULT)
- {
- strmov(mysql->net.last_error,
- ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC));
- DBUG_RETURN(0);
- }
- if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result)+
- sizeof(ulong)*mysql->field_count,
- MYF(MY_WME | MY_ZEROFILL))))
- DBUG_RETURN(0);
- result->lengths=(ulong*) (result+1);
- if (!(result->row=(MYSQL_ROW)
- my_malloc(sizeof(result->row[0])*(mysql->field_count+1), MYF(MY_WME))))
- { /* Ptrs: to one row */
- my_free((gptr) result,MYF(0));
- DBUG_RETURN(0);
- }
- result->fields= mysql->fields;
- result->field_alloc= mysql->field_alloc;
- result->field_count= mysql->field_count;
- result->current_field=0;
- result->handle= mysql;
- result->current_row= 0;
- mysql->fields=0; /* fields is now in result */
- mysql->status=MYSQL_STATUS_USE_RESULT;
- DBUG_RETURN(result); /* Data is read to be fetched */
-}
-
+ DBUG_RETURN(mysql_store_result(mysql));
+}
/**************************************************************************
** Return next field of the query results
@@ -1526,24 +880,6 @@ MYSQL_ROW STDCALL
mysql_fetch_row(MYSQL_RES *res)
{
DBUG_ENTER("mysql_fetch_row");
- if (!res->data)
- { /* Unbufferred fetch */
- if (!res->eof)
- {
- if (!(read_one_row(res->handle,res->field_count,res->row, res->lengths)))
- {
- res->row_count++;
- DBUG_RETURN(res->current_row=res->row);
- }
- else
- {
- DBUG_PRINT("info",("end of data"));
- res->eof=1;
- res->handle->status=MYSQL_STATUS_READY;
- }
- }
- DBUG_RETURN((MYSQL_ROW) NULL);
- }
{
MYSQL_ROW tmp;
if (!res->data_cursor)
@@ -1557,6 +893,7 @@ mysql_fetch_row(MYSQL_RES *res)
}
}
+
/**************************************************************************
** Get column lengths of the current row
** If one uses mysql_use_result, res->lengths contains the length information,
@@ -1566,28 +903,17 @@ mysql_fetch_row(MYSQL_RES *res)
ulong * STDCALL
mysql_fetch_lengths(MYSQL_RES *res)
{
- ulong *lengths,*prev_length;
- byte *start;
+ ulong *lengths;
MYSQL_ROW column,end;
if (!(column=res->current_row))
return 0; /* Something is wrong */
if (res->data)
{
- start=0;
- prev_length=0; /* Keep gcc happy */
lengths=res->lengths;
- for (end=column+res->field_count+1 ; column != end ; column++,lengths++)
+ for (end=column+res->field_count; column != end ; column++,lengths++)
{
- if (!*column)
- {
- *lengths=0; /* Null */
- continue;
- }
- if (start) /* Found end of prev string */
- *prev_length= (uint) (*column-start-1);
- start= *column;
- prev_length=lengths;
+ *lengths= *column ? strlen(*column) : 0;
}
}
return res->lengths;
@@ -1675,8 +1001,9 @@ mysql_list_tables(MYSQL *mysql, const char *wild)
**************************************************************************/
MYSQL_RES * STDCALL
-mysql_list_fields(MYSQL *mysql, const char *table, const char *wild)
+mysql_list_fields(MYSQL *mysql __attribute__((unused)), const char *table __attribute__((unused)), const char *wild __attribute__((unused)))
{
+#ifdef DUMMY
MYSQL_RES *result;
MYSQL_DATA *query;
char buff[257],*end;
@@ -1706,9 +1033,12 @@ mysql_list_fields(MYSQL *mysql, const char *table, const char *wild)
CLIENT_LONG_FLAG));
result->eof=1;
DBUG_RETURN(result);
+#endif
+ return 0;
}
/* List all running processes (threads) in server */
+#ifdef DUMMY
MYSQL_RES * STDCALL
mysql_list_processes(MYSQL *mysql)
@@ -1733,7 +1063,9 @@ mysql_list_processes(MYSQL *mysql)
mysql->status=MYSQL_STATUS_GET_RESULT;
mysql->field_count=field_count;
DBUG_RETURN(mysql_store_result(mysql));
+ return (MYSQL_RES*)mysql;
}
+#endif /*DUMMY*/
int STDCALL
@@ -1791,9 +1123,10 @@ mysql_dump_debug_info(MYSQL *mysql)
const char * STDCALL
mysql_stat(MYSQL *mysql)
{
+#ifdef DUMMY
DBUG_ENTER("mysql_stat");
if (simple_command(mysql,COM_STATISTICS,"",0,0))
- return mysql->net.last_error;
+ return mysql->last_error;
mysql->net.read_pos[mysql->packet_length]=0; /* End of stat string */
if (!mysql->net.read_pos[0])
{
@@ -1802,6 +1135,8 @@ mysql_stat(MYSQL *mysql)
return mysql->net.last_error;
}
DBUG_RETURN((char*) mysql->net.read_pos);
+#endif
+ return (char *)mysql;
}
@@ -1814,23 +1149,23 @@ mysql_ping(MYSQL *mysql)
const char * STDCALL
-mysql_get_server_info(MYSQL *mysql)
+mysql_get_server_info(MYSQL *mysql __attribute__((unused)))
{
- return((char*) mysql->server_version);
+ return MYSQL_SERVER_VERSION;
}
const char * STDCALL
-mysql_get_host_info(MYSQL *mysql)
+mysql_get_host_info(MYSQL *mysql __attribute__((unused)))
{
- return(mysql->host_info);
+ return "localhost";
}
uint STDCALL
-mysql_get_proto_info(MYSQL *mysql)
+mysql_get_proto_info(MYSQL *mysql __attribute__((unused)))
{
- return (mysql->protocol_version);
+ return PROTOCOL_VERSION;
}
const char * STDCALL
@@ -1852,6 +1187,9 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg)
case MYSQL_OPT_COMPRESS:
mysql->options.compress=1; /* Remember for connect */
break;
+ case MYSQL_OPT_USE_RESULT:
+ mysql->options.separate_thread=1; /* Use separate thread for query execution*/
+ break;
case MYSQL_OPT_NAMED_PIPE:
mysql->options.protocol=MYSQL_PROTOCOL_PIPE; /* Force named pipe */
break;
@@ -1951,27 +1289,28 @@ my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql)
uint STDCALL mysql_errno(MYSQL *mysql)
{
- return (mysql)->net.last_errno;
+ return mysql->last_errno;
}
const char * STDCALL mysql_error(MYSQL *mysql)
{
- return (mysql)->net.last_error;
+ return mysql->last_error;
}
-uint STDCALL mysql_warning_count(MYSQL *mysql)
-{
- return mysql->warning_count;
-}
-
-const char *STDCALL mysql_info(MYSQL *mysql)
+const char *STDCALL mysql_info(MYSQL *mysql __attribute__((unused)))
{
+#ifdef DUMMY
return (mysql)->info;
+#endif
+ return 0;
}
-ulong STDCALL mysql_thread_id(MYSQL *mysql)
+ulong STDCALL mysql_thread_id(MYSQL *mysql __attribute__((unused)))
{
+#ifdef DUMMY
return (mysql)->thread_id;
+#endif
+ return 0;
}
const char * STDCALL mysql_character_set_name(MYSQL *mysql)
@@ -1994,10 +1333,9 @@ MYSQL_RES *STDCALL mysql_warnings(MYSQL *mysql)
uint warning_count;
DBUG_ENTER("mysql_warnings");
/* Save warning count as mysql_real_query may change this */
- warning_count= mysql->warning_count;
+ warning_count= mysql_warning_count(mysql);
if (mysql_real_query(mysql, "SHOW WARNINGS", 13))
DBUG_RETURN(0);
- mysql->warning_count= warning_count;
DBUG_RETURN(mysql_store_result(mysql));
}
diff --git a/myisam/ft_boolean_search.c b/myisam/ft_boolean_search.c
index 6749de06ee2..190dc5206b1 100644
--- a/myisam/ft_boolean_search.c
+++ b/myisam/ft_boolean_search.c
@@ -21,6 +21,7 @@
#define FT_CORE
#include "ftdefs.h"
#include <queues.h>
+#include <assert.h> /* for DBUG_ASSERT() */
/* search with boolean queries */
@@ -63,42 +64,44 @@ struct st_ftb_expr
{
FTB_EXPR *up;
byte *quot, *qend;
- float weight;
- uint flags;
my_off_t docid[2]; /* for index search and for scan */
+ float weight;
float cur_weight;
- int yesses; /* number of "yes" words matched */
- int nos; /* number of "no" words matched */
- int ythresh; /* number of "yes" words in expr */
- int yweaks; /* number of "yes" words for scan only */
+ uint flags;
+ uint yesses; /* number of "yes" words matched */
+ uint nos; /* number of "no" words matched */
+ uint ythresh; /* number of "yes" words in expr */
+ uint yweaks; /* number of "yes" words for scan only */
};
typedef struct st_ftb_word
{
- FTB_EXPR *up;
- float weight;
- uint flags;
- my_off_t docid[2]; /* for index search and for scan */
- uint ndepth;
- int len;
- /* ... docid cache can be added here. SerG */
- byte word[1];
+ FTB_EXPR *up;
+ MI_KEYDEF *keyinfo;
+ my_off_t docid[2]; /* for index search and for scan */
+ my_off_t key_root;
+ float weight;
+ uint ndepth;
+ uint flags;
+ uint len;
+ uchar off;
+ byte word[1];
} FTB_WORD;
typedef struct st_ft_info
{
struct _ft_vft *please;
MI_INFO *info;
- uint keynr;
CHARSET_INFO *charset;
- enum { UNINITIALIZED, READY, INDEX_SEARCH, INDEX_DONE /*, SCAN*/ } state;
- uint with_scan;
- my_off_t lastpos;
FTB_EXPR *root;
- QUEUE queue;
- TREE no_dupes;
FTB_WORD **list;
MEM_ROOT mem_root;
+ QUEUE queue;
+ TREE no_dupes;
+ my_off_t lastpos;
+ uint keynr;
+ uchar with_scan;
+ enum { UNINITIALIZED, READY, INDEX_SEARCH, INDEX_DONE } state;
} FTB;
static int FTB_WORD_cmp(my_off_t *v, FTB_WORD *a, FTB_WORD *b)
@@ -160,6 +163,7 @@ static void _ftb_parse_query(FTB *ftb, byte **start, byte *end,
ftbw->up=up;
ftbw->docid[0]=ftbw->docid[1]=HA_POS_ERROR;
ftbw->ndepth= (param.yesno<0) + depth;
+ ftbw->key_root=HA_POS_ERROR;
memcpy(ftbw->word+1, w.pos, w.len);
ftbw->word[0]=w.len;
if (param.yesno > 0) up->ythresh++;
@@ -194,22 +198,98 @@ static int _ftb_no_dupes_cmp(void* not_used __attribute__((unused)),
return CMP_NUM((*((my_off_t*)a)), (*((my_off_t*)b)));
}
+/* returns 1 if the search was finished (must-word wasn't found) */
+static int _ft2_search(FTB *ftb, FTB_WORD *ftbw, my_bool init_search)
+{
+ int r;
+ uint off;
+ int subkeys;
+ MI_INFO *info=ftb->info;
+
+ if (init_search)
+ {
+ ftbw->key_root=info->s->state.key_root[ftb->keynr];
+ ftbw->keyinfo=info->s->keyinfo+ftb->keynr;
+ ftbw->off=0;
+
+ r=_mi_search(info, ftbw->keyinfo, (uchar*) ftbw->word, ftbw->len,
+ SEARCH_FIND | SEARCH_BIGGER, ftbw->key_root);
+ }
+ else
+ {
+ r=_mi_search(info, ftbw->keyinfo, (uchar*) ftbw->word+ftbw->off,
+ USE_WHOLE_KEY, SEARCH_BIGGER, ftbw->key_root);
+ }
+ if (!r && !ftbw->off)
+ {
+ r= mi_compare_text(ftb->charset,
+ info->lastkey + (ftbw->flags & FTB_FLAG_TRUNC),
+ ftbw->len - (ftbw->flags & FTB_FLAG_TRUNC),
+ (uchar*) ftbw->word + (ftbw->flags & FTB_FLAG_TRUNC),
+ ftbw->len - (ftbw->flags & FTB_FLAG_TRUNC),
+ 0);
+ }
+
+ if (r) /* not found */
+ {
+ if (!ftbw->off || !(ftbw->flags & FTB_FLAG_TRUNC))
+ {
+ ftbw->docid[0]=HA_POS_ERROR;
+ if ((ftbw->flags & FTB_FLAG_YES) && ftbw->up->up==0)
+ {
+ /*
+ This word MUST BE present in every document returned,
+ so we can stop the search right now
+ */
+ ftb->state=INDEX_DONE;
+ return 1; /* search is done */
+ }
+ else
+ return 0;
+ }
+
+ /* going up to the first-level tree to continue search there */
+ _mi_dpointer(info, ftbw->word+ftbw->off+HA_FT_WLEN, ftbw->key_root);
+ ftbw->key_root=info->s->state.key_root[ftb->keynr];
+ ftbw->keyinfo=info->s->keyinfo+ftb->keynr;
+ ftbw->off=0;
+ return _ft2_search(ftb, ftbw, 0);
+ }
+
+ /* matching key found */
+ memcpy(ftbw->word+ftbw->off, info->lastkey, info->lastkey_length);
+ if (!ftbw->off && (init_search || (ftbw->flags & FTB_FLAG_TRUNC)))
+ {
+ /* going down ? */
+ get_key_full_length_rdonly(off, info->lastkey);
+ subkeys=ft_sintXkorr(info->lastkey+off);
+ if (subkeys<0)
+ {
+ /* yep, going down, to the second-level tree */
+ /* TODO here: subkey-based optimization */
+ ftbw->off=off;
+ ftbw->key_root=info->lastpos;
+ ftbw->keyinfo=& info->s->ft2_keyinfo;
+ r=_mi_search_first(info, ftbw->keyinfo, ftbw->key_root);
+ DBUG_ASSERT(r==0); /* found something */
+ memcpy(ftbw->word+off, info->lastkey, info->lastkey_length);
+ }
+ }
+ ftbw->docid[0]=info->lastpos;
+ return 0;
+}
+
static void _ftb_init_index_search(FT_INFO *ftb)
{
- int i, r;
+ int i;
FTB_WORD *ftbw;
MI_INFO *info=ftb->info;
- MI_KEYDEF *keyinfo;
- my_off_t keyroot;
if ((ftb->state != READY && ftb->state !=INDEX_DONE) ||
ftb->keynr == NO_SUCH_KEY)
return;
ftb->state=INDEX_SEARCH;
- keyinfo=info->s->keyinfo+ftb->keynr;
- keyroot=info->s->state.key_root[ftb->keynr];
-
for (i=ftb->queue.elements; i; i--)
{
ftbw=(FTB_WORD *)(ftb->queue.root[i]);
@@ -248,34 +328,9 @@ static void _ftb_init_index_search(FT_INFO *ftb)
}
}
}
- r=_mi_search(info, keyinfo, (uchar*) ftbw->word, ftbw->len,
- SEARCH_FIND | SEARCH_BIGGER, keyroot);
- if (!r)
- {
- r= mi_compare_text(ftb->charset,
- info->lastkey + (ftbw->flags&FTB_FLAG_TRUNC),
- ftbw->len - (ftbw->flags&FTB_FLAG_TRUNC),
- (uchar*) ftbw->word + (ftbw->flags&FTB_FLAG_TRUNC),
- ftbw->len - (ftbw->flags&FTB_FLAG_TRUNC),
- 0);
- }
- if (r) /* not found */
- {
- if (ftbw->flags&FTB_FLAG_YES && ftbw->up->up==0)
- {
- /*
- This word MUST BE present in every document returned,
- so we can abort the search right now
- */
- ftb->state=INDEX_DONE;
- return;
- }
- }
- else
- {
- memcpy(ftbw->word, info->lastkey, info->lastkey_length);
- ftbw->docid[0]=info->lastpos;
- }
+
+ if (_ft2_search(ftb, ftbw, 1))
+ return;
}
queue_fix(& ftb->queue);
}
@@ -436,10 +491,7 @@ int ft_boolean_read_next(FT_INFO *ftb, char *record)
FTB_EXPR *ftbe;
FTB_WORD *ftbw;
MI_INFO *info=ftb->info;
- MI_KEYDEF *keyinfo=info->s->keyinfo+ftb->keynr;
- my_off_t keyroot=info->s->state.key_root[ftb->keynr];
my_off_t curdoc;
- int r;
if (ftb->state != INDEX_SEARCH && ftb->state != INDEX_DONE)
return -1;
@@ -466,34 +518,7 @@ int ft_boolean_read_next(FT_INFO *ftb, char *record)
_ftb_climb_the_tree(ftb, ftbw, 0);
/* update queue */
- r=_mi_search(info, keyinfo, (uchar*) ftbw->word, USE_WHOLE_KEY,
- SEARCH_BIGGER , keyroot);
- if (!r)
- {
- r= mi_compare_text(ftb->charset,
- info->lastkey + (ftbw->flags&FTB_FLAG_TRUNC),
- ftbw->len - (ftbw->flags&FTB_FLAG_TRUNC),
- (uchar*) ftbw->word + (ftbw->flags&FTB_FLAG_TRUNC),
- ftbw->len - (ftbw->flags&FTB_FLAG_TRUNC),
- 0);
- }
- if (r) /* not found */
- {
- ftbw->docid[0]=HA_POS_ERROR;
- if (ftbw->flags&FTB_FLAG_YES && ftbw->up->up==0)
- {
- /*
- This word MUST BE present in every document returned,
- so we can stop the search right now
- */
- ftb->state=INDEX_DONE;
- }
- }
- else
- {
- memcpy(ftbw->word, info->lastkey, info->lastkey_length);
- ftbw->docid[0]=info->lastpos;
- }
+ _ft2_search(ftb, ftbw, 0);
queue_replaced(& ftb->queue);
}
@@ -503,9 +528,9 @@ int ft_boolean_read_next(FT_INFO *ftb, char *record)
{
/* curdoc matched ! */
if (is_tree_inited(&ftb->no_dupes) &&
- tree_insert(&ftb->no_dupes, &curdoc, 0,
+ tree_insert(&ftb->no_dupes, &curdoc, 0,
ftb->no_dupes.custom_arg)->count >1)
- /* but it managed to get past this line once */
+ /* but it managed already to get past this line once */
continue;
info->lastpos=curdoc;
diff --git a/myisam/ft_dump.c b/myisam/ft_dump.c
index d430b611836..3ecb0652eea 100644
--- a/myisam/ft_dump.c
+++ b/myisam/ft_dump.c
@@ -56,7 +56,7 @@ static struct my_option my_long_options[] =
int main(int argc,char *argv[])
{
- int error=0;
+ int error=0, subkeys;
uint keylen, keylen2=0, inx, doc_cnt=0;
float weight;
double gws, min_gws=0, avg_gws=0;
@@ -125,7 +125,9 @@ int main(int argc,char *argv[])
keylen=*(info->lastkey);
#if HA_FT_WTYPE == HA_KEYTYPE_FLOAT
- mi_float4get(weight,info->lastkey+keylen+1);
+ subkeys=mi_sint4korr(info->lastkey+keylen+1);
+ if (subkeys >= 0)
+ weight=*(float*)&subkeys;
#else
#error
#endif
@@ -164,7 +166,10 @@ int main(int argc,char *argv[])
}
}
if (dump)
- printf("%9qx %20.7f %s\n",info->lastpos,weight,buf);
+ if (subkeys>=0)
+ printf("%9qx %20.7f %s\n",info->lastpos,weight,buf);
+ else
+ printf("%9qx => %17d %s\n",info->lastpos,-subkeys,buf);
if(verbose && (total%HOW_OFTEN_TO_WRITE)==0)
printf("%10ld\r",total);
@@ -216,18 +221,18 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
{
switch(optid) {
case 'd':
- dump=1;
+ dump=1;
complain(count || query);
break;
- case 's':
- stats=1;
+ case 's':
+ stats=1;
complain(query!=0);
break;
- case 'c':
+ case 'c':
count= 1;
complain(dump || query);
break;
- case 'l':
+ case 'l':
lstats=1;
complain(query!=0);
break;
diff --git a/myisam/ft_nlq_search.c b/myisam/ft_nlq_search.c
index 858a8dcbe06..b1d7d67ae79 100644
--- a/myisam/ft_nlq_search.c
+++ b/myisam/ft_nlq_search.c
@@ -42,8 +42,6 @@ typedef struct st_all_in_one
uint keynr;
CHARSET_INFO *charset;
uchar *keybuff;
- MI_KEYDEF *keyinfo;
- my_off_t key_root;
TREE dtree;
} ALL_IN_ONE;
@@ -66,13 +64,14 @@ static int FT_SUPERDOC_cmp(void* cmp_arg __attribute__((unused)),
static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio)
{
+ int subkeys;
uint keylen, r, doc_cnt;
-#ifdef EVAL_RUN
- uint cnt;
- double sum, sum2, suml;
-#endif /* EVAL_RUN */
FT_SUPERDOC sdoc, *sptr;
TREE_ELEMENT *selem;
+ MI_INFO *info=aio->info;
+ uchar *keybuff=aio->keybuff;
+ MI_KEYDEF *keyinfo=info->s->keyinfo+aio->keynr;
+ my_off_t key_root=info->s->state.key_root[aio->keynr];
#if HA_FT_WTYPE == HA_KEYTYPE_FLOAT
float tmp_weight;
#else
@@ -83,45 +82,45 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio)
word->weight=LWS_FOR_QUERY;
- keylen=_ft_make_key(aio->info,aio->keynr,(char*) aio->keybuff,word,0);
-#ifdef EVAL_RUN
- keylen-=1+HA_FT_WLEN;
-#else /* EVAL_RUN */
+ keylen=_ft_make_key(info,aio->keynr,(char*) keybuff,word,0);
keylen-=HA_FT_WLEN;
-#endif /* EVAL_RUN */
-
-#ifdef EVAL_RUN
- sum=sum2=suml=
-#endif /* EVAL_RUN */
doc_cnt=0;
- r=_mi_search(aio->info, aio->keyinfo, aio->keybuff, keylen,
- SEARCH_FIND | SEARCH_PREFIX, aio->key_root);
- aio->info->update|= HA_STATE_AKTIV; /* for _mi_test_if_changed() */
+ r=_mi_search(info, keyinfo, keybuff, keylen, SEARCH_FIND, key_root);
+ info->update|= HA_STATE_AKTIV; /* for _mi_test_if_changed() */
while (!r)
{
- if (mi_compare_text(aio->charset,
- aio->info->lastkey,keylen,
- aio->keybuff,keylen,0))
+
+ if (keylen &&
+ mi_compare_text(aio->charset,info->lastkey,keylen, keybuff,keylen,0))
break;
+ subkeys=ft_sintXkorr(info->lastkey+keylen);
+ if (subkeys<0)
+ {
+ if (doc_cnt)
+ DBUG_RETURN(1); /* index is corrupted */
+ /*
+ TODO here: unsafe optimization, should this word
+ be skipped (based on subkeys) ?
+ */
+ keybuff+=keylen;
+ keyinfo=& info->s->ft2_keyinfo;
+ key_root=info->lastpos;
+ keylen=0;
+ r=_mi_search_first(info, keyinfo, key_root);
+ continue;
+ }
#if HA_FT_WTYPE == HA_KEYTYPE_FLOAT
-#ifdef EVAL_RUN
- mi_float4get(tmp_weight,aio->info->lastkey+keylen+1);
-#else /* EVAL_RUN */
- mi_float4get(tmp_weight,aio->info->lastkey+keylen);
-#endif /* EVAL_RUN */
+ tmp_weight=*(float*)&subkeys;
#else
#error
#endif
- if(tmp_weight==0) DBUG_RETURN(doc_cnt); /* stopword, doc_cnt should be 0 */
+ if (tmp_weight==0)
+ DBUG_RETURN(doc_cnt); /* stopword, doc_cnt should be 0 */
-#ifdef EVAL_RUN
- cnt=*(byte *)(aio->info->lastkey+keylen);
-#endif /* EVAL_RUN */
-
- sdoc.doc.dpos=aio->info->lastpos;
+ sdoc.doc.dpos=info->lastpos;
/* saving document matched into dtree */
if (!(selem=tree_insert(&aio->dtree, &sdoc, 0, aio->dtree.custom_arg)))
@@ -138,20 +137,13 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio)
sptr->tmp_weight=tmp_weight;
doc_cnt++;
-#ifdef EVAL_RUN
- sum +=cnt;
- sum2+=cnt*cnt;
- suml+=cnt*log(cnt);
-#endif /* EVAL_RUN */
-
- if (_mi_test_if_changed(aio->info) == 0)
- r=_mi_search_next(aio->info, aio->keyinfo, aio->info->lastkey,
- aio->info->lastkey_length, SEARCH_BIGGER,
- aio->key_root);
+
+ if (_mi_test_if_changed(info) == 0)
+ r=_mi_search_next(info, keyinfo, info->lastkey, info->lastkey_length,
+ SEARCH_BIGGER, key_root);
else
- r=_mi_search(aio->info, aio->keyinfo, aio->info->lastkey,
- aio->info->lastkey_length, SEARCH_BIGGER,
- aio->key_root);
+ r=_mi_search(info, keyinfo, info->lastkey, info->lastkey_length,
+ SEARCH_BIGGER, key_root);
}
if (doc_cnt)
{
@@ -201,10 +193,8 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, byte *query,
aio.info=info;
aio.keynr=keynr;
- aio.keyinfo=info->s->keyinfo+keynr;
- aio.charset=aio.keyinfo->seg->charset;
+ aio.charset=info->s->keyinfo[keynr].seg->charset;
aio.keybuff=info->lastkey+info->s->base.max_key_length;
- aio.key_root=info->s->state.key_root[keynr];
bzero(&allocated_wtree,sizeof(allocated_wtree));
diff --git a/myisam/ft_parser.c b/myisam/ft_parser.c
index 358706a8ffa..14c67333734 100644
--- a/myisam/ft_parser.c
+++ b/myisam/ft_parser.c
@@ -18,21 +18,10 @@
#include "ftdefs.h"
-#ifdef EVAL_RUN
-#ifdef PIVOT_STAT
-ulong collstat=0;
-#endif
-#endif /* EVAL_RUN */
-
typedef struct st_ft_docstat {
FT_WORD *list;
uint uniq;
double sum;
-#ifdef EVAL_RUN
- uint words, totlen;
- double max, nsum, nsum2;
-#endif /* EVAL_RUN */
-
} FT_DOCSTAT;
static int FT_WORD_cmp(CHARSET_INFO* cs, FT_WORD *w1, FT_WORD *w2)
@@ -44,15 +33,7 @@ static int FT_WORD_cmp(CHARSET_INFO* cs, FT_WORD *w1, FT_WORD *w2)
static int walk_and_copy(FT_WORD *word,uint32 count,FT_DOCSTAT *docstat)
{
word->weight=LWS_IN_USE;
-
-#ifdef EVAL_RUN
- word->cnt= (uchar) count;
- if(docstat->max < word->weight) docstat->max=word->weight;
- docstat->words+=count;
- docstat->totlen+=word->len;
-#endif /* EVAL_RUN */
docstat->sum+=word->weight;
-
memcpy_fixed((docstat->list)++,word,sizeof(FT_WORD));
return 0;
}
@@ -70,9 +51,6 @@ FT_WORD * ft_linearize(TREE *wtree)
{
docstat.list=wlist;
docstat.uniq=wtree->elements_in_tree;
-#ifdef EVAL_RUN
- docstat.nsum=docstat.nsum2=docstat.max=docstat.words=docstat.totlen=
-#endif /* EVAL_RUN */
docstat.sum=0;
tree_walk(wtree,(tree_walk_action)&walk_and_copy,&docstat,left_root_right);
}
@@ -85,18 +63,8 @@ FT_WORD * ft_linearize(TREE *wtree)
for (p=wlist;p->pos;p++)
{
p->weight=PRENORM_IN_USE;
-#ifdef EVAL_RUN
- docstat.nsum+=p->weight;
- docstat.nsum2+=p->weight*p->weight;
-#endif /* EVAL_RUN */
}
-#ifdef EVAL_RUN
-#ifdef PIVOT_STAT
- collstat+=PIVOT_STAT;
-#endif
-#endif /* EVAL_RUN */
-
for (p=wlist;p->pos;p++)
{
p->weight/=NORM_IN_USE;
diff --git a/myisam/ft_static.c b/myisam/ft_static.c
index 5c2629e9e9e..b714a7f0c35 100644
--- a/myisam/ft_static.c
+++ b/myisam/ft_static.c
@@ -26,25 +26,21 @@ const char *ft_boolean_syntax="+ -><()~*:\"\"&|";
const HA_KEYSEG ft_keysegs[FT_SEGS]={
{
HA_KEYTYPE_VARTEXT, /* type */
- 7, /* language (will be overwritten) */
+ 63, /* language (will be overwritten) */
0, 0, 0, /* null_bit, bit_start, bit_end */
HA_VAR_LENGTH | HA_PACK_KEY, /* flag */
HA_FT_MAXLEN, /* length */
-#ifdef EVAL_RUN
- HA_FT_WLEN+1, /* start */
-#else /* EVAL_RUN */
HA_FT_WLEN, /* start */
-#endif /* EVAL_RUN */
0, /* null_pos */
NULL /* charset */
},
-#ifdef EVAL_RUN
{
- HA_KEYTYPE_INT8, 7, 0, 0, 0, 0, 1, HA_FT_WLEN, 0, NULL
- },
-#endif /* EVAL_RUN */
- {
- HA_FT_WTYPE, 7, 0, 0, 0, HA_NO_SORT, HA_FT_WLEN, 0, 0, NULL
+/*
+ Note, this (and the last HA_KEYTYPE_END) segment should NOT
+ be packed in any way, otherwise w_search() won't be able to
+ update key entry 'in vivo'
+*/
+ HA_FT_WTYPE, 63, 0, 0, 0, HA_NO_SORT, HA_FT_WLEN, 0, 0, NULL
}
};
diff --git a/myisam/ft_update.c b/myisam/ft_update.c
index 41876028104..4b6d1c4bffc 100644
--- a/myisam/ft_update.c
+++ b/myisam/ft_update.c
@@ -31,7 +31,7 @@
void _mi_ft_segiterator_init(MI_INFO *info, uint keynr, const byte *record,
FT_SEG_ITERATOR *ftsi)
{
- ftsi->num=info->s->keyinfo[keynr].keysegs-FT_SEGS;
+ ftsi->num=info->s->keyinfo[keynr].keysegs;
ftsi->seg=info->s->keyinfo[keynr].seg;
ftsi->rec=record;
}
@@ -113,7 +113,7 @@ FT_WORD * _mi_ft_parserecord(MI_INFO *info, uint keynr,
if (_mi_ft_parse(&ptree, info, keynr, record))
return NULL;
- return ft_linearize(/*info, keynr, keybuf, */ &ptree);
+ return ft_linearize(&ptree);
}
static int _mi_ft_store(MI_INFO *info, uint keynr, byte *keybuf,
@@ -267,13 +267,7 @@ uint _ft_make_key(MI_INFO *info, uint keynr, byte *keybuf, FT_WORD *wptr,
#error
#endif
-#ifdef EVAL_RUN
- *(buf+HA_FT_WLEN)=wptr->cnt;
- int2store(buf+HA_FT_WLEN+1,wptr->len);
- memcpy(buf+HA_FT_WLEN+3,wptr->pos,wptr->len);
-#else /* EVAL_RUN */
int2store(buf+HA_FT_WLEN,wptr->len);
memcpy(buf+HA_FT_WLEN+2,wptr->pos,wptr->len);
-#endif /* EVAL_RUN */
return _mi_make_key(info,keynr,(uchar*) keybuf,buf,filepos);
}
diff --git a/myisam/ftdefs.h b/myisam/ftdefs.h
index 592b60a0133..88d7e79937b 100644
--- a/myisam/ftdefs.h
+++ b/myisam/ftdefs.h
@@ -60,16 +60,6 @@
#define NORM_SUM (docstat.nsum)
#define NORM_COS (sqrt(docstat.nsum2))
-#ifdef EVAL_RUN
-/*
-extern ulong collstat;
-#define PIVOT_STAT (docstat.uniq)
-#define PIVOT_SLOPE (0.69)
-#define PIVOT_PIVOT ((double)collstat/(info->state->records+1))
-#define NORM_PIVOT ((1-PIVOT_SLOPE)*PIVOT_PIVOT+PIVOT_SLOPE*docstat.uniq)
-*/
-#endif /* EVAL_RUN */
-
#define PIVOT_VAL (0.0115)
#define NORM_PIVOT (1+PIVOT_VAL*docstat.uniq)
/*---------------------------------------------------------------*/
@@ -102,9 +92,6 @@ typedef struct st_ft_word {
byte * pos;
uint len;
double weight;
-#ifdef EVAL_RUN
- byte cnt;
-#endif /* EVAL_RUN */
} FT_WORD;
typedef struct st_ftb_param {
diff --git a/myisam/fulltext.h b/myisam/fulltext.h
index 39801c1c87e..ec267eb3e86 100644
--- a/myisam/fulltext.h
+++ b/myisam/fulltext.h
@@ -21,19 +21,16 @@
#include "myisamdef.h"
#include "ft_global.h"
-/* shoudn't be def'ed when linking with mysql */
-#undef EVAL_RUN
-
#define HA_FT_WTYPE HA_KEYTYPE_FLOAT
#define HA_FT_WLEN 4
-#ifdef EVAL_RUN
-#define FT_SEGS 3
-#else /* EVAL_RUN */
#define FT_SEGS 2
-#endif /* EVAL_RUN */
+
+#define ft_sintXkorr(A) mi_sint4korr(A)
+#define ft_intXstore(T,A) mi_int4store(T,A)
extern const HA_KEYSEG ft_keysegs[FT_SEGS];
int _mi_ft_cmp(MI_INFO *, uint, const byte *, const byte *);
int _mi_ft_add(MI_INFO *, uint, byte *, const byte *, my_off_t);
int _mi_ft_del(MI_INFO *, uint, byte *, const byte *, my_off_t);
+
diff --git a/myisam/mi_check.c b/myisam/mi_check.c
index 700ac5b0b62..271c6a55c8c 100644
--- a/myisam/mi_check.c
+++ b/myisam/mi_check.c
@@ -49,10 +49,11 @@ static int sort_key_read(MI_SORT_PARAM *sort_param,void *key);
static int sort_ft_key_read(MI_SORT_PARAM *sort_param,void *key);
static int sort_get_next_record(MI_SORT_PARAM *sort_param);
static int sort_key_cmp(MI_SORT_PARAM *sort_param, const void *a,const void *b);
+static int sort_ft_key_write(MI_SORT_PARAM *sort_param, const void *a);
static int sort_key_write(MI_SORT_PARAM *sort_param, const void *a);
static my_off_t get_record_for_key(MI_INFO *info,MI_KEYDEF *keyinfo,
uchar *key);
-static int sort_insert_key(MI_SORT_PARAM *sort_param,
+static int sort_insert_key(MI_SORT_PARAM *sort_param,
reg1 SORT_KEY_BLOCKS *key_block,
uchar *key, my_off_t prev_block);
static int sort_delete_record(MI_SORT_PARAM *sort_param);
@@ -1875,7 +1876,6 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
((param->testflag & T_CREATE_MISSING_KEYS) ? info->state->records :
(ha_rows) (sort_info.filelength/length+1));
sort_param.key_cmp=sort_key_cmp;
- sort_param.key_write=sort_key_write;
sort_param.lock_in_memory=lock_memory;
sort_param.tmpdir=param->tmpdir;
sort_param.sort_info=&sort_info;
@@ -1928,10 +1928,14 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
(ha_rows) (sort_info.filelength/ft_max_word_len_for_sort+1);
sort_param.key_read=sort_ft_key_read;
+ sort_param.key_write=sort_ft_key_write;
sort_param.key_length+=ft_max_word_len_for_sort-HA_FT_MAXLEN;
}
else
+ {
sort_param.key_read=sort_key_read;
+ sort_param.key_write=sort_key_write;
+ }
if (_create_index_by_sort(&sort_param,
(my_bool) (!(param->testflag & T_VERBOSE)),
@@ -1977,9 +1981,6 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
else
info->state->data_file_length=sort_param.max_pos;
- /*if (flush_pending_blocks(param))
- goto err;*/
-
param->read_cache.file=info->dfile; /* re-init read cache */
reinit_io_cache(&param->read_cache,READ_CACHE,share->pack.header_length,
1,1);
@@ -2078,6 +2079,7 @@ err:
MYF(MY_ALLOW_ZERO_PTR));
my_free(sort_param.record,MYF(MY_ALLOW_ZERO_PTR));
my_free((gptr) sort_info.key_block,MYF(MY_ALLOW_ZERO_PTR));
+ my_free((gptr) sort_info.ft_buf, MYF(MY_ALLOW_ZERO_PTR));
my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR));
VOID(end_io_cache(&param->read_cache));
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
@@ -2093,7 +2095,7 @@ err:
Threaded repair of table using sorting
SYNOPSIS
- mi_repair_by_sort_r()
+ mi_repair_by_sort_parallel()
param Repair parameters
info MyISAM handler to repair
name Name of table (for warnings)
@@ -2265,10 +2267,17 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
}
if ((!(param->testflag & T_SILENT)))
printf ("- Fixing index %d\n",key+1);
- sort_param[i].key_read= ((sort_param[i].keyinfo->flag & HA_FULLTEXT) ?
- sort_ft_key_read : sort_key_read);
+ if (sort_param[i].keyinfo->flag & HA_FULLTEXT)
+ {
+ sort_param[i].key_read=sort_ft_key_read;
+ sort_param[i].key_write=sort_ft_key_write;
+ }
+ else
+ {
+ sort_param[i].key_read=sort_key_read;
+ sort_param[i].key_write=sort_key_write;
+ }
sort_param[i].key_cmp=sort_key_cmp;
- sort_param[i].key_write=sort_key_write;
sort_param[i].lock_in_memory=lock_memory;
sort_param[i].tmpdir=param->tmpdir;
sort_param[i].sort_info=&sort_info;
@@ -2461,6 +2470,7 @@ err:
pthread_cond_destroy (&sort_info.cond);
pthread_mutex_destroy(&sort_info.mutex);
+ my_free((gptr) sort_info.ft_buf, MYF(MY_ALLOW_ZERO_PTR));
my_free((gptr) sort_info.key_block,MYF(MY_ALLOW_ZERO_PTR));
my_free((gptr) sort_param,MYF(MY_ALLOW_ZERO_PTR));
my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR));
@@ -3095,6 +3105,137 @@ static int sort_key_write(MI_SORT_PARAM *sort_param, const void *a)
(uchar*) a, HA_OFFSET_ERROR));
} /* sort_key_write */
+int sort_ft_buf_flush(MI_SORT_PARAM *sort_param)
+{
+ SORT_INFO *sort_info=sort_param->sort_info;
+ SORT_KEY_BLOCKS *key_block=sort_info->key_block;
+ MYISAM_SHARE *share=sort_info->info->s;
+ uint val_off, val_len, error;
+ SORT_FT_BUF *ft_buf=sort_info->ft_buf;
+ uchar *from, *to;
+
+ val_len=share->ft2_keyinfo.keylength;
+ get_key_full_length_rdonly(val_off, ft_buf->lastkey);
+ to=ft_buf->lastkey+val_off;
+
+ if (ft_buf->buf)
+ { /* flushing first-level tree */
+ error=sort_insert_key(sort_param,key_block,ft_buf->lastkey,HA_OFFSET_ERROR);
+ for (from=to+val_len;
+ !error && from < ft_buf->buf;
+ from+= val_len)
+ {
+ memcpy(to, from, val_len);
+ error=sort_insert_key(sort_param,key_block,ft_buf->lastkey,HA_OFFSET_ERROR);
+ }
+ return error;
+ }
+ /* flushing second-level tree keyblocks */
+ error=flush_pending_blocks(sort_param);
+ /* updating lastkey with second-level tree info */
+ ft_intXstore(ft_buf->lastkey+val_off, -ft_buf->count);
+ _mi_dpointer(sort_info->info, ft_buf->lastkey+val_off+HA_FT_WLEN,
+ share->state.key_root[sort_param->key]);
+ /* restoring first level tree data in sort_info/sort_param */
+ sort_info->key_block=sort_info->key_block_end- sort_info->param->sort_key_blocks;
+ sort_param->keyinfo=share->keyinfo+sort_param->key;
+ share->state.key_root[sort_param->key]=HA_OFFSET_ERROR;
+ /* writing lastkey in first-level tree */
+ return error ? error :
+ sort_insert_key(sort_param,sort_info->key_block,
+ ft_buf->lastkey,HA_OFFSET_ERROR);
+}
+
+static int sort_ft_key_write(MI_SORT_PARAM *sort_param, const void *a)
+{
+ uint a_len, val_off, val_len, error;
+ uchar *p;
+ SORT_INFO *sort_info=sort_param->sort_info;
+ SORT_FT_BUF *ft_buf=sort_info->ft_buf;
+ SORT_KEY_BLOCKS *key_block=sort_info->key_block;
+
+ val_len=HA_FT_WLEN+sort_info->info->s->base.rec_reflength;
+ get_key_full_length_rdonly(a_len, (uchar *)a);
+
+ if (!ft_buf)
+ {
+ /*
+ use two-level tree only if key_reflength fits in rec_reflength place
+ and row format is NOT static - for _mi_dpointer not to garble offsets
+ */
+ if ((sort_info->info->s->base.key_reflength <=
+ sort_info->info->s->base.rec_reflength) &&
+ (sort_info->info->s->options &
+ (HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)))
+ ft_buf=(SORT_FT_BUF *)my_malloc(sort_param->keyinfo->block_length +
+ sizeof(SORT_FT_BUF), MYF(MY_WME));
+
+ if (!ft_buf)
+ {
+ sort_param->key_write=sort_key_write;
+ return sort_key_write(sort_param, a);
+ }
+ sort_info->ft_buf=ft_buf;
+ goto word_init_ft_buf; /* no need to duplicate the code */
+ }
+ get_key_full_length_rdonly(val_off, ft_buf->lastkey);
+
+ if (val_off == a_len &&
+ mi_compare_text(sort_param->keyinfo->seg->charset,
+ ((uchar *)a)+1,a_len-1,
+ ft_buf->lastkey+1,val_off-1, 0)==0)
+ {
+ if (!ft_buf->buf) /* store in second-level tree */
+ {
+ ft_buf->count++;
+ return sort_insert_key(sort_param,key_block,
+ ((uchar *)a)+val_off, HA_OFFSET_ERROR);
+ }
+
+ /* storing the key in the buffer. */
+ memcpy (ft_buf->buf, a+val_off, val_len);
+ ft_buf->buf+=val_len;
+ if (ft_buf->buf < ft_buf->end)
+ return 0;
+
+ /* converting to two-level tree */
+ p=ft_buf->lastkey+val_off;
+
+ while (key_block->inited)
+ key_block++;
+ sort_info->key_block=key_block;
+ sort_param->keyinfo=& sort_info->info->s->ft2_keyinfo;
+ ft_buf->count=(ft_buf->buf - p)/val_len;
+
+ /* flushing buffer to second-level tree */
+ for (error=0; !error && p < ft_buf->buf; p+= val_len)
+ error=sort_insert_key(sort_param,key_block,p,HA_OFFSET_ERROR);
+ ft_buf->buf=0;
+ return error;
+ }
+ else
+ {
+ /* flushing buffer */
+ if ((error=sort_ft_buf_flush(sort_param)))
+ return error;
+
+word_init_ft_buf:
+ a_len+=val_len;
+ memcpy(ft_buf->lastkey, a, a_len);
+ ft_buf->buf=ft_buf->lastkey+a_len;
+ ft_buf->end=ft_buf->lastkey+ (sort_param->keyinfo->block_length-32);
+ /* 32 is just a safety margin here
+ (at least max(val_len, sizeof(nod_flag)) should be there).
+ May be better performance could be achieved if we'd put
+ (sort_info->keyinfo->block_length-32)/XXX
+ instead.
+ TODO: benchmark the best value for XXX.
+ */
+
+ return 0;
+ }
+ return -1; /* impossible */
+} /* sort_ft_key_write */
/* get pointer to record from a key */
@@ -3254,7 +3395,7 @@ int flush_pending_blocks(MI_SORT_PARAM *sort_param)
my_off_t filepos,key_file_length;
SORT_KEY_BLOCKS *key_block;
SORT_INFO *sort_info= sort_param->sort_info;
- MI_CHECK *param=sort_info->param;
+ myf myf_rw=sort_info->param->myf_rw;
MI_INFO *info=sort_info->info;
MI_KEYDEF *keyinfo=sort_param->keyinfo;
DBUG_ENTER("flush_pending_blocks");
@@ -3279,7 +3420,7 @@ int flush_pending_blocks(MI_SORT_PARAM *sort_param)
DBUG_RETURN(1);
}
else if (my_pwrite(info->s->kfile,(byte*) key_block->buff,
- (uint) keyinfo->block_length,filepos, param->myf_rw))
+ (uint) keyinfo->block_length,filepos, myf_rw))
DBUG_RETURN(1);
DBUG_DUMP("buff",(byte*) key_block->buff,length);
nod_flag=1;
diff --git a/myisam/mi_create.c b/myisam/mi_create.c
index 8b33930bcf3..843a92d9d10 100644
--- a/myisam/mi_create.c
+++ b/myisam/mi_create.c
@@ -44,7 +44,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
uint fields,length,max_key_length,packed,pointer,
key_length,info_length,key_segs,options,min_key_length_skipp,
base_pos,varchar_count,long_varchar_count,varchar_length,
- max_key_block_length,unique_key_parts,offset;
+ max_key_block_length,unique_key_parts,fulltext_keys,offset;
ulong reclength, real_reclength,min_pack_length;
char filename[FN_REFLEN],linkname[FN_REFLEN], *linkname_ptr;
ulong pack_reclength;
@@ -223,6 +223,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
reclength+=long_varchar_count; /* We need space for this! */
max_key_length=0; tot_length=0 ; key_segs=0;
+ fulltext_keys=0;
max_key_block_length=0;
share.state.rec_per_key_part=rec_per_key_part;
share.state.key_root=key_root;
@@ -242,14 +243,14 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
if (keydef->flag & HA_SPATIAL)
{
/* BAR TODO to support 3D and more dimensions in the future */
- uint sp_segs=SPDIMS*2;
+ uint sp_segs=SPDIMS*2;
keydef->flag=HA_SPATIAL;
if (flags & HA_DONT_TOUCH_DATA)
{
- /*
+ /*
called by myisamchk - i.e. table structure was taken from
- MYI file and SPATIAL key *do has* additional sp_segs keysegs.
+ MYI file and SPATIAL key *does have* additional sp_segs keysegs.
We'd better delete them now
*/
keydef->keysegs-=sp_segs;
@@ -271,20 +272,11 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
min_key_length_skipp+=SPLEN*2*SPDIMS;
}
else
- if (keydef->flag & HA_FULLTEXT) /* SerG */
+ if (keydef->flag & HA_FULLTEXT)
{
keydef->flag=HA_FULLTEXT | HA_PACK_KEY | HA_VAR_LENGTH_KEY;
options|=HA_OPTION_PACK_KEYS; /* Using packed keys */
- if (flags & HA_DONT_TOUCH_DATA)
- {
- /* called by myisamchk - i.e. table structure was taken from
- MYI file and FULLTEXT key *do has* additional FT_SEGS keysegs.
- We'd better delete them now
- */
- keydef->keysegs-=FT_SEGS;
- }
-
for (j=0, keyseg=keydef->seg ; (int) j < keydef->keysegs ;
j++, keyseg++)
{
@@ -295,19 +287,11 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
goto err;
}
}
- keydef->keysegs+=FT_SEGS;
+ fulltext_keys++;
key_length+= HA_FT_MAXLEN+HA_FT_WLEN;
-#ifdef EVAL_RUN
- key_length++;
-#endif
-
length++; /* At least one length byte */
min_key_length_skipp+=HA_FT_MAXLEN;
-#if HA_FT_MAXLEN >= 255
- min_key_length_skipp+=2; /* prefix may be 3 bytes */
- length+=2;
-#endif
}
else
{
@@ -473,8 +457,9 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
mi_get_pointer_length((tot_length + max_key_block_length * keys *
MI_INDEX_BLOCK_MARGIN) / MI_MIN_KEY_BLOCK_LENGTH,
3);
- share.base.keys= share.state.header.keys = keys;
+ share.base.keys= share.state.header.keys= keys;
share.state.header.uniques= uniques;
+ share.state.header.fulltext_keys= fulltext_keys;
mi_int2store(share.state.header.key_parts,key_segs);
mi_int2store(share.state.header.unique_key_parts,unique_key_parts);
@@ -566,7 +551,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
linkname_ptr=0;
create_flag=MY_DELETE_OLD;
}
- if ((dfile=
+ if ((dfile=
my_create_with_symlink(linkname_ptr, filename,
0,O_RDWR | O_TRUNC,
MYF(MY_WME | create_flag))) < 0)
@@ -590,21 +575,13 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
/* Write key and keyseg definitions */
for (i=0 ; i < share.base.keys - uniques; i++)
{
- uint ft_segs=(keydefs[i].flag & HA_FULLTEXT) ? FT_SEGS : 0;
uint sp_segs=(keydefs[i].flag & HA_SPATIAL) ? 2*SPDIMS : 0;
if (mi_keydef_write(file, &keydefs[i]))
goto err;
- for (j=0 ; j < keydefs[i].keysegs-ft_segs-sp_segs ; j++)
+ for (j=0 ; j < keydefs[i].keysegs-sp_segs ; j++)
if (mi_keyseg_write(file, &keydefs[i].seg[j]))
goto err;
- for (j=0 ; j < ft_segs ; j++)
- {
- HA_KEYSEG seg=ft_keysegs[j];
- seg.language= keydefs[i].seg[0].language;
- if (mi_keyseg_write(file, &seg))
- goto err;
- }
for (j=0 ; j < sp_segs ; j++)
{
HA_KEYSEG sseg;
diff --git a/myisam/mi_delete.c b/myisam/mi_delete.c
index ff723303228..2b19139e668 100644
--- a/myisam/mi_delete.c
+++ b/myisam/mi_delete.c
@@ -23,13 +23,13 @@
#include <errno.h>
#endif
-static int d_search(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key,
- uint key_length, my_off_t page, uchar *anc_buff);
+static int d_search(MI_INFO *info,MI_KEYDEF *keyinfo,uint comp_flag,
+ uchar *key,uint key_length,my_off_t page,uchar *anc_buff);
static int del(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key,uchar *anc_buff,
my_off_t leaf_page,uchar *leaf_buff,uchar *keypos,
my_off_t next_block,uchar *ret_key);
static int underflow(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *anc_buff,
- my_off_t leaf_page, uchar *leaf_buff,uchar *keypos);
+ my_off_t leaf_page,uchar *leaf_buff,uchar *keypos);
static uint remove_key(MI_KEYDEF *keyinfo,uint nod_flag,uchar *keypos,
uchar *lastkey,uchar *page_end,
my_off_t *next_block);
@@ -73,7 +73,6 @@ int mi_delete(MI_INFO *info,const byte *record)
if (((ulonglong) 1 << i) & info->s->state.key_map)
{
info->s->keyinfo[i].version++;
- /* The following code block is for text searching by SerG */
if (info->s->keyinfo[i].flag & HA_FULLTEXT )
{
if (_mi_ft_del(info,i,(char*) old_key,record,info->lastpos))
@@ -82,7 +81,7 @@ int mi_delete(MI_INFO *info,const byte *record)
else
{
if (info->s->keyinfo[i].ck_delete(info,i,old_key,
- _mi_make_key(info,i,old_key,record,info->lastpos)))
+ _mi_make_key(info,i,old_key,record,info->lastpos)))
goto err;
}
}
@@ -129,18 +128,23 @@ err:
int _mi_ck_delete(register MI_INFO *info, uint keynr, uchar *key,
uint key_length)
{
+ return _mi_ck_real_delete(info, info->s->keyinfo+keynr, key, key_length,
+ &info->s->state.key_root[keynr]);
+} /* _mi_ck_delete */
+
+int _mi_ck_real_delete(register MI_INFO *info, MI_KEYDEF *keyinfo,
+ uchar *key, uint key_length, my_off_t *root)
+{
int error;
uint nod_flag;
my_off_t old_root;
uchar *root_buff;
- MI_KEYDEF *keyinfo;
- DBUG_ENTER("_mi_ck_delete");
+ DBUG_ENTER("_mi_ck_real_delete");
- if ((old_root=info->s->state.key_root[keynr]) == HA_OFFSET_ERROR)
+ if ((old_root=*root) == HA_OFFSET_ERROR)
{
DBUG_RETURN(my_errno=HA_ERR_CRASHED);
}
- keyinfo=info->s->keyinfo+keynr;
if (!(root_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
MI_MAX_KEY_BUFF*2)))
{
@@ -153,12 +157,15 @@ int _mi_ck_delete(register MI_INFO *info, uint keynr, uchar *key,
error= -1;
goto err;
}
- if ((error=d_search(info,keyinfo,key,key_length,old_root,root_buff)) >0)
+ if ((error=d_search(info,keyinfo,
+ (keyinfo->flag & HA_FULLTEXT ? SEARCH_FIND
+ : SEARCH_SAME),
+ key,key_length,old_root,root_buff)) >0)
{
if (error == 2)
{
DBUG_PRINT("test",("Enlarging of root when deleting"));
- error=_mi_enlarge_root(info,keynr,key);
+ error=_mi_enlarge_root(info,keyinfo,key,root);
}
else /* error == 1 */
{
@@ -166,10 +173,9 @@ int _mi_ck_delete(register MI_INFO *info, uint keynr, uchar *key,
{
error=0;
if (nod_flag)
- info->s->state.key_root[keynr]=_mi_kpos(nod_flag,
- root_buff+2+nod_flag);
+ *root=_mi_kpos(nod_flag,root_buff+2+nod_flag);
else
- info->s->state.key_root[keynr]= HA_OFFSET_ERROR;
+ *root=HA_OFFSET_ERROR;
if (_mi_dispose(info,keyinfo,old_root))
error= -1;
}
@@ -180,7 +186,7 @@ int _mi_ck_delete(register MI_INFO *info, uint keynr, uchar *key,
err:
my_afree((gptr) root_buff);
DBUG_RETURN(error);
-} /* _mi_ck_delete */
+} /* _mi_ck_real_delete */
/*
@@ -192,11 +198,11 @@ err:
*/
static int d_search(register MI_INFO *info, register MI_KEYDEF *keyinfo,
- uchar *key, uint key_length, my_off_t page,
- uchar *anc_buff)
+ uint comp_flag, uchar *key, uint key_length,
+ my_off_t page, uchar *anc_buff)
{
int flag,ret_value,save_flag;
- uint length,nod_flag;
+ uint length,nod_flag,search_key_length;
my_bool last_key;
uchar *leaf_buff,*keypos;
my_off_t leaf_page,next_block;
@@ -204,9 +210,9 @@ static int d_search(register MI_INFO *info, register MI_KEYDEF *keyinfo,
DBUG_ENTER("d_search");
DBUG_DUMP("page",(byte*) anc_buff,mi_getint(anc_buff));
- flag=(*keyinfo->bin_search)(info,keyinfo,anc_buff,key, USE_WHOLE_KEY,
- SEARCH_SAME,
- &keypos, lastkey, &last_key);
+ search_key_length= (comp_flag & SEARCH_FIND) ? key_length : USE_WHOLE_KEY;
+ flag=(*keyinfo->bin_search)(info,keyinfo,anc_buff,key, search_key_length,
+ comp_flag, &keypos, lastkey, &last_key);
if (flag == MI_FOUND_WRONG_KEY)
{
DBUG_PRINT("error",("Found wrong key"));
@@ -214,6 +220,52 @@ static int d_search(register MI_INFO *info, register MI_KEYDEF *keyinfo,
}
nod_flag=mi_test_if_nod(anc_buff);
+ if (!flag && keyinfo->flag & HA_FULLTEXT)
+ {
+ uint off;
+ int subkeys;
+
+ get_key_full_length_rdonly(off, lastkey);
+ subkeys=ft_sintXkorr(lastkey+off);
+ comp_flag=SEARCH_SAME;
+ if (subkeys >= 0)
+ {
+ /* normal word, one-level tree structure */
+ flag=(*keyinfo->bin_search)(info,keyinfo,anc_buff,key,USE_WHOLE_KEY,
+ comp_flag, &keypos, lastkey, &last_key);
+ /* fall through to normal delete */
+ }
+ else
+ {
+ /* popular word. two-level tree. going down */
+ uint tmp_key_length;
+ my_off_t root;
+ uchar *kpos=keypos;
+
+ tmp_key_length=(*keyinfo->get_key)(keyinfo,nod_flag,&kpos,lastkey);
+ root=_mi_dpos(info,nod_flag,kpos);
+ if (subkeys == -1)
+ {
+ /* the last entry in sub-tree */
+ _mi_dispose(info, keyinfo, root);
+ /* fall through to normal delete */
+ }
+ else
+ {
+ keyinfo=&info->s->ft2_keyinfo;
+ kpos-=keyinfo->keylength; /* we'll modify key entry 'in vivo' */
+ key+=off;
+ ret_value=_mi_ck_real_delete(info, &info->s->ft2_keyinfo,
+ key, HA_FT_WLEN, &root);
+ _mi_dpointer(info, kpos+HA_FT_WLEN, root);
+ subkeys++;
+ ft_intXstore(kpos, subkeys);
+ if (!ret_value)
+ ret_value=_mi_write_keypage(info,keyinfo,page,anc_buff);
+ DBUG_RETURN(ret_value);
+ }
+ }
+ }
leaf_buff=0;
LINT_INIT(leaf_page);
if (nod_flag)
@@ -239,7 +291,8 @@ static int d_search(register MI_INFO *info, register MI_KEYDEF *keyinfo,
goto err;
}
save_flag=0;
- ret_value=d_search(info,keyinfo,key,key_length,leaf_page,leaf_buff);
+ ret_value=d_search(info,keyinfo,comp_flag,key,key_length,
+ leaf_page,leaf_buff);
}
else
{ /* Found key */
diff --git a/myisam/mi_open.c b/myisam/mi_open.c
index ef1906e0c00..250e0483fe5 100644
--- a/myisam/mi_open.c
+++ b/myisam/mi_open.c
@@ -69,7 +69,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
{
int lock_error,kfile,open_mode,save_errno,have_rtree=0;
uint i,j,len,errpos,head_length,base_pos,offset,info_length,keys,
- key_parts,unique_key_parts,tmp_length,uniques;
+ key_parts,unique_key_parts,fulltext_keys,uniques;
char name_buff[FN_REFLEN], org_name [FN_REFLEN], index_name[FN_REFLEN],
data_name[FN_REFLEN];
char *disk_cache,*disk_pos;
@@ -126,8 +126,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
HA_OPTION_TEMP_COMPRESS_RECORD | HA_OPTION_CHECKSUM |
HA_OPTION_TMP_TABLE | HA_OPTION_DELAY_KEY_WRITE))
{
- DBUG_PRINT("error",("wrong options: 0x%lx",
- share->options));
+ DBUG_PRINT("error",("wrong options: 0x%lx", share->options));
my_errno=HA_ERR_OLD_FILE;
goto err;
}
@@ -162,11 +161,9 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
len=mi_uint2korr(share->state.header.state_info_length);
keys= (uint) share->state.header.keys;
uniques= (uint) share->state.header.uniques;
+ fulltext_keys= (uint) share->state.header.fulltext_keys;
key_parts= mi_uint2korr(share->state.header.key_parts);
unique_key_parts= mi_uint2korr(share->state.header.unique_key_parts);
- tmp_length=(MI_STATE_INFO_SIZE + keys * MI_STATE_KEY_SIZE +
- key_parts*MI_STATE_KEYSEG_SIZE +
- share->state.header.max_block_size*MI_STATE_KEYBLOCK_SIZE);
if (len != MI_STATE_INFO_SIZE)
{
DBUG_PRINT("warning",
@@ -203,6 +200,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
goto err;
}
+ key_parts+=fulltext_keys*FT_SEGS;
if (share->base.max_key_length > MI_MAX_KEY_BUFF || keys > MI_MAX_KEY ||
key_parts >= MI_MAX_KEY * MI_MAX_KEY_SEG)
{
@@ -211,7 +209,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
goto err;
}
- /* Correct max_file_length based on length of sizeof_t */
+ /* Correct max_file_length based on length of sizeof(off_t) */
max_data_file_length=
(share->options & (HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)) ?
(((ulonglong) 1 << (share->base.rec_reflength*8))-1) :
@@ -290,12 +288,14 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
for (i=0 ; i < keys ; i++)
{
disk_pos=mi_keydef_read(disk_pos, &share->keyinfo[i]);
+ if (share->keyinfo[i].key_alg == HA_KEY_ALG_RTREE)
+ have_rtree=1;
set_if_smaller(share->blocksize,share->keyinfo[i].block_length);
share->keyinfo[i].seg=pos;
for (j=0 ; j < share->keyinfo[i].keysegs; j++,pos++)
{
disk_pos=mi_keyseg_read(disk_pos, pos);
-
+
if (pos->type == HA_KEYTYPE_TEXT || pos->type == HA_KEYTYPE_VARTEXT)
{
if (!pos->language)
@@ -312,11 +312,41 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
uint sp_segs=SPDIMS*2;
share->keyinfo[i].seg=pos-sp_segs;
share->keyinfo[i].keysegs--;
- } else if (share->keyinfo[i].flag & HA_FULLTEXT)
+ }
+ else if (share->keyinfo[i].flag & HA_FULLTEXT)
{
- share->keyinfo[i].seg=pos-FT_SEGS;
- share->fulltext_index=1;
+ if (!fulltext_keys)
+ { /* 4.0 compatibility code, to be removed in 5.0 */
+ share->keyinfo[i].seg=pos-FT_SEGS;
+ share->keyinfo[i].keysegs-=FT_SEGS;
+ share->state.header.fulltext_keys++;
+ }
+ else
+ {
+ uint j;
+ share->keyinfo[i].seg=pos;
+ for (j=0; j < FT_SEGS; j++)
+ {
+ *pos=ft_keysegs[j];
+ pos[0].language= pos[-1].language;
+ pos[0].charset= pos[-1].charset;
+ pos++;
+ }
+ }
+ if (!share->ft2_keyinfo.seg)
+ {
+ memcpy(& share->ft2_keyinfo, & share->keyinfo[i], sizeof(MI_KEYDEF));
+ share->ft2_keyinfo.keysegs=1;
+ share->ft2_keyinfo.flag=0;
+ share->ft2_keyinfo.keylength=
+ share->ft2_keyinfo.minlength=
+ share->ft2_keyinfo.maxlength=HA_FT_WLEN+share->base.rec_reflength;
+ share->ft2_keyinfo.seg=pos-1;
+ share->ft2_keyinfo.end=pos;
+ setup_key_functions(& share->ft2_keyinfo);
+ }
}
+ setup_key_functions(share->keyinfo+i);
share->keyinfo[i].end=pos;
pos->type=HA_KEYTYPE_END; /* End */
pos->length=share->base.rec_reflength;
@@ -349,12 +379,6 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
pos++;
}
}
- for (i=0 ; i < keys ; i++)
- {
- if (share->keyinfo[i].key_alg == HA_KEY_ALG_RTREE)
- have_rtree=1;
- setup_key_functions(share->keyinfo+i);
- }
for (i=j=offset=0 ; i < share->base.fields ; i++)
{
@@ -720,9 +744,9 @@ static void setup_key_functions(register MI_KEYDEF *keyinfo)
}
-/***************************************************************************
-** Function to save and store the header in the index file (.MSI)
-***************************************************************************/
+/*
+ Function to save and store the header in the index file (.MYI)
+*/
uint mi_state_info_write(File file, MI_STATE_INFO *state, uint pWrite)
{
diff --git a/myisam/mi_rnext.c b/myisam/mi_rnext.c
index daab7c5f085..e1cf916d6d9 100644
--- a/myisam/mi_rnext.c
+++ b/myisam/mi_rnext.c
@@ -51,7 +51,7 @@ int mi_rnext(MI_INFO *info, byte *buf, int inx)
case HA_KEY_ALG_BTREE:
default:
error=_mi_search_first(info,info->s->keyinfo+inx,
- info->s->state.key_root[inx]);
+ info->s->state.key_root[inx]);
break;
}
}
@@ -60,17 +60,17 @@ int mi_rnext(MI_INFO *info, byte *buf, int inx)
switch(info->s->keyinfo[inx].key_alg)
{
case HA_KEY_ALG_RTREE:
- /*
+ /*
Note that rtree doesn't support that the table
may be changed since last call, so we do need
to skip rows inserted by other threads like in btree
*/
error=rtree_get_next(info,inx,info->lastkey_length);
break;
-
+
case HA_KEY_ALG_BTREE:
default:
- if (!changed)
+ if (!changed)
{
error=_mi_search_next(info,info->s->keyinfo+inx,info->lastkey,
info->lastkey_length,flag,
@@ -81,15 +81,15 @@ int mi_rnext(MI_INFO *info, byte *buf, int inx)
error=_mi_search(info,info->s->keyinfo+inx,info->lastkey,
USE_WHOLE_KEY,flag, info->s->state.key_root[inx]);
}
- if (!error)
+ if (!error && info->s->concurrent_insert)
{
while (info->lastpos >= info->state->data_file_length)
{
/* Skip rows that are inserted by other threads since we got a lock */
- if ((error=_mi_search_next(info,info->s->keyinfo+inx,info->lastkey,
- info->lastkey_length,
- SEARCH_BIGGER,
- info->s->state.key_root[inx])))
+ if ((error=_mi_search_next(info,info->s->keyinfo+inx,info->lastkey,
+ info->lastkey_length,
+ SEARCH_BIGGER,
+ info->s->state.key_root[inx])))
break;
}
}
diff --git a/myisam/mi_update.c b/myisam/mi_update.c
index 81142ecabac..53c09a1d35c 100644
--- a/myisam/mi_update.c
+++ b/myisam/mi_update.c
@@ -91,7 +91,6 @@ int mi_update(register MI_INFO *info, const byte *oldrec, byte *newrec)
{
if (((ulonglong) 1 << i) & share->state.key_map)
{
- /* The following code block is for text searching by SerG */
if (share->keyinfo[i].flag & HA_FULLTEXT )
{
if (_mi_ft_cmp(info,i,oldrec, newrec))
@@ -175,7 +174,6 @@ err:
{
if (((ulonglong) 1 << i) & changed)
{
- /* The following code block is for text searching by SerG */
if (share->keyinfo[i].flag & HA_FULLTEXT)
{
if ((flag++ && _mi_ft_del(info,i,(char*) new_key,newrec,pos)) ||
diff --git a/myisam/mi_write.c b/myisam/mi_write.c
index 81941e41010..59b4f0d29c3 100644
--- a/myisam/mi_write.c
+++ b/myisam/mi_write.c
@@ -38,9 +38,9 @@ static int _mi_balance_page(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key,
static uchar *_mi_find_last_pos(MI_KEYDEF *keyinfo, uchar *page,
uchar *key, uint *return_key_length,
uchar **after_key);
-int _mi_ck_write_tree(register MI_INFO *info, uint keynr, uchar *key,
+int _mi_ck_write_tree(register MI_INFO *info, uint keynr,uchar *key,
uint key_length);
-int _mi_ck_write_btree(register MI_INFO *info, uint keynr, uchar *key,
+int _mi_ck_write_btree(register MI_INFO *info, uint keynr,uchar *key,
uint key_length);
/* Write new record to database */
@@ -250,11 +250,12 @@ int _mi_ck_write_btree(register MI_INFO *info, uint keynr, uchar *key,
int error;
uint comp_flag;
MI_KEYDEF *keyinfo=info->s->keyinfo+keynr;
+ my_off_t *root=&info->s->state.key_root[keynr];
DBUG_ENTER("_mi_ck_write_btree");
if (keyinfo->flag & HA_SORT_ALLOWS_SAME)
comp_flag=SEARCH_BIGGER; /* Put after same key */
- else if (keyinfo->flag & HA_NOSAME)
+ else if (keyinfo->flag & (HA_NOSAME|HA_FULLTEXT))
{
comp_flag=SEARCH_FIND | SEARCH_UPDATE; /* No dupplicates */
if (keyinfo->flag & HA_NULL_ARE_EQUAL)
@@ -263,37 +264,34 @@ int _mi_ck_write_btree(register MI_INFO *info, uint keynr, uchar *key,
else
comp_flag=SEARCH_SAME; /* Keys in rec-pos order */
- if (info->s->state.key_root[keynr] == HA_OFFSET_ERROR ||
+ if (*root == HA_OFFSET_ERROR ||
(error=w_search(info, keyinfo, comp_flag, key, key_length,
- info->s->state.key_root[keynr], (uchar *) 0, (uchar*) 0,
+ *root, (uchar *) 0, (uchar*) 0,
(my_off_t) 0, 1)) > 0)
- error=_mi_enlarge_root(info,keynr,key);
+ error=_mi_enlarge_root(info,keyinfo,key,root);
DBUG_RETURN(error);
} /* _mi_ck_write_btree */
/* Make a new root with key as only pointer */
-int _mi_enlarge_root(register MI_INFO *info, uint keynr, uchar *key)
+int _mi_enlarge_root(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key,
+ my_off_t *root)
{
uint t_length,nod_flag;
- reg2 MI_KEYDEF *keyinfo;
MI_KEY_PARAM s_temp;
MYISAM_SHARE *share=info->s;
DBUG_ENTER("_mi_enlarge_root");
- nod_flag= (share->state.key_root[keynr] != HA_OFFSET_ERROR) ?
- share->base.key_reflength : 0;
- _mi_kpointer(info,info->buff+2,share->state.key_root[keynr]); /* if nod */
- keyinfo=share->keyinfo+keynr;
+ nod_flag= (*root != HA_OFFSET_ERROR) ? share->base.key_reflength : 0;
+ _mi_kpointer(info,info->buff+2,*root); /* if nod */
t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,(uchar*) 0,
(uchar*) 0, (uchar*) 0, key,&s_temp);
mi_putint(info->buff,t_length+2+nod_flag,nod_flag);
(*keyinfo->store_key)(keyinfo,info->buff+2+nod_flag,&s_temp);
info->buff_used=info->page_changed=1; /* info->buff is used */
- if ((share->state.key_root[keynr]= _mi_new(info,keyinfo)) ==
- HA_OFFSET_ERROR ||
- _mi_write_keypage(info,keyinfo,share->state.key_root[keynr],info->buff))
+ if ((*root= _mi_new(info,keyinfo)) == HA_OFFSET_ERROR ||
+ _mi_write_keypage(info,keyinfo,*root,info->buff))
DBUG_RETURN(-1);
DBUG_RETURN(0);
} /* _mi_enlarge_root */
@@ -333,15 +331,54 @@ static int w_search(register MI_INFO *info, register MI_KEYDEF *keyinfo,
if (flag == 0)
{
uint tmp_key_length;
- my_errno=HA_ERR_FOUND_DUPP_KEY;
/* get position to record with duplicated key */
tmp_key_length=(*keyinfo->get_key)(keyinfo,nod_flag,&keypos,keybuff);
if (tmp_key_length)
info->dupp_key_pos=_mi_dpos(info,0,keybuff+tmp_key_length);
else
info->dupp_key_pos= HA_OFFSET_ERROR;
- my_afree((byte*) temp_buff);
- DBUG_RETURN(-1);
+ if (keyinfo->flag & HA_FULLTEXT)
+ {
+ uint off;
+ int subkeys;
+
+ get_key_full_length_rdonly(off, keybuff);
+ subkeys=ft_sintXkorr(keybuff+off);
+ comp_flag=SEARCH_SAME;
+ if (subkeys >= 0)
+ {
+ /* normal word, one-level tree structure */
+ flag=(*keyinfo->bin_search)(info, keyinfo, temp_buff, key,
+ USE_WHOLE_KEY, comp_flag,
+ &keypos, keybuff, &was_last_key);
+ }
+ else
+ {
+ /* popular word. two-level tree. going down */
+ my_off_t root=info->dupp_key_pos;
+ keyinfo=&info->s->ft2_keyinfo;
+ key+=off;
+ keypos-=keyinfo->keylength; /* we'll modify key entry 'in vivo' */
+ if ((error=w_search(info, keyinfo, comp_flag, key, HA_FT_WLEN, root,
+ (uchar *) 0, (uchar*) 0, (my_off_t) 0, 1)) > 0)
+ {
+ error=_mi_enlarge_root(info, keyinfo, key, &root);
+ _mi_dpointer(info, keypos+HA_FT_WLEN, root);
+ }
+ subkeys--; /* should there be underflow protection ? */
+ ft_intXstore(keypos, subkeys);
+ if (!error)
+ error=_mi_write_keypage(info,keyinfo,page,temp_buff);
+ my_afree((byte*) temp_buff);
+ DBUG_RETURN(error);
+ }
+ }
+ else /* not HA_FULLTEXT, normal HA_NOSAME key */
+ {
+ my_afree((byte*) temp_buff);
+ my_errno=HA_ERR_FOUND_DUPP_KEY;
+ DBUG_RETURN(-1);
+ }
}
if (flag == MI_FOUND_WRONG_KEY)
DBUG_RETURN(-1);
@@ -394,7 +431,9 @@ int _mi_insert(register MI_INFO *info, register MI_KEYDEF *keyinfo,
#ifndef DBUG_OFF
if (key_pos != anc_buff+2+nod_flag && (keyinfo->flag &
(HA_BINARY_PACK_KEY | HA_PACK_KEY)))
+ {
DBUG_DUMP("prev_key",(byte*) key_buff,_mi_keylength(keyinfo,key_buff));
+ }
if (keyinfo->flag & HA_PACK_KEY)
{
DBUG_PRINT("test",("t_length: %d ref_len: %d",
@@ -753,7 +792,7 @@ int _mi_ck_write_tree(register MI_INFO *info, uint keynr, uchar *key,
DBUG_ENTER("_mi_ck_write_tree");
error= tree_insert(&info->bulk_insert[keynr], key,
- key_length + info->s->rec_reflength,
+ key_length + info->s->rec_reflength,
info->bulk_insert[keynr].custom_arg) ? 0 : HA_ERR_OUT_OF_MEM ;
DBUG_RETURN(error);
diff --git a/myisam/myisamchk.c b/myisam/myisamchk.c
index 1b180a728ba..bbeef27d81b 100644
--- a/myisam/myisamchk.c
+++ b/myisam/myisamchk.c
@@ -874,8 +874,8 @@ static int myisamchk(MI_CHECK *param, my_string filename)
}
else
{
- if (share->fulltext_index)
- ft_init_stopwords(ft_precompiled_stopwords); /* SerG */
+ if (share->state.header.fulltext_keys)
+ ft_init_stopwords(ft_precompiled_stopwords);
if (!(param->testflag & T_READONLY))
lock_type = F_WRLCK; /* table is changed */
diff --git a/myisam/myisamdef.h b/myisam/myisamdef.h
index 005c36271bf..e9485048959 100644
--- a/myisam/myisamdef.h
+++ b/myisam/myisamdef.h
@@ -55,7 +55,8 @@ typedef struct st_mi_state_info
uchar uniques; /* number of UNIQUE definitions */
uchar language; /* Language for indexes */
uchar max_block_size; /* max keyblock size */
- uchar not_used[2]; /* To align to 8 */
+ uchar fulltext_keys;
+ uchar not_used; /* To align to 8 */
} header;
MI_STATUS_INFO state;
@@ -90,7 +91,7 @@ typedef struct st_mi_state_info
} MI_STATE_INFO;
#define MI_STATE_INFO_SIZE (24+14*8+7*4+2*2+8)
-#define MI_STATE_KEY_SIZE 8
+#define MI_STATE_KEY_SIZE 8
#define MI_STATE_KEYBLOCK_SIZE 8
#define MI_STATE_KEYSEG_SIZE 4
#define MI_STATE_EXTRA_SIZE ((MI_MAX_KEY+MI_MAX_KEY_BLOCK_SIZE)*MI_STATE_KEY_SIZE + MI_MAX_KEY*MI_MAX_KEY_SEG*MI_STATE_KEYSEG_SIZE)
@@ -154,6 +155,7 @@ typedef struct st_mi_isam_pack {
typedef struct st_mi_isam_share { /* Shared between opens */
MI_STATE_INFO state;
MI_BASE_INFO base;
+ MI_KEYDEF ft2_keyinfo; /* Second-level ft-key definition */
MI_KEYDEF *keyinfo; /* Key definitions */
MI_UNIQUEDEF *uniqueinfo; /* unique definitions */
HA_KEYSEG *keyparts; /* key part info */
@@ -197,8 +199,7 @@ typedef struct st_mi_isam_share { /* Shared between opens */
global_changed, /* If changed since open */
not_flushed,
temporary,delay_key_write,
- concurrent_insert,
- fulltext_index;
+ concurrent_insert;
#ifdef THREAD
THR_LOCK lock;
pthread_mutex_t intern_lock; /* Locking for use with _locking */
@@ -229,6 +230,8 @@ struct st_myisam_info {
byte *rec_buff; /* Tempbuff for recordpack */
uchar *int_keypos, /* Save position for next/previous */
*int_maxpos; /* -""- */
+ uint int_nod_flag; /* -""- */
+ uint32 int_keytree_version; /* -""- */
int (*read_record)(struct st_myisam_info*, my_off_t, byte*);
invalidator_by_filename invalidator; /* query cache invalidator */
ulong this_unique; /* uniq filenumber or thread */
@@ -247,7 +250,6 @@ struct st_myisam_info {
int dfile; /* The datafile */
uint opt_flag; /* Optim. for space/speed */
uint update; /* If file changed since open */
- uint int_nod_flag; /* -""- */
int lastinx; /* Last used index */
uint lastkey_length; /* Length of key in lastkey */
uint last_rkey_length; /* Last length in mi_rkey() */
@@ -259,7 +261,6 @@ struct st_myisam_info {
uint data_changed; /* Somebody has changed data */
uint save_update; /* When using KEY_READ */
int save_lastinx;
- uint32 int_keytree_version; /* -""- */
LIST open_list;
IO_CACHE rec_cache; /* When cacheing records */
myf lock_wait; /* is 0 or MY_DONT_WAIT */
@@ -372,6 +373,13 @@ typedef struct st_mi_sort_param
{ length=mi_uint2korr((key)+1)+3; (key)+=3; } \
}
+#define get_key_full_length_rdonly(length,key) \
+{ if ((uchar) *(key) != 255) \
+ length= ((uint) (uchar) *((key)))+1; \
+ else \
+ { length=mi_uint2korr((key)+1)+3; } \
+}
+
#define get_pack_length(length) ((length) >= 255 ? 3 : 1)
#define MI_MIN_BLOCK_LENGTH 20 /* Because of delete-link */
@@ -395,7 +403,7 @@ typedef struct st_mi_sort_param
#define MI_FOUND_WRONG_KEY 32738 /* Impossible value from ha_key_cmp */
#define MI_MAX_KEY_BLOCK_SIZE (MI_MAX_KEY_BLOCK_LENGTH/MI_MIN_KEY_BLOCK_LENGTH)
-#define MI_BLOCK_SIZE(key_length,data_pointer,key_pointer) ((((key_length+data_pointer+key_pointer)*4+key_pointer+2)/myisam_block_size+1)*myisam_block_size)
+#define MI_BLOCK_SIZE(key_length,data_pointer,key_pointer) (((((key_length)+(data_pointer)+(key_pointer))*4+(key_pointer)+2)/myisam_block_size+1)*myisam_block_size)
#define MI_MAX_KEYPTR_SIZE 5 /* For calculating block lengths */
#define MI_MIN_KEYBLOCK_LENGTH 50 /* When to split delete blocks */
@@ -455,7 +463,7 @@ extern int _mi_delete_static_record(MI_INFO *info);
extern int _mi_cmp_static_record(MI_INFO *info,const byte *record);
extern int _mi_read_rnd_static_record(MI_INFO*, byte *,my_off_t, my_bool);
extern int _mi_ck_write(MI_INFO *info,uint keynr,uchar *key,uint length);
-extern int _mi_enlarge_root(MI_INFO *info,uint keynr,uchar *key);
+extern int _mi_enlarge_root(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key, my_off_t *root);
extern int _mi_insert(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key,
uchar *anc_buff,uchar *key_pos,uchar *key_buff,
uchar *father_buff, uchar *father_keypos,
@@ -690,6 +698,7 @@ void mi_check_print_error _VARARGS((MI_CHECK *param, const char *fmt,...));
void mi_check_print_warning _VARARGS((MI_CHECK *param, const char *fmt,...));
void mi_check_print_info _VARARGS((MI_CHECK *param, const char *fmt,...));
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);
#ifdef THREAD
pthread_handler_decl(thr_find_all_keys,arg);
diff --git a/myisam/sort.c b/myisam/sort.c
index 7ad23df9358..d86aeb6aa3b 100644
--- a/myisam/sort.c
+++ b/myisam/sort.c
@@ -71,7 +71,8 @@ static int NEAR_F merge_buffers(MI_SORT_PARAM *info,uint keys,
BUFFPEK *Fb, BUFFPEK *Tb);
static int NEAR_F merge_index(MI_SORT_PARAM *,uint,uchar **,BUFFPEK *, int,
IO_CACHE *);
-
+static int flush_ft_buf(MI_SORT_PARAM *info);
+
static int NEAR_F write_keys_varlen(MI_SORT_PARAM *info,uchar **sort_keys,
uint count, BUFFPEK *buffpek,
IO_CACHE *tempfile);
@@ -120,7 +121,7 @@ int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages,
info->read_to_buffer=read_to_buffer;
info->write_key=write_merge_key;
}
-
+
my_b_clear(&tempfile);
my_b_clear(&tempfile_for_exceptions);
bzero((char*) &buffpek,sizeof(buffpek));
@@ -207,7 +208,7 @@ int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages,
goto err; /* purecov: inspected */
}
- if (flush_pending_blocks(info))
+ if (flush_ft_buf(info) || flush_pending_blocks(info))
goto err;
if (my_b_inited(&tempfile_for_exceptions))
@@ -478,7 +479,7 @@ int thr_write_keys(MI_SORT_PARAM *sort_param)
fflush(stdout);
}
if (write_index(sinfo, sinfo->sort_keys, sinfo->keys) ||
- flush_pending_blocks(sinfo))
+ flush_ft_buf(sinfo) || flush_pending_blocks(sinfo))
got_error=1;
}
}
@@ -551,6 +552,7 @@ int thr_write_keys(MI_SORT_PARAM *sort_param)
if (merge_index(sinfo, keys, (uchar **)mergebuf,
dynamic_element(&sinfo->buffpek,0,BUFFPEK *),
maxbuffer,&sinfo->tempfile) ||
+ flush_ft_buf(sinfo) ||
flush_pending_blocks(sinfo))
{
got_error=1;
@@ -976,3 +978,16 @@ merge_index(MI_SORT_PARAM *info, uint keys, uchar **sort_keys,
DBUG_RETURN(0);
} /* merge_index */
+static int
+flush_ft_buf(MI_SORT_PARAM *info)
+{
+ int err=0;
+ if (info->sort_info->ft_buf)
+ {
+ err=sort_ft_buf_flush(info);
+ my_free((gptr)info->sort_info->ft_buf, MYF(0));
+ info->sort_info->ft_buf=0;
+ }
+ return err;
+}
+
diff --git a/mysql-test/r/analyse.result b/mysql-test/r/analyse.result
index ede83afe4e1..0cb33526457 100644
--- a/mysql-test/r/analyse.result
+++ b/mysql-test/r/analyse.result
@@ -1,6 +1,9 @@
drop table if exists t1,t2;
create table t1 (i int, j int);
insert into t1 values (1,2), (3,4), (5,6), (7,8);
+select count(*) from t1 procedure analyse();
+Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
+ -6510615555426900571 -6510615555426900571 -6510615555426900571 -6510615555426900571
select * from t1 procedure analyse();
Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
t1.i 1 7 1 1 0 0 4.0000 2.2361 ENUM('1','3','5','7') NOT NULL
diff --git a/mysql-test/r/fulltext.result b/mysql-test/r/fulltext.result
index 1382c31d145..c40e9d9bfa2 100644
--- a/mysql-test/r/fulltext.result
+++ b/mysql-test/r/fulltext.result
@@ -16,6 +16,8 @@ select * from t1 where MATCH(a,b) AGAINST ("indexes collections");
a b
Full-text indexes are called collections
Only MyISAM tables support collections
+select * from t1 where MATCH(a,b) AGAINST ("only");
+a b
select * from t1 where MATCH(a,b) AGAINST ("collections") UNION ALL select * from t1 where MATCH(a,b) AGAINST ("indexes");
a b
Only MyISAM tables support collections
diff --git a/mysql-test/r/fulltext2.result b/mysql-test/r/fulltext2.result
new file mode 100644
index 00000000000..8086faadba4
--- /dev/null
+++ b/mysql-test/r/fulltext2.result
@@ -0,0 +1,871 @@
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (
+i int(10) unsigned not null auto_increment primary key,
+a varchar(255) not null,
+FULLTEXT KEY (a)
+) TYPE=MyISAM;
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaaxxx');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaazzz');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+insert t1 (a) values ('aaayyy');
+repair table t1 quick;
+Table Op Msg_type Msg_text
+test.t1 repair status OK
+select count(*) from t1 where match a against ('aaaxxx');
+count(*)
+260
+select count(*) from t1 where match a against ('aaayyy');
+count(*)
+250
+select count(*) from t1 where match a against ('aaazzz');
+count(*)
+255
+select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
+count(*)
+260
+select count(*) from t1 where match a against ('aaayyy' in boolean mode);
+count(*)
+250
+select count(*) from t1 where match a against ('aaazzz' in boolean mode);
+count(*)
+255
+select count(*) from t1 where match a against ('aaaxxx aaayyy aaazzz');
+count(*)
+765
+select count(*) from t1 where match a against ('aaaxxx aaayyy aaazzz' in boolean mode);
+count(*)
+765
+select count(*) from t1 where match a against ('aaax*' in boolean mode);
+count(*)
+260
+select count(*) from t1 where match a against ('aaay*' in boolean mode);
+count(*)
+250
+select count(*) from t1 where match a against ('aaa*' in boolean mode);
+count(*)
+765
+insert t1 (a) values ('aaaxxx'),('aaayyy');
+insert t1 (a) values ('aaazzz'),('aaazzz'),('aaazzz'),('aaazzz'),('aaazzz');
+select count(*) from t1 where match a against ('aaaxxx');
+count(*)
+261
+select count(*) from t1 where match a against ('aaayyy');
+count(*)
+251
+select count(*) from t1 where match a against ('aaazzz');
+count(*)
+260
+insert t1 (a) values ('aaaxxx 000000');
+select count(*) from t1 where match a against ('000000');
+count(*)
+1
+delete from t1 where match a against ('000000');
+select count(*) from t1 where match a against ('000000');
+count(*)
+0
+select count(*) from t1 where match a against ('aaaxxx');
+count(*)
+261
+delete from t1 where match a against ('aaazzz');
+select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
+count(*)
+261
+select count(*) from t1 where match a against ('aaayyy' in boolean mode);
+count(*)
+251
+select count(*) from t1 where match a against ('aaazzz' in boolean mode);
+count(*)
+0
+select count(*) from t1 where a = 'aaaxxx';
+count(*)
+261
+select count(*) from t1 where a = 'aaayyy';
+count(*)
+251
+select count(*) from t1 where a = 'aaazzz';
+count(*)
+0
+insert t1 (a) values ('aaaxxx 000000');
+select count(*) from t1 where match a against ('000000');
+count(*)
+1
+update t1 set a='aaazzz' where match a against ('000000');
+select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
+count(*)
+261
+select count(*) from t1 where match a against ('aaazzz' in boolean mode);
+count(*)
+1
+update t1 set a='aaazzz' where a = 'aaaxxx';
+update t1 set a='aaaxxx' where a = 'aaayyy';
+select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
+count(*)
+251
+select count(*) from t1 where match a against ('aaayyy' in boolean mode);
+count(*)
+0
+select count(*) from t1 where match a against ('aaazzz' in boolean mode);
+count(*)
+262
+DROP TABLE IF EXISTS t1;
diff --git a/mysql-test/r/handler.result b/mysql-test/r/handler.result
index 35765c48049..b47f97e167f 100644
--- a/mysql-test/r/handler.result
+++ b/mysql-test/r/handler.result
@@ -5,6 +5,8 @@ insert into t1 values
(14,"aaa"),(15,"bbb"),(16,"ccc"),(16,"xxx"),
(20,"ggg"),(21,"hhh"),(22,"iii");
handler t1 open as t2;
+handler t2 read a=(SELECT 1);
+You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT 1)' at line 1
handler t2 read a first;
a b
14 aaa
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 04bf0575db3..2bbbd71f4cd 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -120,6 +120,8 @@ SELECT (SELECT 1.5,2,'a') = ROW(1.5,'c','a');
SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a');
(SELECT 1.5,'c','a') = ROW(1.5,2,'a')
0
+SELECT (SELECT * FROM (SELECT 'test' a,'test' b) a);
+Cardinality error (more/less than 1 columns)
create table t1 (a int);
create table t2 (a int, b int);
create table t3 (a int);
diff --git a/mysql-test/t/analyse.test b/mysql-test/t/analyse.test
index ccbfb56a801..117ca40ce54 100644
--- a/mysql-test/t/analyse.test
+++ b/mysql-test/t/analyse.test
@@ -7,6 +7,7 @@ drop table if exists t1,t2;
--enable_warnings
create table t1 (i int, j int);
insert into t1 values (1,2), (3,4), (5,6), (7,8);
+select count(*) from t1 procedure analyse();
select * from t1 procedure analyse();
create table t2 select * from t1 procedure analyse();
select * from t2;
diff --git a/mysql-test/t/fulltext.test b/mysql-test/t/fulltext.test
index 02c407abd6c..214236268fa 100644
--- a/mysql-test/t/fulltext.test
+++ b/mysql-test/t/fulltext.test
@@ -18,6 +18,7 @@ INSERT INTO t1 VALUES('MySQL has now support', 'for full-text search'),
select * from t1 where MATCH(a,b) AGAINST ("collections");
select * from t1 where MATCH(a,b) AGAINST ("indexes");
select * from t1 where MATCH(a,b) AGAINST ("indexes collections");
+select * from t1 where MATCH(a,b) AGAINST ("only");
# UNION of fulltext's
select * from t1 where MATCH(a,b) AGAINST ("collections") UNION ALL select * from t1 where MATCH(a,b) AGAINST ("indexes");
diff --git a/mysql-test/t/fulltext2.test b/mysql-test/t/fulltext2.test
new file mode 100644
index 00000000000..2c0d352a870
--- /dev/null
+++ b/mysql-test/t/fulltext2.test
@@ -0,0 +1,96 @@
+#
+# test of new fulltext search features
+#
+
+#
+# two-level tree
+#
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1 (
+ i int(10) unsigned not null auto_increment primary key,
+ a varchar(255) not null,
+ FULLTEXT KEY (a)
+) TYPE=MyISAM;
+
+# two-level entry, second-level tree with depth 2
+let $1=260;
+while ($1)
+{
+ eval insert t1 (a) values ('aaaxxx');
+ dec $1;
+}
+
+# two-level entry, second-level tree has only one page
+let $1=255;
+while ($1)
+{
+ eval insert t1 (a) values ('aaazzz');
+ dec $1;
+}
+
+# one-level entry (entries)
+let $1=250;
+while ($1)
+{
+ eval insert t1 (a) values ('aaayyy');
+ dec $1;
+}
+
+# converting to two-level
+repair table t1 quick;
+
+select count(*) from t1 where match a against ('aaaxxx');
+select count(*) from t1 where match a against ('aaayyy');
+select count(*) from t1 where match a against ('aaazzz');
+select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
+select count(*) from t1 where match a against ('aaayyy' in boolean mode);
+select count(*) from t1 where match a against ('aaazzz' in boolean mode);
+select count(*) from t1 where match a against ('aaaxxx aaayyy aaazzz');
+select count(*) from t1 where match a against ('aaaxxx aaayyy aaazzz' in boolean mode);
+
+select count(*) from t1 where match a against ('aaax*' in boolean mode);
+select count(*) from t1 where match a against ('aaay*' in boolean mode);
+select count(*) from t1 where match a against ('aaa*' in boolean mode);
+
+# mi_write:
+
+insert t1 (a) values ('aaaxxx'),('aaayyy');
+# call to enlarge_root() below
+insert t1 (a) values ('aaazzz'),('aaazzz'),('aaazzz'),('aaazzz'),('aaazzz');
+select count(*) from t1 where match a against ('aaaxxx');
+select count(*) from t1 where match a against ('aaayyy');
+select count(*) from t1 where match a against ('aaazzz');
+
+# mi_delete
+insert t1 (a) values ('aaaxxx 000000');
+select count(*) from t1 where match a against ('000000');
+delete from t1 where match a against ('000000');
+select count(*) from t1 where match a against ('000000');
+select count(*) from t1 where match a against ('aaaxxx');
+delete from t1 where match a against ('aaazzz');
+select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
+select count(*) from t1 where match a against ('aaayyy' in boolean mode);
+select count(*) from t1 where match a against ('aaazzz' in boolean mode);
+# double-check without index
+select count(*) from t1 where a = 'aaaxxx';
+select count(*) from t1 where a = 'aaayyy';
+select count(*) from t1 where a = 'aaazzz';
+
+# update
+insert t1 (a) values ('aaaxxx 000000');
+select count(*) from t1 where match a against ('000000');
+update t1 set a='aaazzz' where match a against ('000000');
+select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
+select count(*) from t1 where match a against ('aaazzz' in boolean mode);
+update t1 set a='aaazzz' where a = 'aaaxxx';
+update t1 set a='aaaxxx' where a = 'aaayyy';
+select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
+select count(*) from t1 where match a against ('aaayyy' in boolean mode);
+select count(*) from t1 where match a against ('aaazzz' in boolean mode);
+
+DROP TABLE IF EXISTS t1;
+
diff --git a/mysql-test/t/handler.test b/mysql-test/t/handler.test
index 2b0a6a7be8d..b72b739600e 100644
--- a/mysql-test/t/handler.test
+++ b/mysql-test/t/handler.test
@@ -12,6 +12,8 @@ insert into t1 values
(14,"aaa"),(15,"bbb"),(16,"ccc"),(16,"xxx"),
(20,"ggg"),(21,"hhh"),(22,"iii");
handler t1 open as t2;
+-- error 1064
+handler t2 read a=(SELECT 1);
handler t2 read a first;
handler t2 read a next;
handler t2 read a next;
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index 1dcbd9a282d..b506baa9fdd 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -51,6 +51,9 @@ SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a');
SELECT (SELECT 1.5,2,'a') = ROW(1.5,'c','a');
SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a');
+-- error 1239
+SELECT (SELECT * FROM (SELECT 'test' a,'test' b) a);
+
create table t1 (a int);
create table t2 (a int, b int);
create table t3 (a int);
diff --git a/mysys/mulalloc.c b/mysys/mulalloc.c
index 6b025bca699..e1eb1c00602 100644
--- a/mysys/mulalloc.c
+++ b/mysys/mulalloc.c
@@ -19,16 +19,18 @@
/*
Malloc many pointers at the same time
+ Only ptr1 can be free'd, and doing this will free all
+ the memory allocated. ptr2, etc all point inside big allocated
+ memory area.
SYNOPSIS
my_multi_malloc()
- myFlags Flags
- ... Multiple arguments terminated by null ptr
-
- ptr, length
- ptr, length
+ myFlags Flags
+ ptr1, length1 Multiple arguments terminated by null ptr
+ ptr2, length2 ...
+ ...
NULL
-*/
+*/
gptr my_multi_malloc(myf myFlags, ...)
{
diff --git a/sql/convert.cc b/sql/convert.cc
index 155cb57f9fe..29abdde7ddc 100644
--- a/sql/convert.cc
+++ b/sql/convert.cc
@@ -457,9 +457,6 @@ bool CONVERT::store(String *packet,const char *from,uint length)
return 1;
char *to=(char*) net_store_length((char*) packet->ptr()+packet_length,
(ulonglong)length);
-
- for (const char *end=from+length ; from != end ; from++)
- *to++= to_map[(uchar) *from];
- packet->length((uint) (to-packet->ptr()));
+ packet->length((uint) (store_dest(to, from, length)-packet->ptr()));
return 0;
}
diff --git a/sql/field.cc b/sql/field.cc
index 1aa01b1e2c5..00bb409e82e 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -4578,8 +4578,13 @@ void Field_geom::get_key_image(char *buff,uint length,CHARSET_INFO *cs, imagetyp
void Field_geom::set_key_image(char *buff,uint length,CHARSET_INFO *cs)
{
+ Field_blob::set_key_image(buff, length, cs);
}
+void Field_geom::sql_type(String &res) const
+{
+ res.set("geometry", 8, default_charset_info);
+}
int Field_blob::key_cmp(const byte *key_ptr, uint max_key_length)
{
@@ -5207,7 +5212,8 @@ uint32 calc_pack_length(enum_field_types type,uint32 length)
case FIELD_TYPE_LONGLONG: return 8; /* Don't crash if no longlong */
case FIELD_TYPE_NULL : return 0;
case FIELD_TYPE_TINY_BLOB: return 1+portable_sizeof_char_ptr;
- case FIELD_TYPE_BLOB: return 2+portable_sizeof_char_ptr;
+ case FIELD_TYPE_BLOB:
+ case FIELD_TYPE_GEOMETRY: return 2+portable_sizeof_char_ptr;
case FIELD_TYPE_MEDIUM_BLOB: return 3+portable_sizeof_char_ptr;
case FIELD_TYPE_LONG_BLOB: return 4+portable_sizeof_char_ptr;
case FIELD_TYPE_SET:
@@ -5256,15 +5262,14 @@ Field *make_field(char *ptr, uint32 field_length,
f_packtype(pack_flag),
field_length);
- if (f_is_blob(pack_flag))
- return new Field_blob(ptr,null_pos,null_bit,
- unireg_check, field_name, table,
- pack_length, field_charset);
if (f_is_geom(pack_flag))
return new Field_geom(ptr,null_pos,null_bit,
unireg_check, field_name, table,
pack_length);
-
+ if (f_is_blob(pack_flag))
+ return new Field_blob(ptr,null_pos,null_bit,
+ unireg_check, field_name, table,
+ pack_length, field_charset);
if (interval)
{
if (f_is_enum(pack_flag))
diff --git a/sql/field.h b/sql/field.h
index af479c81b40..97900938e9d 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -948,6 +948,8 @@ public:
:Field_blob(len_arg, maybe_null_arg, field_name_arg,
table_arg, my_charset_bin) {}
enum ha_base_keytype key_type() const { return HA_KEYTYPE_VARBINARY; }
+ enum_field_types type() const { return FIELD_TYPE_GEOMETRY;}
+ void sql_type(String &str) const;
void get_key_image(char *buff,uint length, CHARSET_INFO *cs,imagetype type);
void set_key_image(char *buff,uint length, CHARSET_INFO *cs);
diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc
index 067c066713f..cdb5a8c1219 100644
--- a/sql/ha_berkeley.cc
+++ b/sql/ha_berkeley.cc
@@ -2096,6 +2096,7 @@ static void print_msg(THD *thd, const char *table_name, const char *op_name,
msgbuf[sizeof(msgbuf) - 1] = 0; // healthy paranoia
DBUG_PRINT(msg_type,("message: %s",msgbuf));
+ protocol->set_nfields(4);
protocol->prepare_for_resend();
protocol->store(table_name);
protocol->store(op_name);
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index 6125a616f78..c639431c0fa 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -893,6 +893,7 @@ innobase_commit_low(
/*================*/
trx_t* trx) /* in: transaction handle */
{
+#ifdef HAVE_REPLICATION
if (current_thd->slave_thread) {
/* Update the replication position info inside InnoDB */
#ifdef NEED_TO_BE_FIXED
@@ -906,6 +907,7 @@ innobase_commit_low(
active_mi->rli.event_len +
active_mi->rli.pending));
}
+#endif /* HAVE_REPLICATION */
trx_commit_for_mysql(trx);
}
@@ -2510,11 +2512,6 @@ ha_innobase::change_active_index(
the flag ROW_MYSQL_WHOLE_ROW below, but that caused unnecessary
copying. Starting from MySQL-4.1 we use a more efficient flag here. */
- /*
- TODO: In 4.0 the below user_thd was changed to NULL.
- Heikki, please delete this comment after you have read this and may
- acted upon it.
- */
build_template(prebuilt, user_thd, table, ROW_MYSQL_REC_FIELDS);
DBUG_RETURN(0);
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index 84dec41ea07..754d7dc8641 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -60,11 +60,14 @@ static void mi_check_print_msg(MI_CHECK *param, const char* msg_type,
DBUG_PRINT(msg_type,("message: %s",msgbuf));
+#ifndef EMBEDDED_LIBRARY
if (thd->net.vio == 0)
{
sql_print_error(msgbuf);
return;
}
+#endif
+
if (param->testflag & (T_CREATE_MISSING_KEYS | T_SAFE_REPAIR |
T_AUTO_REPAIR))
{
@@ -136,6 +139,7 @@ const char *ha_myisam::index_type(uint key_number)
"BTREE");
}
+#ifdef HAVE_REPLICATION
int ha_myisam::net_read_dump(NET* net)
{
int data_fd = file->dfile;
@@ -160,7 +164,6 @@ int ha_myisam::net_read_dump(NET* net)
goto err;
}
}
-
err:
return error;
}
@@ -217,6 +220,7 @@ err:
my_free((gptr) buf, MYF(0));
return error;
}
+#endif /* HAVE_REPLICATION */
/* Name is here without an extension */
@@ -1053,8 +1057,9 @@ int ha_myisam::create(const char *name, register TABLE *table_arg,
for (i=0; i < table_arg->keys ; i++, pos++)
{
keydef[i].flag= (pos->flags & (HA_NOSAME | HA_FULLTEXT | HA_SPATIAL));
- keydef[i].key_alg=pos->algorithm == HA_KEY_ALG_UNDEF ?
- HA_KEY_ALG_BTREE : pos->algorithm;
+ keydef[i].key_alg= pos->algorithm == HA_KEY_ALG_UNDEF ?
+ (pos->flags & HA_SPATIAL ? HA_KEY_ALG_RTREE : HA_KEY_ALG_BTREE) :
+ pos->algorithm;
keydef[i].seg=keyseg;
keydef[i].keysegs=pos->key_parts;
for (j=0 ; j < pos->key_parts ; j++)
@@ -1108,7 +1113,7 @@ int ha_myisam::create(const char *name, register TABLE *table_arg,
keydef[i].flag|=HA_AUTO_KEY;
found_auto_increment=1;
}
- if (field->type() == FIELD_TYPE_BLOB)
+ if ((field->type() == FIELD_TYPE_BLOB) || (field->type() == FIELD_TYPE_GEOMETRY))
{
keydef[i].seg[j].flag|=HA_BLOB_PART;
/* save number of bytes used to pack length */
diff --git a/sql/ha_myisam.h b/sql/ha_myisam.h
index 215608f8f0a..5dc294b3b9f 100644
--- a/sql/ha_myisam.h
+++ b/sql/ha_myisam.h
@@ -127,6 +127,8 @@ class ha_myisam: public handler
int optimize(THD* thd, HA_CHECK_OPT* check_opt);
int restore(THD* thd, HA_CHECK_OPT* check_opt);
int backup(THD* thd, HA_CHECK_OPT* check_opt);
+#ifdef HAVE_REPLICATION
int dump(THD* thd, int fd);
int net_read_dump(NET* net);
+#endif
};
diff --git a/sql/item.cc b/sql/item.cc
index a4f7008aa4e..6ae9b92295f 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -567,7 +567,9 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
cause error ER_NON_UNIQ_ERROR in find_field_in_tables.
*/
SELECT_LEX *last= 0;
-
+#ifdef EMBEDDED_LIBRARY
+ thd->net.last_errno= 0;
+#endif
Item **refer= (Item **)not_found_item;
// Prevent using outer fields in subselects, that is not supported now
SELECT_LEX *cursel=(SELECT_LEX *) thd->lex.current_select;
@@ -605,7 +607,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
(char *)field_name);
if (!r)
return 1;
- if (r->check_cols(1) || r->fix_fields(thd, tables, ref))
+ if (r->fix_fields(thd, tables, ref) || r->check_cols(1))
return 1;
r->depended_from= last;
cursel->mark_as_dependent(last);
@@ -629,7 +631,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
if (!rf)
return 1;
(rf)->outer_resolving= outer_resolving;
- return rf->check_cols(1) || rf->fix_fields(thd, tables, ref);
+ return rf->fix_fields(thd, tables, ref) || rf->check_cols(1);
}
}
}
diff --git a/sql/item.h b/sql/item.h
index 03e9a542eea..09882b26724 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -182,6 +182,7 @@ public:
String *val_str(String *str);
int save_in_field(Field *field, bool no_conversions);
int save_safe_in_field(Field *field);
+ bool send(Protocol *protocol, String *str);
enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_NULL; }
bool fix_fields(THD *thd, struct st_table_list *list, Item **item)
@@ -190,7 +191,6 @@ public:
max_length=0;
return res;
}
- bool send(Protocol *protocol, String *str);
bool basic_const_item() const { return 1; }
Item *new_item() { return new Item_null(name); }
bool is_null() { return 1; }
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 829caeede1d..1c579708503 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -912,10 +912,10 @@ double Item_func_case::val()
bool
Item_func_case::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
{
- if (first_expr && (first_expr->check_cols(1) ||
- first_expr->fix_fields(thd, tables, &first_expr)) ||
- else_expr && (else_expr->check_cols(1) ||
- else_expr->fix_fields(thd, tables, &else_expr)))
+ if (first_expr && (first_expr->fix_fields(thd, tables, &first_expr) ||
+ first_expr->check_cols(1)) ||
+ else_expr && (else_expr->fix_fields(thd, tables, &else_expr) ||
+ else_expr->check_cols(1)))
return 1;
if (Item_func::fix_fields(thd, tables, ref))
return 1;
@@ -1472,7 +1472,7 @@ Item_cond::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
}
if (abort_on_null)
item->top_level_item();
- if (item->check_cols(1) || item->fix_fields(thd, tables, li.ref()))
+ if (item->fix_fields(thd, tables, li.ref()) || item->check_cols(1))
return 1; /* purecov: inspected */
used_tables_cache|=item->used_tables();
with_sum_func= with_sum_func || item->with_sum_func;
@@ -1784,10 +1784,8 @@ bool Item_func_like::fix_fields(THD *thd, TABLE_LIST *tlist, Item ** ref)
bool
Item_func_regex::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
{
- if (args[0]->check_cols(1) ||
- args[1]->check_cols(1) ||
- args[0]->fix_fields(thd, tables, args) ||
- args[1]->fix_fields(thd,tables, args + 1))
+ if (args[0]->fix_fields(thd, tables, args) || args[0]->check_cols(1) ||
+ args[1]->fix_fields(thd,tables, args + 1) || args[1]->check_cols(1))
return 1; /* purecov: inspected */
with_sum_func=args[0]->with_sum_func || args[1]->with_sum_func;
max_length= 1;
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index bd7d1bfaf7a..8641ab410b3 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -275,8 +275,7 @@ public:
longlong val_int();
bool fix_fields(THD *thd, struct st_table_list *tlist, Item **ref)
{
- return (item->check_cols(1) ||
- item->fix_fields(thd, tlist, &item) ||
+ return (item->fix_fields(thd, tlist, &item) || item->check_cols(1) ||
Item_func::fix_fields(thd, tlist, ref));
}
void fix_length_and_dec();
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 6ba6ba13744..477b759be61 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -109,8 +109,8 @@ Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
*/
for (arg=args, arg_end=args+arg_count; arg != arg_end ; arg++)
{
- if ((*arg)->check_cols(allowed_arg_cols) ||
- (*arg)->fix_fields(thd, tables, arg))
+ if ((*arg)->fix_fields(thd, tables, arg) ||
+ (*arg)->check_cols(allowed_arg_cols))
return 1; /* purecov: inspected */
if ((*arg)->maybe_null)
maybe_null=1;
@@ -1322,7 +1322,7 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func,
arg != arg_end ;
arg++,i++)
{
- if ((*arg)->check_cols(1) || (*arg)->fix_fields(thd, tables, arg))
+ if ((*arg)->fix_fields(thd, tables, arg) || (*arg)->check_cols(1))
return 1;
if ((*arg)->binary())
func->set_charset(my_charset_bin);
@@ -1665,6 +1665,7 @@ longlong Item_master_pos_wait::val_int()
return 0;
}
ulong pos = (ulong)args[1]->val_int();
+#ifdef HAVE_REPLICATION
LOCK_ACTIVE_MI;
if ((event_count = active_mi->rli.wait_for_pos(thd, log_name, pos)) == -1)
{
@@ -1672,6 +1673,7 @@ longlong Item_master_pos_wait::val_int()
event_count=0;
}
UNLOCK_ACTIVE_MI;
+#endif
return event_count;
}
@@ -2330,7 +2332,7 @@ bool Item_func_match::fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref)
while ((item=li++))
{
- if (item->check_cols(1) || item->fix_fields(thd, tlist, li.ref()))
+ if (item->fix_fields(thd, tlist, li.ref()) || item->check_cols(1))
return 1;
if (item->type() == Item::REF_ITEM)
li.replace(item= *((Item_ref *)item)->ref);
diff --git a/sql/item_func.h b/sql/item_func.h
index a015f6e69ce..ec361cce4c5 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -608,8 +608,7 @@ public:
longlong val_int();
bool fix_fields(THD *thd,struct st_table_list *tlist, Item **ref)
{
- return (item->check_cols(1) ||
- item->fix_fields(thd, tlist, &item) ||
+ return (item->fix_fields(thd, tlist, &item) || item->check_cols(1) ||
Item_func::fix_fields(thd, tlist, ref));
}
void update_used_tables()
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index df2352db231..66f0510cc3d 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -2133,7 +2133,7 @@ bool Item_func_conv_charset::fix_fields(THD *thd,struct st_table_list *tables, I
if (thd && check_stack_overrun(thd,buff))
return 0; // Fatal error if flag is set!
- if (args[0]->check_cols(1) || args[0]->fix_fields(thd, tables, args))
+ if (args[0]->fix_fields(thd, tables, args) || args[0]->check_cols(1))
return 1;
maybe_null=args[0]->maybe_null;
const_item_cache=args[0]->const_item();
@@ -2166,7 +2166,7 @@ bool Item_func_set_collation::fix_fields(THD *thd,struct st_table_list *tables,
if (thd && check_stack_overrun(thd,buff))
return 0; // Fatal error if flag is set!
- if (args[0]->check_cols(1) || args[0]->fix_fields(thd, tables, args))
+ if (args[0]->fix_fields(thd, tables, args) || args[0]->check_cols(1))
return 1;
maybe_null=args[0]->maybe_null;
set_charset(set_collation);
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index c56c59bcaef..339a49a3580 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -101,8 +101,8 @@ public:
void update_used_tables();
bool fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref)
{
- return (separator->check_cols(1) ||
- separator->fix_fields(thd, tlist, &separator) ||
+ return (separator->fix_fields(thd, tlist, &separator) ||
+ separator->check_cols(1) ||
Item_func::fix_fields(thd, tlist, ref));
}
const char *func_name() const { return "concat_ws"; }
@@ -382,8 +382,8 @@ public:
String *val_str(String *str);
bool fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref)
{
- return (item->check_cols(1) ||
- item->fix_fields(thd, tlist, &item) ||
+ return (item->fix_fields(thd, tlist, &item) ||
+ item->check_cols(1) ||
Item_func::fix_fields(thd, tlist, ref));
}
void fix_length_and_dec();
@@ -415,8 +415,8 @@ public:
String *val_str(String *str);
bool fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref)
{
- return (item->check_cols(1) ||
- item->fix_fields(thd, tlist, &item) ||
+ return (item->fix_fields(thd, tlist, &item) ||
+ item->check_cols(1) ||
Item_func::fix_fields(thd, tlist, ref));
}
void fix_length_and_dec();
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index cc90cd8fcd8..273c5a3c1c3 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -119,7 +119,7 @@ Item_sum_num::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
maybe_null=0;
for (uint i=0 ; i < arg_count ; i++)
{
- if (args[i]->check_cols(1) || args[i]->fix_fields(thd, tables, args + i))
+ if (args[i]->fix_fields(thd, tables, args + i) || args[i]->check_cols(1))
return 1;
if (decimals < args[i]->decimals)
decimals=args[i]->decimals;
@@ -145,7 +145,7 @@ Item_sum_hybrid::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
return 1;
}
thd->allow_sum_func=0; // No included group funcs
- if (item->check_cols(1) || item->fix_fields(thd, tables, args))
+ if (item->fix_fields(thd, tables, args) || item->check_cols(1))
return 1;
hybrid_type=item->result_type();
if (hybrid_type == INT_RESULT)
diff --git a/sql/log.cc b/sql/log.cc
index 033896a2674..b0e904969e7 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -201,7 +201,9 @@ bool MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg,
case LOG_NORMAL:
{
char *end;
-#ifdef __NT__
+#ifdef EMBEDDED_LIBRARY
+ sprintf(buff, "%s, Version: %s, embedded library\n", my_progname, server_version);
+#elif __NT__
sprintf(buff, "%s, Version: %s, started with:\nTCP Port: %d, Named Pipe: %s\n", my_progname, server_version, mysql_port, mysql_unix_port);
#else
sprintf(buff, "%s, Version: %s, started with:\nTcp port: %d Unix socket: %s\n", my_progname,server_version,mysql_port,mysql_unix_port);
@@ -611,6 +613,8 @@ err:
LOG_INFO_IO Got IO error while reading file
*/
+#ifdef HAVE_REPLICATION
+
int MYSQL_LOG::purge_first_log(struct st_relay_log_info* rli)
{
int error;
@@ -745,6 +749,8 @@ err:
DBUG_RETURN(error);
}
+#endif /* HAVE_REPLICATION */
+
/*
Create a new log file name
@@ -1054,6 +1060,7 @@ bool MYSQL_LOG::write(Log_event* event_info)
#else
IO_CACHE *file = &log_file;
#endif
+#ifdef HAVE_REPLICATION
if ((thd && !(thd->options & OPTION_BIN_LOG) &&
(thd->master_access & SUPER_ACL)) ||
(local_db && !db_ok(local_db, binlog_do_db, binlog_ignore_db)))
@@ -1062,6 +1069,7 @@ bool MYSQL_LOG::write(Log_event* event_info)
DBUG_PRINT("error",("!db_ok"));
DBUG_RETURN(0);
}
+#endif /* HAVE_REPLICATION */
error=1;
/*
@@ -1444,6 +1452,7 @@ void MYSQL_LOG::close(bool exiting)
DBUG_PRINT("enter",("exiting: %d", (int) exiting));
if (is_open())
{
+#ifdef HAVE_REPLICATION
if (log_type == LOG_BIN && !no_auto_events && exiting)
{
Stop_log_event s;
@@ -1451,6 +1460,7 @@ void MYSQL_LOG::close(bool exiting)
s.write(&log_file);
signal_update();
}
+#endif /* HAVE_REPLICATION */
end_io_cache(&log_file);
if (my_close(log_file.file,MYF(0)) < 0 && ! write_error)
{
@@ -1574,3 +1584,6 @@ void sql_perror(const char *message)
perror(message);
#endif
}
+
+
+
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 248bac04df2..509e62ba03b 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -80,12 +80,12 @@ static void pretty_print_str(FILE* file, char* str, int len)
ignored_error_code()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
inline int ignored_error_code(int err_code)
{
return use_slave_mask && bitmap_is_set(&slave_error_mask, err_code);
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -124,7 +124,7 @@ static char* pretty_print_str(char* packet, char* str, int len)
slave_load_file_stem()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
static inline char* slave_load_file_stem(char*buf, uint file_id,
int event_server_id)
{
@@ -136,7 +136,7 @@ static inline char* slave_load_file_stem(char*buf, uint file_id,
*buf++ = '-';
return int10_to_str(file_id, buf, 10);
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -150,7 +150,7 @@ static inline char* slave_load_file_stem(char*buf, uint file_id,
Easily fixable by adding server_id as a prefix to the log files.
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
static void cleanup_load_tmpdir()
{
MY_DIR *dirp;
@@ -168,7 +168,7 @@ static void cleanup_load_tmpdir()
my_dirend(dirp);
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -286,6 +286,7 @@ Log_event::Log_event(const char* buf, bool old_format)
#ifndef MYSQL_CLIENT
+#ifdef HAVE_REPLICATION
/*****************************************************************************
@@ -329,23 +330,6 @@ void Log_event::pack_info(Protocol *protocol)
protocol->store("",0);
}
-/*****************************************************************************
-
- Log_event::init_show_field_list()
-
- ****************************************************************************/
-void Log_event::init_show_field_list(List<Item>* field_list)
-{
- field_list->push_back(new Item_empty_string("Log_name", 20));
- field_list->push_back(new Item_return_int("Pos", 11,
- MYSQL_TYPE_LONGLONG));
- field_list->push_back(new Item_empty_string("Event_type", 20));
- field_list->push_back(new Item_return_int("Server_id", 10,
- MYSQL_TYPE_LONG));
- field_list->push_back(new Item_return_int("Orig_log_pos", 11,
- MYSQL_TYPE_LONGLONG));
- field_list->push_back(new Item_empty_string("Info", 20));
-}
/*****************************************************************************
@@ -354,6 +338,7 @@ void Log_event::init_show_field_list(List<Item>* field_list)
Only called by SHOW BINLOG EVENTS
****************************************************************************/
+
int Log_event::net_send(Protocol *protocol, const char* log_name, my_off_t pos)
{
const char *p= strrchr(log_name, FN_LIBCHAR);
@@ -371,6 +356,26 @@ int Log_event::net_send(Protocol *protocol, const char* log_name, my_off_t pos)
pack_info(protocol);
return protocol->write();
}
+#endif /* HAVE_REPLICATION */
+
+/*****************************************************************************
+
+ Log_event::init_show_field_list()
+
+ ****************************************************************************/
+void Log_event::init_show_field_list(List<Item>* field_list)
+{
+ field_list->push_back(new Item_empty_string("Log_name", 20));
+ field_list->push_back(new Item_return_int("Pos", 11,
+ MYSQL_TYPE_LONGLONG));
+ field_list->push_back(new Item_empty_string("Event_type", 20));
+ field_list->push_back(new Item_return_int("Server_id", 10,
+ MYSQL_TYPE_LONG));
+ field_list->push_back(new Item_return_int("Orig_log_pos", 11,
+ MYSQL_TYPE_LONGLONG));
+ field_list->push_back(new Item_empty_string("Info", 20));
+}
+
#endif // !MYSQL_CLIENT
/*****************************************************************************
@@ -578,9 +583,11 @@ Log_event* Log_event::read_log_event(const char* buf, int event_len,
case ROTATE_EVENT:
ev = new Rotate_log_event(buf, event_len, old_format);
break;
+#ifdef HAVE_REPLICATION
case SLAVE_EVENT:
ev = new Slave_log_event(buf, event_len);
break;
+#endif /* HAVE_REPLICATION */
case CREATE_FILE_EVENT:
ev = new Create_file_log_event(buf, event_len, old_format);
break;
@@ -596,9 +603,11 @@ Log_event* Log_event::read_log_event(const char* buf, int event_len,
case START_EVENT:
ev = new Start_log_event(buf, old_format);
break;
+#ifdef HAVE_REPLICATION
case STOP_EVENT:
ev = new Stop_log_event(buf, old_format);
break;
+#endif /* HAVE_REPLICATION */
case INTVAR_EVENT:
ev = new Intvar_log_event(buf, old_format);
break;
@@ -685,7 +694,7 @@ void Log_event::set_log_pos(MYSQL_LOG* log)
*****************************************************************************
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
/*****************************************************************************
Query_log_event::pack_info()
@@ -712,7 +721,7 @@ void Query_log_event::pack_info(Protocol *protocol)
protocol->store(buf, pos-buf);
my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -849,7 +858,7 @@ void Query_log_event::print(FILE* file, bool short_form, char* last_db)
Query_log_event::exec_event()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
int Query_log_event::exec_event(struct st_relay_log_info* rli)
{
int expected_error,actual_error = 0;
@@ -955,7 +964,7 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli)
free_root(&thd->mem_root,0);
return Log_event::exec_event(rli);
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -971,7 +980,7 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli)
Start_log_event::pack_info()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
void Start_log_event::pack_info(Protocol *protocol)
{
char buf[12 + ST_SERVER_VER_LEN + 14 + 22], *pos;
@@ -981,7 +990,7 @@ void Start_log_event::pack_info(Protocol *protocol)
pos=int10_to_str(binlog_version, pos, 10);
protocol->store(buf, pos-buf);
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -1050,7 +1059,7 @@ int Start_log_event::write_data(IO_CACHE* file)
In this case we should stop the slave.
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
int Start_log_event::exec_event(struct st_relay_log_info* rli)
{
/* All temporary tables was deleted on the master */
@@ -1062,7 +1071,7 @@ int Start_log_event::exec_event(struct st_relay_log_info* rli)
cleanup_load_tmpdir();
return Log_event::exec_event(rli);
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -1078,7 +1087,7 @@ int Start_log_event::exec_event(struct st_relay_log_info* rli)
Load_log_event::pack_info()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
void Load_log_event::pack_info(Protocol *protocol)
{
char *buf, *pos;
@@ -1181,7 +1190,7 @@ void Load_log_event::pack_info(Protocol *protocol)
protocol->store(buf, pos-buf);
my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -1483,8 +1492,7 @@ void Load_log_event::set_fields(List<Item> &field_list)
}
#endif // !MYSQL_CLIENT
-#ifndef MYSQL_CLIENT
-
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
/*
Does the data loading job when executing a LOAD DATA on the slave
@@ -1624,7 +1632,7 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli,
return ( use_rli_only_for_errors ? 0 : Log_event::exec_event(rli) );
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -1640,7 +1648,7 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli,
Rotate_log_event::pack_info()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
void Rotate_log_event::pack_info(Protocol *protocol)
{
char *buf, *b_pos;
@@ -1656,7 +1664,7 @@ void Rotate_log_event::pack_info(Protocol *protocol)
protocol->store(buf, b_pos-buf);
my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -1749,7 +1757,7 @@ int Rotate_log_event::write_data(IO_CACHE* file)
0 ok
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
int Rotate_log_event::exec_event(struct st_relay_log_info* rli)
{
char* log_name = rli->master_log_name;
@@ -1765,7 +1773,7 @@ int Rotate_log_event::exec_event(struct st_relay_log_info* rli)
flush_relay_log_info(rli);
DBUG_RETURN(0);
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -1781,7 +1789,7 @@ int Rotate_log_event::exec_event(struct st_relay_log_info* rli)
Intvar_log_event::pack_info()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
void Intvar_log_event::pack_info(Protocol *protocol)
{
char buf[64], *pos;
@@ -1790,7 +1798,7 @@ void Intvar_log_event::pack_info(Protocol *protocol)
pos= longlong10_to_str(val, pos, -10);
protocol->store(buf, pos-buf);
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -1869,7 +1877,7 @@ void Intvar_log_event::print(FILE* file, bool short_form, char* last_db)
Intvar_log_event::exec_event()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION)&& !defined(MYSQL_CLIENT)
int Intvar_log_event::exec_event(struct st_relay_log_info* rli)
{
switch (type) {
@@ -1884,7 +1892,7 @@ int Intvar_log_event::exec_event(struct st_relay_log_info* rli)
rli->inc_pending(get_event_len());
return 0;
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -1900,7 +1908,7 @@ int Intvar_log_event::exec_event(struct st_relay_log_info* rli)
Rand_log_event::pack_info()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
void Rand_log_event::pack_info(Protocol *protocol)
{
char buf1[256], *pos;
@@ -1910,7 +1918,7 @@ void Rand_log_event::pack_info(Protocol *protocol)
pos= int10_to_str((long) seed2, pos, 10);
protocol->store(buf1, (uint) (pos-buf1));
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -1963,7 +1971,7 @@ void Rand_log_event::print(FILE* file, bool short_form, char* last_db)
Rand_log_event::exec_event()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
int Rand_log_event::exec_event(struct st_relay_log_info* rli)
{
thd->rand.seed1= (ulong) seed1;
@@ -1971,7 +1979,7 @@ int Rand_log_event::exec_event(struct st_relay_log_info* rli)
rli->inc_pending(get_event_len());
return 0;
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -1987,6 +1995,8 @@ int Rand_log_event::exec_event(struct st_relay_log_info* rli)
Slave_log_event::pack_info()
****************************************************************************/
+#ifdef HAVE_REPLICATION
+
#ifndef MYSQL_CLIENT
void Slave_log_event::pack_info(Protocol *protocol)
{
@@ -2207,6 +2217,7 @@ int Stop_log_event::exec_event(struct st_relay_log_info* rli)
return 0;
}
#endif // !MYSQL_CLIENT
+#endif /* HAVE_REPLICATION */
/*****************************************************************************
@@ -2350,7 +2361,7 @@ void Create_file_log_event::print(FILE* file, bool short_form,
Create_file_log_event::pack_info()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
void Create_file_log_event::pack_info(Protocol *protocol)
{
char buf[NAME_LEN*2 + 30 + 21*2], *pos;
@@ -2366,14 +2377,14 @@ void Create_file_log_event::pack_info(Protocol *protocol)
pos= int10_to_str((long) block_len, pos, 10);
protocol->store(buf, pos-buf);
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
Create_file_log_event::exec_event()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
int Create_file_log_event::exec_event(struct st_relay_log_info* rli)
{
char fname_buf[FN_REFLEN+10];
@@ -2430,7 +2441,7 @@ err:
my_close(fd, MYF(0));
return error ? 1 : Log_event::exec_event(rli);
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -2507,7 +2518,7 @@ void Append_block_log_event::print(FILE* file, bool short_form,
Append_block_log_event::pack_info()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
void Append_block_log_event::pack_info(Protocol *protocol)
{
char buf[256];
@@ -2517,14 +2528,14 @@ void Append_block_log_event::pack_info(Protocol *protocol)
block_len));
protocol->store(buf, (int32) length);
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
Append_block_log_event::exec_event()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
int Append_block_log_event::exec_event(struct st_relay_log_info* rli)
{
char fname[FN_REFLEN+10];
@@ -2552,7 +2563,7 @@ err:
my_close(fd, MYF(0));
return error ? error : Log_event::exec_event(rli);
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -2622,7 +2633,7 @@ void Delete_file_log_event::print(FILE* file, bool short_form,
Delete_file_log_event::pack_info()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
void Delete_file_log_event::pack_info(Protocol *protocol)
{
char buf[64];
@@ -2630,14 +2641,14 @@ void Delete_file_log_event::pack_info(Protocol *protocol)
length= (uint) my_sprintf(buf, (buf, ";file_id=%u", (uint) file_id));
protocol->store(buf, (int32) length);
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
Delete_file_log_event::exec_event()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
int Delete_file_log_event::exec_event(struct st_relay_log_info* rli)
{
char fname[FN_REFLEN+10];
@@ -2650,7 +2661,7 @@ int Delete_file_log_event::exec_event(struct st_relay_log_info* rli)
mysql_bin_log.write(this);
return Log_event::exec_event(rli);
}
-#endif // !MYSQL_CLIENT
+#endif
/*****************************************************************************
@@ -2721,7 +2732,7 @@ void Execute_load_log_event::print(FILE* file, bool short_form,
Execute_load_log_event::pack_info()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
void Execute_load_log_event::pack_info(Protocol *protocol)
{
char buf[64];
@@ -2729,14 +2740,13 @@ void Execute_load_log_event::pack_info(Protocol *protocol)
length= (uint) my_sprintf(buf, (buf, ";file_id=%u", (uint) file_id));
protocol->store(buf, (int32) length);
}
-#endif // !MYSQL_CLIENT
/*****************************************************************************
Execute_load_log_event::exec_event()
****************************************************************************/
-#ifndef MYSQL_CLIENT
+
int Execute_load_log_event::exec_event(struct st_relay_log_info* rli)
{
char fname[FN_REFLEN+10];
@@ -2799,7 +2809,8 @@ err:
}
return error ? error : Log_event::exec_event(rli);
}
-#endif // !MYSQL_CLIENT
+
+#endif
/*****************************************************************************
@@ -2891,8 +2902,3 @@ char* sql_ex_info::init(char* buf,char* buf_end,bool use_new_format)
}
-
-
-
-
-
diff --git a/sql/log_event.h b/sql/log_event.h
index 8046d0abb92..29fdf80b03b 100644
--- a/sql/log_event.h
+++ b/sql/log_event.h
@@ -269,10 +269,12 @@ public:
static int read_log_event(IO_CACHE* file, String* packet,
pthread_mutex_t* log_lock);
void set_log_pos(MYSQL_LOG* log);
- virtual void pack_info(Protocol *protocol);
- int net_send(Protocol *protocol, const char* log_name, my_off_t pos);
static void init_show_field_list(List<Item>* field_list);
+#ifdef HAVE_REPLICATION
+ int net_send(Protocol *protocol, const char* log_name, my_off_t pos);
+ virtual void pack_info(Protocol *protocol);
virtual int exec_event(struct st_relay_log_info* rli);
+#endif /* HAVE_REPLICATION */
virtual const char* get_db()
{
return thd ? thd->db : 0;
@@ -357,8 +359,10 @@ public:
Query_log_event(THD* thd_arg, const char* query_arg, ulong query_length,
bool using_trans);
const char* get_db() { return db; }
+#ifdef HAVE_REPLICATION
void pack_info(Protocol* protocol);
int exec_event(struct st_relay_log_info* rli);
+#endif /* HAVE_REPLICATION */
#else
void print(FILE* file, bool short_form = 0, char* last_db = 0);
#endif
@@ -385,6 +389,7 @@ public:
}
};
+#ifdef HAVE_REPLICATION
/*****************************************************************************
@@ -420,6 +425,8 @@ public:
int write_data(IO_CACHE* file );
};
+#endif /* HAVE_REPLICATION */
+
/*****************************************************************************
@@ -463,14 +470,16 @@ public:
List<Item>& fields_arg, enum enum_duplicates handle_dup,
bool using_trans);
void set_fields(List<Item> &fields_arg);
- void pack_info(Protocol* protocol);
const char* get_db() { return db; }
+#ifdef HAVE_REPLICATION
+ void pack_info(Protocol* protocol);
int exec_event(struct st_relay_log_info* rli)
{
return exec_event(thd->slave_net,rli,0);
}
int exec_event(NET* net, struct st_relay_log_info* rli,
bool use_rli_only_for_errors);
+#endif /* HAVE_REPLICATION */
#else
void print(FILE* file, bool short_form = 0, char* last_db = 0);
#endif
@@ -517,8 +526,10 @@ public:
created = (uint32) when;
memcpy(server_version, ::server_version, ST_SERVER_VER_LEN);
}
+#ifdef HAVE_REPLICATION
void pack_info(Protocol* protocol);
int exec_event(struct st_relay_log_info* rli);
+#endif /* HAVE_REPLICATION */
#else
void print(FILE* file, bool short_form = 0, char* last_db = 0);
#endif
@@ -552,8 +563,10 @@ public:
Intvar_log_event(THD* thd_arg,uchar type_arg, ulonglong val_arg)
:Log_event(),val(val_arg),type(type_arg)
{}
+#ifdef HAVE_REPLICATION
void pack_info(Protocol* protocol);
int exec_event(struct st_relay_log_info* rli);
+#endif /* HAVE_REPLICATION */
#else
void print(FILE* file, bool short_form = 0, char* last_db = 0);
#endif
@@ -584,8 +597,10 @@ class Rand_log_event: public Log_event
Rand_log_event(THD* thd_arg, ulonglong seed1_arg, ulonglong seed2_arg)
:Log_event(thd_arg,0,0),seed1(seed1_arg),seed2(seed2_arg)
{}
+#ifdef HAVE_REPLICATION
void pack_info(Protocol* protocol);
int exec_event(struct st_relay_log_info* rli);
+#endif /* HAVE_REPLICATION */
#else
void print(FILE* file, bool short_form = 0, char* last_db = 0);
#endif
@@ -604,6 +619,8 @@ class Rand_log_event: public Log_event
Stop Log Event class
****************************************************************************/
+#ifdef HAVE_REPLICATION
+
class Stop_log_event: public Log_event
{
public:
@@ -623,6 +640,8 @@ public:
bool is_valid() { return 1; }
};
+#endif /* HAVE_REPLICATION */
+
/*****************************************************************************
@@ -646,8 +665,10 @@ public:
pos(pos_arg),ident_len(ident_len_arg ? ident_len_arg :
(uint) strlen(new_log_ident_arg)), alloced(0)
{}
+#ifdef HAVE_REPLICATION
void pack_info(Protocol* protocol);
int exec_event(struct st_relay_log_info* rli);
+#endif /* HAVE_REPLICATION */
#else
void print(FILE* file, bool short_form = 0, char* last_db = 0);
#endif
@@ -693,8 +714,10 @@ public:
enum enum_duplicates handle_dup,
char* block_arg, uint block_len_arg,
bool using_trans);
+#ifdef HAVE_REPLICATION
void pack_info(Protocol* protocol);
int exec_event(struct st_relay_log_info* rli);
+#endif /* HAVE_REPLICATION */
#else
void print(FILE* file, bool short_form = 0, char* last_db = 0);
void print(FILE* file, bool short_form, char* last_db, bool enable_local);
@@ -744,8 +767,10 @@ public:
#ifndef MYSQL_CLIENT
Append_block_log_event(THD* thd, char* block_arg,
uint block_len_arg, bool using_trans);
+#ifdef HAVE_REPLICATION
int exec_event(struct st_relay_log_info* rli);
void pack_info(Protocol* protocol);
+#endif /* HAVE_REPLICATION */
#else
void print(FILE* file, bool short_form = 0, char* last_db = 0);
#endif
@@ -770,8 +795,10 @@ public:
#ifndef MYSQL_CLIENT
Delete_file_log_event(THD* thd, bool using_trans);
+#ifdef HAVE_REPLICATION
void pack_info(Protocol* protocol);
int exec_event(struct st_relay_log_info* rli);
+#endif /* HAVE_REPLICATION */
#else
void print(FILE* file, bool short_form = 0, char* last_db = 0);
#endif
@@ -796,8 +823,10 @@ public:
#ifndef MYSQL_CLIENT
Execute_load_log_event(THD* thd, bool using_trans);
+#ifdef HAVE_REPLICATION
void pack_info(Protocol* protocol);
int exec_event(struct st_relay_log_info* rli);
+#endif /* HAVE_REPLICATION */
#else
void print(FILE* file, bool short_form = 0, char* last_db = 0);
#endif
diff --git a/sql/mf_iocache.cc b/sql/mf_iocache.cc
index 742f94c9e2b..4b0575c8579 100644
--- a/sql/mf_iocache.cc
+++ b/sql/mf_iocache.cc
@@ -32,6 +32,7 @@
#define MAP_TO_USE_RAID
#include "mysql_priv.h"
+#ifdef HAVE_REPLICATION
#ifdef HAVE_AIOWAIT
#include <mysys_err.h>
#include <errno.h>
@@ -80,3 +81,6 @@ int _my_b_net_read(register IO_CACHE *info, byte *Buffer,
}
} /* extern "C" */
+#endif /* HAVE_REPLICATION */
+
+
diff --git a/sql/mini_client.cc b/sql/mini_client.cc
index 02a0156ce5b..2ee4b551d71 100644
--- a/sql/mini_client.cc
+++ b/sql/mini_client.cc
@@ -23,6 +23,8 @@
*/
#include <my_global.h>
+#ifdef HAVE_EXTERNAL_CLIENT
+
/* my_pthread must be included early to be able to fix things */
#if defined(THREAD)
#include <my_pthread.h> /* because of signal() */
@@ -1476,3 +1478,5 @@ MYSQL_RES *mc_mysql_store_result(MYSQL *mysql)
mysql->fields=0; /* fields is now in result */
DBUG_RETURN(result); /* Data fetched */
}
+
+#endif /* HAVE_EXTERNAL_CLIENT */
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 6b3a1a7600c..3b34f111e8d 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -492,6 +492,7 @@ static uint set_maximum_open_files(uint max_file_limit);
static ulong find_bit_type(const char *x, TYPELIB *bit_lib);
static void clean_up(bool print_message);
+#ifndef EMBEDDED_LIBRARY
/****************************************************************************
** Code to end mysqld
****************************************************************************/
@@ -667,6 +668,7 @@ static void close_connections(void)
DBUG_PRINT("quit",("close_connections thread"));
DBUG_VOID_RETURN;
}
+#endif /*EMBEDDED_LIBRARY*/
static void close_server_sock()
{
@@ -758,6 +760,7 @@ void kill_mysql(void)
DBUG_VOID_RETURN;
}
+#ifndef EMBEDDED_LIBRARY
/* Force server down. kill all connections and threads and exit */
@@ -798,13 +801,16 @@ static void __cdecl kill_server(int sig_ptr)
RETURN_FROM_KILL_SERVER;
}
+#endif /* EMBEDDED_LIBRARY */
#ifdef USE_ONE_SIGNAL_HAND
extern "C" pthread_handler_decl(kill_server_thread,arg __attribute__((unused)))
{
SHUTDOWN_THD;
my_thread_init(); // Initialize new thread
+#ifndef EMBEDDED_LIBRARY
kill_server(0);
+#endif /* EMBEDDED_LIBRARY */
my_thread_end(); // Normally never reached
return 0;
}
@@ -875,8 +881,10 @@ void clean_up(bool print_message)
DBUG_PRINT("exit",("clean_up"));
if (cleanup_done++)
return; /* purecov: inspected */
+#ifdef HAVE_REPLICATION
if (use_slave_mask)
bitmap_free(&slave_error_mask);
+#endif
acl_free(1);
grant_free();
query_cache_destroy();
@@ -898,12 +906,16 @@ void clean_up(bool print_message)
free_defaults(defaults_argv);
my_free(charsets_list, MYF(MY_ALLOW_ZERO_PTR));
free_tmpdir(&mysql_tmpdir_list);
+#ifdef HAVE_REPLICATION
my_free(slave_load_tmpdir,MYF(MY_ALLOW_ZERO_PTR));
+#endif
x_free(opt_bin_logname);
x_free(opt_relay_logname);
bitmap_free(&temp_pool);
free_max_user_conn();
+#ifdef HAVE_REPLICATION
end_slave_list();
+#endif
#ifdef USE_REGEX
regex_end();
#endif
@@ -1189,7 +1201,7 @@ void yyerror(const char *s)
thd->lex.yylineno);
}
-
+#ifndef EMBEDDED_LIBRARY
void close_connection(NET *net,uint errcode,bool lock)
{
st_vio* vio;
@@ -1209,6 +1221,7 @@ void close_connection(NET *net,uint errcode,bool lock)
(void) pthread_mutex_unlock(&LOCK_thread_count);
DBUG_VOID_RETURN;
}
+#endif
/* Called when a thread is aborted */
/* ARGSUSED */
@@ -1730,7 +1743,7 @@ extern "C" int my_message_sql(uint error, const char *str,
void clear_error_message(THD *thd)
{
- thd->net.last_error[0]= 0;
+ thd->clear_error();
}
@@ -1843,28 +1856,15 @@ bool open_log(MYSQL_LOG *log, const char *hostname,
}
-
-#ifdef __WIN__
-int win_main(int argc, char **argv)
-#else
-int main(int argc, char **argv)
-#endif
+static int init_common_variables(const char *conf_file_name, int argc, char **argv,
+ const char **groups)
{
- DEBUGGER_OFF;
-
my_umask=0660; // Default umask for new files
my_umask_dir=0700; // Default umask for new directories
- MAIN_THD;
- /*
- Initialize signal_th and shutdown_th to main_th for default value
- as we need to initialize them to something safe. They are used
- when compiled with safemalloc.
- */
- SIGNAL_THD;
- SHUTDOWN_THD;
- MY_INIT(argv[0]); // init my_sys library & pthreads
+ umask(((~my_umask) & 0666));
tzset(); // Set tzname
+ max_system_variables.pseudo_thread_id= (ulong)~0;
start_time=time((time_t*) 0);
#ifdef OS2
{
@@ -1894,31 +1894,62 @@ int main(int argc, char **argv)
strmov(glob_hostname,"mysql");
strmake(pidfile_name, glob_hostname, sizeof(pidfile_name)-5);
strmov(fn_ext(pidfile_name),".pid"); // Add proper extension
+
#ifndef DBUG_OFF
strxmov(strend(server_version),MYSQL_SERVER_SUFFIX,"-debug",NullS);
#else
strmov(strend(server_version),MYSQL_SERVER_SUFFIX);
#endif
-#ifdef _CUSTOMSTARTUPCONFIG_
- if (_cust_check_startup())
- {
- /* _cust_check_startup will report startup failure error */
- exit( 1 );
- }
-#endif
- load_defaults(MYSQL_CONFIG_NAME,load_default_groups,&argc,&argv);
- defaults_argv=argv;
+ load_defaults(conf_file_name, groups, &argc, &argv);
+ defaults_argv=argv;
set_options();
get_options(argc,argv);
- max_system_variables.pseudo_thread_id= (ulong)~0;
if (opt_log || opt_update_log || opt_slow_log || opt_bin_log)
strcat(server_version,"-log");
DBUG_PRINT("info",("%s Ver %s for %s on %s\n",my_progname,
server_version, SYSTEM_TYPE,MACHINE_TYPE));
- /* These must be set early */
+#if defined( SET_RLIMIT_NOFILE) || defined( OS2)
+ /* connections and databases needs lots of files */
+ {
+ uint wanted_files=10+(uint) max(max_connections*5,
+ max_connections+table_cache_size*2);
+ set_if_bigger(wanted_files, open_files_limit);
+ // Note that some system returns 0 if we succeed here:
+ uint files=set_maximum_open_files(wanted_files);
+ if (files && files < wanted_files && ! open_files_limit)
+ {
+ max_connections= (ulong) min((files-10),max_connections);
+ table_cache_size= (ulong) max((files-10-max_connections)/2,64);
+ DBUG_PRINT("warning",
+ ("Changed limits: max_connections: %ld table_cache: %ld",
+ max_connections,table_cache_size));
+ sql_print_error("Warning: Changed limits: max_connections: %ld table_cache: %ld",max_connections,table_cache_size);
+ }
+ }
+#endif
+ unireg_init(opt_specialflag); /* Set up extern variabels */
+ init_errmessage(); /* Read error messages from file */
+ lex_init();
+ item_init();
+ set_var_init();
+ mysys_uses_curses=0;
+#ifdef USE_REGEX
+ regex_init();
+#endif
+ if (set_default_charset_by_name(sys_charset.value, MYF(MY_WME)))
+ return 1;
+ charsets_list= list_charsets(MYF(MY_CS_COMPILED | MY_CS_CONFIG));
+
+ if (use_temp_pool && bitmap_init(&temp_pool,1024,1))
+ return 2;
+ return 0;
+}
+
+static int init_thread_environement()
+{
(void) pthread_mutex_init(&LOCK_mysql_create_db,MY_MUTEX_INIT_SLOW);
(void) pthread_mutex_init(&LOCK_Acl,MY_MUTEX_INIT_SLOW);
(void) pthread_mutex_init(&LOCK_open,MY_MUTEX_INIT_FAST);
@@ -1935,7 +1966,9 @@ int main(int argc, char **argv)
(void) pthread_mutex_init(&LOCK_bytes_received,MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_timezone,MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_user_conn, MY_MUTEX_INIT_FAST);
+#ifdef HAVE_REPLICATION
(void) pthread_mutex_init(&LOCK_rpl_status, MY_MUTEX_INIT_FAST);
+#endif
(void) pthread_mutex_init(&LOCK_active_mi, MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_global_system_variables, MY_MUTEX_INIT_FAST);
(void) my_rwlock_init(&LOCK_grant, NULL);
@@ -1944,13 +1977,30 @@ int main(int argc, char **argv)
(void) pthread_cond_init(&COND_thread_cache,NULL);
(void) pthread_cond_init(&COND_flush_thread_cache,NULL);
(void) pthread_cond_init(&COND_manager,NULL);
+#ifdef HAVE_REPLICATION
(void) pthread_cond_init(&COND_rpl_status, NULL);
- init_signals();
+#endif
+ /* Parameter for threads created for connections */
+ (void) pthread_attr_init(&connection_attrib);
+ (void) pthread_attr_setdetachstate(&connection_attrib,
+ PTHREAD_CREATE_DETACHED);
+ pthread_attr_setstacksize(&connection_attrib,thread_stack);
+ pthread_attr_setscope(&connection_attrib, PTHREAD_SCOPE_SYSTEM);
- if (set_default_charset_by_name(sys_charset.value, MYF(MY_WME)))
- exit(1);
- charsets_list= list_charsets(MYF(MY_CS_COMPILED | MY_CS_CONFIG));
+ if (pthread_key_create(&THR_THD,NULL) ||
+ pthread_key_create(&THR_MALLOC,NULL))
+ {
+ sql_print_error("Can't create thread-keys");
+ return 1;
+ }
+
+ (void) thr_setconcurrency(concurrency); // 10 by default
+
+ return 0;
+}
+static void init_ssl()
+{
#ifdef HAVE_OPENSSL
if (opt_use_ssl)
{
@@ -1962,70 +2012,13 @@ int main(int argc, char **argv)
if (!ssl_acceptor_fd)
opt_use_ssl = 0;
}
+ if (des_key_file)
+ load_des_key_file(des_key_file);
#endif /* HAVE_OPENSSL */
+}
-#ifdef HAVE_LIBWRAP
- libwrapName= my_progname+dirname_length(my_progname);
- openlog(libwrapName, LOG_PID, LOG_AUTH);
-#endif
-
- if (!(opt_specialflag & SPECIAL_NO_PRIOR))
- my_pthread_setprio(pthread_self(),CONNECT_PRIOR);
- /* Parameter for threads created for connections */
- (void) pthread_attr_init(&connection_attrib);
- (void) pthread_attr_setdetachstate(&connection_attrib,
- PTHREAD_CREATE_DETACHED);
- pthread_attr_setstacksize(&connection_attrib,thread_stack);
-
- if (!(opt_specialflag & SPECIAL_NO_PRIOR))
- my_pthread_attr_setprio(&connection_attrib,WAIT_PRIOR);
- pthread_attr_setscope(&connection_attrib, PTHREAD_SCOPE_SYSTEM);
-
-#if defined( SET_RLIMIT_NOFILE) || defined( OS2)
- /* connections and databases needs lots of files */
- {
- uint wanted_files=10+(uint) max(max_connections*5,
- max_connections+table_cache_size*2);
- set_if_bigger(wanted_files, open_files_limit);
- // Note that some system returns 0 if we succeed here:
- uint files=set_maximum_open_files(wanted_files);
- if (files && files < wanted_files && ! open_files_limit)
- {
- max_connections= (ulong) min((files-10),max_connections);
- table_cache_size= (ulong) max((files-10-max_connections)/2,64);
- DBUG_PRINT("warning",
- ("Changed limits: max_connections: %ld table_cache: %ld",
- max_connections,table_cache_size));
- sql_print_error("Warning: Changed limits: max_connections: %ld table_cache: %ld",max_connections,table_cache_size);
- }
- }
-#endif
- unireg_init(opt_specialflag); /* Set up extern variabels */
- init_errmessage(); /* Read error messages from file */
- lex_init();
- item_init();
- set_var_init();
- mysys_uses_curses=0;
-#ifdef USE_REGEX
- regex_init();
-#endif
- select_thread=pthread_self();
- select_thread_in_use=1;
- if (use_temp_pool && bitmap_init(&temp_pool,1024,1))
- unireg_abort(1);
-
- /*
- We have enough space for fiddling with the argv, continue
- */
- umask(((~my_umask) & 0666));
- if (my_setwd(mysql_real_data_home,MYF(MY_WME)))
- {
- unireg_abort(1); /* purecov: inspected */
- }
- mysql_data_home= mysql_data_home_buff;
- mysql_data_home[0]=FN_CURLIB; // all paths are relative from here
- mysql_data_home[1]=0;
- server_init();
+static int init_server_components()
+{
table_cache_init();
hostname_cache_init();
query_cache_result_size_limit(query_cache_limit);
@@ -2033,12 +2026,9 @@ int main(int argc, char **argv)
randominit(&sql_rand,(ulong) start_time,(ulong) start_time/2);
reset_floating_point_exceptions();
init_thr_lock();
+#ifdef HAVE_REPLICATION
init_slave_list();
-#ifdef HAVE_OPENSSL
- if (des_key_file)
- load_des_key_file(des_key_file);
-#endif /* HAVE_OPENSSL */
-
+#endif
/* Setup log files */
if (opt_log)
open_log(&mysql_log, glob_hostname, opt_logname, ".log", NullS,
@@ -2049,26 +2039,17 @@ int main(int argc, char **argv)
NullS, LOG_NEW);
using_update_log=1;
}
-
+
if (opt_slow_log)
open_log(&mysql_slow_log, glob_hostname, opt_slow_logname, "-slow.log",
NullS, LOG_NORMAL);
-#ifdef __WIN__
-#define MYSQL_ERR_FILE "mysql.err"
- if (!opt_console)
- {
- freopen(MYSQL_ERR_FILE,"a+",stdout);
- freopen(MYSQL_ERR_FILE,"a+",stderr);
- }
-#endif
if (ha_init())
{
sql_print_error("Can't init databases");
- if (unix_sock != INVALID_SOCKET)
- unlink(mysql_unix_port);
- exit(1);
+ return 1;
}
ha_key_cache();
+
#if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT)
if (locked_in_memory && !geteuid())
{
@@ -2087,71 +2068,9 @@ int main(int argc, char **argv)
(void) mi_log( 1 );
ft_init_stopwords(ft_precompiled_stopwords);
-#ifdef __WIN__
- if (!opt_console)
- FreeConsole(); // Remove window
-#endif
-
- /*
- init signals & alarm
- After this we can't quit by a simple unireg_abort
- */
- error_handler_hook = my_message_sql;
- if (pthread_key_create(&THR_THD,NULL) ||
- pthread_key_create(&THR_MALLOC,NULL))
- {
- sql_print_error("Can't create thread-keys");
- if (unix_sock != INVALID_SOCKET)
- unlink(mysql_unix_port);
- exit(1);
- }
- start_signal_handler(); // Creates pidfile
- if (acl_init((THD*) 0, opt_noacl))
- {
- abort_loop=1;
- select_thread_in_use=0;
- (void) pthread_kill(signal_thread,MYSQL_KILL_SIGNAL);
-#ifndef __WIN__
- if (!opt_bootstrap)
- (void) my_delete(pidfile_name,MYF(MY_WME)); // Not needed anymore
-#endif
- if (unix_sock != INVALID_SOCKET)
- unlink(mysql_unix_port);
- exit(1);
- }
- if (!opt_noacl)
- (void) grant_init((THD*) 0);
init_max_user_conn();
init_update_queries();
- DBUG_ASSERT(current_thd == 0);
-#ifdef HAVE_DLOPEN
- if (!opt_noacl)
- udf_init();
-#endif
- /* init_slave() must be called after the thread keys are created */
- init_slave();
-
- DBUG_ASSERT(current_thd == 0);
- if (opt_bin_log && !server_id)
- {
- server_id= !master_host ? 1 : 2;
- switch (server_id) {
-#ifdef EXTRA_DEBUG
- case 1:
- sql_print_error("\
-Warning: You have enabled the binary log, but you haven't set server-id:\n\
-Updates will be logged to the binary log, but connections to slaves will\n\
-not be accepted.");
- break;
-#endif
- case 2:
- sql_print_error("\
-Warning: You should set server-id to a non-0 value if master_host is set.\n\
-The server will not act as a slave.");
- break;
- }
- }
if (opt_bin_log)
{
open_log(&mysql_bin_log, glob_hostname, opt_bin_logname, "-bin",
@@ -2159,25 +2078,29 @@ The server will not act as a slave.");
using_update_log=1;
}
+ return 0;
+}
- if (opt_bootstrap)
- {
- int error=bootstrap(stdin);
- end_thr_alarm(); // Don't allow alarms
- unireg_abort(error ? 1 : 0);
- }
- if (opt_init_file)
+static void create_maintenance_thread()
+{
+ if (
+#ifdef HAVE_BERKELEY_DB
+ !berkeley_skip ||
+#endif
+ (flush_time && flush_time != ~(ulong) 0L))
{
- if (read_init_file(opt_init_file))
- {
- end_thr_alarm(); // Don't allow alarms
- unireg_abort(1);
- }
+ pthread_t hThread;
+ if (pthread_create(&hThread,&connection_attrib,handle_manager,0))
+ sql_print_error("Warning: Can't create thread to manage maintenance");
}
- (void) thr_setconcurrency(concurrency); // 10 by default
-#if defined(__WIN__) && !defined(EMBEDDED_LIBRARY) //IRENA
+}
+
+static void create_shutdown_thread()
+{
+
+#ifdef __WIN__
{
- hEventShutdown=CreateEvent(0, FALSE, FALSE, shutdown_event_name);
+ hEventShutdown=CreateEvent(0, FALSE, FALSE, event_name);
pthread_t hThread;
if (pthread_create(&hThread,&connection_attrib,handle_shutdown,0))
sql_print_error("Warning: Can't create thread to handle shutdown requests");
@@ -2194,38 +2117,24 @@ The server will not act as a slave.");
sql_print_error("Warning: Can't create thread to handle shutdown requests");
}
#endif
+}
- if (
-#ifdef HAVE_BERKELEY_DB
- !berkeley_skip ||
-#endif
- (flush_time && flush_time != ~(ulong) 0L))
- {
- pthread_t hThread;
- if (pthread_create(&hThread,&connection_attrib,handle_manager,0))
- sql_print_error("Warning: Can't create thread to manage maintenance");
- }
-
- printf(ER(ER_READY),my_progname,server_version,"");
- fflush(stdout);
-#if defined(__NT__) || defined(HAVE_SMEM)
#ifdef __NT__
+void create_named_pipe_thread()
+{
if (hPipe == INVALID_HANDLE_VALUE &&
- (!have_tcpip || opt_disable_networking) &&
- !opt_enable_shared_memory)
+ (!have_tcpip || opt_disable_networking))
{
- sql_print_error("TCP/IP,--shared-memory or --named-pipe should be configured on NT OS");
- unireg_abort(1);
+ sql_print_error("TCP/IP or --enable-named-pipe should be configured on NT OS");
+ unireg_abort(1);
}
else
-#endif
{
pthread_mutex_lock(&LOCK_thread_count);
(void) pthread_cond_init(&COND_handler_count,NULL);
{
pthread_t hThread;
handler_count=0;
-#ifdef __NT__
if (hPipe != INVALID_HANDLE_VALUE && opt_enable_named_pipe)
{
handler_count++;
@@ -2236,36 +2145,169 @@ The server will not act as a slave.");
handler_count--;
}
}
-#endif
-#ifdef HAVE_SMEM
- if (opt_enable_shared_memory)
- {
- handler_count++;
- if (pthread_create(&hThread,&connection_attrib,
- handle_connections_shared_memory, 0))
- {
- sql_print_error("Warning: Can't create thread to handle shared memory");
- handler_count--;
- }
- }
-#endif
if (have_tcpip && !opt_disable_networking)
{
handler_count++;
if (pthread_create(&hThread,&connection_attrib,
handle_connections_sockets, 0))
{
- sql_print_error("Warning: Can't create thread to handle tcp/ip");
+ sql_print_error("Warning: Can't create thread to handle named pipes");
handler_count--;
}
}
while (handler_count > 0)
- {
pthread_cond_wait(&COND_handler_count,&LOCK_thread_count);
- }
}
pthread_mutex_unlock(&LOCK_thread_count);
}
+}
+#endif
+
+#ifndef EMBEDDED_LIBRARY
+#ifdef __WIN__
+int win_main(int argc, char **argv)
+#else
+int main(int argc, char **argv)
+#endif
+{
+ int init_error;
+
+ DEBUGGER_OFF;
+
+#ifdef _CUSTOMSTARTUPCONFIG_
+ if (_cust_check_startup())
+ {
+ / * _cust_check_startup will report startup failure error * /
+ exit( 1 );
+ }
+#endif
+
+ MY_INIT(argv[0]); // init my_sys library & pthreads
+
+ if ((init_error=init_common_variables(MYSQL_CONFIG_NAME,
+ argc, argv, load_default_groups)))
+ if (init_error == 2)
+ unireg_abort(1);
+ else
+ exit(1);
+
+ init_signals();
+ if (init_thread_environement())
+ exit(1);
+ select_thread=pthread_self();
+ select_thread_in_use=1;
+ if (!(opt_specialflag & SPECIAL_NO_PRIOR))
+ my_pthread_setprio(pthread_self(),CONNECT_PRIOR);
+
+ if (!(opt_specialflag & SPECIAL_NO_PRIOR))
+ my_pthread_attr_setprio(&connection_attrib,WAIT_PRIOR);
+
+ init_ssl();
+
+#ifdef HAVE_LIBWRAP
+ libwrapName= my_progname+dirname_length(my_progname);
+ openlog(libwrapName, LOG_PID, LOG_AUTH);
+#endif
+
+ /*
+ We have enough space for fiddling with the argv, continue
+ */
+ if (my_setwd(mysql_real_data_home,MYF(MY_WME)))
+ {
+ unireg_abort(1); /* purecov: inspected */
+ }
+ mysql_data_home= mysql_data_home_buff;
+ mysql_data_home[0]=FN_CURLIB; // all paths are relative from here
+ mysql_data_home[1]=0;
+ server_init();
+
+ if (opt_bin_log && !server_id)
+ {
+ server_id= !master_host ? 1 : 2;
+ switch (server_id) {
+#ifdef EXTRA_DEBUG
+ case 1:
+ sql_print_error("\
+Warning: You have enabled the binary log, but you haven't set server-id:\n\
+Updates will be logged to the binary log, but connections to slaves will\n\
+not be accepted.");
+ break;
+#endif
+ case 2:
+ sql_print_error("\
+Warning: You should set server-id to a non-0 value if master_host is set.\n\
+The server will not act as a slave.");
+ break;
+ }
+ }
+
+ if (init_server_components())
+ exit(1);
+
+#ifdef __WIN__
+#define MYSQL_ERR_FILE "mysql.err"
+ if (!opt_console)
+ {
+ freopen(MYSQL_ERR_FILE,"a+",stdout);
+ freopen(MYSQL_ERR_FILE,"a+",stderr);
+ }
+#endif
+
+#ifdef __WIN__
+ if (!opt_console)
+ FreeConsole(); // Remove window
+#endif
+
+ /*
+ init signals & alarm
+ After this we can't quit by a simple unireg_abort
+ */
+ error_handler_hook = my_message_sql;
+ start_signal_handler(); // Creates pidfile
+ if (acl_init((THD *)0, opt_noacl))
+ {
+ abort_loop=1;
+ select_thread_in_use=0;
+ (void) pthread_kill(signal_thread,MYSQL_KILL_SIGNAL);
+#ifndef __WIN__
+ if (!opt_bootstrap)
+ (void) my_delete(pidfile_name,MYF(MY_WME)); // Not needed anymore
+#endif
+ exit(1);
+ }
+ if (!opt_noacl)
+ (void) grant_init((THD *)0);
+
+#ifdef HAVE_DLOPEN
+ if (!opt_noacl)
+ udf_init();
+#endif
+ /* init_slave() must be called after the thread keys are created */
+ init_slave();
+
+ if (opt_bootstrap)
+ {
+ int error=bootstrap(stdin);
+ end_thr_alarm(); // Don't allow alarms
+ unireg_abort(error ? 1 : 0);
+ }
+ if (opt_init_file)
+ {
+ if (read_init_file(opt_init_file))
+ {
+ end_thr_alarm(); // Don't allow alarms
+ unireg_abort(1);
+ }
+ }
+
+ create_shutdown_thread();
+ create_maintenance_thread();
+
+ printf(ER(ER_READY),my_progname,server_version,"");
+ fflush(stdout);
+
+#ifdef __NT__
+ create_named_pipe_thread();
#else
handle_connections_sockets(0);
#ifdef EXTRA_DEBUG2
@@ -2312,6 +2354,8 @@ The server will not act as a slave.");
return(0); /* purecov: deadcode */
}
+#endif /* EMBEDDED_LIBRARY */
+
/****************************************************************************
Main and thread entry function for Win32
@@ -2450,7 +2494,7 @@ int main(int argc, char **argv)
Execute all commands from a file. Used by the mysql_install_db script to
create MySQL privilege tables without having to start a full MySQL server.
*/
-
+#ifndef EMBEDDED_LIBRARY
static int bootstrap(FILE *file)
{
THD *thd= new THD;
@@ -2487,6 +2531,8 @@ static int bootstrap(FILE *file)
DBUG_RETURN(error);
}
+#endif
+
static bool read_init_file(char *file_name)
{
FILE *file;
@@ -2494,11 +2540,14 @@ static bool read_init_file(char *file_name)
DBUG_PRINT("enter",("name: %s",file_name));
if (!(file=my_fopen(file_name,O_RDONLY,MYF(MY_WME))))
return(1);
+#ifndef EMBEDDED_LIBRARY
bootstrap(file); /* Ignore errors from this */
+#endif
(void) my_fclose(file,MYF(MY_WME));
return 0;
}
+#ifndef EMBEDDED_LIBRARY
static void create_new_thread(THD *thd)
{
@@ -2580,6 +2629,7 @@ static void create_new_thread(THD *thd)
DBUG_PRINT("info",("Thread created"));
DBUG_VOID_RETURN;
}
+#endif
#ifdef SIGNALS_DONT_BREAK_READ
inline void kill_broken_server()
@@ -2597,6 +2647,7 @@ inline void kill_broken_server()
#define MAYBE_BROKEN_SYSCALL
#endif
+#ifndef EMBEDDED_LIBRARY
/* Handle new connections and spawn new process to handle them */
extern "C" pthread_handler_decl(handle_connections_sockets,arg __attribute__((unused)))
@@ -3101,6 +3152,7 @@ error:
}
#endif /* HAVE_SMEM */
+#endif /* EMBEDDED_LIBRARY */
/******************************************************************************
** handle start options
@@ -3466,6 +3518,7 @@ struct my_option my_long_options[] =
GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"memlock", OPT_MEMLOCK, "Lock mysqld in memory", (gptr*) &locked_in_memory,
(gptr*) &locked_in_memory, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+#ifdef HAVE_REPLICATION
{"disconnect-slave-event-count", OPT_DISCONNECT_SLAVE_EVENT_COUNT,
"Option used by mysql-test for debugging and testing of replication",
(gptr*) &disconnect_slave_event_count,
@@ -3484,6 +3537,7 @@ struct my_option my_long_options[] =
(gptr*) &opt_sporadic_binlog_dump_fail,
(gptr*) &opt_sporadic_binlog_dump_fail, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
0},
+#endif /* HAVE_REPLICATION */
{"safemalloc-mem-limit", OPT_SAFEMALLOC_MEM_LIMIT,
"Simulate memory shortage when compiled with the --with-debug=full option",
0, 0, 0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -3626,12 +3680,14 @@ struct my_option my_long_options[] =
{"relay-log-info-file", OPT_RELAY_LOG_INFO_FILE, "Undocumented",
(gptr*) &relay_log_info_file, (gptr*) &relay_log_info_file, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+#ifdef HAVE_REPLICATION
{"slave-load-tmpdir", OPT_SLAVE_LOAD_TMPDIR, "Undocumented",
(gptr*) &slave_load_tmpdir, (gptr*) &slave_load_tmpdir, 0, GET_STR_ALLOC,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"slave-skip-errors", OPT_SLAVE_SKIP_ERRORS,
"Tells the slave thread to continue replication when a query returns an error from the provided list",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+#endif
{"socket", OPT_SOCKET, "Socket file to use for connection",
(gptr*) &mysql_unix_port, (gptr*) &mysql_unix_port, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -3968,6 +4024,7 @@ struct my_option my_long_options[] =
(gptr*) &global_system_variables.read_buff_size,
(gptr*) &max_system_variables.read_buff_size,0, GET_ULONG, REQUIRED_ARG,
128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, ~0L, MALLOC_OVERHEAD, IO_SIZE, 0},
+#ifdef HAVE_REPLICATION
{"relay_log_space_limit", OPT_RELAY_LOG_SPACE_LIMIT,
"Max space to use for all relay logs",
(gptr*) &relay_log_space_limit,
@@ -3982,6 +4039,7 @@ struct my_option my_long_options[] =
"Number of seconds to wait for more data from a master/slave connection before aborting the read.",
(gptr*) &slave_net_timeout, (gptr*) &slave_net_timeout, 0,
GET_ULONG, REQUIRED_ARG, SLAVE_NET_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
+#endif
{"slow_launch_time", OPT_SLOW_LAUNCH_TIME,
"If creating the thread takes longer than this value (in seconds), the Slow_launch_threads counter will be incremented.",
(gptr*) &slow_launch_time, (gptr*) &slow_launch_time, 0, GET_ULONG,
@@ -4326,9 +4384,11 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case 'o':
protocol_version=PROTOCOL_VERSION-1;
break;
+#ifdef HAVE_REPLICATION
case OPT_SLAVE_SKIP_ERRORS:
init_slave_skip_errors(argument);
break;
+#endif
case OPT_SAFEMALLOC_MEM_LIMIT:
#if !defined(DBUG_OFF) && defined(SAFEMALLOC)
safemalloc_mem_limit = atoi(argument);
@@ -4368,6 +4428,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case (int) OPT_BIN_LOG:
opt_bin_log=1;
break;
+#ifdef HAVE_REPLICATION
case (int) OPT_INIT_RPL_ROLE:
{
int role;
@@ -4488,13 +4549,14 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
table_rules_on = 1;
break;
}
- case (int) OPT_SLOW_QUERY_LOG:
- opt_slow_log=1;
- break;
case (int)OPT_RECKLESS_SLAVE:
opt_reckless_slave = 1;
init_slave_skip_errors("all");
break;
+#endif /* HAVE_REPLICATION */
+ case (int) OPT_SLOW_QUERY_LOG:
+ opt_slow_log=1;
+ break;
case (int) OPT_SKIP_NEW:
opt_specialflag|= SPECIAL_NO_NEW_FUNC;
delay_key_write_options= (uint) DELAY_KEY_WRITE_NONE;
@@ -4873,11 +4935,13 @@ static void fix_paths(void)
if (init_tmpdir(&mysql_tmpdir_list, opt_mysql_tmpdir))
exit(1);
+#ifdef HAVE_REPLICATION
if (!slave_load_tmpdir)
{
if (!(slave_load_tmpdir = (char*) my_strdup(mysql_tmpdir, MYF(MY_FAE))))
exit(1);
}
+#endif
}
diff --git a/sql/net_serv.cc b/sql/net_serv.cc
index f284106d752..550fb772fce 100644
--- a/sql/net_serv.cc
+++ b/sql/net_serv.cc
@@ -23,6 +23,7 @@
3 byte length & 1 byte package-number.
*/
+#ifndef EMBEDDED_LIBRARY
#ifdef __WIN__
#include <winsock.h>
#endif
@@ -945,3 +946,6 @@ my_net_read(NET *net)
#endif /* HAVE_COMPRESS */
return len;
}
+
+#endif /* EMBEDDED_LIBRARY */
+
diff --git a/sql/protocol.cc b/sql/protocol.cc
index be5202111d0..d0d6a75214b 100644
--- a/sql/protocol.cc
+++ b/sql/protocol.cc
@@ -26,6 +26,27 @@
#include "mysql_priv.h"
#include <stdarg.h>
+#ifndef EMBEDDED_LIBRARY
+bool Protocol::net_store_data(const char *from, uint length)
+{
+ ulong packet_length=packet->length();
+ if (packet_length+5+length > packet->alloced_length() &&
+ packet->realloc(packet_length+5+length))
+ return 1;
+ char *to=(char*) net_store_length((char*) packet->ptr()+packet_length,
+ (ulonglong) length);
+ memcpy(to,from,length);
+ packet->length((uint) (to+length-packet->ptr()));
+ return 0;
+}
+
+inline bool Protocol::convert_str(const char *from, uint length)
+{
+ convert->store(packet, from, length);
+}
+#endif
+
+
/* Send a error string to client */
void send_error(THD *thd, uint sql_errno, const char *err)
@@ -38,7 +59,9 @@ void send_error(THD *thd, uint sql_errno, const char *err)
err ? err : net->last_error[0] ?
net->last_error : "NULL"));
+#ifndef EMBEDDED_LIBRARY /* TODO query cache in embedded library*/
query_cache_abort(net);
+#endif
thd->query_error= 1; // needed to catch query errors during replication
if (!err)
{
@@ -55,6 +78,12 @@ void send_error(THD *thd, uint sql_errno, const char *err)
}
}
}
+
+#ifdef EMBEDDED_LIBRARY
+ net->last_errno= sql_errno;
+ strmake(net->last_error, err, sizeof(net->last_error)-1);
+#else
+
if (net->vio == 0)
{
if (thd->bootstrap)
@@ -77,6 +106,7 @@ void send_error(THD *thd, uint sql_errno, const char *err)
set_if_smaller(length,MYSQL_ERRMSG_SIZE-1);
}
VOID(net_write_command(net,(uchar) 255, "", 0, (char*) err,length));
+#endif /* EMBEDDED_LIBRARY*/
thd->fatal_error=0; // Error message is given
thd->net.report_error= 0;
DBUG_VOID_RETURN;
@@ -87,6 +117,7 @@ void send_error(THD *thd, uint sql_errno, const char *err)
This is used by mysqld.cc, which doesn't have a THD
*/
+#ifndef EMBEDDED_LIBRARY
void net_send_error(NET *net, uint sql_errno, const char *err)
{
char buff[2];
@@ -99,7 +130,7 @@ void net_send_error(NET *net, uint sql_errno, const char *err)
net_write_command(net,(uchar) 255, buff, 2, err, length);
DBUG_VOID_RETURN;
}
-
+#endif
/*
Send a warning to the end user
@@ -136,14 +167,22 @@ net_printf(THD *thd, uint errcode, ...)
{
va_list args;
uint length,offset;
- const char *format,*text_pos;
+ const char *format;
+#ifndef EMBEDDED_LIBRARY
+ const char *text_pos;
+#else
+ char text_pos[500];
+#endif
int head_length= NET_HEADER_SIZE;
NET *net= &thd->net;
+
DBUG_ENTER("net_printf");
DBUG_PRINT("enter",("message: %u",errcode));
thd->query_error= 1; // needed to catch query errors during replication
+#ifndef EMBEDDED_LIBRARY
query_cache_abort(net); // Safety
+#endif
va_start(args,errcode);
/*
The following is needed to make net_printf() work with 0 argument for
@@ -159,13 +198,16 @@ net_printf(THD *thd, uint errcode, ...)
errcode= ER_UNKNOWN_ERROR;
}
offset= net->return_errno ? 2 : 0;
+#ifndef EMBEDDED_LIBRARY
text_pos=(char*) net->buff+head_length+offset+1;
+#endif
(void) vsprintf(my_const_cast(char*) (text_pos),format,args);
length=(uint) strlen((char*) text_pos);
if (length >= sizeof(net->last_error))
length=sizeof(net->last_error)-1; /* purecov: inspected */
va_end(args);
+#ifndef EMBEDDED_LIBRARY
if (net->vio == 0)
{
if (thd->bootstrap)
@@ -186,10 +228,36 @@ net_printf(THD *thd, uint errcode, ...)
if (offset)
int2store(text_pos-2, errcode);
VOID(net_real_write(net,(char*) net->buff,length+head_length+1+offset));
+#else
+ net->last_errno= errcode;
+ strmake(net->last_error, text_pos, length);
+#endif
thd->fatal_error=0; // Error message is given
DBUG_VOID_RETURN;
}
+/*
+ Function called by my_net_init() to set some check variables
+*/
+
+#ifndef EMBEDDED_LIBRARY
+extern "C" {
+void my_net_local_init(NET *net)
+{
+ net->max_packet= (uint) global_system_variables.net_buffer_length;
+ net->read_timeout= (uint) global_system_variables.net_read_timeout;
+ net->write_timeout=(uint) global_system_variables.net_write_timeout;
+ net->retry_count= (uint) global_system_variables.net_retry_count;
+ net->max_packet_size= max(global_system_variables.net_buffer_length,
+ global_system_variables.max_allowed_packet);
+}
+}
+
+#else /* EMBEDDED_LIBRARY */
+void my_net_local_init(NET *net __attribute__(unused))
+{
+}
+#endif /* EMBEDDED_LIBRARY */
/*
Return ok to the client.
@@ -216,6 +284,7 @@ net_printf(THD *thd, uint errcode, ...)
If net->no_send_ok return without sending packet
*/
+#ifndef EMBEDDED_LIBRARY
void
send_ok(THD *thd, ha_rows affected_rows, ulonglong id, const char *message)
@@ -301,6 +370,7 @@ send_eof(THD *thd, bool no_flush)
}
DBUG_VOID_RETURN;
}
+#endif /* EMBEDDED_LIBRARY */
/****************************************************************************
@@ -355,23 +425,6 @@ char *net_store_length(char *pkg, uint length)
}
-/*
- Used internally for storing strings in packet
-*/
-
-static bool net_store_data(String *packet, const char *from, uint length)
-{
- ulong packet_length=packet->length();
- if (packet_length+5+length > packet->alloced_length() &&
- packet->realloc(packet_length+5+length))
- return 1;
- char *to=(char*) net_store_length((char*) packet->ptr()+packet_length,
- (ulonglong) length);
- memcpy(to,from,length);
- packet->length((uint) (to+length-packet->ptr()));
- return 0;
-}
-
/****************************************************************************
Functions used by the protocol functions (like send_ok) to store strings
and numbers in the header result packet.
@@ -408,19 +461,6 @@ char *net_store_data(char *to,longlong from)
Function called by my_net_init() to set some check variables
*/
-extern "C" {
-void my_net_local_init(NET *net)
-{
- net->max_packet= (uint) global_system_variables.net_buffer_length;
- net->read_timeout= (uint) global_system_variables.net_read_timeout;
- net->write_timeout=(uint) global_system_variables.net_write_timeout;
- net->retry_count= (uint) global_system_variables.net_retry_count;
- net->max_packet_size= max(global_system_variables.net_buffer_length,
- global_system_variables.max_allowed_packet);
-}
-}
-
-
/*****************************************************************************
Default Protocol functions
*****************************************************************************/
@@ -457,6 +497,7 @@ void Protocol::init(THD *thd_arg)
1 Error (Note that in this case the error is not sent to the client)
*/
+#ifndef EMBEDDED_LIBRARY
bool Protocol::send_fields(List<Item> *list, uint flag)
{
List_iterator_fast<Item> it(*list);
@@ -539,6 +580,14 @@ err:
DBUG_RETURN(1); /* purecov: inspected */
}
+bool Protocol::send_records_num(List<Item> *list, ulonglong records)
+{
+ char *pos;
+ char buff[20];
+ pos=net_store_length(buff, (uint) list->elements);
+ pos=net_store_length(pos, records);
+ return my_net_write(&thd->net, buff,(uint) (pos-buff));
+}
bool Protocol::write()
{
@@ -547,6 +596,9 @@ bool Protocol::write()
}
+#endif /* EMBEDDED_LIBRARY */
+
+
/*
Send \0 end terminated string
@@ -604,6 +656,7 @@ bool Protocol::store(I_List<i_string>* str_list)
****************************************************************************/
+#ifndef EMBEDDED_LIBRARY
void Protocol_simple::prepare_for_resend()
{
packet->length(0);
@@ -621,6 +674,7 @@ bool Protocol_simple::store_null()
buff[0]= (char)251;
return packet->append(buff, sizeof(buff), PACKET_BUFFET_EXTRA_ALLOC);
}
+#endif
bool Protocol_simple::store(const char *from, uint length)
{
@@ -632,8 +686,8 @@ bool Protocol_simple::store(const char *from, uint length)
field_pos++;
#endif
if (convert)
- return convert->store(packet, from, length);
- return net_store_data(packet, from, length);
+ return convert_str(from, length);
+ return net_store_data(from, length);
}
@@ -643,7 +697,7 @@ bool Protocol_simple::store_tiny(longlong from)
DBUG_ASSERT(field_types == 0 || field_types[field_pos++] == MYSQL_TYPE_TINY);
#endif
char buff[20];
- return net_store_data(packet,(char*) buff,
+ return net_store_data((char*) buff,
(uint) (int10_to_str((int) from,buff, -10)-buff));
}
@@ -654,7 +708,7 @@ bool Protocol_simple::store_short(longlong from)
field_types[field_pos++] == MYSQL_TYPE_SHORT);
#endif
char buff[20];
- return net_store_data(packet,(char*) buff,
+ return net_store_data((char*) buff,
(uint) (int10_to_str((int) from,buff, -10)-buff));
}
@@ -664,7 +718,7 @@ bool Protocol_simple::store_long(longlong from)
DBUG_ASSERT(field_types == 0 || field_types[field_pos++] == MYSQL_TYPE_LONG);
#endif
char buff[20];
- return net_store_data(packet,(char*) buff,
+ return net_store_data((char*) buff,
(uint) (int10_to_str((int) from,buff, -10)-buff));
}
@@ -676,7 +730,7 @@ bool Protocol_simple::store_longlong(longlong from, bool unsigned_flag)
field_types[field_pos++] == MYSQL_TYPE_LONGLONG);
#endif
char buff[22];
- return net_store_data(packet,(char*) buff,
+ return net_store_data((char*) buff,
(uint) (longlong10_to_str(from,buff,
unsigned_flag ? 10 : -10)-
buff));
@@ -690,7 +744,7 @@ bool Protocol_simple::store(float from, uint32 decimals, String *buffer)
field_types[field_pos++] == MYSQL_TYPE_FLOAT);
#endif
buffer->set((double) from, decimals, thd->variables.thd_charset);
- return net_store_data(packet,(char*) buffer->ptr(), buffer->length());
+ return net_store_data((char*) buffer->ptr(), buffer->length());
}
bool Protocol_simple::store(double from, uint32 decimals, String *buffer)
@@ -700,7 +754,7 @@ bool Protocol_simple::store(double from, uint32 decimals, String *buffer)
field_types[field_pos++] == MYSQL_TYPE_DOUBLE);
#endif
buffer->set(from, decimals, thd->variables.thd_charset);
- return net_store_data(packet,(char*) buffer->ptr(), buffer->length());
+ return net_store_data((char*) buffer->ptr(), buffer->length());
}
@@ -715,8 +769,8 @@ bool Protocol_simple::store(Field *field)
String tmp(buff,sizeof(buff),default_charset_info);
field->val_str(&tmp,&tmp);
if (convert)
- return convert->store(packet, tmp.ptr(), tmp.length());
- return net_store_data(packet, tmp.ptr(), tmp.length());
+ return convert_str(tmp.ptr(), tmp.length());
+ return net_store_data(tmp.ptr(), tmp.length());
}
@@ -737,7 +791,7 @@ bool Protocol_simple::store(TIME *tm)
(int) tm->hour,
(int) tm->minute,
(int) tm->second));
- return net_store_data(packet, (char*) buff, length);
+ return net_store_data((char*) buff, length);
}
@@ -753,7 +807,7 @@ bool Protocol_simple::store_date(TIME *tm)
(int) tm->year,
(int) tm->month,
(int) tm->day));
- return net_store_data(packet, (char*) buff, length);
+ return net_store_data((char*) buff, length);
}
@@ -770,7 +824,7 @@ bool Protocol_simple::store_time(TIME *tm)
(long) tm->day*3600L+(long) tm->hour,
(int) tm->minute,
(int) tm->second));
- return net_store_data(packet, (char*) buff, length);
+ return net_store_data((char*) buff, length);
}
@@ -794,7 +848,7 @@ bool Protocol_simple::store_time(TIME *tm)
bool Protocol_prep::prepare_for_send(List<Item> *item_list)
{
- field_count= item_list->elements;
+ Protocol::prepare_for_send(item_list);
bit_fields= (field_count+9)/8;
if (packet->alloc(bit_fields+1))
return 1;
@@ -821,11 +875,10 @@ bool Protocol_prep::store(const char *from,uint length)
#endif
field_pos++;
if (convert)
- return convert->store(packet, from, length);
- return net_store_data(packet, from, length);
+ return convert_str(from, length);
+ return net_store_data(from, length);
}
-
bool Protocol_prep::store_null()
{
uint offset= (field_pos+2)/8+1, bit= (1 << ((field_pos+2) & 7));
diff --git a/sql/protocol.h b/sql/protocol.h
index b3ab0a2b31d..f57652af670 100644
--- a/sql/protocol.h
+++ b/sql/protocol.h
@@ -23,7 +23,9 @@
class CONVERT;
class i_string;
class THD;
-
+#ifdef EMBEDDED_LIBRARY
+typedef struct st_mysql_field MYSQL_FIELD;
+#endif
class Protocol
{
protected:
@@ -33,7 +35,14 @@ protected:
#ifndef DEBUG_OFF
enum enum_field_types *field_types;
#endif
-
+ uint field_count;
+ bool net_store_data(const char *from, uint length);
+ bool convert_str(const char *from, uint length);
+#ifdef EMBEDDED_LIBRARY
+ char **next_field;
+ MYSQL_FIELD *next_mysql_field;
+ MEM_ROOT *alloc;
+#endif
public:
CONVERT *convert;
@@ -41,6 +50,7 @@ public:
Protocol(THD *thd) { init(thd); }
void init(THD* thd);
bool send_fields(List<Item> *list, uint flag);
+ bool send_records_num(List<Item> *list, ulonglong records);
bool store(I_List<i_string> *str_list);
bool store(const char *from);
String *storage_packet() { return packet; }
@@ -52,8 +62,12 @@ public:
{ return store_longlong((longlong) from, 0); }
inline bool store(ulonglong from)
{ return store_longlong((longlong) from, 1); }
-
- virtual bool prepare_for_send(List<Item> *item_list) { return 0;}
+
+ virtual bool prepare_for_send(List<Item> *item_list)
+ {
+ field_count=item_list->elements;
+ return 0;
+ }
virtual void prepare_for_resend()=0;
virtual bool store_null()=0;
@@ -97,7 +111,7 @@ public:
class Protocol_prep :public Protocol
{
private:
- uint field_count, bit_fields;
+ uint bit_fields;
public:
Protocol_prep() {}
Protocol_prep(THD *thd) :Protocol(thd) {}
@@ -117,7 +131,6 @@ public:
virtual bool store(Field *field);
};
-
void send_warning(THD *thd, uint sql_errno, const char *err=0);
void net_printf(THD *thd,uint sql_errno, ...);
void send_ok(THD *thd, ha_rows affected_rows=0L, ulonglong id=0L,
diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc
index 597bcff58f2..49b061ae6b4 100644
--- a/sql/repl_failsafe.cc
+++ b/sql/repl_failsafe.cc
@@ -17,6 +17,8 @@
// Sasha Pachev <sasha@mysql.com> is currently in charge of this file
#include "mysql_priv.h"
+#ifdef HAVE_REPLICATION
+
#include "repl_failsafe.h"
#include "sql_repl.h"
#include "slave.h"
@@ -893,3 +895,6 @@ err:
return error;
}
+
+#endif /* HAVE_REPLICATION */
+
diff --git a/sql/repl_failsafe.h b/sql/repl_failsafe.h
index ef1dc1f8778..72ea0cf2a56 100644
--- a/sql/repl_failsafe.h
+++ b/sql/repl_failsafe.h
@@ -1,3 +1,4 @@
+#ifdef HAVE_REPLICATION
#ifndef REPL_FAILSAFE_H
#define REPL_FAILSAFE_H
@@ -35,3 +36,4 @@ int register_slave(THD* thd, uchar* packet, uint packet_length);
void unregister_slave(THD* thd, bool only_mine, bool need_mutex);
#endif
+#endif /* HAVE_REPLICATION */
diff --git a/sql/set_var.cc b/sql/set_var.cc
index 30067336d5a..cd02010c499 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -47,6 +47,7 @@
#endif
#include "mysql_priv.h"
+#include <mysql.h>
#include "slave.h"
#include "sql_acl.h"
#include <my_getopt.h>
@@ -209,8 +210,10 @@ sys_var_thd_enum sys_query_cache_type("query_cache_type",
sys_var_long_ptr sys_server_id("server_id",&server_id);
sys_var_bool_ptr sys_slave_compressed_protocol("slave_compressed_protocol",
&opt_slave_compressed_protocol);
+#ifdef HAVE_REPLICATION
sys_var_long_ptr sys_slave_net_timeout("slave_net_timeout",
&slave_net_timeout);
+#endif
sys_var_long_ptr sys_slow_launch_time("slow_launch_time",
&slow_launch_time);
sys_var_thd_ulong sys_sort_buffer("sort_buffer_size",
@@ -302,7 +305,9 @@ static sys_var_readonly sys_warning_count("warning_count",
get_warning_count);
/* alias for last_insert_id() to be compatible with Sybase */
+#ifdef HAVE_REPLICATION
static sys_var_slave_skip_counter sys_slave_skip_counter("sql_slave_skip_counter");
+#endif
static sys_var_rand_seed1 sys_rand_seed1("rand_seed1");
static sys_var_rand_seed2 sys_rand_seed2("rand_seed2");
@@ -385,9 +390,11 @@ sys_var *sys_variables[]=
&sys_safe_updates,
&sys_select_limit,
&sys_server_id,
+#ifdef HAVE_REPLICATION
&sys_slave_compressed_protocol,
&sys_slave_net_timeout,
&sys_slave_skip_counter,
+#endif
&sys_slow_launch_time,
&sys_sort_buffer,
&sys_sql_big_tables,
@@ -482,7 +489,9 @@ struct show_var_st init_vars[]= {
{"log", (char*) &opt_log, SHOW_BOOL},
{"log_update", (char*) &opt_update_log, SHOW_BOOL},
{"log_bin", (char*) &opt_bin_log, SHOW_BOOL},
+#ifdef HAVE_REPLICATION
{"log_slave_updates", (char*) &opt_log_slave_updates, SHOW_MY_BOOL},
+#endif
{"log_slow_queries", (char*) &opt_slow_log, SHOW_BOOL},
{sys_log_warnings.name, (char*) &sys_log_warnings, SHOW_SYS},
{sys_long_query_time.name, (char*) &sys_long_query_time, SHOW_SYS},
@@ -535,7 +544,9 @@ struct show_var_st init_vars[]= {
{"shared_memory_base_name", (char*) &shared_memory_base_name, SHOW_CHAR_PTR},
#endif
{sys_server_id.name, (char*) &sys_server_id, SHOW_SYS},
+#ifdef HAVE_REPLICATION
{sys_slave_net_timeout.name,(char*) &sys_slave_net_timeout, SHOW_SYS},
+#endif
{"skip_external_locking", (char*) &my_disable_locking, SHOW_MY_BOOL},
{"skip_networking", (char*) &opt_disable_networking, SHOW_BOOL},
{"skip_show_database", (char*) &opt_skip_show_db, SHOW_BOOL},
@@ -635,6 +646,7 @@ static void fix_tx_isolation(THD *thd, enum_var_type type)
If we are changing the thread variable, we have to copy it to NET too
*/
+#ifdef HAVE_REPLICATION
static void fix_net_read_timeout(THD *thd, enum_var_type type)
{
if (type != OPT_GLOBAL)
@@ -653,6 +665,17 @@ static void fix_net_retry_count(THD *thd, enum_var_type type)
if (type != OPT_GLOBAL)
thd->net.retry_count=thd->variables.net_retry_count;
}
+#else /* HAVE_REPLICATION */
+static void fix_net_read_timeout(THD *thd __attribute__(unused),
+ enum_var_type type __attribute__(unused))
+{}
+static void fix_net_write_timeout(THD *thd __attribute__(unused),
+ enum_var_type type __attribute__(unused))
+{}
+static void fix_net_retry_count(THD *thd __attribute__(unused),
+ enum_var_type type __attribute__(unused))
+{}
+#endif /* HAVE_REPLICATION */
static void fix_query_cache_size(THD *thd, enum_var_type type)
@@ -1192,6 +1215,7 @@ byte *sys_var_insert_id::value_ptr(THD *thd, enum_var_type type)
}
+#ifdef HAVE_REPLICATION
bool sys_var_slave_skip_counter::check(THD *thd, set_var *var)
{
int result= 0;
@@ -1227,7 +1251,7 @@ bool sys_var_slave_skip_counter::update(THD *thd, set_var *var)
UNLOCK_ACTIVE_MI;
return 0;
}
-
+#endif /* HAVE_REPLICATION */
bool sys_var_rand_seed1::update(THD *thd, set_var *var)
{
@@ -1498,7 +1522,7 @@ int set_var::check(THD *thd)
return 0;
}
- if (value->check_cols(1) || value->fix_fields(thd, 0, &value))
+ if (value->fix_fields(thd, 0, &value) || value->check_cols(1))
return -1;
if (var->check_update_type(value->result_type()))
{
diff --git a/sql/set_var.h b/sql/set_var.h
index 5d7463d9fa8..3b4ec9d5bfe 100644
--- a/sql/set_var.h
+++ b/sql/set_var.h
@@ -374,6 +374,7 @@ public:
};
+#ifndef EMBEDDED_LIBRARY
class sys_var_slave_skip_counter :public sys_var
{
public:
@@ -386,7 +387,7 @@ public:
type() or value_ptr()
*/
};
-
+#endif
class sys_var_rand_seed1 :public sys_var
{
diff --git a/sql/slave.cc b/sql/slave.cc
index ce1a8e4befd..4572a265294 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -14,8 +14,10 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
#include "mysql_priv.h"
+
+#ifdef HAVE_REPLICATION
+
#include <mysql.h>
#include <myisam.h>
#include "mini_client.h"
@@ -3194,3 +3196,5 @@ err:
template class I_List_iterator<i_string>;
template class I_List_iterator<i_string_pair>;
#endif
+
+#endif /* HAVE_REPLICATION */
diff --git a/sql/slave.h b/sql/slave.h
index 91eedd60c7c..8122975a809 100644
--- a/sql/slave.h
+++ b/sql/slave.h
@@ -1,3 +1,5 @@
+#ifdef HAVE_REPLICATION
+
#ifndef SLAVE_H
#define SLAVE_H
@@ -463,3 +465,7 @@ extern I_List<i_string_pair> replicate_rewrite_db;
extern I_List<THD> threads;
#endif
+#else
+#define SLAVE_IO 1
+#define SLAVE_SQL 2
+#endif /* HAVE_REPLICATION */
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index cedb34b48bb..645d0439961 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -2721,8 +2721,12 @@ ulong get_table_grant(THD *thd, TABLE_LIST *table)
GRANT_TABLE *grant_table;
rw_rdlock(&LOCK_grant);
+#ifdef EMBEDDED_LIBRARY
+ grant_table= NULL;
+#else
grant_table = table_hash_search(thd->host,thd->ip,db,user,
table->real_name,0);
+#endif
table->grant.grant_table=grant_table; // Remember for column test
table->grant.version=grant_version;
if (grant_table)
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index e4af362c3e3..847617d6462 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -195,7 +195,6 @@ OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *wild)
DBUG_RETURN(open_list);
}
-
/*****************************************************************************
* Functions to free open table cache
****************************************************************************/
@@ -1928,8 +1927,7 @@ int setup_fields(THD *thd, TABLE_LIST *tables, List<Item> &fields,
}
else
{
- if (item->check_cols(1) ||
- item->fix_fields(thd, tables, it.ref()))
+ if (item->fix_fields(thd, tables, it.ref()) || item->check_cols(1))
DBUG_RETURN(-1); /* purecov: inspected */
item= *(it.ref()); //Item can be chenged in fix fields
if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM &&
@@ -2089,7 +2087,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
if (*conds)
{
thd->where="where clause";
- if ((*conds)->check_cols(1) || (*conds)->fix_fields(thd, tables, conds))
+ if ((*conds)->fix_fields(thd, tables, conds) || (*conds)->check_cols(1))
DBUG_RETURN(1);
}
@@ -2100,8 +2098,8 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
{
/* Make a join an a expression */
thd->where="on clause";
- if (table->on_expr->check_cols(1) ||
- table->on_expr->fix_fields(thd, tables, &table->on_expr))
+ if (table->on_expr->fix_fields(thd, tables, &table->on_expr) ||
+ table->on_expr->check_cols(1))
DBUG_RETURN(1);
thd->cond_count++;
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index b1ea9815f42..df06bcfd5c0 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -754,7 +754,7 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
if ((local_tables = is_cacheable(thd, thd->query_length,
thd->query, &thd->lex, tables_used)))
{
- NET *net = &thd->net;
+ NET *net= &thd->net;
byte flags = (thd->client_capabilities & CLIENT_LONG_FLAG ? 0x80 : 0);
STRUCT_LOCK(&structure_guard_mutex);
@@ -1015,11 +1015,13 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
ALIGN_SIZE(sizeof(Query_cache_result))));
Query_cache_result *result = result_block->result();
+#ifndef EMBEDDED_LIBRARY /* TODO query cache in embedded library*/
if (net_real_write(&thd->net, result->data(),
result_block->used -
result_block->headers_len() -
ALIGN_SIZE(sizeof(Query_cache_result))))
break; // Client aborted
+#endif
result_block = result_block->next;
} while (result_block != first_result_block);
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index d352fc95fdd..0b6da3d9bcd 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -107,8 +107,10 @@ THD::THD():user_time(0), fatal_error(0),
mysys_var=0;
#ifndef DBUG_OFF
dbug_sentry=THD_SENTRY_MAGIC;
-#endif
+#endif
+#ifndef EMBEDDED_LIBRARY
net.vio=0;
+#endif
net.last_error[0]=0; // If error on boot
ull=0;
system_thread=cleanup_done=0;
@@ -266,11 +268,13 @@ THD::~THD()
pthread_mutex_unlock(&LOCK_delete);
/* Close connection */
+#ifndef EMBEDDED_LIBRARY
if (net.vio)
{
vio_delete(net.vio);
net_end(&net);
}
+#endif
if (!cleanup_done)
cleanup();
#ifdef USING_TRANSACTIONS
@@ -510,7 +514,6 @@ bool select_send::send_fields(List<Item> &list,uint flag)
return thd->protocol->send_fields(&list,flag);
}
-
/* Send data to client. Returns 0 if ok */
bool select_send::send_data(List<Item> &items)
@@ -966,11 +969,12 @@ int select_dumpvar::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
my_error(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT, MYF(0));
return 1;
}
+ unit=u;
while ((item=li++))
{
ls= gl++;
Item_func_set_user_var *xx = new Item_func_set_user_var(*ls,item);
- xx->fix_fields(current_thd,(TABLE_LIST*) current_thd->lex.select_lex.table_list.first,&item);
+ xx->fix_fields(thd,(TABLE_LIST*) thd->lex.select_lex.table_list.first,&item);
xx->fix_length_and_dec();
vars.push_back(xx);
}
@@ -982,6 +986,11 @@ bool select_dumpvar::send_data(List<Item> &items)
Item_func_set_user_var *xx;
DBUG_ENTER("send_data");
+ if (unit->offset_limit_cnt)
+ { // Using limit offset,count
+ unit->offset_limit_cnt--;
+ DBUG_RETURN(0);
+ }
if (row_count++)
{
my_error(ER_TOO_MANY_ROWS, MYF(0));
diff --git a/sql/sql_class.h b/sql/sql_class.h
index e682bf5741a..216720da801 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -177,6 +177,12 @@ public:
{
convert_array(from_map, (uchar*) a,length);
}
+ char *store_dest(char *to, const char *from, uint length)
+ {
+ for (const char *end=from+length ; from != end ; from++)
+ *to++= to_map[(uchar) *from];
+ return to;
+ }
bool store(String *, const char *,uint);
inline uint number() { return numb; }
};
@@ -338,6 +344,10 @@ class select_result;
#define THD_SENTRY_MAGIC 0xfeedd1ff
#define THD_SENTRY_GONE 0xdeadbeef
+#ifdef EMBEDDED_LIBRARY
+typedef struct st_mysql;
+#endif
+
#define THD_CHECK_SENTRY(thd) DBUG_ASSERT(thd->dbug_sentry == THD_SENTRY_MAGIC)
struct system_variables
@@ -389,9 +399,11 @@ struct system_variables
For each client connection we create a separate thread with THD serving as
a thread/connection descriptor
*/
-
class THD :public ilink {
public:
+#ifdef EMBEDDED_LIBRARY
+ struct st_mysql *mysql;
+#endif
NET net; // client connection descriptor
LEX lex; // parse tree descriptor
MEM_ROOT mem_root; // 1 command-life memory pool
@@ -542,6 +554,7 @@ public:
THD();
~THD();
+
void init(void);
void change_user(void);
void cleanup(void);
@@ -637,12 +650,17 @@ public:
void add_changed_table(const char *key, long key_length);
CHANGED_TABLE_LIST * changed_table_dup(const char *key, long key_length);
int send_explain_fields(select_result *result);
+#ifndef EMBEDDED_LIBRARY
inline void clear_error()
{
net.last_error[0]= 0;
net.last_errno= 0;
net.report_error= 0;
}
+#else
+ void clear_error();
+#endif
+
void add_possible_loop(Item *);
};
diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc
index 0a2e2947add..f4c3979a34a 100644
--- a/sql/sql_derived.cc
+++ b/sql/sql_derived.cc
@@ -25,7 +25,7 @@
#include "sql_select.h"
#include "sql_acl.h"
-static const char *any_db="*any*"; // Special symbol for check_access
+extern const char *any_db; // Special symbol for check_access
/*
Resolve derived tables in all queries
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc
index e2d484b1c2b..ea5c07048ab 100644
--- a/sql/sql_handler.cc
+++ b/sql/sql_handler.cc
@@ -105,7 +105,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
}
tables->table=table;
- if (cond && (cond->check_cols(1) || cond->fix_fields(thd, tables, &cond)))
+ if (cond && (cond->fix_fields(thd, tables, &cond) || cond->check_cols(1)))
return -1;
/* InnoDB needs to know that this table handle is used in the HANDLER */
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 8fca6300992..71d8a3e181b 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -77,6 +77,8 @@ static int read_sep_field(THD *thd,COPY_INFO &info,TABLE *table,
String &enclosed);
+#ifndef EMBEDDED_LIBRARY
+
int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
List<Item> &fields, enum enum_duplicates handle_duplicates,
bool read_file_from_client,thr_lock_type lock_type)
@@ -156,12 +158,14 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
if (read_file_from_client && handle_duplicates == DUP_ERROR)
handle_duplicates=DUP_IGNORE;
+#ifndef EMBEDDED_LIBRARY
if (read_file_from_client)
{
(void)net_request_file(&thd->net,ex->file_name);
file = -1;
}
else
+#endif
{
read_file_from_client=0;
#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS
@@ -346,6 +350,7 @@ err:
DBUG_RETURN(error);
}
+#endif /* EMBEDDED_LIBRARY */
/****************************************************************************
** Read of rows of fixed size + optional garage + optonal newline
@@ -604,9 +609,11 @@ READ_INFO::READ_INFO(File file_par, uint tot_length, String &field_term,
cache.read_function = _my_b_net_read;
need_end_io_cache = 1;
+#ifndef EMBEDDED_LIBRARY
if (!opt_old_rpl_compat && mysql_bin_log.is_open())
cache.pre_read = cache.pre_close =
(IO_CACHE_CALLBACK) log_loaded_block;
+#endif
}
}
}
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index e53d60799c9..d5deabf606b 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -494,6 +494,7 @@ static void reset_mqh(THD *thd, LEX_USER *lu, bool get_them= 0)
Returns 0 on ok, -1 < if error is given > 0 on error.
*/
+#ifndef EMBEDDED_LIBRARY
static int
check_connections(THD *thd)
{
@@ -654,7 +655,7 @@ check_connections(THD *thd)
thd->variables.net_wait_timeout= thd->variables.net_interactive_timeout;
if ((thd->client_capabilities & CLIENT_TRANSACTIONS) &&
opt_using_transactions)
- thd->net.return_status= &thd->server_status;
+ net->return_status= &thd->server_status;
net->read_timeout=(uint) thd->variables.net_read_timeout;
/* Simple connect only for old clients. New clients always use secure auth */
@@ -712,7 +713,6 @@ check_connections(THD *thd)
return 0;
}
-
pthread_handler_decl(handle_one_connection,arg)
{
THD *thd=(THD*) arg;
@@ -903,6 +903,8 @@ end:
DBUG_RETURN(0); // Never reached
}
+#endif /* EMBEDDED_LIBRARY */
+
/* This works because items are allocated with sql_alloc() */
void free_items(Item *item)
@@ -957,8 +959,9 @@ err:
}
- /* Execute one command from socket (query or simple command) */
+#ifndef EMBEDDED_LIBRARY
+ /* Execute one command from socket (query or simple command) */
bool do_command(THD *thd)
{
char *packet;
@@ -1004,6 +1007,7 @@ bool do_command(THD *thd)
DBUG_RETURN(dispatch_command(command,thd, packet+1, (uint) packet_length));
}
+#endif /* EMBEDDED_LIBRARY */
bool dispatch_command(enum enum_server_command command, THD *thd,
char* packet, uint packet_length)
@@ -1033,12 +1037,14 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
if (!mysql_change_db(thd,packet))
mysql_log.write(thd,command,"%s",thd->db);
break;
+#ifndef EMBEDDED_LIBRARY
case COM_REGISTER_SLAVE:
{
if (!register_slave(thd, (uchar*)packet, packet_length))
send_ok(thd);
break;
}
+#endif
case COM_TABLE_DUMP:
{
statistic_increment(com_other, &LOCK_status);
@@ -1055,6 +1061,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
send_error(thd); // dump to NET
break;
}
+#ifndef EMBEDDED_LIBRARY
case COM_CHANGE_USER:
{
thd->change_user();
@@ -1170,7 +1177,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
thd->priv_user=save_priv_user;
break;
}
-
+#endif /* EMBEDDED_LIBRARY */
case COM_EXECUTE:
{
mysql_stmt_execute(thd, packet);
@@ -1198,6 +1205,29 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
mysql_log.write(thd,command,"%s",thd->query);
DBUG_PRINT("query",("%-.4096s",thd->query));
mysql_parse(thd,thd->query, thd->query_length);
+
+ while (!thd->fatal_error && thd->lex.found_colon)
+ {
+ /*
+ Multiple queries exits, execute them individually
+ */
+ if (thd->lock || thd->open_tables || thd->derived_tables)
+ close_thread_tables(thd);
+
+ uint length= thd->query_length-(uint)(thd->lex.found_colon-thd->query);
+
+ /* Remove garbage at start of query */
+ char *packet= thd->lex.found_colon;
+ while (my_isspace(system_charset_info,packet[0]) && length > 0)
+ {
+ packet++;
+ length--;
+ }
+ thd->query= packet;
+ thd->query_length= length;
+ mysql_parse(thd, packet, length);
+ }
+
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),WAIT_PRIOR);
DBUG_PRINT("info",("query ready"));
@@ -1285,6 +1315,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
mysql_rm_db(thd,db,0,0);
break;
}
+#ifndef EMBEDDED_LIBRARY
case COM_BINLOG_DUMP:
{
statistic_increment(com_other,&LOCK_status);
@@ -1309,6 +1340,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
net->error = 0;
break;
}
+#endif
case COM_REFRESH:
{
statistic_increment(com_stat[SQLCOM_FLUSH],&LOCK_status);
@@ -1320,6 +1352,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
reload_acl_and_cache(thd, options, (TABLE_LIST*) 0) ;
break;
}
+#ifndef EMBEDDED_LIBRARY
case COM_SHUTDOWN:
statistic_increment(com_other,&LOCK_status);
if (check_global_access(thd,SHUTDOWN_ACL))
@@ -1340,7 +1373,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
kill_mysql();
error=TRUE;
break;
-
+#endif
+#ifndef EMBEDDED_LIBRARY
case COM_STATISTICS:
{
mysql_log.write(thd,command,NullS);
@@ -1362,6 +1396,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
VOID(net_flush(net));
break;
}
+#endif
case COM_PING:
statistic_increment(com_other,&LOCK_status);
send_ok(thd); // Tell client we are alive
@@ -1425,14 +1460,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
mysql_slow_log.write(thd, thd->query, thd->query_length, start_of_query);
}
}
- if (command == COM_QUERY && thd->lex.found_colon)
- {
- /*
- Multiple queries exits, execute them individually
- */
- uint length= thd->query_length-(uint)(thd->lex.found_colon-thd->query)+1;
- dispatch_command(command, thd, thd->lex.found_colon, length);
- }
thd->proc_info="cleaning up";
VOID(pthread_mutex_lock(&LOCK_thread_count)); // For process list
thd->proc_info=0;
@@ -1463,7 +1490,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
bool alloc_query(THD *thd, char *packet, ulong packet_length)
{
packet_length--; // Remove end null
- /* Remove garage at start and end of query */
+ /* Remove garbage at start and end of query */
while (my_isspace(system_charset_info,packet[0]) && packet_length > 0)
{
packet++;
@@ -1519,6 +1546,7 @@ mysql_execute_command(THD *thd)
*/
thd->old_total_warn_count= thd->total_warn_count;
+#ifndef EMBEDDED_LIBRARY
if (thd->slave_thread)
{
/*
@@ -1540,7 +1568,7 @@ mysql_execute_command(THD *thd)
}
#endif
}
-
+#endif /* EMBEDDED_LIBRARY */
/*
TODO: make derived tables processing 'inside' SELECT processing.
TODO: solve problem with depended derived tables in subselects
@@ -1568,9 +1596,13 @@ mysql_execute_command(THD *thd)
}
}
if ((&lex->select_lex != lex->all_selects_list &&
- lex->unit.create_total_list(thd, lex, &tables)) ||
+ lex->unit.create_total_list(thd, lex, &tables))
+#ifndef EMBEDDED_LIBRARY
+ ||
(table_rules_on && tables && thd->slave_thread &&
- !tables_ok(thd,tables)))
+ !tables_ok(thd,tables))
+#endif
+ )
DBUG_VOID_RETURN;
statistic_increment(com_stat[lex->sql_command],&LOCK_status);
@@ -1660,6 +1692,7 @@ mysql_execute_command(THD *thd)
res= mysqld_help(thd,lex->help_arg);
break;
+#ifndef EMBEDDED_LIBRARY
case SQLCOM_PURGE:
{
if (check_global_access(thd, SUPER_ACL))
@@ -1667,6 +1700,8 @@ mysql_execute_command(THD *thd)
res = purge_master_logs(thd, lex->to_log);
break;
}
+#endif
+
case SQLCOM_SHOW_WARNS:
{
res= mysqld_show_warnings(thd, (ulong)
@@ -1694,6 +1729,8 @@ mysql_execute_command(THD *thd)
#endif
break;
}
+
+#ifndef EMBEDDED_LIBRARY
case SQLCOM_SHOW_SLAVE_HOSTS:
{
if (check_global_access(thd, REPL_SLAVE_ACL))
@@ -1708,6 +1745,8 @@ mysql_execute_command(THD *thd)
res = show_binlog_events(thd);
break;
}
+#endif
+
case SQLCOM_BACKUP_TABLE:
{
if (check_db_used(thd,tables) ||
@@ -1727,6 +1766,8 @@ mysql_execute_command(THD *thd)
res = mysql_restore_table(thd, tables);
break;
}
+
+#ifndef EMBEDDED_LIBRARY
case SQLCOM_CHANGE_MASTER:
{
if (check_global_access(thd, SUPER_ACL))
@@ -1761,6 +1802,7 @@ mysql_execute_command(THD *thd)
else
res = load_master_data(thd);
break;
+#endif /* EMBEDDED_LIBRARY */
#ifdef HAVE_INNOBASE_DB
case SQLCOM_SHOW_INNODB_STATUS:
@@ -1772,6 +1814,7 @@ mysql_execute_command(THD *thd)
}
#endif
+#ifndef EMBEDDED_LIBRARY
case SQLCOM_LOAD_MASTER_TABLE:
{
if (!tables->db)
@@ -1803,6 +1846,8 @@ mysql_execute_command(THD *thd)
UNLOCK_ACTIVE_MI;
break;
}
+#endif /* EMBEDDED_LIBRARY */
+
case SQLCOM_CREATE_TABLE:
{
ulong want_priv= ((lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) ?
@@ -1907,6 +1952,7 @@ mysql_execute_command(THD *thd)
res = mysql_create_index(thd, tables, lex->key_list);
break;
+#ifndef EMBEDDED_LIBRARY
case SQLCOM_SLAVE_START:
{
LOCK_ACTIVE_MI;
@@ -1939,6 +1985,8 @@ mysql_execute_command(THD *thd)
UNLOCK_ACTIVE_MI;
break;
}
+#endif
+
case SQLCOM_ALTER_TABLE:
#if defined(DONT_ALLOW_SHOW_COMMANDS)
send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
@@ -2029,6 +2077,7 @@ mysql_execute_command(THD *thd)
res= -1;
break;
}
+#ifndef EMBEDDED_LIBRARY
case SQLCOM_SHOW_BINLOGS:
#ifdef DONT_ALLOW_SHOW_COMMANDS
send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
@@ -2041,6 +2090,7 @@ mysql_execute_command(THD *thd)
break;
}
#endif
+#endif /* EMBEDDED_LIBRARY */
case SQLCOM_SHOW_CREATE:
#ifdef DONT_ALLOW_SHOW_COMMANDS
send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
@@ -2503,6 +2553,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_CHANGE_DB:
mysql_change_db(thd,select_lex->db);
break;
+#ifndef EMBEDDED_LIBRARY
case SQLCOM_LOAD:
{
uint privilege= (lex->duplicates == DUP_REPLACE ?
@@ -2529,6 +2580,7 @@ mysql_execute_command(THD *thd)
lex->duplicates, (bool) lex->local_file, lex->lock_option);
break;
}
+#endif /* EMBEDDED_LIBRARY */
case SQLCOM_SET_OPTION:
if (tables && ((res= check_table_access(thd, SELECT_ACL, tables)) ||
(res= open_and_lock_tables(thd,tables))))
@@ -3216,7 +3268,9 @@ mysql_parse(THD *thd, char *inBuf, uint length)
else
{
mysql_execute_command(thd);
+#ifndef EMBEDDED_LIBRARY /* TODO query cache in embedded library*/
query_cache_end_of_result(&thd->net);
+#endif
}
}
}
@@ -3224,7 +3278,9 @@ mysql_parse(THD *thd, char *inBuf, uint length)
{
DBUG_PRINT("info",("Command aborted. Fatal_error: %d",
thd->fatal_error));
+#ifndef EMBEDDED_LIBRARY /* TODO query cache in embedded library*/
query_cache_abort(&thd->net);
+#endif
}
thd->proc_info="freeing items";
free_items(thd->free_list); /* Free strings used by items */
@@ -3341,7 +3397,6 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
allowed_type_modifier= AUTO_INCREMENT_FLAG;
break;
case FIELD_TYPE_NULL:
- case FIELD_TYPE_GEOMETRY:
break;
case FIELD_TYPE_DECIMAL:
if (!length)
@@ -3365,6 +3420,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
case FIELD_TYPE_TINY_BLOB:
case FIELD_TYPE_LONG_BLOB:
case FIELD_TYPE_MEDIUM_BLOB:
+ case FIELD_TYPE_GEOMETRY:
if (new_field->length)
{
/* The user has given a length to the blob column */
@@ -3518,7 +3574,8 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
if (new_field->length >= MAX_FIELD_WIDTH ||
(!new_field->length && !(new_field->flags & BLOB_FLAG) &&
- type != FIELD_TYPE_STRING && type != FIELD_TYPE_VAR_STRING))
+ type != FIELD_TYPE_STRING &&
+ type != FIELD_TYPE_VAR_STRING && type != FIELD_TYPE_GEOMETRY))
{
net_printf(thd,ER_TOO_BIG_FIELDLENGTH,field_name,
MAX_FIELD_WIDTH-1); /* purecov: inspected */
@@ -3833,9 +3890,11 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables)
refresh_status();
if (options & REFRESH_THREADS)
flush_thread_cache();
+#ifndef EMBEDDED_LIBRARY
if (options & REFRESH_MASTER)
if (reset_master(thd))
result=1;
+#endif
#ifdef OPENSSL
if (options & REFRESH_DES_KEY_FILE)
{
@@ -3843,6 +3902,7 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables)
result=load_des_key_file(des_key_file);
}
#endif
+#ifndef EMBEDDED_LIBRARY
if (options & REFRESH_SLAVE)
{
LOCK_ACTIVE_MI;
@@ -3859,6 +3919,7 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables)
}
UNLOCK_ACTIVE_MI;
}
+#endif
if (options & REFRESH_USER_RESOURCES)
reset_mqh(thd,(LEX_USER *) NULL);
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 75b4fcb1896..e8ba7e91c7b 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -30,7 +30,11 @@ Prepare:
- Without executing the query, return back to client the total
number of parameters along with result-set metadata information
(if any) in the following format:
- [STMT_ID:4][Columns:2][Param_count:2][Columns meta info][Params meta info]
+ [STMT_ID:4]
+ [Column_count:2]
+ [Param_count:2]
+ [Columns meta info] (if Column_count > 0)
+ [Params meta info] (if Param_count > 0 ) (TODO : 4.1.1)
Prepare-execute:
@@ -140,7 +144,13 @@ static bool send_prep_stmt(PREP_STMT *stmt, uint columns)
int4store(buff, stmt->stmt_id);
int2store(buff+4, columns);
int2store(buff+6, stmt->param_count);
+#ifndef EMBEDDED_LIBRARY
+ /* This should be fixed to work with prepared statements
+ */
return (my_net_write(net, buff, sizeof(buff)) || net_flush(net));
+#else
+ return true;
+#endif
}
/*
@@ -299,7 +309,11 @@ static bool setup_params_data(PREP_STMT *stmt)
Item_param *param;
DBUG_ENTER("setup_params_data");
+#ifndef EMBEDDED_LIBRARY
uchar *pos=(uchar*) thd->net.read_pos+1+MYSQL_STMT_HEADER; //skip header
+#else
+ uchar *pos= 0; //just to compile TODO code for embedded case
+#endif
uchar *read_pos= pos+(stmt->param_count+7) / 8; //skip null bits
if (*read_pos++) //types supplied / first execute
diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc
index 99fcedfc023..522ec9f6aeb 100644
--- a/sql/sql_repl.cc
+++ b/sql/sql_repl.cc
@@ -17,6 +17,8 @@
// Sasha Pachev <sasha@mysql.com> is currently in charge of this file
#include "mysql_priv.h"
+#ifdef HAVE_REPLICATION
+
#include "sql_repl.h"
#include "sql_acl.h"
#include "log_event.h"
@@ -1167,3 +1169,7 @@ int log_loaded_block(IO_CACHE* file)
}
return 0;
}
+
+#endif /* HAVE_REPLICATION */
+
+
diff --git a/sql/sql_repl.h b/sql/sql_repl.h
index 15435382b08..f1fda45fe4b 100644
--- a/sql/sql_repl.h
+++ b/sql/sql_repl.h
@@ -1,3 +1,4 @@
+#ifdef HAVE_REPLICATION
#include "slave.h"
typedef struct st_slave_info
@@ -53,3 +54,6 @@ typedef struct st_load_file_info
} LOAD_FILE_INFO;
int log_loaded_block(IO_CACHE* file);
+
+#endif /* HAVE_REPLICATION */
+
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index d21c89bc512..f758fef4fc9 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -270,8 +270,8 @@ JOIN::prepare(TABLE_LIST *tables_init,
thd->where="having clause";
thd->allow_sum_func=1;
select_lex->having_fix_field= 1;
- bool having_fix_rc= (having->check_cols(1) ||
- having->fix_fields(thd, tables_list, &having));
+ bool having_fix_rc= (having->fix_fields(thd, tables_list, &having) ||
+ having->check_cols(1));
select_lex->having_fix_field= 0;
if (having_fix_rc || thd->net.report_error)
DBUG_RETURN(-1); /* purecov: inspected */
@@ -713,6 +713,13 @@ JOIN::exec()
int tmp_error;
DBUG_ENTER("JOIN::exec");
+
+ if (procedure)
+ {
+ if (procedure->change_columns(fields_list) ||
+ result->prepare(fields_list, unit))
+ DBUG_VOID_RETURN;
+ }
if (!tables_list)
{ // Only test of functions
@@ -767,8 +774,6 @@ JOIN::exec()
test_if_skip_sort_order(&join_tab[const_tables], order,
select_limit, 0))))
order=0;
- if (procedure)
- (void)result->prepare(fields_list, unit);
select_describe(this, need_tmp,
order != 0 && !skip_sort_order,
select_distinct);
@@ -988,9 +993,6 @@ JOIN::exec()
}
if (procedure)
{
- if (procedure->change_columns(fields_list) ||
- result->prepare(fields_list, unit))
- DBUG_VOID_RETURN;
count_field_types(&tmp_table_param, all_fields, 0);
}
if (group || tmp_table_param.sum_func_count ||
@@ -3666,7 +3668,9 @@ remove_eq_conds(COND *cond,Item::cond_result *cond_value)
(thd->options & OPTION_AUTO_IS_NULL) &&
thd->insert_id())
{
+#ifndef EMBEDDED_LIBRARY
query_cache_abort(&thd->net);
+#endif
COND *new_cond;
if ((new_cond= new Item_func_eq(args[0],
new Item_int("last_insert_id()",
@@ -5604,6 +5608,9 @@ end_update(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
{
Item *item= *group->item;
item->save_org_in_field(group->field);
+#ifdef EMBEDDED_LIBRARY
+ join->thd->net.last_errno= 0;
+#endif
/* Store in the used key if the field was 0 */
if (item->maybe_null)
group->buff[-1]=item->null_value ? 1 : 0;
@@ -6930,7 +6937,7 @@ find_order_in_list(THD *thd,TABLE_LIST *tables,ORDER *order,List<Item> &fields,
}
order->in_field_list=0;
Item *it= *order->item;
- if (it->check_cols(1) || it->fix_fields(thd, tables, order->item) ||
+ if (it->fix_fields(thd, tables, order->item) || it->check_cols(1) ||
thd->fatal_error)
return 1; // Wrong field
all_fields.push_front(*order->item); // Add new field to field list
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 3ec45c8eca9..e77947e70f6 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -53,7 +53,6 @@ extern struct st_VioSSLAcceptorFd * ssl_acceptor_fd;
** A database is a directory in the mysql_data_home directory
****************************************************************************/
-
int
mysqld_show_dbs(THD *thd,const char *wild)
{
@@ -688,14 +687,8 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
field_list.push_back(new Item_empty_string("Comment",255));
}
// Send first number of fields and records
- {
- char *pos;
- pos=net_store_length(tmp, (uint) field_list.elements);
- pos=net_store_length(pos,(ulonglong) file->records);
- (void) my_net_write(&thd->net,tmp,(uint) (pos-tmp));
- }
-
- if (protocol->send_fields(&field_list,0))
+ if (protocol->send_records_num(&field_list, (ulonglong)file->records) ||
+ protocol->send_fields(&field_list,0))
DBUG_RETURN(1);
restore_record(table,2); // Get empty record
@@ -755,8 +748,8 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
if (verbose)
{
/* Add grant options & comments */
- col_access= get_column_grant(thd,table_list,field) & COL_ACLS;
end=tmp;
+ col_access= get_column_grant(thd,table_list,field) & COL_ACLS;
for (uint bitnr=0; col_access ; col_access>>=1,bitnr++)
{
if (col_access & 1)
@@ -1284,7 +1277,6 @@ public:
template class I_List<thread_info>;
#endif
-
void mysqld_list_processes(THD *thd,const char *user, bool verbose)
{
Item *field;
@@ -1317,8 +1309,13 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
while ((tmp=it++))
{
struct st_my_thread_var *mysys_var;
+#ifndef EMBEDDED_LIBRARY
if ((tmp->net.vio || tmp->system_thread) &&
(!user || (tmp->user && !strcmp(tmp->user,user))))
+#else
+ if (tmp->system_thread &&
+ (!user || (tmp->user && !strcmp(tmp->user,user))))
+#endif
{
thread_info *thd_info=new thread_info;
@@ -1336,6 +1333,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
if ((mysys_var= tmp->mysys_var))
pthread_mutex_lock(&mysys_var->mutex);
thd_info->proc_info= (char*) (tmp->killed ? "Killed" : 0);
+#ifndef EMBEDDED_LIBRARY
thd_info->state_info= (char*) (tmp->locked ? "Locked" :
tmp->net.reading_or_writing ?
(tmp->net.reading_or_writing == 2 ?
@@ -1346,6 +1344,9 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
tmp->mysys_var &&
tmp->mysys_var->current_cond ?
"Waiting on cond" : NullS);
+#else
+ thd_info->state_info= (char*)"Writing to net";
+#endif
if (mysys_var)
pthread_mutex_unlock(&mysys_var->mutex);
@@ -1398,7 +1399,6 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
DBUG_VOID_RETURN;
}
-
/*****************************************************************************
Status functions
*****************************************************************************/
@@ -1524,10 +1524,10 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables,
case SHOW_QUESTION:
end= int10_to_str((long) thd->query_id, buff, 10);
break;
+#ifndef EMBEDDED_LIBRARY
case SHOW_RPL_STATUS:
end= strmov(buff, rpl_status_type[(int)rpl_status]);
break;
-#ifndef EMBEDDED_LIBRARY
case SHOW_SLAVE_RUNNING:
{
LOCK_ACTIVE_MI;
@@ -1536,7 +1536,7 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables,
UNLOCK_ACTIVE_MI;
break;
}
-#endif
+#endif /* EMBEDDED_LIBRARY */
case SHOW_OPENTABLES:
end= int10_to_str((long) cached_tables(), buff, 10);
break;
@@ -1715,6 +1715,8 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables,
case SHOW_UNDEF: // Show never happen
case SHOW_SYS:
break; // Return empty string
+ default:
+ break;
}
if (protocol->store(pos, (uint32) (end - pos)) ||
protocol->write())
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index f6b3305761e..3f443c34287 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -440,6 +440,16 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
sql_field->unireg_check=Field::BLOB_FIELD;
blob_columns++;
break;
+ case FIELD_TYPE_GEOMETRY:
+ sql_field->pack_flag=FIELDFLAG_GEOM |
+ pack_length_to_packflag(sql_field->pack_length -
+ portable_sizeof_char_ptr);
+ if (sql_field->charset->state & MY_CS_BINSORT)
+ sql_field->pack_flag|=FIELDFLAG_BINARY;
+ sql_field->length=8; // Unireg field length
+ sql_field->unireg_check=Field::BLOB_FIELD;
+ blob_columns++;
+ break;
case FIELD_TYPE_VAR_STRING:
case FIELD_TYPE_STRING:
sql_field->pack_flag=0;
@@ -1221,6 +1231,9 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables,
thd->open_options|= extra_open_options;
table->table = open_ltable(thd, table, lock_type);
+#ifdef EMBEDDED_LIBRARY
+ thd->net.last_errno= 0; // these errors shouldn't get client
+#endif
thd->open_options&= ~extra_open_options;
if (prepare_func)
@@ -1286,6 +1299,9 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables,
}
int result_code = (table->table->file->*operator_func)(thd, check_opt);
+#ifdef EMBEDDED_LIBRARY
+ thd->net.last_errno= 0; // these errors shouldn't get client
+#endif
protocol->prepare_for_resend();
protocol->store(table_name);
protocol->store(operator_name);
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index fb594f28b2d..d603748c443 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -2573,6 +2573,12 @@ select_derived:
{
LEX *lex= Lex;
lex->derived_tables= 1;
+ if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN &&
+ lex->sql_command <= (int)SQLCOM_HA_READ) || lex->sql_command == (int)SQLCOM_KILL)
+ {
+ send_error(lex->thd, ER_SYNTAX_ERROR);
+ YYABORT;
+ }
if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
mysql_new_select(lex, 1))
YYABORT;
@@ -3572,7 +3578,7 @@ kill:
KILL_SYM expr
{
LEX *lex=Lex;
- if ($2->check_cols(1) || $2->fix_fields(lex->thd, 0, &$2))
+ if ($2->fix_fields(lex->thd, 0, &$2) || $2->check_cols(1))
{
send_error(lex->thd, ER_SET_CONSTANTS_ONLY);
YYABORT;
@@ -4640,6 +4646,12 @@ in_subselect_init:
subselect_start:
'(' SELECT_SYM
{
+ LEX *lex=Lex;
+ if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN &&
+ lex->sql_command <= (int)SQLCOM_HA_READ) || lex->sql_command == (int)SQLCOM_KILL) {
+ send_error(lex->thd, ER_SYNTAX_ERROR);
+ YYABORT;
+ }
if (mysql_new_select(Lex, 1))
YYABORT;
};