List:Commits« Previous MessageNext Message »
From:Georgi Kodinov Date:June 3 2011 11:45am
Subject:bzr commit into mysql-trunk branch (Georgi.Kodinov:3153) Bug#11757216
View as plain text  
#At file:///Users/kgeorge/mysql/work/B11757216-trunk/ based on revid:anitha.gopi@stripped

 3153 Georgi Kodinov	2011-06-03
      BUG# 11757216: 49232: --STORAGE-ENGINE SHOULD BE DECOUPLED FROM 
      DEFAULT TEMPTABLE TYPE
      
      Implemented a default_temp_storage_engine variable to complement the 
      default_storage_engine.
      It's default value is the same as of --default-storage-engine.
      But it's totally independent from --default-storage-engine.
      The value of --default-temp-storage-engine affects only the tables created 
      by CREATE TEMPORARY TABLE. All other internally created temp tables are not 
      affected by it.
      Similarly to the special storage engine name "DEFAULT" there's a "DFL_TMP" as 
      an alias of the default temp table storage engine.
      Extended mysql-test-run.pl to issue --default-temp-storage-engine=myisam
      as a complement to --default-storage-engine=myisam.
      
      Test case added. 
      Affected test cases updated.

    added:
      mysql-test/suite/sys_vars/r/default_temp_storage_engine_basic.result
      mysql-test/suite/sys_vars/t/default_temp_storage_engine_basic.test
    modified:
      mysql-test/lib/mtr_cases.pm
      mysql-test/mysql-test-run.pl
      mysql-test/r/mysqld--help-notwin.result
      mysql-test/r/mysqld--help-win.result
      sql/handler.cc
      sql/handler.h
      sql/mysqld.cc
      sql/mysqld.h
      sql/sql_class.h
      sql/sql_plugin.cc
      sql/sql_show.cc
      sql/sql_yacc.yy
      sql/sys_vars.cc
=== modified file 'mysql-test/lib/mtr_cases.pm'
--- a/mysql-test/lib/mtr_cases.pm	2011-05-24 10:07:40 +0000
+++ b/mysql-test/lib/mtr_cases.pm	2011-06-03 11:45:11 +0000
@@ -613,9 +613,12 @@ sub optimize_cases {
     foreach my $opt ( @{$tinfo->{master_opt}} ) {
       my $default_engine=
 	mtr_match_prefix($opt, "--default-storage-engine=");
+      my $default_temp_engine=
+	mtr_match_prefix($opt, "--default-temp-storage-engine=");
 
       # Allow use of uppercase, convert to all lower case
       $default_engine =~ tr/A-Z/a-z/;
+      $default_temp_engine =~ tr/A-Z/a-z/;
 
       if (defined $default_engine){
 
@@ -638,6 +641,27 @@ sub optimize_cases {
 	$tinfo->{'innodb_test'}= 1
 	  if ( $default_engine =~ /^innodb/i );
       }
+      if (defined $default_temp_engine){
+
+	#print " $tinfo->{name}\n";
+	#print " - The test asked to use '$default_engine'\n";
+
+	#my $engine_value= $::mysqld_variables{$default_engine};
+	#print " - The mysqld_variables says '$engine_value'\n";
+
+	if ( ! exists $::mysqld_variables{$default_temp_engine} and
+	     ! exists $builtin_engines{$default_temp_engine} )
+	{
+	  $tinfo->{'skip'}= 1;
+	  $tinfo->{'comment'}=
+	    "'$default_temp_engine' not supported";
+	}
+
+	$tinfo->{'ndb_test'}= 1
+	  if ( $default_temp_engine =~ /^ndb/i );
+	$tinfo->{'innodb_test'}= 1
+	  if ( $default_temp_engine =~ /^innodb/i );
+      }
     }
 
     if ($quick_collect && ! $tinfo->{'skip'})
@@ -987,6 +1011,8 @@ sub collect_one_test_case {
     # the default storage engine is innodb.
     push(@{$tinfo->{'master_opt'}}, "--default-storage-engine=MyISAM");
     push(@{$tinfo->{'slave_opt'}}, "--default-storage-engine=MyISAM");
+    push(@{$tinfo->{'master_opt'}}, "--default-temp-storage-engine=MyISAM");
+    push(@{$tinfo->{'slave_opt'}}, "--default-temp-storage-engine=MyISAM");
   }
 
   if ( $tinfo->{'need_binlog'} )

=== modified file 'mysql-test/mysql-test-run.pl'
--- a/mysql-test/mysql-test-run.pl	2011-05-30 14:00:14 +0000
+++ b/mysql-test/mysql-test-run.pl	2011-06-03 11:45:11 +0000
@@ -1367,6 +1367,12 @@ sub command_line_setup {
       collect_option('default-storage-engine', $1);
       mtr_report("Using default engine '$1'")
     }
+    if ( $arg =~ /default-temp-storage-engine=(\S+)/ )
+    {
+      # Save this for collect phase
+      collect_option('default-temp-storage-engine', $1);
+      mtr_report("Using default temp engine '$1'")
+    }
   }
 
   if (IS_WINDOWS and defined $opt_mem) {

=== modified file 'mysql-test/r/mysqld--help-notwin.result'
--- a/mysql-test/r/mysqld--help-notwin.result	2011-05-26 05:50:01 +0000
+++ b/mysql-test/r/mysqld--help-notwin.result	2011-06-03 11:45:11 +0000
@@ -123,6 +123,9 @@ The following options may be given as th
  The DATETIME format (ignored)
  --default-storage-engine=name 
  The default storage engine for new tables
+ --default-temp-storage-engine=name 
+ The default storage engine for new explict temporary
+ tables
  --default-time-zone=name 
  Set the default time zone.
  --default-week-format=# 
@@ -789,6 +792,7 @@ console FALSE
 date-format %Y-%m-%d
 datetime-format %Y-%m-%d %H:%i:%s
 default-storage-engine InnoDB
+default-temp-storage-engine InnoDB
 default-time-zone (No default value)
 default-week-format 0
 delay-key-write ON

=== modified file 'mysql-test/r/mysqld--help-win.result'
--- a/mysql-test/r/mysqld--help-win.result	2011-05-26 05:50:01 +0000
+++ b/mysql-test/r/mysqld--help-win.result	2011-06-03 11:45:11 +0000
@@ -123,6 +123,9 @@ The following options may be given as th
  The DATETIME format (ignored)
  --default-storage-engine=name 
  The default storage engine for new tables
+ --default-temp-storage-engine=name 
+ The default storage engine for new explict temporary
+ tables
  --default-time-zone=name 
  Set the default time zone.
  --default-week-format=# 
@@ -793,6 +796,7 @@ console FALSE
 date-format %Y-%m-%d
 datetime-format %Y-%m-%d %H:%i:%s
 default-storage-engine InnoDB
+default-temp-storage-engine InnoDB
 default-time-zone (No default value)
 default-week-format 0
 delay-key-write ON

=== added file 'mysql-test/suite/sys_vars/r/default_temp_storage_engine_basic.result'
--- a/mysql-test/suite/sys_vars/r/default_temp_storage_engine_basic.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/r/default_temp_storage_engine_basic.result	2011-06-03 11:45:11 +0000
@@ -0,0 +1,175 @@
+SET @start_global_value = @@global.default_temp_storage_engine;
+SELECT @start_global_value;
+@start_global_value
+InnoDB
+SET @start_session_value = @@session.default_temp_storage_engine;
+SELECT @start_session_value;
+@start_session_value
+InnoDB
+'#--------------------FN_DYNVARS_005_01-------------------------#'
+SET @@global.default_temp_storage_engine = INNODB;
+SET @@global.default_temp_storage_engine = DFL_TMP;
+SELECT @@global.default_temp_storage_engine;
+@@global.default_temp_storage_engine
+InnoDB
+SET @@session.default_temp_storage_engine = INNODB;
+SET @@session.default_temp_storage_engine = DFL_TMP;
+SELECT @@session.default_temp_storage_engine;
+@@session.default_temp_storage_engine
+InnoDB
+'#--------------------FN_DYNVARS_005_02-------------------------#'
+SET @@global.default_temp_storage_engine = MYISAM;
+SELECT @@global.default_temp_storage_engine;
+@@global.default_temp_storage_engine
+MyISAM
+SET @@global.default_temp_storage_engine = MERGE;
+SELECT @@global.default_temp_storage_engine;
+@@global.default_temp_storage_engine
+MRG_MYISAM
+SET @@global.default_temp_storage_engine = MEMORY;
+SELECT @@global.default_temp_storage_engine;
+@@global.default_temp_storage_engine
+MEMORY
+SET @@global.default_temp_storage_engine = INNODB;
+SELECT @@global.default_temp_storage_engine;
+@@global.default_temp_storage_engine
+InnoDB
+'#--------------------FN_DYNVARS_005_03-------------------------#'
+SET @@session.default_temp_storage_engine = MYISAM;
+SELECT @@session.default_temp_storage_engine;
+@@session.default_temp_storage_engine
+MyISAM
+SET @@session.default_temp_storage_engine = MERGE;
+SELECT @@session.default_temp_storage_engine;
+@@session.default_temp_storage_engine
+MRG_MYISAM
+SET @@session.default_temp_storage_engine = MEMORY;
+SELECT @@session.default_temp_storage_engine;
+@@session.default_temp_storage_engine
+MEMORY
+SET @@session.default_temp_storage_engine = INNODB;
+SELECT @@session.default_temp_storage_engine;
+@@session.default_temp_storage_engine
+InnoDB
+'#------------------FN_DYNVARS_005_04-----------------------#'
+SET @@global.default_temp_storage_engine = 8199;
+ERROR 42000: Incorrect argument type to variable 'default_temp_storage_engine'
+SET @@global.default_temp_storage_engine = NULL;
+ERROR 42000: Variable 'default_temp_storage_engine' can't be set to the value of 'NULL'
+SET @@global.default_temp_storage_engine = -1024;
+ERROR 42000: Incorrect argument type to variable 'default_temp_storage_engine'
+SET @@global.default_temp_storage_engine = 65530.34;
+ERROR 42000: Incorrect argument type to variable 'default_temp_storage_engine'
+SET @@global.default_temp_storage_engine = FILE;
+ERROR 42000: Unknown storage engine 'FILE'
+SET @@session.default_temp_storage_engine = 8199;
+ERROR 42000: Incorrect argument type to variable 'default_temp_storage_engine'
+SET @@session.default_temp_storage_engine = 65530.34;
+ERROR 42000: Incorrect argument type to variable 'default_temp_storage_engine'
+SET @@session.default_temp_storage_engine = RECORD;
+ERROR 42000: Unknown storage engine 'RECORD'
+'#------------------FN_DYNVARS_005_05-----------------------#'
+SELECT @@global.default_temp_storage_engine =
+VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
+WHERE VARIABLE_NAME='default_temp_storage_engine';
+@@global.default_temp_storage_engine =
+VARIABLE_VALUE
+1
+'#------------------FN_DYNVARS_005_06-----------------------#'
+SELECT @@session.default_temp_storage_engine =
+VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_VARIABLES
+WHERE VARIABLE_NAME='default_temp_storage_engine';
+@@session.default_temp_storage_engine =
+VARIABLE_VALUE
+1
+'#------------------FN_DYNVARS_005_07-----------------------#'
+SET @@global.default_temp_storage_engine = TRUE;
+ERROR 42000: Incorrect argument type to variable 'default_temp_storage_engine'
+SET @@global.default_temp_storage_engine = FALSE;
+ERROR 42000: Incorrect argument type to variable 'default_temp_storage_engine'
+'#---------------------FN_DYNVARS_001_8----------------------#'
+SET @@default_temp_storage_engine = MYISAM;
+SELECT @@default_temp_storage_engine = @@local.default_temp_storage_engine;
+@@default_temp_storage_engine = @@local.default_temp_storage_engine
+1
+SELECT @@local.default_temp_storage_engine = @@session.default_temp_storage_engine;
+@@local.default_temp_storage_engine = @@session.default_temp_storage_engine
+1
+'#---------------------FN_DYNVARS_001_9----------------------#'
+SET default_temp_storage_engine = MEMORY;
+SELECT @@default_temp_storage_engine;
+@@default_temp_storage_engine
+MEMORY
+SELECT local.default_temp_storage_engine;
+ERROR 42S02: Unknown table 'local' in field list
+SELECT session.default_temp_storage_engine;
+ERROR 42S02: Unknown table 'session' in field list
+SELECT default_temp_storage_engine = @@session.default_temp_storage_engine;
+ERROR 42S22: Unknown column 'default_temp_storage_engine' in 'field list'
+SET @@default_temp_storage_engine = @start_global_value;
+SET default_temp_storage_engine = MyISAM;
+SET default_storage_engine = MyISAM;
+CREATE TABLE t1 (a INT);
+CREATE TEMPORARY TABLE t2 (b INT);
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SHOW CREATE TABLE t2;
+Table	Create Table
+t2	CREATE TEMPORARY TABLE `t2` (
+  `b` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1, t2;
+SET default_temp_storage_engine = InnoDB;
+CREATE TABLE t1 (a INT);
+CREATE TEMPORARY TABLE t2 (b INT);
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SHOW CREATE TABLE t2;
+Table	Create Table
+t2	CREATE TEMPORARY TABLE `t2` (
+  `b` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+DROP TABLE t1, t2;
+SET default_storage_engine = MEMORY;
+CREATE TABLE t1 (a INT);
+CREATE TEMPORARY TABLE t2 (b INT);
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+SHOW CREATE TABLE t2;
+Table	Create Table
+t2	CREATE TEMPORARY TABLE `t2` (
+  `b` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+DROP TABLE t1, t2;
+SET default_temp_storage_engine = DEFAULT;
+SET default_storage_engine = DEFAULT;
+CREATE TABLE t1 (a INT);
+CREATE TEMPORARY TABLE t2 (b INT);
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SHOW CREATE TABLE t2;
+Table	Create Table
+t2	CREATE TEMPORARY TABLE `t2` (
+  `b` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+DROP TABLE t1, t2;
+SET @@global.default_temp_storage_engine = @start_global_value;
+SELECT @@global.default_temp_storage_engine;
+@@global.default_temp_storage_engine
+InnoDB
+SET @@session.default_temp_storage_engine = @start_session_value;
+SELECT @@session.default_temp_storage_engine;
+@@session.default_temp_storage_engine
+InnoDB

=== added file 'mysql-test/suite/sys_vars/t/default_temp_storage_engine_basic.test'
--- a/mysql-test/suite/sys_vars/t/default_temp_storage_engine_basic.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/t/default_temp_storage_engine_basic.test	2011-06-03 11:45:11 +0000
@@ -0,0 +1,197 @@
+--source include/not_embedded.inc
+--source include/have_innodb.inc
+--source include/load_sysvars.inc
+
+######################################################################
+#           START OF default_temp_storage_engine TESTS               #
+######################################################################
+
+
+#############################################################
+#                 Save initial value                        #
+#############################################################
+
+SET @start_global_value = @@global.default_temp_storage_engine;
+SELECT @start_global_value;
+SET @start_session_value = @@session.default_temp_storage_engine;
+SELECT @start_session_value;
+
+
+--echo '#--------------------FN_DYNVARS_005_01-------------------------#'
+######################################################################
+#     Display the DEFAULT value of default_temp_storage_engine       #
+######################################################################
+
+SET @@global.default_temp_storage_engine = INNODB;
+SET @@global.default_temp_storage_engine = DFL_TMP;
+SELECT @@global.default_temp_storage_engine;
+
+SET @@session.default_temp_storage_engine = INNODB;
+SET @@session.default_temp_storage_engine = DFL_TMP;
+SELECT @@session.default_temp_storage_engine;
+
+
+--echo '#--------------------FN_DYNVARS_005_02-------------------------#'
+########################################################################
+# Change the value of default_temp_storage_engine to a valid value for GLOBAL Scope #
+########################################################################
+
+SET @@global.default_temp_storage_engine = MYISAM;
+SELECT @@global.default_temp_storage_engine;
+SET @@global.default_temp_storage_engine = MERGE;
+SELECT @@global.default_temp_storage_engine;
+SET @@global.default_temp_storage_engine = MEMORY;
+SELECT @@global.default_temp_storage_engine;
+SET @@global.default_temp_storage_engine = INNODB;
+SELECT @@global.default_temp_storage_engine;
+
+
+--echo '#--------------------FN_DYNVARS_005_03-------------------------#'
+#########################################################################
+# Change the value of default_temp_storage_engine to a valid value for SESSION Scope #
+#########################################################################
+ 
+SET @@session.default_temp_storage_engine = MYISAM;
+SELECT @@session.default_temp_storage_engine;
+SET @@session.default_temp_storage_engine = MERGE;
+SELECT @@session.default_temp_storage_engine;
+SET @@session.default_temp_storage_engine = MEMORY;
+SELECT @@session.default_temp_storage_engine;
+SET @@session.default_temp_storage_engine = INNODB;
+SELECT @@session.default_temp_storage_engine;
+
+
+--echo '#------------------FN_DYNVARS_005_04-----------------------#'
+##################################################################
+# Change the value of default_temp_storage_engine to an invalid value         #
+##################################################################
+
+--Error ER_WRONG_TYPE_FOR_VAR
+SET @@global.default_temp_storage_engine = 8199;
+
+--Error ER_WRONG_VALUE_FOR_VAR
+SET @@global.default_temp_storage_engine = NULL;
+
+--Error ER_WRONG_TYPE_FOR_VAR
+SET @@global.default_temp_storage_engine = -1024;
+
+--Error ER_WRONG_TYPE_FOR_VAR
+SET @@global.default_temp_storage_engine = 65530.34;
+
+--Error ER_UNKNOWN_STORAGE_ENGINE
+SET @@global.default_temp_storage_engine = FILE;
+
+--Error ER_WRONG_TYPE_FOR_VAR
+SET @@session.default_temp_storage_engine = 8199;
+
+--Error ER_WRONG_TYPE_FOR_VAR
+SET @@session.default_temp_storage_engine = 65530.34;
+
+--Error ER_UNKNOWN_STORAGE_ENGINE
+SET @@session.default_temp_storage_engine = RECORD;
+
+
+--echo '#------------------FN_DYNVARS_005_05-----------------------#'
+####################################################################
+#   Check if the value in GLOBAL Table matches value in variable   #
+####################################################################
+
+
+SELECT @@global.default_temp_storage_engine =
+ VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
+  WHERE VARIABLE_NAME='default_temp_storage_engine';
+
+--echo '#------------------FN_DYNVARS_005_06-----------------------#'
+####################################################################
+#  Check if the value in SESSION Table matches value in variable   #
+####################################################################
+
+SELECT @@session.default_temp_storage_engine =
+ VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_VARIABLES
+  WHERE VARIABLE_NAME='default_temp_storage_engine';
+
+
+--echo '#------------------FN_DYNVARS_005_07-----------------------#'
+####################################################################
+#     Check if TRUE and FALSE values can be used on variable       #
+####################################################################
+
+--Error ER_WRONG_TYPE_FOR_VAR
+SET @@global.default_temp_storage_engine = TRUE;
+
+--Error ER_WRONG_TYPE_FOR_VAR
+SET @@global.default_temp_storage_engine = FALSE;
+
+
+--echo '#---------------------FN_DYNVARS_001_8----------------------#'
+###############################################################
+#  Check if accessing variable with SESSION,LOCAL and without #
+#  SCOPE points to same session variable                      #
+###############################################################
+
+SET @@default_temp_storage_engine = MYISAM;
+SELECT @@default_temp_storage_engine = @@local.default_temp_storage_engine;
+SELECT @@local.default_temp_storage_engine = @@session.default_temp_storage_engine;
+
+
+--echo '#---------------------FN_DYNVARS_001_9----------------------#'
+#########################################################################
+#   Check if default_temp_storage_engine can be accessed with and without @@ sign    #
+#########################################################################
+
+SET default_temp_storage_engine = MEMORY;
+SELECT @@default_temp_storage_engine;
+--Error ER_UNKNOWN_TABLE
+SELECT local.default_temp_storage_engine;
+--Error ER_UNKNOWN_TABLE
+SELECT session.default_temp_storage_engine;
+--Error ER_BAD_FIELD_ERROR
+SELECT default_temp_storage_engine = @@session.default_temp_storage_engine;
+
+# check the old obsolete name
+SET @@default_temp_storage_engine = @start_global_value;
+
+SET default_temp_storage_engine = MyISAM;
+SET default_storage_engine = MyISAM;
+CREATE TABLE t1 (a INT);
+CREATE TEMPORARY TABLE t2 (b INT);
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+DROP TABLE t1, t2;
+
+SET default_temp_storage_engine = InnoDB;
+CREATE TABLE t1 (a INT);
+CREATE TEMPORARY TABLE t2 (b INT);
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+DROP TABLE t1, t2;
+
+SET default_storage_engine = MEMORY;
+CREATE TABLE t1 (a INT);
+CREATE TEMPORARY TABLE t2 (b INT);
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+DROP TABLE t1, t2;
+
+SET default_temp_storage_engine = DEFAULT;
+SET default_storage_engine = DEFAULT;
+CREATE TABLE t1 (a INT);
+CREATE TEMPORARY TABLE t2 (b INT);
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+DROP TABLE t1, t2;
+
+####################################
+#     Restore initial value        #
+####################################
+
+SET @@global.default_temp_storage_engine = @start_global_value;
+SELECT @@global.default_temp_storage_engine;
+SET @@session.default_temp_storage_engine = @start_session_value;
+SELECT @@session.default_temp_storage_engine;
+
+
+#############################################################
+#       END OF default_temp_storage_engine TESTS            #
+#############################################################
+

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2011-05-31 09:30:59 +0000
+++ b/sql/handler.cc	2011-06-03 11:45:11 +0000
@@ -110,7 +110,8 @@ static plugin_ref ha_default_plugin(THD 
 
 
 /** @brief
-  Return the default storage engine handlerton for thread
+  Return the default storage engine handlerton used for non-temp tables 
+  for thread
 
   SYNOPSIS
     ha_default_handlerton(thd)
@@ -129,6 +130,35 @@ handlerton *ha_default_handlerton(THD *t
 }
 
 
+static plugin_ref ha_default_temp_plugin(THD *thd)
+{
+  if (thd->variables.temp_table_plugin)
+    return thd->variables.temp_table_plugin;
+  return my_plugin_lock(thd, &global_system_variables.temp_table_plugin);
+}
+
+
+/** @brief
+  Return the default storage engine handlerton used for explicitly 
+  created temp tables for a thread
+
+  SYNOPSIS
+    ha_default_temp_handlerton(thd)
+    thd         current thread
+
+  RETURN
+    pointer to handlerton
+*/
+handlerton *ha_default_temp_handlerton(THD *thd)
+{
+  plugin_ref plugin= ha_default_temp_plugin(thd);
+  DBUG_ASSERT(plugin);
+  handlerton *hton= plugin_data(plugin, handlerton*);
+  DBUG_ASSERT(hton);
+  return hton;
+}
+
+
 /** @brief
   Return the storage engine handlerton for the supplied name
   
@@ -152,6 +182,11 @@ redo:
                            (const uchar *)STRING_WITH_LEN("DEFAULT"), 0))
     return ha_default_plugin(thd);
 
+  if (thd && !my_charset_latin1.coll->strnncoll(&my_charset_latin1,
+                           (const uchar *)name->str, name->length,
+                           (const uchar *)STRING_WITH_LEN("DFL_TMP"), 0))
+    return ha_default_temp_plugin(thd);
+
   if ((plugin= my_plugin_lock_by_name(thd, name, MYSQL_STORAGE_ENGINE_PLUGIN)))
   {
     handlerton *hton= plugin_data(plugin, handlerton *);

=== modified file 'sql/handler.h'
--- a/sql/handler.h	2011-06-01 09:11:28 +0000
+++ b/sql/handler.h	2011-06-03 11:45:11 +0000
@@ -2436,6 +2436,7 @@ extern ulong total_ha, total_ha_2pc;
 
 /* lookups */
 handlerton *ha_default_handlerton(THD *thd);
+handlerton *ha_default_temp_handlerton(THD *thd);
 plugin_ref ha_resolve_by_name(THD *thd, const LEX_STRING *name);
 plugin_ref ha_lock_engine(THD *thd, const handlerton *hton);
 handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type);

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2011-05-26 15:20:09 +0000
+++ b/sql/mysqld.cc	2011-06-03 11:45:11 +0000
@@ -333,6 +333,7 @@ static char *lc_time_names_name;
 char *my_bind_addr_str;
 static char *default_collation_name;
 char *default_storage_engine;
+char *default_temp_storage_engine;
 static char compiled_default_collation_name[]= MYSQL_DEFAULT_COLLATION_NAME;
 static I_List<THD> thread_cache;
 static bool binlog_format_used= false;
@@ -3333,6 +3334,7 @@ int init_common_variables()
 #else
   default_storage_engine= const_cast<char *>("InnoDB");
 #endif
+  default_temp_storage_engine= default_storage_engine;
 
   /*
     Add server status variables to the dynamic list of
@@ -4041,6 +4043,44 @@ err:
   DBUG_RETURN(1);
 }
 
+
+static bool
+initialize_storage_engine(char *se_name, const char *se_kind,
+                          plugin_ref *dest_plugin)
+{
+  LEX_STRING name= { se_name, strlen(se_name) };
+  plugin_ref plugin;
+  handlerton *hton;
+  if ((plugin= ha_resolve_by_name(0, &name)))
+    hton= plugin_data(plugin, handlerton*);
+  else
+  {
+    sql_print_error("Unknown/unsupported storage engine: %s", se_name);
+    return true;
+  }
+  if (!ha_storage_engine_is_enabled(hton))
+  {
+    if (!opt_bootstrap)
+    {
+      sql_print_error("Default%s storage engine (%s) is not available",
+                      se_kind, se_name);
+      return true;
+    }
+    DBUG_ASSERT(*dest_plugin);
+  }
+  else
+  {
+    /*
+      Need to unlock as global_system_variables.table_plugin
+      was acquired during plugin_init()
+    */
+    plugin_unlock(0, *dest_plugin);
+    *dest_plugin= plugin;
+  }
+  return false;
+}
+
+
 static int init_server_components()
 {
   DBUG_ENTER("init_server_components");
@@ -4348,38 +4388,14 @@ a file name for --log-bin-index option",
 #endif
 
   /*
-    Set the default storage engine
+    Set the default storage engines
   */
-  LEX_STRING name= { default_storage_engine, strlen(default_storage_engine) };
-  plugin_ref plugin;
-  handlerton *hton;
-  if ((plugin= ha_resolve_by_name(0, &name)))
-    hton= plugin_data(plugin, handlerton*);
-  else
-  {
-    sql_print_error("Unknown/unsupported storage engine: %s",
-                    default_storage_engine);
+  if (initialize_storage_engine(default_storage_engine, "",
+                                &global_system_variables.table_plugin))
+    unireg_abort(1);
+  if (initialize_storage_engine(default_temp_storage_engine, " temp",
+                                &global_system_variables.temp_table_plugin))
     unireg_abort(1);
-  }
-  if (!ha_storage_engine_is_enabled(hton))
-  {
-    if (!opt_bootstrap)
-    {
-      sql_print_error("Default storage engine (%s) is not available",
-                      default_storage_engine);
-      unireg_abort(1);
-    }
-    DBUG_ASSERT(global_system_variables.table_plugin);
-  }
-  else
-  {
-    /*
-      Need to unlock as global_system_variables.table_plugin
-      was acquired during plugin_init()
-    */
-    plugin_unlock(0, global_system_variables.table_plugin);
-    global_system_variables.table_plugin= plugin;
-  }
 
   tc_log= (total_ha_2pc > 1 ? (opt_bin_log  ?
                                (TC_LOG *) &mysql_bin_log :
@@ -6139,6 +6155,10 @@ struct my_option my_long_options[]=
   {"default-storage-engine", 0, "The default storage engine for new tables",
    &default_storage_engine, 0, 0, GET_STR, REQUIRED_ARG,
    0, 0, 0, 0, 0, 0 },
+  {"default-temp-storage-engine", 0, 
+    "The default storage engine for new explict temporary tables",
+   &default_temp_storage_engine, 0, 0, GET_STR, REQUIRED_ARG,
+   0, 0, 0, 0, 0, 0 },
   {"default-time-zone", 0, "Set the default time zone.",
    &default_tz_name, &default_tz_name,
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },

=== modified file 'sql/mysqld.h'
--- a/sql/mysqld.h	2011-05-19 09:11:38 +0000
+++ b/sql/mysqld.h	2011-06-03 11:45:11 +0000
@@ -129,6 +129,7 @@ extern my_bool opt_enable_shared_memory;
 extern char *default_tz_name;
 extern Time_zone *default_tz;
 extern char *default_storage_engine;
+extern char *default_temp_storage_engine;
 extern bool opt_endinfo, using_udf_functions;
 extern my_bool locked_in_memory;
 extern bool opt_using_transactions;

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2011-05-31 13:52:09 +0000
+++ b/sql/sql_class.h	2011-06-03 11:45:11 +0000
@@ -490,6 +490,7 @@ typedef struct system_variables
   my_bool big_tables;
 
   plugin_ref table_plugin;
+  plugin_ref temp_table_plugin;
 
   /* Only charset part of these variables is sensible */
   const CHARSET_INFO *character_set_filesystem;

=== modified file 'sql/sql_plugin.cc'
--- a/sql/sql_plugin.cc	2011-05-26 15:20:09 +0000
+++ b/sql/sql_plugin.cc	2011-06-03 11:45:11 +0000
@@ -1315,15 +1315,19 @@ int plugin_init(int *argc, char **argv, 
       if (is_myisam)
       {
         DBUG_ASSERT(!global_system_variables.table_plugin);
+        DBUG_ASSERT(!global_system_variables.temp_table_plugin);
         global_system_variables.table_plugin=
           my_intern_plugin_lock(NULL, plugin_int_to_ref(plugin_ptr));
-        DBUG_ASSERT(plugin_ptr->ref_count == 1);
+        global_system_variables.temp_table_plugin=
+          my_intern_plugin_lock(NULL, plugin_int_to_ref(plugin_ptr));
+        DBUG_ASSERT(plugin_ptr->ref_count == 2);
       }
     }
   }
 
   /* should now be set to MyISAM storage engine */
   DBUG_ASSERT(global_system_variables.table_plugin);
+  DBUG_ASSERT(global_system_variables.temp_table_plugin);
 
   mysql_mutex_unlock(&LOCK_plugin);
 
@@ -2605,13 +2609,16 @@ static char **mysql_sys_var_str(THD* thd
 void plugin_thdvar_init(THD *thd, bool enable_plugins)
 {
   plugin_ref old_table_plugin= thd->variables.table_plugin;
+  plugin_ref old_temp_table_plugin= thd->variables.temp_table_plugin;
   DBUG_ENTER("plugin_thdvar_init");
   
   thd->variables.table_plugin= NULL;
+  thd->variables.temp_table_plugin= NULL;
   cleanup_variables(thd, &thd->variables);
   
   thd->variables= global_system_variables;
   thd->variables.table_plugin= NULL;
+  thd->variables.temp_table_plugin= NULL;
 
   /* we are going to allocate these lazily */
   thd->variables.dynamic_variables_version= 0;
@@ -2624,6 +2631,9 @@ void plugin_thdvar_init(THD *thd, bool e
     thd->variables.table_plugin=
       my_intern_plugin_lock(NULL, global_system_variables.table_plugin);
     intern_plugin_unlock(NULL, old_table_plugin);
+    thd->variables.temp_table_plugin=
+      my_intern_plugin_lock(NULL, global_system_variables.temp_table_plugin);
+    intern_plugin_unlock(NULL, old_temp_table_plugin);
     mysql_mutex_unlock(&LOCK_plugin);
   }
   DBUG_VOID_RETURN;
@@ -2636,7 +2646,9 @@ void plugin_thdvar_init(THD *thd, bool e
 static void unlock_variables(THD *thd, struct system_variables *vars)
 {
   intern_plugin_unlock(NULL, vars->table_plugin);
+  intern_plugin_unlock(NULL, vars->temp_table_plugin);
   vars->table_plugin= NULL;
+  vars->temp_table_plugin= NULL;
 }
 
 
@@ -2677,6 +2689,7 @@ static void cleanup_variables(THD *thd, 
   mysql_rwlock_unlock(&LOCK_system_variables_hash);
 
   DBUG_ASSERT(vars->table_plugin == NULL);
+  DBUG_ASSERT(vars->temp_table_plugin == NULL);
 
   my_free(vars->dynamic_variables_ptr);
   vars->dynamic_variables_ptr= NULL;

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2011-05-26 15:20:09 +0000
+++ b/sql/sql_show.cc	2011-06-03 11:45:11 +0000
@@ -4412,6 +4412,7 @@ static my_bool iter_schema_engines(THD *
   const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
   CHARSET_INFO *scs= system_charset_info;
   handlerton *default_type= ha_default_handlerton(thd);
+  handlerton *default_temp_type= ha_default_temp_handlerton(thd);
   DBUG_ENTER("iter_schema_engines");
 
 
@@ -4448,6 +4449,8 @@ static my_bool iter_schema_engines(THD *
       table->field[0]->store(name->str, name->length, scs);
       if (hton->state == SHOW_OPTION_YES && default_type == hton)
         option_name= "DEFAULT";
+      else if (hton->state == SHOW_OPTION_YES && default_temp_type == hton)
+        option_name= "DFL_TMP";
       table->field[1]->store(option_name, strlen(option_name), scs);
       table->field[2]->store(plugin_decl(plugin)->descr,
                              strlen(plugin_decl(plugin)->descr), scs);

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2011-05-26 15:20:09 +0000
+++ b/sql/sql_yacc.yy	2011-06-03 11:45:11 +0000
@@ -2072,7 +2072,9 @@ create:
             lex->change=NullS;
             memset(&lex->create_info, 0, sizeof(lex->create_info));
             lex->create_info.options=$2 | $4;
-            lex->create_info.db_type= ha_default_handlerton(thd);
+            lex->create_info.db_type=
+              lex->create_info.options & HA_LEX_CREATE_TMP_TABLE ?
+              ha_default_temp_handlerton(thd) : ha_default_handlerton(thd);
             lex->create_info.default_table_charset= NULL;
             lex->name.str= 0;
             lex->name.length= 0;
@@ -2080,11 +2082,14 @@ create:
           }
           create2
           {
-            LEX *lex= YYTHD->lex;
+            THD *thd= YYTHD;
+            LEX *lex= thd->lex;
             lex->current_select= &lex->select_lex; 
             if (!lex->create_info.db_type)
             {
-              lex->create_info.db_type= ha_default_handlerton(YYTHD);
+              lex->create_info.db_type=
+                lex->create_info.options & HA_LEX_CREATE_TMP_TABLE ?
+                ha_default_temp_handlerton(thd) : ha_default_handlerton(thd);
               push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN,
                                   ER_WARN_USING_OTHER_HANDLER,
                                   ER(ER_WARN_USING_OTHER_HANDLER),

=== modified file 'sql/sys_vars.cc'
--- a/sql/sys_vars.cc	2011-05-21 08:25:33 +0000
+++ b/sql/sys_vars.cc	2011-06-03 11:45:11 +0000
@@ -2436,6 +2436,12 @@ static Sys_var_plugin Sys_default_storag
        MYSQL_STORAGE_ENGINE_PLUGIN, DEFAULT(&default_storage_engine),
        NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_not_null));
 
+static Sys_var_plugin Sys_default_temp_storage_engine(
+       "default_temp_storage_engine", "The default storage engine for new explict temporary tables",
+       SESSION_VAR(temp_table_plugin), NO_CMD_LINE,
+       MYSQL_STORAGE_ENGINE_PLUGIN, DEFAULT(&default_temp_storage_engine),
+       NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_not_null));
+
 //  Alias for @@default_storage_engine
 static Sys_var_plugin Sys_storage_engine(
        "storage_engine", "Alias for @@default_storage_engine. Deprecated",


Attachment: [text/bzr-bundle] bzr/georgi.kodinov@oracle.com-20110603114511-1d90a6xsbmvp9i2b.bundle
Thread
bzr commit into mysql-trunk branch (Georgi.Kodinov:3153) Bug#11757216Georgi Kodinov4 Jun