Problems with SPI memory management - Mailing list pgsql-general

From Katsaros Kwn/nos
Subject Problems with SPI memory management
Date
Msg-id 1095246098.6720.22.camel@localhost.localdomain
Whole thread Raw
List 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!



pgsql-general by date:

Previous
From: "Michael Paesold"
Date:
Subject: Re: disk performance benchmarks
Next
From: "Michael Paesold"
Date:
Subject: Re: Rollback on Error