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