summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/ha_innobase.cc6
-rw-r--r--sql/log_event.cc2
-rw-r--r--sql/mysqld.cc74
-rw-r--r--sql/slave.cc8
-rw-r--r--sql/sql_cache.cc59
-rw-r--r--sql/sql_cache.h4
-rw-r--r--sql/sql_parse.cc5
7 files changed, 107 insertions, 51 deletions
diff --git a/sql/ha_innobase.cc b/sql/ha_innobase.cc
index fb22b2d079c..8dd2e49e093 100644
--- a/sql/ha_innobase.cc
+++ b/sql/ha_innobase.cc
@@ -536,7 +536,7 @@ innobase_init(void)
{
int err;
bool ret;
- char current_lib[2], *default_path;
+ char current_lib[3], *default_path;
DBUG_ENTER("innobase_init");
@@ -2044,7 +2044,7 @@ ha_innobase::change_active_index(
else
prebuilt->index = dict_table_get_first_index_noninline(prebuilt->table);
- assert(prebuilt->search_tuple);
+ assert(prebuilt->search_tuple != 0);
dtuple_set_n_fields(prebuilt->search_tuple, prebuilt->index->n_fields);
@@ -2762,7 +2762,7 @@ ha_innobase::create(
innobase_table = dict_table_get(norm_name, NULL);
- assert(innobase_table);
+ assert(innobase_table != 0);
/* Tell the InnoDB server that there might be work for
utility threads: */
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 3552a4264c9..ee975596f4b 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -140,7 +140,7 @@ static void cleanup_load_tmpdir()
for (i=0;i<(uint)dirp->number_off_files;i++)
{
file=dirp->dir_entry+i;
- if (!memcmp(file->name,"SQL_LOAD-",9))
+ if (!bcmp(file->name,"SQL_LOAD-",9))
my_delete(file->name,MYF(MY_WME));
}
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 1294f379d2b..60dd45bc1f2 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -114,8 +114,13 @@ typedef fp_except fp_except_t;
inline void reset_floating_point_exceptions()
{
/* Don't fall for overflow, underflow,divide-by-zero or loss of precision */
- fpsetmask(~(FP_X_INV | FP_X_DNML | FP_X_OFL | FP_X_UFL |
- FP_X_DZ | FP_X_IMP));
+#if defined(__i386__)
+ fpsetmask(~(FP_X_INV | FP_X_DNML | FP_X_OFL | FP_X_UFL | FP_X_DZ |
+ FP_X_IMP));
+else
+ fpsetmask(~(FP_X_INV | FP_X_OFL | FP_X_UFL | FP_X_DZ |
+ FP_X_IMP));
+#endif
}
#else
#define reset_floating_point_exceptions()
@@ -390,6 +395,7 @@ static void get_options(int argc,char **argv);
static char *get_relative_path(const char *path);
static void fix_paths(void);
static pthread_handler_decl(handle_connections_sockets,arg);
+static pthread_handler_decl(kill_server_thread,arg);
static int bootstrap(FILE *file);
static void close_server_sock();
static bool read_init_file(char *file_name);
@@ -625,19 +631,26 @@ void kill_mysql(void)
#elif defined(OS2)
pthread_cond_signal( &eventShutdown); // post semaphore
#elif defined(HAVE_PTHREAD_KILL)
- if (pthread_kill(signal_thread,SIGTERM)) /* End everything nicely */
- {
- DBUG_PRINT("error",("Got error %d from pthread_kill",errno)); /* purecov: inspected */
- }
-#else
- kill(current_pid,SIGTERM);
+ if (pthread_kill(signal_thread,SIGTERM)) /* End everything nicely */
+ {
+ DBUG_PRINT("error",("Got error %d from pthread_kill",errno)); /* purecov: inspected */
+ }
+#elif !defined(SIGNALS_DONT_BREAK_READ)
+ kill(current_pid,SIGTERM);
#endif
- DBUG_PRINT("quit",("After pthread_kill"));
- shutdown_in_progress=1; // Safety if kill didn't work
-#ifdef SIGNALS_DONT_BREAK_READ
+ DBUG_PRINT("quit",("After pthread_kill"));
+ shutdown_in_progress=1; // Safety if kill didn't work
+#ifdef SIGNALS_DONT_BREAK_READ
+ if (!abort_loop)
+ {
+ pthread_t tmp;
abort_loop=1;
+ if (pthread_create(&tmp,&connection_attrib, kill_server_thread,
+ (void*) 0))
+ sql_print_error("Error: Can't create thread to kill server");
+ }
#endif
- DBUG_VOID_RETURN;
+ DBUG_VOID_RETURN;
}
@@ -682,7 +695,7 @@ static void __cdecl kill_server(int sig_ptr)
#ifdef USE_ONE_SIGNAL_HAND
-pthread_handler_decl(kill_server_thread,arg __attribute__((unused)))
+static pthread_handler_decl(kill_server_thread,arg __attribute__((unused)))
{
my_thread_init(); // Initialize new thread
kill_server(0);
@@ -1474,7 +1487,7 @@ static void *signal_hand(void *arg __attribute__((unused)))
(void*) sig))
sql_print_error("Error: Can't create thread to kill server");
#else
- kill_server((void*) sig); // MIT THREAD has a alarm thread
+ kill_server((void*) sig); // MIT THREAD has a alarm thread
#endif
}
break;
@@ -2452,18 +2465,21 @@ pthread_handler_decl(handle_connections_sockets,arg __attribute__((unused)))
fromhost(&req);
if (!hosts_access(&req))
{
- // This may be stupid but refuse() includes an exit(0)
- // which we surely don't want...
- // clean_exit() - same stupid thing ...
+ /*
+ This may be stupid but refuse() includes an exit(0)
+ which we surely don't want...
+ clean_exit() - same stupid thing ...
+ */
syslog(deny_severity, "refused connect from %s", eval_client(&req));
if (req.sink)
((void (*)(int))req.sink)(req.fd);
- // C++ sucks (the gibberish in front just translates the supplied
- // sink function pointer in the req structure from a void (*sink)();
- // to a void(*sink)(int) if you omit the cast, the C++ compiler
- // will cry...
-
+ /*
+ C++ sucks (the gibberish in front just translates the supplied
+ sink function pointer in the req structure from a void (*sink)();
+ to a void(*sink)(int) if you omit the cast, the C++ compiler
+ will cry...
+ */
(void) shutdown(new_sock,2); // This looks fine to me...
(void) closesocket(new_sock);
continue;
@@ -2491,7 +2507,8 @@ pthread_handler_decl(handle_connections_sockets,arg __attribute__((unused)))
if (!(thd= new THD))
{
- (void) shutdown(new_sock,2); VOID(closesocket(new_sock));
+ (void) shutdown(new_sock,2);
+ VOID(closesocket(new_sock));
continue;
}
if (!(vio_tmp=vio_new(new_sock,
@@ -3158,7 +3175,7 @@ struct show_var_st status_vars[]= {
{"Com_drop_table", (char*) (com_stat+(uint) SQLCOM_DROP_TABLE),SHOW_LONG},
{"Com_flush", (char*) (com_stat+(uint) SQLCOM_FLUSH),SHOW_LONG},
{"Com_grant", (char*) (com_stat+(uint) SQLCOM_GRANT),SHOW_LONG},
- {"Com_ha_close", (char*) (com_stat+(uint) SQLCOM_HA_OPEN),SHOW_LONG},
+ {"Com_ha_close", (char*) (com_stat+(uint) SQLCOM_HA_CLOSE),SHOW_LONG},
{"Com_ha_open", (char*) (com_stat+(uint) SQLCOM_HA_OPEN),SHOW_LONG},
{"Com_ha_read", (char*) (com_stat+(uint) SQLCOM_HA_READ),SHOW_LONG},
{"Com_insert", (char*) (com_stat+(uint) SQLCOM_INSERT),SHOW_LONG},
@@ -4283,16 +4300,17 @@ static uint set_maximum_open_files(uint max_file_limit)
rlimit.rlim_cur=rlimit.rlim_max=max_file_limit;
if (setrlimit(RLIMIT_NOFILE,&rlimit))
{
- sql_print_error("Warning: setrlimit couldn't increase number of open files to more than %ld",
- old_cur); /* purecov: inspected */
+ sql_print_error("Warning: setrlimit couldn't increase number of open files to more than %lu (request: %u)",
+ old_cur, max_file_limit); /* purecov: inspected */
max_file_limit=old_cur;
}
else
{
(void) getrlimit(RLIMIT_NOFILE,&rlimit);
if ((uint) rlimit.rlim_cur != max_file_limit)
- sql_print_error("Warning: setrlimit returned ok, but didn't change limits. Max open files is %ld",
- (ulong) rlimit.rlim_cur); /* purecov: inspected */
+ sql_print_error("Warning: setrlimit returned ok, but didn't change limits. Max open files is %ld (request: %u)",
+ (ulong) rlimit.rlim_cur,
+ max_file_limit); /* purecov: inspected */
max_file_limit=rlimit.rlim_cur;
}
}
diff --git a/sql/slave.cc b/sql/slave.cc
index 45d4a33031a..33c4273bcb0 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -766,9 +766,7 @@ int show_master_info(THD* thd)
net_store_data(packet, (longlong) glob_mi.pos);
last_log_seq = glob_mi.last_log_seq;
pthread_mutex_unlock(&glob_mi.lock);
- pthread_mutex_lock(&LOCK_slave); // QQ; This is not needed
net_store_data(packet, slave_running ? "Yes":"No");
- pthread_mutex_unlock(&LOCK_slave); // QQ; This is not needed
net_store_data(packet, &replicate_do_db);
net_store_data(packet, &replicate_ignore_db);
net_store_data(packet, (uint32)last_slave_errno);
@@ -1099,6 +1097,8 @@ slave_begin:
THD *thd; // needs to be first for thread_stack
MYSQL *mysql = NULL ;
char llbuff[22];
+ bool retried_once = 0;
+ ulonglong last_failed_pos = 0;
pthread_mutex_lock(&LOCK_slave);
if (!server_id)
@@ -1123,10 +1123,6 @@ slave_begin:
pthread_cond_broadcast(&COND_slave_start);
pthread_mutex_unlock(&LOCK_slave);
- // int error = 1;
- bool retried_once = 0;
- ulonglong last_failed_pos = 0;
-
// needs to call my_thread_init(), otherwise we get a coredump in DBUG_ stuff
my_thread_init();
slave_thd = thd = new THD; // note that contructor of THD uses DBUG_ !
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index 387bca35d08..c4dc56620d8 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -1951,11 +1951,35 @@ Query_cache::get_free_block(ulong len, my_bool not_less, ulong min)
if (bins[start].number != 0)
{
Query_cache_block *list = bins[start].free_blocks;
- first = list;
- while (first->next != list && first->length < len)
- first=first->next;
- if (first->length >= len)
- block=first;
+ ulong max_len = list->prev->length;
+ if (list->prev->length >= len) // check block with max size
+ {
+ first = list;
+ uint n = 0;
+ while ( n < QUERY_CACHE_MEM_BIN_TRY &&
+ first->length < len) //we don't need irst->next != list
+ {
+ first=first->next;
+ n++;
+ }
+ if (first->length >= len)
+ block=first;
+ else // we don't need if (first->next != list)
+ {
+ n = 0;
+ block = list->prev;
+ while (n < QUERY_CACHE_MEM_BIN_TRY &&
+ block->length > len)
+ {
+ block=block->prev;
+ n++;
+ }
+ if(block->length < len)
+ block=block->next;
+ }
+ }
+ else
+ first = list->prev;
}
if (block == 0 && start > 0)
{
@@ -2117,18 +2141,28 @@ void Query_cache::insert_into_free_memory_list(Query_cache_block *free_block)
uint Query_cache::find_bin(ulong size)
{
- int i;
DBUG_ENTER("Query_cache::find_bin");
- // Begin small blocks to big (small blocks frequently asked)
- for (i=mem_bin_steps - 1; i > 0 && steps[i-1].size < size; i--) ;
- if (i == 0)
+ // Binary search
+ int left = 0, right = mem_bin_steps;
+ do
+ {
+ int middle = (left + right) / 2;
+ if (steps[middle].size > size)
+ left = middle+1;
+ else
+ right = middle;
+ } while (left < right);
+ if (left == 0)
{
// first bin not subordinate of common rules
DBUG_PRINT("qcache", ("first bin (# 0), size %lu",size));
DBUG_RETURN(0);
}
- uint bin = steps[i].idx - (uint)((size - steps[i].size)/steps[i].increment);
- DBUG_PRINT("qcache", ("bin %u step %u, size %lu", bin, i, size));
+ uint bin = steps[left].idx -
+ (uint)((size - steps[left].size)/steps[left].increment);
+ bins_dump();
+ DBUG_PRINT("qcache", ("bin %u step %u, size %lu step size %lu",
+ bin, left, size, steps[left].size));
DBUG_RETURN(bin);
}
@@ -2480,6 +2514,9 @@ my_bool Query_cache::move_by_type(byte **border,
result_block = result_block->next;
} while ( result_block != first_result_block );
}
+ Query_cache_query *new_query= ((Query_cache_query *) new_block->data());
+ pthread_cond_init(&new_query->lock, NULL);
+ pthread_mutex_init(&new_query->clients_guard,MY_MUTEX_INIT_FAST);
NET *net = new_block->query()->writer();
if (net != 0)
{
diff --git a/sql/sql_cache.h b/sql/sql_cache.h
index da7ada14f23..6f8d9bb6dbf 100644
--- a/sql/sql_cache.h
+++ b/sql/sql_cache.h
@@ -41,6 +41,10 @@
#define QUERY_CACHE_MEM_BIN_PARTS_MUL 1.2
#define QUERY_CACHE_MEM_BIN_SPC_LIM_PWR2 3
+/* how many free blocks check when finding most suitable before other 'end'
+ of list of free blocks */
+#define QUERY_CACHE_MEM_BIN_TRY 5
+
/* query flags masks */
#define QUERY_CACHE_CLIENT_LONG_FLAG_MASK 0x80
#define QUERY_CACHE_CHARSET_CONVERT_MASK 0x7F
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index c044d17f0a9..215a6723db9 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -875,8 +875,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
}
thd->free_list=0;
table_list.name=table_list.real_name=thd->strdup(packet);
- thd->query=fields=thd->strdup(strend(packet)+1);
- thd->query_length=strlen(thd->query);
+ packet=strend(packet)+1;
+ if (!(thd->query=fields=thd->memdup(packet,thd->query_length+1)))
+ break;
mysql_log.write(thd,command,"%s %s",table_list.real_name,fields);
remove_escape(table_list.real_name); // This can't have wildcards