Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 0CE0A9FB808 for ; Thu, 11 Oct 2007 06:12:54 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 60907-06 for ; Thu, 11 Oct 2007 06:12:36 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from ptb-relay03.plus.net (ptb-relay03.plus.net [212.159.14.214]) by postgresql.org (Postfix) with ESMTP id 872469FB574 for ; Thu, 11 Oct 2007 06:12:50 -0300 (ADT) Received: from [84.51.143.99] (helo=server3.office.archonet.com) by ptb-relay03.plus.net with esmtp (Exim) id 1Ifu63-0002FE-Gu; Thu, 11 Oct 2007 10:12:47 +0100 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id C040227406B; Thu, 11 Oct 2007 10:12:46 +0100 (BST) Message-ID: <470DE90E.2060605@archonet.com> Date: Thu, 11 Oct 2007 10:12:46 +0100 From: Richard Huxton User-Agent: Thunderbird 2.0.0.6 (X11/20070728) MIME-Version: 1.0 To: theo@flame.co.za CC: pgsql-performance@postgresql.org Subject: Re: Performance problems with prepared statements References: <1192027540.2495.3.camel@localhost.localdomain> <470CE918.4060608@dalibo.com> <1192044840.2549.21.camel@fedmac> In-Reply-To: <1192044840.2549.21.camel@fedmac> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/125 X-Sequence-Number: 27147 Theo Kramer wrote: > Thanks, had missed that, however, I am afraid that I fail to see how > preparing a query using PQprepare() and then executing it using > PQexecPrepared(), is 8 thousand times slower than directly executing > it.,, ( 403386.583ms/50.0ms = 8067 ). > > When doing a 'manual' prepare and explain analyze I get the following > rascal=# explain analyze execute cq ('124 ', 8, 366942); > Total runtime: 3.272 ms > > So I suspect that there is something more fundamental here... OK, so there must be something different between the two scenarios. It can only be one of: 1. Query 2. DB Environment (user, locale, settings) 3. Network environment (server/client/network activity etc) Are you sure you have the parameter types correct in your long-running query? Try setting log_min_duration_statement=9000 or so to capture long-running queries. Make sure the user and any custom settings are the same. Compare SHOW ALL for both ways. You've said elsewhere you've ruled out the network environment, so there's not point worrying about that further. -- Richard Huxton Archonet Ltd