Re: [PATCHES] Avg performance for int8/numeric - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [PATCHES] Avg performance for int8/numeric
Date
Msg-id 365.1164587540@sss.pgh.pa.us
Whole thread Raw
In response to Re: [PATCHES] Avg performance for int8/numeric  (Mark Kirkwood <markir@paradise.net.nz>)
Responses Re: [PATCHES] Avg performance for int8/numeric  (Mark Kirkwood <markir@paradise.net.nz>)
List pgsql-hackers
Mark Kirkwood <markir@paradise.net.nz> writes:
> ... Having said that - the profiles suggest that we are perhaps doing 
> a whole lot more alloc'ing (i.e copying? detoasting?) of memory for 
> numerics than perhaps we need...

Yeah.  We've looked at this in the past and not figured out any
particularly desirable answer for variable-size accumulator state.
There is a hack in there for fixed-size pass-by-reference state (see
count(*)).  It's possible that you could get some traction by only doing
a palloc when the state size has to increase --- with a custom state
type it'd be possible to keep track of the allocated size as well as the
actual current length of the numeric sum.  Another idea to consider in
this context is avoiding repeated numeric pack/unpack overhead by
storing the running sum in the "calculation variable" format, but I'm
not sure how deep you'd need to burrow into numeric.c to allow that.

Most of this depends on being able to have a transition state value
that isn't any standard SQL datatype.  We've discussed that recently
in I-forget-what-context, and didn't find a good answer yet.  I think
you can find the thread by searching for a discussion of using type
"internal" as the state datatype --- which is an idea that doesn't work
by itself because of the security holes it'd open in the type system.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Missing ParameterStatus for backslash_quote
Next
From: Mark Kirkwood
Date:
Subject: Re: [PATCHES] Avg performance for int8/numeric