← Back to team overview

maria-developers team mailing list archive

Re: Rev 2897: Fix for LP bug#611379. in file:///home/bell/maria/bzr/work-maria-5.1-lb611379/

 

Hi!

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

sanja> At file:///home/bell/maria/bzr/work-maria-5.1-lb611379/
sanja> ------------------------------------------------------------
sanja> revno: 2897
sanja> revision-id: sanja@xxxxxxxxxxxx-20100812075534-wc2dngmpiqm9grra
sanja> parent: monty@xxxxxxxxx-20100809170542-ewa2awm6pcoi1ipy
sanja> committer: sanja@xxxxxxxxxxxx
sanja> branch nick: work-maria-5.1-lb611379
sanja> timestamp: Thu 2010-08-12 10:55:34 +0300
sanja> message:
sanja>   Fix for LP bug#611379.
  
sanja>   maybe_null/null_value flag set to TRUE for Item_sum_distinct.


=== modified file 'mysql-test/t/func_group.test'
--- a/mysql-test/t/func_group.test	2009-11-24 15:26:13 +0000
+++ b/mysql-test/t/func_group.test	2010-08-12 07:55:34 +0000
@@ -1082,6 +1082,21 @@
 from t1 a, t1 b;
 select *, f1 = f2 from t1;
 drop table t1;
+
+--echo #
+--echo #test for LP Bug#611379
+--echo #
+create table t1 (a int not null);
+insert into t1 values (1);
+create table t2 (a int not null primary key);
+insert into t2 values (10);
+explain select sum(distinct t1.a) from t1,t2 where t1.a=t2.a;
+explain select * from (select sum(distinct t1.a) from t1,t2 where t1.a=t2.a)
+as t;
+select sum(distinct t1.a) from t1,t2 where t1.a=t2.a;
+select * from (select sum(distinct t1.a) from t1,t2 where t1.a=t2.a) as t;
+drop table t1,t2;
+
 --echo #
 --echo End of 5.1 tests
 

=== modified file 'sql/item_sum.cc'
--- a/sql/item_sum.cc	2010-08-02 09:01:24 +0000
+++ b/sql/item_sum.cc	2010-08-12 07:55:34 +0000
@@ -949,6 +949,7 @@
 {
   DBUG_ASSERT(args[0]->fixed);
 
+  null_value= maybe_null= TRUE;
   table_field_type= args[0]->field_type();
 
I don't think you have to set null_value as this is set in
item_sum_distinct::setup(), but don't think this is critical to fix.

I was checking the Item_sum_num::fix_fields() code and noticed that we
do there:

  maybe_null=0;
  for (uint i=0 ; i < arg_count ; i++)
  {
    if (args[i]->fix_fields(thd, args + i) || args[i]->check_cols(1))
      return TRUE;
    set_if_bigger(decimals, args[i]->decimals);
    maybe_null |= args[i]->maybe_null;
  }
  result_field=0;
  max_length=float_length(decimals);
  null_value=1;
  fix_length_and_dec()

I think we can remove from the above all calculation of maybe_null and
setting of null_value as fix_length_and_dec() sets maybe_null and
null_value.  Instead we could add an assert after fix_length_and_dec
that maybe_null is set.

Regards,
Monty








References