• unknown's avatar
    Fix bug lp:777691 · 53681ee5
    unknown authored
    Analysis:
    
    For some of the re-executions of the correlated subquery the
    where clause is false. In these cases the execution of the
    subquery detects that it must generate a NULL row because of
    implicit grouping. In this case the subquery execution reaches
    the following code in do_select():
    
            while ((table= li++))
              mark_as_null_row(table->table);
    
    This code marks all rows in the table as complete NULL rows.
    In the example, when evaluating the field t2.f10 for the second
    row, all bits of Field::null_ptr[0] are set by the previous call
    to mark_as_null_row(). Then the call to Field::is_null()
    returns true, resulting in a NULL for the MAX function.
    
    Thus the lines above are not suitable for subquery re-execution
    because mark_as_null_row() changes the NULL bits of each table
    field, and there is no logic to restore these fields.
    
    Solution:
    
    The call to mark_as_null_row() was added by the fix for bug
    lp:613029. Therefore removing the fix for lp:613029 corrects
    this wrong result. At the same time the test for lp:613029
    behaves correctly because the changes of MWL#89 result in a
    different execution path where:
    - the constant subquery is evaluated via JOIN::exec_const_cond
    - detecting that it has an empty result triggers the branch
      if (zero_result_cause)
        return_zero_rows()
    - return_zero_rows() calls mark_as_null_row().
    
    53681ee5
sql_select.cc 694 KB