Re: question about window function in C

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dan S <strd911(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: question about window function in C
Date: 2014-12-26 17:57:34
Message-ID: 1612.1419616654@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dan S <strd911(at)gmail(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Edson Carlos Ericksson Richter 2014-12-26 18:41:39 How to install pgAdmin 1.20 on Mint Rebecca?
Previous Message Dan S 2014-12-26 16:41:30 question about window function in C