=== modified file 'mysql-test/include/mix1.inc' --- mysql-test/include/mix1.inc 2009-10-05 13:16:27 +0000 +++ mysql-test/include/mix1.inc 2009-12-09 19:39:56 +0000 @@ -25,7 +25,7 @@ # where just some indexes have been created must be used. # -eval SET SESSION STORAGE_ENGINE = $engine_type; +eval SET SESSION STORAGE_ENGINE = $engine_type, TEMP_STORAGE_ENGINE = $engine_type; --disable_warnings drop table if exists t1,t2,t3,t1m,t1i,t2m,t2i,t4; === modified file 'mysql-test/r/innodb_mysql.result' --- mysql-test/r/innodb_mysql.result 2009-12-01 09:19:51 +0000 +++ mysql-test/r/innodb_mysql.result 2009-12-09 19:56:56 +0000 @@ -1,6 +1,6 @@ set global innodb_support_xa=default; set session innodb_support_xa=default; -SET SESSION STORAGE_ENGINE = InnoDB; +SET SESSION STORAGE_ENGINE = InnoDB, TEMP_STORAGE_ENGINE = InnoDB; drop table if exists t1,t2,t3,t1m,t1i,t2m,t2i,t4; drop procedure if exists p1; create table t1 ( === modified file 'mysql-test/t/temp_table.test' --- mysql-test/t/temp_table.test 2009-01-07 12:11:37 +0000 +++ mysql-test/t/temp_table.test 2009-12-08 22:22:02 +0000 @@ -235,4 +235,6 @@ DROP TABLE t1,t2,t3; DROP FUNCTION f1; +# new functionality of specifying temp table storage engine independently + --echo End of 5.1 tests === modified file 'sql/handler.cc' --- sql/handler.cc 2009-12-01 09:19:51 +0000 +++ sql/handler.cc 2009-12-08 20:56:19 +0000 @@ -78,34 +78,35 @@ -static plugin_ref ha_default_plugin(THD *thd) +static plugin_ref ha_default_plugin(THD *thd, my_bool temporary) { - if (thd->variables.table_plugin) + if (!temporary && thd->variables.table_plugin) return thd->variables.table_plugin; + if (temporary && thd->variables.table_temp_plugin) + return thd->variables.table_temp_plugin; return my_plugin_lock(thd, &global_system_variables.table_plugin); } - /** @brief Return the default storage engine handlerton for thread SYNOPSIS - ha_default_handlerton(thd) + ha_default_handlerton(thd, temporary) thd current thread + temporary should it return the temporary table handler or normal RETURN pointer to handlerton */ -handlerton *ha_default_handlerton(THD *thd) +handlerton *ha_default_handlerton(THD *thd, my_bool temporary) { - plugin_ref plugin= ha_default_plugin(thd); + plugin_ref plugin= ha_default_plugin(thd, temporary); DBUG_ASSERT(plugin); handlerton *hton= plugin_data(plugin, handlerton*); DBUG_ASSERT(hton); return hton; } - /** @brief Return the storage engine handlerton for the supplied name @@ -127,7 +128,7 @@ if (thd && !my_charset_latin1.coll->strnncoll(&my_charset_latin1, (const uchar *)name->str, name->length, (const uchar *)STRING_WITH_LEN("DEFAULT"), 0)) - return ha_default_plugin(thd); + return ha_default_plugin(thd, false); if ((plugin= my_plugin_lock_by_name(thd, name, MYSQL_STORAGE_ENGINE_PLUGIN))) { @@ -189,7 +190,7 @@ plugin_ref plugin; switch (db_type) { case DB_TYPE_DEFAULT: - return ha_default_handlerton(thd); + return ha_default_handlerton(thd, false); default: if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT && (plugin= ha_lock_engine(thd, installed_htons[db_type]))) @@ -232,7 +233,7 @@ break; } - return ha_default_handlerton(thd); + return ha_default_handlerton(thd, false); } /* ha_checktype */ @@ -254,7 +255,7 @@ Here the call to current_thd() is ok as we call this function a lot of times but we enter this branch very seldom. */ - DBUG_RETURN(get_new_handler(share, alloc, ha_default_handlerton(current_thd))); + DBUG_RETURN(get_new_handler(share, alloc, ha_default_handlerton(current_thd, false))); } === modified file 'sql/handler.h' --- sql/handler.h 2009-10-12 12:46:00 +0000 +++ sql/handler.h 2009-12-08 20:35:59 +0000 @@ -1954,7 +1954,7 @@ #define ha_rollback(thd) (ha_rollback_trans((thd), TRUE)) /* lookups */ -handlerton *ha_default_handlerton(THD *thd); +handlerton *ha_default_handlerton(THD *thd, my_bool temporary); plugin_ref ha_resolve_by_name(THD *thd, const LEX_STRING *name); plugin_ref ha_lock_engine(THD *thd, handlerton *hton); handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type); === modified file 'sql/mysql_priv.h.pp' --- sql/mysql_priv.h.pp 2009-10-06 11:04:51 +0000 +++ sql/mysql_priv.h.pp 2009-12-08 20:38:57 +0000 @@ -4495,7 +4495,7 @@ extern TYPELIB tx_isolation_typelib; extern TYPELIB myisam_stats_method_typelib; extern ulong total_ha, total_ha_2pc; -handlerton *ha_default_handlerton(THD *thd); +handlerton *ha_default_handlerton(THD *thd, my_bool temporary); plugin_ref ha_resolve_by_name(THD *thd, const LEX_STRING *name); plugin_ref ha_lock_engine(THD *thd, handlerton *hton); handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type); === modified file 'sql/mysqld.cc' --- sql/mysqld.cc 2009-11-20 12:09:50 +0000 +++ sql/mysqld.cc 2009-12-08 21:06:19 +0000 @@ -396,6 +396,7 @@ static char *my_bind_addr_str; static char *default_collation_name; static char *default_storage_engine_str; +static char *default_temp_storage_engine_str; static char compiled_default_collation_name[]= MYSQL_DEFAULT_COLLATION_NAME; static I_List thread_cache; static double long_query_time; @@ -4078,6 +4079,48 @@ global_system_variables.table_plugin= plugin; } } + /* Set from default storage engine */ + if (!default_temp_storage_engine_str) { + default_temp_storage_engine_str = default_storage_engine_str; + } + + /* initialize temporary storage engine */ + if (default_temp_storage_engine_str) + { + LEX_STRING name= { default_temp_storage_engine_str, + strlen(default_temp_storage_engine_str) }; + plugin_ref plugin; + handlerton *hton; + + if ((plugin= ha_resolve_by_name(0, &name))) + hton= plugin_data(plugin, handlerton*); + else + { + sql_print_error("Unknown/unsupported table type: %s", + default_temp_storage_engine_str); + unireg_abort(1); + } + if (!ha_storage_engine_is_enabled(hton)) + { + if (!opt_bootstrap) + { + sql_print_error("Default storage engine (%s) is not available", + default_temp_storage_engine_str); + unireg_abort(1); + } + DBUG_ASSERT(global_system_variables.table_temp_plugin); + } + else + { + /* + Need to unlock as global_system_variables.table_temp_plugin + was acquired during plugin_init() + */ + plugin_unlock(0, global_system_variables.table_temp_plugin); + global_system_variables.table_temp_plugin= plugin; + } + } + tc_log= (total_ha_2pc > 1 ? (opt_bin_log ? (TC_LOG *) &mysql_bin_log : @@ -5727,7 +5770,8 @@ OPT_SLAVE_EXEC_MODE, OPT_GENERAL_LOG_FILE, OPT_SLOW_QUERY_LOG_FILE, - OPT_IGNORE_BUILTIN_INNODB + OPT_IGNORE_BUILTIN_INNODB, + OPT_TEMP_STORAGE_ENGINE }; @@ -5867,6 +5911,10 @@ "(deprecated) Use --default-storage-engine.", (uchar**)&default_storage_engine_str, (uchar**)&default_storage_engine_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"default-temp-storage-engine", OPT_TEMP_STORAGE_ENGINE, + "Set the default storage engine for temporary tables.", + (uchar**)&default_temp_storage_engine_str, (uchar**)&default_temp_storage_engine_str, + 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"default-time-zone", OPT_DEFAULT_TIME_ZONE, "Set the default time zone.", (uchar**) &default_tz_name, (uchar**) &default_tz_name, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, @@ -7765,6 +7813,7 @@ /* Set default values for some option variables */ default_storage_engine_str= (char*) "MyISAM"; global_system_variables.table_plugin= NULL; + global_system_variables.table_temp_plugin= NULL; global_system_variables.tx_isolation= ISO_REPEATABLE_READ; global_system_variables.select_limit= (ulonglong) HA_POS_ERROR; max_system_variables.select_limit= (ulonglong) HA_POS_ERROR; === modified file 'sql/set_var.cc' --- sql/set_var.cc 2009-09-29 15:38:40 +0000 +++ sql/set_var.cc 2009-12-08 21:21:52 +0000 @@ -616,6 +616,9 @@ &SV::table_plugin); static sys_var_thd_storage_engine sys_storage_engine(&vars, "storage_engine", &SV::table_plugin); +static sys_var_thd_storage_engine sys_temp_storage_engine(&vars, "temp_storage_engine", + &SV::table_temp_plugin); + static sys_var_bool_ptr sys_sync_frm(&vars, "sync_frm", &opt_sync_frm); static sys_var_const_str sys_system_time_zone(&vars, "system_time_zone", system_time_zone); === modified file 'sql/sql_class.h' --- sql/sql_class.h 2009-10-20 18:00:07 +0000 +++ sql/sql_class.h 2009-12-08 20:11:07 +0000 @@ -379,6 +379,7 @@ my_bool old_passwords; plugin_ref table_plugin; + plugin_ref table_temp_plugin; /* Only charset part of these variables is sensible */ CHARSET_INFO *character_set_filesystem; === modified file 'sql/sql_plugin.cc' --- sql/sql_plugin.cc 2009-10-27 13:16:02 +0000 +++ sql/sql_plugin.cc 2009-12-08 22:05:19 +0000 @@ -1200,7 +1200,9 @@ DBUG_ASSERT(!global_system_variables.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.table_temp_plugin= + my_intern_plugin_lock(NULL, plugin_int_to_ref(plugin_ptr)); + DBUG_ASSERT(plugin_ptr->ref_count == 2); } } } @@ -2432,13 +2434,16 @@ void plugin_thdvar_init(THD *thd) { plugin_ref old_table_plugin= thd->variables.table_plugin; + plugin_ref old_table_temp_plugin= thd->variables.table_temp_plugin; DBUG_ENTER("plugin_thdvar_init"); thd->variables.table_plugin= NULL; + thd->variables.table_temp_plugin= NULL; cleanup_variables(thd, &thd->variables); thd->variables= global_system_variables; thd->variables.table_plugin= NULL; + thd->variables.table_temp_plugin= NULL; /* we are going to allocate these lazily */ thd->variables.dynamic_variables_version= 0; @@ -2449,6 +2454,9 @@ thd->variables.table_plugin= my_intern_plugin_lock(NULL, global_system_variables.table_plugin); intern_plugin_unlock(NULL, old_table_plugin); + thd->variables.table_temp_plugin= + my_intern_plugin_lock(NULL, global_system_variables.table_temp_plugin); + intern_plugin_unlock(NULL, old_table_temp_plugin); pthread_mutex_unlock(&LOCK_plugin); DBUG_VOID_RETURN; } @@ -2461,6 +2469,8 @@ { intern_plugin_unlock(NULL, vars->table_plugin); vars->table_plugin= NULL; + intern_plugin_unlock(NULL, vars->table_temp_plugin); + vars->table_temp_plugin= NULL; } === modified file 'sql/sql_show.cc' --- sql/sql_show.cc 2009-10-16 10:29:42 +0000 +++ sql/sql_show.cc 2009-12-08 20:57:18 +0000 @@ -4039,7 +4039,8 @@ handlerton *hton= plugin_data(plugin, handlerton *); 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_type= ha_default_handlerton(thd, false); + handlerton *default_temp_type= ha_default_handlerton(thd, true); DBUG_ENTER("iter_schema_engines"); @@ -4074,6 +4075,8 @@ restore_record(table, s->default_values); table->field[0]->store(name->str, name->length, scs); + if (hton->state == SHOW_OPTION_YES && default_temp_type == hton) + option_name= "DEFAULT TEMP"; if (hton->state == SHOW_OPTION_YES && default_type == hton) option_name= "DEFAULT"; table->field[1]->store(option_name, strlen(option_name), scs); === modified file 'sql/sql_tablespace.cc' --- sql/sql_tablespace.cc 2009-10-16 10:29:42 +0000 +++ sql/sql_tablespace.cc 2009-12-08 20:41:40 +0000 @@ -29,7 +29,7 @@ */ if (hton == NULL || hton->state != SHOW_OPTION_YES) { - hton= ha_default_handlerton(thd); + hton= ha_default_handlerton(thd, false); if (ts_info->storage_engine != 0) push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, ER_WARN_USING_OTHER_HANDLER, === modified file 'sql/sql_yacc.yy' --- sql/sql_yacc.yy 2009-11-25 13:09:12 +0000 +++ sql/sql_yacc.yy 2009-12-08 20:52:35 +0000 @@ -1804,7 +1804,7 @@ lex->change=NullS; bzero((char*) &lex->create_info,sizeof(lex->create_info)); lex->create_info.options=$2 | $4; - lex->create_info.db_type= ha_default_handlerton(thd); + lex->create_info.db_type= ha_default_handlerton(thd, ($2 & HA_LEX_CREATE_TMP_TABLE) > 0); lex->create_info.default_table_charset= NULL; lex->name.str= 0; lex->name.length= 0; @@ -1815,7 +1815,7 @@ 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= ha_default_handlerton(YYTHD, false); push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_USING_OTHER_HANDLER, ER(ER_WARN_USING_OTHER_HANDLER),