diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_base.cc | 2 | ||||
-rw-r--r-- | sql/table.cc | 24 |
2 files changed, 23 insertions, 3 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 9a66b27a454..5345fdbecd0 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -5980,7 +5980,7 @@ find_field_in_tables(THD *thd, Item_ident *item, TRUE, &(item->cached_field_index)); #ifndef NO_EMBEDDED_ACCESS_CHECKS /* Check if there are sufficient access rights to the found field. */ - if (found && check_privileges && + if (found && check_privileges && !is_temporary_table(table_ref) && check_column_grant_in_table_ref(thd, table_ref, name, length)) found= WRONG_GRANT; #endif 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() && |