#At file:///export/home/didrik/mysqldev-6.0-codebase/6.0-codebase-bf-review52068/ based on revid:tor.didriksen@stripped
3830 Tor Didriksen 2010-03-17
comments/questions on patch for bug#52068
modified:
sql/sql_select.cc
=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc 2010-03-17 09:59:35 +0000
+++ b/sql/sql_select.cc 2010-03-17 14:27:53 +0000
@@ -1148,16 +1148,17 @@ static bool sj_table_is_included(JOIN *j
be used.
DESCRIPTION
- Setup the strategies to eliminate semi-join duplicates. ATM there are 4
- strategies:
+ Setup the strategies to eliminate semi-join duplicates.
+ At the moment there are 5 strategies:
1. DuplicateWeedout (use of temptable to remove duplicates based on rowids
of row combinations)
2. FirstMatch (pick only the 1st matching row combination of inner tables)
3. LooseScan (scanning the sj-inner table in a way that groups duplicates
together and picking the 1st one)
- 4. SJ-Materialization.
-
+ 4. MaterializeLookup
+ 5. MaterializeScan
+
The join order has "duplicate-generating ranges", and every range is
served by one strategy or a combination of FirstMatch with with some
other strategy.
@@ -1232,7 +1233,7 @@ static bool sj_table_is_included(JOIN *j
(2) - The handled range, which may contain only inner tables.
The inner tables are materialized in a temporary table that is
later used as a lookup structure for the outer correlated tables.
- (3) - The suffix of outer non-correlated tables.
+ (3) - The suffix of non-correlated tables.
MaterializeScan strategy
~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1241,7 +1242,7 @@ static bool sj_table_is_included(JOIN *j
+---+ +==========+ +-----+
(1) (2) (3)
- (1) - Prefix of outer non-correlated tables.
+ (1) - Prefix of non-correlated tables.
(2) - The handled range, which may contain only inner tables.
The inner tables are materialized in a temporary table which is
@@ -7232,7 +7233,7 @@ optimize_straight_join(JOIN *join, table
is returned. This is a purely heuristic decision.
*/
-static uint
+static int
allows_semijoin_materialization(const JOIN *join, table_map remaining_tables,
const JOIN_TAB *tab, uint idx)
{
@@ -7241,28 +7242,31 @@ allows_semijoin_materialization(const JO
1. We're in a semi-join nest that can be run with SJ-materialization
2. All the tables from the subquery are in the prefix
*/
- TABLE_LIST *emb_sj_nest= tab->emb_sj_nest;
+ const TABLE_LIST *emb_sj_nest= tab->emb_sj_nest;
if (!emb_sj_nest ||
!emb_sj_nest->sj_mat_info ||
remaining_tables & emb_sj_nest->sj_inner_tables)
return SJ_OPT_NONE;
+
/*
Walk back and check if all immediately preceding tables are from
this semi-join.
*/
- uint n_tables= my_count_bits(emb_sj_nest->sj_inner_tables);
+ const uint n_tables= my_count_bits(emb_sj_nest->sj_inner_tables);
for (uint i= 1; i < n_tables ; i++)
{
if (join->positions[idx - i].table->emb_sj_nest != emb_sj_nest)
return SJ_OPT_NONE;
}
+
/*
Disallow any plan that has dependent outer tables both in the prefix
part and the suffix part of the table order.
*/
- if ((remaining_tables & emb_sj_nest->nested_join->sj_depends_on) &&
- (emb_sj_nest->nested_join->sj_depends_on & ~remaining_tables))
+ if (( remaining_tables & emb_sj_nest->nested_join->sj_depends_on) &&
+ (~remaining_tables & emb_sj_nest->nested_join->sj_depends_on))
return SJ_OPT_NONE;
+
/*
Must use MaterializeScan strategy if there are outer correlated tables
among the remaining tables.
@@ -7271,11 +7275,9 @@ allows_semijoin_materialization(const JO
{
if (!emb_sj_nest->sj_subq_pred->sjm_scan_allowed)
return SJ_OPT_NONE;
- else
- return SJ_OPT_MATERIALIZE_SCAN;
+ return SJ_OPT_MATERIALIZE_SCAN;
}
- else
- return SJ_OPT_MATERIALIZE_LOOKUP;
+ return SJ_OPT_MATERIALIZE_LOOKUP;
}
@@ -13454,8 +13456,8 @@ void advance_sj_state(JOIN *join, table_
join->cur_dups_producing_tables &= ~handled_by_fm_or_ls;
/* 4. MaterializationLookup and MaterializationScan strategy handler */
- uint sjm_strategy= allows_semijoin_materialization(join, remaining_tables,
- new_join_tab, idx);
+ const int sjm_strategy=
+ allows_semijoin_materialization(join, remaining_tables, new_join_tab, idx);
if (sjm_strategy != SJ_OPT_NONE)
{
SJ_MATERIALIZATION_INFO *mat_info= emb_sj_nest->sj_mat_info;
Attachment: [text/bzr-bundle] bzr/tor.didriksen@sun.com-20100317142753-l503gtazj5nnjgiu.bundle
| Thread |
|---|
| • bzr commit into mysql-6.0-codebase-bugfixing branch (tor.didriksen:3830)Bug#52068 | Tor Didriksen | 17 Mar |