Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id D4FAC9FBB14 for ; Thu, 11 Oct 2007 17:04:22 -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 50685-04 for ; Thu, 11 Oct 2007 17:04:13 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.168]) by postgresql.org (Postfix) with ESMTP id 94D769FBA75 for ; Thu, 11 Oct 2007 17:04:14 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id j3so518394ugf for ; Thu, 11 Oct 2007 13:04:01 -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=wLH4d4eamPQAOOsw2X2gK0K53kXMM9JKBtQzbEwkxGU=; b=r7gcQzPztzNgFMshZVIZ3p4UhQ3Y7lyPG676v6HlDZjWHVlCfwNqX0TQFJZ5i76dp8zGLsH1lbSuTe0o5c28AXSUxgDKWnFlnsbGJrX4yCj65lc2hm03hkD6PSU3sJdXoY8LuMezWn7ilF/tDzno34G0xod2ox1ndnJnQnLiEcU= 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=kmtw865pQvF9MSjHNHqQfz0SVaU0m8Vjb5TUmu+sTYe/aYsu/DbDD/vxRIsH/nDzVxcwWoxfJ9+YSEW/SuuBGZl9/hV/eb0zV0z80o5UOaXV/1lEmfq7XpeN7Jxrk8kz9/iot88v9pmKO/D1zblLmEpZhyuZvgmQNEva9k5PHSY= Received: by 10.78.200.3 with SMTP id x3mr1825273huf.1192133041208; Thu, 11 Oct 2007 13:04:01 -0700 (PDT) Received: by 10.78.33.6 with HTTP; Thu, 11 Oct 2007 13:04:01 -0700 (PDT) Message-ID: Date: Thu, 11 Oct 2007 16:04:01 -0400 From: "Merlin Moncure" To: theo@flame.co.za Subject: Re: Performance problems with prepared statements Cc: pgsql-performance@postgresql.org, andrew@supernews.com In-Reply-To: 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> <470CE918.4060608@dalibo.com> <1192044840.2549.21.camel@fedmac> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/138 X-Sequence-Number: 27160 On 10/11/07, Andrew - Supernews wrote: > On 2007-10-10, Theo Kramer wrote: > > When doing a 'manual' prepare and explain analyze I get the following > > > > rascal=# prepare cq (char(12), smallint, integer) as SELECT oid, > > calllog_mainteng, calllog_phase, calllog_self FROM calllog > > WHERE calllog_mainteng = $1 > > AND calllog_phase = $2 > > AND calllog_self < $3 > > OR calllog_mainteng = $1 > > AND calllog_phase < $2 > > ORDER BY calllog_mainteng DESC, > > calllog_phase DESC, > > calllog_self DESC limit 25; > > PREPARE > > When you do this from the application, are you passing it 3 parameters, > or 5? The plan is clearly taking advantage of the fact that the two > occurrences of $1 and $2 are known to be the same value; if your app is > using some interface that uses ? placeholders rather than numbered > parameters, then the planner will not be able to make this assumption. > > Also, from the application, is the LIMIT 25 passed as a constant or is that > also a parameter? also, this looks a bit like a drilldown query, which is ordering the table on 2+ fields. if that's the case, row wise comparison is a better and faster approach. is this a converted cobol app? merlin