Re: SPI access to PostgreSQL query plan - Mailing list pgsql-hackers

From Florian G. Pflug
Subject Re: SPI access to PostgreSQL query plan
Date
Msg-id 46EF1FD6.8010305@phlo.org
Whole thread Raw
In response to Re: SPI access to PostgreSQL query plan  ("Cristiano Duarte" <cunha17@gmail.com>)
Responses Re: SPI access to PostgreSQL query plan
List pgsql-hackers
Cristiano Duarte wrote:
> 2007/9/17, Tom Lane <tgl@sss.pgh.pa.us>:
>> "Cristiano Duarte" <cunha17@gmail.com> writes:
>>> Is there a way to have access to PostgreSQL query plan and/or predicates 
>>> inside a function using spi (or any other way)?
>> No.
>> 
>> Hi Tom,
> 
> "No" means: there is no way since the query plan is stored in a 
> secret/safe/protected/non-visible/fort-knox like place :) or it means, there
> is no friendly way to do it with spi or casual c language programming?

"No" as in: You function is not told by the executor which filters are applied
to it's results, and since it might be called multiple times within a query you
cannot figure that out yourself, even if you somehow got hold of the currently
executed plan.

So unless you start to hack the executor in serious ways, you'll either have to
pass the filter condition manually to your function, or live with it producing
unnecessary output rows.

Thats only holds true for functions in languages other than pl/sql (Which is
*not* the same as pl/pgsql) - SQL functions can be inlined by the executor, and
then are subject to the usual optimizations. (So they essentially behave like
views).

greetings, Florian Pflug



pgsql-hackers by date:

Previous
From: Guillaume Lelarge
Date:
Subject: Re: errcontext function
Next
From: Georgi Chulkov
Date:
Subject: Raw device I/O for large objects