diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/ChangeLog | 4 | ||||
-rw-r--r-- | sql/lock.cc | 1 | ||||
-rw-r--r-- | sql/log.cc | 83 | ||||
-rw-r--r-- | sql/mysql_priv.h | 2 | ||||
-rw-r--r-- | sql/mysqld.cc | 69 | ||||
-rw-r--r-- | sql/sql_acl.cc | 2 | ||||
-rw-r--r-- | sql/sql_base.cc | 9 | ||||
-rw-r--r-- | sql/sql_class.cc | 10 | ||||
-rw-r--r-- | sql/sql_class.h | 12 | ||||
-rw-r--r-- | sql/sql_db.cc | 20 | ||||
-rw-r--r-- | sql/sql_delete.cc | 18 | ||||
-rw-r--r-- | sql/sql_insert.cc | 27 | ||||
-rw-r--r-- | sql/sql_load.cc | 14 | ||||
-rw-r--r-- | sql/sql_parse.cc | 84 | ||||
-rw-r--r-- | sql/sql_rename.cc | 9 | ||||
-rw-r--r-- | sql/sql_table.cc | 40 | ||||
-rw-r--r-- | sql/sql_update.cc | 9 |
17 files changed, 246 insertions, 167 deletions
diff --git a/sql/ChangeLog b/sql/ChangeLog index fe67aca1cc0..df9b2567113 100644 --- a/sql/ChangeLog +++ b/sql/ChangeLog @@ -1,3 +1,7 @@ +2000-09-15 Michael Widenius <monty@mysql.com> + +* Added a thd argument to log::write() to get more speed. + 2000-09-01 Michael Widenius <monty@mysql.com> * Avoid allocation of "localhost" string. diff --git a/sql/lock.cc b/sql/lock.cc index eba1851bae0..7eb42f6b084 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -127,6 +127,7 @@ retry: sql_lock=0; } } + thd->lock_time(); DBUG_RETURN (sql_lock); } diff --git a/sql/log.cc b/sql/log.cc index 29ca0247a1b..c5862621cfd 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -338,7 +338,7 @@ void MYSQL_LOG::new_file() close(); open(old_name, log_type, new_name); my_free(old_name,MYF(0)); - if (!file) // Something got wrong + if (!file) // Something went wrong log_type=LOG_CLOSED; last_time=query_start=0; write_error=0; @@ -347,10 +347,10 @@ void MYSQL_LOG::new_file() } -void MYSQL_LOG::write(enum enum_server_command command, +void MYSQL_LOG::write(THD *thd,enum enum_server_command command, const char *format,...) { - if (name && (what_to_log & (1L << (uint) command))) + if (is_open() && (what_to_log & (1L << (uint) command))) { va_list args; va_start(args,format); @@ -359,7 +359,6 @@ void MYSQL_LOG::write(enum enum_server_command command, { time_t skr; ulong id; - THD *thd=current_thd; int error=0; if (thd) { // Normal thread @@ -423,14 +422,14 @@ void MYSQL_LOG::write(enum enum_server_command command, void MYSQL_LOG::write(Query_log_event* event_info) { - if (name) + if (is_open()) { VOID(pthread_mutex_lock(&LOCK_log)); - if(file) + if (file) { THD *thd=event_info->thd; if ((!(thd->options & OPTION_BIN_LOG) && - thd->master_access & PROCESS_ACL) || + thd->master_access & PROCESS_ACL) || !db_ok(event_info->db, binlog_do_db, binlog_ignore_db)) { VOID(pthread_mutex_unlock(&LOCK_log)); @@ -457,57 +456,50 @@ void MYSQL_LOG::write(Query_log_event* event_info) } } - if(event_info->write(file)) + if (event_info->write(file)) { sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno); } err: VOID(pthread_cond_broadcast(&COND_binlog_update)); - - VOID(pthread_mutex_unlock(&LOCK_log)); } + VOID(pthread_mutex_unlock(&LOCK_log)); } - } void MYSQL_LOG::write(Load_log_event* event_info) { - if(name) + if (is_open()) { VOID(pthread_mutex_lock(&LOCK_log)); - if(file) + if (file) { THD *thd=event_info->thd; - if (!(thd->options & OPTION_BIN_LOG) && - (thd->master_access & PROCESS_ACL)) + if ((thd->options & OPTION_BIN_LOG) || + !(thd->master_access & PROCESS_ACL)) { - VOID(pthread_mutex_unlock(&LOCK_log)); - return; + if (event_info->write(file)) + sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno); + VOID(pthread_cond_broadcast(&COND_binlog_update)); } - - - if (event_info->write(file)) - sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno); - VOID(pthread_cond_broadcast(&COND_binlog_update)); - - VOID(pthread_mutex_unlock(&LOCK_log)); } + VOID(pthread_mutex_unlock(&LOCK_log)); } } /* Write update log in a format suitable for incremental backup */ -void MYSQL_LOG::write(const char *query, uint query_length, - ulong time_for_query) +void MYSQL_LOG::write(THD *thd,const char *query, uint query_length, + time_t query_start) { - if (name) + if (is_open()) { + time_t current_time; VOID(pthread_mutex_lock(&LOCK_log)); if (file) { // Safety agains reopen int error=0; - THD *thd=current_thd; char buff[80],*end; end=buff; if (!(thd->options & OPTION_UPDATE_LOG) && @@ -518,13 +510,13 @@ void MYSQL_LOG::write(const char *query, uint query_length, } if (specialflag & SPECIAL_LONG_LOG_FORMAT) { - time_t skr=time(NULL); - if (skr != last_time) + current_time=time(NULL); + if (current_time != last_time) { - last_time=skr; + last_time=current_time; struct tm tm_tmp; struct tm *start; - localtime_r(&skr,&tm_tmp); + localtime_r(¤t_time,&tm_tmp); start=&tm_tmp; if (fprintf(file,"# Time: %02d%02d%02d %2d:%02d:%02d\n", start->tm_year % 100, @@ -542,8 +534,16 @@ void MYSQL_LOG::write(const char *query, uint query_length, thd->ip ? thd->ip : "") < 0) error=errno;; } - if (time_for_query) - fprintf(file,"# Time: %lu\n",time_for_query); + if (query_start) + { + /* For slow query log */ + if (!(specialflag & SPECIAL_LONG_LOG_FORMAT)) + current_time=time(NULL); + fprintf(file,"# Time: %lu Lock_time: %lu Rows_sent %lu\n", + (ulong) (current_time - query_start), + (ulong) (thd->time_after_lock - query_start), + (ulong) thd->sent_row_count); + } if (thd->db && strcmp(thd->db,db)) { // Database changed if (fprintf(file,"use %s;\n",thd->db) < 0) @@ -637,16 +637,15 @@ void MYSQL_LOG::close(bool exiting) name=0; } - if(exiting && index_file) + if (exiting && index_file) + { + if (my_fclose(index_file,MYF(0)) < 0 && ! write_error) { - if (my_fclose(index_file,MYF(0)) < 0 && ! write_error) - { - write_error=1; - sql_print_error(ER(ER_ERROR_ON_WRITE),name,errno); - } - index_file=0; - + write_error=1; + sql_print_error(ER(ER_ERROR_ON_WRITE),name,errno); } + index_file=0; + } } diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 18930468541..46437dfff0c 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -458,7 +458,7 @@ extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open, extern pthread_cond_t COND_refresh,COND_thread_count, COND_binlog_update, COND_slave_stopped; extern pthread_attr_t connection_attrib; -extern bool opt_endinfo,using_udf_functions; +extern bool opt_endinfo,using_udf_functions, locked_in_memory; extern ulong ha_read_count, ha_write_count, ha_delete_count, ha_update_count, ha_read_key_count, ha_read_next_count, ha_read_prev_count, ha_read_first_count, ha_read_last_count, diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 4d3dc8de519..b8c77d81bd9 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -72,6 +72,10 @@ int allow_severity = LOG_INFO; int deny_severity = LOG_WARNING; #endif /* HAVE_LIBWRAP */ +#ifdef HAVE_SYS_MMAN_H +#include <sys/mman.h> +#endif + #if defined(__FreeBSD__) && defined(HAVE_IEEEFP_H) #include <ieeefp.h> #ifdef HAVE_FP_EXCEPT // Fix type conflict @@ -139,13 +143,13 @@ static my_socket unix_sock= INVALID_SOCKET,ip_sock= INVALID_SOCKET; static ulong back_log,connect_timeout,concurrency; static my_string opt_logname=0,opt_update_logname=0, opt_binlog_index_name = 0,opt_slow_logname=0; -my_string opt_bin_logname = 0; // this one needs to be seen in sql_parse.cc +my_string opt_bin_logname = 0; // this one needs to be seen in sql_parse.cc static char mysql_home[FN_REFLEN],pidfile_name[FN_REFLEN]; static pthread_t select_thread; static pthread_t flush_thread; // Used when debugging static bool opt_log,opt_update_log,opt_bin_log,opt_slow_log,opt_noacl, opt_disable_networking=0, opt_bootstrap=0,opt_skip_show_db=0, - opt_ansi_mode,opt_myisam_log=0; + opt_ansi_mode=0,opt_myisam_log=0; bool opt_sql_bin_update = 0, opt_log_slave_updates = 0; // if sql_bin_update is true, SQL_LOG_UPDATE and SQL_LOG_BIN are kept in sync, and are @@ -197,7 +201,7 @@ uint master_port = MYSQL_PORT, master_connect_retry = 60; ulong max_tmp_tables,max_heap_table_size; ulong bytes_sent = 0L, bytes_received = 0L; -bool opt_endinfo,using_udf_functions,low_priority_updates; +bool opt_endinfo,using_udf_functions,low_priority_updates, locked_in_memory; bool volatile abort_loop,select_thread_in_use,flush_thread_in_use,grant_option; bool volatile ready_to_exit,shutdown_in_progress; ulong refresh_version=1L,flush_version=1L; /* Increments on each reload */ @@ -589,6 +593,7 @@ void clean_up(void) x_free((gptr) errmsg[ERRMAPP]); /* Free messages */ free_defaults(defaults_argv); my_free(mysql_tmpdir,MYF(0)); + x_free(opt_bin_logname); my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); /* Tell main we are ready */ @@ -1472,6 +1477,13 @@ int main(int argc, char **argv) LOG_NEW); if (opt_bin_log) { + if (!opt_bin_logname) + { + char tmp[FN_REFLEN]; + strnmov(tmp,hostname,FN_REFLEN-5); + strmov(strcend(tmp,'.'),"-bin"); + opt_bin_logname=my_strdup(tmp,MYF(MY_WME)); + } mysql_bin_log.set_index_file_name(opt_binlog_index_name); open_log(&mysql_bin_log, hostname, opt_bin_logname, "-bin", LOG_BIN); @@ -1484,6 +1496,21 @@ int main(int argc, char **argv) sql_print_error("Can't init databases"); exit(1); } +#ifdef HAVE_MLOCKALL + if (locked_in_memory && !geteuid()) + { + ha_key_cache(); + 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); /* SerG */ @@ -2171,7 +2198,8 @@ enum options { OPT_MASTER_CONNECT_RETRY, OPT_SQL_BIN_UPDATE_SAME, OPT_REPLICATE_DO_DB, OPT_REPLICATE_IGNORE_DB, OPT_LOG_SLAVE_UPDATES, OPT_BINLOG_DO_DB, - OPT_BINLOG_IGNORE_DB, OPT_WANT_CORE + OPT_BINLOG_IGNORE_DB, OPT_WANT_CORE, + OPT_SKIP_CONCURRENT_INSERT, OPT_MEMLOCK }; static struct option long_options[] = { @@ -2225,6 +2253,7 @@ static struct option long_options[] = { {"master-port", required_argument, 0, (int) OPT_MASTER_PORT}, {"master-connect-retry", required_argument, 0, (int) OPT_MASTER_CONNECT_RETRY}, {"master-info-file", required_argument, 0, (int) OPT_MASTER_INFO_FILE}, + {"memlock", no_argument, 0, (int) OPT_MEMLOCK}, {"new", no_argument, 0, 'n'}, {"old-protocol", no_argument, 0, 'o'}, #ifndef DBUG_OFF @@ -2240,6 +2269,7 @@ static struct option long_options[] = { #ifdef HAVE_BERKELEY_DB {"skip-bdb", no_argument, 0, (int) OPT_BDB_SKIP}, #endif + {"skip-concurrent-insert", no_argument, 0, (int) OPT_SKIP_CONCURRENT_INSERT}, {"skip-delay-key-write", no_argument, 0, (int) OPT_SKIP_DELAY_KEY_WRITE}, {"skip-grant-tables", no_argument, 0, (int) OPT_SKIP_GRANT}, {"skip-locking", no_argument, 0, (int) OPT_SKIP_LOCK}, @@ -2369,6 +2399,9 @@ struct show_var_st init_vars[]= { {"interactive_timeout", (char*) &net_interactive_timeout, SHOW_LONG}, {"key_buffer_size", (char*) &keybuff_size, SHOW_LONG}, {"language", language, SHOW_CHAR}, +#ifdef HAVE_MEMLOCKALL + {"locked_in_memory", (char*) &locked_in_memory, SHOW_BOOL}, +#endif {"log", (char*) &opt_log, SHOW_BOOL}, {"log_update", (char*) &opt_update_log, SHOW_BOOL}, {"log_bin", (char*) &opt_bin_log, SHOW_BOOL}, @@ -2532,9 +2565,10 @@ static void usage(void) Log slow queries to this log file. Defaults logging\n\ to hostname-slow.log\n\ --pid-file=path Pid file used by safe_mysqld\n\ - -P, --port=... Port number to use for connection\n\ + --memlock Lock mysqld in memory\n\ -n, --new Use very new possible 'unsafe' functions\n\ - -o, --old-protocol Use the old (3.20) protocol\n"); + -o, --old-protocol Use the old (3.20) protocol\n\ + -P, --port=... Port number to use for connection\n"); #ifndef DBUG_OFF puts("\ --one-thread Only use one thread (for debugging under Linux)\n"); @@ -2546,6 +2580,8 @@ static void usage(void) Start without grant tables. This gives all users\n\ FULL ACCESS to all tables!\n\ --safe-mode Skip some optimize stages (for testing)\n\ + --skip-concurrent-insert\n\ + Don't use concurrent insert with MyISAM\n\ --skip-delay-key-write\n\ Ignore the delay_key_write option for all tables\n\ --skip-locking Don't use system locking. To use isamchk one has\n\ @@ -2607,11 +2643,12 @@ The default values (after parsing the command line arguments) are:\n\n"); printf("logfile: %s\n",opt_logname); if (opt_update_logname) printf("update log: %s\n",opt_update_logname); - if (opt_bin_logname) - { - printf("binary log: %s\n",opt_bin_logname); - printf("binary log index: %s\n",opt_binlog_index_name); - } + if (opt_bin_log) + { + printf("binary log: %s\n",opt_bin_logname ? opt_bin_logname : ""); + printf("binary log index: %s\n", + opt_binlog_index_name ? opt_binlog_index_name : ""); + } if (opt_slow_logname) printf("update log: %s\n",opt_slow_logname); printf("TCP port: %d\n",mysql_port); @@ -2771,7 +2808,9 @@ static void get_options(int argc,char **argv) break; case (int) OPT_BIN_LOG: opt_bin_log=1; - opt_bin_logname=optarg; + x_free(opt_bin_logname); + if (optarg && optarg[0]) + opt_bin_logname=my_strdup(optarg,MYF(0)); break; case (int) OPT_LOG_SLAVE_UPDATES: opt_log_slave_updates = 1; @@ -2820,6 +2859,9 @@ static void get_options(int argc,char **argv) myisam_delay_key_write=0; myisam_concurrent_insert=0; break; + case (int) OPT_SKIP_CONCURRENT_INSERT: + myisam_concurrent_insert=0; + break; case (int) OPT_SKIP_PRIOR: opt_specialflag|= SPECIAL_NO_PRIOR; break; @@ -2853,6 +2895,9 @@ static void get_options(int argc,char **argv) opt_specialflag|=SPECIAL_SKIP_SHOW_DB; mysql_port=0; break; + case (int) OPT_MEMLOCK: + locked_in_memory=1; + break; case (int) OPT_ONE_THREAD: test_flags |= TEST_NO_THREADS; break; diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 5089c8d75ee..f103fce1ad9 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -820,7 +820,7 @@ bool change_password(THD *thd, const char *host, const char *user, acl_user->user, acl_user->host.hostname ? acl_user->host.hostname : "", new_password)); - mysql_update_log.write(buff,(uint) strlen(buff)); + mysql_update_log.write(thd,buff,qinfo.q_len); mysql_bin_log.write(&qinfo); return 0; } diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 84213a26b94..a37506bcbf4 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -29,7 +29,6 @@ #include <io.h> #endif -static int key_cache_used=0; TABLE *unused_tables; /* Used by mysql_test */ HASH open_cache; /* Used by mysql_test */ @@ -550,10 +549,9 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh, VOID(hash_delete(&open_cache,(byte*) unused_tables)); #endif } - if (!open_cache.records) + if (!open_cache.records && ! locked_in_memory) { end_key_cache(); /* No tables in memory */ - key_cache_used=0; } refresh_version++; // Force close of open tables } @@ -980,11 +978,8 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, table->key_length=key_length; table->version=refresh_version; table->flush_version=flush_version; - if (!key_cache_used) - { - key_cache_used=1; + if (!key_cache_inited) ha_key_cache(); - } DBUG_PRINT("info", ("inserting table %p into the cache", table)); VOID(hash_insert(&open_cache,(byte*) table)); } diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 1c506e969f7..059b17c6d84 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -221,6 +221,7 @@ bool select_send::send_data(List<Item> &items) DBUG_RETURN(1); } } + thd->sent_row_count++; bool error=my_net_write(&thd->net,(char*) packet->ptr(),packet->length()); DBUG_RETURN(error); } @@ -256,6 +257,7 @@ select_export::~select_export() (void) my_close(file,MYF(0)); file= -1; } + thd->sent_row_count=row_count; } int @@ -461,10 +463,10 @@ err: void select_export::send_error(uint errcode,const char *err) { - ::send_error(&thd->net,errcode,err); - (void) end_io_cache(&cache); - (void) my_close(file,MYF(0)); - file= -1; + ::send_error(&thd->net,errcode,err); + (void) end_io_cache(&cache); + (void) my_close(file,MYF(0)); + file= -1; } diff --git a/sql/sql_class.h b/sql/sql_class.h index 4389512c1b3..34379baedd6 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -94,8 +94,9 @@ public: void open(const char *log_name,enum_log_type log_type, const char *new_name=0); void new_file(void); - void write(enum enum_server_command command,const char *format,...); - void write(const char *query, uint query_length, ulong time_to_do_query=0); + void write(THD *thd, enum enum_server_command command,const char *format,...); + void write(THD *thd, const char *query, uint query_length, + time_t query_start=0); void write(Query_log_event* event_info); // binary log write void write(Load_log_event* event_info); @@ -111,7 +112,7 @@ public: int find_next_log(LOG_INFO* linfo); int get_current_log(LOG_INFO* linfo); - bool is_open() { return log_type != LOG_CLOSED; } + inline bool is_open() { return log_type != LOG_CLOSED; } char* get_index_fname() { return index_file_name;} char* get_log_fname() { return log_file_name; } }; @@ -241,7 +242,7 @@ public: const char *where; char* last_nx_table; // last non-existent table, we need this for replication char* last_nx_db; // database of the last nx table - time_t start_time; + time_t start_time,time_after_lock; time_t connect_time,thr_create_time; // track down slow pthread_create thr_lock_type update_lock_default; delayed_insert *di; @@ -257,7 +258,7 @@ public: #endif ulonglong next_insert_id,last_insert_id,current_insert_id; ha_rows select_limit,offset_limit,default_select_limit,cuted_fields, - max_join_size; + max_join_size,sent_row_count; ulong query_id,version, inactive_timeout,options,thread_id; long dbug_thread_id; pthread_t real_id; @@ -276,6 +277,7 @@ public: inline time_t query_start() { query_start_used=1; return start_time; } inline void set_time() { if (!user_time) time(&start_time); } inline void set_time(time_t t) { start_time=t; user_time=1; } + inline void lock_time() { time(&time_after_lock); } inline void insert_id(ulonglong id) { last_insert_id=id; insert_id_used=1; } inline ulonglong insert_id(void) diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 33c8ee54037..5c816aa8dc5 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -71,9 +71,12 @@ void mysql_create_db(THD *thd, char *db, uint create_options) path); } { - mysql_update_log.write(thd->query, thd->query_length); - Query_log_event qinfo(thd, thd->query); - mysql_bin_log.write(&qinfo); + mysql_update_log.write(thd,thd->query, thd->query_length); + if (mysql_bin_log.is_open()) + { + Query_log_event qinfo(thd, thd->query); + mysql_bin_log.write(&qinfo); + } } if (thd->query == path) { @@ -131,9 +134,12 @@ void mysql_rm_db(THD *thd,char *db,bool if_exists) thd->query_length = (uint) (strxmov(path,"drop database ", db, NullS)- path); } - mysql_update_log.write(thd->query, thd->query_length); - Query_log_event qinfo(thd, thd->query); - mysql_bin_log.write(&qinfo); + mysql_update_log.write(thd, thd->query, thd->query_length); + if (mysql_bin_log.is_open()) + { + Query_log_event qinfo(thd, thd->query); + mysql_bin_log.write(&qinfo); + } if (thd->query == path) { thd->query = 0; // just in case @@ -276,7 +282,7 @@ bool mysql_change_db(THD *thd,const char *name) thd->priv_user, thd->host ? thd->host : thd->ip ? thd->ip : "unknown", dbname); - mysql_log.write(COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR), + mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR), thd->priv_user, thd->host ? thd->host : thd->ip ? thd->ip : "unknown", dbname); diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 5d21a089283..05bed157d27 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -89,9 +89,12 @@ static int generate_table(THD *thd, TABLE_LIST *table_list, if (!error) { send_ok(&thd->net); // This should return record count - mysql_update_log.write(thd->query,thd->query_length); - Query_log_event qinfo(thd, thd->query); - mysql_bin_log.write(&qinfo); + mysql_update_log.write(thd,thd->query,thd->query_length); + if (mysql_bin_log.is_open()) + { + Query_log_event qinfo(thd, thd->query); + mysql_bin_log.write(&qinfo); + } } DBUG_RETURN(error ? -1 : 0); } @@ -188,9 +191,12 @@ int mysql_delete(THD *thd,TABLE_LIST *table_list,COND *conds,ha_rows limit, VOID(table->file->extra(HA_EXTRA_READCHECK)); if (deleted) { - mysql_update_log.write(thd->query, thd->query_length); - Query_log_event qinfo(thd, thd->query); - mysql_bin_log.write(&qinfo); + mysql_update_log.write(thd,thd->query, thd->query_length); + if (mysql_bin_log.is_open()) + { + Query_log_event qinfo(thd, thd->query); + mysql_bin_log.write(&qinfo); + } } if (ha_autocommit_or_rollback(thd,error >= 0)) error=1; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index bd0415aa936..13feba9ab9c 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -246,9 +246,12 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List<Item> &fields, id=table->next_number_field->val_int(); // Return auto_increment value if (info.copied || info.deleted) { - mysql_update_log.write(thd->query, thd->query_length); - Query_log_event qinfo(thd, thd->query); - mysql_bin_log.write(&qinfo); + mysql_update_log.write(thd, thd->query, thd->query_length); + if (mysql_bin_log.is_open()) + { + Query_log_event qinfo(thd, thd->query); + mysql_bin_log.write(&qinfo); + } } error=ha_autocommit_or_rollback(thd,error); if (thd->lock) @@ -1085,9 +1088,12 @@ bool delayed_insert::handle_inserts(void) } if (row->query && row->log_query) { - mysql_update_log.write(row->query, row->query_length); - Query_log_event qinfo(&thd, row->query); - mysql_bin_log.write(&qinfo); + mysql_update_log.write(&thd,row->query, row->query_length); + if (mysql_bin_log.is_open()) + { + Query_log_event qinfo(&thd, row->query); + mysql_bin_log.write(&qinfo); + } } if (table->blob_fields) free_delayed_insert_blobs(table); @@ -1245,9 +1251,12 @@ bool select_insert::send_eof() if (last_insert_id) thd->insert_id(last_insert_id); // For update log ::send_ok(&thd->net,info.copied,last_insert_id,buff); - mysql_update_log.write(thd->query,thd->query_length); - Query_log_event qinfo(thd, thd->query); - mysql_bin_log.write(&qinfo); + mysql_update_log.write(thd,thd->query,thd->query_length); + if (mysql_bin_log.is_open()) + { + Query_log_event qinfo(thd, thd->query); + mysql_bin_log.write(&qinfo); + } return 0; } } diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 145bbec4d88..ef64b5e3bfa 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -244,14 +244,14 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, sprintf(name,ER(ER_LOAD_INFO),info.records,info.deleted, info.records-info.copied,thd->cuted_fields); send_ok(&thd->net,info.copied+info.deleted,0L,name); - mysql_update_log.write(thd->query,thd->query_length); + mysql_update_log.write(thd,thd->query,thd->query_length); - if(!read_file_from_client) - { - ex->skip_lines = save_skip_lines; - Load_log_event qinfo(thd, ex, table->table_name, fields, handle_duplicates); - mysql_bin_log.write(&qinfo); - } + if (!read_file_from_client) + { + ex->skip_lines = save_skip_lines; + Load_log_event qinfo(thd, ex, table->table_name, fields, handle_duplicates); + mysql_bin_log.write(&qinfo); + } DBUG_RETURN(0); } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 97eb7c80b50..1626f03ed7a 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -119,7 +119,7 @@ static bool check_user(THD *thd,enum_server_command command, const char *user, thd->user, thd->host ? thd->host : thd->ip, passwd[0] ? ER(ER_YES) : ER(ER_NO)); - mysql_log.write(COM_CONNECT,ER(ER_ACCESS_DENIED_ERROR), + mysql_log.write(thd,COM_CONNECT,ER(ER_ACCESS_DENIED_ERROR), thd->user, thd->host ? thd->host : thd->ip ? thd->ip : "unknown ip", passwd[0] ? ER(ER_YES) : ER(ER_NO)); @@ -137,7 +137,7 @@ static bool check_user(THD *thd,enum_server_command command, const char *user, return(1); } } - mysql_log.write(command, + mysql_log.write(thd,command, (thd->priv_user == thd->user ? (char*) "%s@%s on %s" : (char*) "%s@%s as anonymous on %s"), @@ -578,7 +578,7 @@ bool do_command(THD *thd) switch(command) { case COM_INIT_DB: if (!mysql_change_db(thd,packet+1)) - mysql_log.write(command,"%s",thd->db); + mysql_log.write(thd,command,"%s",thd->db); break; case COM_TABLE_DUMP: { @@ -646,7 +646,7 @@ bool do_command(THD *thd) thd->packet.shrink(net_buffer_length); // Reclaim some memory if (!(specialflag & SPECIAL_NO_PRIOR)) my_pthread_setprio(pthread_self(),QUERY_PRIOR); - mysql_log.write(command,"%s",thd->query); + mysql_log.write(thd,command,"%s",thd->query); DBUG_PRINT("query",("%s",thd->query)); mysql_parse(thd,thd->query,packet_length-1); if (!(specialflag & SPECIAL_NO_PRIOR)) @@ -671,7 +671,7 @@ bool do_command(THD *thd) thd->free_list=0; table_list.name=table_list.real_name=thd->strdup(packet+1); thd->query=fields=thd->strdup(strend(packet+1)+1); - mysql_log.write(command,"%s %s",table_list.real_name,fields); + mysql_log.write(thd,command,"%s %s",table_list.real_name,fields); remove_escape(table_list.real_name); // This can't have wildcards if (check_access(thd,SELECT_ACL,table_list.db,&thd->col_access)) @@ -685,7 +685,7 @@ bool do_command(THD *thd) } #endif case COM_QUIT: - mysql_log.write(command,NullS); + mysql_log.write(thd,command,NullS); net->error=0; // Don't give 'abort' message error=TRUE; // End server break; @@ -695,7 +695,7 @@ bool do_command(THD *thd) char *db=thd->strdup(packet+1); if (check_access(thd,CREATE_ACL,db,0,1)) break; - mysql_log.write(command,packet+1); + mysql_log.write(thd,command,packet+1); mysql_create_db(thd,db,0); break; } @@ -704,7 +704,7 @@ bool do_command(THD *thd) char *db=thd->strdup(packet+1); if (check_access(thd,DROP_ACL,db,0,1)) break; - mysql_log.write(command,db); + mysql_log.write(thd,command,db); mysql_rm_db(thd,db,0); break; } @@ -712,7 +712,7 @@ bool do_command(THD *thd) { if(check_access(thd, FILE_ACL, any_db)) break; - mysql_log.write(command, 0); + mysql_log.write(thd,command, 0); ulong pos; ushort flags; @@ -726,7 +726,7 @@ bool do_command(THD *thd) uint options=(uchar) packet[1]; if (check_access(thd,RELOAD_ACL,any_db)) break; - mysql_log.write(command,NullS); + mysql_log.write(thd,command,NullS); if (reload_acl_and_cache(thd, options, (TABLE_LIST*) 0)) send_error(net,0); else @@ -737,7 +737,7 @@ bool do_command(THD *thd) if (check_access(thd,SHUTDOWN_ACL,any_db)) break; /* purecov: inspected */ DBUG_PRINT("quit",("Got shutdown command")); - mysql_log.write(command,NullS); + mysql_log.write(thd,command,NullS); send_eof(net); #ifdef __WIN__ sleep(1); // must wait after eof() @@ -752,7 +752,7 @@ bool do_command(THD *thd) case COM_STATISTICS: { - mysql_log.write(command,NullS); + mysql_log.write(thd,command,NullS); char buff[200]; ulong uptime = (ulong) (time((time_t*) 0) - start_time); sprintf((char*) buff, @@ -776,7 +776,7 @@ bool do_command(THD *thd) case COM_PROCESS_INFO: if (!thd->priv_user[0] && check_access(thd,PROCESS_ACL,any_db)) break; - mysql_log.write(command,NullS); + mysql_log.write(thd,command,NullS); mysqld_list_processes(thd,thd->master_access & PROCESS_ACL ? NullS : thd->priv_user,0); break; @@ -790,7 +790,7 @@ bool do_command(THD *thd) if (check_access(thd,PROCESS_ACL,any_db)) break; /* purecov: inspected */ mysql_print_status(thd); - mysql_log.write(command,NullS); + mysql_log.write(thd,command,NullS); send_eof(net); break; case COM_SLEEP: @@ -816,8 +816,7 @@ bool do_command(THD *thd) if ((ulong) (thd->start_time - start_of_query) > long_query_time) { long_query_count++; - mysql_slow_log.write(thd->query, thd->query_length, - (ulong) (thd->start_time - start_of_query)); + mysql_slow_log.write(thd, thd->query, thd->query_length, start_of_query); } VOID(pthread_mutex_lock(&LOCK_thread_count)); // For process list thd->proc_info=0; @@ -1625,11 +1624,14 @@ mysql_execute_command(void) res = mysql_table_grant(thd,tables,lex->users_list, lex->columns, lex->grant, lex->sql_command == SQLCOM_REVOKE); if(!res) + { + mysql_update_log.write(thd, thd->query,thd->query_length); + if (mysql_bin_log.is_open()) { - mysql_update_log.write(thd->query,thd->query_length); - Query_log_event qinfo(thd, thd->query); - mysql_bin_log.write(&qinfo); + Query_log_event qinfo(thd, thd->query); + mysql_bin_log.write(&qinfo); } + } } else { @@ -1643,9 +1645,12 @@ mysql_execute_command(void) lex->sql_command == SQLCOM_REVOKE); if(!res) { - mysql_update_log.write(thd->query,thd->query_length); - Query_log_event qinfo(thd, thd->query); - mysql_bin_log.write(&qinfo); + mysql_update_log.write(thd, thd->query,thd->query_length); + if (mysql_bin_log.is_open()) + { + Query_log_event qinfo(thd, thd->query); + mysql_bin_log.write(&qinfo); + } } } break; @@ -1905,6 +1910,7 @@ mysql_init_query(THD *thd) thd->lex.table_list.next= (byte**) &thd->lex.table_list.first; thd->fatal_error=0; // Safety thd->last_insert_id_used=thd->query_start_used=thd->insert_id_used=0; + thd->sent_row_count=0; DBUG_VOID_RETURN; } @@ -2625,37 +2631,23 @@ static int change_master(THD* thd) static void reset_master() { if(!mysql_bin_log.is_open()) - { - my_error(ER_FLUSH_MASTER_BINLOG_CLOSED, MYF(ME_BELL+ME_WAITTANG)); - return; - } + { + my_error(ER_FLUSH_MASTER_BINLOG_CLOSED, MYF(ME_BELL+ME_WAITTANG)); + return; + } LOG_INFO linfo; - - if(mysql_bin_log.find_first_log(&linfo, "")) + if (mysql_bin_log.find_first_log(&linfo, "")) return; for(;;) - { - my_delete(linfo.log_file_name, MYF(MY_WME)); - if(mysql_bin_log.find_next_log(&linfo)) - break; - } - mysql_bin_log.close(1); // exiting close - my_delete(mysql_bin_log.get_index_fname(), MYF(MY_WME)); - - char tmp[FN_REFLEN]; - if (!opt_bin_logname || !opt_bin_logname[0]) { - char hostname[FN_REFLEN]; - if (gethostname(hostname,sizeof(hostname)-4) < 0) - strmov(hostname,"mysql"); - - strnmov(tmp,hostname,FN_REFLEN-5); - strmov(strcend(tmp,'.'),"-bin"); - opt_bin_logname=tmp; + my_delete(linfo.log_file_name, MYF(MY_WME)); + if (mysql_bin_log.find_next_log(&linfo)) + break; } - + mysql_bin_log.close(1); // exiting close + my_delete(mysql_bin_log.get_index_fname(), MYF(MY_WME)); mysql_bin_log.open(opt_bin_logname,LOG_BIN); } diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index e1be78ada1c..c3acbac1bd2 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -87,9 +87,12 @@ end: } if (!error) { - mysql_update_log.write(thd->query,thd->query_length); - Query_log_event qinfo(thd, thd->query); - mysql_bin_log.write(&qinfo); + mysql_update_log.write(thd,thd->query,thd->query_length); + if (mysql_bin_log.is_open()) + { + Query_log_event qinfo(thd, thd->query); + mysql_bin_log.write(&qinfo); + } send_ok(&thd->net); } for (TABLE_LIST *table=table_list ; table != lock_table ; table=table->next) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 5a983c8cf06..afd7ebabc53 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -117,9 +117,12 @@ int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists) } if (some_tables_deleted) { - mysql_update_log.write(thd->query,thd->query_length); - Query_log_event qinfo(thd, thd->query); - mysql_bin_log.write(&qinfo); + mysql_update_log.write(thd, thd->query,thd->query_length); + if (mysql_bin_log.is_open()) + { + Query_log_event qinfo(thd, thd->query); + mysql_bin_log.write(&qinfo); + } } VOID(pthread_cond_broadcast(&COND_refresh)); // Signal to refresh @@ -526,9 +529,12 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, if (!tmp_table && !no_log) { // Must be written before unlock - mysql_update_log.write(thd->query, thd->query_length); - Query_log_event qinfo(thd, thd->query); - mysql_bin_log.write(&qinfo); + mysql_update_log.write(thd,thd->query, thd->query_length); + if (mysql_bin_log.is_open()) + { + Query_log_event qinfo(thd, thd->query); + mysql_bin_log.write(&qinfo); + } } if (create_info->options & HA_LEX_CREATE_TMP_TABLE) { @@ -966,9 +972,12 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, VOID(pthread_mutex_unlock(&LOCK_open)); if (!error) { - mysql_update_log.write(thd->query,thd->query_length); - Query_log_event qinfo(thd, thd->query); - mysql_bin_log.write(&qinfo); + mysql_update_log.write(thd, thd->query, thd->query_length); + if (mysql_bin_log.is_open()) + { + Query_log_event qinfo(thd, thd->query); + mysql_bin_log.write(&qinfo); + } send_ok(&thd->net); } @@ -1257,10 +1266,12 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, my_free((gptr) new_table,MYF(0)); goto err; } - mysql_update_log.write(thd->query,thd->query_length); - Query_log_event qinfo(thd, thd->query); - mysql_bin_log.write(&qinfo); - + mysql_update_log.write(thd, thd->query,thd->query_length); + if (mysql_bin_log.is_open()) + { + Query_log_event qinfo(thd, thd->query); + mysql_bin_log.write(&qinfo); + } goto end_temporary; DBUG_RETURN(0); } @@ -1364,7 +1375,8 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, } thd->proc_info="end"; - mysql_update_log.write(thd->query,thd->query_length); + mysql_update_log.write(thd, thd->query,thd->query_length); + if (mysql_bin_log.is_open()) { Query_log_event qinfo(thd, thd->query); mysql_bin_log.write(&qinfo); diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 41f0eb97456..29e9c8b8aac 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -237,9 +237,12 @@ int mysql_update(THD *thd,TABLE_LIST *table_list,List<Item> &fields, table->time_stamp=save_time_stamp; // Restore auto timestamp pointer if (updated) { - mysql_update_log.write(thd->query,thd->query_length); - Query_log_event qinfo(thd, thd->query); - mysql_bin_log.write(&qinfo); + mysql_update_log.write(thd,thd->query,thd->query_length); + if (mysql_bin_log.is_open()) + { + Query_log_event qinfo(thd, thd->query); + mysql_bin_log.write(&qinfo); + } } if (ha_autocommit_or_rollback(thd, error >= 0)) error=1; |