#At file:///work/bzr_trees/wl3485-merge-6.0/ based on revid:epotemkin@stripped
2822 Evgeny Potemkin 2009-03-02
WL#3485 Subquery optimization: FROM (SELECT)
A small fix for EXPLAIN to correctly show select's type when
derived tables/views are involved.
modified:
sql/sql_cache.cc
sql/sql_select.cc
sql/table.cc
=== modified file 'sql/sql_cache.cc'
--- a/sql/sql_cache.cc 2008-12-17 18:40:14 +0000
+++ b/sql/sql_cache.cc 2009-03-02 21:37:55 +0000
@@ -3390,16 +3390,17 @@ Query_cache::process_and_count_tables(TH
}
else
{
- DBUG_PRINT("qcache", ("table: %s db: %s type: %u",
- tables_used->table->s->table_name.str,
- tables_used->table->s->db.str,
- tables_used->table->s->db_type()->db_type));
if (tables_used->derived)
{
+ DBUG_PRINT("qcache", ("table: %s", tables_used->alias));
table_count--;
DBUG_PRINT("qcache", ("derived table skipped"));
continue;
}
+ DBUG_PRINT("qcache", ("table: %s db: %s type: %u",
+ tables_used->table->s->table_name.str,
+ tables_used->table->s->db.str,
+ tables_used->table->s->db_type()->db_type));
*tables_type|= tables_used->table->file->table_cache_type();
/*
=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc 2009-02-26 21:27:14 +0000
+++ b/sql/sql_select.cc 2009-03-02 21:37:55 +0000
@@ -21795,13 +21795,32 @@ bool mysql_explain_union(THD *thd, SELEC
sl;
sl= sl->next_select())
{
+ bool is_primary= FALSE;
+ if (sl->next_select())
+ is_primary= TRUE;
+
+ if (!is_primary && sl->first_inner_unit())
+ {
+ /*
+ If there is at least one materialized derived|view then it's a PRIMARY select.
+ Otherwise, all derived tables/views were merged and this select is a SIMPLE one.
+ */
+ for (SELECT_LEX_UNIT *un= sl->first_inner_unit();
+ un;
+ un= un->next_unit())
+ {
+ if ((!un->derived ||
+ un->derived->is_materialized_derived()))
+ {
+ is_primary= TRUE;
+ break;
+ }
+ }
+ }
// drop UNCACHEABLE_EXPLAIN, because it is for internal usage only
uint8 uncacheable= (sl->uncacheable & ~UNCACHEABLE_EXPLAIN);
sl->type= (((&thd->lex->select_lex)==sl)?
- ((sl->first_inner_unit() || sl->next_select()) &&
- (!sl->master_unit()->derived ||
- sl->master_unit()->derived->is_materialized_derived())
- ? "PRIMARY" : "SIMPLE"):
+ (is_primary ? "PRIMARY" : "SIMPLE"):
((sl == first)?
((sl->linkage == DERIVED_TABLE_TYPE) ?
"DERIVED":
=== modified file 'sql/table.cc'
--- a/sql/table.cc 2009-02-26 21:27:14 +0000
+++ b/sql/table.cc 2009-03-02 21:37:55 +0000
@@ -5189,12 +5189,7 @@ bool TABLE_LIST::init_derived(THD *thd,
SELECT_LEX *first_select= get_single_select();
SELECT_LEX_UNIT *unit= get_unit();
- /*
- Initialization is split for views and derived tables. Views
- are initialized after tables are opened, derived tables - prior to
- JOIN::prepare.
- */
- if (!unit || (!init_view && view))
+ if (!unit)
return FALSE;
/*
Check whether we can merge this derived table into main select.
@@ -5204,11 +5199,11 @@ bool TABLE_LIST::init_derived(THD *thd,
if (first_select->table_list.elements > 1)
set_multitable();
+ unit->derived= this;
if (init_view && !view)
{
/* This is all what we can do for a derived table for now. */
set_derived();
- unit->derived= this;
}
if (!is_view())
| Thread |
|---|
| • bzr commit into mysql-6.0-opt branch (epotemkin:2822) WL#3485 | Evgeny Potemkin | 2 Mar |