Re: Problems with SPI memory management

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Katsaros Kwn/nos" <ntinos(at)aueb(dot)gr>
Cc: Postgres Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Problems with SPI memory management
Date: 2004-09-15 16:51:40
Message-ID: 4821.1095267100@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

"Katsaros Kwn/nos" <ntinos(at)aueb(dot)gr> writes:
> 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.

What do you mean by "begin a new SPI session" --- do you SPI_finish()
and SPI_connect()? (If so, why bother?) I think that SPI_finish()
would release the memory in which the previous plan existed. If you're
not copying the entire parse tree this would lead to trouble.

You'd be well advised to be doing this sort of hackery in a build with
--enable-cassert. That turns on CLOBBER_FREED_MEMORY which makes
misuse of freed memory a whole lot more obvious.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jean-Luc Lachance 2004-09-15 16:55:24 Re: division by zero issue
Previous Message Katsaros Kwn/nos 2004-09-15 16:34:06 Problems with SPI memory management

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2004-09-15 17:34:01 xact.c state machine redesign
Previous Message James William Pye 2004-09-15 16:48:10 Re: banner vs version