1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

Bug #16792 query with subselect, join, and group not returning proper values

Treat queries with no FROM and aggregate functions as normal queries,
so the aggregate function get correctly calculated as if there is 1 row. 
This means that they will be considered to have one row, so COUNT(*) will return
1 instead of 0. Other aggregates will behave in compatible manner.


mysql-test/r/func_gconcat.result:
  Bug #16792 query with subselect, join, and group not returning proper values
   - test case. Note how it improves the support for DUAL.
mysql-test/r/func_group.result:
  Bug #16792 query with subselect, join, and group not returning proper values
   - test case. Note how it improves the support for DUAL.
mysql-test/r/subselect.result:
  Bug #16792 query with subselect, join, and group not returning proper values
   - consequence of (SELECT MAX(<const>)) now returning <const> instead of 0
mysql-test/t/func_group.test:
  Bug #16792 query with subselect, join, and group not returning proper values
   - test case.
sql/opt_sum.cc:
  Bug #16792 query with subselect, join, and group not returning proper values
   - cannot do the optimization if the index is already opened by (say) UPDATE
     as it invloves opening reading and closing the index.
sql/sql_select.cc:
  Bug #16792 query with subselect, join, and group not returning proper values
   - Treat queries with no FROM and aggregate functions as normal queries,
  so the aggregate function get correctly calculated as if there is 1 row.
This commit is contained in:
unknown
2006-08-10 16:45:02 +03:00
parent 84ece59cef
commit d3dd6fa008
6 changed files with 55 additions and 15 deletions

View File

@ -1131,7 +1131,7 @@ JOIN::exec()
DBUG_VOID_RETURN;
}
if (!tables_list)
if (!tables_list && (tables || !select_lex->with_sum_func))
{ // Only test of functions
if (select_options & SELECT_DESCRIBE)
select_describe(this, FALSE, FALSE, FALSE,
@ -1170,7 +1170,12 @@ JOIN::exec()
thd->examined_row_count= 0;
DBUG_VOID_RETURN;
}
thd->limit_found_rows= thd->examined_row_count= 0;
/*
don't reset the found rows count if there're no tables
as FOUND_ROWS() may be called.
*/
if (tables)
thd->limit_found_rows= thd->examined_row_count= 0;
if (zero_result_cause)
{
@ -1209,7 +1214,8 @@ JOIN::exec()
having= tmp_having;
select_describe(this, need_tmp,
order != 0 && !skip_sort_order,
select_distinct);
select_distinct,
!tables ? "No tables used" : NullS);
DBUG_VOID_RETURN;
}
@ -6028,9 +6034,12 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure)
else
end_select=end_send;
}
join->join_tab[join->tables-1].next_select=end_select;
if (join->tables)
{
join->join_tab[join->tables-1].next_select=end_select;
join_tab=join->join_tab+join->const_tables;
join_tab=join->join_tab+join->const_tables;
}
join->send_records=0;
if (join->tables == join->const_tables)
{
@ -6048,6 +6057,7 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure)
}
else
{
DBUG_ASSERT(join_tab);
error= sub_select(join,join_tab,0);
if (error >= 0)
error= sub_select(join,join_tab,1);