Combine function returning NULL unhandled?

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-hackers(at)postgresql(dot)org, Robert Haas <robertmhaas(at)gmail(dot)com>, Simon Riggs <simon(at)2ndQuadrant(dot)com>, David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
Subject: Combine function returning NULL unhandled?
Date: 2017-11-21 03:36:42
Message-ID: 20171121033642.7xvmjqrl4jdaaat3@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Since
commit a7de3dc5c346e07e0439275982569996e645b3c2
Author: Robert Haas <rhaas(at)postgresql(dot)org>
Date: 2016-01-20 13:46:50 -0500

Support multi-stage aggregation.

Aggregate nodes now have two new modes: a "partial" mode where they
output the unfinalized transition state, and a "finalize" mode where
they accept unfinalized transition states rather than individual
values as input.

These new modes are not used anywhere yet, but they will be necessary
for parallel aggregation. The infrastructure also figures to be
useful for cases where we want to aggregate local data and remote
data via the FDW interface, and want to bring back partial aggregates
from the remote side that can then be combined with locally generated
partial aggregates to produce the final value. It may also be useful
even when neither FDWs nor parallelism are in play, as explained in
the comments in nodeAgg.c.

David Rowley and Simon Riggs, reviewed by KaiGai Kohei, Heikki
Linnakangas, Haribabu Kommi, and me.

there's both advance_transition_function and advance_combine_function,
fulfilling closely related duties.

While working on that code (making transition and combine functions go
through expression evaluation, so they can be JITed), I noticed a small
difference in behaviour beteween the two:

The plain transition case contains:
if (pergroupstate->transValueIsNull)
{
/*
* Don't call a strict function with NULL inputs. Note it is
* possible to get here despite the above tests, if the transfn is
* strict *and* returned a NULL on a prior cycle. If that happens
* we will propagate the NULL all the way to the end.
*/
return;
}

how come similar logic is not present for combine functions? I don't see
any checks preventing a combinefunc from returning NULL, nor do I see
https://www.postgresql.org/docs/devel/static/sql-createaggregate.html
spell out a requirement that that not be the case.

Greetings,

Andres Freund

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2017-11-21 04:36:08 Re: [JDBC] [HACKERS] Channel binding support for SCRAM-SHA-256
Previous Message Tom Lane 2017-11-21 01:30:00 Re: [HACKERS] Index only scan for cube and seg