List:General Discussion« Previous MessageNext Message »
From:Sasha Pachev Date:July 19 1999 10:14pm
Subject:Re: SUM() changed in 3.23?
View as plain text  
Paul DuBois wrote:
> 
> At 4:16 PM -0500 7/19/99, Sasha Pachev wrote:
> >Scott Hess wrote:
> >>
> >> Sasha Pachev <sasha@stripped> wrote:
> >> > Balint TOTH wrote:
> >> > > Is it OK if sum(field) returns NULL if the table has no records?
> Older
> >> > > versions (like 3.22.22) returned 0.
> >> >
> >> > This is more logical, I think. If this is not what you want, you can
> do
> >> > ifnull(sum(field), 0)
> >>
> >> Except insofar as it breaks existing code!  Just this weekend this became a
> >> problem as I tested against 3.22.23 (we were using 3.22.15).
> >>
> >> Is this how SUM() is supposed to work?  When I described the problem at the
> >> office, my colleagues were pretty much amazed that this happened, and think
> >> it must be a bug.  If it's considered a feature, I need to send some emails
> >> around...
> >>
> >> Later,
> >> scott
> >
> >If you have too much code that depends on this, and you cannot just
> >change it in the code, you can change a couple of lines in the sources
> >of mysql and recompile.
> 
> Where?  Which file?  What lines?
> 

OK, Paul, you made me look for it :-) This actually good, since it gave
me a chance to better familiarize myself with MySQL sources. The magic
line is in
sql/item_sum.h ( line 97) :

void fix_length_and_dec() { maybe_null=null_value=1; }

change 1 to 0 - this is the way it was in 3.22 versions

I did test it - changing it to 0 makes the sum on an empty table return
0 and it does not break normal sum - as far as I can tell there should
not be any other issues involved, but I would like to have Monty confirm
it before I say anything authoritative.

-- 
Sasha Pachev
http://www.sashanet.com/ (home)
http://www.direct1.com/ (work)
Thread
SUM() changed in 3.23?Balint TOTH19 Jul
  • Re: SUM() changed in 3.23?Sasha Pachev19 Jul
  • Re: SUM() changed in 3.23?Scott Hess20 Jul
  • Re: SUM() changed in 3.23?Sasha Pachev20 Jul
    • Re: SUM() changed in 3.23?Paul DuBois20 Jul
  • Re: SUM() changed in 3.23?Sasha Pachev20 Jul
    • Re: SUM() changed in 3.23?Michael Widenius30 Jul