mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Bug #29717 INSERT INTO SELECT inserts values even if
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()
This commit is contained in:
@ -777,6 +777,7 @@ JOIN::optimize()
|
||||
order=0; // The output has only one row
|
||||
simple_order=1;
|
||||
select_distinct= 0; // No need in distinct for 1 row
|
||||
group_optimized_away= 1;
|
||||
}
|
||||
|
||||
calc_group_buffer(this, group_list);
|
||||
@ -6896,7 +6897,8 @@ end_send_group(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
|
||||
if (!join->first_record || end_of_records ||
|
||||
(idx=test_if_group_changed(join->group_fields)) >= 0)
|
||||
{
|
||||
if (join->first_record || (end_of_records && !join->group))
|
||||
if (join->first_record ||
|
||||
(end_of_records && !join->group && !join->group_optimized_away))
|
||||
{
|
||||
if (join->procedure)
|
||||
join->procedure->end_group();
|
||||
|
Reference in New Issue
Block a user