diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_base.cc | 17 | ||||
-rw-r--r-- | sql/sql_class.h | 6 | ||||
-rw-r--r-- | sql/sql_union.cc | 9 |
3 files changed, 31 insertions, 1 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc index ac4b8a45107..3758b3ba710 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -769,6 +769,23 @@ void close_thread_tables(THD *thd) thd->derived_tables= 0; } + if (thd->rec_tables) + { + TABLE *next; + /* + Close all temporary tables created for recursive table references. + This action was postponed because the table could be used in the + statements like ANALYZE WITH r AS (...) SELECT * from r + where r is defined through recursion. + */ + for (table= thd->rec_tables ; table ; table= next) + { + next= table->next; + free_tmp_table(thd, table); + } + thd->rec_tables= 0; + } + /* Mark all temporary tables used by this statement as free for reuse. */ diff --git a/sql/sql_class.h b/sql/sql_class.h index b6dafd939bc..295474d0d62 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1381,6 +1381,11 @@ public: */ TABLE *derived_tables; + /* + Temporary tables created for recursive table references. + */ + TABLE *rec_tables; + /* During a MySQL session, one can lock tables in two modes: automatic or manual. In automatic mode all necessary tables are locked just before @@ -1461,6 +1466,7 @@ public: open_tables= 0; temporary_tables= 0; derived_tables= 0; + rec_tables= 0; extra_lock= 0; lock= 0; locked_tables_mode= LTM_NONE; diff --git a/sql/sql_union.cc b/sql/sql_union.cc index b30b5528741..71d0e331101 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -283,7 +283,14 @@ void select_union_recursive::cleanup() tab->file->extra(HA_EXTRA_RESET_STATE); tab->file->ha_delete_all_rows(); } - free_tmp_table(thd, tab); + /* + The table will be closed later in close_thread_tables(), + because it might be used in the statements like + ANALYZE WITH r AS (...) SELECT * from r + where r is defined through recursion. + */ + tab->next= thd->rec_tables; + thd->rec_tables= tab; } } |