It’s difficult to implement SUM efficiently. It needs two pieces of state: an accumulator (containing the total of values seen so far) and a count (recording whether any records were seen).
SUM0 is simpler to implement. It contains only the accumulator, and outsources the counting to another agg function. Often there are several agg functions which each need a count, so the effort can be shared. Julian
