Re: How to use SPI_saveplan

From: Jack Orenstein <jao(at)geophile(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to use SPI_saveplan
Date: 2006-09-10 02:20:55
Message-ID: 45037687.3070802@geophile.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:
> Jack Orenstein <jao(at)geophile(dot)com> writes:
>> I'm missing something very basic. If I do this:
>
>> Datum foobar(PG_FUNCTION_ARGS)
>> {
>> ...
>> void* plan = SPI_prepare(...);
>> void* saved_plan = SPI_saveplan(plan);
>> ...
>> }
>
>> then how can I access the saved plan in a later invocation of foobar?
>
> It's up to you to save the pointer somewhere where you can find it again
> when you need it. If there's only one interesting plan, use a static
> variable. Otherwise, you'll need some sort of data structure to map
> from what-you-need to the-plan-that-does-it. You can find examples of
> these approaches in the PG sources (from memory, ruleutils.c has some
> examples of the former approach while ri_triggers.c does the latter).

OK, that makes sense. It was use of the term "local variable" that threw
me.

Assigning SPI_prepare output to a local makes sense. Assigning
SPI_saveplan output to a static makes sense. But I don't see
the point in assigning SPI_saveplan output to a local, yet
that's what one case the doc specifically mentions.

Jack Orenstein

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-09-10 02:44:06 Re: How to use SPI_saveplan
Previous Message Christopher Browne 2006-09-10 01:48:23 Re: Data Warehouse