← Back to team overview

maria-developers team mailing list archive

review: [Commits] Rev 2946: Fix LP BUG#715738 in file:///home/tsk/mprog/src/5.3/

 

Hi!

>>>>> "timour" == timour  <timour@xxxxxxxxxxxx> writes:

timour> At file:///home/tsk/mprog/src/5.3/
timour> ------------------------------------------------------------
timour> revno: 2946
timour> revision-id: timour@xxxxxxxxxxxx-20110322132154-moeuyey4saatnm5x
timour> parent: igor@xxxxxxxxxxxx-20110315193048-akp4yq0y079dkkx2
timour> committer: timour@xxxxxxxxxxxx
timour> branch nick: 5.3
timour> timestamp: Tue 2011-03-22 15:21:54 +0200
timour> message:
timour>   Fix LP BUG#715738
  
timour>   Analysis:
timour>   A query with implicit grouping is one with aggregate functions and
timour>   no GROUP BY clause. MariaDB inherits from MySQL an SQL extenstion
timour>   that allows mixing aggregate functions with non-aggregate fields.
timour>   If a query with such mixed select clause produces an empty result
timour>   set, the meaning of aggregate functions is well defined - either
timour>   NULL (MIN, MAX, etc.), or 0 (count(*)). However the non-aggregated
timour>   fields must also have some value, and the only reasonable value in
timour>   the case of empty result is NULL.
  
<cut>

=== modified file 'sql/sql_lex.cc'
--- a/sql/sql_lex.cc	2011-03-09 13:47:59 +0000
+++ b/sql/sql_lex.cc	2011-03-22 13:21:54 +0000
@@ -1667,6 +1667,11 @@ void st_select_lex::init_select()
   cond_value= having_value= Item::COND_UNDEF;
   inner_refs_list.empty();
   full_group_by_flag= 0;
+  n_sum_items= 0;
+  n_child_sum_items= 0;
+  select_n_sum_item= 0;
+  select_n_nonsum_item= 0;
+

ok, but I am not totally happy with that we get even more things that
needs to be initialized for every select (we already initialize a lot
of things...)

Please change the names of 'n_' to something more understandable.
'number_of_' or 'use the _count' prefix that we use in other places.


=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2011-03-09 13:47:59 +0000
+++ b/sql/sql_yacc.yy	2011-03-22 13:21:54 +0000
@@ -1338,7 +1338,7 @@ bool my_yyoverflow(short **a, YYSTYPE **
         ev_alter_on_schedule_completion opt_ev_rename_to opt_ev_sql_stmt
 
 %type <ulong_num>
-        ulong_num real_ulong_num merge_insert_types
+        ulong_num real_ulong_num merge_insert_types remember_n_sum_func
 
 %type <ulonglong_number>
         ulonglong_num real_ulonglong_num size_number
@@ -7019,31 +7019,43 @@ select_item_list:
         ;
 
 select_item:
-          remember_name select_item2 remember_end select_alias
+          remember_n_sum_func remember_name select_item2 remember_end select_alias
           {
             THD *thd= YYTHD;
-            DBUG_ASSERT($1 < $3);
+            DBUG_ASSERT($2 < $4);
 
-            if (add_item_to_list(thd, $2))
+            if (thd->lex->current_select->n_sum_items > $1)
+              ++thd->lex->current_select->select_n_sum_item;
+            else
+              ++thd->lex->current_select->select_n_nonsum_item;

Not sure if the counting of select_n_nonsum_item is correct.

For example, we may have an item:

SELECT MAX(field)+const_field from t1 ...

In this case 'MAX(field)+const_field' will be counted as
select_n_sum_item even if it should be counted also as
select_n_nonsum_item.

Not sure we can do this test properly at the parsing stage...

Regards,
Monty