=== added file 'doc/source/diagnostics/slow_log_in_memory.rst'
--- doc/source/diagnostics/slow_log_in_memory.rst	1970-01-01 00:00:00 +0000
+++ doc/source/diagnostics/slow_log_in_memory.rst	2012-01-02 12:24:34 +0000
@@ -0,0 +1,74 @@
+.. _slow_log_in_memory:
+
+=================
+ Slow Log In Memory
+=================
+
+The feature is used to save slow queries in memory. This feature adds an ``INFORMATION_SCHEMA.SLOW_LOG`` table to show the latest queries, a variable to limit the max memory used, and status to show the status of memory used. 
+
+There are two plugins in the feature. They can be installed by command ``"install plugin SLOWLOG_IN_MEMORY_AUDIT soname 'slowlog_in_memory.so'"`` and ``"install plugin SLOW_LOG soname 'slowlog_in_memory.so'"``, they work by keeping one list in memory. 
+
+
+Other Information
+=================
+
+  * Author/Origin:
+     *Percona*; *Percona* added an ``INFORMATION_SCHEMA`` table and the :variable:`slowlog_in_memory_audit_max_memory` and the :status:`slow_log_current_memory`.
+
+System Variables
+================
+
+.. variable:: slowlog_in_memory_audit_max_memory
+
+     :cli: Yes
+     :conf: Yes
+     :scope: Global
+     :dyn: Yes
+     :vartype: ULONG
+     :default: 1M
+     :range: 0 - 1G
+
+The variable is used to limit the max-memory used for slow log. If a new slow query will make the `current_memory` bigger than this value, the most eldest items will be discarded, until there is enough memory for new item. When the value is decrease dynamically, it behaves the same.
+
+Status Variables
+================
+
+One new status variable was introduced by this feature.
+
+.. variable:: slow_log_current_memory
+
+     :vartype: ULONG
+     :scope: Global
+
+The variable showes the current memory used for the slow queries. It can never be bigger than the `slowlog_in_memory_audit_max_memory` variable.
+
+
+INFORMATION_SCHEMA Tables
+=========================
+
+.. table:: INFORMATION_SCHEMA.SLOW_LOG
+
+  :column EVENT_ID: A global increment id for every record in the table, can be used to identify every one.
+  :column TIMESTAMP: The timestamp when the query stop.
+  :column THREAD_ID: The thread_id of the query.
+  :column DB: The current database() of the query, may be NULL.
+  :column INNODB_TRX_ID: The Innodb_trx_id if InnoDB is used, may be NULL.
+  :column ERROR: The errno of the query, 0 means no error.
+  :column MS_QUERY_TIME: The query_exec_time of the query, in second.
+  :column QUERY: The query statement.
+
+This table holds the lastest slow queries.
+
+Example: ::
+
+  mysql> select * from information_schema.slow_log \G
+  *************************** 1. row ***************************
+       EVENT_ID: 1
+      TIMESTAMP: 1323753896
+      THREAD_ID: 2
+             DB: test
+  INNODB_TRX_ID: NULL
+          ERRNO: 0
+  MS_QUERY_TIME: 3001
+          QUERY: select sleep(3)
+

=== modified file 'patches/series'
--- patches/series	2011-12-16 09:37:26 +0000
+++ patches/series	2012-01-02 12:24:34 +0000
@@ -62,3 +62,4 @@
 bug45702.patch
 group_commit.patch
 warning_fixes.patch
+slowlog_in_memory.patch

=== added file 'patches/slowlog_in_memory.patch'
--- patches/slowlog_in_memory.patch	1970-01-01 00:00:00 +0000
+++ patches/slowlog_in_memory.patch	2012-01-02 12:24:34 +0000
@@ -0,0 +1,804 @@
+--- a/plugin/slowlog_in_memory/CMakeLists.txt	1970-01-01 08:00:00.000000000 +0800
++++ b/plugin/slowlog_in_memory/CMakeLists.txt	2011-12-22 21:08:28.000000000 +0800
+@@ -0,0 +1,17 @@
++# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
++# 
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; version 2 of the License.
++# 
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++# 
++# You should have received a copy of the GNU General Public License
++# along with this program; if not, write to the Free Software
++# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
++
++MYSQL_ADD_PLUGIN(slowlog_in_memory slowlog_in_memory.cc
++  MODULE_ONLY MODULE_OUTPUT_NAME "slowlog_in_memory")
+--- a/plugin/slowlog_in_memory/slowlog_in_memory.cc	1970-01-01 08:00:00.000000000 +0800
++++ b/plugin/slowlog_in_memory/slowlog_in_memory.cc	2011-12-22 21:09:34.000000000 +0800
+@@ -0,0 +1,295 @@
++/* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
++
++  This program is free software; you can redistribute it and/or
++  modify it under the terms of the GNU General Public License
++  as published by the Free Software Foundation; version 2 of
++  the License.
++
++  This program is distributed in the hope that it will be useful,
++  but WITHOUT ANY WARRANTY; without even the implied warranty of
++  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++  GNU General Public License for more details.
++
++  You should have received a copy of the GNU General Public License
++  along with this program; if not, write to the Free Software
++  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
++
++#include "ut_slow_log_list.h"
++
++#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
++#define __attribute__(A)
++#endif
++typedef struct st_mysql_sys_var SYS_VAR;
++uint max_memory_for_slow_log;
++
++/* lock management */
++
++slow_log_list *global_slow_log_list= NULL;
++
++/*
++  Initialize the plugin at server start or plugin installation.
++
++  SYNOPSIS
++    slow_log_in_memory_plugin_init()
++
++  DESCRIPTION
++    Does nothing.
++
++  RETURN VALUE
++    0                    success
++    1                    failure (cannot happen)
++*/
++
++static int slow_log_in_memory_plugin_init(void *arg __attribute__((unused)))
++{
++#ifdef HAVE_PSI_INTERFACE
++  init_semisync_psi_keys();
++#endif
++
++  mysql_mutex_init(key_ss_mutex_LOCK_slow_event_id_,
++                   &LOCK_slow_event_id_, MY_MUTEX_INIT_FAST);
++  global_slow_log_list= new slow_log_list(max_memory_for_slow_log);
++
++  return 0; 
++}
++
++
++/*
++  Terminate the plugin at server shutdown or plugin deinstallation.
++
++  SYNOPSIS
++    slow_log_in_memory_plugin_deinit()
++    Does nothing.
++
++  RETURN VALUE
++    0                    success
++    1                    failure (cannot happen)
++*/
++
++static int slow_log_in_memory_plugin_deinit(void *arg __attribute__((unused)))
++{
++  if (global_slow_log_list)
++  {
++    delete global_slow_log_list;
++    global_slow_log_list= NULL;
++  }
++
++  mysql_mutex_destroy(&LOCK_slow_event_id_);
++  return 0;
++}
++
++/*
++  Foo
++
++  SYNOPSIS
++    slow_log_in_memory_notify()
++      thd                connection context
++
++  DESCRIPTION
++*/
++
++static void slow_log_in_memory_notify(MYSQL_THD thd __attribute__((unused)),
++                              unsigned int event_class,
++                              const void *event)
++{
++  if (max_memory_for_slow_log == 0) return;
++
++  if (event_class == MYSQL_AUDIT_GENERAL_CLASS)
++  {
++    const struct mysql_event_general *event_general=
++      (const struct mysql_event_general *) event;
++    if (event_general->event_subclass != MYSQL_AUDIT_GENERAL_STATUS)
++      return;
++
++    ulonglong utime_of_query= thd->current_utime() - thd->utime_after_lock;
++
++#ifndef DBUG_OFF
++    if (thd->variables.query_exec_time != 0)
++      utime_of_query= thd->lex->sql_command != SQLCOM_SET_OPTION ? thd->variables.query_exec_time : 0;
++#endif
++
++    if (utime_of_query <= thd->variables.long_query_time)
++      return;
++
++    slow_log_t *tmp= new slow_log_t(event_general->general_time, event_general->general_thread_id, thd->db, thd->innodb_trx_id, event_general->general_error_code, (double)utime_of_query/1000000, event_general->general_query);
++    global_slow_log_list->push_back(tmp);
++  }
++}
++
++
++/*
++  Plugin type-specific descriptor
++*/
++
++static struct st_mysql_audit slow_log_in_memory_descriptor=
++{
++  MYSQL_AUDIT_INTERFACE_VERSION,                    /* interface version    */
++  NULL,                                             /* release_thd function */
++  slow_log_in_memory_notify,                                /* notify function      */
++  { (unsigned long) MYSQL_AUDIT_GENERAL_CLASSMASK } /* class mask           */
++};
++
++static void change_max_memory_for_slow_log(MYSQL_THD thd,
++					SYS_VAR *var,
++					void *ptr,
++					const void *val)
++{
++  uint new_len= *(uint *)val;
++  *(uint *)ptr= new_len;
++  
++  global_slow_log_list->change_max_memory(new_len);
++  return;
++}
++
++static MYSQL_SYSVAR_UINT(max_memory, max_memory_for_slow_log,
++  PLUGIN_VAR_OPCMDARG,
++  "The max memory that can be allocated for slow log.",
++  NULL,				// check
++  &change_max_memory_for_slow_log, // update
++  1024*1024, 0, 1024*1024*1024, 1);
++
++static SYS_VAR* slow_log_in_memory_system_vars[]= {
++  MYSQL_SYSVAR(max_memory),
++  NULL,
++};
++
++static uint slow_log_current_memory(MYSQL_THD thd, SHOW_VAR *var, char *buff)
++{
++  var->type= SHOW_INT;
++  var->value= (char*)&global_slow_log_list->current_memory;
++  return 0;
++}
++
++/* plugin status variables */
++static SHOW_VAR slow_log_in_memory_status_vars[]= {
++  {"slow_log_current_memory",
++   (char*) &slow_log_current_memory,
++   SHOW_FUNC},
++  {NULL, NULL, SHOW_LONG},
++};
++
++
++/*
++   I_S_SLOW_LOG 
++*/
++static struct st_mysql_information_schema i_s_slow_log=
++{
++  MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
++};
++
++static ST_FIELD_INFO i_s_slow_log_fields[] =
++{
++  {"EVENT_ID", 11, MYSQL_TYPE_LONGLONG, 0, 0, 0, SKIP_OPEN_TABLE},
++  {"TIMESTAMP", 11, MYSQL_TYPE_LONGLONG, 0, 0, 0, SKIP_OPEN_TABLE},
++  {"THREAD_ID", 11, MYSQL_TYPE_LONG, 0, 0, 0, SKIP_OPEN_TABLE},
++  {"DB", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
++  {"INNODB_TRX_ID", 11, MYSQL_TYPE_LONGLONG, 0, 1, 0, SKIP_OPEN_TABLE},
++  {"ERRNO", 11, MYSQL_TYPE_LONG, 0, 0, 0, SKIP_OPEN_TABLE},
++  {"MS_QUERY_TIME", 11, MYSQL_TYPE_FLOAT, 0, 0, 0, SKIP_OPEN_TABLE},
++
++  {"QUERY", 255, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
++  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
++};
++
++
++int i_s_fill_table_slow_log(THD* thd, TABLE_LIST* tables, COND* cond)
++{
++  if (!global_slow_log_list) return 0;
++ 
++  TABLE *table= tables->table;
++
++  mysql_mutex_lock(&global_slow_log_list->LOCK_slow_log_);
++
++  slow_log_t *item= global_slow_log_list->first;
++  while (item)
++  {
++    restore_record(table, s->default_values);
++
++    table->field[0]->store(item->event_id, TRUE);
++    table->field[1]->store(item->timestamp, TRUE);
++    table->field[2]->store(item->thread_id, TRUE);
++
++    if (item->schema)
++    {
++      table->field[3]->store(item->schema, item->schema_len-1, system_charset_info);
++      table->field[3]->set_notnull();
++    }
++
++    if (item->innodb_trx_id)
++    {
++      table->field[4]->store(item->innodb_trx_id, TRUE);
++      table->field[4]->set_notnull();
++    }
++
++    table->field[5]->store(item->cmd_errno, TRUE);
++    table->field[6]->store(item->time_of_query);
++
++    if (item->general_query)
++    {
++      table->field[7]->store(item->general_query, item->general_query_len-1, system_charset_info);
++      table->field[7]->set_notnull();
++    }
++
++    schema_table_store_record(thd, table);
++    item= item->next;
++  }
++
++  mysql_mutex_unlock(&global_slow_log_list->LOCK_slow_log_);
++  return 0;
++}
++
++
++static int i_s_slow_log_plugin_init(void *arg __attribute__((unused)))
++{
++  ST_SCHEMA_TABLE* schema;
++
++  schema = (ST_SCHEMA_TABLE*) arg;
++
++  schema->fields_info = i_s_slow_log_fields;
++  schema->fill_table = i_s_fill_table_slow_log;
++  return 0;
++}
++
++
++static int i_s_slow_log_plugin_deinit(void *arg __attribute__((unused)))
++{
++  return(0);
++}
++
++/*
++  Plugin library descriptor
++*/
++
++mysql_declare_plugin(slow_log_in_memory)
++{
++  MYSQL_AUDIT_PLUGIN,         /* type                            */
++  &slow_log_in_memory_descriptor,     /* descriptor                      */
++  "SLOW_LOG_IN_MEMORY_AUDIT",               /* name                            */
++  "Percona",              /* author                          */
++  "Error code histogram Audit",        /* description                     */
++  PLUGIN_LICENSE_GPL,
++  slow_log_in_memory_plugin_init,     /* init function (when loaded)     */
++  slow_log_in_memory_plugin_deinit,   /* deinit function (when unloaded) */
++  0x0001,                     /* version                         */
++  slow_log_in_memory_status_vars,              /* status variables                */
++  slow_log_in_memory_system_vars,                       /* system variables                */
++  NULL,
++  0,
++},
++{
++  MYSQL_INFORMATION_SCHEMA_PLUGIN,         /* type                            */
++  &i_s_slow_log,     /* descriptor                      */
++  "SLOW_LOG",               /* name                            */
++  "Percona",              /* author                          */
++  "latest slow log in memory",        /* description                     */
++  PLUGIN_LICENSE_GPL,
++  i_s_slow_log_plugin_init,     /* init function (when loaded)     */
++  i_s_slow_log_plugin_deinit,   /* deinit function (when unloaded) */
++  0x0001,                     /* version                         */
++  NULL,              /* status variables                */
++  NULL,                       /* system variables                */
++  NULL,
++  0,
++}
++mysql_declare_plugin_end;
++
+--- a/plugin/slowlog_in_memory/ut_slow_log_list.h	1970-01-01 08:00:00.000000000 +0800
++++ b/plugin/slowlog_in_memory/ut_slow_log_list.h	2011-12-22 21:09:34.000000000 +0800
+@@ -0,0 +1,230 @@
++#ifndef UT_SLOW_LOG_LIST_H
++#define UT_SLOW_LOG_LIST_H
++
++#define MYSQL_SERVER
++#include <mysql/plugin_audit.h>
++#include "unireg.h"
++#include "sql_show.h"
++#include "sql_class.h"
++
++mysql_mutex_t LOCK_slow_event_id_;
++
++#ifdef HAVE_PSI_INTERFACE
++PSI_mutex_key key_ss_mutex_LOCK_slow_log_;
++PSI_mutex_key key_ss_mutex_LOCK_slow_event_id_;
++
++static PSI_mutex_info all_semisync_mutexes[]=
++{
++  {&key_ss_mutex_LOCK_slow_log_, "LOCK_slow_log_", 0},
++  {&key_ss_mutex_LOCK_slow_event_id_, "LOCK_slow_event_id_", 0}
++};
++
++static void init_semisync_psi_keys(void)
++{
++  const char* category= "semisync";
++  int count;
++
++  if (PSI_server == NULL)
++    return;
++
++  count= array_elements(all_semisync_mutexes);
++  PSI_server->register_mutex(category, all_semisync_mutexes, count);
++
++}
++#endif /* HAVE_PSI_INTERFACE */
++
++/* unique event id for each slow query */
++ulonglong global_event_id= 0;
++
++const uint MAX_QUERY_LEN= 255;
++
++class slow_log_t
++{
++public:
++  ulonglong event_id;
++  ulonglong timestamp;
++  ulong thread_id;
++  char *schema;
++  ulonglong innodb_trx_id;
++  int cmd_errno;
++  double time_of_query;
++  char *general_query;
++  
++  uint schema_len;
++  uint general_query_len;
++
++  slow_log_t *next;
++
++  slow_log_t(ulonglong timestamp, ulong thread_id, const char *schema,
++    ulonglong innodb_trx_id, int cmd_errno, double time_of_query, const char *general_query):next(NULL)
++  {
++    this->timestamp= timestamp;
++    this->thread_id= thread_id;
++
++    if (schema)
++    {
++      this->schema_len= strlen(schema) + 1;
++      this->schema= strndup(schema, this->schema_len);
++    }
++    else
++    {
++      this->schema= NULL;
++      this->schema_len= 0;
++    }
++
++    this->innodb_trx_id= innodb_trx_id;
++    this->cmd_errno= cmd_errno;
++    this->time_of_query= time_of_query;
++
++    if (general_query)
++    {
++      this->general_query_len= strlen(general_query) + 1;
++
++      if (this->general_query_len > MAX_QUERY_LEN)
++      {
++        this->general_query_len= MAX_QUERY_LEN;
++      }
++
++      this->general_query= strndup(general_query, this->general_query_len);
++      this->general_query[this->general_query_len-1]= '\0';
++    }
++    else
++    {
++      this->general_query= NULL;
++      this->general_query_len= 0;
++    }
++
++    this->real_size= sizeof(slow_log_t) + this->schema_len + this->general_query_len;
++    
++    mysql_mutex_lock(&LOCK_slow_event_id_);
++    this->event_id= ++global_event_id;
++    mysql_mutex_unlock(&LOCK_slow_event_id_);
++  }
++
++  ~slow_log_t()
++  {
++    if (schema)
++    {
++       free(schema);
++       schema= NULL;
++    }
++
++    if (general_query)
++    {
++       free(general_query);
++       general_query= NULL;
++    }
++  }
++
++  uint size_of_instance()
++  {
++    return real_size;
++  }
++
++  uint real_size;
++};
++
++class slow_log_list
++{
++public:
++  slow_log_t *first, *last;
++  mysql_mutex_t LOCK_slow_log_;
++
++  uint current_memory;
++
++  void change_max_memory(uint new_len)
++  {
++    mysql_mutex_lock(&LOCK_slow_log_);
++
++    max_memory= new_len;
++
++    /* if the size is larger than current size, just change the value*/
++    if (max_memory >= current_memory)
++    {
++      mysql_mutex_unlock(&LOCK_slow_log_);
++      return;
++    }
++
++    while (current_memory > max_memory)
++    {
++      pop_front();
++    }
++
++    mysql_mutex_unlock(&LOCK_slow_log_);
++  }
++
++  slow_log_list(uint max_memory)
++  {
++    first= NULL;
++    last= NULL;
++    current_memory= 0;
++    this->max_memory= max_memory;
++
++    mysql_mutex_init(key_ss_mutex_LOCK_slow_log_,
++                &LOCK_slow_log_, MY_MUTEX_INIT_FAST);
++  }
++
++  ~slow_log_list()
++  {
++    mysql_mutex_lock(&LOCK_slow_log_);
++    while (first)
++    {
++      pop_front();
++    }
++    mysql_mutex_unlock(&LOCK_slow_log_);
++
++    mysql_mutex_destroy(&LOCK_slow_log_);
++  }
++
++  void push_back(slow_log_t * item)
++  {
++    mysql_mutex_lock(&LOCK_slow_log_);
++
++    uint size= item->size_of_instance();
++
++    if (size > max_memory)
++    {
++      sql_print_warning("the insert item size %u > %u discarded", size, max_memory);
++      mysql_mutex_unlock(&LOCK_slow_log_);
++      return;
++    }
++
++    while (current_memory + size > max_memory)
++    {
++      pop_front();
++    }
++
++    if (!first)
++    {
++       first= item;
++       last= item;
++    }
++    else
++    {
++      last->next= item;
++      last= item;
++    }
++
++    current_memory+= size;
++    mysql_mutex_unlock(&LOCK_slow_log_);
++  }
++
++  /*functions call pop_front should have hold LOCK_slow_log_*/
++  void pop_front()
++  {
++    if (!first) return;
++
++    slow_log_t *item= first;
++    first= first->next;
++
++    if (!first) last= NULL;
++
++    current_memory-= item->size_of_instance();
++    delete item;
++  }
++
++private:
++  uint max_memory;
++};
++#endif
++
+--- a/mysql-test/include/have_slog_log_in_memory_audit_plugin.inc	1970-01-01 08:00:00.000000000 +0800
++++ b/mysql-test/include/have_slog_log_in_memory_audit_plugin.inc	2011-12-22 21:08:28.000000000 +0800
+@@ -0,0 +1,21 @@
++#
++# Check if server has support for loading plugins
++#
++if (`SELECT @@have_dynamic_loading != 'YES'`) {
++  --skip Requires dynamic loading
++}
++
++#
++# Check if the variable SLOW_LOG_IN_MEMORY_AUDIT is set
++#
++if (!$SLOW_LOG_IN_MEMORY_AUDIT)
++{
++  skip Need slow_log_in_memory plugins;
++}
++
++#
++# Check if --plugin-dir was setup for slow_log_in_memory
++#
++if (`SELECT CONCAT('--plugin-dir=', @@plugin_dir) != '$SLOW_LOG_IN_MEMORY_AUDIT_OPT'`) {
++  --skip SLOW_LOG plugin requires that --plugin-dir is set to the slow_log_in_memory plugin dir (either the .opt file does not contain \$SLOW_LOG_IN_MEMORY_AUDIT_OPT or another plugin is in use)
++}
+--- a/mysql-test/include/plugin.defs	2011-12-19 14:44:49.000000000 +0800
++++ b/mysql-test/include/plugin.defs	2011-12-22 21:08:28.000000000 +0800
+@@ -40,3 +40,5 @@
+ ha_federated       storage/federated  FEDERATED_PLUGIN
+ mypluglib          plugin/fulltext    SIMPLE_PARSER
+ libdaemon_example  plugin/daemon_example DAEMONEXAMPLE
++slowlog_in_memory  plugin/slowlog_in_memory SLOW_LOG
++slowlog_in_memory  plugin/slowlog_in_memory SLOW_LOG_IN_MEMORY_AUDIT 
+--- a/mysql-test/r/slow_log_in_memory.result	1970-01-01 08:00:00.000000000 +0800
++++ b/mysql-test/r/slow_log_in_memory.result	2011-12-22 21:10:53.000000000 +0800
+@@ -0,0 +1,69 @@
++#
++# feature: slow log show in information_schema.slow_log 
++#
++install plugin SLOW_LOG_IN_MEMORY_AUDIT  soname 'slowlog_in_memory.so';
++install plugin SLOW_LOG  soname 'slowlog_in_memory.so';
++show variables like 'slow_log_in_memory_audit_max_memory';
++Variable_name	Value
++slow_log_in_memory_audit_max_memory	1048576
++SET long_query_time=2;
++SET query_exec_time=2.123456;
++select 1;
++1
++1
++SET query_exec_time=0;
++SET long_query_time=2;
++SET query_exec_time=2.1;
++select 1;
++1
++1
++SET query_exec_time=0;
++SET long_query_time=2;
++SET query_exec_time=2.1;
++select 1;
++1
++1
++SET query_exec_time=0;
++show global status like 'slow_log_current_memory';
++Variable_name	Value
++slow_log_current_memory	XX
++select * from information_schema.slow_log;
++EVENT_ID	TIMESTAMP	THREAD_ID	DB	INNODB_TRX_ID	ERRNO	MS_QUERY_TIME	QUERY
++1	XX	XX	test	XX	0	2.123456	select 1
++2	XX	XX	test	XX	0	2.1	select 1
++3	XX	XX	test	XX	0	2.1	select 1
++# decrease max_memory and wash eldest
++set global slow_log_in_memory_audit_max_memory=240;
++use information_schema;
++SET long_query_time=2;
++SET query_exec_time=2.1;
++select 1;
++1
++1
++SET query_exec_time=0;
++show global status like 'slow_log_current_memory';
++Variable_name	Value
++slow_log_current_memory	XX
++select * from information_schema.slow_log;
++EVENT_ID	TIMESTAMP	THREAD_ID	DB	INNODB_TRX_ID	ERRNO	MS_QUERY_TIME	QUERY
++3	XX	XX	test	XX	0	2.1	select 1
++4	XX	XX	information_schema	XX	0	2.1	select 1
++# set to zero to disable audit
++set global slow_log_in_memory_audit_max_memory=0;
++SET long_query_time=2;
++SET query_exec_time=2.1;
++select 1;
++1
++1
++SET query_exec_time=0;
++show global status like 'slow_log_current_memory';
++Variable_name	Value
++slow_log_current_memory	0
++select * from information_schema.slow_log;
++EVENT_ID	TIMESTAMP	THREAD_ID	DB	INNODB_TRX_ID	ERRNO	MS_QUERY_TIME	QUERY
++uninstall plugin SLOW_LOG;
++uninstall plugin SLOW_LOG_IN_MEMORY_AUDIT;
++Warnings:
++Warning	1620	Plugin is busy and will be uninstalled on shutdown
++SET SESSION query_exec_time=default;
++SET long_query_time=default;
+--- a/mysql-test/suite/sys_vars/r/slow_log_in_memory_audit.result	1970-01-01 08:00:00.000000000 +0800
++++ b/mysql-test/suite/sys_vars/r/slow_log_in_memory_audit.result	2011-12-22 21:08:28.000000000 +0800
+@@ -0,0 +1,31 @@
++install plugin SLOW_LOG_IN_MEMORY_AUDIT  soname 'slowlog_in_memory.so';
++install plugin SLOW_LOG  soname 'slowlog_in_memory.so';
++select @@global.slow_log_in_memory_audit_max_memory;
++@@global.slow_log_in_memory_audit_max_memory
++1048576
++show global variables like 'slow_log_in_memory_audit_max_memory';
++Variable_name	Value
++slow_log_in_memory_audit_max_memory	1048576
++select * from information_schema.global_variables where variable_name='slow_log_in_memory_audit_max_memory';
++VARIABLE_NAME	VARIABLE_VALUE
++SLOW_LOG_IN_MEMORY_AUDIT_MAX_MEMORY	1048576
++set global slow_log_in_memory_audit_max_memory=2097152;
++select @@global.slow_log_in_memory_audit_max_memory;
++@@global.slow_log_in_memory_audit_max_memory
++2097152
++show global variables like 'slow_log_in_memory_audit_max_memory';
++Variable_name	Value
++slow_log_in_memory_audit_max_memory	2097152
++set global slow_log_in_memory_audit_max_memory=1.1;
++ERROR 42000: Incorrect argument type to variable 'slow_log_in_memory_audit_max_memory'
++set global slow_log_in_memory_audit_max_memory=1e1;
++ERROR 42000: Incorrect argument type to variable 'slow_log_in_memory_audit_max_memory'
++set global slow_log_in_memory_audit_max_memory="some text";
++ERROR 42000: Incorrect argument type to variable 'slow_log_in_memory_audit_max_memory'
++select @@global.slow_log_in_memory_audit_max_memory;
++@@global.slow_log_in_memory_audit_max_memory
++2097152
++UNINSTALL PLUGIN SLOW_LOG;
++UNINSTALL PLUGIN SLOW_LOG_IN_MEMORY_AUDIT;
++Warnings:
++Warning	1620	Plugin is busy and will be uninstalled on shutdown
+--- a/mysql-test/suite/sys_vars/t/slow_log_in_memory_audit-master.opt	1970-01-01 08:00:00.000000000 +0800
++++ b/mysql-test/suite/sys_vars/t/slow_log_in_memory_audit-master.opt	2011-12-22 21:08:28.000000000 +0800
+@@ -0,0 +1 @@
++$SLOW_LOG_IN_MEMORY_AUDIT_OPT
+--- a/mysql-test/suite/sys_vars/t/slow_log_in_memory_audit.test	1970-01-01 08:00:00.000000000 +0800
++++ b/mysql-test/suite/sys_vars/t/slow_log_in_memory_audit.test	2011-12-22 21:08:28.000000000 +0800
+@@ -0,0 +1,40 @@
++
++#
++# exists as a global only
++#
++source include/not_embedded.inc;
++source include/have_slog_log_in_memory_audit_plugin.inc;
++# The following is to prevent a mis-match on windows that has the name of of the lib ending with 'dll' 
++--replace_regex /\.dll/.so/
++install plugin SLOW_LOG_IN_MEMORY_AUDIT  soname 'slowlog_in_memory.so';
++install plugin SLOW_LOG  soname 'slowlog_in_memory.so';
++select @@global.slow_log_in_memory_audit_max_memory;
++
++show global variables like 'slow_log_in_memory_audit_max_memory';
++select * from information_schema.global_variables where variable_name='slow_log_in_memory_audit_max_memory';
++
++#
++# show that it's writable
++#
++set global slow_log_in_memory_audit_max_memory=2097152;
++select @@global.slow_log_in_memory_audit_max_memory;
++show global variables like 'slow_log_in_memory_audit_max_memory';
++
++#
++# incorrect types
++#
++--error ER_WRONG_TYPE_FOR_VAR
++set global slow_log_in_memory_audit_max_memory=1.1;
++--error ER_WRONG_TYPE_FOR_VAR
++set global slow_log_in_memory_audit_max_memory=1e1;
++--error ER_WRONG_TYPE_FOR_VAR
++set global slow_log_in_memory_audit_max_memory="some text";
++
++
++#
++# Cleanup
++#
++select @@global.slow_log_in_memory_audit_max_memory;
++UNINSTALL PLUGIN SLOW_LOG;
++UNINSTALL PLUGIN SLOW_LOG_IN_MEMORY_AUDIT;
++
+--- a/mysql-test/t/slow_log_in_memory-master.opt	1970-01-01 08:00:00.000000000 +0800
++++ b/mysql-test/t/slow_log_in_memory-master.opt	2011-12-22 21:08:28.000000000 +0800
+@@ -0,0 +1 @@
++$SLOW_LOG_IN_MEMORY_AUDIT_OPT
+--- a/mysql-test/t/slow_log_in_memory.test	1970-01-01 08:00:00.000000000 +0800
++++ b/mysql-test/t/slow_log_in_memory.test	2011-12-22 21:10:45.000000000 +0800
+@@ -0,0 +1,61 @@
++--source include/have_debug.inc
++--source include/have_slog_log_in_memory_audit_plugin.inc
++
++--echo #
++--echo # feature: slow log show in information_schema.slow_log 
++--echo #
++
++install plugin SLOW_LOG_IN_MEMORY_AUDIT  soname 'slowlog_in_memory.so';
++install plugin SLOW_LOG  soname 'slowlog_in_memory.so';
++show variables like 'slow_log_in_memory_audit_max_memory';
++
++SET long_query_time=2;
++SET query_exec_time=2.123456;
++select 1;
++SET query_exec_time=0;
++
++connect (con1,localhost,root,,);
++
++SET long_query_time=2;
++SET query_exec_time=2.1;
++select 1;
++SET query_exec_time=0;
++
++connect (con2,localhost,root,,);
++
++SET long_query_time=2;
++SET query_exec_time=2.1;
++select 1;
++SET query_exec_time=0;
++--replace_column 2 XX
++show global status like 'slow_log_current_memory';
++--replace_column 2 XX 3 XX 5 XX
++select * from information_schema.slow_log;
++
++--echo # decrease max_memory and wash eldest
++set global slow_log_in_memory_audit_max_memory=240;
++connection con1;
++use information_schema;
++SET long_query_time=2;
++SET query_exec_time=2.1;
++select 1;
++SET query_exec_time=0;
++--replace_column 2 XX
++show global status like 'slow_log_current_memory';
++--replace_column 2 XX 3 XX 5 XX
++select * from information_schema.slow_log;
++
++--echo # set to zero to disable audit
++connection con1;
++set global slow_log_in_memory_audit_max_memory=0;
++SET long_query_time=2;
++SET query_exec_time=2.1;
++select 1;
++SET query_exec_time=0;
++show global status like 'slow_log_current_memory';
++select * from information_schema.slow_log;
++
++uninstall plugin SLOW_LOG;
++uninstall plugin SLOW_LOG_IN_MEMORY_AUDIT;
++SET SESSION query_exec_time=default;
++SET long_query_time=default;

