• Olav Sandstaa's avatar
    Fix for Bug#14636211 WRONG RESULT (EXTRA ROW) ON A FROM SUBQUERY · fd5380b4
    Olav Sandstaa authored
                         WITH A VARIABLE AND ORDER BY
            Bug#16035412 MYSQL SERVER 5.5.29 WRONG SORTING USING COMPLEX INDEX
          
    This is a fix for a regression introduced by Bug#12667154:
    Bug#12667154 attempted to fix a performance problem with subqueries
    that did filesort. For doing filesort, the optimizer creates a quick
    select object to use when building the sort index. This quick select
    object was deleted after the first call to create_sort_index(). Thus,
    for queries where the subquery was executed multiple times, the quick
    object was only used for the first execution. For all later executions
    of the subquery, filesort used a complete table scan for building the
    sort index. The fix for Bug#12667154 tried to fix this by not deleting
    the quick object after the first execution of create_sort_index() so
    that it would be re-used for building the sort index by the following
    executions of the subquery.
          
    This regression introduced in Bug#12667154 is that due to not deleting
    the quick select object after building the sort index, the quick
    object could in some cases be used also during the second phase of the
    execution of the subquery instead of using the created sort
    index. This caused wrong results to be returned.
          
    The fix for this issue is to delete the reference to the select object
    after it has been used in create_sort_index(). In this way the select 
    and quick objects will not be available when doing the second phase
    of the execution of the select operation. To ensure that the select
    object can be re-used for the following executions of the subquery
    we make a copy of the select pointer. This is used for restoring the
    select object after the select operation is completed.
    
    
    mysql-test/suite/innodb/r/innodb_mysql.result:
      Changed explain output: The explain now contains "Using where" since we
      have restored the select pointer after doing the filesort operation.
    sql/sql_select.cc:
      Change create_sort_index() so that it always sets the pointer to
      the select object to NULL. This is done in order to avoid that the
      select->quick object can be used when execution the main part of
      the select operation.
    sql/sql_select.h:
      New member in JOIN_TAB: saved_select. Used by create_sort_index to
      make a backup copy of the select pointer.
    fd5380b4
sql_select.h 30.6 KB