• holyfoot/hf@mysql.com/hfmain.(none)'s avatar
    Bug #29717 INSERT INTO SELECT inserts values even if · f1ee2d06
    holyfoot/hf@mysql.com/hfmain.(none) 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()
    f1ee2d06
sql_select.cc 301 KB