Re: question about window function in C - Mailing list pgsql-general

From Tom Lane
Subject Re: question about window function in C
Date
Msg-id 1612.1419616654@sss.pgh.pa.us
Whole thread Raw
In response to question about window function in C  (Dan S <strd911@gmail.com>)
Responses Re: question about window function in C
List pgsql-general
Dan S <strd911@gmail.com> writes:
> I'm trying to write a window function in C .
> In the function I'm using a tuplesort to sort the window data and then do
> some processing.

Hmm ... why do you feel you need to do that?  The window function's input
should already be sorted according to the window specification.

> Now when I'm running the function I get this: 'WARNING:  temporary file
> leak: File 43 still referenced'
> The warning comes from my failure to call tuplesort_end at the appropriate
> time.

Unsurprising.

> So I think I need to use some callback mechanism to get that to work.
> I've found some reference in the postgres source code to
> RegisterExprContextCallback which seemed promising but I have no idea how
> to get the right expression context to put in as the first argument to that
> function.

I don't think there is one :-(.  WindowAgg has a per-input-tuple econtext,
and a per-output-tuple econtext, but what you'd need for this is a
partition-lifespan econtext, which doesn't exist.

It's possible that we could promote the "partcontext" memory context into
a full econtext so as to support this sort of behavior.  But I'd want to
see a reasonably convincing use-case for it.

            regards, tom lane


pgsql-general by date:

Previous
From: Dan S
Date:
Subject: question about window function in C
Next
From: Edson Carlos Ericksson Richter
Date:
Subject: How to install pgAdmin 1.20 on Mint Rebecca?