clear markdown compare help best fiddles feedback dbanow.uk
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2805490 fiddles created (40771 in the last week).

create aggregate mysum_fast (numeric) ( sfunc = numeric_add, stype = numeric );
 hidden batch(es)


create or replace function f_mysum_slow (numeric, numeric) returns numeric language sql as $$ select $1+$2; $$;
 hidden batch(es)


create aggregate mysum_slow (numeric) ( sfunc = f_mysum_slow, stype = numeric );
 hidden batch(es)


create table foo(bar integer);
 hidden batch(es)


insert into foo(bar) select generate_series(1,100000);
 hidden batch(es)


vacuum analyze;
 hidden batch(es)


select sum(bar), clock_timestamp()-statement_timestamp() from foo;
sum ?column?
5000050000 00:00:00.015017
 hidden batch(es)


select mysum_fast(bar), clock_timestamp()-statement_timestamp() from foo;
mysum_fast ?column?
5000050000 00:00:00.045341
 hidden batch(es)


select mysum_slow(bar), clock_timestamp()-statement_timestamp() from foo;
mysum_slow ?column?
00:00:00.230979
 hidden batch(es)