diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2019-02-08 15:18:02 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2019-02-08 16:24:28 +0400 |
commit | bd13a78caf431966608481fcde084617b67c5684 (patch) | |
tree | 8554ab0bfebfb82ed1527ed8fcc1719d688992f7 | |
parent | 2840e083664514d0da52c7dffe74811d0f914e91 (diff) | |
download | mariadb-git-bb-10.4-svoj-MDEV17805.tar.gz |
Pass same share to ha_create() and ha_open()bb-10.4-svoj-MDEV17805
Part of MDEV-17805 - Remove InnoDB cache for temporary tables.
-rw-r--r-- | mysql-test/main/temp_table_frm.result | 4 | ||||
-rw-r--r-- | sql/sql_class.h | 6 | ||||
-rw-r--r-- | sql/sql_table.cc | 42 | ||||
-rw-r--r-- | sql/temporary_tables.cc | 24 |
4 files changed, 46 insertions, 30 deletions
diff --git a/mysql-test/main/temp_table_frm.result b/mysql-test/main/temp_table_frm.result index a9c59ff5969..372dccccafa 100644 --- a/mysql-test/main/temp_table_frm.result +++ b/mysql-test/main/temp_table_frm.result @@ -10,7 +10,7 @@ from information_schema.session_status join t1 using (variable_name); variable_name session_status.variable_value - t1.variable_value OPENED_FILES 0 OPENED_PLUGIN_LIBRARIES 0 -OPENED_TABLE_DEFINITIONS 2 +OPENED_TABLE_DEFINITIONS 1 OPENED_TABLES 1 OPENED_VIEWS 0 truncate table t2; @@ -19,7 +19,7 @@ from information_schema.session_status join t1 using (variable_name); variable_name session_status.variable_value - t1.variable_value OPENED_FILES 0 OPENED_PLUGIN_LIBRARIES 0 -OPENED_TABLE_DEFINITIONS 2 +OPENED_TABLE_DEFINITIONS 1 OPENED_TABLES 1 OPENED_VIEWS 0 set @@use_stat_tables= @save_use_stat_tables; diff --git a/sql/sql_class.h b/sql/sql_class.h index 41aa1ce8eec..9d7b79b6bf3 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -4727,7 +4727,8 @@ public: TABLE *create_and_open_tmp_table(LEX_CUSTRING *frm, const char *path, const char *db, - const char *table_name); + const char *table_name, + HA_CREATE_INFO *create_info); TABLE *find_temporary_table(const char *db, const char *table_name, Temporary_table_state state= TMP_TABLE_IN_USE); @@ -4767,7 +4768,8 @@ private: const char *table_name); TMP_TABLE_SHARE *create_temporary_table(LEX_CUSTRING *frm, const char *path, const char *db, - const char *table_name); + const char *table_name, + bool write_frm); TABLE *find_temporary_table(const char *key, uint key_length, Temporary_table_state state); TABLE *open_temporary_table(TMP_TABLE_SHARE *share, const char *alias); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 12085e598e6..5005da888e1 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4737,38 +4737,36 @@ static int create_ordinary(THD *thd, const char *path, const char *db, const char *table_name, HA_CREATE_INFO *create_info, LEX_CUSTRING *frm) { - int error= 1; - TABLE_SHARE share; - bool write_frm_now= !create_info->db_type->discover_table && - !create_info->tmp_table(); DBUG_ENTER("create_ordinary"); - init_tmp_table_share(thd, &share, db, 0, table_name, path); - share.frm_image= frm; - // open an frm image - if (share.init_from_binary_frm_image(thd, write_frm_now, - frm->str, frm->length)) - goto err; - if (thd->variables.keep_files_on_create) create_info->options|= HA_CREATE_KEEP_FILES; - if (ha_create_table(thd, share, create_info)) - goto err; - if (create_info->tmp_table() || (create_info->options & HA_CREATE_TMP_ALTER)) { - TABLE *table= thd->create_and_open_tmp_table(frm, path, db, table_name); + TABLE *table= thd->create_and_open_tmp_table(frm, path, db, table_name, + create_info); if (!table) - goto err; + DBUG_RETURN(1); create_info->table= table; } - - error= 0; -err: - free_table_share(&share); - DBUG_RETURN(error); + else + { + bool result; + TABLE_SHARE share; + bool write_frm_now= !create_info->db_type->discover_table; + init_tmp_table_share(thd, &share, db, 0, table_name, path); + share.frm_image= frm; + // open an frm image + result= share.init_from_binary_frm_image(thd, write_frm_now, + frm->str, frm->length) || + ha_create_table(thd, share, create_info); + free_table_share(&share); + if (result) + DBUG_RETURN(1); + } + DBUG_RETURN(0); } @@ -4823,7 +4821,7 @@ static int discover_assisted(THD *thd, if (create_info->tmp_table()) { TABLE *table= thd->create_and_open_tmp_table(frm, path, db->str, - table_name->str); + table_name->str, 0); if (!table) return 1; diff --git a/sql/temporary_tables.cc b/sql/temporary_tables.cc index 5e92cf6717a..de0cdafb8f4 100644 --- a/sql/temporary_tables.cc +++ b/sql/temporary_tables.cc @@ -27,6 +27,7 @@ #include "sql_show.h" /* append_identifier */ #include "sql_handler.h" /* mysql_ha_rm_temporary_tables */ #include "rpl_rli.h" /* rpl_group_info */ +#include "discover.h" #define IS_USER_TABLE(A) ((A->tmp_table == TRANSACTIONAL_TMP_TABLE) || \ (A->tmp_table == NON_TRANSACTIONAL_TMP_TABLE)) @@ -60,15 +61,28 @@ bool THD::has_thd_temporary_tables() TABLE *THD::create_and_open_tmp_table(LEX_CUSTRING *frm, const char *path, const char *db, - const char *table_name) + const char *table_name, + HA_CREATE_INFO *create_info) { DBUG_ENTER("THD::create_and_open_tmp_table"); TMP_TABLE_SHARE *share; TABLE *table= NULL; - if ((share= create_temporary_table(frm, path, db, table_name))) + if ((share= create_temporary_table(frm, path, db, table_name, + !create_info->tmp_table()))) { + if (create_info) + { + if (ha_create_table(this, *share, create_info)) + { + deletefrm(share->normalized_path.str); + temporary_tables->remove(share); + free_tmp_table_share(share, false); + DBUG_RETURN(0); + } + } + open_options|= HA_OPEN_FOR_CREATE; table= open_temporary_table(share, table_name); open_options&= ~HA_OPEN_FOR_CREATE; @@ -927,7 +941,8 @@ uint THD::create_tmp_table_def_key(char *key, const char *db, TMP_TABLE_SHARE *THD::create_temporary_table(LEX_CUSTRING *frm, const char *path, const char *db, - const char *table_name) + const char *table_name, + bool write_frm) { DBUG_ENTER("THD::create_temporary_table"); @@ -961,6 +976,7 @@ TMP_TABLE_SHARE *THD::create_temporary_table(LEX_CUSTRING *frm, init_tmp_table_share(this, share, saved_key_cache, key_length, strend(saved_key_cache) + 1, tmp_path); + share->frm_image= frm; /* Prefer using frm image over file. The image might not be available in @@ -968,7 +984,7 @@ TMP_TABLE_SHARE *THD::create_temporary_table(LEX_CUSTRING *frm, TABLE::read_frm_image). */ res= (frm->str) - ? share->init_from_binary_frm_image(this, false, frm->str, frm->length) + ? share->init_from_binary_frm_image(this, write_frm, frm->str, frm->length) : open_table_def(this, share, GTS_TABLE | GTS_USE_DISCOVERY); if (res) |