• unknown's avatar
    Fix for BUG#20954: avg(keyval) retuns 0.38 but max(keyval) returns an empty set · 996cdfd3
    unknown authored
    The problem was in that opt_sum_query() replaced MIN/MAX functions
    with the corresponding constant found in a key, but due to imprecise
    representation of float numbers, when evaluating the where clause,
    this comparison failed.
    
    When MIN/MAX optimization detects that all tables can be removed,
    also remove all conjuncts in a where clause that refer to these
    tables. As a result of this fix, these conditions are not evaluated
    twice, and in the case of float number comparisons we do not discard
    result rows due to imprecise float representation.
    
    As a side-effect this fix also corrects an unnoticed problem in
    bug 12882.
    
    
    mysql-test/r/func_group.result:
      BUG#20954 - test result adjustment.
      Adjusted the test result of bug 12882 which was not preperly fixed.
      The current patch corrects the problem that was fully corrected by the
      patch for 12882.
      
      The problem was that opt_sum_query() indicated that the optimizer may
      remove all tables because all MIN/MAX/COUNT functions are constants,
      but this lead to an empty result instead of NULL because the WHERE
      clause was still evaluated.
      
      The current fix removes all conjuncts in the where clause that
      reference the removed tables, and thus corrects the problem.
    mysql-test/r/select.result:
      BUG#20954 - added test
    mysql-test/r/subselect.result:
      BUG#20954 - test result adjustment.
      
      The fix removes those conditions in a where clause that refer to
      tables optimized away by MIN/MAX optimization (opt_sum_query()).
    mysql-test/t/select.test:
      BUG#20954 - added test
    sql/sql_select.cc:
      Fix for BUG#20954: avg(keyval) retuns 0.38 but max(keyval) returns an empty set
      
      When MIN/MAX optimization detects that all tables can be removed,
      also remove all conjuncts in a where clause that refer to these
      tables. As a result of this fix, these conditions are not evaluated
      twice, and in the case of float number comparisons we do not discard
      result rows due to imprecise float representation.
      
      As a side-effect this fix also corrects an unnoticed problem in
      bug 12882.
    996cdfd3
func_group.result 30.1 KB