Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 4E3379FB71E for ; Wed, 10 Oct 2007 16:57:09 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 77725-05 for ; Wed, 10 Oct 2007 16:55:09 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.230]) by postgresql.org (Postfix) with ESMTP id 8B18C9FB5D9 for ; Wed, 10 Oct 2007 16:55:09 -0300 (ADT) Received: by nz-out-0506.google.com with SMTP id l8so240150nzf for ; Wed, 10 Oct 2007 12:55:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=NljUHGDjjOdS8bvPOB7374AtrlLItmGl/14qfNFS9Dg=; b=WdCUghugmCPzmSTHiYnsPyQ1l7pjl+qHtVfgF2vZOjVu2fnH+Fu0afINUikwmyoYwXc2eIzGF8iOknjVE2nF/52fWvn8KyTw+KPRUvXPWaMwSkutMQIe4cGU9qFYjQAgvgjerURfZ/vgPcYVbT6aeK6KIDZitWHtCtXNkfCaVKU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Sc2ILu88A2kIEsf2Mklp0H7NqyvdPxI2/LWfwShF75kca7CXkrWg/ZMs4+VXQKri5GtqQLmBMcp+YUATcmFCblff/CTAjTVS3KRNMB4AhI47EKjRr5iy81pKj85VPjYD0mCfFjywfQAVDpRuEuvqORLyt+XzTHfysV14CQ2EqZc= Received: by 10.142.102.5 with SMTP id z5mr391278wfb.1192046107296; Wed, 10 Oct 2007 12:55:07 -0700 (PDT) Received: by 10.143.8.5 with HTTP; Wed, 10 Oct 2007 12:55:07 -0700 (PDT) Message-ID: <36e682920710101255n5760a009v8fdbf42e4599f16f@mail.gmail.com> Date: Wed, 10 Oct 2007 15:55:07 -0400 From: "Jonah H. Harris" To: theo@flame.co.za Subject: Re: Performance problems with prepared statements Cc: pgsql-performance@postgresql.org In-Reply-To: <1192027540.2495.3.camel@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <1192027540.2495.3.camel@localhost.localdomain> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/108 X-Sequence-Number: 27130 On 10/10/07, Theo Kramer wrote: > When running the query directly from psql it returns the required rows > in less than 100 milli-seconds. > > However, when using a prepared statement from my C application on the > above query and executing it the query duration is as follows > ... > Row[s] = 25, Duration = 435409.474 ms > How are you timing it? Does it really take 435 seconds to complete? Try the following in psql: postgres# PREPARE yourplan (VARCHAR, INT, INT) AS SELECT oid, * FROM calllog WHERE calllog_mainteng = $1 AND calllog_phase = $2 AND calllog_self < $3 OR calllog_mainteng = $1 AND calllog_phase < 8 ORDER BY calllog_mainteng DESC, calllog_phase DESC, calllog_self DESC limit 25; postgres# EXECUTE yourplan('124 ', 8, 366942); -- Jonah H. Harris, Sr. Software Architect | phone: 732.331.1324 EnterpriseDB Corporation | fax: 732.331.1301 499 Thornall Street, 2nd Floor | jonah.harris@enterprisedb.com Edison, NJ 08837 | http://www.enterprisedb.com/