1
0
mirror of https://github.com/MariaDB/server.git synced 2025-12-24 11:21:21 +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:
holyfoot/hf@mysql.com/hfmain.(none)
2007-07-31 10:46:04 +05:00
parent 40fb6443ce
commit f1ee2d0687
6 changed files with 106 additions and 1 deletions

View File

@@ -180,6 +180,14 @@ class JOIN :public Sql_alloc
ROLLUP rollup; // Used with rollup
bool select_distinct; // Set if SELECT DISTINCT
/*
If we have the GROUP BY statement in the query,
but the group_list was emptied by optimizer, this
flag is TRUE.
It happens when fields in the GROUP BY are from
constant table
*/
bool group_optimized_away;
/*
simple_xxxxx is set if ORDER/GROUP BY doesn't include any references
@@ -276,6 +284,7 @@ class JOIN :public Sql_alloc
ref_pointer_array_size= 0;
zero_result_cause= 0;
optimized= 0;
group_optimized_away= 0;
fields_list= fields_arg;
bzero((char*) &keyuse,sizeof(keyuse));