pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feedRQ: Prepared statements used by multiple connections
7+ messages / 5 participants
[nested] [flat]
* RQ: Prepared statements used by multiple connections
@ 2005-01-25 09:27 Bojidar Mihajlov <bmihajlov@yahoo.com>
2005-01-25 09:37 ` Re: [HACKERS] RQ: Prepared statements used by multiple connections Christopher Kings-Lynne <chriskl@familyhealth.com.au>
0 siblings, 1 reply; 7+ messages in thread
From: Bojidar Mihajlov @ 2005-01-25 09:27 UTC (permalink / raw)
To: pgsql-hackers@postgresql.org; pgsql-odbc
Hi all !
I need a mechanism to keep my queries in optimized
state so that multiple processes can use them.
__________________________________
Do you Yahoo!?
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: [HACKERS] RQ: Prepared statements used by multiple connections
2005-01-25 09:27 RQ: Prepared statements used by multiple connections Bojidar Mihajlov <bmihajlov@yahoo.com>
@ 2005-01-25 09:37 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2005-01-25 10:19 ` Re: [HACKERS] RQ: Prepared statements used by multiple connections Neil Conway <neilc@samurai.com>
0 siblings, 1 reply; 7+ messages in thread
From: Christopher Kings-Lynne @ 2005-01-25 09:37 UTC (permalink / raw)
To: Bojidar Mihajlov <bmihajlov@yahoo.com>; +Cc: pgsql-hackers@postgresql.org; pgsql-odbc
> 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.
You use it like this:
SELECT * FROM get_table_id(3);
Chris
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: [HACKERS] RQ: Prepared statements used by multiple connections
2005-01-25 09:27 RQ: Prepared statements used by multiple connections Bojidar Mihajlov <bmihajlov@yahoo.com>
2005-01-25 09:37 ` Re: [HACKERS] RQ: Prepared statements used by multiple connections Christopher Kings-Lynne <chriskl@familyhealth.com.au>
@ 2005-01-25 10:19 ` Neil Conway <neilc@samurai.com>
2005-01-25 10:36 ` Re: [HACKERS] RQ: Prepared statements used by multiple connections Christopher Kings-Lynne <chriskl@familyhealth.com.au>
0 siblings, 1 reply; 7+ messages in thread
From: Neil Conway @ 2005-01-25 10:19 UTC (permalink / raw)
To: Christopher Kings-Lynne <chriskl@familyhealth.com.au>; +Cc: Bojidar Mihajlov <bmihajlov@yahoo.com>; pgsql-hackers@postgresql.org; pgsql-odbc
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
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: [HACKERS] RQ: Prepared statements used by multiple connections
2005-01-25 09:27 RQ: Prepared statements used by multiple connections Bojidar Mihajlov <bmihajlov@yahoo.com>
2005-01-25 09:37 ` Re: [HACKERS] RQ: Prepared statements used by multiple connections Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2005-01-25 10:19 ` Re: [HACKERS] RQ: Prepared statements used by multiple connections Neil Conway <neilc@samurai.com>
@ 2005-01-25 10:36 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2005-01-25 21:46 ` Re: [HACKERS] RQ: Prepared statements used by multiple connections Michael Fuhr <mike@fuhr.org>
0 siblings, 1 reply; 7+ messages in thread
From: Christopher Kings-Lynne @ 2005-01-25 10:36 UTC (permalink / raw)
To: Neil Conway <neilc@samurai.com>; +Cc: Bojidar Mihajlov <bmihajlov@yahoo.com>; pgsql-hackers@postgresql.org; pgsql-odbc
> ... 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.
Are you sure it's only per-backend? I thought I tested it and it seemed
to prepare it everywhere... oh well.
Either way, it avoids the problem with prepared queries in that you
cannot know in advance if your query has already been prepared or not.
Chris
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: [HACKERS] RQ: Prepared statements used by multiple connections
2005-01-25 09:27 RQ: Prepared statements used by multiple connections Bojidar Mihajlov <bmihajlov@yahoo.com>
2005-01-25 09:37 ` Re: [HACKERS] RQ: Prepared statements used by multiple connections Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2005-01-25 10:19 ` Re: [HACKERS] RQ: Prepared statements used by multiple connections Neil Conway <neilc@samurai.com>
2005-01-25 10:36 ` Re: [HACKERS] RQ: Prepared statements used by multiple connections Christopher Kings-Lynne <chriskl@familyhealth.com.au>
@ 2005-01-25 21:46 ` Michael Fuhr <mike@fuhr.org>
0 siblings, 0 replies; 7+ messages in thread
From: Michael Fuhr @ 2005-01-25 21:46 UTC (permalink / raw)
To: Christopher Kings-Lynne <chriskl@familyhealth.com.au>; +Cc: Neil Conway <neilc@samurai.com>; Bojidar Mihajlov <bmihajlov@yahoo.com>; pgsql-hackers@postgresql.org; pgsql-odbc
On Tue, Jan 25, 2005 at 10:36:34AM +0000, Christopher Kings-Lynne wrote:
> >
> >... 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.
>
> Are you sure it's only per-backend? I thought I tested it and it seemed
> to prepare it everywhere... oh well.
How did you test it? You can use settings like debug_print_plan
and client_min_messages to see what's happening in each backend.
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: RQ: Prepared statements used by multiple connections
@ 2005-01-26 11:26 Bojidar Mihajlov <bmihajlov@yahoo.com>
0 siblings, 0 replies; 7+ messages in thread
From: Bojidar Mihajlov @ 2005-01-26 11:26 UTC (permalink / raw)
To: pgsql-hackers@postgresql.org; pgsql-odbc
It looks it couldn't happen this a way.
Did somebody find out an alternative.
Is reasonable some idea based on a connection pool ?
-Bozhidar
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: [HACKERS] RQ: Prepared statements used by multiple connections
@ 2005-01-26 13:26 Merlin Moncure <merlin.moncure@rcsonline.com>
0 siblings, 0 replies; 7+ messages in thread
From: Merlin Moncure @ 2005-01-26 13:26 UTC (permalink / raw)
To: Christopher Kings-Lynne <chriskl@familyhealth.com.au>; +Cc: pgsql-hackers@postgresql.org; pgsql-odbc
> > ... 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.
>
> Are you sure it's only per-backend? I thought I tested it and it
seemed
> to prepare it everywhere... oh well.
Plpgsql functions at the least are compiled by each backend. I take
advantage of this...I use schemas and I don't have to keep a copy of the
function for each dataset. I think vanilla sql functions might be
different.
> Either way, it avoids the problem with prepared queries in that you
> cannot know in advance if your query has already been prepared or not.
Yep. I like things the way they are, but I can feel the pain of
applications that don't (or can't) keep connections open.
Merlin
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2005-01-26 13:26 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-01-25 09:27 RQ: Prepared statements used by multiple connections Bojidar Mihajlov <bmihajlov@yahoo.com>
2005-01-25 09:37 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2005-01-25 10:19 ` Neil Conway <neilc@samurai.com>
2005-01-25 10:36 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2005-01-25 21:46 ` Michael Fuhr <mike@fuhr.org>
2005-01-26 11:26 Re: RQ: Prepared statements used by multiple connections Bojidar Mihajlov <bmihajlov@yahoo.com>
2005-01-26 13:26 Re: [HACKERS] RQ: Prepared statements used by multiple connections Merlin Moncure <merlin.moncure@rcsonline.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox