List:Internals« Previous MessageNext Message »
From:Øystein Grøvlen Date:November 11 2009 4:22pm
Subject:Re: Table pull-out for const tables in subqueries with straight-join
View as plain text  
Jay Pipes wrote:
 > Øystein Grøvlen wrote:
 >>  From my point of view, one should try to pull out t3 if t2 is
 >> pulled-out, but not otherwise.  Does anyone disagree?
 >
 > No, that makes sense to me. :)  It is also what the WL#3740 seems to
 > indicate is the correct behaviour:
<snip>
 > So, perhaps the current code has a bug in it somewhere?

I think there might be more that one bug preventing the table from
being pulled out.  The relevant code from make_join_statistics is as
follows:

   if (s->dependent)	// If dependent on some table
   {
     // All dep. must be constants
     if (s->dependent & ~(found_const_table_map))
       continue;
     if (table->file->stats.records <= 1L &&
         (table->file->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT) &&
         !table->pos_in_table_list->embedding)
     {					// system table
       <Register table as a constant table>
     }

Note that s->dependent will refer to the table of the left side of
STRAIGHT_JOIN.  There are two issues with this code:

1. As far as I can tell, found_const_table_map will only contain tables
    with one row.  To also include tables with zero rows, one should test
    against join->const_table_map.

2. At least in my particular example,
    table->pos_in_table_list->embedding is non-zero.  I have not quite
    figured out what this means, but I observe that if I remove this
    criteria some existing tests start failing.

--
Øystein

Thread
Table pull-out for const tables in subqueries with straight-joinØystein Grøvlen10 Nov
  • Re: Table pull-out for const tables in subqueries with straight-joinJay Pipes10 Nov
    • Re: Table pull-out for const tables in subqueries with straight-joinØystein Grøvlen11 Nov