Re: RQ: Prepared statements used by multiple connections - Mailing list pgsql-hackers

From Neil Conway
Subject Re: RQ: Prepared statements used by multiple connections
Date
Msg-id 41F61D42.50804@samurai.com
Whole thread Raw
In response to Re: RQ: Prepared statements used by multiple connections  (Christopher Kings-Lynne <chriskl@familyhealth.com.au>)
Responses Re: RQ: Prepared statements used by multiple connections  (Christopher Kings-Lynne <chriskl@familyhealth.com.au>)
List pgsql-hackers
Christopher Kings-Lynne wrote:
>> I need a mechanism to keep my queries in optimized state so that
>> multiple processes can use them.
>
>
> You should use stored procedures then.
>
> For instance, say you want to keep 'SELECT * FROM table WHERE id=x'
> prepared.  You would go:
>
> CREATE OR REPLACE FUNCTION get_table_id(integer) RETURNS SETOF table AS
> 'SELECT * FROM table WHERE id=$1' LANGUAGE SQL;
>
> PostgreSQL will store a prepared version of that statement after its
> first use.

... a prepared version that is local to the backend that invokes the
function, yes (i.e. it will be planned once per backend). So ISTM this
is equivalent functionality to what you can get using PREPARE or the
extended query protocol.

There currently isn't support for prepared queries that span multiple
connections. There has been prior discussion of the topic, so try
searching the pgsql-hackers archive. There are some implementation
issues that require thought (e.g. managing dependencies, storing a
potentially unbounded set of prepared queries in a finite amount of shmem).

-Neil


pgsql-hackers by date:

Previous
From: Christopher Kings-Lynne
Date:
Subject: Re: RQ: Prepared statements used by multiple connections
Next
From: ITAGAKI Takahiro
Date:
Subject: Re: [PATCHES] WAL: O_DIRECT and multipage-writer