X-Original-To: pgsql-odbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C3EB33A427E; Tue, 25 Jan 2005 10:19:56 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 38559-08; Tue, 25 Jan 2005 10:19:53 +0000 (GMT) Received: from sue.samurai.com (sue.samurai.com [205.207.28.74]) by svr1.postgresql.org (Postfix) with ESMTP id 51E423A19B8; Tue, 25 Jan 2005 10:19:54 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by sue.samurai.com (Postfix) with ESMTP id 4BE5B197EA; Tue, 25 Jan 2005 05:19:54 -0500 (EST) Received: from sue.samurai.com ([127.0.0.1]) by localhost (sue.samurai.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 36014-01-2; Tue, 25 Jan 2005 05:19:49 -0500 (EST) Received: from [220.101.3.183] (r220-101-3-183.cpe.unwired.net.au [220.101.3.183]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by sue.samurai.com (Postfix) with ESMTP id BB1B7197AA; Tue, 25 Jan 2005 05:19:47 -0500 (EST) Message-ID: <41F61D42.50804@samurai.com> Date: Tue, 25 Jan 2005 21:19:46 +1100 From: Neil Conway User-Agent: Mozilla Thunderbird 1.0 (Macintosh/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Christopher Kings-Lynne Cc: Bojidar Mihajlov , pgsql-hackers@postgresql.org, pgsql-odbc@postgresql.org Subject: Re: [HACKERS] RQ: Prepared statements used by multiple connections References: <20050125092707.32541.qmail@web50502.mail.yahoo.com> <41F61367.5060807@familyhealth.com.au> In-Reply-To: <41F61367.5060807@familyhealth.com.au> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at mailbox.samurai.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.008 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200501/73 X-Sequence-Number: 4868 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