Problems with SPI memory management

From: "Katsaros Kwn/nos" <ntinos(at)aueb(dot)gr>
To: Postgres Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Problems with SPI memory management
Date: 2004-09-15 16:34:06
Message-ID: 1095266046.8788.5.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Hi!
I posted the following message to the general list but no answer.Could
you please help?

I have some problems with the SPI memory management (at least I think
this is the problem).

What I'm trying to do is to get the Query related to a select statement,
alter it and produce a new SPI_plan that will execute. To do so, I
retrieve the query from the _SPI_plan->qtlist, alter it (seems OK in
nodeToString) and then use some SPI functions copied in my code to
produce the new _SPI_plan. In more details, I begin a new my_SPI
session, call my_SPI_prepare and pass the query. The code is almost the
same with that in spi.c apart from that I do not call pg_parse and
pg_analyze_and_rewrite.Then I begin a new SPI session and pass the new
plan.

Now, the problem:

Everything works fine only when I execute my function just after I have
initiated a new psql session. When I try to call it again, the Query
structure inside the new plan seems empty (all fields shown by
nodeToString seem to have no values). Even if I reload my shared library
(load command),the same problem appears. I allocate memory for the Query
object with palloc() outside a SPI or my_SPI session.

Any hints?

Thanks in advance!
Ntinos Katsaros

PS: I'm not very good at C!

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-09-15 16:51:40 Re: Problems with SPI memory management
Previous Message Greg Donald 2004-09-15 16:30:51 division by zero issue

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2004-09-15 16:38:59 Re: PG_exception_stack
Previous Message James William Pye 2004-09-15 16:30:07 Re: PG_exception_stack