Exposing ArrayBuildState to pl/pgsql - Mailing list pgsql-hackers

From Dave Byrne
Subject Exposing ArrayBuildState to pl/pgsql
Date
Msg-id 13CE86C3-D0AD-43AE-BF24-DE4052D057AC@mdb.com
Whole thread Raw
List pgsql-hackers
For many aggregate functions it is necessary to store the actual column values in the aggregate state and then do
whatevercalculation across them in the final function.  In many examples this is done by using array_append as the
sfuncand then a custom plpgsql function as the final function operating on the array.  Unfortunately array_append
allocatesa new array on each call which makes it unusably slow for any large aggregates. 

The speed of allocating an array is largely fixed by using array_agg_transfn as the state function and a custom C
functionas the final function,  however this requires writing/compiling/packaging the aggregate as an extension written
inC when often the final function does very simple operations on the array that could easily be expressed in a higher
levellanguage for convenience. 

From what I can tell ArrayBuildState is defined as type internal because it is a pointer being passed by value.  Is
thisin fact the limitation that requires it to be type 'internal' or is there another limitation?  Is there someway to
exposeArrayBuildState as a type or even another way to do a 'fast' array collection of an aggregate that is to be
operatedon by a final function written in sql or any of the pl-languages? 

Thanks
Dave Byrne


NOTICE: This message and any attachments are intended only for the use of the addressee and may contain confidential,
proprietaryand/or privileged information. If you are not the intended recipient, any review, use, distribution,
disseminationor copying of this email is prohibited. If you have received this email in error, please notify the sender
byreplying to this message and delete this email immediately. Securities trading, account management, and investment
bankingservices are offered by MDB Capital Group LLC, a registered broker-dealer and member of FINRA and SIPC. Unless
clearlystated, nothing herein shall be construed to be an offer to sell, nor a solicitation of an offer to buy, any
financialproduct. 



pgsql-hackers by date:

Previous
From: Phil Sorber
Date:
Subject: Re: [PATCH] pg_isready (was: [WIP] pg_ping utility)
Next
From: Noah Misch
Date:
Subject: Re: Visual Studio 2012 RC