summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <monty@donna.mysql.fi>2001-04-25 01:11:29 +0300
committerunknown <monty@donna.mysql.fi>2001-04-25 01:11:29 +0300
commitdbd56fcdc575d522e8cac6046b85e29d496a37e9 (patch)
treeb35002c3218b71a338dff899023d7799c6cc4829
parent7337a193b1bb590c127daa9d92839e476e9b219f (diff)
downloadmariadb-git-dbd56fcdc575d522e8cac6046b85e29d496a37e9.tar.gz
Fixes for embedded MySQL
Some limit optimization BitKeeper/deleted/.del-ib_config.h.in~9e57db8504e55b7: Delete: innobase/ib_config.h.in BitKeeper/deleted/.del-ib_config.h~7539e26ffc614439: Delete: innobase/ib_config.h client/errmsg.c: Moved error messages from libmysqld/ client/mysql.cc: Removed warnings include/errmsg.h: New info for embedded versions include/mysql_com.h: Fixes for embedded MySQL libmysql/errmsg.c: Fixes for embedded MySQL libmysqld/Makefile.am: Added HANDLER code libmysqld/lib_sql.cc: Fixes for embedded MySQL libmysqld/lib_vio.c: Fixes for embedded MySQL BitKeeper/etc/ignore: Added libmysqld/sql_handler.cc to the ignore list libmysqld/libmysqld.c: Fixes for embedded MySQL mysql-test/r/null_key.result: Fixed result for 4.0 sql/net_serv.cc: Fixes for embedded MySQL sql/sql_parse.cc: Fixes for embedded MySQL where the query could be a const char* sql/sql_select.cc: Added limit optimization sql/sql_select.h: Added limit optimization
-rw-r--r--.bzrignore1
-rw-r--r--client/errmsg.c16
-rw-r--r--client/mysql.cc26
-rw-r--r--include/errmsg.h1
-rw-r--r--include/mysql_com.h8
-rw-r--r--innobase/ib_config.h25
-rw-r--r--innobase/ib_config.h.in24
-rw-r--r--libmysql/errmsg.c6
-rw-r--r--libmysqld/Makefile.am6
-rw-r--r--libmysqld/lib_sql.cc45
-rw-r--r--libmysqld/lib_vio.c4
-rw-r--r--libmysqld/libmysqld.c133
-rw-r--r--mysql-test/r/null_key.result2
-rw-r--r--sql/net_serv.cc4
-rw-r--r--sql/sql_parse.cc4
-rw-r--r--sql/sql_select.cc17
-rw-r--r--sql/sql_select.h2
17 files changed, 95 insertions, 229 deletions
diff --git a/.bzrignore b/.bzrignore
index bd4d7870157..05395e62b57 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -315,3 +315,4 @@ libmysqld/time.cc
libmysqld/unireg.cc
linked_libmysqld_sources
sql-bench/bench-count-distinct
+libmysqld/sql_handler.cc
diff --git a/client/errmsg.c b/client/errmsg.c
index a31386e70b4..1d95e5ac84f 100644
--- a/client/errmsg.c
+++ b/client/errmsg.c
@@ -36,14 +36,17 @@ const char *client_errors[]=
"MySQL client got out of memory",
"Wrong host info",
"Localhost via UNIX socket",
- "%s via TCP/IP",
+ "%-.64s via TCP/IP",
"Error in server handshake",
"Lost connection to MySQL server during query",
"Commands out of sync; You can't run this command now",
"Verbindung ueber Named Pipe; Host: %-.64s",
"Kann nicht auf Named Pipe warten. Host: %-.64s pipe: %-.32s (%lu)",
"Kann Named Pipe nicht oeffnen. Host: %-.64s pipe: %-.32s (%lu)",
- "Kann den Status der Named Pipe nicht setzen. Host: %-.64s pipe: %-.32s (%lu)"
+ "Kann den Status der Named Pipe nicht setzen. Host: %-.64s pipe: %-.32s (%lu)",
+ "Can't initialize character set %-.64s (path: %-.64s)",
+ "Got packet bigger than 'max_allowed_packet'",
+ "Embedded server",
};
#else /* ENGLISH */
@@ -60,19 +63,22 @@ const char *client_errors[]=
"MySQL client run out of memory",
"Wrong host info",
"Localhost via UNIX socket",
- "%s via TCP/IP",
+ "%-.64s via TCP/IP",
"Error in server handshake",
"Lost connection to MySQL server during query",
"Commands out of sync; You can't run this command now",
- "%s via named pipe",
+ "%-.64s via named pipe",
"Can't wait for named pipe to host: %-.64s pipe: %-.32s (%lu)",
"Can't open named pipe to host: %-.64s pipe: %-.32s (%lu)",
"Can't set state of named pipe to host: %-.64s pipe: %-.32s (%lu)",
+ "Can't initialize character set %-.64s (path: %-.64s)",
+ "Got packet bigger than 'max_allowed_packet'",
+ "Embedded server",
};
#endif
void init_client_errs(void)
{
- errmsg[CLIENT_ERRMAP] = &client_errors[0];
+ my_errmsg[CLIENT_ERRMAP] = &client_errors[0];
}
diff --git a/client/mysql.cc b/client/mysql.cc
index 1c8e8485c01..ce51467ffd9 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -133,7 +133,7 @@ static String glob_buffer,old_buffer;
static int wait_time = 5;
static STATUS status;
static ulong select_limit,max_join_size,opt_connect_timeout=0;
-static char *xmlmeta[] = {
+static const char *xmlmeta[] = {
"&", "&amp;",
"<", "&lt;",
0, 0
@@ -173,8 +173,8 @@ static int sql_connect(char *host,char *database,char *user,char *password,
uint silent);
static int put_info(const char *str,INFO_TYPE info,uint error=0);
static void safe_put_field(const char *pos,ulong length);
-static char *array_value(char **array, char *key);
-static char *xmlencode(char *dest, char *src);
+static const char *array_value(const char **array, char *key);
+static void xmlencode(char *dest, char *src);
static void my_chomp(char *end);
static void init_pager();
static void end_pager();
@@ -1739,8 +1739,8 @@ print_table_data_vertically(MYSQL_RES *result)
}
}
-static char
-*array_value(char **array, char *key) {
+static const char
+*array_value(const char **array, char *key) {
int x;
for(x=0; array[x]; x+=2)
if(!strcmp(array[x], key))
@@ -1748,19 +1748,21 @@ static char
return 0;
}
-static char
-*xmlencode(char *dest, char *src) {
+static void
+xmlencode(char *dest, char *src)
+{
char *p = src;
- char *t;
+ const char *t;
char s[2] = { 0, 0 };
*dest = 0;
- do {
+ do
+ {
s[0] = *p;
- if(!(t=array_value(xmlmeta, s))) t = s;
- strcat(dest, t);
+ if (!(t=array_value(xmlmeta, s)))
+ t = s;
+ dest=strmov(dest, t);
} while(*p++);
- return dest;
}
static void
diff --git a/include/errmsg.h b/include/errmsg.h
index b7afe11b615..12a3ee5557a 100644
--- a/include/errmsg.h
+++ b/include/errmsg.h
@@ -53,3 +53,4 @@ extern const char *client_errors[]; /* Error messages */
#define CR_NAMEDPIPESETSTATE_ERROR 2018
#define CR_CANT_READ_CHARSET 2019
#define CR_NET_PACKET_TOO_LARGE 2020
+#define CR_EMBEDDED_CONNECTION 2021
diff --git a/include/mysql_com.h b/include/mysql_com.h
index 15a14a508e5..874430910ef 100644
--- a/include/mysql_com.h
+++ b/include/mysql_com.h
@@ -157,6 +157,10 @@ extern unsigned long net_buffer_length;
#define net_new_transaction(net) ((net)->pkt_nr=0)
+#ifdef __cplusplus
+extern "C" {
+#endif
+
int my_net_init(NET *net, Vio* vio);
void net_end(NET *net);
void net_clear(NET *net);
@@ -172,6 +176,10 @@ struct rand_struct {
double max_value_dbl;
};
+#ifdef __cplusplus
+}
+#endif
+
/* The following is for user defined functions */
enum Item_result {STRING_RESULT,REAL_RESULT,INT_RESULT};
diff --git a/innobase/ib_config.h b/innobase/ib_config.h
deleted file mode 100644
index a2276199abd..00000000000
--- a/innobase/ib_config.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* ib_config.h. Generated automatically by configure. */
-/* ib_config.h.in. Generated automatically from configure.in by autoheader. */
-
-/* Define as __inline if that's what the C compiler calls it. */
-/* #undef inline */
-
-/* Define if your processor stores words with the most significant
- byte first (like Motorola and SPARC, unlike Intel and VAX). */
-/* #undef WORDS_BIGENDIAN */
-
-/* The number of bytes in a int. */
-#define SIZEOF_INT 4
-
-/* Define if you have the <aio.h> header file. */
-#define HAVE_AIO_H 1
-
-/* Name of package */
-#define PACKAGE "ib"
-
-/* Version number of package */
-#define VERSION "0.90"
-
-/* No inlining because gcc broken on HP-UX */
-/* #undef UNIV_MUST_NOT_INLINE */
-
diff --git a/innobase/ib_config.h.in b/innobase/ib_config.h.in
deleted file mode 100644
index 1ea07f5c0c3..00000000000
--- a/innobase/ib_config.h.in
+++ /dev/null
@@ -1,24 +0,0 @@
-/* ib_config.h.in. Generated automatically from configure.in by autoheader. */
-
-/* Define as __inline if that's what the C compiler calls it. */
-#undef inline
-
-/* Define if your processor stores words with the most significant
- byte first (like Motorola and SPARC, unlike Intel and VAX). */
-#undef WORDS_BIGENDIAN
-
-/* The number of bytes in a int. */
-#undef SIZEOF_INT
-
-/* Define if you have the <aio.h> header file. */
-#undef HAVE_AIO_H
-
-/* Name of package */
-#undef PACKAGE
-
-/* Version number of package */
-#undef VERSION
-
-/* No inlining because gcc broken on HP-UX */
-#undef UNIV_MUST_NOT_INLINE
-
diff --git a/libmysql/errmsg.c b/libmysql/errmsg.c
index 711228e459d..1d95e5ac84f 100644
--- a/libmysql/errmsg.c
+++ b/libmysql/errmsg.c
@@ -45,7 +45,8 @@ const char *client_errors[]=
"Kann Named Pipe nicht oeffnen. Host: %-.64s pipe: %-.32s (%lu)",
"Kann den Status der Named Pipe nicht setzen. Host: %-.64s pipe: %-.32s (%lu)",
"Can't initialize character set %-.64s (path: %-.64s)",
- "Got packet bigger than 'max_allowed_packet'"
+ "Got packet bigger than 'max_allowed_packet'",
+ "Embedded server",
};
#else /* ENGLISH */
@@ -71,7 +72,8 @@ const char *client_errors[]=
"Can't open named pipe to host: %-.64s pipe: %-.32s (%lu)",
"Can't set state of named pipe to host: %-.64s pipe: %-.32s (%lu)",
"Can't initialize character set %-.64s (path: %-.64s)",
- "Got packet bigger than 'max_allowed_packet'"
+ "Got packet bigger than 'max_allowed_packet'",
+ "Embedded server",
};
#endif
diff --git a/libmysqld/Makefile.am b/libmysqld/Makefile.am
index 396213b7e04..8d8ac3c9a21 100644
--- a/libmysqld/Makefile.am
+++ b/libmysqld/Makefile.am
@@ -41,7 +41,8 @@ libmysqlobjects = errmsg.lo get_password.lo password.lo
sqlsources = convert.cc derror.cc field.cc field_conv.cc filesort.cc \
ha_berkeley.cc ha_heap.cc ha_isam.cc ha_isammrg.cc \
- ha_myisam.cc ha_myisammrg.cc handler.cc hostname.cc init.cc \
+ ha_myisam.cc ha_myisammrg.cc handler.cc sql_handler.cc \
+ hostname.cc init.cc \
item.cc item_buff.cc item_cmpfunc.cc item_create.cc \
item_func.cc item_strfunc.cc item_sum.cc item_timefunc.cc \
item_uniq.cc key.cc lock.cc log.cc log_event.cc md5.c \
@@ -58,7 +59,8 @@ sqlsources = convert.cc derror.cc field.cc field_conv.cc filesort.cc \
## XXX: we should not have to duplicate info from the sources list
sqlobjects = convert.lo derror.lo field.lo field_conv.lo filesort.lo \
ha_berkeley.lo ha_heap.lo ha_isam.lo ha_isammrg.lo \
- ha_myisam.lo ha_myisammrg.lo handler.lo hostname.lo init.lo \
+ ha_myisam.lo ha_myisammrg.lo handler.lo sql_handler.lo \
+ hostname.lo init.lo \
item.lo item_buff.lo item_cmpfunc.lo item_create.lo \
item_func.lo item_strfunc.lo item_sum.lo item_timefunc.lo \
item_uniq.lo key.lo lock.lo log.lo log_event.lo md5.lo \
diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc
index 8a484301b61..b2889079ac8 100644
--- a/libmysqld/lib_sql.cc
+++ b/libmysqld/lib_sql.cc
@@ -126,8 +126,6 @@ void start_embedded_conn1(NET * net)
if (thd->max_join_size == HA_POS_ERROR)
thd->options |= OPTION_BIG_SELECTS;
- if (thd->client_capabilities & CLIENT_COMPRESS)
- net->compress=1; // Use compression
if (thd->options & OPTION_ANSI_MODE)
thd->client_capabilities|=CLIENT_IGNORE_SPACE;
@@ -180,9 +178,6 @@ check_connections1(THD *thd)
end+=4;
memcpy(end,thd->scramble,SCRAMBLE_LENGTH+1);
end+=SCRAMBLE_LENGTH +1;
-#ifdef HAVE_COMPRESS
- client_flags |= CLIENT_COMPRESS;
-#endif /* HAVE_COMPRESS */
int2store(end,client_flags);
end[2]=MY_CHARSET_CURRENT;
@@ -391,32 +386,34 @@ void embedded_srv_init(void)
/* 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_grant,MY_MUTEX_INIT_FAST);
+ (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_binlog_update, MY_MUTEX_INIT_FAST); // QQ NOT USED
+ (void) pthread_mutex_init(&LOCK_slave, MY_MUTEX_INIT_FAST);
+ (void) pthread_mutex_init(&LOCK_server_id, MY_MUTEX_INIT_FAST);
+ (void) pthread_mutex_init(&LOCK_user_conn, MY_MUTEX_INIT_FAST);
(void) pthread_cond_init(&COND_thread_count,NULL);
- (void) pthread_mutex_init(&LOCK_mysql_create_db,NULL);
- (void) pthread_mutex_init(&LOCK_Acl,NULL);
- (void) pthread_mutex_init(&LOCK_grant,NULL);
- (void) pthread_mutex_init(&LOCK_open,NULL);
- (void) pthread_mutex_init(&LOCK_thread_count,NULL);
- (void) pthread_mutex_init(&LOCK_mapped_file,NULL);
- (void) pthread_mutex_init(&LOCK_status,NULL);
- (void) pthread_mutex_init(&LOCK_error_log,NULL);
- (void) pthread_mutex_init(&LOCK_delayed_insert,NULL);
- (void) pthread_mutex_init(&LOCK_delayed_status,NULL);
- (void) pthread_mutex_init(&LOCK_delayed_create,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_mutex_init(&LOCK_manager,NULL);
- (void) pthread_mutex_init(&LOCK_crypt,NULL);
- (void) pthread_mutex_init(&LOCK_bytes_sent,NULL);
- (void) pthread_mutex_init(&LOCK_bytes_received,NULL);
- (void) pthread_mutex_init(&LOCK_timezone,NULL);
- (void) pthread_mutex_init(&LOCK_binlog_update, NULL);
- (void) pthread_mutex_init(&LOCK_slave, NULL);
- (void) pthread_mutex_init(&LOCK_server_id, NULL);
(void) pthread_cond_init(&COND_binlog_update, NULL);
(void) pthread_cond_init(&COND_slave_stopped, NULL);
+ (void) pthread_cond_init(&COND_slave_start, NULL);
if (set_default_charset_by_name(default_charset, MYF(MY_WME)))
unireg_abort(1);
diff --git a/libmysqld/lib_vio.c b/libmysqld/lib_vio.c
index a1cd8ca9565..3238fd59699 100644
--- a/libmysqld/lib_vio.c
+++ b/libmysqld/lib_vio.c
@@ -156,13 +156,13 @@ int vio_write(Vio * vio, const gptr buf, int size)
{
*vio->last_packet = packet;
vio->last_packet = (char **)packet;
- *((char **)packet) = 0; /* safety */
+ *((char **)packet) = 0; /* Set forward link to 0 */
packet += sizeof(char *);
int4store(packet, size);
memcpy(packet + 4, buf, size);
}
else
- size=0;
+ size= -1;
return (size);
}
diff --git a/libmysqld/libmysqld.c b/libmysqld/libmysqld.c
index a9def5c37ef..732c102c640 100644
--- a/libmysqld/libmysqld.c
+++ b/libmysqld/libmysqld.c
@@ -14,12 +14,13 @@
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA */
+
#define DONT_USE_RAID
+#include <global.h>
#if defined(__WIN__) || defined(_WIN32) || defined(_WIN64)
#include <winsock.h>
#include <odbcinst.h>
#endif
-#include <global.h>
#include <my_sys.h>
#include <mysys_err.h>
#include <m_string.h>
@@ -95,20 +96,9 @@ static sig_handler pipe_sig_handler(int sig);
static ulong mysql_sub_escape_string(CHARSET_INFO *charset_info, char *to,
const char *from, ulong length);
-/*
- Let the user specify that we don't want SIGPIPE; This doesn't however work
- with threaded applications as we can have multiple read in progress.
-*/
-
-#if !defined(__WIN__) && defined(SIGPIPE) && !defined(THREAD)
-#define init_sigpipe_variables sig_return old_signal_handler=(sig_return) 0;
-#define set_sigpipe(mysql) if ((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE) old_signal_handler=signal(SIGPIPE,pipe_sig_handler)
-#define reset_sigpipe(mysql) if ((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE) signal(SIGPIPE,old_signal_handler);
-#else
#define init_sigpipe_variables
#define set_sigpipe(mysql)
#define reset_sigpipe(mysql)
-#endif
#if 0
/****************************************************************************
@@ -212,78 +202,6 @@ static int connect2(my_socket s, const struct sockaddr *name, uint namelen,
}
#endif /* 0 */
-/*
-** Create a named pipe connection
-*/
-
-#ifdef __WIN__
-
-HANDLE create_named_pipe(NET *net, uint connect_timeout, char **arg_host,
- char **arg_unix_socket)
-{
- HANDLE hPipe=INVALID_HANDLE_VALUE;
- char szPipeName [ 257 ];
- DWORD dwMode;
- int i;
- my_bool testing_named_pipes=0;
- char *host= *arg_host, *unix_socket= *arg_unix_socket;
-
- if ( ! unix_socket || (unix_socket)[0] == 0x00)
- unix_socket = mysql_unix_port;
- if (!host || !strcmp(host,LOCAL_HOST))
- host=LOCAL_HOST_NAMEDPIPE;
-
- sprintf( szPipeName, "\\\\%s\\pipe\\%s", host, unix_socket);
- DBUG_PRINT("info",("Server name: '%s'. Named Pipe: %s",
- host, unix_socket));
-
- for (i=0 ; i < 100 ; i++) /* Don't retry forever */
- {
- if ((hPipe = CreateFile(szPipeName,
- GENERIC_READ | GENERIC_WRITE,
- 0,
- NULL,
- OPEN_EXISTING,
- 0,
- NULL )) != INVALID_HANDLE_VALUE)
- break;
- if (GetLastError() != ERROR_PIPE_BUSY)
- {
- net->last_errno=CR_NAMEDPIPEOPEN_ERROR;
- sprintf(net->last_error,ER(net->last_errno),host, unix_socket,
- (ulong) GetLastError());
- return INVALID_HANDLE_VALUE;
- }
- /* wait for for an other instance */
- if (! WaitNamedPipe(szPipeName, connect_timeout*1000) )
- {
- net->last_errno=CR_NAMEDPIPEWAIT_ERROR;
- sprintf(net->last_error,ER(net->last_errno),host, unix_socket,
- (ulong) GetLastError());
- return INVALID_HANDLE_VALUE;
- }
- }
- if (hPipe == INVALID_HANDLE_VALUE)
- {
- net->last_errno=CR_NAMEDPIPEOPEN_ERROR;
- sprintf(net->last_error,ER(net->last_errno),host, unix_socket,
- (ulong) GetLastError());
- return INVALID_HANDLE_VALUE;
- }
- dwMode = PIPE_READMODE_BYTE | PIPE_WAIT;
- if ( !SetNamedPipeHandleState(hPipe, &dwMode, NULL, NULL) )
- {
- CloseHandle( hPipe );
- net->last_errno=CR_NAMEDPIPESETSTATE_ERROR;
- sprintf(net->last_error,ER(net->last_errno),host, unix_socket,
- (ulong) GetLastError());
- return INVALID_HANDLE_VALUE;
- }
- *arg_host=host ; *arg_unix_socket=unix_socket; /* connect arg */
- return (hPipe);
-}
-#endif
-
/*****************************************************************************
** read a packet from server. Give error message if socket was down
@@ -1010,6 +928,7 @@ static void mysql_once_init()
embedded_srv_init();
init_client_errs();
mysql_port = MYSQL_PORT;
+ DEBUGGER_ON;
mysql_debug(NullS);
}
#ifdef THREAD
@@ -1052,7 +971,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
uint port, const char *unix_socket,uint client_flag)
{
char buff[100],charset_name_buff[16],*end,*host_info, *charset_name;
- my_socket sock;
uint pkt_length;
NET *net= &mysql->net;
DBUG_ENTER("mysql_real_connect");
@@ -1082,40 +1000,14 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
if (!passwd)
{
passwd=mysql->options.password;
-#ifndef DONT_USE_MYSQL_PWD
- if (!passwd)
- passwd=getenv("MYSQL_PWD"); /* get it from environment (haneke) */
-#endif
}
if (!db || !db[0])
db=mysql->options.db;
- if (!port)
- port=mysql->options.port;
- if (!unix_socket)
- unix_socket=mysql->options.unix_socket;
-
+ port=0;
+ unix_socket=0;
mysql->reconnect=1; /* Reconnect as default */
mysql->server_status=SERVER_STATUS_AUTOCOMMIT;
-
- /*
- ** Grab a socket and connect it to the server
- */
-
- unix_socket=0; /* This is not used */
- if (!port)
- port=mysql_port;
- if (!host)
- host=LOCAL_HOST;
- sprintf(host_info=buff,ER(CR_TCP_CONNECTION),host);
- DBUG_PRINT("info",("Server name: '%s'. TCP sock: %d", host,port));
- /* _WIN64 ; Assume that the (int) range is enough for socket() */
- if ((sock = (my_socket) socket(AF_INET,SOCK_STREAM,0)) == SOCKET_ERROR)
- {
- net->last_errno=CR_IPSOCK_ERROR;
- sprintf(net->last_error,ER(net->last_errno),ERRNO);
- goto error;
- }
-
+ host_info=(char*) ER(CR_EMBEDDED_CONNECTION);
if (my_net_init(net, net->vio))
{
vio_delete(net->vio);
@@ -1199,6 +1091,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
/* 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,
@@ -1228,14 +1121,9 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
/* Send client information for access check */
client_flag|=CLIENT_CAPABILITIES;
-
-
+ client_flag&= ~CLIENT_COMPRESS;
if (db)
client_flag|=CLIENT_CONNECT_WITH_DB;
-
- client_flag&= ~CLIENT_COMPRESS;
-
-
int2store(buff,client_flag);
mysql->client_flag=client_flag;
@@ -1251,7 +1139,8 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
DBUG_PRINT("info",("user: %s",buff+5));
end=scramble(strend(buff+5)+1, mysql->scramble_buff, passwd,
(my_bool) (mysql->protocol_version == 9));
- if (db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB))
+
+ if (db)
{
end=strmov(end+1,db);
mysql->db=my_strdup(db,MYF(MY_WME));
@@ -1264,8 +1153,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
if( net_safe_read(mysql) == packet_error)
goto error;
- if (client_flag & CLIENT_COMPRESS) /* We will use compression */
- net->compress=1;
if (db && mysql_select_db(mysql,db))
goto error;
if (mysql->options.init_command)
diff --git a/mysql-test/r/null_key.result b/mysql-test/r/null_key.result
index ead1dc29326..87ba8961ad6 100644
--- a/mysql-test/r/null_key.result
+++ b/mysql-test/r/null_key.result
@@ -53,7 +53,7 @@ t1 ref a,b a 5 const 1 where used
table type possible_keys key key_len ref rows Extra
t1 ALL NULL NULL NULL NULL 12 where used
table type possible_keys key key_len ref rows Extra
-t1 range a,b a 5 NULL 12 where used
+t1 range a,b a 5 NULL 5 where used
table type possible_keys key key_len ref rows Extra
t1 range a,b a 5 NULL 4 where used
table type possible_keys key key_len ref rows Extra
diff --git a/sql/net_serv.cc b/sql/net_serv.cc
index 44c082c1693..a5600dffa4c 100644
--- a/sql/net_serv.cc
+++ b/sql/net_serv.cc
@@ -42,6 +42,8 @@
#include <violite.h>
#include <assert.h>
+extern "C" {
+
#ifdef MYSQL_SERVER
ulong max_allowed_packet=65536;
extern ulong net_read_timeout,net_write_timeout;
@@ -824,3 +826,5 @@ my_net_read(NET *net)
#endif /* HAVE_COMPRESS */
return len;
}
+
+}
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 1dc6b22c6ac..b5edf084b53 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -827,9 +827,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
pos--;
packet_length--;
}
- *pos=0;
- if (!(thd->query= (char*) thd->memdup((gptr) (packet),packet_length)))
+ if (!(thd->query= (char*) thd->memdup((gptr) (packet),packet_length+1)))
break;
+ thd->query[packet_length]=0;
thd->packet.shrink(net_buffer_length); // Reclaim some memory
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),QUERY_PRIOR);
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 28e840dbac8..2f417fc2618 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -275,6 +275,8 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
join.having=0;
join.do_send_rows = 1;
join.group= group != 0;
+ join.row_limit= ((select_distinct || order || group) ? HA_POS_ERROR :
+ thd->select_limit);
#ifdef RESTRICTED_GROUP
if (join.sum_func_count && !group && (join.func_count || join.field_count))
@@ -812,7 +814,7 @@ err:
*****************************************************************************/
static ha_rows get_quick_record_count(SQL_SELECT *select,TABLE *table,
- key_map keys)
+ key_map keys,ha_rows limit)
{
int error;
DBUG_ENTER("get_quick_record_count");
@@ -820,7 +822,7 @@ static ha_rows get_quick_record_count(SQL_SELECT *select,TABLE *table,
{
select->head=table;
table->reginfo.impossible_range=0;
- if ((error=select->test_quick_select(keys,(table_map) 0,HA_POS_ERROR))
+ if ((error=select->test_quick_select(keys,(table_map) 0,limit))
== 1)
DBUG_RETURN(select->quick->records);
if (error == -1)
@@ -1032,7 +1034,8 @@ make_join_statistics(JOIN *join,TABLE_LIST *tables,COND *conds,
s->read_time=(ha_rows) s->table->file->scan_time();
/* Set a max range of how many seeks we can expect when using keys */
- s->worst_seeks= (double) (s->read_time*2);
+ /* This was (s->read_time*5), but this was too low with small rows */
+ s->worst_seeks= (double) s->found_records / 5;
if (s->worst_seeks < 2.0) // Fix for small tables
s->worst_seeks=2.0;
@@ -1045,7 +1048,8 @@ make_join_statistics(JOIN *join,TABLE_LIST *tables,COND *conds,
select=make_select(s->table,const_table_map,
0,
and_conds(conds,s->on_expr),&error);
- records=get_quick_record_count(select,s->table, s->const_keys);
+ records=get_quick_record_count(select,s->table, s->const_keys,
+ join->row_limit);
s->quick=select->quick;
s->needed_reg=select->needed_reg;
select->quick=0;
@@ -1732,7 +1736,7 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count,
{
/* we can use only index tree */
uint keys_per_block= table->file->block_size/2/
- keyinfo->key_length+1;
+ (keyinfo->key_length+table->file->ref_length)+1;
tmp=(record_count*(records+keys_per_block-1)/
keys_per_block);
}
@@ -1802,7 +1806,7 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count,
{
/* we can use only index tree */
uint keys_per_block= table->file->block_size/2/
- keyinfo->key_length+1;
+ (keyinfo->key_length+table->file->ref_length)+1;
tmp=record_count*(tmp+keys_per_block-1)/keys_per_block;
}
else
@@ -2215,6 +2219,7 @@ make_simple_join(JOIN *join,TABLE *tmp_table)
join->send_records=(ha_rows) 0;
join->group=0;
join->do_send_rows = 1;
+ join->row_limit=HA_POS_ERROR;
join_tab->cache.buff=0; /* No cacheing */
join_tab->table=tmp_table;
diff --git a/sql/sql_select.h b/sql/sql_select.h
index e4607b0e369..9539bb14842 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -152,7 +152,7 @@ class JOIN {
bool sort_and_group,first_record,full_join,group, no_field_update;
bool do_send_rows;
table_map const_table_map,outer_join;
- ha_rows send_records,found_records;
+ ha_rows send_records,found_records,examined_rows,row_limit;
POSITION positions[MAX_TABLES+1],best_positions[MAX_TABLES+1];
double best_read;
List<Item> *fields;