summaryrefslogtreecommitdiff
path: root/sql/sql_lex.cc
diff options
context:
space:
mode:
authorSergey Petrunya <psergey@askmonty.org>2011-12-05 01:31:42 +0400
committerSergey Petrunya <psergey@askmonty.org>2011-12-05 01:31:42 +0400
commit255fd6c9294025ced406382980b0ad51960f0971 (patch)
treee7d4f9097843a55ec9272790fa30d8c48cbf6c50 /sql/sql_lex.cc
parentb5a05df61ea263aa3c3b9df78c56148adf029f04 (diff)
downloadmariadb-git-255fd6c9294025ced406382980b0ad51960f0971.tar.gz
Make subquery Materialization, as well as semi-join Materialization be shown
in EXPLAIN as select_type==MATERIALIZED. Before, we had select_type==SUBQUERY and it was difficult to tell materialized subqueries from uncorrelated scalar-context subqueries.
Diffstat (limited to 'sql/sql_lex.cc')
-rw-r--r--sql/sql_lex.cc64
1 files changed, 51 insertions, 13 deletions
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 117a866555c..2e2bec06c06 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -3527,20 +3527,58 @@ void st_select_lex::set_explain_type()
SELECT_LEX *first= master_unit()->first_select();
/* drop UNCACHEABLE_EXPLAIN, because it is for internal usage only */
uint8 is_uncacheable= (uncacheable & ~UNCACHEABLE_EXPLAIN);
+
+ bool using_materialization= FALSE;
+ Item_subselect *parent_item;
+ if ((parent_item= master_unit()->item) &&
+ parent_item->substype() == Item_subselect::IN_SUBS)
+ {
+ Item_in_subselect *in_subs= (Item_in_subselect*)parent_item;
+ /*
+ Surprisingly, in_subs->is_set_strategy() can return FALSE here,
+ even for the last invocation of this function for the select.
+ */
+ if (in_subs->test_strategy(SUBS_MATERIALIZATION))
+ using_materialization= TRUE;
+ }
- type= ((&master_unit()->thd->lex->select_lex == this) ?
- (is_primary ? "PRIMARY" : "SIMPLE"):
- ((this == first) ?
- ((linkage == DERIVED_TABLE_TYPE) ?
- "DERIVED" :
- ((is_uncacheable & UNCACHEABLE_DEPENDENT) ?
- "DEPENDENT SUBQUERY" :
- (is_uncacheable ? "UNCACHEABLE SUBQUERY" :
- "SUBQUERY"))) :
- ((is_uncacheable & UNCACHEABLE_DEPENDENT) ?
- "DEPENDENT UNION":
- is_uncacheable ? "UNCACHEABLE UNION":
- "UNION")));
+ if (&master_unit()->thd->lex->select_lex == this)
+ {
+ type= is_primary ? "PRIMARY" : "SIMPLE";
+ }
+ else
+ {
+ if (this == first)
+ {
+ /* If we're a direct child of a UNION, we're the first sibling there */
+ if (linkage == DERIVED_TABLE_TYPE)
+ type= "DERIVED";
+ else if (using_materialization)
+ type= "MATERIALIZED";
+ else
+ {
+ if (is_uncacheable & UNCACHEABLE_DEPENDENT)
+ type= "DEPENDENT SUBQUERY";
+ else
+ {
+ type= is_uncacheable? "UNCACHEABLE SUBQUERY" :
+ "SUBQUERY";
+ }
+ }
+ }
+ else
+ {
+ /* This a non-first sibling in UNION */
+ if (is_uncacheable & UNCACHEABLE_DEPENDENT)
+ type= "DEPENDENT UNION";
+ else if (using_materialization)
+ type= "MATERIALIZED UNION";
+ else
+ {
+ type= is_uncacheable ? "UNCACHEABLE UNION": "UNION";
+ }
+ }
+ }
options|= SELECT_DESCRIBE;
}