-diff -r bb81fcdd7db2 include/my_time.h
---- a/include/my_time.h Mon Sep 08 16:38:33 2008 -0700
-+++ b/include/my_time.h Mon Sep 08 16:38:46 2008 -0700
+diff -r 1242d4575291 include/my_getopt.h
+--- a/include/my_getopt.h Tue Jul 28 23:39:12 2009 -0700
++++ b/include/my_getopt.h Tue Jul 28 23:42:44 2009 -0700
+@@ -28,7 +28,8 @@
+ #define GET_ULL 8
+ #define GET_STR 9
+ #define GET_STR_ALLOC 10
+-#define GET_DISABLED 11
++#define GET_MICROTIME 11
++#define GET_DISABLED 12
+
+ #define GET_ASK_ADDR 128
+ #define GET_TYPE_MASK 127
+diff -r 1242d4575291 include/my_time.h
+--- a/include/my_time.h Tue Jul 28 23:39:12 2009 -0700
++++ b/include/my_time.h Tue Jul 28 23:42:44 2009 -0700
@@ -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);
C_MODE_END
#endif /* _my_time_h_ */
-diff -r bb81fcdd7db2 innobase/buf/buf0buf.c
---- a/innobase/buf/buf0buf.c Mon Sep 08 16:38:33 2008 -0700
-+++ b/innobase/buf/buf0buf.c Mon Sep 08 16:38:46 2008 -0700
-@@ -37,6 +37,7 @@
+diff -r 1242d4575291 innobase/buf/buf0buf.c
+--- a/innobase/buf/buf0buf.c Tue Jul 28 23:39:12 2009 -0700
++++ b/innobase/buf/buf0buf.c Tue Jul 28 23:42:44 2009 -0700
+@@ -37,6 +37,10 @@
#include "log0log.h"
#include "trx0undo.h"
#include "srv0srv.h"
-+#include "thr0loc.h"
++#include "trx0trx.h"
++
++/* prototypes for new functions added to ha_innodb.cc */
++trx_t* innobase_get_trx();
/*
IMPLEMENTATION OF THE BUFFER POOL
-@@ -1086,6 +1087,31 @@
+@@ -1086,6 +1090,36 @@
return(block);
}
+
+ ut_ad(block);
+
-+ if (!trx || !trx->distinct_page_access_hash)
++ if (!srv_slow_log || !trx || !trx->take_stats)
+ return;
+
++ if (!trx->distinct_page_access_hash) {
++ trx->distinct_page_access_hash = mem_alloc(DPAH_SIZE);
++ memset(trx->distinct_page_access_hash, 0, DPAH_SIZE);
++ }
++
+ block_hash = ut_hash_ulint((block->space << 20) + block->space +
+ block->offset, DPAH_SIZE << 3);
+ block_hash_byte = block_hash >> 3;
/************************************************************************
This is the general function used to get access to a database page. */
-@@ -1108,6 +1134,11 @@
+@@ -1108,6 +1142,11 @@
ulint fix_type;
ibool success;
ibool must_read;
-+ trx_t* trx;
++ trx_t* trx = NULL;
+ ulint sec;
+ ulint ms;
+ ib_longlong start_time;
ut_ad(mtr);
ut_ad((rw_latch == RW_S_LATCH)
-@@ -1119,6 +1150,7 @@
+@@ -1119,6 +1158,9 @@
#ifndef UNIV_LOG_DEBUG
ut_ad(!ibuf_inside() || ibuf_page(space, offset));
#endif
-+ trx = thr_local_get_trx(os_thread_get_curr_id());
++ if (srv_slow_log) {
++ trx = innobase_get_trx();
++ }
buf_pool->n_page_gets++;
loop:
block = NULL;
-@@ -1148,7 +1180,7 @@
+@@ -1148,7 +1190,7 @@
return(NULL);
}
#ifdef UNIV_DEBUG
buf_dbg_counter++;
-@@ -1261,6 +1293,11 @@
+@@ -1261,6 +1303,11 @@
/* Let us wait until the read operation
completes */
-+ if (trx)
++ if (srv_slow_log && trx && trx->take_stats)
+ {
+ ut_usectime(&sec, &ms);
+ start_time = (ib_longlong)sec * 1000000 + ms;
for (;;) {
mutex_enter(&block->mutex);
-@@ -1275,6 +1312,12 @@
-
+@@ -1276,6 +1323,12 @@
break;
}
-+ }
-+ if (trx)
+ }
++ if (srv_slow_log && trx && trx->take_stats && start_time)
+ {
+ ut_usectime(&sec, &ms);
+ finish_time = (ib_longlong)sec * 1000000 + ms;
+ trx->io_reads_wait_timer += (ulint)(finish_time - start_time);
- }
++ }
}
-@@ -1296,12 +1339,15 @@
+ fix_type = MTR_MEMO_BUF_FIX;
+@@ -1296,12 +1349,17 @@
/* In the case of a first access, try to apply linear
read-ahead */
ut_a(ibuf_count_get(block->space, block->offset) == 0);
#endif
+
-+ _increment_page_get_statistics(block, trx);
++ if (srv_slow_log) {
++ _increment_page_get_statistics(block, trx);
++ }
+
return(block->frame);
}
-@@ -1326,6 +1372,7 @@
+@@ -1326,6 +1384,7 @@
ibool accessed;
ibool success;
ulint fix_type;
-+ trx_t* trx;
++ trx_t* trx = NULL;
ut_ad(mtr && block);
ut_ad((rw_latch == RW_S_LATCH) || (rw_latch == RW_X_LATCH));
-@@ -1440,13 +1487,16 @@
+@@ -1440,7 +1499,7 @@
read-ahead */
buf_read_ahead_linear(buf_frame_get_space_id(guess),
}
#ifdef UNIV_IBUF_DEBUG
- ut_a(ibuf_count_get(block->space, block->offset) == 0);
+@@ -1448,6 +1507,11 @@
#endif
buf_pool->n_page_gets++;
-+
-+ trx = thr_local_get_trx(os_thread_get_curr_id());
-+ _increment_page_get_statistics(block, trx);
++ if (srv_slow_log) {
++ trx = innobase_get_trx();
++ _increment_page_get_statistics(block, trx);
++ }
++
return(TRUE);
}
-@@ -1470,6 +1520,7 @@
+
+@@ -1470,6 +1534,7 @@
buf_block_t* block;
ibool success;
ulint fix_type;
-+ trx_t* trx;
++ trx_t* trx = NULL;
ut_ad(mtr);
ut_ad((rw_latch == RW_S_LATCH) || (rw_latch == RW_X_LATCH));
-@@ -1558,6 +1609,9 @@
- || (ibuf_count_get(block->space, block->offset) == 0));
+@@ -1559,6 +1624,11 @@
#endif
buf_pool->n_page_gets++;
-+
-+ trx = thr_local_get_trx(os_thread_get_curr_id());
-+ _increment_page_get_statistics(block, trx);
++ if (srv_slow_log) {
++ trx = innobase_get_trx();
++ _increment_page_get_statistics(block, trx);
++ }
++
return(TRUE);
}
-diff -r bb81fcdd7db2 innobase/buf/buf0rea.c
---- a/innobase/buf/buf0rea.c Mon Sep 08 16:38:33 2008 -0700
-+++ b/innobase/buf/buf0rea.c Mon Sep 08 16:38:46 2008 -0700
+
+diff -r 1242d4575291 innobase/buf/buf0rea.c
+--- a/innobase/buf/buf0rea.c Tue Jul 28 23:39:12 2009 -0700
++++ b/innobase/buf/buf0rea.c Tue Jul 28 23:42:44 2009 -0700
@@ -70,7 +70,8 @@
treat the tablespace as dropped; this is a timestamp we
use to stop dangling page reads from a tablespace
}
}
-diff -r bb81fcdd7db2 innobase/fil/fil0fil.c
---- a/innobase/fil/fil0fil.c Mon Sep 08 16:38:33 2008 -0700
-+++ b/innobase/fil/fil0fil.c Mon Sep 08 16:38:46 2008 -0700
+diff -r 1242d4575291 innobase/fil/fil0fil.c
+--- a/innobase/fil/fil0fil.c Tue Jul 28 23:39:12 2009 -0700
++++ b/innobase/fil/fil0fil.c Tue Jul 28 23:42:44 2009 -0700
@@ -3527,7 +3527,7 @@
node->name, node->handle, buf,
offset_low, offset_high,
#endif
ut_a(ret);
-diff -r bb81fcdd7db2 innobase/include/buf0rea.h
---- a/innobase/include/buf0rea.h Mon Sep 08 16:38:33 2008 -0700
-+++ b/innobase/include/buf0rea.h Mon Sep 08 16:38:46 2008 -0700
+diff -r 1242d4575291 innobase/include/buf0rea.h
+--- a/innobase/include/buf0rea.h Tue Jul 28 23:39:12 2009 -0700
++++ b/innobase/include/buf0rea.h Tue Jul 28 23:42:44 2009 -0700
@@ -10,6 +10,7 @@
#define buf0rea_h
/************************************************************************
Issues read requests for pages which the ibuf module wants to read in, in
order to contract the insert buffer tree. Technically, this function is like
-diff -r bb81fcdd7db2 innobase/include/fil0fil.h
---- a/innobase/include/fil0fil.h Mon Sep 08 16:38:33 2008 -0700
-+++ b/innobase/include/fil0fil.h Mon Sep 08 16:38:46 2008 -0700
+diff -r 1242d4575291 innobase/include/fil0fil.h
+--- a/innobase/include/fil0fil.h Tue Jul 28 23:39:12 2009 -0700
++++ b/innobase/include/fil0fil.h Tue Jul 28 23:42:44 2009 -0700
@@ -534,8 +534,11 @@
/************************************************************************
Reads or writes data. This operation is asynchronous (aio). */
/************************************************************************
Reads data from a space to a buffer. Remember that the possible incomplete
blocks at the end of file are ignored: they are not taken into account when
-diff -r bb81fcdd7db2 innobase/include/os0file.h
---- a/innobase/include/os0file.h Mon Sep 08 16:38:33 2008 -0700
-+++ b/innobase/include/os0file.h Mon Sep 08 16:38:46 2008 -0700
-@@ -10,6 +10,8 @@
- #define os0file_h
+diff -r 1242d4575291 innobase/include/os0file.h
+--- a/innobase/include/os0file.h Tue Jul 28 23:39:12 2009 -0700
++++ b/innobase/include/os0file.h Tue Jul 28 23:42:44 2009 -0700
+@@ -11,6 +11,8 @@
#include "univ.i"
-+
-+#include "trx0types.h"
++#include "trx0types.h"
++
#ifndef __WIN__
#include <dirent.h>
+ #include <sys/stat.h>
@@ -421,8 +423,11 @@
/***********************************************************************
Requests a synchronous read operation. */
/****************************************************************************
Wakes up all async i/o threads so that they know to exit themselves in
shutdown. */
-diff -r bb81fcdd7db2 innobase/include/thr0loc.h
---- a/innobase/include/thr0loc.h Mon Sep 08 16:38:33 2008 -0700
-+++ b/innobase/include/thr0loc.h Mon Sep 08 16:38:46 2008 -0700
-@@ -15,6 +15,7 @@
+diff -r 1242d4575291 innobase/include/srv0srv.h
+--- a/innobase/include/srv0srv.h Tue Jul 28 23:39:12 2009 -0700
++++ b/innobase/include/srv0srv.h Tue Jul 28 23:42:44 2009 -0700
+@@ -27,6 +27,8 @@
+ #define SRV_AUTO_EXTEND_INCREMENT \
+ (srv_auto_extend_increment * ((1024 * 1024) / UNIV_PAGE_SIZE))
- #include "univ.i"
- #include "os0thread.h"
-+#include "trx0trx.h"
-
- /********************************************************************
- Initializes the thread local storage module. */
-@@ -36,6 +37,14 @@
- /*===========*/
- os_thread_id_t id); /* in: thread id */
- /***********************************************************************
-+Gets trx */
++extern ibool srv_slow_log;
+
-+trx_t*
-+thr_local_get_trx(
-+/*==================*/
-+ /* out: trx for mysql */
-+ os_thread_id_t id); /* in: thread id of the thread */
-+/***********************************************************************
- Gets the slot number in the thread table of a thread. */
+ /* This is set to TRUE if the MySQL user has set it in MySQL */
+ extern ibool srv_lower_case_table_names;
- ulint
-@@ -43,6 +52,14 @@
- /*==================*/
- /* out: slot number */
- os_thread_id_t id); /* in: thread id of the thread */
-+/***********************************************************************
-+Sets in the local storage the slot number in the thread table of a thread. */
-+
-+void
-+thr_local_set_trx(
-+/*==================*/
-+ os_thread_id_t id, /* in: thread id of the thread */
-+ trx_t* trx); /* in: slot number */
- /***********************************************************************
- Sets in the local storage the slot number in the thread table of a thread. */
-
-diff -r bb81fcdd7db2 innobase/include/trx0trx.h
---- a/innobase/include/trx0trx.h Mon Sep 08 16:38:33 2008 -0700
-+++ b/innobase/include/trx0trx.h Mon Sep 08 16:38:46 2008 -0700
+diff -r 1242d4575291 innobase/include/trx0trx.h
+--- a/innobase/include/trx0trx.h Tue Jul 28 23:39:12 2009 -0700
++++ b/innobase/include/trx0trx.h Tue Jul 28 23:42:44 2009 -0700
@@ -668,6 +668,17 @@
/*------------------------------*/
char detailed_error[256]; /* detailed error message for last
error, or empty. */
+ /*------------------------------*/
-+ os_thread_id_t trx_thread_id;
+ ulint io_reads;
+ ib_longlong io_read;
+ ulint io_reads_wait_timer;
+ ulint distinct_page_access;
+#define DPAH_SIZE 8192
+ byte* distinct_page_access_hash;
++ ibool take_stats;
};
#define TRX_MAX_N_THREADS 32 /* maximum number of concurrent
-diff -r bb81fcdd7db2 innobase/lock/lock0lock.c
---- a/innobase/lock/lock0lock.c Mon Sep 08 16:38:33 2008 -0700
-+++ b/innobase/lock/lock0lock.c Mon Sep 08 16:38:46 2008 -0700
+diff -r 1242d4575291 innobase/lock/lock0lock.c
+--- a/innobase/lock/lock0lock.c Tue Jul 28 23:39:12 2009 -0700
++++ b/innobase/lock/lock0lock.c Tue Jul 28 23:42:44 2009 -0700
@@ -1806,6 +1806,8 @@
{
lock_t* lock;
#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
-@@ -1861,6 +1863,8 @@
+@@ -1861,6 +1863,10 @@
trx->que_state = TRX_QUE_LOCK_WAIT;
trx->was_chosen_as_deadlock_victim = FALSE;
trx->wait_started = time(NULL);
-+ ut_usectime(&sec, &ms);
-+ trx->lock_que_wait_ustarted = (ib_longlong)sec * 1000000 + ms;
++ if (srv_slow_log && trx->take_stats) {
++ ut_usectime(&sec, &ms);
++ trx->lock_que_wait_ustarted = (ib_longlong)sec * 1000000 + ms;
++ }
ut_a(que_thr_stop(thr));
-@@ -3514,7 +3518,9 @@
+@@ -3514,7 +3520,9 @@
{
lock_t* lock;
trx_t* trx;
#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
#endif /* UNIV_SYNC_DEBUG */
-@@ -3563,7 +3569,10 @@
-
+@@ -3564,6 +3572,10 @@
return(DB_SUCCESS);
}
--
-+
-+ trx->wait_started = time(NULL);
-+ ut_usectime(&sec, &ms);
-+ trx->lock_que_wait_ustarted = (ib_longlong)sec * 1000000 + ms;
+
++ if (srv_slow_log && trx->take_stats) {
++ ut_usectime(&sec, &ms);
++ trx->lock_que_wait_ustarted = (ib_longlong)sec * 1000000 + ms;
++ }
trx->que_state = TRX_QUE_LOCK_WAIT;
trx->was_chosen_as_deadlock_victim = FALSE;
trx->wait_started = time(NULL);
-@@ -4289,7 +4298,7 @@
- ulint i;
- mtr_t mtr;
- trx_t* trx;
--
-+
- fprintf(file, "LIST OF TRANSACTIONS FOR EACH SESSION:\n");
-
- /* First print info on non-active transactions */
-diff -r bb81fcdd7db2 innobase/os/os0file.c
---- a/innobase/os/os0file.c Mon Sep 08 16:38:33 2008 -0700
-+++ b/innobase/os/os0file.c Mon Sep 08 16:38:46 2008 -0700
-@@ -14,6 +14,7 @@
+diff -r 1242d4575291 innobase/os/os0file.c
+--- a/innobase/os/os0file.c Tue Jul 28 23:39:12 2009 -0700
++++ b/innobase/os/os0file.c Tue Jul 28 23:42:44 2009 -0700
+@@ -14,6 +14,8 @@
#include "srv0start.h"
#include "fil0fil.h"
#include "buf0buf.h"
+#include "trx0sys.h"
++#include "trx0trx.h"
#if defined(UNIV_HOTBACKUP) && defined(__WIN__)
/* Add includes for the _stat() call to compile on Windows */
-@@ -101,6 +102,7 @@
- struct aiocb control; /* Posix control block for aio
- request */
- #endif
-+ trx_t* trx;
- };
-
- /* The aio array structure */
@@ -1903,9 +1905,13 @@
#ifndef __WIN__
/***********************************************************************
os_n_file_reads++;
-
-+ if (trx)
++ if (srv_slow_log && trx && trx->take_stats)
+ {
+ trx->io_reads++;
+ trx->io_read += n;
os_n_pending_reads--;
os_mutex_exit(os_file_count_mutex);
-+ if (trx)
++ if (srv_slow_log && trx && trx->take_stats && start_time)
+ {
+ ut_usectime(&sec, &ms);
+ finish_time = (ib_longlong)sec * 1000000 + ms;
return(n_bytes);
#else
{
-@@ -1980,6 +2004,13 @@
- os_mutex_enter(os_file_count_mutex);
+@@ -1981,6 +2005,13 @@
os_n_pending_reads--;
os_mutex_exit(os_file_count_mutex);
-+
-+ if (trx)
+
++ if (srv_slow_log && trx && trx->take_stats && start_time)
+ {
+ ut_usectime(&sec, &ms);
+ finish_time = (ib_longlong)sec * 1000000 + ms;
+ trx->io_reads_wait_timer += (ulint)(finish_time - start_time);
+ }
-
++
return(ret);
}
+ #endif
@@ -2103,7 +2134,7 @@
Requests a synchronous positioned read operation. */
{
#ifdef __WIN__
BOOL ret;
-@@ -2128,8 +2160,7 @@
-
- os_n_file_reads++;
- os_bytes_read_since_printout += n;
--
--try_again:
-+try_again:
- ut_ad(file);
- ut_ad(buf);
- ut_ad(n > 0);
-@@ -2177,7 +2208,7 @@
+@@ -2177,7 +2209,7 @@
os_bytes_read_since_printout += n;
try_again:
if ((ulint)ret == n) {
-@@ -3137,7 +3168,8 @@
+@@ -3137,7 +3169,8 @@
offset */
ulint offset_high, /* in: most significant 32 bits of
offset */
{
os_aio_slot_t* slot;
#ifdef WIN_ASYNC_IO
-@@ -3196,7 +3228,7 @@
- slot->offset = offset;
- slot->offset_high = offset_high;
- slot->io_already_done = FALSE;
--
-+
- #ifdef WIN_ASYNC_IO
- control = &(slot->control);
- control->Offset = (DWORD)offset;
-@@ -3390,7 +3422,8 @@
+@@ -3390,7 +3423,8 @@
can be used to identify a completed aio
operation); if mode is OS_AIO_SYNC, these
are ignored */
{
os_aio_array_t* array;
os_aio_slot_t* slot;
-@@ -3429,8 +3462,8 @@
+@@ -3429,8 +3463,8 @@
wait in the Windows case. */
if (type == OS_FILE_READ) {
}
ut_a(type == OS_FILE_WRITE);
-@@ -3463,14 +3496,19 @@
+@@ -3463,8 +3497,13 @@
ut_error;
}
if (type == OS_FILE_READ) {
if (os_aio_use_native_aio) {
#ifdef WIN_ASYNC_IO
- os_n_file_reads++;
- os_bytes_read_since_printout += len;
--
-+
- ret = ReadFile(file, buf, (DWORD)n, &len,
- &(slot->control));
- #elif defined(POSIX_ASYNC_IO)
-@@ -4038,7 +4076,7 @@
-
- ut_memcpy(consecutive_ios[i]->buf, combined_buf + offs,
- consecutive_ios[i]->len);
-- offs += consecutive_ios[i]->len;
-+ offs += consecutive_ios[i]->len;
- }
- }
-
-@@ -4050,9 +4088,8 @@
-
- /* Mark the i/os done in slots */
-
-- for (i = 0; i < n_consecutive; i++) {
-+ for (i = 0; i < n_consecutive; i++)
- consecutive_ios[i]->io_already_done = TRUE;
-- }
+diff -r 1242d4575291 innobase/srv/srv0srv.c
+--- a/innobase/srv/srv0srv.c Tue Jul 28 23:39:12 2009 -0700
++++ b/innobase/srv/srv0srv.c Tue Jul 28 23:42:44 2009 -0700
+@@ -48,6 +48,8 @@
+ #include "srv0start.h"
+ #include "row0mysql.h"
- /* We return the messages for the first slot now, and if there were
- several slots, the messages will be returned with subsequent calls
-diff -r bb81fcdd7db2 innobase/srv/srv0srv.c
---- a/innobase/srv/srv0srv.c Mon Sep 08 16:38:33 2008 -0700
-+++ b/innobase/srv/srv0srv.c Mon Sep 08 16:38:46 2008 -0700
-@@ -996,6 +996,10 @@
++ibool srv_slow_log = 0;
++
+ /* This is set to TRUE if the MySQL user has set it in MySQL; currently
+ affects only FOREIGN KEY definition parsing */
+ ibool srv_lower_case_table_names = FALSE;
+@@ -1002,6 +1004,10 @@
ibool has_slept = FALSE;
srv_conc_slot_t* slot = NULL;
ulint i;
/* If trx has 'free tickets' to enter the engine left, then use one
such ticket */
-@@ -1054,6 +1058,7 @@
+@@ -1060,6 +1066,7 @@
if (SRV_THREAD_SLEEP_DELAY > 0)
{
os_thread_sleep(SRV_THREAD_SLEEP_DELAY);
}
trx->op_info = "";
-@@ -1109,11 +1114,18 @@
+@@ -1115,12 +1122,23 @@
/* Go to wait for the event; when a thread leaves InnoDB it will
release this thread */
-+ ut_usectime(&sec, &ms);
-+ start_time = (ib_longlong)sec * 1000000 + ms;
++ if (srv_slow_log && trx->take_stats) {
++ ut_usectime(&sec, &ms);
++ start_time = (ib_longlong)sec * 1000000 + ms;
++ }
+
trx->op_info = "waiting in InnoDB queue";
os_event_wait(slot->event);
trx->op_info = "";
-+
-+ ut_usectime(&sec, &ms);
-+ finish_time = (ib_longlong)sec * 1000000 + ms;
-+ trx->innodb_que_wait_timer += (ulint)(finish_time - start_time);
-
- os_fast_mutex_lock(&srv_conc_mutex);
-diff -r bb81fcdd7db2 innobase/thr/thr0loc.c
---- a/innobase/thr/thr0loc.c Mon Sep 08 16:38:33 2008 -0700
-+++ b/innobase/thr/thr0loc.c Mon Sep 08 16:38:46 2008 -0700
-@@ -45,6 +45,7 @@
- for this thread */
- ibool in_ibuf;/* TRUE if the the thread is doing an ibuf
- operation */
-+ trx_t* trx;
- hash_node_t hash; /* hash chain node */
- ulint magic_n;
- };
-@@ -113,6 +114,29 @@
- }
-
- /***********************************************************************
-+Gets trx */
-+
-+trx_t*
-+thr_local_get_trx(
-+/*==================*/
-+ /* out: trx for mysql */
-+ os_thread_id_t id) /* in: thread id of the thread */
-+{
-+ trx_t* trx;
-+ thr_local_t* local;
-+
-+ mutex_enter(&thr_local_mutex);
-+
-+ local = thr_local_get(id);
-+
-+ trx = local->trx;
-+
-+ mutex_exit(&thr_local_mutex);
-+
-+ return(trx);
-+}
-+
-+/***********************************************************************
- Sets the slot number in the thread table of a thread. */
-
- void
-@@ -124,11 +148,31 @@
- thr_local_t* local;
-
- mutex_enter(&thr_local_mutex);
--
-+
- local = thr_local_get(id);
-
- local->slot_no = slot_no;
--
-+
-+ mutex_exit(&thr_local_mutex);
-+}
-+
-+/***********************************************************************
-+Sets trx */
-+
-+void
-+thr_local_set_trx(
-+/*==================*/
-+ os_thread_id_t id, /* in: thread id of the thread */
-+ trx_t* trx) /* in: trx */
-+{
-+ thr_local_t* local;
-+
-+ mutex_enter(&thr_local_mutex);
-+
-+ local = thr_local_get(id);
-+
-+ local->trx = trx;
++ if (srv_slow_log && trx->take_stats && start_time) {
++ ut_usectime(&sec, &ms);
++ finish_time = (ib_longlong)sec * 1000000 + ms;
++ trx->innodb_que_wait_timer += (ulint)(finish_time - start_time);
++ }
+
- mutex_exit(&thr_local_mutex);
- }
-
-@@ -172,6 +216,7 @@
- local->magic_n = THR_LOCAL_MAGIC_N;
-
- local->in_ibuf = FALSE;
-+ local->trx = NULL;
-
- mutex_enter(&thr_local_mutex);
+ os_fast_mutex_lock(&srv_conc_mutex);
-diff -r bb81fcdd7db2 innobase/trx/trx0trx.c
---- a/innobase/trx/trx0trx.c Mon Sep 08 16:38:33 2008 -0700
-+++ b/innobase/trx/trx0trx.c Mon Sep 08 16:38:46 2008 -0700
-@@ -190,6 +190,16 @@
+ srv_conc_n_waiting_threads--;
+diff -r 1242d4575291 innobase/trx/trx0trx.c
+--- a/innobase/trx/trx0trx.c Tue Jul 28 23:39:12 2009 -0700
++++ b/innobase/trx/trx0trx.c Tue Jul 28 23:42:44 2009 -0700
+@@ -190,6 +190,15 @@
trx->global_read_view_heap = mem_heap_create(256);
trx->global_read_view = NULL;
trx->read_view = NULL;
+ trx->innodb_que_wait_timer = 0;
+ trx->distinct_page_access = 0;
+ trx->distinct_page_access_hash = NULL;
-+ trx->trx_thread_id = os_thread_get_curr_id();
-+ thr_local_set_trx(trx->trx_thread_id, NULL);
++ trx->take_stats = FALSE;
/* Set X/Open XA transaction identification to NULL */
memset(&trx->xid, 0, sizeof(trx->xid));
-@@ -230,6 +240,10 @@
+@@ -230,6 +239,11 @@
trx->mysql_process_no = os_proc_get_number();
-+ trx->distinct_page_access_hash = mem_alloc(DPAH_SIZE);
-+ memset(trx->distinct_page_access_hash, 0, DPAH_SIZE);
-+ thr_local_set_trx(trx->mysql_thread_id, trx);
++ if (srv_slow_log && trx->take_stats) {
++ trx->distinct_page_access_hash = mem_alloc(DPAH_SIZE);
++ memset(trx->distinct_page_access_hash, 0, DPAH_SIZE);
++ }
+
return(trx);
}
-@@ -355,6 +369,8 @@
-
- ut_a(trx->read_view == NULL);
-
-+ thr_local_free(trx->trx_thread_id);
-+
- mem_free(trx);
- }
-
-@@ -366,6 +382,12 @@
+@@ -366,6 +380,12 @@
/*===============*/
trx_t* trx) /* in, own: trx object */
{
thr_local_free(trx->mysql_thread_id);
mutex_enter(&kernel_mutex);
-@@ -1064,7 +1086,10 @@
+@@ -389,6 +409,12 @@
+ /*====================*/
+ trx_t* trx) /* in, own: trx object */
+ {
++ if (trx->distinct_page_access_hash)
++ {
++ mem_free(trx->distinct_page_access_hash);
++ trx->distinct_page_access_hash= NULL;
++ }
++
+ mutex_enter(&kernel_mutex);
+
+ trx_free(trx);
+@@ -1064,7 +1090,10 @@
trx_t* trx) /* in: transaction */
{
que_thr_t* thr;
#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
#endif /* UNIV_SYNC_DEBUG */
-@@ -1080,6 +1105,9 @@
+@@ -1080,6 +1109,11 @@
thr = UT_LIST_GET_FIRST(trx->wait_thrs);
}
-+ ut_usectime(&sec, &ms);
-+ now = (ib_longlong)sec * 1000000 + ms;
-+ trx->lock_que_wait_timer += (ulint)(now - trx->lock_que_wait_ustarted);
++ if (srv_slow_log && trx->take_stats) {
++ ut_usectime(&sec, &ms);
++ now = (ib_longlong)sec * 1000000 + ms;
++ trx->lock_que_wait_timer += (ulint)(now - trx->lock_que_wait_ustarted);
++ }
trx->que_state = TRX_QUE_RUNNING;
}
-@@ -1093,6 +1121,9 @@
+@@ -1093,6 +1127,9 @@
trx_t* trx) /* in: transaction in the TRX_QUE_LOCK_WAIT state */
{
que_thr_t* thr;
#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
-@@ -1109,6 +1140,9 @@
+@@ -1109,6 +1146,11 @@
thr = UT_LIST_GET_FIRST(trx->wait_thrs);
}
-+ ut_usectime(&sec, &ms);
-+ now = (ib_longlong)sec * 1000000 + ms;
-+ trx->lock_que_wait_timer += (ulint)(now - trx->lock_que_wait_ustarted);
++ if (srv_slow_log && trx->take_stats) {
++ ut_usectime(&sec, &ms);
++ now = (ib_longlong)sec * 1000000 + ms;
++ trx->lock_que_wait_timer += (ulint)(now - trx->lock_que_wait_ustarted);
++ }
trx->que_state = TRX_QUE_RUNNING;
}
-diff -r bb81fcdd7db2 patch_info/microslow_innodb.info
+diff -r 1242d4575291 mysys/my_getopt.c
+--- a/mysys/my_getopt.c Tue Jul 28 23:39:12 2009 -0700
++++ b/mysys/my_getopt.c Tue Jul 28 23:42:44 2009 -0700
+@@ -827,7 +827,8 @@
+ #endif
+ break;
+ default:
+- DBUG_ASSERT((optp->var_type & GET_TYPE_MASK) == GET_ULL);
++ DBUG_ASSERT((optp->var_type & GET_TYPE_MASK) == GET_ULL
++ || (optp->var_type & GET_TYPE_MASK) == GET_MICROTIME);
+ break;
+ }
+
+@@ -1061,6 +1062,9 @@
+ case GET_ULONG:
+ printf("%lu\n", *((ulong*) value));
+ break;
++ case GET_MICROTIME:
++ printf("%6f\n", ((double)(*((longlong*) value))) / 1000000.0);
++ break;
+ case GET_LL:
+ printf("%s\n", llstr(*((longlong*) value), buff));
+ break;
+diff -r 1242d4575291 patch_info/microslow_innodb.info
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
-+++ b/patch_info/microslow_innodb.info Mon Sep 08 16:38:46 2008 -0700
-@@ -0,0 +1,6 @@
++++ b/patch_info/microslow_innodb.info Tue Jul 28 23:42:44 2009 -0700
+@@ -0,0 +1,15 @@
+File=microslow_innodb.patch
+Name=Extended statistics in slow.log
-+Version=1.0
++Version=1.2
+Author=Percona <info@percona.com>
+License=GPL
+Comment=
-diff -r bb81fcdd7db2 scripts/mysqldumpslow.sh
---- a/scripts/mysqldumpslow.sh Mon Sep 08 16:38:33 2008 -0700
-+++ b/scripts/mysqldumpslow.sh Mon Sep 08 16:38:46 2008 -0700
++Changelog
++2008-11-26
++YK: Fix inefficient determination of trx, Make not to call useless gettimeofday when don't use slow log. Make log_slow_queries dynamic (bool).
++
++2008-11-07
++VT: Moved log_slow_rate_limit in SHOW VARIABLE into right place
++
++2008-11
++Arjen Lentz: Fixups (backward compatibility) by Arjen Lentz <arjen@openquery.com.au>
+diff -r 1242d4575291 scripts/mysqldumpslow.sh
+--- a/scripts/mysqldumpslow.sh Tue Jul 28 23:39:12 2009 -0700
++++ b/scripts/mysqldumpslow.sh Tue Jul 28 23:42:44 2009 -0700
@@ -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) : ('','');
$t -= $l unless $opt{l};
# remove fluff that mysqld writes to log when it (re)starts:
-diff -r bb81fcdd7db2 sql-common/my_time.c
---- a/sql-common/my_time.c Mon Sep 08 16:38:33 2008 -0700
-+++ b/sql-common/my_time.c Mon Sep 08 16:38:46 2008 -0700
-@@ -1252,3 +1252,37 @@
+diff -r 1242d4575291 sql-common/my_time.c
+--- a/sql-common/my_time.c Tue Jul 28 23:39:12 2009 -0700
++++ b/sql-common/my_time.c Tue Jul 28 23:42:44 2009 -0700
+@@ -1253,3 +1253,37 @@
return 0;
}
+ newtime= (GetTickCount() * 1000; /* GetTickCount only returns milliseconds */
+#else
+ struct timeval t;
-+ gettimeofday(&t, NULL);
-+ newtime= (ulonglong)t.tv_sec * 1000000 + t.tv_usec;
++ if (gettimeofday(&t, NULL) != -1)
++ newtime= (ulonglong)t.tv_sec * 1000000 + t.tv_usec;
+#endif
+ if (ltime)
+ *ltime= newtime;
+ return newtime;
+}
-diff -r bb81fcdd7db2 sql/filesort.cc
---- a/sql/filesort.cc Mon Sep 08 16:38:33 2008 -0700
-+++ b/sql/filesort.cc Mon Sep 08 16:38:46 2008 -0700
+diff -r 1242d4575291 sql/filesort.cc
+--- a/sql/filesort.cc Tue Jul 28 23:39:12 2009 -0700
++++ b/sql/filesort.cc Tue Jul 28 23:42:44 2009 -0700
@@ -180,6 +180,7 @@
{
statistic_increment(thd->status_var.filesort_scan_count, &LOCK_status);
if (param->not_killable)
{
killed= ¬_killable;
-diff -r bb81fcdd7db2 sql/ha_innodb.cc
---- a/sql/ha_innodb.cc Mon Sep 08 16:38:33 2008 -0700
-+++ b/sql/ha_innodb.cc Mon Sep 08 16:38:46 2008 -0700
+diff -r 1242d4575291 sql/ha_innodb.cc
+--- a/sql/ha_innodb.cc Tue Jul 28 23:39:12 2009 -0700
++++ b/sql/ha_innodb.cc Tue Jul 28 23:42:44 2009 -0700
@@ -1,3 +1,4 @@
+
/* Copyright (C) 2000-2005 MySQL AB & Innobase Oy
This program is free software; you can redistribute it and/or modify
-@@ -6098,6 +6099,7 @@
+@@ -819,9 +820,34 @@
+ trx->check_unique_secondary = TRUE;
+ }
+
++ if (thd->variables.log_slow_verbosity & SLOG_V_INNODB) {
++ trx->take_stats = TRUE;
++ } else {
++ trx->take_stats = FALSE;
++ }
++
+ return(trx);
+ }
+
++/*************************************************************************
++Gets current trx. */
++extern "C"
++trx_t*
++innobase_get_trx()
++{
++ THD *thd=current_thd;
++ if (likely(thd != 0)) {
++ return((trx_t*) thd->ha_data[innobase_hton.slot]);
++ } else {
++ return(NULL);
++ }
++}
++
++void
++innobase_update_var_slow_log()
++{
++ srv_slow_log = (ibool) opt_slow_log;
++}
+
+ /*************************************************************************
+ Construct ha_innobase handler. */
+@@ -1324,6 +1350,8 @@
+
+ /* -------------- Log files ---------------------------*/
+
++ srv_slow_log = (ibool) opt_slow_log;
++
+ /* The default dir for log files is the datadir of MySQL */
+
+ if (!innobase_log_group_home_dir) {
+@@ -4697,6 +4725,12 @@
+ trx->check_unique_secondary = FALSE;
+ }
+
++ if (thd->variables.log_slow_verbosity & SLOG_V_INNODB) {
++ trx->take_stats = TRUE;
++ } else {
++ trx->take_stats = FALSE;
++ }
++
+ if (lower_case_table_names) {
+ srv_lower_case_table_names = TRUE;
+ } else {
+@@ -4962,6 +4996,12 @@
+ trx->check_unique_secondary = FALSE;
+ }
+
++ if (thd->variables.log_slow_verbosity & SLOG_V_INNODB) {
++ trx->take_stats = TRUE;
++ } else {
++ trx->take_stats = FALSE;
++ }
++
+ name_len = strlen(name);
+
+ assert(name_len < 1000);
+@@ -5049,6 +5089,12 @@
+ trx->check_foreigns = FALSE;
+ }
+
++ if (current_thd->variables.log_slow_verbosity & SLOG_V_INNODB) {
++ trx->take_stats = TRUE;
++ } else {
++ trx->take_stats = FALSE;
++ }
++
+ error = row_drop_database_for_mysql(namebuf, trx);
+ my_free(namebuf, MYF(0));
+
+@@ -5115,6 +5161,12 @@
+ trx->check_foreigns = FALSE;
+ }
+
++ if (current_thd->variables.log_slow_verbosity & SLOG_V_INNODB) {
++ trx->take_stats = TRUE;
++ } else {
++ trx->take_stats = FALSE;
++ }
++
+ name_len1 = strlen(from);
+ name_len2 = strlen(to);
+
+@@ -6122,6 +6174,7 @@
{
row_prebuilt_t* prebuilt = (row_prebuilt_t*) innobase_prebuilt;
trx_t* trx;
DBUG_ENTER("ha_innobase::external_lock");
DBUG_PRINT("enter",("lock_type: %d", lock_type));
-@@ -6221,7 +6223,24 @@
+@@ -6245,7 +6298,24 @@
if (trx->n_mysql_tables_in_use == 0) {
prebuilt->used_in_HANDLER = FALSE;
if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
-diff -r bb81fcdd7db2 sql/log.cc
---- a/sql/log.cc Mon Sep 08 16:38:33 2008 -0700
-+++ b/sql/log.cc Mon Sep 08 16:38:46 2008 -0700
-@@ -2229,10 +2229,11 @@
+diff -r 1242d4575291 sql/ha_innodb.h
+--- a/sql/ha_innodb.h Tue Jul 28 23:39:12 2009 -0700
++++ b/sql/ha_innodb.h Tue Jul 28 23:42:44 2009 -0700
+@@ -271,6 +271,8 @@
+
+ int innobase_start_trx_and_assign_read_view(THD* thd);
+
++void innobase_update_var_slow_log();
++
+ /***********************************************************************
+ This function is used to prepare X/Open XA distributed transaction */
+
+diff -r 1242d4575291 sql/log.cc
+--- a/sql/log.cc Tue Jul 28 23:39:12 2009 -0700
++++ b/sql/log.cc Tue Jul 28 23:42:44 2009 -0700
+@@ -2289,11 +2289,12 @@
*/
bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length,
{
bool error=0;
time_t current_time;
+- if (!is_open())
+ ulonglong current_timer;
- if (!is_open())
++ if (!opt_slow_log || !is_open())
return 0;
DBUG_ENTER("MYSQL_LOG::write");
-@@ -2243,7 +2244,8 @@
+
+@@ -2303,7 +2304,8 @@
int tmp_errno=0;
char buff[80],*end;
end=buff;
{
VOID(pthread_mutex_unlock(&LOCK_log));
DBUG_RETURN(0);
-@@ -2273,22 +2275,69 @@
+@@ -2333,22 +2335,72 @@
if (my_b_printf(&log_file, "# User@Host: %s[%s] @ %s [%s]\n",
sctx->priv_user ?
sctx->priv_user : "",
{
+ char buf[5][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);
++ snprintf(buf[0], 20, "%.6f", (current_timer ? (current_timer - query_start_timer):0) / 1000000.0);
++ snprintf(buf[1], 20, "%.6f", (thd->timer_after_lock - query_start_timer) / 1000000.0);
+ if (!query_length)
+ {
+ thd->sent_row_count= thd->examined_row_count= 0;
++ thd->row_count= 0;
+ thd->innodb_was_used= FALSE;
+ thd->query_plan_flags= QPLAN_NONE;
+ thd->query_plan_fsort_passes= 0;
- (ulong) (current_time - query_start_arg),
- (ulong) (thd->time_after_lock - query_start_arg),
+ "# Thread_id: %lu Schema: %s\n" \
-+ "# Query_time: %s Lock_time: %s Rows_sent: %lu Rows_examined: %lu\n",
++ "# Query_time: %s Lock_time: %s Rows_sent: %lu Rows_examined: %lu Rows_affected: %lu Rows_read: %lu\n",
+ (ulong) thd->thread_id, (thd->db ? thd->db : ""),
+ buf[0], buf[1],
(ulong) thd->sent_row_count,
- (ulong) thd->examined_row_count) == (uint) -1)
+- (ulong) thd->examined_row_count) == (uint) -1)
++ (ulong) thd->examined_row_count,
++ ((long) thd->row_count_func > 0 ) ? (ulong) thd->row_count_func : 0,
++ (ulong) thd->row_count) == (uint) -1)
tmp_errno=errno;
+ if ((thd->variables.log_slow_verbosity & SLOG_V_QUERY_PLAN) &&
+ my_b_printf(&log_file,
+ tmp_errno=errno;
+ if ((thd->variables.log_slow_verbosity & SLOG_V_INNODB) && thd->innodb_was_used)
+ {
-+ sprintf(buf[2], "%.6f", thd->innodb_io_reads_wait_timer / 1000000.0);
-+ sprintf(buf[3], "%.6f", thd->innodb_lock_que_wait_timer / 1000000.0);
-+ sprintf(buf[4], "%.6f", thd->innodb_innodb_que_wait_timer / 1000000.0);
++ snprintf(buf[2], 20, "%.6f", thd->innodb_io_reads_wait_timer / 1000000.0);
++ snprintf(buf[3], 20, "%.6f", thd->innodb_lock_que_wait_timer / 1000000.0);
++ snprintf(buf[4], 20, "%.6f", thd->innodb_innodb_que_wait_timer / 1000000.0);
+ if (my_b_printf(&log_file,
+ "# InnoDB_IO_r_ops: %lu InnoDB_IO_r_bytes: %lu InnoDB_IO_r_wait: %s\n" \
+ "# InnoDB_rec_lock_wait: %s InnoDB_queue_wait: %s\n" \
}
if (thd->db && strcmp(thd->db,db))
{ // Database changed
-diff -r bb81fcdd7db2 sql/log_event.cc
---- a/sql/log_event.cc Mon Sep 08 16:38:33 2008 -0700
-+++ b/sql/log_event.cc Mon Sep 08 16:38:46 2008 -0700
-@@ -2039,6 +2039,7 @@
+diff -r 1242d4575291 sql/log_event.cc
+--- a/sql/log_event.cc Tue Jul 28 23:39:12 2009 -0700
++++ b/sql/log_event.cc Tue Jul 28 23:42:44 2009 -0700
+@@ -2061,6 +2061,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);
}
else
-diff -r bb81fcdd7db2 sql/mysql_priv.h
---- a/sql/mysql_priv.h Mon Sep 08 16:38:33 2008 -0700
-+++ b/sql/mysql_priv.h Mon Sep 08 16:38:46 2008 -0700
-@@ -484,6 +484,78 @@
- #define WEEK_FIRST_WEEKDAY 4
+diff -r 1242d4575291 sql/mysql_priv.h
+--- a/sql/mysql_priv.h Tue Jul 28 23:39:12 2009 -0700
++++ b/sql/mysql_priv.h Tue Jul 28 23:42:44 2009 -0700
+@@ -507,6 +507,78 @@
#define STRING_BUFFER_USUAL_SIZE 80
-+
+
+/* Slow log */
+
+struct msl_opts
+ { SLOG_F_FILESORT_DISK, "filesort_on_disk" },
+ { SLOG_F_INVALID, (char *)0 }
+};
-
++
enum enum_parsing_place
{
-@@ -1333,7 +1405,7 @@
+ NO_MATTER,
+@@ -1365,6 +1437,7 @@
+ extern bool using_update_log, opt_large_files, server_id_supplied;
+ extern bool opt_update_log, opt_bin_log, opt_error_log;
+ extern my_bool opt_log, opt_slow_log, opt_log_queries_not_using_indexes;
++extern char *opt_slow_logname;
+ extern bool opt_disable_networking, opt_skip_show_db;
+ extern my_bool opt_character_set_client_handshake;
+ extern bool volatile abort_loop, shutdown_in_progress, grant_option;
+@@ -1376,7 +1449,8 @@
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 opt_use_global_long_query_time;
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 -r bb81fcdd7db2 sql/mysqld.cc
---- a/sql/mysqld.cc Mon Sep 08 16:38:33 2008 -0700
-+++ b/sql/mysqld.cc Mon Sep 08 16:38:46 2008 -0700
-@@ -175,7 +175,6 @@
- static void getvolumename();
+diff -r 1242d4575291 sql/mysqld.cc
+--- a/sql/mysqld.cc Tue Jul 28 23:39:12 2009 -0700
++++ b/sql/mysqld.cc Tue Jul 28 23:42:44 2009 -0700
+@@ -176,7 +176,6 @@
static void getvolumeID(BYTE *volumeName);
#endif /* __NETWARE__ */
--
+-
#ifdef _AIX41
int initgroups(const char *,unsigned int);
-@@ -406,6 +405,7 @@
+ #endif
+@@ -411,10 +410,13 @@
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 opt_use_global_long_query_time= 0;
my_bool lower_case_file_system= 0;
my_bool opt_large_pages= 0;
uint opt_large_page_size= 0;
-@@ -503,6 +503,7 @@
+ my_bool opt_old_style_user_limits= 0, trust_function_creators= 0;
++char* opt_slow_logname= 0;
+ /*
+ True if there is at least one per-hour limit for some user, so we should
+ check them before each query (and possibly reset counters when hour is
+@@ -509,6 +511,7 @@
Ge_creator ge_creator;
Le_creator le_creator;
FILE *bootstrap_file;
int bootstrap_error;
-@@ -3649,6 +3650,8 @@
+@@ -588,7 +591,7 @@
+ static int cleanup_done;
+ static ulong opt_specialflag, opt_myisam_block_size;
+ static char *opt_logname, *opt_update_logname, *opt_binlog_index_name;
+-static char *opt_slow_logname, *opt_tc_heuristic_recover;
++static char *opt_tc_heuristic_recover;
+ static char *mysql_home_ptr, *pidfile_name_ptr;
+ static char **defaults_argv;
+ static char *opt_bin_logname;
+@@ -3697,6 +3700,8 @@
unireg_abort(1);
}
}
#endif /* __WIN__ */
if (init_common_variables(MYSQL_CONFIG_NAME,
-@@ -4892,7 +4895,7 @@
+@@ -4947,7 +4952,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_LOWER_CASE_TABLE_NAMES, OPT_MAX_ALLOWED_PACKET,
OPT_MAX_BINLOG_CACHE_SIZE, OPT_MAX_BINLOG_SIZE,
OPT_MAX_CONNECTIONS, OPT_MAX_CONNECT_ERRORS,
-@@ -4983,6 +4986,10 @@
+@@ -5038,11 +5043,18 @@
OPT_TIMED_MUTEXES,
OPT_OLD_STYLE_USER_LIMITS,
OPT_LOG_SLOW_ADMIN_STATEMENTS,
+ OPT_LOG_SLOW_VERBOSITY,
+ OPT_LOG_SLOW_FILTER,
OPT_TABLE_LOCK_WAIT_TIMEOUT,
+ OPT_PLUGIN_DIR,
OPT_PORT_OPEN_TIMEOUT,
OPT_MERGE,
-@@ -5374,6 +5381,11 @@
- "Log slow OPTIMIZE, ANALYZE, ALTER and other administrative statements to the slow log if it is open.",
+ OPT_PROFILING,
++ OPT_SLOW_LOG,
++ OPT_SLOW_QUERY_LOG_FILE,
++ OPT_USE_GLOBAL_LONG_QUERY_TIME,
+ OPT_INNODB_ROLLBACK_ON_TIMEOUT,
+ OPT_SECURE_FILE_PRIV,
+ OPT_KEEP_FILES_ON_CREATE,
+@@ -5441,10 +5453,19 @@
(gptr*) &opt_log_slow_admin_statements,
(gptr*) &opt_log_slow_admin_statements,
-+ 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+ 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},
++ 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.",
-@@ -6038,11 +6050,27 @@
+ (gptr*) &opt_slow_logname, (gptr*) &opt_slow_logname, 0, GET_STR, OPT_ARG,
+ 0, 0, 0, 0, 0, 0},
++ {"slow_query_log_file", OPT_SLOW_QUERY_LOG_FILE,
++ "Log slow queries to given log file. Defaults logging to hostname-slow.log. Must be enabled to activate other slow log options.",
++ (gptr*) &opt_slow_logname, (gptr*) &opt_slow_logname, 0, GET_STR, OPT_ARG,
++ 0, 0, 0, 0, 0, 0},
+ {"log-tc", OPT_LOG_TC,
+ "Path to transaction coordinator log (used for transactions that affect "
+ "more than one storage engine, when binary log is disabled)",
+@@ -5808,6 +5829,9 @@
+ "Tells the slave thread to continue replication when a query returns an error from the provided list.",
+ 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ #endif
++ {"slow-query-log", OPT_SLOW_LOG,
++ "Enable|disable slow query log", (gptr*) &opt_slow_log,
++ (gptr*) &opt_slow_log, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
+ {"socket", OPT_SOCKET, "Socket file to use for connection.",
+ (gptr*) &mysqld_unix_port, (gptr*) &mysqld_unix_port, 0, GET_STR,
+ REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+@@ -6110,11 +6134,31 @@
(gptr*) 0,
0, (GET_ULONG | GET_ASK_ADDR) , REQUIRED_ARG, 100,
1, 100, 0, 1, 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,
+- (gptr*) &max_system_variables.long_query_time, 0, GET_ULONG,
+- REQUIRED_ARG, 10, 1, LONG_TIMEOUT, 0, 1, 0},
+ {"log_slow_filter", OPT_LOG_SLOW_FILTER,
+ "Log only the queries that followed certain execution plan. Multiple flags allowed in a comma-separated string. [qc_miss, full_scan, full_join, tmp_table, tmp_table_on_disk, filesort, filesort_on_disk]",
+ 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, SLOG_F_NONE, 0, 0},
+ "Rate limit statement writes to slow log to only those from every (1/log_slow_rate_limit) session.",
+ (gptr*) &global_system_variables.log_slow_rate_limit,
+ (gptr*) &max_system_variables.log_slow_rate_limit, 0, GET_ULONG,
-+ REQUIRED_ARG, 1, 1, ~0L, 0, 1L, 0},
++ REQUIRED_ARG, 1, 1, LONG_MAX, 0, 1L, 0},
+ {"log_slow_verbosity", OPT_LOG_SLOW_VERBOSITY,
+ "Choose how verbose the messages to your slow log will be. Multiple flags allowed in a comma-separated string. [microtime, query_plan, innodb]",
+ 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, SLOG_V_MICROTIME, 0, 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,
- (gptr*) &max_system_variables.long_query_time, 0, GET_ULONG,
-- REQUIRED_ARG, 10, 1, LONG_TIMEOUT, 0, 1, 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,
++ (gptr*) &max_system_variables.long_query_time, 0, GET_MICROTIME,
+ 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, 0, ~0L, 0, 1L, 0},
++ REQUIRED_ARG, 0, 0, LONG_MAX, 0, 1L, 0},
++ {"use_global_long_query_time", OPT_USE_GLOBAL_LONG_QUERY_TIME,
++ "Control always use global long_query_time or local long_query_time.",
++ (gptr*) &opt_use_global_long_query_time, (gptr*) &opt_use_global_long_query_time,
++ 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 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,
-@@ -6810,7 +6838,9 @@
+@@ -6893,7 +6937,11 @@
global_system_variables.max_join_size= (ulonglong) HA_POS_ERROR;
max_system_variables.max_join_size= (ulonglong) HA_POS_ERROR;
global_system_variables.old_passwords= 0;
-
++ global_system_variables.long_query_time = 10000000;
++ max_system_variables.long_query_time = LONG_TIMEOUT * 1000000;
+ global_system_variables.log_slow_verbosity= SLOG_V_MICROTIME;
+ global_system_variables.log_slow_filter= SLOG_F_NONE;
+
/*
Default behavior for 4.1 and 5.0 is to treat NULL values as unequal
when collecting index statistics for MyISAM tables.
-@@ -7271,6 +7301,24 @@
+@@ -7364,6 +7412,35 @@
case OPT_BOOTSTRAP:
opt_noacl=opt_bootstrap=1;
break;
+ msl_flag_resolve_by_name(slog_filter, argument,
+ SLOG_F_NONE, SLOG_F_INVALID)) == SLOG_F_INVALID)
+ {
-+ fprintf(stderr,"Invalid argument to log_slow_filter\n");
++ fprintf(stderr,"Invalid argument in log_slow_filter: %s\n", argument);
+ exit(1);
+ }
+ break;
+ msl_flag_resolve_by_name(slog_verb, argument,
+ SLOG_V_NONE, SLOG_V_INVALID)) == SLOG_V_INVALID)
+ {
-+ fprintf(stderr,"Invalid argument to log_slow_verbosity\n");
++ fprintf(stderr,"Invalid argument in log_slow_verbosity: %s\n", argument);
+ exit(1);
+ }
+ break;
++ case OPT_LONG_QUERY_TIME:
++ {
++ double doubleslow = strtod(argument,NULL);
++ if (doubleslow < 0 || doubleslow > (LONG_TIMEOUT))
++ {
++ fprintf(stderr,"Out of range long_query_time value: %s\n", argument);
++ exit(1);
++ }
++ global_system_variables.long_query_time = (ulonglong) (doubleslow * 1000000);
++ break;
++ }
case OPT_STORAGE_ENGINE:
{
if ((enum db_type)((global_system_variables.table_type=
-@@ -7603,10 +7651,14 @@
+@@ -7696,10 +7773,14 @@
if (opt_bdb)
sql_print_warning("this binary does not contain BDB storage engine");
#endif
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 -r bb81fcdd7db2 sql/set_var.cc
---- a/sql/set_var.cc Mon Sep 08 16:38:33 2008 -0700
-+++ b/sql/set_var.cc Mon Sep 08 16:38:46 2008 -0700
-@@ -215,7 +215,7 @@
+diff -r 1242d4575291 sql/set_var.cc
+--- a/sql/set_var.cc Tue Jul 28 23:39:12 2009 -0700
++++ b/sql/set_var.cc Tue Jul 28 23:42:44 2009 -0700
+@@ -217,9 +217,13 @@
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",
++sys_var_thd_microtime sys_long_query_time("long_query_time",
&SV::long_query_time);
++sys_var_bool_ptr sys_use_global_long_query_time("use_global_long_query_time",
++ &opt_use_global_long_query_time);
sys_var_bool_const_ptr sys_log_slow("log_slow_queries", &opt_slow_log);
++sys_var_log_slow sys_slow_query_log("slow_query_log", &opt_slow_log);
++sys_var_const_str_ptr sys_slow_query_log_file("slow_query_log_file", &opt_slow_logname);
sys_var_thd_bool sys_low_priority_updates("low_priority_updates",
-@@ -281,6 +281,8 @@
+ &SV::low_priority_updates,
+ fix_low_priority_updates);
+@@ -283,6 +287,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_multi_range_count("multi_range_count",
&SV::multi_range_count);
sys_var_long_ptr sys_myisam_data_pointer_size("myisam_data_pointer_size",
-@@ -324,6 +326,20 @@
+@@ -327,6 +333,20 @@
sys_var_bool_ptr sys_relay_log_purge("relay_log_purge",
&relay_log_purge);
#endif
sys_var_long_ptr sys_rpl_recovery_rank("rpl_recovery_rank",
&rpl_recovery_rank);
sys_var_long_ptr sys_query_cache_size("query_cache_size",
-@@ -675,6 +691,9 @@
+@@ -697,6 +717,10 @@
&sys_log_off,
&sys_log_queries_not_using_indexes,
&sys_log_slow,
+ &sys_log_slow_filter,
+ &sys_log_slow_rate_limit,
+ &sys_log_slow_verbosity,
++ &sys_use_global_long_query_time,
&sys_log_update,
&sys_log_warnings,
&sys_long_query_time,
-@@ -698,6 +717,7 @@
+@@ -720,6 +744,7 @@
&sys_max_tmp_tables,
&sys_max_user_connections,
&sys_max_write_lock_count,
&sys_multi_range_count,
&sys_myisam_data_pointer_size,
&sys_myisam_max_sort_file_size,
-@@ -963,6 +983,8 @@
+@@ -773,6 +798,8 @@
+ &sys_slave_skip_counter,
+ #endif
+ &sys_slow_launch_time,
++ &sys_slow_query_log,
++ &sys_slow_query_log_file,
+ &sys_sort_buffer,
+ &sys_sql_big_tables,
+ &sys_sql_low_priority_updates,
+@@ -994,8 +1021,11 @@
{"log_slave_updates", (char*) &opt_log_slave_updates, SHOW_MY_BOOL},
#endif
{sys_log_slow.name, (char*) &sys_log_slow, SHOW_SYS},
+ {sys_log_slow_filter.name, (char*) &sys_log_slow_filter, SHOW_SYS},
++ {sys_log_slow_rate_limit.name, (char*) &sys_log_slow_rate_limit, SHOW_SYS},
+ {sys_log_slow_verbosity.name, (char*) &sys_log_slow_verbosity, SHOW_SYS},
{sys_log_warnings.name, (char*) &sys_log_warnings, SHOW_SYS},
- {sys_long_query_time.name, (char*) &sys_long_query_time, SHOW_SYS},
+- {sys_long_query_time.name, (char*) &sys_long_query_time, SHOW_SYS},
++ {sys_long_query_time.name, (char*) &sys_long_query_time, SHOW_MICROTIME},
{sys_low_priority_updates.name, (char*) &sys_low_priority_updates, SHOW_SYS},
-@@ -991,6 +1013,7 @@
+ {"lower_case_file_system", (char*) &lower_case_file_system, SHOW_MY_BOOL},
+ {"lower_case_table_names", (char*) &lower_case_table_names, SHOW_INT},
+@@ -1022,6 +1052,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_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,
-@@ -1043,6 +1066,7 @@
- {sys_query_prealloc_size.name, (char*) &sys_query_prealloc_size, SHOW_SYS},
- {sys_range_alloc_block_size.name, (char*) &sys_range_alloc_block_size,
- SHOW_SYS},
-+ {sys_log_slow_rate_limit.name, (char*) &sys_log_slow_rate_limit, SHOW_SYS},
- {sys_read_buff_size.name, (char*) &sys_read_buff_size, SHOW_SYS},
- {sys_readonly.name, (char*) &sys_readonly, SHOW_SYS},
- {sys_read_rnd_buff_size.name,(char*) &sys_read_rnd_buff_size, SHOW_SYS},
-@@ -1639,6 +1663,57 @@
- return (byte*) &(thd->variables.*offset);
+@@ -1109,6 +1140,8 @@
+ {sys_slave_trans_retries.name,(char*) &sys_slave_trans_retries, SHOW_SYS},
+ #endif
+ {sys_slow_launch_time.name, (char*) &sys_slow_launch_time, SHOW_SYS},
++ {sys_slow_query_log.name, (char*) &sys_slow_query_log, SHOW_SYS},
++ {sys_slow_query_log_file.name,(char*) &sys_slow_query_log_file, SHOW_SYS},
+ #ifdef HAVE_SYS_UN_H
+ {"socket", (char*) &mysqld_unix_port, SHOW_CHAR_PTR},
+ #endif
+@@ -1149,6 +1182,7 @@
+ {sys_tx_isolation.name, (char*) &sys_tx_isolation, SHOW_SYS},
+ {sys_updatable_views_with_limit.name,
+ (char*) &sys_updatable_views_with_limit,SHOW_SYS},
++ {sys_use_global_long_query_time.name, (char*) &sys_use_global_long_query_time, SHOW_SYS},
+ {sys_version.name, (char*) &sys_version, SHOW_SYS},
+ #ifdef HAVE_BERKELEY_DB
+ {sys_version_bdb.name, (char*) &sys_version_bdb, SHOW_SYS},
+@@ -1777,6 +1811,17 @@
}
-+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;
++ 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)
-+{
-+ bool fixed= FALSE;
-+ ulonglong tmp= var->save_result.ulonglong_value;
+ bool sys_var_thd_bool::update(THD *thd, set_var *var)
+ {
+ if (var->type == OPT_GLOBAL)
+@@ -1933,6 +1978,19 @@
+ pthread_mutex_unlock(&LOCK_global_system_variables);
+ return new Item_int(value);
+ }
++ case SHOW_MICROTIME:
++ {
++ longlong value;
++ char buff[80];
++ int len;
+
-+ if (tmp > max_system_variables.*offset)
-+ tmp= max_system_variables.*offset;
++ pthread_mutex_lock(&LOCK_global_system_variables);
++ value= *(longlong*) value_ptr(thd, var_type, base);
++ pthread_mutex_unlock(&LOCK_global_system_variables);
+
-+ if (option_limits)
-+ tmp= getopt_ull_limit_value(tmp, option_limits, &fixed);
++ len = snprintf(buff, 80, "%f", ((double) value) / 1000000.0);
++ return new Item_float(buff,len);
++ }
+ case SHOW_HA_ROWS:
+ {
+ ha_rows value;
+@@ -2765,6 +2823,30 @@
+ }
+
+
++bool sys_var_log_slow::update(THD *thd, set_var *var)
++{
++ bool ret;
+
-+ if (fixed)
-+ throw_bounds_warning(thd, option_limits->name, tmp);
-+
-+ /* Lock is needed to make things safe on 32 bit systems */
-+ if (var->type == OPT_GLOBAL)
++ pthread_mutex_lock(&LOCK_global_system_variables);
++ if (var->save_result.ulong_value)
+ {
-+ /* 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);
++ if(!mysql_slow_log.is_open())
++ {
++ mysql_slow_log.open_slow_log(opt_slow_logname);
++ }
+ }
-+ else
-+ thd->variables.*offset= (ulonglong) tmp;
++ pthread_mutex_unlock(&LOCK_global_system_variables);
+
-+ return 0;
++ ret = sys_var_bool_ptr::update(thd, var);
++
++#ifdef HAVE_INNOBASE_DB
++ innobase_update_var_slow_log();
++#endif
++
++ return(ret);
+}
-
- bool sys_var_thd_ha_rows::update(THD *thd, set_var *var)
++
++
+ #ifdef HAVE_REPLICATION
+ bool sys_var_slave_skip_counter::check(THD *thd, set_var *var)
{
-@@ -3483,6 +3558,191 @@
+@@ -3549,6 +3631,191 @@
#endif
}
/****************************************************************************
Functions to handle table_type
****************************************************************************/
-diff -r bb81fcdd7db2 sql/set_var.h
---- a/sql/set_var.h Mon Sep 08 16:38:33 2008 -0700
-+++ b/sql/set_var.h Mon Sep 08 16:38:46 2008 -0700
-@@ -123,6 +123,7 @@
+diff -r 1242d4575291 sql/set_var.h
+--- a/sql/set_var.h Tue Jul 28 23:39:12 2009 -0700
++++ b/sql/set_var.h Tue Jul 28 23:42:44 2009 -0700
+@@ -132,6 +132,7 @@
};
class sys_var_ulonglong_ptr :public sys_var
{
public:
-@@ -309,7 +310,6 @@
+@@ -168,6 +169,13 @@
+ bool check_update_type(Item_result type) { return 0; }
+ };
+
++class sys_var_log_slow :public sys_var_bool_ptr
++{
++public:
++ sys_var_log_slow(const char *name_arg, my_bool *value_arg)
++ :sys_var_bool_ptr(name_arg, value_arg) {}
++ bool update(THD *thd, set_var *var);
++};
+
+ class sys_var_bool_const_ptr : public sys_var
+ {
+@@ -340,7 +348,6 @@
}
};
class sys_var_thd_ulong :public sys_var_thd
{
sys_check_func check_func;
-@@ -329,6 +329,23 @@
+@@ -360,7 +367,6 @@
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
{
-@@ -346,7 +363,6 @@
- SHOW_TYPE show_type() { return SHOW_HA_ROWS; }
+ public:
+@@ -378,7 +384,6 @@
byte *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
};
--
+-
class sys_var_thd_ulonglong :public sys_var_thd
{
-@@ -376,7 +392,6 @@
+ public:
+@@ -407,6 +412,19 @@
}
};
--
++class sys_var_thd_microtime :public sys_var_thd_ulonglong
++{
++public:
++ sys_var_thd_microtime(const char *name_arg, ulonglong SV::*offset_arg)
++ :sys_var_thd_ulonglong(name_arg, offset_arg)
++ {}
++ SHOW_TYPE show_type() { return SHOW_MICROTIME; }
++ 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_bool :public sys_var_thd
{
- public:
-@@ -446,6 +461,66 @@
- ulong *length);
+@@ -478,6 +496,66 @@
};
-+
+
+class sys_var_thd_msl_option :public sys_var_thd
+{
+protected:
+ bool update(THD *thd, set_var *var);
+ byte *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
+};
-
++
class sys_var_thd_storage_engine :public sys_var_thd
{
-@@ -1042,3 +1117,11 @@
+ protected:
+@@ -1109,3 +1187,11 @@
bool process_key_caches(int (* func) (const char *name, KEY_CACHE *));
void delete_elements(I_List<NAMED_LIST> *list,
void (*free_element)(const char*, gptr));
+ const ulong none_val, const ulong invalid_val);
+const char *msl_option_get_name(const struct msl_opts *opts, ulong val);
+char *msl_flag_get_name(const struct msl_opts *opts, char *buf, ulong val);
-diff -r bb81fcdd7db2 sql/slave.cc
---- a/sql/slave.cc Mon Sep 08 16:38:33 2008 -0700
-+++ b/sql/slave.cc Mon Sep 08 16:38:46 2008 -0700
-@@ -2925,6 +2925,12 @@
+diff -r 1242d4575291 sql/slave.cc
+--- a/sql/slave.cc Tue Jul 28 23:39:12 2009 -0700
++++ b/sql/slave.cc Tue Jul 28 23:42:44 2009 -0700
+@@ -2983,6 +2983,12 @@
+ MAX_LOG_EVENT_HEADER; /* note, incr over the global not session var */
thd->slave_thread = 1;
set_slave_thread_options(thd);
thd->client_capabilities = CLIENT_LOCAL_FILES;
thd->real_id=pthread_self();
pthread_mutex_lock(&LOCK_thread_count);
-diff -r bb81fcdd7db2 sql/sql_cache.cc
---- a/sql/sql_cache.cc Mon Sep 08 16:38:33 2008 -0700
-+++ b/sql/sql_cache.cc Mon Sep 08 16:38:46 2008 -0700
-@@ -1334,6 +1334,7 @@
+diff -r 1242d4575291 sql/sql_cache.cc
+--- a/sql/sql_cache.cc Tue Jul 28 23:39:12 2009 -0700
++++ b/sql/sql_cache.cc Tue Jul 28 23:42:44 2009 -0700
+@@ -1402,6 +1402,7 @@
thd->limit_found_rows = query->found_rows();
thd->status_var.last_query_cost= 0.0;
BLOCK_UNLOCK_RD(query_block);
DBUG_RETURN(1); // Result sent to client
-@@ -1341,6 +1342,7 @@
+@@ -1409,6 +1410,7 @@
err_unlock:
STRUCT_UNLOCK(&structure_guard_mutex);
err:
DBUG_RETURN(0); // Query was not cached
}
-diff -r bb81fcdd7db2 sql/sql_class.cc
---- a/sql/sql_class.cc Mon Sep 08 16:38:33 2008 -0700
-+++ b/sql/sql_class.cc Mon Sep 08 16:38:46 2008 -0700
-@@ -174,7 +174,7 @@
- lock_id(&main_lock_id),
- user_time(0), in_sub_stmt(0), global_read_lock(0), is_fatal_error(0),
+diff -r 1242d4575291 sql/sql_class.cc
+--- a/sql/sql_class.cc Tue Jul 28 23:39:12 2009 -0700
++++ b/sql/sql_class.cc Tue Jul 28 23:42:44 2009 -0700
+@@ -190,7 +190,7 @@
+ table_map_for_update(0),
+ global_read_lock(0), is_fatal_error(0),
transaction_rollback_request(0), is_fatal_sub_stmt_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),
-@@ -2198,6 +2198,12 @@
+@@ -2251,6 +2251,12 @@
backup->cuted_fields= cuted_fields;
backup->client_capabilities= client_capabilities;
backup->savepoints= transaction.savepoints;
if (!lex->requires_prelocking() || is_update_query(lex->sql_command))
options&= ~OPTION_BIN_LOG;
-@@ -2214,7 +2220,13 @@
+@@ -2267,7 +2273,13 @@
sent_row_count= 0;
cuted_fields= 0;
transaction.savepoints= 0;
/* Surpress OK packets in case if we will execute statements */
net.no_send_ok= TRUE;
}
-@@ -2267,6 +2279,12 @@
+@@ -2320,6 +2332,12 @@
*/
examined_row_count+= backup->examined_row_count;
cuted_fields+= backup->cuted_fields;
}
-diff -r bb81fcdd7db2 sql/sql_class.h
---- a/sql/sql_class.h Mon Sep 08 16:38:33 2008 -0700
-+++ b/sql/sql_class.h Mon Sep 08 16:38:46 2008 -0700
-@@ -43,6 +43,13 @@
+diff -r 1242d4575291 sql/sql_class.h
+--- a/sql/sql_class.h Tue Jul 28 23:39:12 2009 -0700
++++ b/sql/sql_class.h Tue Jul 28 23:42:44 2009 -0700
+@@ -43,6 +43,7 @@
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)
-@@ -314,7 +321,7 @@
+@@ -321,7 +322,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,
bool write(Log_event* event_info); // binary log write
bool write(THD *thd, IO_CACHE *cache, Log_event *commit_event);
-@@ -520,13 +527,14 @@
+@@ -527,13 +528,14 @@
ulong auto_increment_increment, auto_increment_offset;
ulong bulk_insert_buff_size;
ulong join_buff_size;
ulong multi_range_count;
ulong myisam_repair_threads;
ulong myisam_sort_buff_size;
-@@ -541,10 +549,13 @@
- ulong optimizer_search_depth;
+@@ -549,10 +551,13 @@
ulong preload_buff_size;
+ ulong profiling_history_size;
ulong query_cache_type;
+ ulong log_slow_rate_limit;
ulong read_buff_size;
ulong table_type;
ulong tx_isolation;
ulong completion_type;
-@@ -1111,6 +1122,12 @@
+@@ -1129,6 +1134,12 @@
uint in_sub_stmt;
bool enable_slow_log, insert_id_used, clear_next_insert_id;
bool last_insert_id_used;
my_bool no_send_ok;
SAVEPOINT *savepoints;
};
-@@ -1167,6 +1184,11 @@
+@@ -1185,6 +1196,11 @@
class THD :public Statement,
public Open_tables_state
{
public:
/*
Constant for THD::where initialization in the beginning of every query.
-@@ -1272,10 +1294,24 @@
+@@ -1293,10 +1309,24 @@
*/
const char *where;
time_t start_time,time_after_lock,user_time;
/* <> 0 if we are inside of trigger or stored function. */
uint in_sub_stmt;
-@@ -1661,11 +1697,11 @@
+@@ -1696,11 +1726,11 @@
sql_print_information("time() failed with %d", errno);
}
inline void insert_id(ulonglong id_arg)
{
last_insert_id= id_arg;
-diff -r bb81fcdd7db2 sql/sql_parse.cc
---- a/sql/sql_parse.cc Mon Sep 08 16:38:33 2008 -0700
-+++ b/sql/sql_parse.cc Mon Sep 08 16:38:46 2008 -0700
+diff -r 1242d4575291 sql/sql_parse.cc
+--- a/sql/sql_parse.cc Tue Jul 28 23:39:12 2009 -0700
++++ b/sql/sql_parse.cc Tue Jul 28 23:42:44 2009 -0700
@@ -20,6 +20,7 @@
#include <m_ctype.h>
#include <myisam.h>
#ifdef HAVE_INNOBASE_DB
#include "ha_innodb.h"
-@@ -1180,6 +1181,15 @@
+@@ -1227,6 +1228,15 @@
my_net_set_read_timeout(net, thd->variables.net_read_timeout);
my_net_set_write_timeout(net, thd->variables.net_write_timeout);
while (!net->error && net->vio != 0 &&
!(thd->killed == THD::KILL_CONNECTION))
{
-@@ -2255,26 +2265,52 @@
+@@ -2353,28 +2363,57 @@
return; // Don't set time for sub stmt
start_of_query= thd->start_time;
+- thd->end_time(); // Set start time
+ ulonglong start_of_query_timer= thd->start_timer;
- thd->end_time(); // Set start time
++ thd->end_time(); // Set start timea
+
+
+ /* Follow the slow log filter configuration. */
-+ if (thd->variables.log_slow_filter != SLOG_F_NONE &&
++ if (thd->variables.log_slow_filter != SLOG_F_NONE &&
+ (!(thd->variables.log_slow_filter & thd->query_plan_flags) ||
-+ ((thd->variables.log_slow_filter & SLOG_F_QC_NO) &&
++ ((thd->variables.log_slow_filter & SLOG_F_QC_NO) &&
+ (thd->query_plan_flags & QPLAN_QC))))
+ return;
+
+ /*
-+ Low long_query_time value most likely means user is debugging stuff and even
-+ though some thread's queries are not supposed to be logged b/c of the rate
-+ limit, if one of them takes long enough (>= 1 second) it will be sensible
++ Low long_query_time value most likely means user is debugging stuff and even
++ though some thread's queries are not supposed to be logged b/c of the rate
++ limit, if one of them takes long enough (>= 1 second) it will be sensible
+ to make an exception and write to slow log anyway.
+ */
-+ if (thd->write_to_slow_log != TRUE && thd->variables.long_query_time < 1000000 &&
-+ (ulong) (thd->start_timer - thd->timer_after_lock) >= 1000000)
-+ thd->write_to_slow_log= TRUE;
++
++ if (opt_use_global_long_query_time)
++ thd->variables.long_query_time = global_system_variables.long_query_time;
+
+ /* Do not log this thread's queries due to rate limiting. */
-+ if (thd->write_to_slow_log != TRUE)
++ if (thd->write_to_slow_log != TRUE
++ && (thd->variables.long_query_time >= 1000000
++ || (ulong) (thd->start_timer - thd->timer_after_lock) < 1000000))
+ return;
++
/*
Do not log administrative statements unless the appropriate option is
+ if (thd->enable_slow_log &&
+ (!thd->user_time || (thd->slave_thread && opt_log_slow_slave_statements))
+ )
++
{
- thd->proc_info="logging slow query";
+ thd_proc_info(thd, "logging slow query");
-- if ((ulong) (thd->start_time - thd->time_after_lock) >
-- thd->variables.long_query_time ||
-- (thd->server_status &
+- if ((thd->start_time > thd->time_after_lock &&
+- (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)) &&
- opt_log_queries_not_using_indexes &&
- /* == SQLCOM_END unless this is a SHOW command */
-- thd->lex->orig_sql_command == SQLCOM_END)
+- thd->lex->orig_sql_command == SQLCOM_END))
+ if (((ulong) (thd->start_timer - thd->timer_after_lock) >=
+ thd->variables.long_query_time ||
+ (thd->server_status &
+ thd->lex->orig_sql_command == SQLCOM_END) &&
+ thd->examined_row_count >= thd->variables.min_examined_row_limit)
{
+ thd_proc_info(thd, "logging slow query");
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);
}
}
}
-@@ -5949,6 +5985,15 @@
+@@ -2669,6 +2708,8 @@
+ context.resolve_in_table_list_only((TABLE_LIST*)select_lex->
+ table_list.first);
+
++ /* Reset the counter at all cases for the extended slow query log */
++ thd->row_count= 1;
+ /*
+ Reset warning count for each query that uses tables
+ A better approach would be to reset this for any commands
+@@ -6203,6 +6244,15 @@
thd->total_warn_count=0; // Warnings for this query
thd->rand_used= 0;
thd->sent_row_count= thd->examined_row_count= 0;
}
DBUG_VOID_RETURN;
}
-diff -r bb81fcdd7db2 sql/sql_select.cc
---- a/sql/sql_select.cc Mon Sep 08 16:38:33 2008 -0700
-+++ b/sql/sql_select.cc Mon Sep 08 16:38:46 2008 -0700
-@@ -6198,8 +6198,11 @@
+diff -r 1242d4575291 sql/sql_select.cc
+--- a/sql/sql_select.cc Tue Jul 28 23:39:12 2009 -0700
++++ b/sql/sql_select.cc Tue Jul 28 23:42:44 2009 -0700
+@@ -6272,8 +6272,11 @@
{
join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
if (statistics)
}
}
else
-@@ -6214,8 +6217,11 @@
+@@ -6288,8 +6291,11 @@
{
join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
if (statistics)
}
}
if (!table->no_keyread)
-@@ -9265,6 +9271,7 @@
+@@ -9350,6 +9356,7 @@
(ulong) rows_limit,test(group)));
statistic_increment(thd->status_var.created_tmp_tables, &LOCK_status);
if (use_temp_pool && !(test_flags & TEST_KEEP_TMP_TABLES))
temp_pool_slot = bitmap_set_next(&temp_pool);
-@@ -10125,6 +10132,7 @@
+@@ -10210,6 +10217,7 @@
}
statistic_increment(table->in_use->status_var.created_tmp_disk_tables,
&LOCK_status);
table->s->db_record_offset= 1;
DBUG_RETURN(0);
err:
-diff -r bb81fcdd7db2 sql/sql_show.cc
---- a/sql/sql_show.cc Mon Sep 08 16:38:33 2008 -0700
-+++ b/sql/sql_show.cc Mon Sep 08 16:38:46 2008 -0700
-@@ -1531,6 +1531,9 @@
- value= ((char *) status_var + (ulonglong) value);
+diff -r 1242d4575291 sql/sql_show.cc
+--- a/sql/sql_show.cc Tue Jul 28 23:39:12 2009 -0700
++++ b/sql/sql_show.cc Tue Jul 28 23:42:44 2009 -0700
+@@ -1560,6 +1560,12 @@
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_MICROTIME:
++ show_type= ((sys_var*) value)->show_type();
++ value= (char*) ((sys_var*) value)->value_ptr(thd, value_type,
++ &null_lex_str);
++ end= buff + sprintf(buff, "%f", (((double) (*(ulonglong*)value))) / 1000000.0);
++ break;
case SHOW_HA_ROWS:
end= longlong10_to_str((longlong) *(ha_rows*) value, buff, 10);
-diff -r bb81fcdd7db2 sql/structs.h
---- a/sql/structs.h Mon Sep 08 16:38:33 2008 -0700
-+++ b/sql/structs.h Mon Sep 08 16:38:46 2008 -0700
-@@ -168,7 +168,7 @@
+ break;
+diff -r 1242d4575291 sql/structs.h
+--- a/sql/structs.h Tue Jul 28 23:39:12 2009 -0700
++++ b/sql/structs.h Tue Jul 28 23:42:44 2009 -0700
+@@ -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_DOUBLE_STATUS,
+ SHOW_BOOL, SHOW_MY_BOOL, SHOW_OPENTABLES, SHOW_STARTTIME, SHOW_QUERIES,
SHOW_LONG_CONST, SHOW_INT_CONST, SHOW_HAVE, SHOW_SYS, SHOW_HA_ROWS,
+ SHOW_VARS,