Exposing ArrayBuildState to pl/pgsql

From: Dave Byrne <dbyrne(at)mdb(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Exposing ArrayBuildState to pl/pgsql
Date: 2013-02-05 18:13:07
Message-ID: 13CE86C3-D0AD-43AE-BF24-DE4052D057AC@mdb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

For many aggregate functions it is necessary to store the actual column values in the aggregate state and then do whatever calculation across them in the final function. In many examples this is done by using array_append as the sfunc and then a custom plpgsql function as the final function operating on the array. Unfortunately array_append allocates a 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 function as the final function, however this requires writing/compiling/packaging the aggregate as an extension written in C when often the final function does very simple operations on the array that could easily be expressed in a higher level language for convenience.

From what I can tell ArrayBuildState is defined as type internal because it is a pointer being passed by value. Is this in fact the limitation that requires it to be type 'internal' or is there another limitation? Is there someway to expose ArrayBuildState as a type or even another way to do a 'fast' array collection of an aggregate that is to be operated on 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, proprietary and/or privileged information. If you are not the intended recipient, any review, use, distribution, dissemination or copying of this email is prohibited. If you have received this email in error, please notify the sender by replying to this message and delete this email immediately. Securities trading, account management, and investment banking services are offered by MDB Capital Group LLC, a registered broker-dealer and member of FINRA and SIPC. Unless clearly stated, nothing herein shall be construed to be an offer to sell, nor a solicitation of an offer to buy, any financial product.

Browse pgsql-hackers by date

  From Date Subject
Next Message Noah Misch 2013-02-05 18:22:06 Re: Visual Studio 2012 RC
Previous Message Phil Sorber 2013-02-05 17:44:15 Re: [PATCH] pg_isready (was: [WIP] pg_ping utility)