diff -ur mysql-5.0.44/include/my_time.h mysql-5.0.44-microslow/include/my_time.h --- mysql-5.0.44/include/my_time.h 2007-06-21 03:23:03.000000000 -0400 +++ mysql-5.0.44-microslow/include/my_time.h 2007-08-17 15:58:57.000000000 -0400 @@ -140,7 +140,7 @@ int my_date_to_str(const MYSQL_TIME *l_time, char *to); int my_datetime_to_str(const MYSQL_TIME *l_time, char *to); int my_TIME_to_str(const MYSQL_TIME *l_time, char *to); - +ulonglong my_timer(ulonglong *ltime, ulonglong frequency); C_MODE_END #endif /* _my_time_h_ */ Only in mysql-5.0.44-microslow: patch.slow-micro.5.0.45.diff diff -ur mysql-5.0.44/scripts/mysqldumpslow.sh mysql-5.0.44-microslow/scripts/mysqldumpslow.sh --- mysql-5.0.44/scripts/mysqldumpslow.sh 2007-06-21 03:24:03.000000000 -0400 +++ mysql-5.0.44-microslow/scripts/mysqldumpslow.sh 2007-08-17 15:58:57.000000000 -0400 @@ -83,8 +83,8 @@ s/^#? Time: \d{6}\s+\d+:\d+:\d+.*\n//; my ($user,$host) = s/^#? User\@Host:\s+(\S+)\s+\@\s+(\S+).*\n// ? ($1,$2) : ('',''); - s/^# Query_time: (\d+) Lock_time: (\d+) Rows_sent: (\d+).*\n//; - my ($t, $l, $r) = ($1, $2, $3); + s/^# Query_time: (\d+(\.\d+)?) Lock_time: (\d+(\.\d+)?) Rows_sent: (\d+(\.\d+)?).*\n//; + my ($t, $l, $r) = ($1, $3, $5); $t -= $l unless $opt{l}; # remove fluff that mysqld writes to log when it (re)starts: diff -ur mysql-5.0.44/sql/log.cc mysql-5.0.44-microslow/sql/log.cc --- mysql-5.0.44/sql/log.cc 2007-06-21 03:24:21.000000000 -0400 +++ mysql-5.0.44-microslow/sql/log.cc 2007-08-17 15:58:57.000000000 -0400 @@ -1930,10 +1930,11 @@ */ bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length, - time_t query_start_arg) + time_t query_start_arg, ulonglong query_start_timer) { bool error=0; time_t current_time; + ulonglong current_timer; if (!is_open()) return 0; DBUG_ENTER("MYSQL_LOG::write"); @@ -1944,7 +1945,8 @@ int tmp_errno=0; char buff[80],*end; end=buff; - if (!(thd->options & OPTION_UPDATE_LOG)) + if (!(thd->options & OPTION_UPDATE_LOG) && + !(thd->slave_thread && opt_log_slow_slave_statements)) { VOID(pthread_mutex_unlock(&LOCK_log)); DBUG_RETURN(0); @@ -1961,7 +1963,7 @@ localtime_r(¤t_time,&tm_tmp); start=&tm_tmp; /* Note that my_b_write() assumes it knows the length for this */ - sprintf(buff,"# Time: %02d%02d%02d %2d:%02d:%02d\n", + sprintf(buff,"# Time: %02d%02d%02d %2d:%02d:%02d ", start->tm_year % 100, start->tm_mon+1, start->tm_mday, @@ -1974,19 +1976,22 @@ if (my_b_printf(&log_file, "# User@Host: %s[%s] @ %s [%s]\n", sctx->priv_user ? sctx->priv_user : "", - sctx->user ? sctx->user : "", + sctx->user ? sctx->user : (thd->slave_thread ? "SQL_SLAVE" : ""), sctx->host ? sctx->host : "", sctx->ip ? sctx->ip : "") == (uint) -1) tmp_errno=errno; } - if (query_start_arg) + if (query_start_timer) { + char buf[2][20]; + ulonglong current_timer= my_timer(¤t_timer, frequency); + sprintf(buf[0], "%.6f", (current_timer - query_start_timer) / 1000000.0); + sprintf(buf[1], "%.6f", (thd->timer_after_lock - query_start_timer) / 1000000.0); /* For slow query log */ if (my_b_printf(&log_file, - "# Query_time: %lu Lock_time: %lu Rows_sent: %lu Rows_examined: %lu\n", - (ulong) (current_time - query_start_arg), - (ulong) (thd->time_after_lock - query_start_arg), + "# Query_time: %s Lock_time: %s Rows_sent: %lu Rows_examined: %lu\n", + buf[0], buf[1], (ulong) thd->sent_row_count, (ulong) thd->examined_row_count) == (uint) -1) tmp_errno=errno; diff -ur mysql-5.0.44/sql/log_event.cc mysql-5.0.44-microslow/sql/log_event.cc --- mysql-5.0.44/sql/log_event.cc 2007-06-21 03:24:02.000000000 -0400 +++ mysql-5.0.44-microslow/sql/log_event.cc 2007-08-17 15:58:57.000000000 -0400 @@ -1900,6 +1900,7 @@ /* Execute the query (note that we bypass dispatch_command()) */ const char* found_semicolon= NULL; mysql_parse(thd, thd->query, thd->query_length, &found_semicolon); + log_slow_statement(thd); } else diff -ur mysql-5.0.44/sql/mysqld.cc mysql-5.0.44-microslow/sql/mysqld.cc --- mysql-5.0.44/sql/mysqld.cc 2007-06-21 03:23:28.000000000 -0400 +++ mysql-5.0.44-microslow/sql/mysqld.cc 2007-08-17 15:58:57.000000000 -0400 @@ -169,6 +169,7 @@ static void getvolumeID(BYTE *volumeName); #endif /* __NETWARE__ */ +ulonglong frequency= 0; #ifdef _AIX41 int initgroups(const char *,unsigned int); @@ -384,6 +385,7 @@ my_bool opt_secure_auth= 0; char* opt_secure_file_priv= 0; my_bool opt_log_slow_admin_statements= 0; +my_bool opt_log_slow_slave_statements= 0; my_bool lower_case_file_system= 0; my_bool opt_large_pages= 0; uint opt_large_page_size= 0; @@ -3490,6 +3492,8 @@ unireg_abort(1); } } + if (!QueryPerformanceFrequency((LARGE_INTEGER *)&frequency)) + frequency= 0; #endif /* __WIN__ */ if (init_common_variables(MYSQL_CONFIG_NAME, @@ -4724,7 +4728,7 @@ OPT_INTERACTIVE_TIMEOUT, OPT_JOIN_BUFF_SIZE, OPT_KEY_BUFFER_SIZE, OPT_KEY_CACHE_BLOCK_SIZE, OPT_KEY_CACHE_DIVISION_LIMIT, OPT_KEY_CACHE_AGE_THRESHOLD, - OPT_LONG_QUERY_TIME, + OPT_LONG_QUERY_TIME, OPT_MIN_EXAMINED_ROW_LIMIT, OPT_LOWER_CASE_TABLE_NAMES, OPT_MAX_ALLOWED_PACKET, OPT_MAX_BINLOG_CACHE_SIZE, OPT_MAX_BINLOG_SIZE, OPT_MAX_CONNECTIONS, OPT_MAX_CONNECT_ERRORS, @@ -4815,6 +4819,7 @@ OPT_TIMED_MUTEXES, OPT_OLD_STYLE_USER_LIMITS, OPT_LOG_SLOW_ADMIN_STATEMENTS, + OPT_LOG_SLOW_SLAVE_STATEMENTS, OPT_TABLE_LOCK_WAIT_TIMEOUT, OPT_PORT_OPEN_TIMEOUT, OPT_MERGE, @@ -5195,6 +5200,11 @@ (gptr*) &opt_log_slow_admin_statements, (gptr*) &opt_log_slow_admin_statements, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"log-slow-slave-statements", OPT_LOG_SLOW_SLAVE_STATEMENTS, + "Log slow replicated statements to the slow log if it is open.", + (gptr*) &opt_log_slow_slave_statements, + (gptr*) &opt_log_slow_slave_statements, + 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"log-slow-queries", OPT_SLOW_QUERY_LOG, "Log slow queries to this log file. Defaults logging to hostname-slow.log file. Must be enabled to activate other slow log options.", (gptr*) &opt_slow_logname, (gptr*) &opt_slow_logname, 0, GET_STR, OPT_ARG, @@ -5850,7 +5860,12 @@ "Log all queries that have taken more than long_query_time seconds to execute to file.", (gptr*) &global_system_variables.long_query_time, (gptr*) &max_system_variables.long_query_time, 0, GET_ULONG, - REQUIRED_ARG, 10, 1, LONG_TIMEOUT, 0, 1, 0}, + REQUIRED_ARG, 10000000, 0, LONG_TIMEOUT * 1000000, 0, 1, 0}, + {"min_examined_row_limit", OPT_MIN_EXAMINED_ROW_LIMIT, + "Don't log queries which examine less than min_examined_row_limit rows to file.", + (gptr*) &global_system_variables.min_examined_row_limit, + (gptr*) &max_system_variables.min_examined_row_limit, 0, GET_ULONG, + REQUIRED_ARG, 0, 1, ~0L, 0, 1L, 0}, {"lower_case_table_names", OPT_LOWER_CASE_TABLE_NAMES, "If set to 1 table names are stored in lowercase on disk and table names will be case-insensitive. Should be set to 2 if you are using a case insensitive file system", (gptr*) &lower_case_table_names, @@ -7393,10 +7408,14 @@ if (opt_bdb) sql_print_warning("this binary does not contain BDB storage engine"); #endif - if ((opt_log_slow_admin_statements || opt_log_queries_not_using_indexes) && + if ((opt_log_slow_admin_statements || opt_log_queries_not_using_indexes || + opt_log_slow_slave_statements) && !opt_slow_log) - sql_print_warning("options --log-slow-admin-statements and --log-queries-not-using-indexes have no effect if --log-slow-queries is not set"); - + { + sql_print_warning("options --log-slow-admin-statements, --log-slow-slave-statements and --log-queries-not-using-indexes have no effect if --log-slow-queries is not set"); + opt_log_slow_slave_statements= FALSE; + } + if (argc > 0) { fprintf(stderr, "%s: Too many arguments (first extra is '%s').\nUse --help to get a list of available options\n", my_progname, *argv); diff -ur mysql-5.0.44/sql/mysql_priv.h mysql-5.0.44-microslow/sql/mysql_priv.h --- mysql-5.0.44/sql/mysql_priv.h 2007-06-21 03:24:03.000000000 -0400 +++ mysql-5.0.44-microslow/sql/mysql_priv.h 2007-08-17 15:58:57.000000000 -0400 @@ -1317,7 +1317,7 @@ extern my_bool opt_enable_named_pipe, opt_sync_frm, opt_allow_suspicious_udfs; extern my_bool opt_secure_auth; extern char* opt_secure_file_priv; -extern my_bool opt_log_slow_admin_statements; +extern my_bool opt_log_slow_admin_statements, opt_log_slow_slave_statements; extern my_bool sp_automatic_privileges, opt_noacl; extern my_bool opt_old_style_user_limits, trust_function_creators; extern uint opt_crash_binlog_innodb; diff -ur mysql-5.0.44/sql/my_time.c mysql-5.0.44-microslow/sql/my_time.c --- mysql-5.0.44/sql/my_time.c 2007-06-21 03:23:42.000000000 -0400 +++ mysql-5.0.44-microslow/sql/my_time.c 2007-08-17 15:58:57.000000000 -0400 @@ -1250,3 +1250,37 @@ return 0; } +/* + int my_timer(ulonglong *ltime, ulonglong frequency) + + For performance measurement this function returns the number + of microseconds since the epoch (SVr4, BSD 4.3, POSIX 1003.1-2001) + or system start (Windows platforms). + + For windows platforms frequency value (obtained via + QueryPerformanceFrequency) has to be specified. The global frequency + value is set in mysqld.cc. + + If Windows platform doesn't support QueryPerformanceFrequency we will + obtain the time via GetClockCount, which supports microseconds only. +*/ + +ulonglong my_timer(ulonglong *ltime, ulonglong frequency) +{ + ulonglong newtime= 0; +#ifdef __WIN__ + if (frequency) + { + QueryPerformanceCounter((LARGE_INTEGER *)&newtime); + newtime/= (frequency / 1000000); + } else + newtime= (GetTickCount() * 1000); /* GetTickCount only returns milliseconds */ +#else + struct timeval t; + gettimeofday(&t, NULL); + newtime= (ulonglong)t.tv_sec * 1000000 + t.tv_usec; +#endif + if (ltime) + *ltime= newtime; + return newtime; +} diff -ur mysql-5.0.44/sql/set_var.cc mysql-5.0.44-microslow/sql/set_var.cc --- mysql-5.0.44/sql/set_var.cc 2007-06-21 03:23:54.000000000 -0400 +++ mysql-5.0.44-microslow/sql/set_var.cc 2007-08-17 15:58:57.000000000 -0400 @@ -211,7 +211,7 @@ sys_log_queries_not_using_indexes("log_queries_not_using_indexes", &opt_log_queries_not_using_indexes); sys_var_thd_ulong sys_log_warnings("log_warnings", &SV::log_warnings); -sys_var_thd_ulong sys_long_query_time("long_query_time", +sys_var_thd_ulonglong sys_long_query_time("long_query_time", &SV::long_query_time); sys_var_thd_bool sys_low_priority_updates("low_priority_updates", &SV::low_priority_updates, @@ -276,6 +276,8 @@ &SV::max_tmp_tables); sys_var_long_ptr sys_max_write_lock_count("max_write_lock_count", &max_write_lock_count); +sys_var_thd_ulong sys_min_examined_row_limit("min_examined_row_limit", + &SV::min_examined_row_limit); sys_var_thd_ulong sys_multi_range_count("multi_range_count", &SV::multi_range_count); sys_var_long_ptr sys_myisam_data_pointer_size("myisam_data_pointer_size", @@ -686,6 +688,7 @@ &sys_max_tmp_tables, &sys_max_user_connections, &sys_max_write_lock_count, + &sys_min_examined_row_limit, &sys_multi_range_count, &sys_myisam_data_pointer_size, &sys_myisam_max_sort_file_size, @@ -978,6 +981,7 @@ {sys_max_tmp_tables.name, (char*) &sys_max_tmp_tables, SHOW_SYS}, {sys_max_user_connections.name,(char*) &sys_max_user_connections, SHOW_SYS}, {sys_max_write_lock_count.name, (char*) &sys_max_write_lock_count,SHOW_SYS}, + {sys_min_examined_row_limit.name, (char*) &sys_min_examined_row_limit, SHOW_SYS}, {sys_multi_range_count.name, (char*) &sys_multi_range_count, SHOW_SYS}, {sys_myisam_data_pointer_size.name, (char*) &sys_myisam_data_pointer_size, SHOW_SYS}, {sys_myisam_max_sort_file_size.name, (char*) &sys_myisam_max_sort_file_size, @@ -1567,6 +1571,53 @@ return (byte*) &(thd->variables.*offset); } +void sys_var_thd_microtime::set_default(THD *thd, enum_var_type type) +{ + pthread_mutex_lock(&LOCK_global_system_variables); + global_system_variables.*offset= (ulonglong) option_limits->def_value; + pthread_mutex_unlock(&LOCK_global_system_variables); +} + +bool sys_var_thd_microtime::check(THD *thd, set_var *var) +{ + if (var->value->result_type() == DECIMAL_RESULT) + var->save_result.ulonglong_value= (ulonglong)(var->value->val_real() * 1000000); + else + var->save_result.ulonglong_value= (ulonglong)var->value->val_int() * 1000000; + return 0; +} + +byte *sys_var_thd_microtime::value_ptr(THD *thd, enum_var_type type, + LEX_STRING *base) +{ + if (type == OPT_GLOBAL) + return (byte*) &(global_system_variables.*offset); + return (byte*) &(thd->variables.*offset); +} + +bool sys_var_thd_microtime::update(THD *thd, set_var *var) +{ + ulonglong tmp= var->save_result.ulonglong_value; + + if (tmp > max_system_variables.*offset) + tmp= max_system_variables.*offset; + + if (option_limits) + tmp= getopt_ull_limit_value(tmp, option_limits); + + /* Lock is needed to make things safe on 32 bit systems */ + if (var->type == OPT_GLOBAL) + { + /* Lock is needed to make things safe on 32 bit systems */ + pthread_mutex_lock(&LOCK_global_system_variables); + global_system_variables.*offset= tmp; + pthread_mutex_unlock(&LOCK_global_system_variables); + } + else + thd->variables.*offset= (ulonglong) tmp; + + return 0; +} bool sys_var_thd_ha_rows::update(THD *thd, set_var *var) { diff -ur mysql-5.0.44/sql/set_var.h mysql-5.0.44-microslow/sql/set_var.h --- mysql-5.0.44/sql/set_var.h 2007-06-21 03:23:43.000000000 -0400 +++ mysql-5.0.44-microslow/sql/set_var.h 2007-08-17 15:58:57.000000000 -0400 @@ -123,6 +123,7 @@ }; + class sys_var_ulonglong_ptr :public sys_var { public: @@ -287,7 +288,6 @@ } }; - class sys_var_thd_ulong :public sys_var_thd { sys_check_func check_func; @@ -307,6 +307,23 @@ byte *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base); }; +class sys_var_thd_microtime :public sys_var_thd +{ +public: + ulonglong SV::*offset; + sys_var_thd_microtime(const char *name_arg, ulonglong SV::*offset_arg) + :sys_var_thd(name_arg), offset(offset_arg) + {} + bool update(THD *thd, set_var *var); + void set_default(THD *thd, enum_var_type type); + SHOW_TYPE type() { return SHOW_MICROTIME; } + byte *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base); + bool check(THD *thd, set_var *var); + bool check_update_type(Item_result type) + { + return type != INT_RESULT && type != DECIMAL_RESULT; + } +}; class sys_var_thd_ha_rows :public sys_var_thd { @@ -325,7 +342,6 @@ byte *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base); }; - class sys_var_thd_ulonglong :public sys_var_thd { public: @@ -353,7 +369,6 @@ } }; - class sys_var_thd_bool :public sys_var_thd { public: diff -ur mysql-5.0.44/sql/slave.cc mysql-5.0.44-microslow/sql/slave.cc --- mysql-5.0.44/sql/slave.cc 2007-06-21 03:23:31.000000000 -0400 +++ mysql-5.0.44-microslow/sql/slave.cc 2007-08-17 15:58:57.000000000 -0400 @@ -2907,6 +2907,8 @@ + MAX_LOG_EVENT_HEADER; /* note, incr over the global not session var */ thd->slave_thread = 1; set_slave_thread_options(thd); + if (opt_log_slow_slave_statements) + thd->enable_slow_log= TRUE; thd->client_capabilities = CLIENT_LOCAL_FILES; thd->real_id=pthread_self(); pthread_mutex_lock(&LOCK_thread_count); diff -ur mysql-5.0.44/sql/sql_class.cc mysql-5.0.44-microslow/sql/sql_class.cc --- mysql-5.0.44/sql/sql_class.cc 2007-06-21 03:24:03.000000000 -0400 +++ mysql-5.0.44-microslow/sql/sql_class.cc 2007-08-17 15:58:57.000000000 -0400 @@ -173,7 +173,7 @@ Open_tables_state(refresh_version), lock_id(&main_lock_id), user_time(0), in_sub_stmt(0), global_read_lock(0), is_fatal_error(0), - rand_used(0), time_zone_used(0), + rand_used(0), time_zone_used(0), user_timer(0), last_insert_id_used(0), last_insert_id_used_bin_log(0), insert_id_used(0), clear_next_insert_id(0), in_lock_tables(0), bootstrap(0), derived_tables_processing(FALSE), spcont(NULL), m_lip(NULL) diff -ur mysql-5.0.44/sql/sql_class.h mysql-5.0.44-microslow/sql/sql_class.h --- mysql-5.0.44/sql/sql_class.h 2007-06-21 03:24:03.000000000 -0400 +++ mysql-5.0.44-microslow/sql/sql_class.h 2007-08-17 15:58:57.000000000 -0400 @@ -43,6 +43,13 @@ extern char internal_table_name[2]; extern char empty_c_string[1]; extern const char **errmesg; +#ifdef __cplusplus +__BEGIN_DECLS +#endif +extern ulonglong frequency; +#ifdef __cplusplus +__END_DECLS +#endif #define TC_LOG_PAGE_SIZE 8192 #define TC_LOG_MIN_SIZE (3*TC_LOG_PAGE_SIZE) @@ -308,7 +315,7 @@ bool write(THD *thd, enum enum_server_command command, const char *format, ...) ATTRIBUTE_FORMAT(printf, 4, 5); bool write(THD *thd, const char *query, uint query_length, - time_t query_start=0); + time_t query_start=0, ulonglong query_start_timer=0); bool write(Log_event* event_info); // binary log write bool write(THD *thd, IO_CACHE *cache, Log_event *commit_event); @@ -514,13 +521,14 @@ ulong auto_increment_increment, auto_increment_offset; ulong bulk_insert_buff_size; ulong join_buff_size; - ulong long_query_time; + ulonglong long_query_time; ulong max_allowed_packet; ulong max_error_count; ulong max_length_for_sort_data; ulong max_sort_length; ulong max_tmp_tables; ulong max_insert_delayed_threads; + ulong min_examined_row_limit; ulong multi_range_count; ulong myisam_repair_threads; ulong myisam_sort_buff_size; @@ -1141,6 +1149,11 @@ class THD :public Statement, public Open_tables_state { +private: + inline ulonglong query_start_timer() { return start_timer; } + inline void set_timer() { if (user_timer) start_timer=timer_after_lock=user_timer; else timer_after_lock=my_timer(&start_timer, frequency); } + inline void end_timer() { my_timer(&start_timer, frequency); } + inline void lock_timer() { my_timer(&timer_after_lock, frequency); } public: /* Constant for THD::where initialization in the beginning of every query. @@ -1246,6 +1259,7 @@ */ const char *where; time_t start_time,time_after_lock,user_time; + ulonglong start_timer,timer_after_lock, user_timer; time_t connect_time,thr_create_time; // track down slow pthread_create thr_lock_type update_lock_default; Delayed_insert *di; @@ -1581,11 +1595,11 @@ proc_info = old_msg; pthread_mutex_unlock(&mysys_var->mutex); } - inline time_t query_start() { query_start_used=1; return start_time; } - inline void set_time() { if (user_time) start_time=time_after_lock=user_time; else time_after_lock=time(&start_time); } - inline void end_time() { time(&start_time); } - inline void set_time(time_t t) { time_after_lock=start_time=user_time=t; } - inline void lock_time() { time(&time_after_lock); } + inline time_t query_start() { query_start_timer(); query_start_used=1; return start_time; } + inline void set_time() { set_timer(); if (user_time) start_time=time_after_lock=user_time; else time_after_lock=time(&start_time); } + inline void end_time() { end_timer(); time(&start_time); } + inline void set_time(time_t t) { set_timer(); time_after_lock=start_time=user_time=t; } + inline void lock_time() { lock_timer(); time(&time_after_lock); } inline void insert_id(ulonglong id_arg) { last_insert_id= id_arg; diff -ur mysql-5.0.44/sql/sql_parse.cc mysql-5.0.44-microslow/sql/sql_parse.cc --- mysql-5.0.44/sql/sql_parse.cc 2007-06-21 03:24:03.000000000 -0400 +++ mysql-5.0.44-microslow/sql/sql_parse.cc 2007-08-17 16:07:21.000000000 -0400 @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef HAVE_INNOBASE_DB #include "ha_innodb.h" @@ -2193,26 +2194,30 @@ return; // Don't set time for sub stmt start_of_query= thd->start_time; + ulonglong start_of_query_timer= thd->start_timer; thd->end_time(); // Set start time /* Do not log administrative statements unless the appropriate option is set; do not log into slow log if reading from backup. */ - if (thd->enable_slow_log && !thd->user_time) + if (thd->enable_slow_log && + (!thd->user_time || (thd->slave_thread && opt_log_slow_slave_statements)) + ) { thd->proc_info="logging slow query"; - if ((ulong) (thd->start_time - thd->time_after_lock) > - thd->variables.long_query_time || - (thd->server_status & - (SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED)) && - (specialflag & SPECIAL_LOG_QUERIES_NOT_USING_INDEXES) && - /* == SQLCOM_END unless this is a SHOW command */ - thd->lex->orig_sql_command == SQLCOM_END) + if (((ulong) (thd->start_timer - thd->timer_after_lock) >= + thd->variables.long_query_time || + (thd->server_status & + (SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED)) && + (specialflag & SPECIAL_LOG_QUERIES_NOT_USING_INDEXES) && + /* == SQLCOM_END unless this is a SHOW command */ + thd->lex->orig_sql_command == SQLCOM_END) && + thd->examined_row_count >= thd->variables.min_examined_row_limit) { thd->status_var.long_query_count++; - mysql_slow_log.write(thd, thd->query, thd->query_length, start_of_query); + mysql_slow_log.write(thd, thd->query, thd->query_length, start_of_query, start_of_query_timer); } } } diff -ur mysql-5.0.44/sql/sql_show.cc mysql-5.0.44-microslow/sql/sql_show.cc --- mysql-5.0.44/sql/sql_show.cc 2007-06-21 03:23:42.000000000 -0400 +++ mysql-5.0.44-microslow/sql/sql_show.cc 2007-08-17 15:58:57.000000000 -0400 @@ -1468,6 +1468,9 @@ case SHOW_LONGLONG: end= longlong10_to_str(*(longlong*) value, buff, 10); break; + case SHOW_MICROTIME: + end= buff + sprintf(buff, "%.6f", (*(ulonglong*)value) / 1000000.0); + break; case SHOW_HA_ROWS: end= longlong10_to_str((longlong) *(ha_rows*) value, buff, 10); break; diff -ur mysql-5.0.44/sql/structs.h mysql-5.0.44-microslow/sql/structs.h --- mysql-5.0.44/sql/structs.h 2007-06-21 03:23:43.000000000 -0400 +++ mysql-5.0.44-microslow/sql/structs.h 2007-08-17 15:58:57.000000000 -0400 @@ -168,8 +168,8 @@ enum SHOW_TYPE { SHOW_UNDEF, - SHOW_LONG, SHOW_LONGLONG, SHOW_INT, SHOW_CHAR, SHOW_CHAR_PTR, - SHOW_DOUBLE_STATUS, + SHOW_LONG, SHOW_LONGLONG, SHOW_MICROTIME, SHOW_INT, SHOW_CHAR, + SHOW_CHAR_PTR, SHOW_DOUBLE_STATUS, SHOW_BOOL, SHOW_MY_BOOL, SHOW_OPENTABLES, SHOW_STARTTIME, SHOW_QUESTION, SHOW_LONG_CONST, SHOW_INT_CONST, SHOW_HAVE, SHOW_SYS, SHOW_HA_ROWS, SHOW_VARS, diff -ur mysql-5.0.44/sql-common/my_time.c mysql-5.0.44-microslow/sql-common/my_time.c --- mysql-5.0.44/sql-common/my_time.c 2007-06-21 03:23:42.000000000 -0400 +++ mysql-5.0.44-microslow/sql-common/my_time.c 2007-08-17 15:58:57.000000000 -0400 @@ -1250,3 +1250,37 @@ return 0; } +/* + int my_timer(ulonglong *ltime, ulonglong frequency) + + For performance measurement this function returns the number + of microseconds since the epoch (SVr4, BSD 4.3, POSIX 1003.1-2001) + or system start (Windows platforms). + + For windows platforms frequency value (obtained via + QueryPerformanceFrequency) has to be specified. The global frequency + value is set in mysqld.cc. + + If Windows platform doesn't support QueryPerformanceFrequency we will + obtain the time via GetClockCount, which supports microseconds only. +*/ + +ulonglong my_timer(ulonglong *ltime, ulonglong frequency) +{ + ulonglong newtime= 0; +#ifdef __WIN__ + if (frequency) + { + QueryPerformanceCounter((LARGE_INTEGER *)&newtime); + newtime/= (frequency * 1000000); + } else + newtime= (GetTickCount() * 1000; /* GetTickCount only returns milliseconds */ +#else + struct timeval t; + gettimeofday(&t, NULL); + newtime= (ulonglong)t.tv_sec * 1000000 + t.tv_usec; +#endif + if (ltime) + *ltime= newtime; + return newtime; +}