Re: partial aggregation with internal state type

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: partial aggregation with internal state type
Date: 2017-06-09 16:47:29
Message-ID: CAMkU=1xQbDtrJOZq5NTQ+8Pf=s3EB88ZWK-p0qKOKKbH573rhA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jun 9, 2017 at 9:06 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Jeff Janes <jeff(dot)janes(at)gmail(dot)com> writes:
> > The docs for creating aggregates for 9.6 and beyond say:
> > "For aggregate functions whose state_data_type is internal, the
> combinefunc
> > must not be strict. In this case the combinefunc must ensure that null
> > states are handled correctly and that the state being returned is
> properly
> > stored in the aggregate memory context."
>
> > Since combinefunc with an internal type is only useful when serialfunc
> and
> > deserialfunc are also defined, why can't the built-in machinery just do
> the
> > right thing when faced with a strict combinefunc?
>
> The issue is how to initialize the state value to begin with.
>

Why does it need to be initialized? initializing a NULL state upon first
use is already the job of sfunc. Can't it just be left NULL if both inputs
are NULL? (and use serialize/deserialize to change the memory context of
the not-NULL argument if one is NULL and one is not NULL)

Cheers,

Jeff

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Supun Nakandala 2017-06-09 17:04:58 Re: How to refer to resource files from UDFs written in C
Previous Message Robert Haas 2017-06-09 16:19:26 Re: transition table behavior with inheritance appears broken (was: Declarative partitioning - another take)