summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <monty@hundin.mysql.fi>2001-12-21 07:00:58 +0200
committerunknown <monty@hundin.mysql.fi>2001-12-21 07:00:58 +0200
commit9603291efdd930b1b7efb1534ba76569d517aac9 (patch)
tree14f15faabd0531594907bd3b9b9e4787da493d83
parent10863a359080d70a979bf0fc8bd88e7c51a6a2c2 (diff)
downloadmariadb-git-9603291efdd930b1b7efb1534ba76569d517aac9.tar.gz
Cleanup of alarm macros.
Fixed data corruption bug in query cache. Made queries be dependent of the database in use. Docs/manual.texi: Update binary log reference client/mysql.cc: Removed warning include/thr_alarm.h: Cleanup of alarm macros. libmysql/libmysql.c: Portabiliy fix libmysql/net.c: Cleanup of alarm macros. mysql-test/t/rpl_get_lock.test: Fixed results after merge. mysys/my_bitmap.c: Removed warning. sql/log_event.cc: Use thd->db_length sql/mini_client.cc: Cleanup of alarm macros. sql/net_serv.cc: Cleanup of alarm macros. sql/sql_acl.cc: Use thd->db_length sql/sql_cache.cc: Store used database together with the query. sql/sql_class.cc: Use thd->db_length sql/sql_class.h: Use thd->db_length sql/sql_db.cc: Use thd->db_length sql/sql_parse.cc: Use thd->db_length sql/sql_udf.cc: Use thd->db_length
-rw-r--r--Docs/manual.texi13
-rw-r--r--client/mysql.cc1
-rw-r--r--include/thr_alarm.h19
-rw-r--r--libmysql/libmysql.c8
-rw-r--r--libmysql/net.c67
-rw-r--r--mysql-test/t/rpl_get_lock.test3
-rw-r--r--mysys/my_bitmap.c2
-rw-r--r--sql/log_event.cc14
-rw-r--r--sql/mini_client.cc40
-rw-r--r--sql/net_serv.cc67
-rw-r--r--sql/sql_acl.cc6
-rw-r--r--sql/sql_cache.cc69
-rw-r--r--sql/sql_class.cc2
-rw-r--r--sql/sql_class.h8
-rw-r--r--sql/sql_db.cc7
-rw-r--r--sql/sql_parse.cc13
-rw-r--r--sql/sql_udf.cc3
17 files changed, 188 insertions, 154 deletions
diff --git a/Docs/manual.texi b/Docs/manual.texi
index cd44d842f3e..d3934061ec3 100644
--- a/Docs/manual.texi
+++ b/Docs/manual.texi
@@ -10200,7 +10200,7 @@ because it can't compile @code{.S} (assembler) files.
The following configure line should work:
@example
-CFLAGS="-DHPUX -I/opt/dce/include" CXXFLAGS="-DHPUX -I/opt/dce/include -felide-constructors -fno-exceptions -fno-rtti" CXX=gcc ./configure --with-pthread --with-named-thread-libs='-ldce' --prefix=/usr/local/mysql --disable-shared
+CFLAGS="-DHPUX -I/opt/dce/include -fpic" CXXFLAGS="-DHPUX -I/opt/dce/include -felide-constructors -fno-exceptions -fno-rtti" CXX=gcc ./configure --with-pthread --with-named-thread-libs='-ldce' --prefix=/usr/local/mysql --disable-shared
@end example
If you are compiling @code{gcc} 2.95 yourself, you should NOT link it with
@@ -22679,10 +22679,13 @@ file is written in the data directory.
If you supply an extension to @code{--log-bin=filename.extension}, the
extension will be silenty removed.
-To the binary log filename @code{mysqld} will append an extension that is a
-number that is incremented each time you execute @code{mysqladmin
-refresh}, execute @code{mysqladmin flush-logs}, execute the @code{FLUSH LOGS}
-statement or restart the server.
+To the binary log filename @code{mysqld} will append an extension that
+is a number that is incremented each time you execute @code{mysqladmin
+refresh}, execute @code{mysqladmin flush-logs}, execute the @code{FLUSH
+LOGS} statement or restart the server. A new binary log will also
+automaticly be created when it reaches @code{max_bin_log_size}. You can
+delete all not active binary log files with the @code{RESET MASTER}
+command. @xref{RESET}.
You can use the following options to @code{mysqld} to affect what is logged
to the binary log:
diff --git a/client/mysql.cc b/client/mysql.cc
index 27fc096ccaf..2f040a0596f 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -1717,7 +1717,6 @@ print_table_data_xml(MYSQL_RES *result)
(void) tee_fputs("\n <row>\n", PAGER);
for (uint i=0; i < mysql_num_fields(result); i++)
{
- char *data;
ulong *lengths=mysql_fetch_lengths(result);
tee_fprintf(PAGER, "\t<%s>", (fields[i].name ?
(fields[i].name[0] ? fields[i].name :
diff --git a/include/thr_alarm.h b/include/thr_alarm.h
index 48fad54444e..5caf552718c 100644
--- a/include/thr_alarm.h
+++ b/include/thr_alarm.h
@@ -38,24 +38,23 @@ extern "C" {
#define THR_SERVER_ALARM SIGALRM
#endif
-#if defined(DONT_USE_THR_ALARM)
+#if defined(DONT_USE_THR_ALARM) || !defined(THREAD)
#define USE_ALARM_THREAD
#undef USE_ONE_SIGNAL_HAND
-typedef struct st_thr_alarm_entry
-{
- uint crono;
-} thr_alarm_entry;
+typedef my_bool thr_alarm_t;
+typedef my_bool ALARM;
-#define thr_alarm_init(A) (A)->crono=0
-#define thr_alarm_in_use(A) (A)->crono
+#define thr_alarm_init(A) (*(A))=0
+#define thr_alarm_in_use(A) (*(A) != 0)
+#define thr_end_alarm(A)
+#define thr_alarm(A,B,C) ((*(A)=1)-1)
+/* The following should maybe be (*(A)) */
+#define thr_got_alarm(A) 0
#define init_thr_alarm(A)
#define thr_alarm_kill(A)
#define end_thr_alarm()
-#define thr_alarm(A,B) (((A)->crono=1)-1)
-#define thr_got_alarm(A) (A)->crono
-#define thr_end_alarm(A)
#else
#if defined(__WIN__)
diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c
index f1043787b6a..0e9a163a5b5 100644
--- a/libmysql/libmysql.c
+++ b/libmysql/libmysql.c
@@ -2225,8 +2225,8 @@ send_file_to_server(MYSQL *mysql, const char *filename)
my_net_write(&mysql->net,"",0); /* Server needs one packet */
net_flush(&mysql->net);
mysql->net.last_errno=EE_FILENOTFOUND;
- snprintf(mysql->net.last_error,sizeof(mysql->net.last_error)-1,
- EE(mysql->net.last_errno),tmp_name, errno);
+ my_snprintf(mysql->net.last_error,sizeof(mysql->net.last_error)-1,
+ EE(mysql->net.last_errno),tmp_name, errno);
goto err;
}
@@ -2250,8 +2250,8 @@ send_file_to_server(MYSQL *mysql, const char *filename)
if (readcount < 0)
{
mysql->net.last_errno=EE_READ; /* the errmsg for not entire file read */
- snprintf(mysql->net.last_error,sizeof(mysql->net.last_error)-1,
- tmp_name,errno);
+ my_snprintf(mysql->net.last_error,sizeof(mysql->net.last_error)-1,
+ tmp_name,errno);
goto err;
}
result=0; /* Ok */
diff --git a/libmysql/net.c b/libmysql/net.c
index 7eb4e0159a5..666c572ccee 100644
--- a/libmysql/net.c
+++ b/libmysql/net.c
@@ -41,68 +41,55 @@
#include <signal.h>
#include <errno.h>
+/*
+ The following handles the differences when this is linked between the
+ client and the server.
+
+ This gives an error if a too big packet is found
+ The server can change this with the -O switch, but because the client
+ can't normally do this the client should have a bigger max_allowed_packet.
+*/
+
#ifdef MYSQL_SERVER
ulong max_allowed_packet=65536;
extern ulong net_read_timeout,net_write_timeout;
extern uint test_flags;
#else
-
-/*
-** Give error if a too big packet is found
-** The server can change this with the -O switch, but because the client
-** can't normally do this the client should have a bigger max_allowed_packet.
-*/
-
-ulong max_allowed_packet=~0L;
+ulong max_allowed_packet=16*1024*1024L;
ulong net_read_timeout= NET_READ_TIMEOUT;
ulong net_write_timeout= NET_WRITE_TIMEOUT;
#endif
-ulong net_buffer_length=8192; /* Default length. Enlarged if necessary */
-#if defined(__WIN__) || defined(MSDOS)
-#undef MYSQL_SERVER /* Win32 can't handle interrupts */
+#ifdef __WIN__
+/* The following is because alarms doesn't work on windows. */
+#undef MYSQL_SERVER
#endif
+
#ifdef MYSQL_SERVER
#include "my_pthread.h"
-#include "thr_alarm.h"
void sql_print_error(const char *format,...);
#define RETRY_COUNT mysqld_net_retry_count
extern ulong mysqld_net_retry_count;
-#else
-
-#ifdef OS2 /* avoid name conflict */
-#define thr_alarm_t thr_alarm_t_net
-#define ALARM ALARM_net
-#endif
-
-typedef my_bool thr_alarm_t;
-typedef my_bool ALARM;
-#define thr_alarm_init(A) (*(A))=0
-#define thr_alarm_in_use(A) (*(A) != 0)
-#define thr_end_alarm(A)
-#define thr_alarm(A,B,C) local_thr_alarm((A),(B),(C))
-inline int local_thr_alarm(my_bool *A,int B __attribute__((unused)),ALARM *C __attribute__((unused)))
-{
- *A=1;
- return 0;
-}
-#define thr_got_alarm(A) 0
-#define RETRY_COUNT 1
-#endif
-
-#ifdef MYSQL_SERVER
extern ulong bytes_sent, bytes_received;
extern pthread_mutex_t LOCK_bytes_sent , LOCK_bytes_received;
+
extern void query_cache_insert(NET *net, const char *packet, ulong length);
#else
#undef statistic_add
#define statistic_add(A,B,C)
-#endif
+#define DONT_USE_THR_ALARM
+#define RETRY_COUNT 1
+#endif /* MYSQL_SERVER */
+
+#include "thr_alarm.h"
#define TEST_BLOCKING 8
+#define MAX_THREE_BYTES 255L*255L*255L
+
+ulong net_buffer_length=8192; /* Default length. Enlarged if necessary */
+
static int net_write_buff(NET *net,const char *packet,ulong len);
-#define MAX_THREE_BYTES 255L*255L*255L
/* Init with packet info */
@@ -335,7 +322,7 @@ net_real_write(NET *net,const char *packet,ulong len)
long int length;
char *pos,*end;
thr_alarm_t alarmed;
-#if !defined(__WIN__) && !defined(__EMX__) && !defined(OS2)
+#if defined(MYSQL_SERVER)
ALARM alarm_buff;
#endif
uint retry_count=0;
@@ -522,7 +509,7 @@ my_real_read(NET *net, ulong *complen)
uint i,retry_count=0;
ulong len=packet_error;
thr_alarm_t alarmed;
-#if (!defined(__WIN__) && !defined(__EMX__) && !defined(OS2)) || defined(MYSQL_SERVER)
+#if defined(MYSQL_SERVER)
ALARM alarm_buff;
#endif
my_bool net_blocking=vio_is_blocking(net->vio);
@@ -775,7 +762,7 @@ my_net_read(NET *net)
if (read_length != MAX_THREE_BYTES) /* last package */
{
- multi_byte_packet= 0; // No last zero length packet
+ multi_byte_packet= 0; /* No last zero len packet */
break;
}
multi_byte_packet= NET_HEADER_SIZE;
diff --git a/mysql-test/t/rpl_get_lock.test b/mysql-test/t/rpl_get_lock.test
index 3c33103e4c7..3fe45eecf46 100644
--- a/mysql-test/t/rpl_get_lock.test
+++ b/mysql-test/t/rpl_get_lock.test
@@ -6,6 +6,8 @@ dirty_close master;
connection master1;
select get_lock("lock",2);
select release_lock("lock");
+#ignore
+disable_query_log;
let $1=2000;
while ($1)
{
@@ -13,6 +15,7 @@ while ($1)
do release_lock("lock");
dec $1;
}
+enable_query_log;
save_master_pos;
connection slave;
sync_with_master;
diff --git a/mysys/my_bitmap.c b/mysys/my_bitmap.c
index 7fc094bdb71..8834dda98e1 100644
--- a/mysys/my_bitmap.c
+++ b/mysys/my_bitmap.c
@@ -25,7 +25,7 @@
#include "mysys_priv.h"
#include <my_bitmap.h>
#include <assert.h>
-#include <string.h>
+#include <m_string.h>
inline void bitmap_lock(MY_BITMAP* map)
{
diff --git a/sql/log_event.cc b/sql/log_event.cc
index ee975596f4b..f56837cb81a 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -1539,7 +1539,8 @@ int Query_log_event::exec_event(struct st_master_info* mi)
{
int expected_error,actual_error = 0;
init_sql_alloc(&thd->mem_root, 8192,0);
- thd->db = rewrite_db((char*)db);
+ thd->db= rewrite_db((char*)db);
+ thd->db_length=strlen(thd->db);
if (db_ok(thd->db, replicate_do_db, replicate_ignore_db))
{
thd->query = (char*)query;
@@ -1584,14 +1585,16 @@ int Query_log_event::exec_event(struct st_master_info* mi)
else
{
// master could be inconsistent, abort and tell DBA to check/fix it
- thd->db = thd->query = 0;
+ thd->db= thd->query= 0;
+ thd->db_length=0;
thd->convert_set = 0;
close_thread_tables(thd);
free_root(&thd->mem_root,0);
return 1;
}
}
- thd->db = 0; // prevent db from being freed
+ thd->db= 0; // prevent db from being freed
+ thd->db_length=0;
thd->query = 0; // just to be sure
// assume no convert for next query unless set explictly
thd->convert_set = 0;
@@ -1612,7 +1615,7 @@ int Query_log_event::exec_event(struct st_master_info* mi)
int Load_log_event::exec_event(NET* net, struct st_master_info* mi)
{
init_sql_alloc(&thd->mem_root, 8192,0);
- thd->db = rewrite_db((char*)db);
+ thd->db= rewrite_db((char*)db);
thd->query = 0;
thd->query_error = 0;
@@ -1685,7 +1688,8 @@ int Load_log_event::exec_event(NET* net, struct st_master_info* mi)
}
thd->net.vio = 0;
- thd->db = 0;// prevent db from being freed
+ thd->db= 0;// prevent db from being freed
+ thd->db_length=0;
close_thread_tables(thd);
if (thd->query_error)
{
diff --git a/sql/mini_client.cc b/sql/mini_client.cc
index 74073990d95..6bbbe653cdd 100644
--- a/sql/mini_client.cc
+++ b/sql/mini_client.cc
@@ -22,21 +22,15 @@
in case we decide to make them external at some point
*/
+#ifdef EMBEDDED_LIBRARY
+#define net_read_timeout net_read_timeout1
+#define net_write_timeout net_write_timeout1
+#endif
+
#if defined(__WIN__)
#include <winsock.h>
-#include <odbcinst.h>
-/* Disable alarms */
-typedef my_bool ALARM;
-#define thr_alarm_init(A) (*(A))=0
-#define thr_alarm_in_use(A) (*(A))
-#define thr_end_alarm(A)
-#define thr_alarm(A,B,C) local_thr_alarm((A),(B),(C))
-inline int local_thr_alarm(my_bool *A,int B __attribute__((unused)),ALARM *C __attribute__((unused)))
-{
- *A=1;
- return 0;
-}
-#define thr_got_alarm(A) 0
+#include <odbcinst.h> /* QQ: Is this really needed ? */
+#define DONT_USE_THR_ALARM
#endif
#include <my_global.h>
@@ -53,12 +47,7 @@ inline int local_thr_alarm(my_bool *A,int B __attribute__((unused)),ALARM *C __a
#include "mysqld_error.h"
#include "errmsg.h"
-#ifdef EMBEDDED_LIBRARY
-#define net_read_timeout net_read_timeout1
-#define net_write_timeout net_write_timeout1
-#endif
-
-#if defined( OS2) && defined( MYSQL_SERVER)
+#if defined( OS2) && defined(MYSQL_SERVER)
#undef ER
#define ER CER
#endif
@@ -82,18 +71,17 @@ extern "C" { // Because of SCO 3.2V4.2
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
-#endif
+#endif /*!defined(MSDOS) && !defined(__WIN__) */
#ifdef HAVE_SYS_UN_H
# include <sys/un.h>
#endif
#if defined(THREAD)
#include <my_pthread.h> /* because of signal() */
-#include <thr_alarm.h>
#endif
+#include <thr_alarm.h>
#ifndef INADDR_NONE
#define INADDR_NONE -1
#endif
-
}
static void mc_free_rows(MYSQL_DATA *cur);
@@ -1073,8 +1061,8 @@ static int mc_send_file_to_server(MYSQL *mysql, const char *filename)
my_net_write(&mysql->net,"",0); // Server needs one packet
net_flush(&mysql->net);
mysql->net.last_errno=EE_FILENOTFOUND;
- snprintf(mysql->net.last_error,sizeof(mysql->net.last_error)-1,
- EE(mysql->net.last_errno),tmp_name, errno);
+ my_snprintf(mysql->net.last_error,sizeof(mysql->net.last_error)-1,
+ EE(mysql->net.last_errno),tmp_name, errno);
goto err;
}
@@ -1098,8 +1086,8 @@ static int mc_send_file_to_server(MYSQL *mysql, const char *filename)
if (readcount < 0)
{
mysql->net.last_errno=EE_READ; /* the errmsg for not entire file read */
- snprintf(mysql->net.last_error,sizeof(mysql->net.last_error)-1,
- tmp_name,errno);
+ my_snprintf(mysql->net.last_error,sizeof(mysql->net.last_error)-1,
+ tmp_name,errno);
goto err;
}
result=0; // Ok
diff --git a/sql/net_serv.cc b/sql/net_serv.cc
index 7eb4e0159a5..666c572ccee 100644
--- a/sql/net_serv.cc
+++ b/sql/net_serv.cc
@@ -41,68 +41,55 @@
#include <signal.h>
#include <errno.h>
+/*
+ The following handles the differences when this is linked between the
+ client and the server.
+
+ This gives an error if a too big packet is found
+ The server can change this with the -O switch, but because the client
+ can't normally do this the client should have a bigger max_allowed_packet.
+*/
+
#ifdef MYSQL_SERVER
ulong max_allowed_packet=65536;
extern ulong net_read_timeout,net_write_timeout;
extern uint test_flags;
#else
-
-/*
-** Give error if a too big packet is found
-** The server can change this with the -O switch, but because the client
-** can't normally do this the client should have a bigger max_allowed_packet.
-*/
-
-ulong max_allowed_packet=~0L;
+ulong max_allowed_packet=16*1024*1024L;
ulong net_read_timeout= NET_READ_TIMEOUT;
ulong net_write_timeout= NET_WRITE_TIMEOUT;
#endif
-ulong net_buffer_length=8192; /* Default length. Enlarged if necessary */
-#if defined(__WIN__) || defined(MSDOS)
-#undef MYSQL_SERVER /* Win32 can't handle interrupts */
+#ifdef __WIN__
+/* The following is because alarms doesn't work on windows. */
+#undef MYSQL_SERVER
#endif
+
#ifdef MYSQL_SERVER
#include "my_pthread.h"
-#include "thr_alarm.h"
void sql_print_error(const char *format,...);
#define RETRY_COUNT mysqld_net_retry_count
extern ulong mysqld_net_retry_count;
-#else
-
-#ifdef OS2 /* avoid name conflict */
-#define thr_alarm_t thr_alarm_t_net
-#define ALARM ALARM_net
-#endif
-
-typedef my_bool thr_alarm_t;
-typedef my_bool ALARM;
-#define thr_alarm_init(A) (*(A))=0
-#define thr_alarm_in_use(A) (*(A) != 0)
-#define thr_end_alarm(A)
-#define thr_alarm(A,B,C) local_thr_alarm((A),(B),(C))
-inline int local_thr_alarm(my_bool *A,int B __attribute__((unused)),ALARM *C __attribute__((unused)))
-{
- *A=1;
- return 0;
-}
-#define thr_got_alarm(A) 0
-#define RETRY_COUNT 1
-#endif
-
-#ifdef MYSQL_SERVER
extern ulong bytes_sent, bytes_received;
extern pthread_mutex_t LOCK_bytes_sent , LOCK_bytes_received;
+
extern void query_cache_insert(NET *net, const char *packet, ulong length);
#else
#undef statistic_add
#define statistic_add(A,B,C)
-#endif
+#define DONT_USE_THR_ALARM
+#define RETRY_COUNT 1
+#endif /* MYSQL_SERVER */
+
+#include "thr_alarm.h"
#define TEST_BLOCKING 8
+#define MAX_THREE_BYTES 255L*255L*255L
+
+ulong net_buffer_length=8192; /* Default length. Enlarged if necessary */
+
static int net_write_buff(NET *net,const char *packet,ulong len);
-#define MAX_THREE_BYTES 255L*255L*255L
/* Init with packet info */
@@ -335,7 +322,7 @@ net_real_write(NET *net,const char *packet,ulong len)
long int length;
char *pos,*end;
thr_alarm_t alarmed;
-#if !defined(__WIN__) && !defined(__EMX__) && !defined(OS2)
+#if defined(MYSQL_SERVER)
ALARM alarm_buff;
#endif
uint retry_count=0;
@@ -522,7 +509,7 @@ my_real_read(NET *net, ulong *complen)
uint i,retry_count=0;
ulong len=packet_error;
thr_alarm_t alarmed;
-#if (!defined(__WIN__) && !defined(__EMX__) && !defined(OS2)) || defined(MYSQL_SERVER)
+#if defined(MYSQL_SERVER)
ALARM alarm_buff;
#endif
my_bool net_blocking=vio_is_blocking(net->vio);
@@ -775,7 +762,7 @@ my_net_read(NET *net)
if (read_length != MAX_THREE_BYTES) /* last package */
{
- multi_byte_packet= 0; // No last zero length packet
+ multi_byte_packet= 0; /* No last zero len packet */
break;
}
multi_byte_packet= NET_HEADER_SIZE;
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index 0d2568e8c5e..5da31df81ab 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -132,7 +132,8 @@ int acl_init(bool dont_read_acl_tables)
thd->mysys_var=my_thread_var;
thd->current_tablenr=0;
thd->open_tables=0;
- thd->db=my_strdup("mysql",MYF(0));
+ thd->db= my_strdup("mysql",MYF(0));
+ thd->db_length=5; // Safety
bzero((char*) &tables,sizeof(tables));
tables[0].name=tables[0].real_name=(char*) "host";
tables[1].name=tables[1].real_name=(char*) "user";
@@ -2120,7 +2121,8 @@ int grant_init (void)
thd->mysys_var=my_thread_var;
thd->current_tablenr=0;
thd->open_tables=0;
- thd->db=my_strdup("mysql",MYF(0));
+ thd->db= my_strdup("mysql",MYF(0));
+ thd->db_length=5; // Safety
bzero((char*) &tables,sizeof(tables));
tables[0].name=tables[0].real_name= (char*) "tables_priv";
tables[1].name=tables[1].real_name= (char*) "columns_priv";
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index 2674430312b..5051c9b775b 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -752,8 +752,20 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
/* Check if another thread is processing the same query? */
thd->query[thd->query_length] = (char) flags;
+ if (thd->db_length)
+ {
+ memcpy(thd->query+thd->query_length+1, thd->db, thd->db_length);
+ DBUG_PRINT("qcache", ("database : %s length %u",
+ thd->db, thd->db_length));
+ }
+ else
+ {
+ DBUG_PRINT("qcache", ("No active database"));
+ }
+
Query_cache_block *competitor = (Query_cache_block *)
- hash_search(&queries, (byte*) thd->query, thd->query_length+1);
+ hash_search(&queries, (byte*) thd->query,
+ thd->query_length+1+thd->db_length);
DBUG_PRINT("qcache", ("competitor 0x%lx, flags %x", (ulong) competitor,
flags));
if (competitor == 0)
@@ -761,7 +773,7 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
/* Query is not in cache and no one is working with it; Store it */
thd->query[thd->query_length] = (char) flags;
Query_cache_block *query_block;
- query_block= write_block_data(thd->query_length+1,
+ query_block= write_block_data(thd->query_length+1+thd->db_length,
(gptr) thd->query,
ALIGN_SIZE(sizeof(Query_cache_query)),
Query_cache_block::QUERY, tables, 1);
@@ -894,10 +906,21 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
flags |= (byte) thd->convert_set->number();
DBUG_ASSERT(thd->convert_set->number() < 128);
}
-
sql[query_length] = (char) flags;
+ if (thd->db_length)
+ {
+ memcpy(sql+query_length+1, thd->db, thd->db_length);
+ DBUG_PRINT("qcache", ("database : %s length %u",
+ thd->db, thd->db_length));
+ }
+ else
+ {
+ DBUG_PRINT("qcache", ("No active database"));
+ }
query_block = (Query_cache_block *) hash_search(&queries, (byte*) sql,
- query_length+1);
+ query_length+1+
+ thd->db_length);
+
sql[query_length] = '\0';
/* Quick abort on unlocked data */
@@ -2450,10 +2473,21 @@ my_bool Query_cache::move_by_type(byte **border,
Query_cache_block_table *nlist_root = new_block->table(0);
nlist_root->n = 0;
- nlist_root->next = (tnext == list_root ? nlist_root : tnext);
- nlist_root->prev = (tprev == list_root ? nlist_root: tnext);
- tnext->prev = nlist_root;
- tprev->next = nlist_root;
+ if (tnext == list_root)
+ {
+ nlist_root->next = nlist_root;
+ nlist_root->prev = nlist_root;
+ }
+ else
+ {
+ nlist_root->next = tnext;
+ tnext->prev = nlist_root;
+ }
+ if (tprev != list_root)
+ {
+ nlist_root->prev = tnext;
+ tprev->next = nlist_root;
+ }
for (;tnext != nlist_root; tnext=tnext->next)
tnext->parent = new_block->table();
*border += len;
@@ -2592,10 +2626,21 @@ void Query_cache::relink(Query_cache_block *oblock,
Query_cache_block *next, Query_cache_block *prev,
Query_cache_block *pnext, Query_cache_block *pprev)
{
- nblock->prev = (prev == oblock ? nblock : prev); //check pointer to himself
- nblock->next = (next == oblock ? nblock : next);
- prev->next=nblock;
- next->prev=nblock;
+ if (prev == oblock) //check pointer to himself
+ {
+ nblock->prev = nblock;
+ nblock->next = nblock;
+ }
+ else
+ {
+ nblock->prev = prev;
+ prev->next=nblock;
+ }
+ if (next != oblock)
+ {
+ nblock->next = next;
+ next->prev=nblock;
+ }
nblock->pprev = pprev; // Physical pointer to himself have only 1 free block
nblock->pnext = pnext;
pprev->pnext=nblock;
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 93db784b66d..f26b2dd6847 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -85,7 +85,7 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
host_or_ip="unknown ip";
locked=killed=count_cuted_fields=some_tables_deleted=no_errors=password=
query_start_used=safe_to_cache_query=0;
- query_length=col_access=0;
+ db_length=query_length=col_access=0;
query_error=0;
next_insert_id=last_insert_id=0;
open_tables=temporary_tables=handler_tables=0;
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 803c1df9dd9..1eac7843e96 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -288,6 +288,7 @@ public:
uint current_tablenr,tmp_table,cond_count,col_access;
uint server_status,open_options;
uint32 query_length;
+ uint32 db_length;
enum_tx_isolation tx_isolation, session_tx_isolation;
char scramble[9];
uint8 query_cache_type; // type of query cache processing
@@ -400,6 +401,13 @@ public:
{ return strmake_root(&mem_root,str,size); }
inline char *memdup(const char *str, uint size)
{ return memdup_root(&mem_root,str,size); }
+ inline char *memdup_w_gap(const char *str, uint size, uint gap)
+ {
+ gptr ptr;
+ if ((ptr=alloc_root(&mem_root,size+gap)))
+ memcpy(ptr,str,size);
+ return ptr;
+ }
};
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index b476a8b1797..dd8ed634011 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -317,19 +317,19 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
bool mysql_change_db(THD *thd,const char *name)
{
- int length;
+ int length, db_length;
char *dbname=my_strdup((char*) name,MYF(MY_WME));
char path[FN_REFLEN];
uint db_access;
DBUG_ENTER("mysql_change_db");
- if (!dbname || !(length=stripp_sp(dbname)))
+ if (!dbname || !(db_length=stripp_sp(dbname)))
{
x_free(dbname); /* purecov: inspected */
send_error(&thd->net,ER_NO_DB_ERROR); /* purecov: inspected */
DBUG_RETURN(1); /* purecov: inspected */
}
- if ((length > NAME_LEN) || check_db_name(dbname))
+ if ((db_length > NAME_LEN) || check_db_name(dbname))
{
net_printf(&thd->net,ER_WRONG_DB_NAME, dbname);
x_free(dbname);
@@ -369,6 +369,7 @@ bool mysql_change_db(THD *thd,const char *name)
send_ok(&thd->net);
x_free(thd->db);
thd->db=dbname;
+ thd->db_length=db_length;
thd->db_access=db_access;
DBUG_RETURN(0);
}
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index f7c522ba782..e61bb83ee29 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -127,6 +127,7 @@ static bool check_user(THD *thd,enum_server_command command, const char *user,
{
NET *net= &thd->net;
thd->db=0;
+ thd->db_length=0;
if (!(thd->user = my_strdup(user, MYF(0))))
{
@@ -632,7 +633,8 @@ pthread_handler_decl(handle_bootstrap,arg)
buff[length]=0;
thd->current_tablenr=0;
thd->query_length=length;
- thd->query= thd->memdup(buff,length+1);
+ thd->query= thd->memdup_w_gap(buff, length+1, thd->db_length+1);
+ thd->query[length] = '\0';
thd->query_id=query_id++;
mysql_parse(thd,thd->query,length);
close_thread_tables(thd); // Free tables
@@ -807,6 +809,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
/* Save user and privileges */
uint save_master_access=thd->master_access;
uint save_db_access= thd->db_access;
+ uint save_db_length= thd->db_length;
char *save_user= thd->user;
char *save_priv_user= thd->priv_user;
char *save_db= thd->db;
@@ -823,6 +826,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
thd->master_access=save_master_access;
thd->db_access=save_db_access;
thd->db=save_db;
+ thd->db_length=save_db_length;
thd->user=save_user;
thd->priv_user=save_priv_user;
break;
@@ -844,7 +848,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
packet_length--;
}
thd->query_length= packet_length;
- if (!(thd->query= (char*) thd->memdup((gptr) (packet),packet_length+1)))
+ if (!(thd->query= (char*) thd->memdup_w_gap((gptr) (packet),
+ packet_length+1,
+ thd->db_length+1)))
break;
thd->query[packet_length]=0;
thd->packet.shrink(net_buffer_length); // Reclaim some memory
@@ -876,6 +882,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
thd->free_list=0;
table_list.name=table_list.real_name=thd->strdup(packet);
packet=strend(packet)+1;
+ // command not cachable => no gap for data base name
if (!(thd->query=fields=thd->memdup(packet,thd->query_length+1)))
break;
mysql_log.write(thd,command,"%s %s",table_list.real_name,fields);
@@ -1117,7 +1124,7 @@ mysql_execute_command(void)
if (lex->sql_command == SQLCOM_SELECT)
{
lex->sql_command = SQLCOM_DO;
- lex->insert_list = &lex->item_list;
+ lex->insert_list = &select_lex->item_list;
}
#endif
}
diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc
index 3ee4b9ff37e..9493f969802 100644
--- a/sql/sql_udf.cc
+++ b/sql/sql_udf.cc
@@ -139,7 +139,8 @@ void udf_init()
new_thd->version = refresh_version; //current_thd->version;
new_thd->current_tablenr = 0;
new_thd->open_tables = 0;
- new_thd->db = my_strdup("mysql", MYF(0));
+ new_thd->db= my_strdup("mysql", MYF(0));
+ new_thd->db_length=5;
bzero((gptr) &tables,sizeof(tables));
tables.name = tables.real_name = (char*) "func";