Problems with SPI memory management

From: "Katsaros Kwn/nos" <ntinos(at)aueb(dot)gr>
To: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Problems with SPI memory management
Date: 2004-09-15 11:01:38
Message-ID: 1095246098.6720.22.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi!

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!

Browse pgsql-general by date

  From Date Subject
Next Message Michael Paesold 2004-09-15 11:06:25 Re: Rollback on Error
Previous Message Michael Paesold 2004-09-15 09:39:42 Re: disk performance benchmarks