Re: percentile value check can be slow - Mailing list pgsql-hackers

From David Fetter
Subject Re: percentile value check can be slow
Date
Msg-id 20171118213016.GI4411@fetter.org
Whole thread Raw
In response to Re: percentile value check can be slow  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: percentile value check can be slow  (Tomas Vondra <tomas.vondra@2ndquadrant.com>)
List pgsql-hackers
On Sat, Nov 18, 2017 at 10:44:36AM -0500, Tom Lane wrote:
> jotpe <jotpe@posteo.de> writes:
> > I tried to enter invalid percentile fractions, and was astonished
> > that it seems to be checked after many work is done?
> 
> IIRC, only the aggregate's final-function is concerned with direct
> arguments, so it's not all that astonishing.

It may not be surprising from the point of view of a systems
programmer, but it's pretty surprising that this check is deferred to
many seconds in when the system has all the information it need in
order to establish this before execution begins.

I'm not sure I see an easy way to do this check early, but it's worth
trying on grounds of POLA violation.  I have a couple of ideas on how
to do this, one less invasive but hinky, the other a lot more invasive
but better overall.

Ugly Hack With Ugly Performance Consequences:   Inject a subtransaction at the start of execution that supplies an
emptyinput to the final function with the supplied direct   arguments.
 

Bigger Lift:   Require a separate recognizer function direct arguments and fire   it during post-parse analysis.
Perhapsthis could be called   recognizer along with the corresponding mrecognizer.  It's not   clear that it's sane to
haveseparate ones, but I thought I'd   bring it up for completeness.
 

Way Bigger Lift, As Far As I Can Tell, But More Fun For Users:   Allow optional CHECK constraints in CREATE AGGREGATE
fordirect   arguments.
 

Best,
David.
-- 
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: WIP: BRIN multi-range indexes
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] Repetitive code in RI triggers