summaryrefslogtreecommitdiff
path: root/sql/table.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/table.cc')
-rw-r--r--sql/table.cc24
1 files changed, 22 insertions, 2 deletions
diff --git a/sql/table.cc b/sql/table.cc
index d4f8170e0af..ca6ce02e4f2 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -8232,6 +8232,24 @@ void TABLE_LIST::wrap_into_nested_join(List<TABLE_LIST> &join_list)
/**
+ Check whether optimization has been performed and a derived table either
+ been merged to upper select level or materialized.
+
+ @param table a TABLE_LIST object containing a derived table
+
+ @return true in case the derived table has been merged to surrounding select,
+ false otherwise
+*/
+
+static inline bool derived_table_optimization_done(TABLE_LIST *table)
+{
+ return table->derived &&
+ (table->derived->is_excluded() ||
+ table->is_materialized_derived());
+}
+
+
+/**
@brief
Initialize this derived table/view
@@ -8267,13 +8285,15 @@ bool TABLE_LIST::init_derived(THD *thd, bool init_view)
set_multitable();
unit->derived= this;
- if (init_view && !view)
+ if (init_view && !view &&
+ !derived_table_optimization_done(this))
{
/* This is all what we can do for a derived table for now. */
set_derived();
}
- if (!is_view())
+ if (!is_view() &&
+ !derived_table_optimization_done(this))
{
/* A subquery might be forced to be materialized due to a side-effect. */
if (!is_materialized_derived() && first_select->is_mergeable() &&