• unknown's avatar
    Bug #29717 INSERT INTO SELECT inserts values even if · 791584ae
    unknown authored
     SELECT statement itself returns empty.
    
    As a result of this bug 'SELECT AGGREGATE_FUNCTION(fld) ... GROUP BY'
    can return one row instead of an empty result set.
    
    When GROUP BY only has fields of constant tables
    (with a single row), the optimizer deletes the group_list.
    After that we lose the information about whether we had an
    GROUP BY statement. Though it's important
    as SELECT min(x) from empty_table; and
       SELECT min(x) from empty_table GROUP BY y; have to return
    different results - the first query should return one row,
    second - an empty result set.
    So here we add the 'group_optimized_away' flag to remember this case
    when GROUP BY exists in the query and is removed
    by the optimizer, and check this flag in end_send_group()
    
    
    mysql-test/r/group_by.result:
      Bug #29717 INSERT INTO SELECT inserts values even if
       SELECT statement itself returns empty.
      
      test result
    mysql-test/r/insert_select.result:
      Bug #29717 INSERT INTO SELECT inserts values even if
       SELECT statement itself returns empty.
      
      test result
    mysql-test/t/group_by.test:
      Bug #29717 INSERT INTO SELECT inserts values even if
       SELECT statement itself returns empty.
      
      This is additional testcase that is more basic than the
      original bug's testcase and has the same reason.
    mysql-test/t/insert_select.test:
      Bug #29717 INSERT INTO SELECT inserts values even if
       SELECT statement itself returns empty.
      
      test case
    sql/sql_select.cc:
      Bug #29717 INSERT INTO SELECT inserts values even if
       SELECT statement itself returns empty.
      
      Remember the 'GROUP BY was optimized away' case in the JOIN::group_optimized
      and check this in the end_send_group()
    sql/sql_select.h:
      Bug #29717 INSERT INTO SELECT inserts values even if
       SELECT statement itself returns empty.
      
      JOIN::group_optimized member added to remember the 'GROUP BY optimied away'
      case
    791584ae
group_by.result 29.7 KB