summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc22
-rw-r--r--sql/ha_innodb.cc30
-rw-r--r--sql/handler.cc4
-rw-r--r--sql/log.cc70
-rw-r--r--sql/mysql_priv.h5
-rw-r--r--sql/mysqld.cc18
-rw-r--r--sql/set_var.cc19
-rw-r--r--sql/set_var.h16
-rw-r--r--sql/sql_class.cc3
-rw-r--r--sql/sql_select.cc10
-rw-r--r--sql/sql_select.h3
-rw-r--r--sql/sql_table.cc9
-rw-r--r--sql/sql_udf.cc2
-rw-r--r--sql/sql_update.cc18
14 files changed, 131 insertions, 98 deletions
diff --git a/sql/field.cc b/sql/field.cc
index e631ade16b1..afd594b7045 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -1491,12 +1491,14 @@ void Field_medium::sql_type(String &res) const
void Field_long::store(const char *from,uint len)
{
+ char *end;
while (len && isspace(*from))
{
len--; from++;
}
long tmp;
String tmp_str(from,len);
+ from= tmp_str.c_ptr(); // Add end null if needed
errno=0;
if (unsigned_flag)
{
@@ -1506,11 +1508,13 @@ void Field_long::store(const char *from,uint len)
errno=ERANGE;
}
else
- tmp=(long) strtoul(tmp_str.c_ptr(),NULL,10);
+ tmp=(long) strtoul(from, &end, 10);
}
else
- tmp=strtol(tmp_str.c_ptr(),NULL,10);
- if (errno || current_thd->count_cuted_fields && !test_if_int(from,len))
+ tmp=strtol(from, &end, 10);
+ if (errno ||
+ (from+len != end && current_thd->count_cuted_fields &&
+ !test_if_int(from,len)))
current_thd->cuted_fields++;
#ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first)
@@ -1719,12 +1723,14 @@ void Field_long::sql_type(String &res) const
void Field_longlong::store(const char *from,uint len)
{
+ char *end;
while (len && isspace(*from))
{ // For easy error check
len--; from++;
}
longlong tmp;
String tmp_str(from,len);
+ from= tmp_str.c_ptr(); // Add end null if needed
errno=0;
if (unsigned_flag)
{
@@ -1734,12 +1740,14 @@ void Field_longlong::store(const char *from,uint len)
errno=ERANGE;
}
else
- tmp=(longlong) strtoull(tmp_str.c_ptr(),NULL,10);
+ tmp=(longlong) strtoull(from, &end, 10);
}
else
- tmp=strtoll(tmp_str.c_ptr(),NULL,10);
- if (errno || current_thd->count_cuted_fields && !test_if_int(from,len))
- current_thd->cuted_fields++;
+ tmp=strtoll(from, &end, 10);
+ if (errno ||
+ (from+len != end && current_thd->count_cuted_fields &&
+ !test_if_int(from,len)))
+ current_thd->cuted_fields++;
#ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first)
{
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index 343b8477d38..2868011c443 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -674,36 +674,6 @@ innobase_init(void)
/* Set InnoDB initialization parameters according to the values
read from MySQL .cnf file */
- /* --------------------------------------------------*/
- /* Make copies of all string-valued parameters, because after
- C# calls server_init(), it may move the parameter strings around */
-
- if (innobase_data_home_dir) {
- innobase_data_home_dir = my_strdup(
- innobase_data_home_dir,
- MYF(MY_WME));
- }
- if (innobase_data_file_path) {
- innobase_data_file_path = my_strdup(
- innobase_data_file_path,
- MYF(MY_WME));
- }
- if (innobase_log_group_home_dir) {
- innobase_log_group_home_dir = my_strdup(
- innobase_log_group_home_dir,
- MYF(MY_WME));
- }
- if (innobase_log_arch_dir) {
- innobase_log_arch_dir = my_strdup(
- innobase_log_arch_dir,
- MYF(MY_WME));
- }
- if (innobase_unix_file_flush_method) {
- innobase_unix_file_flush_method = my_strdup(
- innobase_unix_file_flush_method,
- MYF(MY_WME));
- }
-
/*--------------- Data files -------------------------*/
/* The default dir for data files is the datadir of MySQL */
diff --git a/sql/handler.cc b/sql/handler.cc
index c4e742ef519..d4fd45613d4 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -883,13 +883,13 @@ int ha_create_table(const char *name, HA_CREATE_INFO *create_info,
void ha_key_cache(void)
{
if (keybuff_size)
- (void) init_key_cache(keybuff_size);
+ (void) init_key_cache((ulong) keybuff_size);
}
void ha_resize_key_cache(void)
{
- (void) resize_key_cache(keybuff_size);
+ (void) resize_key_cache((ulong) keybuff_size);
}
diff --git a/sql/log.cc b/sql/log.cc
index 597985e8796..32dbdac1074 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -1053,40 +1053,44 @@ bool MYSQL_LOG::write(Log_event* event_info)
No check for auto events flag here - this write method should
never be called if auto-events are enabled
*/
- if (thd && thd->last_insert_id_used)
+ if (thd)
{
- Intvar_log_event e(thd,(uchar)LAST_INSERT_ID_EVENT,thd->last_insert_id);
- e.set_log_pos(this);
- if (thd->server_id)
- e.server_id = thd->server_id;
- if (e.write(file))
- goto err;
- }
- if (thd && thd->insert_id_used)
- {
- Intvar_log_event e(thd,(uchar)INSERT_ID_EVENT,thd->last_insert_id);
- e.set_log_pos(this);
- if (thd->server_id)
- e.server_id = thd->server_id;
- if (e.write(file))
- goto err;
- }
- if (thd && thd->rand_used)
- {
- Rand_log_event e(thd,thd->rand_saved_seed1,thd->rand_saved_seed2);
- e.set_log_pos(this);
- if (e.write(file))
- goto err;
- }
- if (thd && thd->variables.convert_set)
- {
- char buf[1024] = "SET CHARACTER SET ";
- char* p = strend(buf);
- p = strmov(p, thd->variables.convert_set->name);
- Query_log_event e(thd, buf, (ulong)(p - buf), 0);
- e.set_log_pos(this);
- if (e.write(file))
- goto err;
+ if (thd->last_insert_id_used)
+ {
+ Intvar_log_event e(thd,(uchar) LAST_INSERT_ID_EVENT,
+ thd->last_insert_id);
+ e.set_log_pos(this);
+ if (thd->server_id)
+ e.server_id = thd->server_id;
+ if (e.write(file))
+ goto err;
+ }
+ if (thd->insert_id_used)
+ {
+ Intvar_log_event e(thd,(uchar) INSERT_ID_EVENT,thd->last_insert_id);
+ e.set_log_pos(this);
+ if (thd->server_id)
+ e.server_id = thd->server_id;
+ if (e.write(file))
+ goto err;
+ }
+ if (thd->rand_used)
+ {
+ Rand_log_event e(thd,thd->rand_saved_seed1,thd->rand_saved_seed2);
+ e.set_log_pos(this);
+ if (e.write(file))
+ goto err;
+ }
+ if (thd->variables.convert_set)
+ {
+ char buf[256], *p;
+ p= strmov(strmov(buf, "SET CHARACTER SET "),
+ thd->variables.convert_set->name);
+ Query_log_event e(thd, buf, (ulong) (p - buf), 0);
+ e.set_log_pos(this);
+ if (e.write(file))
+ goto err;
+ }
}
event_info->set_log_pos(this);
if (event_info->write(file) ||
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 7cfbd84a99d..3cf6bb2c1a5 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -625,6 +625,7 @@ extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN];
extern char pidfile_name[FN_REFLEN], time_zone[30], *opt_init_file;
extern char blob_newline;
extern double log_10[32];
+extern ulonglong keybuff_size;
extern ulong refresh_version,flush_version, thread_id,query_id,opened_tables;
extern ulong created_tmp_tables, created_tmp_disk_tables;
extern ulong aborted_threads,aborted_connects;
@@ -643,8 +644,7 @@ extern ulong ha_read_count, ha_write_count, ha_delete_count, ha_update_count;
extern ulong ha_read_key_count, ha_read_next_count, ha_read_prev_count;
extern ulong ha_read_first_count, ha_read_last_count;
extern ulong ha_read_rnd_count, ha_read_rnd_next_count;
-extern ulong ha_commit_count, ha_rollback_count;
-extern ulong keybuff_size,table_cache_size;
+extern ulong ha_commit_count, ha_rollback_count,table_cache_size;
extern ulong max_connections,max_connect_errors, connect_timeout;
extern ulong max_insert_delayed_threads, max_user_connections;
extern ulong long_query_count, what_to_log,flush_time,opt_sql_mode;
@@ -689,6 +689,7 @@ extern String empty_string;
extern SHOW_VAR init_vars[],status_vars[], internal_vars[];
extern struct system_variables global_system_variables;
extern struct system_variables max_system_variables;
+extern struct rand_struct sql_rand;
/* optional things, have_* variables */
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index a65cbd1139d..2c15b21ac7d 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -32,6 +32,7 @@
#include <nisam.h>
#include <thr_alarm.h>
#include <ft_global.h>
+#include <assert.h>
#ifndef DBUG_OFF
#define ONE_THREAD
@@ -317,7 +318,8 @@ ulong thd_startup_options=(OPTION_UPDATE_LOG | OPTION_AUTO_IS_NULL |
uint protocol_version=PROTOCOL_VERSION;
struct system_variables global_system_variables;
struct system_variables max_system_variables;
-ulong keybuff_size,table_cache_size,
+ulonglong keybuff_size;
+ulong table_cache_size,
thread_stack,
thread_stack_min,what_to_log= ~ (1L << (uint) COM_TIME),
query_buff_size,
@@ -1371,7 +1373,7 @@ or misconfigured. This error can also be caused by malfunctioning hardware.\n",
We will try our best to scrape up some info that will hopefully help diagnose\n\
the problem, but since we have already crashed, something is definitely wrong\n\
and this may fail.\n\n");
- fprintf(stderr, "key_buffer_size=%ld\n", keybuff_size);
+ fprintf(stderr, "key_buffer_size=%lu\n", (ulong) keybuff_size);
fprintf(stderr, "read_buffer_size=%ld\n", global_system_variables.read_buff_size);
fprintf(stderr, "sort_buffer_size=%ld\n", thd->variables.sortbuff_size);
fprintf(stderr, "max_used_connections=%ld\n", max_used_connections);
@@ -1379,8 +1381,9 @@ and this may fail.\n\n");
fprintf(stderr, "threads_connected=%d\n", thread_count);
fprintf(stderr, "It is possible that mysqld could use up to \n\
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections = %ld K\n\
-bytes of memory\n", (keybuff_size + (global_system_variables.read_buff_size +
- thd->variables.sortbuff_size) *
+bytes of memory\n", ((ulong) keybuff_size +
+ (global_system_variables.read_buff_size +
+ thd->variables.sortbuff_size) *
max_connections)/ 1024);
fprintf(stderr, "Hope that's ok; if not, decrease some variables in the equation.\n\n");
@@ -2091,6 +2094,7 @@ int main(int argc, char **argv)
(void) grant_init((THD*) 0);
init_max_user_conn();
init_update_queries();
+ DBUG_ASSERT(current_thd == 0);
#ifdef HAVE_DLOPEN
if (!opt_noacl)
@@ -2099,6 +2103,7 @@ int main(int argc, char **argv)
/* 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;
@@ -3506,8 +3511,9 @@ struct my_option my_long_options[] =
IO_SIZE, 0},
{"key_buffer_size", OPT_KEY_BUFFER_SIZE,
"The size of the buffer used for index blocks. Increase this to get better index handling (for all reads and multiple writes) to as much as you can afford; 64M on a 256M machine that mainly runs MySQL is quite common.",
- (gptr*) &keybuff_size, (gptr*) &keybuff_size, 0, GET_ULONG, REQUIRED_ARG,
- KEY_CACHE_SIZE, MALLOC_OVERHEAD, (long) ~0, MALLOC_OVERHEAD, IO_SIZE, 0},
+ (gptr*) &keybuff_size, (gptr*) &keybuff_size, 0, GET_ULL,
+ REQUIRED_ARG, KEY_CACHE_SIZE, MALLOC_OVERHEAD, (long) ~0, MALLOC_OVERHEAD,
+ IO_SIZE, 0},
{"long_query_time", OPT_LONG_QUERY_TIME,
"Log all queries that have taken more than long_query_time seconds to execute to file.",
(gptr*) &global_system_variables.long_query_time,
diff --git a/sql/set_var.cc b/sql/set_var.cc
index 0675f7b4286..28222740c14 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -119,7 +119,7 @@ sys_var_thd_ulong sys_interactive_timeout("interactive_timeout",
&SV::net_interactive_timeout);
sys_var_thd_ulong sys_join_buffer_size("join_buffer_size",
&SV::join_buff_size);
-sys_var_long_ptr sys_key_buffer_size("key_buffer_size",
+sys_var_ulonglong_ptr sys_key_buffer_size("key_buffer_size",
&keybuff_size,
fix_key_buffer_size);
sys_var_bool_ptr sys_local_infile("local_infile",
@@ -669,6 +669,23 @@ void sys_var_long_ptr::set_default(THD *thd, enum_var_type type)
}
+bool sys_var_ulonglong_ptr::update(THD *thd, set_var *var)
+{
+ ulonglong tmp= var->value->val_int();
+ if (option_limits)
+ *value= (ulonglong) getopt_ull_limit_value(tmp, option_limits);
+ else
+ *value= (ulonglong) tmp;
+ return 0;
+}
+
+
+void sys_var_ulonglong_ptr::set_default(THD *thd, enum_var_type type)
+{
+ *value= (ulonglong) option_limits->def_value;
+}
+
+
bool sys_var_bool_ptr::update(THD *thd, set_var *var)
{
*value= (my_bool) var->save_result.ulong_value;
diff --git a/sql/set_var.h b/sql/set_var.h
index a171c4f5e76..3edd0373db9 100644
--- a/sql/set_var.h
+++ b/sql/set_var.h
@@ -85,6 +85,22 @@ public:
};
+class sys_var_ulonglong_ptr :public sys_var
+{
+public:
+ ulonglong *value;
+ sys_var_ulonglong_ptr(const char *name_arg, ulonglong *value_ptr)
+ :sys_var(name_arg),value(value_ptr) {}
+ sys_var_ulonglong_ptr(const char *name_arg, ulonglong *value_ptr,
+ sys_after_update_func func)
+ :sys_var(name_arg,func), value(value_ptr) {}
+ bool update(THD *thd, set_var *var);
+ void set_default(THD *thd, enum_var_type type);
+ SHOW_TYPE type() { return SHOW_LONGLONG; }
+ byte *value_ptr(THD *thd, enum_var_type type) { return (byte*) value; }
+};
+
+
class sys_var_bool_ptr :public sys_var
{
public:
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 8b276cf0d9b..5f73c6fa64e 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -37,7 +37,6 @@
#include <mysys_err.h>
#include <assert.h>
-extern struct rand_struct sql_rand;
/*****************************************************************************
** Instansiate templates
@@ -159,7 +158,7 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
pthread_mutex_lock(&LOCK_thread_count);
ulong tmp=(ulong) (rnd(&sql_rand) * 3000000);
pthread_mutex_unlock(&LOCK_thread_count);
- randominit(&rand, tmp + (ulong) start_time, tmp + (ulong) thread_id);
+ randominit(&rand, tmp + (ulong) &rand, tmp + (ulong) ::query_id);
}
}
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 80b1ceb0538..c4bc10a8b2a 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -2848,9 +2848,7 @@ join_free(JOIN *join)
}
join->group_fields.delete_elements();
join->tmp_table_param.copy_funcs.delete_elements();
- if (join->tmp_table_param.copy_field) // Because of bug in ecc
- delete [] join->tmp_table_param.copy_field;
- join->tmp_table_param.copy_field=0;
+ join->tmp_table_param.cleanup();
DBUG_VOID_RETURN;
}
@@ -3699,13 +3697,13 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
NullS))
{
bitmap_clear_bit(&temp_pool, temp_pool_slot);
- DBUG_RETURN(NULL); /* purecov: inspected */
+ DBUG_RETURN(NULL); /* purecov: inspected */
}
if (!(param->copy_field=copy=new Copy_field[field_count]))
{
bitmap_clear_bit(&temp_pool, temp_pool_slot);
- my_free((gptr) table,MYF(0)); /* purecov: inspected */
- DBUG_RETURN(NULL); /* purecov: inspected */
+ my_free((gptr) table,MYF(0)); /* purecov: inspected */
+ DBUG_RETURN(NULL); /* purecov: inspected */
}
param->funcs=copy_func;
strmov(tmpname,path);
diff --git a/sql/sql_select.h b/sql/sql_select.h
index d0e10f75727..40eb4d8ef51 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -115,7 +115,8 @@ typedef struct st_position { /* Used in find_best */
/* Param to create temporary tables when doing SELECT:s */
-class TMP_TABLE_PARAM {
+class TMP_TABLE_PARAM :public Sql_alloc
+{
public:
List<Item> copy_funcs;
List_iterator_fast<Item> copy_funcs_it;
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index aa0946113c9..266bf8aefa9 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -1771,8 +1771,14 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
/* We changed a temporary table */
if (error)
{
+ /*
+ * The following function call will also free a
+ * new_table pointer.
+ * Therefore, here new_table pointer is not free'd as it is
+ * free'd in close_temporary() which is called by by the
+ * close_temporary_table() function.
+ */
close_temporary_table(thd,new_db,tmp_name);
- my_free((gptr) new_table,MYF(0));
goto err;
}
/* Close lock if this is a transactional table */
@@ -2092,7 +2098,6 @@ copy_data_between_tables(TABLE *from,TABLE *to,
if (to->file->external_lock(thd,F_UNLCK))
error=1;
err:
- tmp_error = ha_recovery_logging(thd,TRUE);
free_io_cache(from);
*copied= found_count;
*deleted=delete_count;
diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc
index 420ec67f0c5..937d1e52656 100644
--- a/sql/sql_udf.cc
+++ b/sql/sql_udf.cc
@@ -202,6 +202,8 @@ void udf_init()
new_thd->version--; // Force close to free memory
close_thread_tables(new_thd);
delete new_thd;
+ /* Remember that we don't have a THD */
+ my_pthread_setspecific_ptr(THR_THD, 0);
DBUG_VOID_RETURN;
}
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 887d4e0acc0..4eab38bebad 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -412,9 +412,10 @@ end:
multi_update::multi_update(THD *thd_arg, TABLE_LIST *table_list,
List<Item> *field_list, List<Item> *value_list,
enum enum_duplicates handle_duplicates_arg)
- :all_tables(table_list), thd(thd_arg), tmp_tables(0), updated(0),
- found(0), fields(field_list), values(value_list), table_count(0),
- handle_duplicates(handle_duplicates_arg), do_update(1)
+ :all_tables(table_list), update_tables(0), thd(thd_arg), tmp_tables(0),
+ updated(0), found(0), fields(field_list), values(value_list),
+ table_count(0), copy_field(0), handle_duplicates(handle_duplicates_arg),
+ do_update(1), trans_safe(0)
{}
@@ -594,9 +595,14 @@ multi_update::~multi_update()
if (tmp_tables)
{
- for (uint counter = 0; counter < table_count; counter++)
- if (tmp_tables[counter])
- free_tmp_table(thd,tmp_tables[counter]);
+ for (uint cnt = 0; cnt < table_count; cnt++)
+ {
+ if (tmp_tables[cnt])
+ {
+ free_tmp_table(thd, tmp_tables[cnt]);
+ tmp_table_param[cnt].cleanup();
+ }
+ }
}
if (copy_field)
delete [] copy_field;