Commit 91ffdc83 authored by Monty's avatar Monty

Don't try to open temporary tables if there are no temporary tables.

This was done to increase performance when not using temporary tables
as checking if a table is a temporary table involves a lot of code.
parent f9f33b85
......@@ -3691,9 +3691,9 @@ open_and_process_table(THD *thd, TABLE_LIST *tables, uint *counter, uint flags,
The problem is that since those attributes are not set in merge
children, another round of PREPARE will not help.
*/
error= thd->open_temporary_table(tables);
if (!error && !tables->table)
if (!thd->has_temporary_tables() ||
(!(error= thd->open_temporary_table(tables)) &&
!tables->table))
error= open_table(thd, tables, ot_ctx);
thd->pop_internal_handler();
......@@ -3710,9 +3710,9 @@ open_and_process_table(THD *thd, TABLE_LIST *tables, uint *counter, uint flags,
Repair_mrg_table_error_handler repair_mrg_table_handler;
thd->push_internal_handler(&repair_mrg_table_handler);
error= thd->open_temporary_table(tables);
if (!error && !tables->table)
if (!thd->has_temporary_tables() ||
(!(error= thd->open_temporary_table(tables)) &&
!tables->table))
error= open_table(thd, tables, ot_ctx);
thd->pop_internal_handler();
......@@ -3727,7 +3727,8 @@ open_and_process_table(THD *thd, TABLE_LIST *tables, uint *counter, uint flags,
still might need to look for a temporary table if this table
list element corresponds to underlying table of a merge table.
*/
error= thd->open_temporary_table(tables);
if (thd->has_temporary_tables())
error= thd->open_temporary_table(tables);
}
if (!error && !tables->table)
......
......@@ -4851,6 +4851,7 @@ class THD: public THD_count, /* this must be first */
TMP_TABLE_ANY
};
bool has_thd_temporary_tables();
bool has_temporary_tables();
TABLE *create_and_open_tmp_table(LEX_CUSTRING *frm,
const char *path,
......@@ -4889,7 +4890,6 @@ class THD: public THD_count, /* this must be first */
/* Whether a lock has been acquired? */
bool m_tmp_tables_locked;
bool has_temporary_tables();
uint create_tmp_table_def_key(char *key, const char *db,
const char *table_name);
TMP_TABLE_SHARE *create_temporary_table(LEX_CUSTRING *frm,
......
......@@ -834,6 +834,7 @@ st_select_lex_unit *With_element::clone_parsed_spec(THD *thd,
st_select_lex_unit *res= NULL;
Query_arena backup;
Query_arena *arena= thd->activate_stmt_arena_if_needed(&backup);
bool has_tmp_tables;
if (!(lex= (LEX*) new(thd->mem_root) st_lex_local))
{
......@@ -879,11 +880,12 @@ st_select_lex_unit *With_element::clone_parsed_spec(THD *thd,
spec_tables= lex->query_tables;
spec_tables_tail= 0;
has_tmp_tables= thd->has_temporary_tables();
for (TABLE_LIST *tbl= spec_tables;
tbl;
tbl= tbl->next_global)
{
if (!tbl->derived && !tbl->schema_table &&
if (has_tmp_tables && !tbl->derived && !tbl->schema_table &&
thd->open_temporary_table(tbl))
goto err;
spec_tables_tail= tbl;
......
......@@ -338,9 +338,11 @@ bool THD::open_temporary_table(TABLE_LIST *tl)
have invalid db or table name.
Instead THD::open_tables() should be used.
*/
DBUG_ASSERT(!tl->derived && !tl->schema_table);
DBUG_ASSERT(!tl->derived);
DBUG_ASSERT(!tl->schema_table);
DBUG_ASSERT(has_temporary_tables());
if (tl->open_type == OT_BASE_ONLY || !has_temporary_tables())
if (tl->open_type == OT_BASE_ONLY)
{
DBUG_PRINT("info", ("skip_temporary is set or no temporary tables"));
DBUG_RETURN(false);
......@@ -452,10 +454,13 @@ bool THD::open_temporary_table(TABLE_LIST *tl)
*/
bool THD::open_temporary_tables(TABLE_LIST *tl)
{
TABLE_LIST *first_not_own;
DBUG_ENTER("THD::open_temporary_tables");
TABLE_LIST *first_not_own= lex->first_not_own_table();
if (!has_temporary_tables())
DBUG_RETURN(0);
first_not_own= lex->first_not_own_table();
for (TABLE_LIST *table= tl; table && table != first_not_own;
table= table->next_global)
{
......@@ -868,7 +873,7 @@ void THD::restore_tmp_table_share(TMP_TABLE_SHARE *share)
@return false Temporary tables exist
true No temporary table exist
*/
inline bool THD::has_temporary_tables()
bool THD::has_temporary_tables()
{
DBUG_ENTER("THD::has_temporary_tables");
bool result= (rgi_slave
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment