Hi,

I know that i am not Firebird core developer and I have less influence.
But, why do you still say about WHILE, SUSSPEND, YIELD, FETCH if there is 
simple alternative to not have it at all?
Can someone tell me what is wrong with my proposition? 
------------------------------------------------------------------


Instead of simple

create aggregate function custom_sum (i integer) returns (o integer)
as
begin                
  if (i is not null) then
     begin
        if (o is null) then
                o = 0;
        o = o + i;
     end
end

you propose something like this 

create aggregate function custom_sum (i integer) returns (o integer)
as
begin
    while (not agg_finished)
    do
    begin
        if (i is not null) then
        begin
            if (o is null) then
                o = 0;
            o = o + i;
        end

        suspend;
    end
end

------------------------------------------------------------------

instead of simple:

create aggregate function custom_avg (i double precision) returns (o double 
precision)
as
    declare accumulated double precision = 0;
begin
   if (i is not null) then
       accumulated = accumulated + i;        
                
  if (agg_result_needed and (accumulated is not null) then
    o = accumulated / agg_i;
end

you propose:
create aggregate function custom_avg (i double precision) returns (o double 
precision)
as
    declare count integer = 0;
    declare accumulated double precision = 0;
begin
    while (not agg_finished)
    do
    begin
        if (i is not null) then
        begin
            count = count + 1;
            accumulated = accumulated + i;
            o = accumulated / count;
        end

        suspend;
    end
end

------------------------------------------------------------------

Can you tell me also how you prevent:
- Infinite while do (i know user should use it with care but why increase risk?)
- that user do not write SUSPEND/YIELD/FETCH or user call it to many times?
- minimize code execution like in avg? Instead of make one division you propose 
design where you must divide it always row by row.
 And e.g. if you have 1000 rows with only one grouping key, you have 1000 of 
additions and 1000 of divisions.

------------------------------------------------------------------

How work internal SUM, AVG already? They call yead/fetch/suspend or something 
like this?
Or engine send them required state of parameters/variables?

regards,
Karol Bieniaszewski
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to